Compiler side of state updates

No support in FATE yet though
This commit is contained in:
Ulf Norell 2019-05-06 14:58:48 +02:00
parent db48be1805
commit fac136bded
2 changed files with 11 additions and 1 deletions

View File

@ -211,8 +211,12 @@ init_type_env() ->
-spec to_fcode(env(), aeso_syntax:ast()) -> fcode(). -spec to_fcode(env(), aeso_syntax:ast()) -> fcode().
to_fcode(Env, [{contract, _, {con, _, Main}, Decls}]) -> to_fcode(Env, [{contract, _, {con, _, Main}, Decls}]) ->
#{ builtins := Builtins } = Env,
MainEnv = Env#{ context => {main_contract, Main},
builtins => Builtins#{[Main, "state"] => {get_state, none},
[Main, "put"] => {set_state, 1}} },
#{ functions := Funs } = Env1 = #{ functions := Funs } = Env1 =
decls_to_fcode(Env#{ context => {main_contract, Main} }, Decls), decls_to_fcode(MainEnv, Decls),
StateType = lookup_type(Env1, [Main, "state"], [], {tuple, []}), StateType = lookup_type(Env1, [Main, "state"], [], {tuple, []}),
EventType = lookup_type(Env1, [Main, "event"], [], none), EventType = lookup_type(Env1, [Main, "event"], [], none),
#{ contract_name => Main, #{ contract_name => Main,

View File

@ -38,6 +38,7 @@
-define(i(X), {immediate, X}). -define(i(X), {immediate, X}).
-define(a, {stack, 0}). -define(a, {stack, 0}).
-define(s, {var, -1}). %% TODO: until we have state support in FATE
-define(IsOp(Op), ( -define(IsOp(Op), (
Op =:= 'STORE' orelse Op =:= 'STORE' orelse
@ -372,6 +373,11 @@ call_to_scode(Env, CallCode, Args) ->
[[to_scode(notail(Env), A) || A <- lists:reverse(Args)], [[to_scode(notail(Env), A) || A <- lists:reverse(Args)],
CallCode]. CallCode].
builtin_to_scode(_Env, get_state, none) ->
[push(?s)];
builtin_to_scode(Env, set_state, [_] = Args) ->
call_to_scode(Env, [aeb_fate_code:store(?s, ?a),
aeb_fate_code:tuple(0)], Args);
builtin_to_scode(_Env, map_empty, none) -> builtin_to_scode(_Env, map_empty, none) ->
[aeb_fate_code:map_empty(?a)]; [aeb_fate_code:map_empty(?a)];
builtin_to_scode(_Env, bits_none, none) -> builtin_to_scode(_Env, bits_none, none) ->