Skip to content

Commit

Permalink
Merge pull request #2714 from aeternity/sophia-stdlib-overhaul
Browse files Browse the repository at this point in the history
Sophia stdlib overhaul
  • Loading branch information
UlfNorell committed Aug 28, 2019
2 parents 7fadf48 + 43c3ac5 commit 06b31e9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions apps/aecontract/test/aect_test_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ compile(Vsn, File) ->
compile_(?SOPHIA_LIMA_FATE, File) ->
{ok, AsmBin} = file:read_file(File),
Source = binary_to_list(AsmBin),
case aeso_compiler:from_string(Source, [{backend, fate}, no_implicit_stdlib]) of
case aeso_compiler:from_string(Source, [{backend, fate}]) of
{ok, Map} -> {ok, aect_sophia:serialize(Map, latest_sophia_contract_version())};
{error, E} = Err -> io:format("~s\n", [E]), Err
end;
compile_(SophiaVsn, File) when SophiaVsn == ?SOPHIA_LIMA_AEVM ->
{ok, ContractBin} = file:read_file(File),
case aeso_compiler:from_string(binary_to_list(ContractBin), [no_implicit_stdlib]) of
case aeso_compiler:from_string(binary_to_list(ContractBin), []) of
{ok, Map} -> {ok, aect_sophia:serialize(Map, latest_sophia_contract_version())};
{error, _} = Err -> Err
end;
Expand Down Expand Up @@ -412,7 +412,7 @@ encode_call_data(Vsn, Code, Fun, Args) ->
encode_call_data_(Vsn, Code, Fun, Args, Backend) when Vsn == ?SOPHIA_LIMA_AEVM; Vsn == ?SOPHIA_LIMA_FATE ->
try aeso_compiler:create_calldata(to_str(Code), to_str(Fun),
lists:map(fun to_str/1, Args),
[{backend, Backend}, no_implicit_stdlib])
[{backend, Backend}])
catch _T:_E ->
{error, <<"bad argument">>}
end;
Expand Down Expand Up @@ -459,7 +459,7 @@ decode_call_result(Backend, Code, Fun, Res, EValue = <<"cb_", _/binary>>) ->
end;
decode_call_result(Backend, Code, Fun, Res, Value) ->
{ok, ValExpr} = aeso_compiler:to_sophia_value(to_str(Code), to_str(Fun),
Res, Value, [{backend, Backend}, no_implicit_stdlib]),
Res, Value, [{backend, Backend}]),
aeso_aci:json_encode_expr(ValExpr).

decode_data(Type, <<"cb_", _/binary>> = EncData) ->
Expand Down
4 changes: 2 additions & 2 deletions apps/aefate/test/aefa_sophia_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ expect(Chain, Contract, Function, Arguments, Expect) ->

%% For now, implement pipeline here.
compile_contract(Code) ->
compile_contract(Code, [{debug, [scode, opt, opt_rules, compile]}, pp_fcode]).
compile_contract(Code, [{debug, [scode, opt, opt_rules, compile]}, pp_fcode, {include, {file_system, ["."]}}]).

compile_contract(Code, Options) ->
try
{ok, Ast} = aeso_parser:string(Code),
{ok, Ast} = aeso_parser:string(Code, Options),
TypedAst = aeso_ast_infer_types:infer(Ast, Options),
FCode = aeso_ast_to_fcode:ast_to_fcode(TypedAst, Options),
Fate = aeso_fcode_to_fate:compile(FCode, Options),
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
{sname, 'aeternity_ct@localhost'}]},
{deps, [{meck, "0.8.12"},
{websocket_client, {git, "git://github.com/aeternity/websocket_client", {ref, "a4fb3db"}}},
{aesophia, {git, "https://github.com/aeternity/aesophia.git", {ref,"07cf162"}}},
{aesophia, {git, "https://github.com/aeternity/aesophia.git", {ref,"c51531f"}}},
{aesophia_cli, {git, "git://github.com/aeternity/aesophia_cli", {tag, "v3.2.0"}}},
{aestratum_client, {git, "git://github.com/aeternity/aestratum_client", {tag, "v0.1.1"}}}
]}
Expand Down
4 changes: 2 additions & 2 deletions test/contracts/stdlib_tests.aes
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ contract StdTest =
, (Func.tuplify2((a, b) => a + b)((2, 3)) == 5, "tuplify")

, (List.is_empty([]), "empty")
, (option_int_cmp(List.first([1,2,3,4]), Some(1)), "list first")
, (option_int_cmp(List.first([1..4]), Some(1)), "list first")
, (option_int_cmp(List.find((x) => x > 0, [-1, -2, 3, -1]), Some(3)), "find")
, (list_int_cmp(List.replace_at(2, 0, [1,1,1,1,1]), [1,1,0,1,1]), "replace at")
// following test seems to break the FATE runtime. It definitely SHOULD work.
// , (list_int_cmp(List.foldr((e, cont) => (x) => cont(e::x), (x) => x, [1,2,3])([]), [3,2,1]), "foldr")
, (List.foldl((a, x) => a - x, 0, [1,2,3]) == -6, "foldl")
, (list_int_cmp(List.reverse([1,2,3]), [3,2,1]), "reverse")
, (list_int_cmp(List.filter((x) => x > 0, [-1,1,0,-2,2]), [1,2]), "filter")
, (list_int_cmp(List.take(2, List.drop(2, [1,2,3,4,5,6])), [3,4]), "drop&take")
, (list_int_cmp(List.take(2, List.drop(2, [1..6])), [3,4]), "drop&take")
, (list_int_cmp(List.take_while(
(x) => x > 0,
List.drop_while(
Expand Down
6 changes: 3 additions & 3 deletions test/measure_gas_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ compile(File) ->
CodeDir = filename:join(code:lib_dir(aecore), "../../extras/test/contracts"),
FileName = filename:join(CodeDir, File),
{ok, Cwd} = file:get_cwd(),
{ok, Aevm} = aeso_compiler:file(FileName, [no_implicit_stdlib, {backend, aevm}, {include, {file_system, [Cwd, CodeDir]}}]),
{ok, Fate} = aeso_compiler:file(FileName, [no_implicit_stdlib, {backend, fate}, {include, {file_system, [Cwd, CodeDir]}}]),
{ok, Aevm} = aeso_compiler:file(FileName, [{backend, aevm}, {include, {file_system, [Cwd, CodeDir]}}]),
{ok, Fate} = aeso_compiler:file(FileName, [{backend, fate}, {include, {file_system, [Cwd, CodeDir]}}]),
ct:pal("Size aevm: ~p\n fate: ~p\n", [byte_size(aect_sophia:serialize(Aevm, aect_test_utils:latest_sophia_contract_version())),
byte_size(aect_sophia:serialize(Fate, aect_test_utils:latest_sophia_contract_version()))]),
{Aevm, Fate}.
Expand Down Expand Up @@ -248,7 +248,7 @@ contract_call(Trees, Sender, ContractId, CompiledContract, Fun, Args, Backend) -


encode_call_data(Code, Fun, Args, Backend) ->
aeso_compiler:create_calldata(Code, Fun, Args, [no_implicit_stdlib, {backend, Backend}]).
aeso_compiler:create_calldata(Code, Fun, Args, [{backend, Backend}]).

tx_timer(N, Backend, Trees, Env, F) ->
{NewTrees, NewEnv, AllTimes} =
Expand Down

0 comments on commit 06b31e9

Please sign in to comment.