From 3721fde7e83dbd16c2546e1f824eca70502da1a3 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Tue, 13 Aug 2019 14:18:01 +0200 Subject: [PATCH 1/4] Add typereps to remote call instructions --- src/aeb_fate_generate_ops.erl | 24 ++++++++++++++---------- test/asm_code/test.fate | 10 +++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/aeb_fate_generate_ops.erl b/src/aeb_fate_generate_ops.erl index 1c34692..6ec3444 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -46,10 +46,10 @@ ops_defs() -> [ { 'RETURN', 16#00, true, true, true, 2, [], return, {}, any, "Return from function call, top of stack is return value . The type of the retun value has to match the return type of the function."} , { 'RETURNR', 16#01, true, true, true, 2, [a], returnr, {any}, any, "Push Arg0 and return from function. The type of the retun value has to match the return type of the function."} , { 'CALL', 16#02, true, true, true, 4, [a], call, {string}, any, "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, true, false, true, 8, [a,is,ii,a], call_r, {contract, string, integer, integer}, any, "Remote call to contract Arg0 and Arg2-ary function Arg1 with value Arg3. The types of the arguments has to match the argument typs of the function."} + , { 'CALL_R', 16#03, true, false, true, 8, [a,is,a,a,a], call_r, {contract, string, typerep, typerep, integer}, any, "Remote call to contract Arg0 and function Arg1 of type Arg2 => Arg3 with value Arg4. The types of the arguments has to match the argument typs of the function."} , { 'CALL_T', 16#04, true, true, true, 4, [a], call_t, {string}, any, "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."} , { 'UNUSED_1', 16#05, false, false, true, 8, [], unused_1, {}, none, "Was CALL_TR."} - , { 'CALL_GR', 16#06, true, false, true, 8, [a,is,ii,a,a], call_gr, {contract, string, integer, integer, integer}, any, "Remote call with gas cap in Arg3. Otherwise as CALL_R."} + , { 'CALL_GR', 16#06, true, false, true, 8, [a,is,a,a,a,a], call_gr, {contract, string, typerep, typerep, integer, integer}, any, "Remote call with gas cap in Arg4. Otherwise as CALL_R."} , { 'UNUSED_2', 16#07, false, false, true, 8, [], unused_2, {}, none, "Was CALL_GTR."} , { 'JUMP', 16#08, true, true, true, 3, [ii], jump, {integer}, none, "Jump to a basic block. The basic block has to exist in the current function."} , { 'JUMPIF', 16#09, true, true, true, 4, [a,ii], jumpif, {boolean, integer}, none, "Conditional jump to a basic block. If Arg0 then jump to Arg1."} @@ -489,28 +489,32 @@ gen_asm_pp(Module, Path, Ops) -> file:close(File). gen_format(#{opname := Name}) when (Name =:= 'CALL_R') -> - io_lib:format("format_op({~w, {immediate, Contract}, {immediate, Function}, Arity, Value}, Symbols) ->\n" + io_lib:format("format_op({~w, {immediate, Contract}, {immediate, Function}, ArgType, RetType, Value}, Symbols) ->\n" " [\"~s \", lookup(Contract, Symbols), \".\", " "lookup(Function, Symbols), \" \", " - "format_arg(a, Arity), \" \", " + "format_arg(a, ArgType), \" \", " + "format_arg(a, RetType), \" \", " "format_arg(a, Value)];\n" - "format_op({~w, Contract, {immediate, Function}, Arity, Value}, Symbols) ->\n" + "format_op({~w, Contract, {immediate, Function}, ArgType, RetType, Value}, Symbols) ->\n" "[\"~s \", format_arg(a, Contract), \".\", " "lookup(Function, Symbols), \" \", " - "format_arg(a, Arity), \" \", " + "format_arg(a, ArgType), \" \", " + "format_arg(a, RetType), \" \", " "format_arg(a, Value)];\n", [Name, atom_to_list(Name), Name, atom_to_list(Name)]); gen_format(#{opname := Name}) when (Name =:= 'CALL_GR') -> - io_lib:format("format_op({~w, {immediate, Contract}, {immediate, Function}, Arity, Value, Gas}, Symbols) ->\n" + io_lib:format("format_op({~w, {immediate, Contract}, {immediate, Function}, ArgType, RetType, Value, Gas}, Symbols) ->\n" " [\"~s \", lookup(Contract, Symbols), \".\", " "lookup(Function, Symbols), \" \", " - "format_arg(a, Arity), \" \", " + "format_arg(a, ArgType), \" \", " + "format_arg(a, RetType), \" \", " "format_arg(a, Value), \" \", " "format_arg(a, Gas)];\n" - "format_op({~w, Contract, {immediate, Function}, Arity, Value, Gas}, Symbols) ->\n" + "format_op({~w, Contract, {immediate, Function}, ArgType, RetType, Value, Gas}, Symbols) ->\n" "[\"~s \", format_arg(a, Contract), \".\", " "lookup(Function, Symbols), \" \", " - "format_arg(a, Arity), \" \", " + "format_arg(a, ArgType), \" \", " + "format_arg(a, RetType), \" \", " "format_arg(a, Value), \" \", " "format_arg(a, Gas)];\n", [Name, atom_to_list(Name), Name, atom_to_list(Name)]); diff --git a/test/asm_code/test.fate b/test/asm_code/test.fate index b80af70..a42e7de 100644 --- a/test/asm_code/test.fate +++ b/test/asm_code/test.fate @@ -28,11 +28,11 @@ FUNCTION tailcall(integer) -> integer INCA CALL_T "inc" -FUNCTION remote_call(integer) : integer - PUSH arg0 - CALL_R remote.add_five 1 0 - INCA - RETURN +;; FUNCTION remote_call(integer) : integer +;; PUSH arg0 +;; CALL_R remote.add_five {tuple, [integer]} integer 0 ;; typereps don't parse +;; INCA +;; RETURN ;; Test the code from the shell ;; _build/default/rel/aessembler/bin/aessembler console From 52781060b2d51b68fd73fc155bf7def86367c31d Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Tue, 13 Aug 2019 15:55:03 +0200 Subject: [PATCH 2/4] fix type spec --- src/aeb_fate_maps.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeb_fate_maps.erl b/src/aeb_fate_maps.erl index ed9e86a..c6b7b0b 100644 --- a/src/aeb_fate_maps.erl +++ b/src/aeb_fate_maps.erl @@ -134,7 +134,7 @@ write_cache(Key, Val, Map) -> %% -- Reference counting ----------------------------------------------------- --type refcount() :: #{id() => pos_integer()}. +-type refcount() :: #{id() => integer()}. -spec refcount_zero() -> refcount(). refcount_zero() -> #{}. From 834ab298d1ceafec8b41c85d02b1f2c03fa9145c Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Wed, 14 Aug 2019 09:27:51 +0200 Subject: [PATCH 3/4] typereps are values --- include/aeb_fate_data.hrl | 1 + src/aeb_fate_data.erl | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/include/aeb_fate_data.hrl b/include/aeb_fate_data.hrl index 8c07896..c6c6ae6 100644 --- a/include/aeb_fate_data.hrl +++ b/include/aeb_fate_data.hrl @@ -17,6 +17,7 @@ -define(FATE_VOID_T, void). -define(FATE_TUPLE_T, {tuple, tuple()}). -define(FATE_BITS_T, {bits, integer()}). +-define(FATE_TYPEREP_T, {typerep, fate_type_type()}). -define(IS_FATE_INTEGER(X), (is_integer(X))). -define(IS_FATE_LIST(X), (is_list(X))). diff --git a/src/aeb_fate_data.erl b/src/aeb_fate_data.erl index eb7b54b..10a314b 100644 --- a/src/aeb_fate_data.erl +++ b/src/aeb_fate_data.erl @@ -21,6 +21,7 @@ -type fate_variant() :: ?FATE_VARIANT_T. -type fate_tuple() :: ?FATE_TUPLE_T. -type fate_bits() :: ?FATE_BITS_T. +-type fate_typerep() :: ?FATE_TYPEREP_T. -type fate_type_type() :: integer | boolean @@ -54,7 +55,8 @@ | fate_channel() | fate_variant() | fate_map() - | fate_bits(). + | fate_bits() + | fate_typerep(). -export_type([fate_type/0 , fate_boolean/0 From 13211887a3c94f3896efb5b4e9bdfc17360e6472 Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Wed, 14 Aug 2019 09:32:23 +0200 Subject: [PATCH 4/4] Update src/aeb_fate_generate_ops.erl Co-Authored-By: Hans Svensson --- 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 6ec3444..b2ff954 100644 --- a/src/aeb_fate_generate_ops.erl +++ b/src/aeb_fate_generate_ops.erl @@ -46,7 +46,7 @@ ops_defs() -> [ { 'RETURN', 16#00, true, true, true, 2, [], return, {}, any, "Return from function call, top of stack is return value . The type of the retun value has to match the return type of the function."} , { 'RETURNR', 16#01, true, true, true, 2, [a], returnr, {any}, any, "Push Arg0 and return from function. The type of the retun value has to match the return type of the function."} , { 'CALL', 16#02, true, true, true, 4, [a], call, {string}, any, "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, true, false, true, 8, [a,is,a,a,a], call_r, {contract, string, typerep, typerep, integer}, any, "Remote call to contract Arg0 and function Arg1 of type Arg2 => Arg3 with value Arg4. The types of the arguments has to match the argument typs of the function."} + , { 'CALL_R', 16#03, true, false, true, 8, [a,is,a,a,a], call_r, {contract, string, typerep, typerep, integer}, any, "Remote call to contract Arg0 and function Arg1 of type Arg2 => Arg3 with value Arg4. The types of the arguments has to match the argument types of the function."} , { 'CALL_T', 16#04, true, true, true, 4, [a], call_t, {string}, any, "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."} , { 'UNUSED_1', 16#05, false, false, true, 8, [], unused_1, {}, none, "Was CALL_TR."} , { 'CALL_GR', 16#06, true, false, true, 8, [a,is,a,a,a,a], call_gr, {contract, string, typerep, typerep, integer, integer}, any, "Remote call with gas cap in Arg4. Otherwise as CALL_R."}