Merge pull request #117 from aeternity/PT-167701356-split-store
PT-167701356 split store
This commit is contained in:
commit
74933b0616
@ -156,7 +156,7 @@ bind_tvars(Xs, Env) ->
|
|||||||
check_tvar(#env{ typevars = TVars}, T = {tvar, _, X}) ->
|
check_tvar(#env{ typevars = TVars}, T = {tvar, _, X}) ->
|
||||||
case TVars == unrestricted orelse lists:member(X, TVars) of
|
case TVars == unrestricted orelse lists:member(X, TVars) of
|
||||||
true -> ok;
|
true -> ok;
|
||||||
false -> type_error({unbound_type_variable, T})
|
false -> type_error({unbound_type, T})
|
||||||
end,
|
end,
|
||||||
T.
|
T.
|
||||||
|
|
||||||
@ -2160,6 +2160,8 @@ pp_error({contract_has_no_entrypoints, Con}) ->
|
|||||||
io_lib:format("The contract ~s (at ~s) has no entrypoints. Since Sophia version 3.2, public\n"
|
io_lib:format("The contract ~s (at ~s) has no entrypoints. Since Sophia version 3.2, public\n"
|
||||||
"contract functions must be declared with the 'entrypoint' keyword instead of\n"
|
"contract functions must be declared with the 'entrypoint' keyword instead of\n"
|
||||||
"'function'.\n", [pp_expr("", Con), pp_loc(Con)]);
|
"'function'.\n", [pp_expr("", Con), pp_loc(Con)]);
|
||||||
|
pp_error({unbound_type, Type}) ->
|
||||||
|
io_lib:format("Unbound type ~s (at ~s).\n", [pp_type("", Type), pp_loc(Type)]);
|
||||||
pp_error(Err) ->
|
pp_error(Err) ->
|
||||||
io_lib:format("Unknown error: ~p\n", [Err]).
|
io_lib:format("Unknown error: ~p\n", [Err]).
|
||||||
|
|
||||||
|
@ -239,7 +239,8 @@ to_fcode(Env, [{contract, _, {con, _, Main}, Decls}]) ->
|
|||||||
#{ contract_name => Main,
|
#{ contract_name => Main,
|
||||||
state_type => StateType,
|
state_type => StateType,
|
||||||
event_type => EventType,
|
event_type => EventType,
|
||||||
functions => add_event_function(Env1, EventType, Funs) };
|
functions => add_init_function(Env1,
|
||||||
|
add_event_function(Env1, EventType, Funs)) };
|
||||||
to_fcode(Env, [{contract, _, {con, _, Con}, Decls} | Code]) ->
|
to_fcode(Env, [{contract, _, {con, _, Con}, Decls} | Code]) ->
|
||||||
Env1 = decls_to_fcode(Env#{ context => {abstract_contract, Con} }, Decls),
|
Env1 = decls_to_fcode(Env#{ context => {abstract_contract, Con} }, Decls),
|
||||||
to_fcode(Env1, Code);
|
to_fcode(Env1, Code);
|
||||||
@ -824,6 +825,19 @@ builtin_to_fcode(Builtin, Args) ->
|
|||||||
false -> {builtin, Builtin, Args}
|
false -> {builtin, Builtin, Args}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
%% -- Init function --
|
||||||
|
|
||||||
|
add_init_function(_Env, Funs) ->
|
||||||
|
InitName = {entrypoint, <<"init">>},
|
||||||
|
InitFun = #{ args := InitArgs } =
|
||||||
|
case maps:get(InitName, Funs, none) of
|
||||||
|
none -> #{ attrs => [], args => [], return => {tuple, []}, body => {tuple, []} };
|
||||||
|
Info -> Info
|
||||||
|
end,
|
||||||
|
Vars = [ {var, X} || {X, _} <- InitArgs ],
|
||||||
|
Funs#{ init => InitFun#{ return => {tuple, []},
|
||||||
|
body => {builtin, set_state, [{def, InitName, Vars}]} } }.
|
||||||
|
|
||||||
%% -- Event function --
|
%% -- Event function --
|
||||||
|
|
||||||
add_event_function(_Env, none, Funs) -> Funs;
|
add_event_function(_Env, none, Funs) -> Funs;
|
||||||
@ -1016,8 +1030,7 @@ make_fun_name(#{ context := Context }, Ann, Name) ->
|
|||||||
Entrypoint = proplists:get_value(entrypoint, Ann, false),
|
Entrypoint = proplists:get_value(entrypoint, Ann, false),
|
||||||
case Context of
|
case Context of
|
||||||
{main_contract, Main} ->
|
{main_contract, Main} ->
|
||||||
if Name == "init" -> init;
|
if Entrypoint -> {entrypoint, list_to_binary(Name)};
|
||||||
Entrypoint -> {entrypoint, list_to_binary(Name)};
|
|
||||||
true -> {local_fun, [Main, Name]}
|
true -> {local_fun, [Main, Name]}
|
||||||
end;
|
end;
|
||||||
{namespace, Lib} ->
|
{namespace, Lib} ->
|
||||||
@ -1295,7 +1308,7 @@ pp_fun(Name, #{ args := Args, return := Return, body := Body }) ->
|
|||||||
pp_text(" : "), pp_ftype(Return), pp_text(" =")]),
|
pp_text(" : "), pp_ftype(Return), pp_text(" =")]),
|
||||||
prettypr:nest(2, pp_fexpr(Body))).
|
prettypr:nest(2, pp_fexpr(Body))).
|
||||||
|
|
||||||
pp_fun_name(init) -> pp_text(init);
|
pp_fun_name(init) -> pp_text('INIT');
|
||||||
pp_fun_name(event) -> pp_text(event);
|
pp_fun_name(event) -> pp_text(event);
|
||||||
pp_fun_name({entrypoint, E}) -> pp_text(binary_to_list(E));
|
pp_fun_name({entrypoint, E}) -> pp_text(binary_to_list(E));
|
||||||
pp_fun_name({local_fun, Q}) -> pp_text(string:join(Q, ".")).
|
pp_fun_name({local_fun, Q}) -> pp_text(string:join(Q, ".")).
|
||||||
|
@ -139,7 +139,7 @@ compile(FCode, Options) ->
|
|||||||
make_function_id(X) ->
|
make_function_id(X) ->
|
||||||
aeb_fate_code:symbol_identifier(make_function_name(X)).
|
aeb_fate_code:symbol_identifier(make_function_name(X)).
|
||||||
|
|
||||||
make_function_name(init) -> <<"init">>;
|
make_function_name(init) -> <<"INIT">>;
|
||||||
make_function_name(event) -> <<"Chain.event">>;
|
make_function_name(event) -> <<"Chain.event">>;
|
||||||
make_function_name({entrypoint, Name}) -> Name;
|
make_function_name({entrypoint, Name}) -> Name;
|
||||||
make_function_name({local_fun, Xs}) -> list_to_binary("." ++ string:join(Xs, ".")).
|
make_function_name({local_fun, Xs}) -> list_to_binary("." ++ string:join(Xs, ".")).
|
||||||
@ -196,7 +196,7 @@ add_default_init_function(SFuns, StateType) when StateType /= {tuple, []} ->
|
|||||||
SFuns;
|
SFuns;
|
||||||
add_default_init_function(SFuns, {tuple, []}) ->
|
add_default_init_function(SFuns, {tuple, []}) ->
|
||||||
%% Only add default if the init function is not present
|
%% Only add default if the init function is not present
|
||||||
InitName = make_function_name(init),
|
InitName = make_function_name({entrypoint, <<"init">>}),
|
||||||
case maps:find(InitName, SFuns) of
|
case maps:find(InitName, SFuns) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
SFuns;
|
SFuns;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user