diff --git a/src/gd_v_devman.erl b/src/gd_v_devman.erl index 244efee..2f70e44 100644 --- a/src/gd_v_devman.erl +++ b/src/gd_v_devman.erl @@ -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 @@ -1332,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}].