factor compile/aaci logic
Instead of removing `init` and changing the definition of what the AACI is, we can just remove it in the one case that needs `init` removed, which is load3.
This commit is contained in:
parent
1d1e735b16
commit
b8a31e994f
@ -427,10 +427,9 @@ call_params([{L, C} | T], A) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
clicked4(State,
|
clicked4(State,
|
||||||
#c{id = ConID, build = #{aci := ACI}, funs = {_, Funs}},
|
#c{id = ConID, build = #{aaci := AACI}, funs = {_, Funs}},
|
||||||
{Name, Type},
|
{Name, Type},
|
||||||
{PK, Nonce, TTL, GasP, Gas, Amt}) ->
|
{PK, Nonce, TTL, GasP, Gas, Amt}) ->
|
||||||
AACI = hz:prepare_aaci(ACI),
|
|
||||||
#f{args = ArgFields} = maps:get(Name, Funs),
|
#f{args = ArgFields} = maps:get(Name, Funs),
|
||||||
Args = lists:map(fun get_arg/1, ArgFields),
|
Args = lists:map(fun get_arg/1, ArgFields),
|
||||||
case hz:contract_call(PK, Nonce, Gas, GasP, Amt, TTL, AACI, ConID, Name, Args) of
|
case hz:contract_call(PK, Nonce, Gas, GasP, Amt, TTL, AACI, ConID, Name, Args) of
|
||||||
@ -596,17 +595,12 @@ deploy(State = #s{code = {Codebook, Pages}}) ->
|
|||||||
|
|
||||||
deploy2(State, Source) ->
|
deploy2(State, Source) ->
|
||||||
case compile(Source) of
|
case compile(Source) of
|
||||||
% Options = sophia_options(),
|
|
||||||
% case so_compiler:from_string(Source, Options) of
|
|
||||||
% TODO: Make hz accept either the aaci or the aci, preferring the aaci if present
|
% TODO: Make hz accept either the aaci or the aci, preferring the aaci if present
|
||||||
{ok, Build} ->
|
{ok, Build} ->
|
||||||
ACI = maps:get(aci, Build),
|
{aaci, ContractName, Funs, NS} = maps:get(aaci, Build),
|
||||||
RawAACI = {aaci, ContractName, Funs, NS} = hz:prepare_aaci(ACI),
|
|
||||||
{InitSpec, Callable} = maps:take("init", Funs),
|
|
||||||
AACI = setelement(3, RawAACI, Callable),
|
|
||||||
Complete = maps:put(aaci, AACI, Build),
|
|
||||||
ok = tell(info, "Deploying Contract: ~p", [ContractName]),
|
ok = tell(info, "Deploying Contract: ~p", [ContractName]),
|
||||||
deploy3(State, InitSpec, Complete, NS);
|
InitSpec = maps:get("init", Funs),
|
||||||
|
deploy3(State, InitSpec, Build, NS);
|
||||||
Other ->
|
Other ->
|
||||||
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
|
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
|
||||||
State
|
State
|
||||||
@ -835,10 +829,9 @@ open_hash2(State, Address) ->
|
|||||||
|
|
||||||
open_hash3(State, Address, Source) ->
|
open_hash3(State, Address, Source) ->
|
||||||
% TODO: Compile on load and verify the deployed hash for validity.
|
% TODO: Compile on load and verify the deployed hash for validity.
|
||||||
Options = sophia_options(),
|
case compile(Source) of
|
||||||
case so_compiler:from_string(Source, Options) of
|
{ok, Build} ->
|
||||||
{ok, Build = #{aci := ACI}} ->
|
{aaci, _, FunDefs, _} = maps:get(aaci, Build),
|
||||||
{aaci, _Name, FunDefs, _TypeDefs} = hz:prepare_aaci(ACI),
|
|
||||||
ok = tell(info, "Compilation Succeeded!~n~tp~n~n~tp", [Build, FunDefs]),
|
ok = tell(info, "Compilation Succeeded!~n~tp~n~n~tp", [Build, FunDefs]),
|
||||||
add_code_page(State, {hash, Address}, Source);
|
add_code_page(State, {hash, Address}, Source);
|
||||||
Other ->
|
Other ->
|
||||||
@ -1114,15 +1107,12 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
|
|||||||
{Out, IFaces, Build, NewButtons} =
|
{Out, IFaces, Build, NewButtons} =
|
||||||
case compile(Source) of
|
case compile(Source) of
|
||||||
{ok, Output} ->
|
{ok, Output} ->
|
||||||
ACI = maps:get(aci, Output),
|
{aaci, _, Funs, NS} = maps:get(aaci, Output),
|
||||||
AACI = {aaci, ContractName, Funs, NS} = hz:prepare_aaci(ACI),
|
|
||||||
Complete = maps:put(aaci, AACI, Output),
|
|
||||||
ok = tell(info, "Loading Contract: ~p", [ContractName]),
|
|
||||||
Callable = maps:remove("init", Funs),
|
Callable = maps:remove("init", Funs),
|
||||||
tell(info, "Callable: ~p", [Callable]),
|
tell(info, "Callable: ~p", [Callable]),
|
||||||
{NB, IFs} = fun_interfaces(ScrollWin, FunSz, Buttons, Callable, NS, J),
|
{NB, IFs} = fun_interfaces(ScrollWin, FunSz, Buttons, Callable, NS, J),
|
||||||
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Complete]),
|
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Output]),
|
||||||
{O, IFs, Complete, NB};
|
{O, IFs, Output, NB};
|
||||||
Other ->
|
Other ->
|
||||||
O = io_lib:format("Compilation Failed!~n~tp~n", [Other]),
|
O = io_lib:format("Compilation Failed!~n~tp~n", [Other]),
|
||||||
{O, [], none, Buttons}
|
{O, [], none, Buttons}
|
||||||
@ -1157,21 +1147,6 @@ get_arg({_, TextCtrl}) ->
|
|||||||
get_record([{L, A} | T]) ->
|
get_record([{L, A} | T]) ->
|
||||||
[{L, get_arg(A)} | get_record(T)].
|
[{L, get_arg(A)} | get_record(T)].
|
||||||
|
|
||||||
find_main(ACI) ->
|
|
||||||
find_main(ACI, none, []).
|
|
||||||
|
|
||||||
find_main([#{contract := I = #{kind := contract_interface}} | T], M, Is) ->
|
|
||||||
find_main(T, M, [I | Is]);
|
|
||||||
find_main([#{contract := M = #{kind := contract_main}} | T], _, Is) ->
|
|
||||||
find_main(T, M, Is);
|
|
||||||
find_main([#{namespace := _} | T], M, Is) ->
|
|
||||||
find_main(T, M, Is);
|
|
||||||
find_main([C | T], M, Is) ->
|
|
||||||
ok = tell("Surprising ACI element: ~p", [C]),
|
|
||||||
find_main(T, M, Is);
|
|
||||||
find_main([], M, Is) ->
|
|
||||||
{M, Is}.
|
|
||||||
|
|
||||||
fun_interfaces(ScrollWin, FunSz, Buttons, Funs, NS, J) ->
|
fun_interfaces(ScrollWin, FunSz, Buttons, Funs, NS, J) ->
|
||||||
MakeIface =
|
MakeIface =
|
||||||
fun(Name, {Args, _}) ->
|
fun(Name, {Args, _}) ->
|
||||||
@ -1203,6 +1178,9 @@ fun_interfaces(ScrollWin, FunSz, Buttons, Funs, NS, J) ->
|
|||||||
% "variant" types should be wxChoice
|
% "variant" types should be wxChoice
|
||||||
% Booleans should either be wxChoice or check boxes
|
% Booleans should either be wxChoice or check boxes
|
||||||
% The sizer expansion direction for vertical elements is stupid
|
% The sizer expansion direction for vertical elements is stupid
|
||||||
|
% FIXME: We probably don't need the opaque type definitions 'NS', since the
|
||||||
|
% AACI already caches the useful expansions that might be needed for error
|
||||||
|
% messages.
|
||||||
make_arg_fields(ScrollWin, GridSz, Args, NS, J) ->
|
make_arg_fields(ScrollWin, GridSz, Args, NS, J) ->
|
||||||
MakeArgField =
|
MakeArgField =
|
||||||
fun
|
fun
|
||||||
@ -1332,7 +1310,16 @@ list_iface_buttons(#f{call = #w{id = CID}, dryrun = #w{id = DID}}, A) ->
|
|||||||
|
|
||||||
compile(Source) ->
|
compile(Source) ->
|
||||||
Options = sophia_options(),
|
Options = sophia_options(),
|
||||||
so_compiler:from_string(Source, Options).
|
case so_compiler:from_string(Source, Options) of
|
||||||
|
{ok, Build} ->
|
||||||
|
ACI = maps:get(aci, Build),
|
||||||
|
AACI = hz:prepare_aaci(ACI),
|
||||||
|
Complete = maps:put(aaci, AACI, Build),
|
||||||
|
{ok, Complete};
|
||||||
|
Other ->
|
||||||
|
Other
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
sophia_options() ->
|
sophia_options() ->
|
||||||
[{aci, json}].
|
[{aci, json}].
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user