From 8d7025f7943508cf41de1cc104b40efd889e1417 Mon Sep 17 00:00:00 2001 From: radrow Date: Fri, 7 Apr 2023 12:06:29 +0200 Subject: [PATCH] Cleanup pretty printing --- CHANGELOG.md | 10 ++++++++++ src/aeso_ast.erl | 27 --------------------------- src/aeso_compiler.erl | 35 +++++++++++++++++------------------ src/aeso_pretty.erl | 1 - 4 files changed, 27 insertions(+), 46 deletions(-) delete mode 100644 src/aeso_ast.erl diff --git a/CHANGELOG.md b/CHANGELOG.md index ed83675..eb7cf78 100644 --- a/CHANGELOG.md +++ b/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/), 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] diff --git a/src/aeso_ast.erl b/src/aeso_ast.erl deleted file mode 100644 index 4c36123..0000000 --- a/src/aeso_ast.erl +++ /dev/null @@ -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]). - diff --git a/src/aeso_compiler.erl b/src/aeso_compiler.erl index 31b4ef8..bd78c6f 100644 --- a/src/aeso_compiler.erl +++ b/src/aeso_compiler.erl @@ -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 --------------------------------------------------- diff --git a/src/aeso_pretty.erl b/src/aeso_pretty.erl index afce62c..866d318 100644 --- a/src/aeso_pretty.erl +++ b/src/aeso_pretty.erl @@ -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}}. -