Permalink
Browse files

partial support for definline functions

  • Loading branch information...
1 parent 1f2abf1 commit 10d022314f87697a90716c8261f24247f12ffca5 @ericbmerritt ericbmerritt committed Dec 29, 2011
Showing with 18 additions and 0 deletions.
  1. +10 −0 src/jxa_ctx.erl
  2. +8 −0 src/jxa_definition.erl
View
@@ -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,
@@ -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)
View
@@ -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)),

0 comments on commit 10d0223

Please sign in to comment.