Skip to content

Commit

Permalink
Merge pull request #2679 from aeternity/fate-compiler-optimizations
Browse files Browse the repository at this point in the history
Allow writing to FATE function argument
  • Loading branch information
UlfNorell committed Aug 22, 2019
2 parents 40f495a + 3e80dad commit 7b852bc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 1 addition & 3 deletions apps/aefate/src/aefa_fate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

%% Memory handling.
-export([ lookup_var/2
, store_var/3]).
, store_var/3 ]).

%% Stack handling.
-export([ dup/1
Expand Down Expand Up @@ -203,8 +203,6 @@ abort(bad_store_map_id, ES) ->
?t("Maps: Map does not exist", [], ES);
abort({type_error, cons}, ES) ->
?t("Type error in cons: creating polymorphic list", [], ES);
abort({cannot_write_to_arg, N}, ES) ->
?t("Arguments are read only: ~p", [N], ES);
abort({undefined_var, Var}, ES) ->
?t("Undefined var: ~p", [Var], ES);
abort({bad_return_type, Val, Type}, ES) ->
Expand Down
4 changes: 2 additions & 2 deletions apps/aefate/src/aefa_fate_op.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1405,8 +1405,8 @@ write({stack, 0}, Val, ES) ->
aefa_engine_state:push_accumulator(Val, ES);
write({var, _} = Name, Val, ES) ->
aefa_fate:store_var(Name, Val, ES);
write({arg, N}, _, ES) ->
aefa_fate:abort({cannot_write_to_arg, N}, ES).
write({arg, _} = Arg, Val, ES) ->
aefa_fate:store_var(Arg, Val, ES).


%% ------------------------------------------------------
Expand Down
10 changes: 6 additions & 4 deletions apps/aefate/test/aefa_sophia_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,14 @@ compile_contract(Code, Options) ->
{error, {type_errors, Err}}
end.

-define(CALL_GAS, 1000000).

make_call_spec(Contract, Function0, Arguments) ->
Function = aeb_fate_code:symbol_identifier(Function0),
EncArgs = list_to_tuple([aefate_test_utils:encode(A) || A <- Arguments]),
Calldata = {tuple, {Function, {tuple, EncArgs}}},
#{ contract => pad_contract_name(Contract),
gas => 1000000,
gas => ?CALL_GAS,
value => 0,
call => aeb_fate_encoding:serialize(Calldata),
store => aect_contracts_store:new() }.
Expand All @@ -104,11 +105,12 @@ run_call(Code, Fun, Args) ->
Cache = compile_contracts([{<<"test">>, Code}]),
case run(Cache, <<"test">>, list_to_binary(Fun), Args) of
{ok, ES} ->
Trace = aefa_engine_state:trace(ES),
Red = fun({_, {reductions, R}}) -> R end,
GasUsed = ?CALL_GAS - aefa_engine_state:gas(ES),
Trace = aefa_engine_state:trace(ES),
Red = fun({_, {reductions, R}}) -> R end,
Reductions = Red(hd(Trace)) - Red(lists:last(Trace)),
Steps = length(Trace),
io:format("~p steps (~p reductions)\n", [Steps, Reductions]),
io:format("~p steps / ~p gas / ~p reductions\n", [Steps, GasUsed, Reductions]),
aefa_engine_state:accumulator(ES);
{error, Err, ES} ->
io:format("~s\n", [Err]),
Expand Down
2 changes: 1 addition & 1 deletion apps/aevm/src/aevm_ae_primops.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ types(?PRIM_CALL_AENS_CLAIM,_HeapValue,_Store,_State) ->
{[word, string, word, sign_t()], tuple0_t()};
types(?PRIM_CALL_AENS_PRECLAIM,_HeapValue,_Store,_State) ->
{[word, word, sign_t()], tuple0_t()};
types(?PRIM_CALL_AENS_RESOLVE, HeapValue, Store, State) ->
types(?PRIM_CALL_AENS_RESOLVE, HeapValue, _Store, State) ->
%% The out type is given in the third argument
T = {tuple, [word, word, word, typerep]},
{ok, Bin} = aevm_eeevm_state:heap_value_to_binary(T, HeapValue, State),
Expand Down

0 comments on commit 7b852bc

Please sign in to comment.