From ceb7de21195ec57f4d5c778f75cc4a55f6c00dac Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Tue, 29 Jan 2019 13:58:00 +0100 Subject: [PATCH 1/5] Remove a leftover reference to enacl --- src/aesophia.app.src | 1 - 1 file changed, 1 deletion(-) diff --git a/src/aesophia.app.src b/src/aesophia.app.src index 46c5a67..37b056d 100644 --- a/src/aesophia.app.src +++ b/src/aesophia.app.src @@ -5,7 +5,6 @@ {applications, [kernel, stdlib, - enacl, syntax_tools, aebytecode ]}, From b8cb7ab1b550eca5fbba71b5d5558f7999e0c65c Mon Sep 17 00:00:00 2001 From: Ulf Norell Date: Mon, 28 Jan 2019 14:54:34 +0100 Subject: [PATCH 2/5] Fix incorrect type specs h/t OTP-21 dialyzer --- src/aeso_abi.erl | 10 +++++----- src/aeso_compiler.erl | 2 +- src/aeso_pretty.erl | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/aeso_abi.erl b/src/aeso_abi.erl index ff767ea..c9f32ba 100644 --- a/src/aeso_abi.erl +++ b/src/aeso_abi.erl @@ -27,8 +27,8 @@ -type typerep() :: aeso_sophia:type(). -type function_type_info() :: { FunctionHash :: hash() , FunctionName :: function_name() - , ArgType :: aeso_sophia:heap() %% binary typerep - , OutType :: aeso_sophia:heap() %% binary typerep + , ArgType :: binary() %% binary typerep + , OutType :: binary() %% binary typerep }. -type type_info() :: [function_type_info()]. @@ -84,8 +84,8 @@ check_given_type(FunName, GivenArgs, GivenRet, CalldataType, ExpectRet) -> {expected, ExpectArgs, '=>', ExpectRet}}} end. --spec check_calldata(aeso_sophia:heap(), type_info()) -> - {'ok', typerep()} | {'error', atom()}. +-spec check_calldata(binary(), type_info()) -> + {'ok', typerep(), typerep()} | {'error', atom()}. check_calldata(CallData, TypeInfo) -> %% The first element of the CallData should be the function name case get_function_hash_from_calldata(CallData) of @@ -153,7 +153,7 @@ arg_typerep_from_function(Function, TypeInfo) -> end. -spec typereps_from_type_hash(hash(), type_info()) -> - {'ok', typerep()} | {'error', 'bad_type_data' | 'unknown_function'}. + {'ok', typerep(), typerep()} | {'error', 'bad_type_data' | 'unknown_function'}. typereps_from_type_hash(TypeHash, TypeInfo) -> case lists:keyfind(TypeHash, 1, TypeInfo) of {TypeHash,_Function, ArgTypeBin, OutTypeBin} -> diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index e132005..bbe8e10 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -99,7 +99,7 @@ check_call(ContractString, Options) -> end. -spec create_calldata(map(), string(), string()) -> - {ok, aeso_sophia:heap(), aeso_sophia:type(), aeso_sophia:type()} + {ok, binary(), aeso_sophia:type(), aeso_sophia:type()} | {error, argument_syntax_error}. create_calldata(Contract, "", CallCode) when is_map(Contract) -> case check_call(CallCode, []) of diff --git a/src/aeso_pretty.erl b/src/aeso_pretty.erl index 3462a2e..71da2b4 100644 --- a/src/aeso_pretty.erl +++ b/src/aeso_pretty.erl @@ -170,7 +170,7 @@ expr(E) -> expr_p(0, E). %% -- Not exported ----------------------------------------------------------- --spec name(aeso_syntax:id() | aeso_syntax:con() | aeso_syntax:tvar()) -> doc(). +-spec name(aeso_syntax:id() | aeso_syntax:qid() | aeso_syntax:con() | aeso_syntax:qcon() | aeso_syntax:tvar()) -> doc(). name({id, _, Name}) -> text(Name); name({con, _, Name}) -> text(Name); name({qid, _, Names}) -> text(string:join(Names, ".")); From 87e5562f74e6b9906ec2f28f2fffffb6e304a6bc Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Fri, 25 Jan 2019 14:49:18 +0100 Subject: [PATCH 3/5] Super simple standalone version of the compiler --- rebar.config | 5 +++ rebar.lock | 8 ++++- src/aeso_compiler.erl | 2 +- src/aesophia.app.src | 1 + src/aesophia.erl | 71 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 src/aesophia.erl diff --git a/rebar.config b/rebar.config index 66e9732..03d2d8b 100644 --- a/rebar.config +++ b/rebar.config @@ -1,8 +1,13 @@ {erl_opts, [debug_info]}. +{escript_name, aesophia}. + +{provider_hooks, [{post, [{compile, escriptize}]}]}. + %% NOTE: When possible deps are referenced by Git ref to ensure consistency between builds. {deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"99bf097"}}} + , {getopt, "1.0.1"} ]}. diff --git a/rebar.lock b/rebar.lock index 34aa736..6f391f3 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,4 +1,10 @@ +{"1.1.0", [{<<"aebytecode">>, {git,"https://github.com/aeternity/aebytecode.git", {ref,"99bf097759dedbe7553f87a796bc7e1c7322e64b"}}, - 0}]. + 0}, + {<<"getopt">>,{pkg,<<"getopt">>,<<"1.0.1">>},0}]}. +[ +{pkg_hash,[ + {<<"getopt">>, <<"C73A9FA687B217F2FF79F68A3B637711BB1936E712B521D8CE466B29CBF7808A">>}]} +]. diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index bbe8e10..ca496ab 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -252,7 +252,7 @@ parse_error({Line,Pos}, ErrorString) -> error({parse_errors,[Error]}). read_contract(Name) -> - {ok, Bin} = file:read_file(filename:join(contract_path(), lists:concat([Name, ".aes"]))), + {ok, Bin} = file:read_file(Name), binary_to_list(Bin). contract_path() -> diff --git a/src/aesophia.app.src b/src/aesophia.app.src index 37b056d..6a47608 100644 --- a/src/aesophia.app.src +++ b/src/aesophia.app.src @@ -6,6 +6,7 @@ [kernel, stdlib, syntax_tools, + getopt, aebytecode ]}, {env,[]}, diff --git a/src/aesophia.erl b/src/aesophia.erl new file mode 100644 index 0000000..c7c57d9 --- /dev/null +++ b/src/aesophia.erl @@ -0,0 +1,71 @@ +-module(aesophia). + +-export([main/1]). + +-define(OPT_SPEC, + [ {src_file, undefined, undefined, string, "Sophia source code file"} + , {verbose, $v, "verbose", undefined, "Verbose output"} + , {help, $h, "help", undefined, "Show this message"} + , {outfile, $o, "out", string, "Output file (experimental)"} ]). + +usage() -> + getopt:usage(?OPT_SPEC, "aesophia"). + +main(Args) -> + case getopt:parse(?OPT_SPEC, Args) of + {ok, {Opts, []}} -> + case proplists:get_value(help, Opts, false) of + false -> + compile(Opts); + true -> + usage() + end; + + {ok, {_, NonOpts}} -> + io:format("Can't understand ~p\n\n", [NonOpts]), + usage(); + + {error, {Reason, Data}} -> + io:format("Error: ~s ~p\n\n", [Reason, Data]), + usage() + end. + + +compile(Opts) -> + case proplists:get_value(src_file, Opts, undefined) of + undefined -> + io:format("Error: no input source file\n\n"), + usage(); + File -> + compile(File, Opts) + end. + +compile(File, Opts) -> + Verbose = proplists:get_value(verbose, Opts, false), + OutFile = proplists:get_value(outfile, Opts, undefined), + + try + Res = aeso_compiler:file(File, [pp_ast || Verbose]), + write_outfile(OutFile, Res), + io:format("\nCompiled successfully!\n") + catch + %% The compiler errors. + error:{type_errors, Errors} -> + io:format("\n~s\n", [string:join(["** Type errors\n" | Errors], "\n")]); + error:{parse_errors, Errors} -> + io:format("\n~s\n", [string:join(["** Parse errors\n" | Errors], "\n")]); + error:{code_errors, Errors} -> + ErrorStrings = [ io_lib:format("~p", [E]) || E <- Errors ], + io:format("\n~s\n", [string:join(["** Code errors\n" | ErrorStrings], "\n")]); + %% General programming errors in the compiler. + error:Error -> + Where = hd(erlang:get_stacktrace()), + ErrorString = io_lib:format("Error: ~p in\n ~p", [Error,Where]), + io:format("\n~s\n", [ErrorString]) + end. + +write_outfile(undefined, _) -> ok; +write_outfile(Out, ResMap) -> + %% Lazy approach + file:write_file(Out, term_to_binary(ResMap)), + io:format("Output written to: ~s\n", [Out]). From 65b679117641375a00f93dd12457c8f980566080 Mon Sep 17 00:00:00 2001 From: Dincho Todorov Date: Tue, 29 Jan 2019 15:35:41 +0200 Subject: [PATCH 4/5] Initial CircleCI integration (#20) --- .circleci/config.yml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..33debcf --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,37 @@ +version: 2.1 + +executors: + aebuilder: + docker: + - image: aeternity/builder + user: builder + working_directory: ~/aesophia + +jobs: + build: + executor: aebuilder + steps: + - checkout + - restore_cache: + keys: + - dialyzer-cache-v2-{{ .Branch }}-{{ .Revision }} + - dialyzer-cache-v2-{{ .Branch }}- + - dialyzer-cache-v2- + - run: + name: Build + command: rebar3 compile + - run: + name: Static Analysis + command: rebar3 dialyzer + - run: + name: Eunit + command: rebar3 eunit + - run: + name: Common Tests + command: rebar3 ct + - save_cache: + key: dialyzer-cache-v2-{{ .Branch }}-{{ .Revision }} + paths: + - _build/default/rebar3_20.3.8_plt + - store_artifacts: + path: _build/test/logs From 362373c0d7bd34474c8a28e2fd65e59f42cfe45d Mon Sep 17 00:00:00 2001 From: Hans Svensson Date: Wed, 30 Jan 2019 10:55:11 +0100 Subject: [PATCH 5/5] Add escript post_hooks --- rebar.config | 19 ++++++++++++++----- src/aeso_compiler.erl | 2 -- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/rebar.config b/rebar.config index 03d2d8b..f2e5106 100644 --- a/rebar.config +++ b/rebar.config @@ -1,15 +1,24 @@ {erl_opts, [debug_info]}. -{escript_name, aesophia}. - -{provider_hooks, [{post, [{compile, escriptize}]}]}. - -%% NOTE: When possible deps are referenced by Git ref to ensure consistency between builds. {deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git", {ref,"99bf097"}}} , {getopt, "1.0.1"} ]}. +{escript_incl_apps, [aesophia, aebytecode, getopt]}. +{escript_main_app, aesophia}. +{escript_name, aesophia}. +{escript_emu_args, "%%! +sbtu +A0\n"}. +{provider_hooks, [{post, [{compile, escriptize}]}]}. + +{post_hooks, [{"(linux|darwin|solaris|freebsd|netbsd|openbsd)", + escriptize, + "cp \"$REBAR_BUILD_DIR/bin/aesophia\" ./aesophia"}, + {"win32", + escriptize, + "robocopy \"%REBAR_BUILD_DIR%/bin/\" ./ aesophia* " + "/njs /njh /nfl /ndl & exit /b 0"} % silence things + ]}. {dialyzer, [ {warnings, [unknown]}, diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index ca496ab..92d9afe 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -255,5 +255,3 @@ read_contract(Name) -> {ok, Bin} = file:read_file(Name), binary_to_list(Bin). -contract_path() -> - "apps/aesophia/test/contracts".