From 3ea8470dc852b94a887b6f86a8e2814efebfd78e Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 9 Sep 2019 16:01:35 +0200 Subject: [PATCH] Compile Bytes.concat and split to FATE --- src/aeso_ast_to_fcode.erl | 5 ++++- src/aeso_fcode_to_fate.erl | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index d813348..e795594 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -198,7 +198,7 @@ builtins() -> {["String"], [{"length", 1}, {"concat", 2}, {"sha3", 1}, {"sha256", 1}, {"blake2b", 1}]}, {["Bits"], [{"set", 2}, {"clear", 2}, {"test", 2}, {"sum", 1}, {"intersection", 2}, {"union", 2}, {"difference", 2}, {"none", none}, {"all", none}]}, - {["Bytes"], [{"to_int", 1}, {"to_str", 1}]}, + {["Bytes"], [{"to_int", 1}, {"to_str", 1}, {"concat", 2}, {"split", 1}]}, {["Int"], [{"to_str", 1}]}, {["Address"], [{"to_str", 1}, {"is_oracle", 1}, {"is_contract", 1}, {"is_payable", 1}]} ], @@ -427,6 +427,9 @@ expr_to_fcode(Env, Type, {qid, Ann, X}) -> validate_aens_resolve_type(Ann, ResType, AensType), TypeArgs = [{lit, {typerep, AensType}}], {builtin_u, B, Ar, TypeArgs}; + {builtin_u, B = bytes_split, Ar} -> + {fun_t, _, _, _, {tuple_t, _, [{bytes_t, _, N}, _]}} = Type, + {builtin_u, B, Ar, [{lit, {int, N}}]}; Other -> Other end; diff --git a/src/aeso_fcode_to_fate.erl b/src/aeso_fcode_to_fate.erl index 9412c79..96a61b5 100644 --- a/src/aeso_fcode_to_fate.erl +++ b/src/aeso_fcode_to_fate.erl @@ -106,6 +106,8 @@ Op =:= 'AUTH_TX_HASH' orelse Op =:= 'BYTES_TO_INT' orelse Op =:= 'BYTES_TO_STR' orelse + Op =:= 'BYTES_CONCAT' orelse + Op =:= 'BYTES_SPLIT' orelse Op =:= 'ORACLE_CHECK' orelse Op =:= 'ORACLE_CHECK_QUERY' orelse Op =:= 'IS_ORACLE' orelse @@ -490,6 +492,10 @@ builtin_to_scode(Env, bytes_to_int, [_] = Args) -> call_to_scode(Env, aeb_fate_ops:bytes_to_int(?a, ?a), Args); builtin_to_scode(Env, bytes_to_str, [_] = Args) -> call_to_scode(Env, aeb_fate_ops:bytes_to_str(?a, ?a), Args); +builtin_to_scode(Env, bytes_concat, [_, _] = Args) -> + call_to_scode(Env, aeb_fate_ops:bytes_concat(?a, ?a, ?a), Args); +builtin_to_scode(Env, bytes_split, [_, _] = Args) -> + call_to_scode(Env, aeb_fate_ops:bytes_split(?a, ?a, ?a), Args); builtin_to_scode(Env, abort, [_] = Args) -> call_to_scode(Env, aeb_fate_ops:abort(?a), Args); builtin_to_scode(Env, chain_spend, [_, _] = Args) -> @@ -846,6 +852,8 @@ attributes(I) -> {'AUTH_TX_HASH', A} -> Pure(A, []); {'BYTES_TO_INT', A, B} -> Pure(A, [B]); {'BYTES_TO_STR', A, B} -> Pure(A, [B]); + {'BYTES_CONCAT', A, B, C} -> Pure(A, [B, C]); + {'BYTES_SPLIT', A, B, C} -> Pure(A, [B, C]); {'ORACLE_CHECK', A, B, C, D} -> Impure(A, [B, C, D]); {'ORACLE_CHECK_QUERY', A, B, C, D, E} -> Impure(A, [B, C, D, E]); {'IS_ORACLE', A, B} -> Impure(A, [B]);