Compare commits

..

2 Commits

Author SHA1 Message Date
Jarvis Carroll
b8a31e994f 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.
2025-08-22 22:57:12 +10:00
Jarvis Carroll
1d1e735b16 Remove some trace tells
d'oh
2025-08-22 19:59:47 +10:00

View File

@ -427,10 +427,9 @@ call_params([{L, C} | T], A) ->
end.
clicked4(State,
#c{id = ConID, build = #{aci := ACI}, funs = {_, Funs}},
#c{id = ConID, build = #{aaci := AACI}, funs = {_, Funs}},
{Name, Type},
{PK, Nonce, TTL, GasP, Gas, Amt}) ->
AACI = hz:prepare_aaci(ACI),
#f{args = ArgFields} = maps:get(Name, Funs),
Args = lists:map(fun get_arg/1, ArgFields),
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) ->
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
{ok, Build} ->
ACI = maps:get(aci, 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),
{aaci, ContractName, Funs, NS} = maps:get(aaci, Build),
ok = tell(info, "Deploying Contract: ~p", [ContractName]),
deploy3(State, InitSpec, Complete, NS);
InitSpec = maps:get("init", Funs),
deploy3(State, InitSpec, Build, NS);
Other ->
ok = tell(info, "Compilation Failed!~n~tp", [Other]),
State
@ -835,10 +829,9 @@ open_hash2(State, Address) ->
open_hash3(State, Address, Source) ->
% TODO: Compile on load and verify the deployed hash for validity.
Options = sophia_options(),
case so_compiler:from_string(Source, Options) of
{ok, Build = #{aci := ACI}} ->
{aaci, _Name, FunDefs, _TypeDefs} = hz:prepare_aaci(ACI),
case compile(Source) of
{ok, Build} ->
{aaci, _, FunDefs, _} = maps:get(aaci, Build),
ok = tell(info, "Compilation Succeeded!~n~tp~n~n~tp", [Build, FunDefs]),
add_code_page(State, {hash, Address}, Source);
Other ->
@ -1114,15 +1107,12 @@ load3(State = #s{tabs = TopBook, cons = {Consbook, Pages}, buttons = Buttons, j
{Out, IFaces, Build, NewButtons} =
case compile(Source) of
{ok, Output} ->
ACI = maps:get(aci, Output),
AACI = {aaci, ContractName, Funs, NS} = hz:prepare_aaci(ACI),
Complete = maps:put(aaci, AACI, Output),
ok = tell(info, "Loading Contract: ~p", [ContractName]),
{aaci, _, Funs, NS} = maps:get(aaci, Output),
Callable = maps:remove("init", Funs),
tell(info, "Callable: ~p", [Callable]),
{NB, IFs} = fun_interfaces(ScrollWin, FunSz, Buttons, Callable, NS, J),
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Complete]),
{O, IFs, Complete, NB};
O = io_lib:format("Compilation Succeeded!~n~tp~n~nDone!~n", [Output]),
{O, IFs, Output, NB};
Other ->
O = io_lib:format("Compilation Failed!~n~tp~n", [Other]),
{O, [], none, Buttons}
@ -1157,21 +1147,6 @@ get_arg({_, TextCtrl}) ->
get_record([{L, A} | 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) ->
MakeIface =
fun(Name, {Args, _}) ->
@ -1203,6 +1178,9 @@ fun_interfaces(ScrollWin, FunSz, Buttons, Funs, NS, J) ->
% "variant" types should be wxChoice
% Booleans should either be wxChoice or check boxes
% 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) ->
MakeArgField =
fun
@ -1273,7 +1251,6 @@ make_arg_fields(ScrollWin, GridSz, Args, NS, J) ->
lists:map(MakeArgField, Args).
make_unnamed_fields(ScrollWin, InnerSz, Elems, NS, J) ->
tell(info, "ta", []),
ChooseName =
fun
(Ann = {_, _, T}) when is_atom(T) ->
@ -1284,9 +1261,7 @@ make_unnamed_fields(ScrollWin, InnerSz, Elems, NS, J) ->
(Ann = {_, _, {T, _}}) when is_atom(T) ->
{atom_to_list(T), Ann}
end,
tell(info, "tb", []),
WithNames = lists:map(ChooseName, Elems),
tell(info, "tc", []),
make_arg_fields(ScrollWin, InnerSz, WithNames, NS, J).
fill() ->
@ -1335,7 +1310,16 @@ list_iface_buttons(#f{call = #w{id = CID}, dryrun = #w{id = DID}}, A) ->
compile(Source) ->
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() ->
[{aci, json}].