Skip to content

Commit

Permalink
Check if calling #erl_func and #erl_mfa return a list
Browse files Browse the repository at this point in the history
Also commented out some test output.
  • Loading branch information
rvirding committed Oct 28, 2024
1 parent bede967 commit d148483
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/luerl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -431,17 +431,17 @@ decode_userdata(U, St, _In) ->
{userdata,Data}.

decode_luafunc(Fun, _St, _In) ->
io:format("dec ~p\n", [Fun]),
%% io:format("dec ~p\n", [Fun]),
fun(Args, State) ->
luerl_emul:functioncall(Fun, Args, State)
end.

decode_erlfunc(#erl_func{code=Fun}=Ef, _St, _In) ->
io:format("dec ~p\n", [Ef]),
decode_erlfunc(#erl_func{code=Fun}=_Ef, _St, _In) ->
%% io:format("dec ~p\n", [Ef]),
Fun. %Just the bare fun

decode_erlmfa(#erl_mfa{m=Mod,f=Func,a=Arg}=Mfa, _St, _In) ->
io:format("mfa ~p\n", [Mfa]),
decode_erlmfa(#erl_mfa{m=Mod,f=Func,a=Arg}=_Mfa, _St, _In) ->
%% io:format("mfa ~p\n", [Mfa]),
{Mod,Func,Arg}.

%% Externalize and Internalize ensure that the VM state passed in
Expand Down
4 changes: 2 additions & 2 deletions src/luerl_emul.erl
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ call_luafunc(#lua_func{lsz=Lsz,esz=Esz,pars=_Pars,body=Fis},
call_erlfunc(Func, Args, Stk, Cs0, #luerl{stk=Stk0}=St0) ->
case Func(Args, St0#luerl{stk=Stk,cs=Cs0}) of
%% {Ret,#luerl{}=St1} when is_list(Ret) ->
{Ret,St1} ->
{Ret,St1} when is_list(Ret) ->
[#call_frame{is=Is,cont=Cont,lvs=Lvs,env=Env}|Cs1] = Cs0,
emul(Is, Cont, Lvs, [Ret|Stk], Env, Cs1, St1#luerl{stk=Stk0,cs=Cs1});
_Other ->
Expand All @@ -807,7 +807,7 @@ call_erlfunc(Func, Args, Stk, Cs0, #luerl{stk=Stk0}=St0) ->

call_erlmfa({M,F,A}, Args, Stk, Cs0, #luerl{stk=Stk0}=St0) ->
case apply(M, F, [A, Args, St0#luerl{stk=Stk,cs=Cs0}]) of
{Ret,St1} ->
{Ret,St1} when is_list(Ret) ->
[#call_frame{is=Is,cont=Cont,lvs=Lvs,env=Env}|Cs1] = Cs0,
emul(Is, Cont, Lvs, [Ret|Stk], Env, Cs1, St1#luerl{stk=Stk0,cs=Cs1});
_Other ->
Expand Down
16 changes: 8 additions & 8 deletions src/luerl_new.erl
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,14 @@ encode(L, St0) when is_list(L) ->
{T,St2}; %No more to do for now
encode(F, St) when is_function(F, 2) ->
F1 = fun(Args, State) -> F(Args, State) end,
io:format("enc ~p\n", [#erl_func{code=F1}]),
%% io:format("enc ~p\n", [#erl_func{code=F1}]),
{#erl_func{code=F1}, St};
encode(F, St) when is_function(F, 1) ->
F1 = fun(Args, State) -> Res = F(Args), {Res,State} end,
io:format("enc ~p\n", [#erl_func{code=F1}]),
%% io:format("enc ~p\n", [#erl_func{code=F1}]),
{#erl_func{code=F1}, St};
encode({M,F,A}, St) when is_atom(M) and is_atom(F) ->
io:format("enc ~p\n", [#erl_mfa{m=M,f=F,a=A}]),
%% io:format("enc ~p\n", [#erl_mfa{m=M,f=F,a=A}]),
{#erl_mfa{m=M,f=F,a=A}, St};
encode({userdata,Data}, St) ->
luerl_heap:alloc_userdata(Data, St);
Expand Down Expand Up @@ -447,17 +447,17 @@ decode_userdata(U, St, _In) ->
{userdata,Data}.

decode_luafunc(Fun, _St, _In) ->
io:format("dec ~p\n", [Fun]),
%% io:format("dec ~p\n", [Fun]),
fun(Args, State) ->
luerl_emul:functioncall(Fun, Args, State)
end.

decode_erlfunc(#erl_func{code=Fun}=Ef, _St, _In) ->
io:format("dec ~p\n", [Ef]),
decode_erlfunc(#erl_func{code=Fun}=_Ef, _St, _In) ->
%% io:format("dec ~p\n", [Ef]),
Fun. %Just the bare fun

decode_erlmfa(#erl_mfa{m=Mod,f=Func,a=Arg}=Mfa, _St, _In) ->
io:format("mfa ~p\n", [Mfa]),
decode_erlmfa(#erl_mfa{m=Mod,f=Func,a=Arg}=_Mfa, _St, _In) ->
%% io:format("mfa ~p\n", [Mfa]),
{Mod,Func,Arg}.

%% Externalize and Internalize ensure that the VM state passed in
Expand Down

0 comments on commit d148483

Please sign in to comment.