Pt 165352420 dissallow stack n (#42)

* Get rid of redundant arity field from op defs. Reorder and renumber ops. Fix bb_end for abort and exit.

* FATE does not accept arbitrary stack positions, only the accumulator aka stack 0.
This commit is contained in:
Erik Stenman
2019-05-23 13:40:49 +02:00
committed by GitHub
parent 3e0e289f2f
commit 0d1899b32a
5 changed files with 62 additions and 56 deletions
+3 -5
View File
@@ -30,9 +30,7 @@
%%% arg0
%%% References to variables/registers start with var followed by an integer
%%% var0
%%% References to stack postions is either a (for stack 0)
%%% or start with stack followed by an integer
%%% stack1
%%% References to the top of the stack is the letter a (for accumulator)
%%% a
%%%
%%% Immediate values can be of 11 types:
@@ -243,8 +241,8 @@ to_bytecode([{arg,_line, N}|Rest], Address, Env, Code, Opts) ->
to_bytecode(Rest, Address, Env, [{arg, N}|Code], Opts);
to_bytecode([{var,_line, N}|Rest], Address, Env, Code, Opts) ->
to_bytecode(Rest, Address, Env, [{var, N}|Code], Opts);
to_bytecode([{stack,_line, N}|Rest], Address, Env, Code, Opts) ->
to_bytecode(Rest, Address, Env, [{stack, N}|Code], Opts);
to_bytecode([{stack,_line}|Rest], Address, Env, Code, Opts) ->
to_bytecode(Rest, Address, Env, [{stack, 0}|Code], Opts);
to_bytecode([{int,_line, Int}|Rest], Address, Env, Code, Opts) ->
to_bytecode(Rest, Address, Env, [{immediate, Int}|Code], Opts);
to_bytecode([{boolean,_line, Bool}|Rest], Address, Env, Code, Opts) ->
+2 -3
View File
@@ -27,8 +27,7 @@ BITS = (\!)?\<[\s01]*\>
Rules.
arg{INT} : {token, {arg, TokenLine, parse_arg(TokenChars)}}.
var{INT} : {token, {var, TokenLine, parse_var(TokenChars)}}.
a : {token, {stack, TokenLine, 0}}.
a{INT} : {token, {stack, TokenLine, parse_acc(TokenChars)}}.
a : {token, {stack, TokenLine}}.
true : {token, {boolean, TokenLine, true}}.
false : {token, {boolean, TokenLine, false}}.
@@ -108,7 +107,7 @@ parse_int(Chars) -> list_to_integer(Chars).
parse_arg("arg" ++ N) -> list_to_integer(N).
parse_var("var" ++ N) -> list_to_integer(N).
parse_acc("a" ++ N) -> list_to_integer(N).
parse_hash("#" ++ Chars) ->
+16 -6
View File
@@ -174,10 +174,10 @@ serialize_code([{_,_}|_] = List ) ->
Mods = << <<(modifier_bits(Type)):2>> || {Type, _} <- pad_args(lists:reverse(Args)) >>,
case Mods of
<<M1:8, M2:8>> ->
[M1, M2 | [serialize_data(Type, Arg) || {Type, Arg} <- Args]] ++
[M1, M2 | [serialize_data(Type, Arg) || {Type, Arg} <- Args, Type =/= stack]] ++
serialize_code(Rest);
<<M1:8>> ->
[M1 | [serialize_data(Type, Arg) || {Type, Arg} <- Args]] ++
[M1 | [serialize_data(Type, Arg) || {Type, Arg} <- Args, Type =/= stack]] ++
serialize_code(Rest)
end;
serialize_code([Op|Rest]) ->
@@ -304,15 +304,25 @@ deserialize_op(Op, Rest, Code) ->
deserialize_n_args(N, <<M3:2, M2:2, M1:2, M0:2, Rest/binary>>) when N =< 4 ->
ArgMods = lists:sublist([M0, M1, M2, M3], N),
lists:mapfoldl(fun(M, Acc) ->
{Arg, Acc2} = aeb_fate_encoding:deserialize_one(Acc),
{{bits_to_modifier(M), Arg}, Acc2}
case bits_to_modifier(M) of
stack ->
{{stack, 0}, Acc};
Modifier ->
{Arg, Acc2} = aeb_fate_encoding:deserialize_one(Acc),
{{Modifier, Arg}, Acc2}
end
end, Rest, ArgMods);
deserialize_n_args(N, <<M7:2, M6:2, M5:2, M4:2, M3:2, M2:2, M1:2, M0:2,
Rest/binary>>) when N =< 8 ->
ArgMods = lists:sublist([M0, M1, M2, M3, M4, M5, M6, M7], N),
lists:mapfoldl(fun(M, Acc) ->
{Arg, Acc2} = aeb_fate_encoding:deserialize_one(Acc),
{{bits_to_modifier(M), Arg}, Acc2}
case bits_to_modifier(M) of
stack ->
{{stack, 0}, Acc};
Modifier ->
{Arg, Acc2} = aeb_fate_encoding:deserialize_one(Acc),
{{Modifier, Arg}, Acc2}
end
end, Rest, ArgMods).
deserialize_signature(Binary) ->
+5 -6
View File
@@ -43,7 +43,7 @@ ops_defs() ->
, { 'SWITCH_VN', 16#0c, true, 4, [a, li], switch, "Conditional jump to a basic block on variant tag."}
, { 'CALL_VALUE', 16#0d, false, 3, [a], call_value, "The value sent in the current remote call."}
, { 'PUSH', 16#0e, false, 2, [a], push, "Push argument to stack."}
, { 'DUPA', 16#0f, false, 3, [], dup, "push copy of accumulator on stack."}
, { 'DUPA', 16#0f, false, 3, [], dup, "Duplicate top of stack."}
, { 'DUP', 16#10, false, 3, [a], dup, "push Arg0 stack pos on top of stack."}
, { 'POP', 16#11, false, 3, [a], pop, "Arg0 := top of stack."}
, { 'INCA', 16#12, false, 2, [], inc, "Increment accumulator."}
@@ -92,7 +92,7 @@ ops_defs() ->
, { 'INT_TO_ADDR', 16#3d, false, 3, [a,a], int_to_addr, "Arg0 := turn integer Arg1 into an address."}
, { 'VARIANT', 16#3e, false, 3, [a,a,a,a], variant, "Arg0 := create a variant of size Arg1 with the tag Arg2 (Arg2 < Arg1) and take Arg3 elements from the stack."}
, { 'VARIANT_TEST', 16#3f, false, 3, [a,a,a], variant_test, "Arg0 := true if variant Arg1 has the tag Arg2."}
, { 'VARIANT_ELEMENT', 16#40, false, 3, [a,a,a], variant_element, "Arg0 := element number Arg2 from variant Arg1."}
, { 'VARIANT_ELEMENT', 16#40, false, 3, [a,a,a], variant_element, "Arg0 := element number Arg2 from variant Arg1."}
, { 'BITS_NONEA', 16#41, false, 3, [], bits_none, "accumulator := empty bitmap."}
, { 'BITS_NONE', 16#42, false, 3, [a], bits_none, "Arg0 := empty bitmap."}
, { 'BITS_ALLA', 16#43, false, 3, [], bits_all, "accumulator := full bitmap."}
@@ -215,7 +215,7 @@ generate_code_ops(Modulename, SrcDir, Ops) ->
"-type fate_arg_immediate(T) :: {immediate, T}.\n"
"-type fate_arg_var() :: {var, integer()}.\n"
"-type fate_arg_arg() :: {arg, integer()}.\n"
"-type fate_arg_stack() :: {stack, integer()}.\n"
"-type fate_arg_stack() :: {stack, 0}.\n"
"-type fate_arg() :: fate_arg_immediate()\n"
" | fate_arg_var()\n"
" | fate_arg_arg()\n"
@@ -425,8 +425,7 @@ gen_asm_pp(Module, Path, Ops) ->
" aeb_fate_data:format(I);\n"
"format_arg(a, {arg, N}) -> io_lib:format(\"arg~~p\", [N]);\n"
"format_arg(a, {var, N}) -> io_lib:format(\"var~~p\", [N]);\n"
"format_arg(a, {stack, 0}) -> \"a\";\n"
"format_arg(a, {stack, N}) -> io_lib:format(\"a~~p\", [N]).\n\n"
"format_arg(a, {stack, 0}) -> \"a\".\n\n"
"lookup(Name, Symbols) ->\n"
" maps:get(Name, Symbols, io_lib:format(\"~~p\",[Name])).\n\n"
"~s"
@@ -562,7 +561,7 @@ gen_arg(t) -> "integer".
any_arg() ->
element(rand:uniform(5), {"a", stack_arg(), var_arg(), arg_arg(), imm_arg()}).
stack_arg() -> "a" ++ integer_to_list(rand:uniform(255)-1).
stack_arg() -> "a".
arg_arg() -> "arg" ++ integer_to_list(rand:uniform(256)-1).
var_arg() -> "var" ++ integer_to_list(rand:uniform(256)-1).
imm_arg() ->