From bb4ef61a5082d0d2d94f4de1b278fe6d36bfcf82 Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Mon, 3 Jun 2019 09:08:53 +0200 Subject: [PATCH] Allow negative literals in calldata and result --- src/aeso_compiler.erl | 3 ++- test/aeso_abi_tests.erl | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index 48da520..18f6bb3 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -276,7 +276,7 @@ translate_vm_value(word, {id, _, "address"}, N) -> address_l translate_vm_value(word, {app_t, _, {id, _, "oracle"}, _}, N) -> address_literal(oracle_pubkey, N); translate_vm_value(word, {app_t, _, {id, _, "oracle_query"}, _}, N) -> address_literal(oracle_query_id, N); translate_vm_value(word, {con, _, _Name}, N) -> address_literal(contract_pubkey, N); -translate_vm_value(word, {id, _, "int"}, N) -> {int, [], N}; +translate_vm_value(word, {id, _, "int"}, N) -> <> = <>, {int, [], N1}; translate_vm_value(word, {id, _, "bits"}, N) -> error({todo, bits, N}); translate_vm_value(word, {id, _, "bool"}, N) -> {bool, [], N /= 0}; translate_vm_value(word, {bytes_t, _, Len}, Val) when Len =< 32 -> @@ -412,6 +412,7 @@ get_decode_type(FunName, [_ | Contracts]) -> %% Translate an icode value (error if not value) to an Erlang term that can be %% consumed by aeb_heap:to_binary(). icode_to_term(word, {integer, N}) -> N; +icode_to_term(word, {unop, '-', {integer, N}}) -> -N; icode_to_term(string, {tuple, [{integer, Len} | Words]}) -> <> = << <> || {integer, W} <- Words >>, Str; diff --git a/test/aeso_abi_tests.erl b/test/aeso_abi_tests.erl index d586042..a38a478 100644 --- a/test/aeso_abi_tests.erl +++ b/test/aeso_abi_tests.erl @@ -62,6 +62,7 @@ encode_decode_sophia_test() -> Other -> Other end end, ok = Check("int", "42"), + ok = Check("int", "-42"), ok = Check("bool", "true"), ok = Check("bool", "false"), ok = Check("string", "\"Hello\""),