Reification for Macros

157 views
Skip to first unread message

Nicolas Cannasse

unread,
Jun 17, 2012, 5:26:16 PM6/17/12
to haxe...@googlegroups.com
Hi,

I have added today reification for macros in Haxe, I'm interested in
tests/feedback, see http://ncannasse.fr/blog/reification_for_macros

Best,
Nicolas

Stephane Le Dorze

unread,
Jun 17, 2012, 5:33:56 PM6/17/12
to haxe...@googlegroups.com
Won't be able to play with it before a couple of days.
My very first feedback, without thinking about the details, is a big thanks Nicolas; I really think it makes macro usage more approachable so more usefull for a broader audience.
Very neat! :)

Stephane Le Dorze

unread,
Jun 17, 2012, 5:39:58 PM6/17/12
to haxe...@googlegroups.com
I think it brings nothing (so is of minor importance) but for homogeneity with 'format', have you though about:

macro foo( ${ <code generating an Expression> } )

as a short cut for:

var myExp = <code generating an Expression>;
macro foo( $myExp )

Stephane


Le dimanche 17 juin 2012 22:26:16 UTC+1, Nicolas Cannasse a écrit :

Nicolas Cannasse

unread,
Jun 17, 2012, 5:44:23 PM6/17/12
to haxe...@googlegroups.com
Le 17/06/2012 23:39, Stephane Le Dorze a �crit :
> I think it brings nothing (so is of minor importance) but for
> homogeneity with 'format', have you though about:
>
> macro foo( ${ <code generating an Expression> } )

${} is not a valid expression in Haxe, that would require to add syntax.
Unless you meant $(...) ?

Best,
Nicolas

Stephane Le Dorze

unread,
Jun 17, 2012, 5:46:18 PM6/17/12
to haxe...@googlegroups.com
Indeed!.

Le dimanche 17 juin 2012 22:44:23 UTC+1, Nicolas Cannasse a écrit :
Le 17/06/2012 23:39, Stephane Le Dorze a �crit :

Juraj Kirchheim

unread,
Jun 17, 2012, 5:49:11 PM6/17/12
to haxe...@googlegroups.com
Don't have time to try it right now, but it sure looks great! :)

A few questions though:

What kind of syntax is "macro <expr>"? Is this somehow directly
embedded into the parser? Or is it a first class expression (that
could in fact itself be generated by a macro - not that that's useful
in any way). Does the change make "macro" a keyword (in your blog post
it says "special word" which is really vague)?

Regards,
Juraj

On Sun, Jun 17, 2012 at 11:44 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:
> Le 17/06/2012 23:39, Stephane Le Dorze a écrit :
>
>> I think it brings nothing (so is of minor importance) but for
>> homogeneity with 'format', have you though about:
>>
>> macro foo( ${ <code generating an Expression> } )
>
>
> ${} is not a valid expression in Haxe, that would require to add syntax.
> Unless you meant $(...) ?
>
>
> Best,
> Nicolas
>
> --
> To post to this group haxe...@googlegroups.com
> http://groups.google.com/group/haxelang?hl=en

Nicolas Cannasse

unread,
Jun 17, 2012, 6:31:00 PM6/17/12
to haxe...@googlegroups.com
Le 17/06/2012 23:49, Juraj Kirchheim a �crit :
> Don't have time to try it right now, but it sure looks great! :)
>
> A few questions though:
>
> What kind of syntax is "macro <expr>"? Is this somehow directly
> embedded into the parser? Or is it a first class expression (that
> could in fact itself be generated by a macro - not that that's useful
> in any way). Does the change make "macro" a keyword (in your blog post
> it says "special word" which is really vague)?

It's a first class expression EMacro( e : Expr )
I used "special word" because it's not keyword ;)

Best,
Nicolas

airfoil

unread,
Jun 17, 2012, 9:27:23 PM6/17/12
to haxe...@googlegroups.com
Looks great! I can't wait to play with it!

Maximiliano Fernández

unread,
Jun 17, 2012, 9:53:30 PM6/17/12
to haxe...@googlegroups.com
Great addition. Kudos Nico!

Maximiliano Fernández do Santos

0 1 0              0 1 0
0 0 1  Rammserker  1 0 0
1 1 1              1 1 1

dlots

unread,
Jun 17, 2012, 11:48:19 PM6/17/12
to haxe...@googlegroups.com
Faurking amazing. Srsly. I had half a mind to start writing this sort of abstraction for macros. Just amazing. Thank you. This is 100 times better.

Jason O'Neil

unread,
Jun 17, 2012, 11:52:50 PM6/17/12
to haxe...@googlegroups.com
Agreed.

I think I'll wait until 2.10 to try them out but I'm excited by these
changes.

