From 491489ca7d2e1f3488cb84d2f157b7fcb31fba1b Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 29 Apr 2019 09:53:51 +0200 Subject: [PATCH 1/5] Change ~w to ~p --- src/aeb_fate_generate_ops.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 5c224ca..6486d6a 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -427,7 +427,7 @@ gen_asm_pp(Module, Path, Ops) -> "format_arg(a, {stack, 0}) -> \"a\";\n" "format_arg(a, {stack, N}) -> io_lib:format(\"a~~p\", [N]).\n\n" "lookup(Name, Symbols) ->\n" - " maps:get(Name, Symbols, io_lib:format(\"~~w\",[Name])).\n\n" + " maps:get(Name, Symbols, io_lib:format(\"~~p\",[Name])).\n\n" "~s" , [Formats]), From bf6741eac4261c3d63030aa8cd72f49799eebf89 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 29 Apr 2019 13:37:00 +0200 Subject: [PATCH 2/5] Format of li should be {immediate, [integer()]} --- src/aeb_fate_generate_ops.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 6486d6a..63659f7 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -287,7 +287,7 @@ gen_arg_uses(_, []) -> gen_arg_uses(N, [a]) -> io_lib:format("Arg~w", [N]); gen_arg_uses(N, [is]) -> io_lib:format("{immediate, Arg~w}", [N]); gen_arg_uses(N, [ii]) -> io_lib:format("{immediate, Arg~w}", [N]); -gen_arg_uses(N, [li]) -> io_lib:format("[{immediate, I} || I <- Arg~w]", [N]); +gen_arg_uses(N, [li]) -> io_lib:format("{immediate, Arg~w}", [N]); gen_arg_uses(N, [t]) -> io_lib:format("Arg~w", [N]); gen_arg_uses(N, [a | Args]) -> io_lib:format("Arg~w, ", [N]) ++ gen_arg_uses(N+1, Args); @@ -381,7 +381,7 @@ expand_types([T|Ts]) ->expand_type(T) ++ ", " ++ expand_types(Ts). expand_type(a) -> "fate_arg()"; expand_type(is) -> "fate_arg_immediate(aeb_fate_data:fate_string())"; expand_type(ii) -> "fate_arg_immediate(aeb_fate_data:fate_integer())"; -expand_type(li) -> "[fate_arg_immediate(aeb_fate_data:fate_integer())]"; +expand_type(li) -> "fate_arg_immediate([aeb_fate_data:fate_integer()])"; expand_type(t) -> "aeb_fate_data:fate_type_type()". generate_scanner(TemplateFile, Outfile, Path, Ops) -> From 1887486d3670a52aa836c233fdd567bcc5c6e246 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Tue, 30 Apr 2019 11:48:11 +0200 Subject: [PATCH 3/5] Replace STR_EQ by APPEND STR_EQ is not needed, the regular EQ instruction can handle strings as well. Having an instruction for list append is quite handy though (would need two passes to do it tail recursive in FATE assembly) --- src/aeb_fate_generate_ops.erl | 2 +- test/asm_code/all_instructions.fate | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 63659f7..6c08d9a 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -78,7 +78,7 @@ ops_defs() -> , { 'HD', 16#35, 2, false, 3, [a,a], hd, "Arg0 := head of list Arg1."} , { 'TL', 16#36, 2, false, 3, [a,a], tl, "Arg0 := tail of list Arg1."} , { 'LENGTH', 16#37, 2, false, 3, [a,a], length, "Arg0 := length of list Arg1."} - , { 'STR_EQ', 16#38, 3, false, 3, [a,a,a], str_eq, "Arg0 := true iff the strings Arg1 and Arg2 are the same."} + , { 'APPEND', 16#38, 3, false, 3, [a,a,a], append, "Arg0 := Arg1 ++ Arg2."} , { 'STR_JOIN', 16#39, 3, false, 3, [a,a,a], str_join, "Arg0 := string Arg1 followed by string Arg2."} , { 'INT_TO_STR', 16#40, 2, false, 3, [a,a], int_to_str, "Arg0 := turn integer Arg1 into a string."} , { 'ADDR_TO_STR', 16#41, 2, false, 3, [a,a], addr_to_str, "Arg0 := turn address Arg1 into a string."} diff --git a/test/asm_code/all_instructions.fate b/test/asm_code/all_instructions.fate index 1cdfeb0..e8cdb29 100644 --- a/test/asm_code/all_instructions.fate +++ b/test/asm_code/all_instructions.fate @@ -104,7 +104,7 @@ FUNCTION foo () : {tuple, []} LENGTH var216 a143 - STR_EQ { 203961992615221001243597889146034217896 => 0x1f53a1843} 281217554184165828643225535776787296845 a177 + APPEND { 203961992615221001243597889146034217896 => 0x1f53a1843} 281217554184165828643225535776787296845 a177 STR_JOIN a a 7144184027126178769820155907121270843348 From 91fc56c3223ce0a76b30a146b5c1e1cfa673b4d0 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 6 May 2019 10:24:54 +0200 Subject: [PATCH 4/5] Change local calls to allow dynamic function name --- src/aeb_fate_generate_ops.erl | 8 ++------ test/asm_code/all_instructions.fate | 4 ++-- test/asm_code/memory.fate | 2 +- test/asm_code/test.fate | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 6c08d9a..8909a05 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -30,9 +30,9 @@ ops_defs() -> %% Opname, Opcode, args, end_bb, gas, format, Constructor, Documentation [ { 'RETURN', 16#00, 0, true, 2, atomic, return, "Return from function call pop stack to arg0. The type of the retun value has to match the return type of the function."} , { 'RETURNR', 16#01, 1, true, 2, [a], returnr, "Return from function call copy Arg0 to arg0. The type of the retun value has to match the return type of the function."} - , { 'CALL', 16#02, 1, true, 4, [is], call, "Call given function with args on stack. The types of the arguments has to match the argument typs of the function."} + , { 'CALL', 16#02, 1, true, 4, [a], call, "Call the function Arg0 with args on stack. The types of the arguments has to match the argument typs of the function."} , { 'CALL_R', 16#03, 2, true, 8, [a,is], call_r, "Remote call to given contract and function. The types of the arguments has to match the argument typs of the function."} - , { 'CALL_T', 16#04, 1, true, 4, [is], call_t, "Tail call to given function. The types of the arguments has to match the argument typs of the function. And the return type of the called function has to match the type of the current function."} + , { 'CALL_T', 16#04, 1, true, 4, [a], call_t, "Tail call to function Arg0. The types of the arguments has to match the argument typs of the function. And the return type of the called function has to match the type of the current function."} , { 'CALL_TR', 16#05, 2, true, 8, [a,is], call_tr, "Remote tail call to given contract and function. The types of the arguments has to match the argument typs of the function. And the return type of the called function has to match the type of the current function."} , { 'JUMP', 16#06, 1, true, 3, [ii], jump, "Jump to a basic block. The basic block has to exist in the current function."} , { 'JUMPIF', 16#07, 2, true, 4, [a,ii], jumpif, "Conditional jump to a basic block. If Arg0 then jump to Arg1."} @@ -434,10 +434,6 @@ gen_asm_pp(Module, Path, Ops) -> io:format(File, "format_op(Op, _Symbols) -> io_lib:format(\";; Bad Op: ~~w\\n\", [Op]).\n", []), file:close(File). -gen_format(#{opname := Name}) when ('CALL' =:= Name) or (Name =:= 'CALL_T') -> - io_lib:format("format_op({~w, {immediate, Function}}, Symbols) ->\n" - "[\"~s \", lookup(Function, Symbols)];", - [Name, atom_to_list(Name)]); gen_format(#{opname := Name}) when (Name =:= 'CALL_R') or (Name =:= 'CALL_TR') -> io_lib:format("format_op({~w, {immediate, Contract}, {immediate, Function}}, Symbols) ->\n" "[\"~s \", lookup(Contract, Symbols), \".\", lookup(Function, Symbols)];\n" diff --git a/test/asm_code/all_instructions.fate b/test/asm_code/all_instructions.fate index e8cdb29..472f9fe 100644 --- a/test/asm_code/all_instructions.fate +++ b/test/asm_code/all_instructions.fate @@ -8,11 +8,11 @@ FUNCTION foo () : {tuple, []} RETURNR a13 - CALL foo + CALL "foo" CALL_R arg125 foo - CALL_T foo + CALL_T "foo" CALL_TR arg245 foo diff --git a/test/asm_code/memory.fate b/test/asm_code/memory.fate index e162daa..ede1e57 100644 --- a/test/asm_code/memory.fate +++ b/test/asm_code/memory.fate @@ -2,7 +2,7 @@ FUNCTION call(integer):integer STORE var1 arg0 PUSH 0 - CALL write + CALL "write" PUSH var1 RETURN diff --git a/test/asm_code/test.fate b/test/asm_code/test.fate index aae9102..e08c0eb 100644 --- a/test/asm_code/test.fate +++ b/test/asm_code/test.fate @@ -19,14 +19,14 @@ FUNCTION inc(integer) -> integer FUNCTION call(integer) -> integer INCA - CALL inc + CALL "inc" INCA RETURN FUNCTION tailcall(integer) -> integer INCA - CALL_T inc + CALL_T "inc" FUNCTION remote_call(integer) : integer PUSH arg0 @@ -42,4 +42,4 @@ FUNCTION remote_tailcall(integer) : integer ;; _build/default/rel/aessembler/bin/aessembler console ;; aeb_aefa:file("../../../../test/asm_code/test.fate", []). -;; f(Asm), f(Env), f(BC), Asm = aefa_asm:read_file("../../../../test/asm_code/test.fate"), {Env, BC} = aefa_asm:asm_to_bytecode(Asm, []), aefa_asm:bytecode_to_fate_code(BC, []). \ No newline at end of file +;; f(Asm), f(Env), f(BC), Asm = aefa_asm:read_file("../../../../test/asm_code/test.fate"), {Env, BC} = aefa_asm:asm_to_bytecode(Asm, []), aefa_asm:bytecode_to_fate_code(BC, []). From 6eab9a32c9e636773948275e50cf1f75629be8a9 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Tue, 7 May 2019 10:11:20 +0200 Subject: [PATCH 5/5] Bump aeserialization dependency --- rebar.config | 2 +- rebar.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index 5f75d04..99ed2cd 100644 --- a/rebar.config +++ b/rebar.config @@ -6,7 +6,7 @@ {deps, [ {eblake2, "1.0.0"} , {aeserialization, {git, "https://github.com/aeternity/aeserialization.git", - {ref, "6dce265"}}} + {ref, "816bf99"}}} , {getopt, "1.0.1"} ]}. diff --git a/rebar.lock b/rebar.lock index 0e58139..188572f 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,7 @@ {"1.1.0", [{<<"aeserialization">>, {git,"https://github.com/aeternity/aeserialization.git", - {ref,"6dce265753af4e651f77746e77ea125145c85dd3"}}, + {ref,"816bf994ffb5cee218c3f22dc5fea296c9e0882e"}}, 0}, {<<"base58">>, {git,"https://github.com/aeternity/erl-base58.git",