From 91fc56c3223ce0a76b30a146b5c1e1cfa673b4d0 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 6 May 2019 10:24:54 +0200 Subject: [PATCH] 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, []).