On Mon 18 Jun 2012 11:48:19 WST, dlots wrote:
> Faurking amazing. Srsly. I had half a mind to start writing this sort
> of abstraction for macros. Just amazing. Thank you. This is 100 times
> better.
>
> On Sunday, June 17, 2012 9:53:30 PM UTC-4, Rammserker wrote:
>
> Great addition. Kudos Nico!
>
> _Maximiliano Fernández do Santos
> _
>
> 0 *1* 0 0 *1* 0
> 0 0 *1 *Rammserker *1* 0 0
> *1 1 1 1 1 1*

Simon Krajewski

unread,
Jun 18, 2012, 1:17:32 AM6/18/12
to haxe...@googlegroups.com
While I love the feature itself, the "macro" keyword seems somewhat out
of place there. Shouldn't it be "expr" instead?
return expr "Hello World";
That seems more natural.

Simon

Yamuu

unread,
Jun 18, 2012, 10:05:26 AM6/18/12
to haxe...@googlegroups.com
Can this be used to call global functions?

Ex (works):
@:macro public static function is(instance:Expr, of_type:Expr):Expr
{
return
{
expr : EUntyped(
{
expr : ECall(
{
expr : EConst(CIdent("__is__")),
pos : pos
},
[
instance,
of_type
]),
pos : pos
}),
pos : pos
};
}

Ex (does not work):
@:macro public static function is(instance:Expr, of_type:Expr):Expr
{
return macro $__is__($instance, $of_type);
}

Nicolas Cannasse

unread,
Jun 18, 2012, 10:44:26 AM6/18/12
to haxe...@googlegroups.com
Le 18/06/2012 16:05, Yamuu a �crit :
> Can this be used to call global functions?
>
> Ex (works):
> @:macro public static function is(instance:Expr, of_type:Expr):Expr
> {
> return
> {
> expr : EUntyped(
> {
> expr : ECall(
> {
> expr : EConst(CIdent("__is__")),
> pos : pos
> },
> [
> instance,
> of_type
> ]),
> pos : pos
> }),
> pos : pos
> };
> }
>
> Ex (does not work):
> @:macro public static function is(instance:Expr, of_type:Expr):Expr
> {
> return macro $__is__($instance, $of_type);
> }

Why using $__is__ here ?

The equivalent to your previous example should be :

reurn macro untyped __is__($instance, $of_type);

Best,
Nicolas

Benjamin Dubois

unread,
Jun 18, 2012, 11:58:47 AM6/18/12
to haxe...@googlegroups.com
Looks I don't have excuse to avoid macro anymore :)

Ben

Marc Weber

unread,
Jun 18, 2012, 12:03:53 PM6/18/12
to haxelang
Excerpts from Benjamin Dubois's message of Mon Jun 18 17:58:47 +0200 2012:
> Looks I don't have excuse to avoid macro anymore :)

There was no excuse previously either because tink_macros provided a
similar feature, right?

Marc Weber

Michiel Crefcoeur

unread,
Jun 18, 2012, 1:13:39 PM6/18/12
to haxe...@googlegroups.com
haxe.awesomeness++;

