diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..227cea2 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2.0.0 diff --git a/docs/aeso_compiler.md b/docs/aeso_compiler.md index 8bb0f38..5d2e88b 100644 --- a/docs/aeso_compiler.md +++ b/docs/aeso_compiler.md @@ -15,7 +15,7 @@ returns the compiled module in a map which can then be loaded. ``` erlang contract_string() = string() | binary() contract_map() = #{bytecode => binary(), - compiler_version => string(), + compiler_version => binary(), contract_souce => string(), type_info => type_info()} type_info() @@ -75,12 +75,12 @@ Types Get the type representation of a type declaration. -#### version() -> Version +#### version() -> {ok, Version} | {error, term()} Types ``` erlang -Version = integer() +Version = binary() ``` Get the current version of the Sophia compiler. diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index c632f3e..6561eb8 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -39,14 +39,24 @@ , options/0 ]). --define(COMPILER_VERSION_1, 1). --define(COMPILER_VERSION_2, 2). - --define(COMPILER_VERSION, ?COMPILER_VERSION_2). - --spec version() -> pos_integer(). +-spec version() -> {ok, binary()} | {error, term()}. version() -> - ?COMPILER_VERSION. + case lists:keyfind(aesophia, 1, application:loaded_applications()) of + false -> + case application:load(aesophia) of + ok -> + case application:get_key(aesophia, vsn) of + {ok, VsnString} -> + {ok, list_to_binary(VsnString)}; + undefined -> + {error, failed_to_load_aesophia} + end; + Err = {error, _} -> + Err + end; + {_App, _Des, VsnString} -> + {ok, list_to_binary(VsnString)} + end. -spec file(string()) -> {ok, map()} | {error, binary()}. file(Filename) -> @@ -75,8 +85,9 @@ from_string(ContractString, Options) -> ByteCodeList = to_bytecode(Assembler, Options), ByteCode = << << B:8 >> || B <- ByteCodeList >>, pp_bytecode(ByteCode, Options), + {ok, Version} = version(), {ok, #{byte_code => ByteCode, - compiler_version => version(), + compiler_version => Version, contract_source => ContractString, type_info => TypeInfo }} diff --git a/src/aesophia.app.src b/src/aesophia.app.src index d7da977..ba9ca1e 100644 --- a/src/aesophia.app.src +++ b/src/aesophia.app.src @@ -1,6 +1,6 @@ {application, aesophia, [{description, "Contract Language for Aethernity"}, - {vsn, "1.2.0"}, + {vsn, {cmd, "cat VERSION | tr -d '[:space:]'"}}, {registered, []}, {applications, [kernel, diff --git a/src/aesophia.erl b/src/aesophia.erl index c7c57d9..277b444 100644 --- a/src/aesophia.erl +++ b/src/aesophia.erl @@ -4,6 +4,7 @@ -define(OPT_SPEC, [ {src_file, undefined, undefined, string, "Sophia source code file"} + , {version, $V, "version", undefined, "Print compiler version"} , {verbose, $v, "verbose", undefined, "Verbose output"} , {help, $h, "help", undefined, "Show this message"} , {outfile, $o, "out", string, "Output file (experimental)"} ]). @@ -14,11 +15,13 @@ usage() -> main(Args) -> case getopt:parse(?OPT_SPEC, Args) of {ok, {Opts, []}} -> - case proplists:get_value(help, Opts, false) of - false -> - compile(Opts); - true -> - usage() + case Opts of + [version] -> + print_vsn(); + [help] -> + usage(); + _ -> + compile(Opts) end; {ok, {_, NonOpts}} -> @@ -69,3 +72,7 @@ write_outfile(Out, ResMap) -> %% Lazy approach file:write_file(Out, term_to_binary(ResMap)), io:format("Output written to: ~s\n", [Out]). + +print_vsn() -> + {ok, Vsn} = aeso_compiler:version(), + io:format("Compiler version: ~s\n", [Vsn]).