From 4f9d4e5c073cbb644645e022576f5100c36adf0d Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Thu, 20 Jun 2019 12:11:43 +0200 Subject: [PATCH] Update compiler for bytes --- src/aeso_ast_to_fcode.erl | 17 +++++------------ src/aeso_fcode_to_fate.erl | 6 ++---- src/aeso_vm_decode.erl | 4 +--- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index 26b4c1d..7c760a4 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -37,8 +37,7 @@ -type flit() :: {int, integer()} | {string, binary()} - | {hash, binary()} - | {signature, binary()} + | {bytes, binary()} | {account_pubkey, binary()} | {contract_pubkey, binary()} | {oracle_pubkey, binary()} @@ -90,8 +89,7 @@ | {map, ftype(), ftype()} | {tuple, [ftype()]} | address - | hash - | signature + | {bytes, non_neg_integer()} | contract | {oracle, ftype(), ftype()} %% Query type, Response type | oracle_query @@ -320,10 +318,8 @@ type_to_fcode(Env, Sub, {tuple_t, _, Types}) -> type_to_fcode(Env, Sub, {record_t, Fields}) -> FieldType = fun({field_t, _, _, Ty}) -> Ty end, type_to_fcode(Env, Sub, {tuple_t, [], lists:map(FieldType, Fields)}); -type_to_fcode(_Env, _Sub, {bytes_t, _, 32}) -> hash; -type_to_fcode(_Env, _Sub, {bytes_t, _, 64}) -> signature; -type_to_fcode(_Env, _Sub, {bytes_t, _, _N}) -> - string; %% TODO: add bytes type to FATE +type_to_fcode(_Env, _Sub, {bytes_t, _, N}) -> + {bytes, N}; type_to_fcode(_Env, Sub, {tvar, _, X}) -> maps:get(X, Sub, {tvar, X}); type_to_fcode(Env, Sub, {fun_t, _, Named, Args, Res}) -> @@ -367,10 +363,7 @@ expr_to_fcode(_Env, _Type, {account_pubkey, _, K}) -> {lit, {account_pubkey, K} expr_to_fcode(_Env, _Type, {contract_pubkey, _, K}) -> {lit, {contract_pubkey, K}}; expr_to_fcode(_Env, _Type, {oracle_pubkey, _, K}) -> {lit, {oracle_pubkey, K}}; expr_to_fcode(_Env, _Type, {oracle_query_id, _, K}) -> {lit, {oracle_query_id, K}}; - -expr_to_fcode(_Env, _Type, {bytes, _, Bin = <<_:32/binary>>}) -> {lit, {hash, Bin}}; -expr_to_fcode(_Env, _Type, {bytes, _, Bin = <<_:64/binary>>}) -> {lit, {signature, Bin}}; -expr_to_fcode(_Env, _Type, {bytes, _, Bin}) -> {lit, {string, Bin}}; +expr_to_fcode(_Env, _Type, {bytes, _, B}) -> {lit, {bytes, B}}; %% Variables expr_to_fcode(Env, _Type, {id, _, X}) -> resolve_var(Env, [X]); diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 5441ae3..679481c 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -161,8 +161,7 @@ type_to_scode(integer) -> integer; type_to_scode(boolean) -> boolean; type_to_scode(string) -> string; type_to_scode(address) -> address; -type_to_scode(hash) -> hash; -type_to_scode(signature) -> signature; +type_to_scode({bytes, N}) -> {bytes, N}; type_to_scode(contract) -> contract; type_to_scode({oracle, _, _}) -> oracle; type_to_scode(oracle_query) -> oracle_query; @@ -236,8 +235,7 @@ lit_to_fate(L) -> case L of {int, N} -> aeb_fate_data:make_integer(N); {string, S} -> aeb_fate_data:make_string(S); - {hash, H} -> aeb_fate_data:make_hash(H); - {signature, S} -> aeb_fate_data:make_signature(S); + {bytes, B} -> aeb_fate_data:make_bytes(B); {bool, B} -> aeb_fate_data:make_boolean(B); {account_pubkey, K} -> aeb_fate_data:make_address(K); {contract_pubkey, K} -> aeb_fate_data:make_contract(K); diff --git a/src/aeso_vm_decode.erl b/src/aeso_vm_decode.erl index edc79f1..bf61a48 100644 --- a/src/aeso_vm_decode.erl +++ b/src/aeso_vm_decode.erl @@ -69,9 +69,7 @@ from_fate({id, _, "address"}, ?FATE_ADDRESS(Bin)) -> {account_pubkey, [], Bin}; from_fate({app_t, _, {id, _, "oracle"}, _}, ?FATE_ORACLE(Bin)) -> {oracle_pubkey, [], Bin}; from_fate({app_t, _, {id, _, "oracle_query"}, _}, ?FATE_ORACLE_Q(Bin)) -> {oracle_query_id, [], Bin}; from_fate({con, _, _Name}, ?FATE_CONTRACT(Bin)) -> {contract_pubkey, [], Bin}; -from_fate({bytes_t, _, 32}, ?FATE_HASH(Bin)) -> {bytes, [], Bin}; -from_fate({bytes_t, _, 64}, ?FATE_SIGNATURE(Bin)) -> {bytes, [], Bin}; -from_fate({bytes_t, _, N}, Bin) when size(Bin) == N -> {bytes, [], Bin}; +from_fate({bytes_t, _, N}, ?FATE_BYTES(Bin)) when byte_size(Bin) == N -> {bytes, [], Bin}; from_fate({id, _, "bits"}, ?FATE_BITS(Bin)) -> error({todo, bits, Bin}); from_fate({id, _, "int"}, N) when is_integer(N) -> {int, [], N}; from_fate({id, _, "bool"}, B) when is_boolean(B) -> {bool, [], B};