btw: your website has been down all day :-(

Cauê Waneck

unread,
Jun 18, 2012, 2:00:59 PM6/18/12
to haxe...@googlegroups.com
Whoa, that's great!!! :) :)

2012/6/18 Michiel Crefcoeur <mpc...@gmail.com>
--

Nicolas Cannasse

unread,
Jun 18, 2012, 3:03:55 PM6/18/12
to haxe...@googlegroups.com
Le 18/06/2012 19:13, Michiel Crefcoeur a �crit :
> haxe.awesomeness++;
>
> btw: your website has been down all day :-(

Uhm, looks like we have some router issue, hope it is fixed soon.

Best,
Nicolas

Cauê Waneck

unread,
Jun 18, 2012, 3:14:03 PM6/18/12
to haxe...@googlegroups.com
it was due to the huge traffic generated from this announcement ;)

2012/6/18 Nicolas Cannasse <ncan...@motion-twin.com>
Le 18/06/2012 19:13, Michiel Crefcoeur a écrit :

haxe.awesomeness++;

btw: your website has been down all day :-(

Uhm, looks like we have some router issue, hope it is fixed soon.


Best,
Nicolas

Juraj Kirchheim

unread,
Jun 18, 2012, 3:15:03 PM6/18/12
to haxe...@googlegroups.com
You're right, tink_macros already offers that kind of functionality
since quite some time already
(https://github.com/back2dos/tinkerbell/wiki/tink_macros#wiki-ast). I
am very happy to see this become a supported first class language
feature, although it should be noted that currently AST.build is still
more powerful, because you can do things like:

package ;
#if macro
import haxe.macro.Expr;
import tink.macro.tools.AST;
#end
class Main {
static function main() {
var o = { foo: 5 };
var f = getter('foo');
trace(f(o));//5
}
@:macro static function getter(field:String) {
return AST.build(function (o) return o.eval__field);
}
}

I would very much like to see something like this supported as well,
because it has turned out to be a very powerful feature.

Regards,
Juraj

Nicolas Cannasse

unread,
Jun 18, 2012, 3:26:42 PM6/18/12
to haxe...@googlegroups.com
Le 18/06/2012 21:15, Juraj Kirchheim a �crit :
I made sure that every $-prefix string can be replaced with the
corresponding value, so we a bit more relaxing on the parser we could do
the following :

return macro function(o) return o.$field;

Best,
Nicolas

Stephane Le Dorze

unread,
Jun 18, 2012, 3:32:19 PM6/18/12
to haxe...@googlegroups.com
uh oh.. :)
and could the identifier be dynamically generated?

Le lundi 18 juin 2012 20:26:42 UTC+1, Nicolas Cannasse a écrit :
Le 18/06/2012 21:15, Juraj Kirchheim a �crit :

Juraj Kirchheim

unread,
Jun 18, 2012, 3:41:23 PM6/18/12
to haxe...@googlegroups.com
On Mon, Jun 18, 2012 at 9:26 PM, Nicolas Cannasse
<ncan...@motion-twin.com> wrote:
[...]
> I made sure that every $-prefix string can be replaced with the
> corresponding value, so we a bit more relaxing on the parser we could do the
> following :
>
>  return macro function(o) return o.$field;

That would be really, really cool!
Also it would ideally allow to useTypePaths and ComplexTypes from the
outer context.

Regards,
Juraj

Marcelo de Moraes Serpa

unread,
Jun 19, 2012, 7:23:23 PM6/19/12
to haxe...@googlegroups.com
Wasn't this somewhat already implemented in tink_macros ?

Looks interesting though,


- Marcelo

Juraj Kirchheim

unread,
Jun 20, 2012, 9:29:36 AM6/20/12
to haxe...@googlegroups.com
It was, but having this as a first class feature is favorable :)

dlots

unread,
Jul 15, 2012, 3:18:33 PM7/15/12
to haxe...@googlegroups.com
@:macro function object_owner_dao_get(method:String):Expr {
        return macro {
            if(object_owner_dao!=null) {
                var o:Dynamic=object_owner_dao.$method; //<--
                return viewManager.view_get(o,object_viewInfo.viewType,object_viewInfo.data)
            }
        }
    }

Is something like the above possible? I am getting:

s:/_flash/shared_haxe/shared/src/nodion/shared/dao/server/Dao_server_s.hx:226: characters 47-54 : Unexpected $method

I'm also not sure whether one needs to use a string or an expression for method (neither way works as the error has to do with :

object_owner_dao_get("get_withId_sql(id,cache,lock,key)");
object_owner_dao_get(get_withId_sql(id,cache,lock,key));

as specified by:


I made sure that every $-prefix string can be replaced with the
corresponding value, so we a bit more relaxing on the parser we could do
the following :

   return macro function(o) return o.$field;

Is the above possible with tink macros? I will be checking that shortly but if anyone knows that would be appreciated :)

Juraj Kirchheim

unread,
Jul 16, 2012, 5:48:21 AM7/16/12
to haxe...@googlegroups.com
This is due to a limitation in the Haxe syntax, although at some point
in this thread Nicolas said it might be lifted.

With tink_macros, there's a workaround, but you'll have to write
`eval__method` instead of `$method`:

@:macro function object_owner_dao_get(method:String):Expr {
return AST.build({
if(object_owner_dao!=null) {
var o:Dynamic=object_owner_dao.eval__method; //<--
return
viewManager.view_get(o,object_viewInfo.viewType,object_viewInfo.data)
}
});
}

Documentation is here:
https://github.com/back2dos/tinkerbell/wiki/tink_macros#wiki-ast

Please note that tink doesn't currently work with 2.10 but I'll have
that fixed today. The Haxe team has been busy while I was on holiday
:)

Regards,
Juraj

Nicolas Cannasse

unread,
Jul 16, 2012, 10:11:08 AM7/16/12
to haxe...@googlegroups.com
Le 15/07/2012 21:18, dlots a �crit :
> @:macro function object_owner_dao_get(method:String):Expr {
> return macro {
> if(object_owner_dao!=null) {
> var o:Dynamic=object_owner_dao.$method; //<--
> return
> viewManager.view_get(o,object_viewInfo.viewType,object_viewInfo.data)
> }
> }
> }
>
> Is something like the above possible? I am getting:

Not in time for 2.10, but you can fill an issue for a change request.

Best,
Nicolas
Reply all
Reply to author
Forward
0 new messages