Skip to content
Browse files

add placeholder to allow recursive functions

  • Loading branch information...
1 parent f315d8d commit 30587a4e0371256bc462da4086610acb34246441 @ericbmerritt ericbmerritt committed Dec 28, 2011
Showing with 17 additions and 7 deletions.
  1. +8 −0 src/jxa_ctx.erl
  2. +9 −7 src/jxa_definition.erl
View
8 src/jxa_ctx.erl
@@ -26,6 +26,7 @@
definitions/1,
add_exported_definition/5,
add_definition/5,
+ add_def_placeholder/3,
resolve_reference/3,
push_scope/1,
add_variable_to_scope/2,
@@ -242,6 +243,13 @@ add_exported_definition(Line, Name, Vars, Body, Ctx0) ->
add_definition(Line, Name, Vars, Body,
add_export(Line, Name, Arity, Ctx0)).
+
+-spec add_def_placeholder(atom(), non_neg_integer(), context()) ->
+ context().
+add_def_placeholder(Name, Arity, Ctx0=#context{definitions=Defs}) ->
+ Ctx0#context{definitions=ec_dictionary:add({Name, Arity},
+ '__placeholder__', Defs)}.
+
-spec add_definition(non_neg_integer(),
atom(), [cerl:cerl()], cerl:cerl(),
context()) ->
View
16 src/jxa_definition.erl
@@ -9,18 +9,20 @@
%%=============================================================================
comp(Path0, Ctx0, ['defn+', Name, Args, Expression])
when is_atom(Name), is_list(Args) ->
- {Ctx1, ArgList, Body} =
- jxa_expression:do_function_body(jxa_path:incr(2, Path0), Ctx0,
+ 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(Ctx1)),
- jxa_ctx:add_exported_definition(Line, Name, ArgList, Body, Ctx1);
+ jxa_ctx:annots(Ctx2)),
+ jxa_ctx:add_exported_definition(Line, Name, ArgList, Body, Ctx2);
comp(Path0, Ctx0, [defn, Name, Args, Expression]) ->
- {Ctx1, ArgList, Body} =
- jxa_expression:do_function_body(jxa_path:incr(2, Path0), Ctx0,
+ 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(Ctx1)),
+ jxa_ctx:annots(Ctx2)),
jxa_ctx:add_definition(Line, Name, ArgList, Body, Ctx1);
comp(Path0, Ctx0, _) ->
{_, Idx} = jxa_annot:get(jxa_path:add_path(Path0),

0 comments on commit 30587a4

Please sign in to comment.
Something went wrong with that request. Please try again.