Skip to content

Commit

Permalink
partial support for definline functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbmerritt committed Dec 29, 2011
1 parent 1f2abf1 commit 10d0223
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/jxa_ctx.erl
Expand Up @@ -26,6 +26,7 @@
definitions/1,
add_exported_definition/5,
add_definition/5,
add_inline_definition/5,
add_def_placeholder/3,
resolve_reference/3,
push_scope/1,
Expand Down Expand Up @@ -263,6 +264,15 @@ add_definition(Line, Name, Vars, Body, Ctx0=#context{definitions=Defs}) ->
{CerlName, CerlBody}, Defs)}.


add_inline_definition(Line, Name, Vars, Body, Ctx0=#context{definitions=Defs}) ->
Arity = erlang:length(Vars),
CerlName = cerl:ann_c_fname([Line, inline],
Name, Arity),
CerlBody = cerl:ann_c_fun([Line], Vars, Body),
Ctx0#context{definitions=ec_dictionary:add({Name, Arity},
{CerlName, CerlBody}, Defs)}.


resolve_reference(Ref={'__fun__', _, Arity}, Arity, Ctx) ->
search_for_defined_used_function(Ref, Arity, Ctx);
resolve_reference({'__fun__', Module, Function}, Arity, Ctx)
Expand Down
8 changes: 8 additions & 0 deletions src/jxa_definition.erl
Expand Up @@ -24,6 +24,14 @@ comp(Path0, Ctx0, [defn, Name, Args, Expression]) ->
{_, {Line, _}} = jxa_annot:get(jxa_path:add_path(Path0),
jxa_ctx:annots(Ctx2)),
jxa_ctx:add_definition(Line, Name, ArgList, Body, Ctx1);
comp(Path0, Ctx0, [definline, Name, Args, Expression]) ->
Ctx1 = jxa_ctx:add_def_placeholder(Name, erlang:length(Args), Ctx0),
{Ctx2, ArgList, Body} =
jxa_expression:do_function_body(jxa_path:incr(2, Path0), Ctx1,
Args, Expression),
{_, {Line, _}} = jxa_annot:get(jxa_path:add_path(Path0),
jxa_ctx:annots(Ctx2)),
jxa_ctx:add_inline_definition(Line, Name, ArgList, Body, Ctx1);
comp(Path0, Ctx0, _) ->
{_, Idx} = jxa_annot:get(jxa_path:add_path(Path0),
jxa_ctx:annots(Ctx0)),
Expand Down

0 comments on commit 10d0223

Please sign in to comment.