Cleanup pretty printing

This commit is contained in:
radrow 2023-04-07 12:06:29 +02:00
parent 99bb3fe1fb
commit 8d7025f794
4 changed files with 27 additions and 46 deletions

View File

@ -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/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
### Changed
### Removed
### 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.
## [7.1.0]

View File

@ -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]).

View File

@ -29,11 +29,10 @@
-include("aeso_utils.hrl").
-type option() :: pp_sophia_code
| pp_ast
-type option() :: pp_ast
| pp_types
| pp_typed_ast
| pp_assembler
| pp_fate
| no_code
| keep_included
| debug_mode
@ -118,7 +117,7 @@ from_string1(ContractString, Options) ->
#{ child_con_env := ChildContracts } = FCodeEnv,
SavedFreshNames = maps:get(saved_fresh_names, FCodeEnv, #{}),
{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, []),
{ok, Version} = version(),
Res = #{byte_code => ByteCode,
@ -150,7 +149,6 @@ maybe_generate_aci(Result, FoldedTypedAst, Options) ->
-spec string_to_code(string(), options()) -> map().
string_to_code(ContractString, Options) ->
Ast = parse(ContractString, Options),
pp_sophia_code(Ast, Options),
pp_ast(Ast, Options),
{TypeEnv, FoldedTypedAst, UnfoldedTypedAst, Warnings} = aeso_ast_infer_types:infer(Ast, [return_env | Options]),
pp_typed_ast(UnfoldedTypedAst, Options),
@ -365,21 +363,22 @@ get_decode_type(FunName, [_ | Contracts]) ->
%% The __decode should be in the final contract
get_decode_type(FunName, Contracts).
pp_sophia_code(C, Opts)-> pp(C, Opts, pp_sophia_code, fun(Code) ->
io:format("~s\n", [prettypr:format(aeso_pretty:decls(Code))])
end).
pp_ast(C, Opts) -> pp(C, Opts, pp_ast, fun aeso_ast:pp/1).
pp_typed_ast(C, Opts)-> pp(C, Opts, pp_typed_ast, fun aeso_ast:pp_typed/1).
pp_ast(C, Opts) ->
[ io:format("AST:\n~s\n",
[prettypr:format(aeso_pretty:decls(Ast, []))])
|| true <- proplists:get_value(pp_ast, Opts)
].
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) ->
case proplists:lookup(Option, Options) of
{Option1, true} when Option1 =:= Option ->
PPFun(Code);
none ->
ok
end.
pp_fate(C, Opts) ->
[ io:format("FATE:\n~s\n", [aeb_fate_asm:pp(Asm)])
|| true <- proplists:get_value(pp_fate, Opts)
].
%% -- Byte code validation ---------------------------------------------------

View File

@ -526,4 +526,3 @@ get_elifs(If = {'if', Ann, Cond, Then, Else}, Elifs) ->
_ -> {lists:reverse(Elifs), If}
end;
get_elifs(Else, Elifs) -> {lists:reverse(Elifs), {else, Else}}.