From afdb78b93302b3b80aa979f7b9fff220573a731d Mon Sep 17 00:00:00 2001 From: Erik Stenman Date: Fri, 15 Feb 2019 13:47:40 +0100 Subject: [PATCH] Fix erros found by dialyzer and warnings. --- .gitignore | 2 +- rebar.config | 2 +- src/aeb_fate_asm.erl | 14 +++++++++----- src/aeb_fate_data.erl | 5 ++++- 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index cde56db..4ad6576 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,6 @@ rel/example_project .concrete/DEV_MODE .rebar aeb_asm_scan.erl -aefa_asm_scan.erl +aeb_fate_asm_scan.erl _build/ aefateasm diff --git a/rebar.config b/rebar.config index aae208e..6118607 100644 --- a/rebar.config +++ b/rebar.config @@ -24,7 +24,7 @@ {dialyzer, [ {warnings, [unknown]}, {plt_apps, all_deps}, - {base_plt_apps, [erts, kernel, stdlib, crypto]} + {base_plt_apps, [erts, kernel, stdlib, crypto, getopt]} ]}. diff --git a/src/aeb_fate_asm.erl b/src/aeb_fate_asm.erl index c465c50..2932e2a 100644 --- a/src/aeb_fate_asm.erl +++ b/src/aeb_fate_asm.erl @@ -10,6 +10,10 @@ %%% DUP %%% Identifiers start with a lower case letter %%% an_identifier +%%% References to function arguments start with arg +%%% arg0 +%%% References to variables/registers start with var +%%% var0 %%% Immediates can be of 9 types: %%% 1. Integers %%% 42 @@ -56,7 +60,7 @@ assemble_file(InFile, OutFile, Options) -> Asm = read_file(InFile), - {Env, BC} = asm_to_bytecode(Asm, Options), + {_Env, BC} = asm_to_bytecode(Asm, Options), ok = file:write_file(OutFile, BC). pp(Asm) -> @@ -148,7 +152,7 @@ deserialize(<>, , current_bb_code := Code , code := Program} = Env) -> {Rest2, OpCode} = deserialize_op(Op, Rest, Code), - case aebe_fate_opcodes:end_bb(Op) of + case aeb_fate_opcodes:end_bb(Op) of true -> deserialize(Rest2, Env#{ bb => BB+1 , current_bb_code => [] @@ -402,9 +406,10 @@ to_bytecode([{id,_line, ID}|Rest], Address, Env, Code, Opts) -> to_bytecode(Rest, Address, Env2, [{immediate, Hash}|Code], Opts); to_bytecode([], Address, Env, Code, Opts) -> Env2 = insert_fun(Address, Code, Env), + #{functions := Funs} = Env2, case proplists:lookup(pp_opcodes, Opts) of {pp_opcodes, true} -> - Ops = [C || {_Name, {_Sig, C}} <- maps:to_list(Env2)], + Ops = [C || {_Name, {_Sig, C}} <- maps:to_list(Funs)], io:format("opcodes ~p~n", [Ops]); none -> ok @@ -480,5 +485,4 @@ insert_symbol(Id, Hash, #{symbols := Symbols} = Env) -> {Hash, Env#{symbols => Symbols#{ Id => Hash , Hash => Id}}} end. -lookup_symbol(Id, #{symbols := Symbols} = Env) -> - maps:find(Id, Symbols). + diff --git a/src/aeb_fate_data.erl b/src/aeb_fate_data.erl index 9426b7c..243b204 100644 --- a/src/aeb_fate_data.erl +++ b/src/aeb_fate_data.erl @@ -129,7 +129,7 @@ format(M) when ?IS_FATE_MAP(M) -> "#{ " ++ format_kvs(maps:to_list(?FATE_MAP_VALUE(M))) ++" }"; -format(?FATE_ADDRESS(Address)) -> base58:binary_to_base58(Address); +format(?FATE_ADDRESS(Address)) -> address_to_base58(Address); format(V) -> exit({not_a_fate_type, V}). format_list([]) -> " ]"; @@ -167,6 +167,9 @@ base58_to_address(Base58) -> Bin = <>, Bin. +address_to_base58(<>) -> + integer_to_base58(A). + integer_to_base58(0) -> <<"1">>; integer_to_base58(Integer) -> Base58String = integer_to_base58(Integer, []),