Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for AOT code generation #3

Open
hyperthunk opened this issue Jan 13, 2012 · 1 comment
Open

Support for AOT code generation #3

hyperthunk opened this issue Jan 13, 2012 · 1 comment
Assignees
Labels

Comments

@hyperthunk
Copy link
Owner

It would be nice if we could write an annotation handler that is used to generate code at compile time (or when runtime code (re)gen is being applied). The canonical use-case I have for this at the moment is to avoid this:

starts_with(Axis, Value) ->
    binop(starts_with, Axis, Value).

eq(Axis, Value) ->
    binop(eq, Axis, Value).

%% etc
binop(Op, Axis, {literal, _}=Literal) ->
    {Axis, {operator, Op}, Literal}.

And instead to be able to do something like this:

-aliases({[eq, starts_with, ends_with|_Etc], binop, {prefix, function}}). 
binop(Op, Axis, {literal, _}=Literal) ->
    {Axis, {operator, Op}, Literal}.

such that the wrapper functions are generated for me. Quite what the callback/annotation handler module needs to look like isn't clear to me at the moment, but I suspect either a generate_code function or maybe some meta-data to indicate that we want code-gen to occur would do:

-module(aliases).
%% etc...

code_gen(#annotation{data={Aliases, Target, Options}, AST, Options) ->
    {export, [annotations:gen_function(A, redirect_here, Target) || A <- Aliases]}.

around_advice(#annotation{data=Target}, _M, F, _Inputs) ->
    annotation:call_advised(Mod, Target, [F|Inputs]).
@ghost ghost assigned hyperthunk Jan 13, 2012
@hyperthunk
Copy link
Owner Author

This is partly implemented in b4ed0cf (v0.0.2) but still needs some work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant