Cleanup pretty printing
This commit is contained in:
parent
99bb3fe1fb
commit
8d7025f794
10
CHANGELOG.md
10
CHANGELOG.md
@ -4,11 +4,21 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
### Changed
|
### Changed
|
||||||
### Removed
|
### Removed
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
## [8.x.x]
|
||||||
|
### Added
|
||||||
|
### Changed
|
||||||
|
- `pp_assembler` option to `pp_fate` as it is more specific.
|
||||||
|
### Removed
|
||||||
|
- `pp_sophia_code` option as it was a duplicate of `pp_ast`.
|
||||||
|
- `aeso_ast` module as it was unused.
|
||||||
|
### Fixed
|
||||||
- Warning about unused include when there is no include.
|
- Warning about unused include when there is no include.
|
||||||
|
|
||||||
## [7.1.0]
|
## [7.1.0]
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
-module(aeso_ast).
|
|
||||||
|
|
||||||
-export([int/2,
|
|
||||||
line/1,
|
|
||||||
pp/1,
|
|
||||||
pp_typed/1,
|
|
||||||
symbol/2,
|
|
||||||
symbol_name/1
|
|
||||||
]).
|
|
||||||
|
|
||||||
|
|
||||||
symbol(Line, Chars) -> {symbol, Line, Chars}.
|
|
||||||
int(Line, Int) -> {'Int', Line, Int}.
|
|
||||||
|
|
||||||
line({symbol, Line, _}) -> Line.
|
|
||||||
|
|
||||||
symbol_name({symbol, _, Name}) -> Name.
|
|
||||||
|
|
||||||
pp(Ast) ->
|
|
||||||
String = prettypr:format(aeso_pretty:decls(Ast, [])),
|
|
||||||
io:format("Ast:\n~s\n", [String]).
|
|
||||||
|
|
||||||
pp_typed(TypedAst) ->
|
|
||||||
%% io:format("Typed tree:\n~p\n",[TypedAst]),
|
|
||||||
String = prettypr:format(aeso_pretty:decls(TypedAst, [show_generated])),
|
|
||||||
io:format("Type ast:\n~s\n",[String]).
|
|
||||||
|
|
@ -29,11 +29,10 @@
|
|||||||
-include("aeso_utils.hrl").
|
-include("aeso_utils.hrl").
|
||||||
|
|
||||||
|
|
||||||
-type option() :: pp_sophia_code
|
-type option() :: pp_ast
|
||||||
| pp_ast
|
|
||||||
| pp_types
|
| pp_types
|
||||||
| pp_typed_ast
|
| pp_typed_ast
|
||||||
| pp_assembler
|
| pp_fate
|
||||||
| no_code
|
| no_code
|
||||||
| keep_included
|
| keep_included
|
||||||
| debug_mode
|
| debug_mode
|
||||||
@ -118,7 +117,7 @@ from_string1(ContractString, Options) ->
|
|||||||
#{ child_con_env := ChildContracts } = FCodeEnv,
|
#{ child_con_env := ChildContracts } = FCodeEnv,
|
||||||
SavedFreshNames = maps:get(saved_fresh_names, FCodeEnv, #{}),
|
SavedFreshNames = maps:get(saved_fresh_names, FCodeEnv, #{}),
|
||||||
{FateCode, VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options),
|
{FateCode, VarsRegs} = aeso_fcode_to_fate:compile(ChildContracts, FCode, SavedFreshNames, Options),
|
||||||
pp_assembler(FateCode, Options),
|
pp_fate(FateCode, Options),
|
||||||
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
ByteCode = aeb_fate_code:serialize(FateCode, []),
|
||||||
{ok, Version} = version(),
|
{ok, Version} = version(),
|
||||||
Res = #{byte_code => ByteCode,
|
Res = #{byte_code => ByteCode,
|
||||||
@ -150,7 +149,6 @@ maybe_generate_aci(Result, FoldedTypedAst, Options) ->
|
|||||||
-spec string_to_code(string(), options()) -> map().
|
-spec string_to_code(string(), options()) -> map().
|
||||||
string_to_code(ContractString, Options) ->
|
string_to_code(ContractString, Options) ->
|
||||||
Ast = parse(ContractString, Options),
|
Ast = parse(ContractString, Options),
|
||||||
pp_sophia_code(Ast, Options),
|
|
||||||
pp_ast(Ast, Options),
|
pp_ast(Ast, Options),
|
||||||
{TypeEnv, FoldedTypedAst, UnfoldedTypedAst, Warnings} = aeso_ast_infer_types:infer(Ast, [return_env | Options]),
|
{TypeEnv, FoldedTypedAst, UnfoldedTypedAst, Warnings} = aeso_ast_infer_types:infer(Ast, [return_env | Options]),
|
||||||
pp_typed_ast(UnfoldedTypedAst, Options),
|
pp_typed_ast(UnfoldedTypedAst, Options),
|
||||||
@ -365,21 +363,22 @@ get_decode_type(FunName, [_ | Contracts]) ->
|
|||||||
%% The __decode should be in the final contract
|
%% The __decode should be in the final contract
|
||||||
get_decode_type(FunName, Contracts).
|
get_decode_type(FunName, Contracts).
|
||||||
|
|
||||||
pp_sophia_code(C, Opts)-> pp(C, Opts, pp_sophia_code, fun(Code) ->
|
pp_ast(C, Opts) ->
|
||||||
io:format("~s\n", [prettypr:format(aeso_pretty:decls(Code))])
|
[ io:format("AST:\n~s\n",
|
||||||
end).
|
[prettypr:format(aeso_pretty:decls(Ast, []))])
|
||||||
pp_ast(C, Opts) -> pp(C, Opts, pp_ast, fun aeso_ast:pp/1).
|
|| true <- proplists:get_value(pp_ast, Opts)
|
||||||
pp_typed_ast(C, Opts)-> pp(C, Opts, pp_typed_ast, fun aeso_ast:pp_typed/1).
|
].
|
||||||
|
|
||||||
pp_assembler(C, Opts) -> pp(C, Opts, pp_assembler, fun(Asm) -> io:format("~s", [aeb_fate_asm:pp(Asm)]) end).
|
pp_typed_ast(C, Opts) ->
|
||||||
|
[ io:format("Typed AST:\n~s\n",
|
||||||
|
[prettypr:format(aeso_pretty:decls(Ast, [show_generated]))])
|
||||||
|
|| true <- proplists:get_value(pp_typed_ast, Opts)
|
||||||
|
].
|
||||||
|
|
||||||
pp(Code, Options, Option, PPFun) ->
|
pp_fate(C, Opts) ->
|
||||||
case proplists:lookup(Option, Options) of
|
[ io:format("FATE:\n~s\n", [aeb_fate_asm:pp(Asm)])
|
||||||
{Option1, true} when Option1 =:= Option ->
|
|| true <- proplists:get_value(pp_fate, Opts)
|
||||||
PPFun(Code);
|
].
|
||||||
none ->
|
|
||||||
ok
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% -- Byte code validation ---------------------------------------------------
|
%% -- Byte code validation ---------------------------------------------------
|
||||||
|
|
||||||
|
@ -526,4 +526,3 @@ get_elifs(If = {'if', Ann, Cond, Then, Else}, Elifs) ->
|
|||||||
_ -> {lists:reverse(Elifs), If}
|
_ -> {lists:reverse(Elifs), If}
|
||||||
end;
|
end;
|
||||||
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}.
|
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user