Handle tailcall

This commit is contained in:
Erik Stenman 2019-02-13 16:49:55 +01:00
parent 286a8c1913
commit 25319fccd4
4 changed files with 23 additions and 6 deletions

View File

@ -269,7 +269,7 @@ to_bytecode([], Address, Env, Code, Opts) ->
to_fun_def([{id, _, Name}, {'(', _} | Rest]) ->
{ArgsType, [{'->', _} | Rest2]} = to_arg_types(Rest),
{ArgsType, [{'to', _} | Rest2]} = to_arg_types(Rest),
{RetType, Rest3} = to_type(Rest2),
{{Name, ArgsType, RetType}, Rest3}.

View File

@ -132,7 +132,8 @@ COMMENT : {token, {mnemonic, TokenLine, 'COMMENT'}}.
%% Symbols
\-\> : {token, {'->', TokenLine}}.
\-\> : {token, {'to', TokenLine}}.
\: : {token, {'to', TokenLine}}.
, : {token, {',', TokenLine}}.
\. : {token, {'.', TokenLine}}.
\( : {token, {'(', TokenLine}}.

View File

@ -30,7 +30,8 @@ mnemonic(?PUSH) -> 'PUSH' ;
mnemonic(?JUMP) -> 'JUMP' ;
mnemonic(?INC) -> 'INC' ;
mnemonic(?CALL) -> 'CALL' ;
mnemonic(OP) -> {OP, nothandled} ;
mnemonic(?CALL_T) -> 'CALL_T' ;
mnemonic(OP) -> {OP, nothandled} ;
mnemonic({comment,_}) -> 'COMMENT' .
m_to_op('NOP') -> ?NOP ;
@ -40,6 +41,7 @@ m_to_op('PUSH') -> ?PUSH ;
m_to_op('JUMP') -> ?JUMP ;
m_to_op('INC') -> ?INC ;
m_to_op('CALL') -> ?CALL ;
m_to_op('CALL_T') -> ?CALL_T ;
m_to_op(Data) when 0=<Data, Data=<255 -> Data.
args(?NOP) -> 0;
@ -48,10 +50,12 @@ args(?PUSH) -> 1;
args(?JUMP) -> 1;
args(?INC) -> 0;
args(?CALL) -> hash;
args(?CALL_T) -> hash;
args(_) -> 0. %% TODO do not allow this
end_bb(?RETURN) -> true;
end_bb(?JUMP) -> true;
end_bb(?CALL) -> true;
end_bb(_) -> false.
end_bb(?JUMP) -> true;
end_bb(?CALL) -> true;
end_bb(?CALL_T) -> true;
end_bb(_) -> false.

View File

@ -23,6 +23,18 @@ FUNCTION call(integer) -> integer
INC
RETURN
FUNCTION tailcall(integer) -> integer
INC
CALL_T inc
FUNCTION remote_call(integer) : integer
PUSH arg0
CALL_R remote.add_five
INC
RETURN
;; Test the code from the shell
;; _build/default/rel/aessembler/bin/aessembler console