Report saved fresh names as part of fcode env
This commit is contained in:
parent
f8f67ced47
commit
4715894471
@ -127,8 +127,7 @@
|
|||||||
state_layout := state_layout(),
|
state_layout := state_layout(),
|
||||||
event_type := ftype() | none,
|
event_type := ftype() | none,
|
||||||
functions := #{ fun_name() => fun_def() },
|
functions := #{ fun_name() => fun_def() },
|
||||||
payable := boolean(),
|
payable := boolean() }.
|
||||||
saved_fresh_names := #{ var_name() => var_name() } }.
|
|
||||||
|
|
||||||
-type type_def() :: fun(([ftype()]) -> ftype()).
|
-type type_def() :: fun(([ftype()]) -> ftype()).
|
||||||
|
|
||||||
@ -160,7 +159,8 @@
|
|||||||
state_layout => state_layout(),
|
state_layout => state_layout(),
|
||||||
context => context(),
|
context => context(),
|
||||||
vars => [var_name()],
|
vars => [var_name()],
|
||||||
functions := #{ fun_name() => fun_def() }
|
functions := #{ fun_name() => fun_def() },
|
||||||
|
saved_fresh_names := #{ var_name() => var_name() }
|
||||||
}.
|
}.
|
||||||
|
|
||||||
-define(HASH_BYTES, 32).
|
-define(HASH_BYTES, 32).
|
||||||
@ -180,10 +180,10 @@ ast_to_fcode(Code, Options) ->
|
|||||||
fun (_, FC) -> optimize(FC, Options) end,
|
fun (_, FC) -> optimize(FC, Options) end,
|
||||||
maps:get(child_con_env, Env1)
|
maps:get(child_con_env, Env1)
|
||||||
)},
|
)},
|
||||||
FCode3 = FCode2#{saved_fresh_names => get(saved_fresh_names)},
|
Env3 = Env2#{ saved_fresh_names => get(saved_fresh_names) },
|
||||||
clear_fresh_names(),
|
clear_fresh_names(),
|
||||||
clear_saved_fresh_names(),
|
clear_saved_fresh_names(),
|
||||||
{Env2, FCode3}.
|
{Env3, FCode2}.
|
||||||
|
|
||||||
optimize(FCode1, Options) ->
|
optimize(FCode1, Options) ->
|
||||||
Verbose = lists:member(pp_fcode, Options),
|
Verbose = lists:member(pp_fcode, Options),
|
||||||
@ -1748,7 +1748,7 @@ clear_saved_fresh_names() ->
|
|||||||
fresh_name_save(Name) ->
|
fresh_name_save(Name) ->
|
||||||
Fresh = fresh_name(),
|
Fresh = fresh_name(),
|
||||||
Old = get(saved_fresh_names),
|
Old = get(saved_fresh_names),
|
||||||
New = put(saved_fresh_names, Old#{Fresh => Name}),
|
put(saved_fresh_names, Old#{Fresh => Name}),
|
||||||
Fresh.
|
Fresh.
|
||||||
|
|
||||||
-spec fresh_name() -> var_name().
|
-spec fresh_name() -> var_name().
|
||||||
|
@ -112,10 +112,10 @@ from_string(ContractString, Options) ->
|
|||||||
|
|
||||||
from_string1(ContractString, Options) ->
|
from_string1(ContractString, Options) ->
|
||||||
#{ fcode := FCode
|
#{ fcode := FCode
|
||||||
, fcode_env := #{child_con_env := ChildContracts}
|
, fcode_env := #{child_con_env := ChildContracts, saved_fresh_names := SavedFreshNames}
|
||||||
, folded_typed_ast := FoldedTypedAst
|
, folded_typed_ast := FoldedTypedAst
|
||||||
, warnings := Warnings } = string_to_code(ContractString, Options),
|
, warnings := Warnings } = string_to_code(ContractString, Options),
|
||||||
{FateCode, VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, FCode, Options),
|
{FateCode, VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options),
|
||||||
pp_assembler(FateCode, Options),
|
pp_assembler(FateCode, Options),
|
||||||
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
||||||
{ok, Version} = version(),
|
{ok, Version} = version(),
|
||||||
@ -184,9 +184,9 @@ check_call1(ContractString0, FunName, Args, Options) ->
|
|||||||
try
|
try
|
||||||
%% First check the contract without the __call function
|
%% First check the contract without the __call function
|
||||||
#{fcode := OrgFcode
|
#{fcode := OrgFcode
|
||||||
, fcode_env := #{child_con_env := ChildContracts}
|
, fcode_env := #{child_con_env := ChildContracts, saved_fresh_names := SavedFreshNames}
|
||||||
, ast := Ast} = string_to_code(ContractString0, Options),
|
, ast := Ast} = string_to_code(ContractString0, Options),
|
||||||
{FateCode, _VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, []),
|
{FateCode, _VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, OrgFcode, SavedFreshNames, []),
|
||||||
%% collect all hashes and compute the first name without hash collision to
|
%% collect all hashes and compute the first name without hash collision to
|
||||||
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
SymbolHashes = maps:keys(aeb_fate_code:symbols(FateCode)),
|
||||||
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
CallName = first_none_match(?CALL_NAME, SymbolHashes,
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(aeso_fcode_to_fate).
|
-module(aeso_fcode_to_fate).
|
||||||
|
|
||||||
-export([compile/2, compile/3, term_to_fate/1, term_to_fate/2]).
|
-export([compile/3, compile/4, term_to_fate/1, term_to_fate/2]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-export([optimize_fun/4, to_basic_blocks/1]).
|
-export([optimize_fun/4, to_basic_blocks/1]).
|
||||||
@ -78,13 +78,18 @@ code_error(Err) ->
|
|||||||
%% -- Main -------------------------------------------------------------------
|
%% -- Main -------------------------------------------------------------------
|
||||||
|
|
||||||
%% @doc Main entry point.
|
%% @doc Main entry point.
|
||||||
compile(FCode, Options) ->
|
compile(FCode, SavedFreshNames, Options) ->
|
||||||
compile(#{}, FCode, Options).
|
compile(#{}, FCode, SavedFreshNames, Options).
|
||||||
compile(ChildContracts, FCode, Options) ->
|
compile(ChildContracts, FCode, SavedFreshNames, Options) ->
|
||||||
#{ contract_name := ContractName,
|
|
||||||
functions := Functions,
|
|
||||||
saved_fresh_names := SavedFreshNames } = FCode,
|
|
||||||
try
|
try
|
||||||
|
compile1(ChildContracts, FCode, SavedFreshNames, Options)
|
||||||
|
after
|
||||||
|
put(variables_registers, undefined)
|
||||||
|
end.
|
||||||
|
|
||||||
|
compile1(ChildContracts, FCode, SavedFreshNames, Options) ->
|
||||||
|
#{ contract_name := ContractName,
|
||||||
|
functions := Functions } = FCode,
|
||||||
SFuns = functions_to_scode(ChildContracts, ContractName, Functions, SavedFreshNames, Options),
|
SFuns = functions_to_scode(ChildContracts, ContractName, Functions, SavedFreshNames, Options),
|
||||||
SFuns1 = optimize_scode(SFuns, Options),
|
SFuns1 = optimize_scode(SFuns, Options),
|
||||||
FateCode = to_basic_blocks(SFuns1),
|
FateCode = to_basic_blocks(SFuns1),
|
||||||
@ -93,10 +98,7 @@ compile(ChildContracts, FCode, Options) ->
|
|||||||
false -> FateCode;
|
false -> FateCode;
|
||||||
true -> add_child_symbols(ChildContracts, FateCode)
|
true -> add_child_symbols(ChildContracts, FateCode)
|
||||||
end,
|
end,
|
||||||
{FateCode1, get_variables_registers()}
|
{FateCode1, get_variables_registers()}.
|
||||||
after
|
|
||||||
put(variables_registers, undefined)
|
|
||||||
end.
|
|
||||||
|
|
||||||
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)).
|
||||||
@ -222,8 +224,9 @@ serialize_contract_code(Env, C) ->
|
|||||||
case maps:get(C, Cache, none) of
|
case maps:get(C, Cache, none) of
|
||||||
none ->
|
none ->
|
||||||
Options = Env#env.options,
|
Options = Env#env.options,
|
||||||
|
SavedFreshNames = Env#env.saved_fresh_names,
|
||||||
FCode = maps:get(C, Env#env.child_contracts),
|
FCode = maps:get(C, Env#env.child_contracts),
|
||||||
{FateCode, _} = compile(Env#env.child_contracts, FCode, Options),
|
{FateCode, _} = compile1(Env#env.child_contracts, FCode, SavedFreshNames, Options),
|
||||||
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
||||||
{ok, Version} = aeso_compiler:version(),
|
{ok, Version} = aeso_compiler:version(),
|
||||||
OriginalSourceCode = proplists:get_value(original_src, Options, ""),
|
OriginalSourceCode = proplists:get_value(original_src, Options, ""),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user