From 8b3877a92c13ff7a0156678d3570b03256930be1 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Wulfman Date: Mon, 16 Mar 2020 14:28:05 +0100 Subject: [PATCH] rename AST to imperative, sugar and core. Factor code in compile --- .../contributors/big-picture/middle-end.md | 2 +- .../docs/contributors/ligo_test_guide.md | 2 +- src/bin/cli.ml | 128 +++++------------- src/main/compile/dune | 8 +- src/main/compile/helpers.ml | 36 ++--- .../compile/{of_simplified.ml => of_core.ml} | 22 +-- .../{of_abstracted.ml => of_imperative.ml} | 4 +- .../compile/{of_complex.ml => of_sugar.ml} | 6 +- src/main/compile/utils.ml | 65 +++++++++ src/main/run/dune | 2 +- src/passes/2-abstracter/camligo.ml.old | 2 +- src/passes/2-abstracter/pascaligo.mli | 4 +- src/passes/4-Instruction_remover/dune | 2 +- .../instruction_remover.ml | 2 +- src/passes/5-self_ast_complex/dune | 6 +- src/passes/6-simplifier/dune | 4 +- src/passes/6-simplifier/simplifier.ml | 4 +- src/passes/7-self_ast_simplified/dune | 6 +- src/passes/8-typer-new/dune | 2 +- src/passes/8-typer-new/solver.ml | 2 +- src/passes/8-typer-new/typer.ml | 16 +-- src/passes/8-typer-new/typer.ml.old | 4 +- src/passes/8-typer-new/typer.mli | 2 +- src/passes/8-typer-old/dune | 2 +- src/passes/8-typer-old/typer.ml | 2 +- src/passes/8-typer-old/typer.mli | 2 +- src/passes/8-typer/dune | 2 +- src/passes/8-typer/typer.ml | 2 +- src/passes/8-typer/typer.mli | 2 +- src/passes/operators/dune | 4 +- src/passes/operators/operators.ml | 2 +- src/stages/1-ast_imperative/combinators.ml | 2 +- src/stages/1-ast_imperative/types.ml | 2 +- .../{2-ast_complex => 2-ast_sugar}/PP.ml | 2 +- .../ast_sugar.ml} | 0 .../combinators.ml | 2 +- .../combinators.mli | 0 .../{2-ast_complex => 2-ast_sugar}/dune | 4 +- .../{2-ast_complex => 2-ast_sugar}/misc.ml | 0 .../{2-ast_complex => 2-ast_sugar}/misc.mli | 0 .../{2-ast_complex => 2-ast_sugar}/types.ml | 6 +- .../{3-ast_simplified => 3-ast_core}/PP.ml | 2 +- .../ast_core.ml} | 0 .../combinators.ml | 2 +- .../combinators.mli | 0 .../{3-ast_simplified => 3-ast_core}/dune | 4 +- .../{3-ast_simplified => 3-ast_core}/misc.ml | 0 .../{3-ast_simplified => 3-ast_core}/misc.mli | 0 .../{3-ast_simplified => 3-ast_core}/types.ml | 6 +- src/stages/4-ast_typed/combinators.ml | 2 +- src/stages/4-ast_typed/dune | 2 +- src/stages/4-ast_typed/types.ml | 2 +- src/stages/typesystem/misc.ml | 24 ++-- src/test/coase_tests.ml | 9 +- src/test/hash_lock_tests.ml | 7 +- src/test/id_tests.ml | 7 +- src/test/integration_tests.ml | 82 +++++------ src/test/md_file_tests.ml | 8 +- src/test/multisig_tests.ml | 7 +- src/test/multisig_v2_tests.ml | 7 +- src/test/pledge_tests.ml | 7 +- src/test/replaceable_id_tests.ml | 7 +- src/test/test_helpers.ml | 40 +++--- src/test/time_lock_repeat_tests.ml | 7 +- src/test/time_lock_tests.ml | 7 +- src/test/typer_tests.ml | 6 +- src/test/vote_tests.ml | 11 +- 67 files changed, 292 insertions(+), 331 deletions(-) rename src/main/compile/{of_simplified.ml => of_core.ml} (59%) rename src/main/compile/{of_abstracted.ml => of_imperative.ml} (79%) rename src/main/compile/{of_complex.ml => of_sugar.ml} (74%) create mode 100644 src/main/compile/utils.ml rename src/stages/{2-ast_complex => 2-ast_sugar}/PP.ml (99%) rename src/stages/{2-ast_complex/ast_complex.ml => 2-ast_sugar/ast_sugar.ml} (100%) rename src/stages/{2-ast_complex => 2-ast_sugar}/combinators.ml (99%) rename src/stages/{2-ast_complex => 2-ast_sugar}/combinators.mli (100%) rename src/stages/{2-ast_complex => 2-ast_sugar}/dune (77%) rename src/stages/{2-ast_complex => 2-ast_sugar}/misc.ml (100%) rename src/stages/{2-ast_complex => 2-ast_sugar}/misc.mli (100%) rename src/stages/{2-ast_complex => 2-ast_sugar}/types.ml (95%) rename src/stages/{3-ast_simplified => 3-ast_core}/PP.ml (99%) rename src/stages/{3-ast_simplified/ast_simplified.ml => 3-ast_core/ast_core.ml} (100%) rename src/stages/{3-ast_simplified => 3-ast_core}/combinators.ml (99%) rename src/stages/{3-ast_simplified => 3-ast_core}/combinators.mli (100%) rename src/stages/{3-ast_simplified => 3-ast_core}/dune (75%) rename src/stages/{3-ast_simplified => 3-ast_core}/misc.ml (100%) rename src/stages/{3-ast_simplified => 3-ast_core}/misc.mli (100%) rename src/stages/{3-ast_simplified => 3-ast_core}/types.ml (95%) diff --git a/gitlab-pages/docs/contributors/big-picture/middle-end.md b/gitlab-pages/docs/contributors/big-picture/middle-end.md index 6dac7f5ec..f7cd04a8b 100644 --- a/gitlab-pages/docs/contributors/big-picture/middle-end.md +++ b/gitlab-pages/docs/contributors/big-picture/middle-end.md @@ -6,7 +6,7 @@ title: Middle End The Middle-End is the core of LIGO. It is also composed of three parts. ## Common AST The Common AST is the closest thing to what could be called “LIGO lang”. As such, it should be as simple as possible. Collapsing particular cases in more general constructs is encouraged. Documenting it is crucial for people who’ll write new parsers or editor support for Front-end related things. -Its files are in `ast_simplified/`, of interest is the definition of the AST itself in `ast_simplified/types.ml`. +Its files are in `ast_core/`, of interest is the definition of the AST itself in `ast_core/types.ml`. ## Type Checker The Type Checker, among other things, checks that a given AST is valid with regard to type-safety. It also annotates expressions with their types, free-variables and local environments. As time passes, we want to make the type-system stronger, to encode arbitrarily complex properties in an extensible manner. diff --git a/gitlab-pages/docs/contributors/ligo_test_guide.md b/gitlab-pages/docs/contributors/ligo_test_guide.md index eea05d77d..f8be06001 100644 --- a/gitlab-pages/docs/contributors/ligo_test_guide.md +++ b/gitlab-pages/docs/contributors/ligo_test_guide.md @@ -102,7 +102,7 @@ What's going on is similar to the last program: `expect_eq_evaluate` runs a prog For example, once the program stops running the value of `address` is `"tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx"`. The *comparison*, however, is made to a constructed expression. -Remember that we're testing from OCaml, but the program is written and evaluated as LIGO. In order to provide a proper comparison, we convert our expected test values into LIGO expressions and data. Constructors such as `e_list` and `e_address` provide a bridge between LIGO and OCaml. Their definitions can be found in files such as [src/stages/ast_simplified/combinators.ml](https://gitlab.com/ligolang/ligo/blob/dev/src/stages/ast_simplified/combinators.ml), or using [Merlin's definition point finder](https://github.com/ocaml/merlin/wiki). These same functions are used during the simplification stage of LIGO compilation, so becoming familiar with them will help prepare you to work on the [front end](contributors/big-picture/front-end/). +Remember that we're testing from OCaml, but the program is written and evaluated as LIGO. In order to provide a proper comparison, we convert our expected test values into LIGO expressions and data. Constructors such as `e_list` and `e_address` provide a bridge between LIGO and OCaml. Their definitions can be found in files such as [src/stages/ast_core/combinators.ml](https://gitlab.com/ligolang/ligo/blob/dev/src/stages/ast_core/combinators.ml), or using [Merlin's definition point finder](https://github.com/ocaml/merlin/wiki). These same functions are used during the simplification stage of LIGO compilation, so becoming familiar with them will help prepare you to work on the [front end](contributors/big-picture/front-end/). ## How To Write A Test For LIGO diff --git a/src/bin/cli.ml b/src/bin/cli.ml index 2a1f21744..7292d66c1 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -140,10 +140,7 @@ module Run = Ligo.Run.Of_michelson let compile_file = let f source_file entry_point syntax display_format disable_typecheck michelson_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complexed = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complexed in - let%bind typed,_ = Compile.Of_simplified.compile (Contract entry_point) simplified in + let%bind typed,_ = Compile.Utils.type_file source_file syntax (Contract entry_point) in let%bind mini_c = Compile.Of_typed.compile typed in let%bind michelson = Compile.Of_mini_c.aggregate_and_compile_contract mini_c entry_point in let%bind contract = Compile.Of_michelson.build_contract ~disable_typecheck michelson in @@ -170,10 +167,8 @@ let print_cst = let print_ast = let f source_file syntax display_format = ( toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - ok @@ Format.asprintf "%a\n" Compile.Of_simplified.pretty_print simplified + let%bind core = Compile.Utils.to_core source_file syntax in + ok @@ Format.asprintf "%a\n" Compile.Of_core.pretty_print core ) in let term = Term.(const f $ source_file 0 $ syntax $ display_format) in @@ -184,10 +179,7 @@ let print_ast = let print_typed_ast = let f source_file syntax display_format = ( toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed,_ = Compile.Of_simplified.compile Env simplified in + let%bind typed,_ = Compile.Utils.type_file source_file syntax Env in ok @@ Format.asprintf "%a\n" Compile.Of_typed.pretty_print typed ) in @@ -199,10 +191,7 @@ let print_typed_ast = let print_mini_c = let f source_file syntax display_format = ( toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed,_ = Compile.Of_simplified.compile Env simplified in + let%bind typed,_ = Compile.Utils.type_file source_file syntax Env in let%bind mini_c = Compile.Of_typed.compile typed in ok @@ Format.asprintf "%a\n" Compile.Of_mini_c.pretty_print mini_c ) @@ -215,13 +204,7 @@ let print_mini_c = let measure_contract = let f source_file entry_point syntax display_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed,_ = Compile.Of_simplified.compile (Contract entry_point) simplified in - let%bind mini_c = Compile.Of_typed.compile typed in - let%bind michelson = Compile.Of_mini_c.aggregate_and_compile_contract mini_c entry_point in - let%bind contract = Compile.Of_michelson.build_contract michelson in + let%bind contract = Compile.Utils.compile_file source_file syntax entry_point in let open Tezos_utils in ok @@ Format.asprintf "%d bytes\n" (Michelson.measure contract) in @@ -234,10 +217,7 @@ let measure_contract = let compile_parameter = let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed_prg,state = Compile.Of_simplified.compile (Contract entry_point) simplified in + let%bind typed_prg,state = Compile.Utils.type_file source_file syntax (Contract entry_point) in let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in let%bind michelson_prg = Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg entry_point in let env = Ast_typed.program_environment typed_prg in @@ -245,11 +225,7 @@ let compile_parameter = (* fails if the given entry point is not a valid contract *) Compile.Of_michelson.build_contract michelson_prg in - let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in - let%bind abstracted_param = Compile.Of_source.compile_expression v_syntax expression in - let%bind complex_param = Compile.Of_abstracted.compile_expression abstracted_param in - let%bind simplified_param = Compile.Of_complex.compile_expression complex_param in - let%bind (typed_param,_) = Compile.Of_simplified.compile_expression ~env ~state simplified_param in + let%bind (typed_param,_) = Compile.Utils.type_expression (Some source_file) syntax expression env state in let%bind mini_c_param = Compile.Of_typed.compile_expression typed_param in let%bind compiled_param = Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c_param in let%bind () = Compile.Of_typed.assert_equal_contract_type Check_parameter entry_point typed_prg typed_param in @@ -269,20 +245,13 @@ let interpret = toplevel ~display_format @@ let%bind (decl_list,state,env) = match init_file with | Some init_file -> - let%bind abstracted = Compile.Of_source.compile init_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed_prg,state = Compile.Of_simplified.compile Env simplified in + let%bind typed_prg,state = Compile.Utils.type_file init_file syntax Env in let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in let env = Ast_typed.program_environment typed_prg in ok (mini_c_prg,state,env) | None -> ok ([],Typer.Solver.initial_state,Ast_typed.Environment.full_empty) in - let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) init_file in - let%bind abstracted_exp = Compile.Of_source.compile_expression v_syntax expression in - let%bind complex_exp = Compile.Of_abstracted.compile_expression abstracted_exp in - let%bind simplified_exp = Compile.Of_complex.compile_expression complex_exp in - let%bind (typed_exp,_) = Compile.Of_simplified.compile_expression ~env ~state simplified_exp in + let%bind (typed_exp,_) = Compile.Utils.type_expression init_file syntax expression env state in let%bind mini_c_exp = Compile.Of_typed.compile_expression typed_exp in let%bind compiled_exp = Compile.Of_mini_c.aggregate_and_compile_expression decl_list mini_c_exp in let%bind options = Run.make_dry_run_options {predecessor_timestamp ; amount ; balance ; sender ; source } in @@ -292,8 +261,8 @@ let interpret = let%bind failstring = Run.failwith_to_string fail_res in ok @@ Format.asprintf "%s" failstring | Success value' -> - let%bind simplified_output = Uncompile.uncompile_expression typed_exp.type_expression value' in - ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression simplified_output + let%bind core_output = Uncompile.uncompile_expression typed_exp.type_expression value' in + ok @@ Format.asprintf "%a\n" Ast_core.PP.expression core_output in let term = Term.(const f $ expression "EXPRESSION" 0 $ init_file $ syntax $ amount $ balance $ sender $ source $ predecessor_timestamp $ display_format ) in @@ -304,10 +273,7 @@ let interpret = let temp_ligo_interpreter = let f source_file syntax display_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed,_ = Compile.Of_simplified.compile Env simplified in + let%bind typed,_ = Compile.Utils.type_file source_file syntax Env in let%bind res = Compile.Of_typed.some_interpret typed in ok @@ Format.asprintf "%s\n" res in @@ -320,10 +286,7 @@ let temp_ligo_interpreter = let compile_storage = let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed_prg,state = Compile.Of_simplified.compile (Contract entry_point) simplified in + let%bind typed_prg,state = Compile.Utils.type_file source_file syntax (Contract entry_point) in let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in let%bind michelson_prg = Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg entry_point in let env = Ast_typed.program_environment typed_prg in @@ -331,11 +294,7 @@ let compile_storage = (* fails if the given entry point is not a valid contract *) Compile.Of_michelson.build_contract michelson_prg in - let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in - let%bind abstracted_param = Compile.Of_source.compile_expression v_syntax expression in - let%bind complex_param = Compile.Of_abstracted.compile_expression abstracted_param in - let%bind simplified_param = Compile.Of_complex.compile_expression complex_param in - let%bind (typed_param,_) = Compile.Of_simplified.compile_expression ~env ~state simplified_param in + let%bind (typed_param,_) = Compile.Utils.type_expression (Some source_file) syntax expression env state in let%bind mini_c_param = Compile.Of_typed.compile_expression typed_param in let%bind compiled_param = Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c_param in let%bind () = Compile.Of_typed.assert_equal_contract_type Check_storage entry_point typed_prg typed_param in @@ -353,10 +312,7 @@ let compile_storage = let dry_run = let f source_file entry_point storage input amount balance sender source predecessor_timestamp syntax display_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed_prg,state = Compile.Of_simplified.compile (Contract entry_point) simplified in + let%bind typed_prg,state = Compile.Utils.type_file source_file syntax (Contract entry_point) in let env = Ast_typed.program_environment typed_prg in let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in let%bind michelson_prg = Compile.Of_mini_c.aggregate_and_compile_contract mini_c_prg entry_point in @@ -364,13 +320,7 @@ let dry_run = (* fails if the given entry point is not a valid contract *) Compile.Of_michelson.build_contract michelson_prg in - let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in - let%bind abstracted = Compile.Of_source.compile_contract_input storage input v_syntax in - let%bind complex = Compile.Of_abstracted.compile_expression abstracted in - let%bind simplified = Compile.Of_complex.compile_expression complex in - let%bind typed,_ = Compile.Of_simplified.compile_expression ~env ~state simplified in - let%bind mini_c = Compile.Of_typed.compile_expression typed in - let%bind compiled_params = Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c in + let%bind compiled_params = Compile.Utils.compile_storage storage input source_file syntax env state mini_c_prg in let%bind args_michelson = Run.evaluate_expression compiled_params.expr compiled_params.expr_ty in let%bind options = Run.make_dry_run_options {predecessor_timestamp ; amount ; balance ; sender ; source } in @@ -380,8 +330,8 @@ let dry_run = let%bind failstring = Run.failwith_to_string fail_res in ok @@ Format.asprintf "%s" failstring | Success michelson_output -> - let%bind simplified_output = Uncompile.uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in - ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression simplified_output + let%bind core_output = Uncompile.uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in + ok @@ Format.asprintf "%a\n" Ast_core.PP.expression core_output in let term = Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ expression "STORAGE" 3 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format) in @@ -392,20 +342,17 @@ let dry_run = let run_function = let f source_file entry_point parameter amount balance sender source predecessor_timestamp syntax display_format = toplevel ~display_format @@ - let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in - let%bind abstracted_prg = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex_prg = Compile.Of_abstracted.compile abstracted_prg in - let%bind simplified_prg = Compile.Of_complex.compile complex_prg in - let%bind typed_prg,state = Compile.Of_simplified.compile Env simplified_prg in + let%bind typed_prg,state = Compile.Utils.type_file source_file syntax Env in let env = Ast_typed.program_environment typed_prg in let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in - let%bind abstracted_param = Compile.Of_source.compile_expression v_syntax parameter in - let%bind complex_param = Compile.Of_abstracted.compile_expression abstracted_param in - let%bind simplified_param = Compile.Of_complex.compile_expression complex_param in - let%bind app = Compile.Of_simplified.apply entry_point simplified_param in - let%bind (typed_app,_) = Compile.Of_simplified.compile_expression ~env ~state app in + let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in + let%bind imperative_param = Compile.Of_source.compile_expression v_syntax parameter in + let%bind sugar_param = Compile.Of_imperative.compile_expression imperative_param in + let%bind core_param = Compile.Of_sugar.compile_expression sugar_param in + let%bind app = Compile.Of_core.apply entry_point core_param in + let%bind (typed_app,_) = Compile.Of_core.compile_expression ~env ~state app in let%bind compiled_applied = Compile.Of_typed.compile_expression typed_app in let%bind michelson = Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg compiled_applied in @@ -417,7 +364,7 @@ let run_function = ok @@ Format.asprintf "%s" failstring | Success michelson_output -> let%bind simplified_output = Uncompile.uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in - ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression simplified_output + ok @@ Format.asprintf "%a\n" Ast_core.PP.expression simplified_output in let term = Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format) in @@ -428,17 +375,14 @@ let run_function = let evaluate_value = let f source_file entry_point amount balance sender source predecessor_timestamp syntax display_format = toplevel ~display_format @@ - let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex = Compile.Of_abstracted.compile abstracted in - let%bind simplified = Compile.Of_complex.compile complex in - let%bind typed_prg,_ = Compile.Of_simplified.compile Env simplified in + let%bind typed_prg,_ = Compile.Utils.type_file source_file syntax Env in let%bind mini_c = Compile.Of_typed.compile typed_prg in let%bind (exp,_) = Mini_c.get_entry mini_c entry_point in let%bind compiled = Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp in let%bind options = Run.make_dry_run_options {predecessor_timestamp ; amount ; balance ; sender ; source } in let%bind michelson_output = Run.run_no_failwith ~options compiled.expr compiled.expr_ty in let%bind simplified_output = Uncompile.uncompile_typed_program_entry_expression_result typed_prg entry_point michelson_output in - ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression simplified_output + ok @@ Format.asprintf "%a\n" Ast_core.PP.expression simplified_output in let term = Term.(const f $ source_file 0 $ entry_point 1 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format) in @@ -449,15 +393,9 @@ let evaluate_value = let compile_expression = let f expression syntax display_format michelson_format = toplevel ~display_format @@ - let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (None) in let env = Ast_typed.Environment.full_empty in let state = Typer.Solver.initial_state in - let%bind abstracted = Compile.Of_source.compile_expression v_syntax expression in - let%bind complex = Compile.Of_abstracted.compile_expression abstracted in - let%bind simplified = Compile.Of_complex.compile_expression complex in - let%bind (typed_exp,_) = Compile.Of_simplified.compile_expression ~env ~state simplified in - let%bind mini_c_exp = Compile.Of_typed.compile_expression typed_exp in - let%bind compiled_exp = Compile.Of_mini_c.compile_expression mini_c_exp in + let%bind compiled_exp = Compile.Utils.compile_expression None syntax expression env state in let%bind value = Run.evaluate_expression compiled_exp.expr compiled_exp.expr_ty in ok @@ Format.asprintf "%a\n" (Main.Display.michelson_pp michelson_format) value in @@ -478,10 +416,8 @@ let dump_changelog = let list_declarations = let f source_file syntax = toplevel ~display_format:(`Human_readable) @@ - let%bind abstracted_prg = Compile.Of_source.compile source_file (Syntax_name syntax) in - let%bind complex_prg = Compile.Of_abstracted.compile abstracted_prg in - let%bind simplified_prg = Compile.Of_complex.compile complex_prg in - let json_decl = List.map (fun decl -> `String decl) @@ Compile.Of_simplified.list_declarations simplified_prg in + let%bind core_prg = Compile.Utils.to_core source_file syntax in + let json_decl = List.map (fun decl -> `String decl) @@ Compile.Of_core.list_declarations core_prg in ok @@ J.to_string @@ `Assoc [ ("source_file", `String source_file) ; ("declarations", `List json_decl) ] in let term = diff --git a/src/main/compile/dune b/src/main/compile/dune index 514fa22f5..323200979 100644 --- a/src/main/compile/dune +++ b/src/main/compile/dune @@ -9,11 +9,11 @@ ast_imperative self_ast_imperative instruction_remover - ast_complex - self_ast_complex + ast_sugar + self_ast_sugar simplifier - ast_simplified - self_ast_simplified + ast_core + self_ast_core typer_new typer ast_typed diff --git a/src/main/compile/helpers.ml b/src/main/compile/helpers.ml index d4809c9eb..4fabbd0fa 100644 --- a/src/main/compile/helpers.ml +++ b/src/main/compile/helpers.ml @@ -23,55 +23,55 @@ let parsify_pascaligo source = let%bind raw = trace (simple_error "parsing") @@ Parser.Pascaligo.parse_file source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting") @@ Abstracter.Pascaligo.abstr_program raw - in ok simplified + in ok imperative let parsify_expression_pascaligo source = let%bind raw = trace (simple_error "parsing expression") @@ Parser.Pascaligo.parse_expression source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting expression") @@ Abstracter.Pascaligo.abstr_expression raw - in ok simplified + in ok imperative let parsify_cameligo source = let%bind raw = trace (simple_error "parsing") @@ Parser.Cameligo.parse_file source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting") @@ Abstracter.Cameligo.abstr_program raw - in ok simplified + in ok imperative let parsify_expression_cameligo source = let%bind raw = trace (simple_error "parsing expression") @@ Parser.Cameligo.parse_expression source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting expression") @@ Abstracter.Cameligo.abstr_expression raw - in ok simplified + in ok imperative let parsify_reasonligo source = let%bind raw = trace (simple_error "parsing") @@ Parser.Reasonligo.parse_file source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting") @@ Abstracter.Cameligo.abstr_program raw - in ok simplified + in ok imperative let parsify_expression_reasonligo source = let%bind raw = trace (simple_error "parsing expression") @@ Parser.Reasonligo.parse_expression source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting expression") @@ Abstracter.Cameligo.abstr_expression raw - in ok simplified + in ok imperative let parsify syntax source = let%bind parsify = @@ -96,28 +96,28 @@ let parsify_string_reasonligo source = let%bind raw = trace (simple_error "parsing") @@ Parser.Reasonligo.parse_string source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting") @@ Abstracter.Cameligo.abstr_program raw - in ok simplified + in ok imperative let parsify_string_pascaligo source = let%bind raw = trace (simple_error "parsing") @@ Parser.Pascaligo.parse_string source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting") @@ Abstracter.Pascaligo.abstr_program raw - in ok simplified + in ok imperative let parsify_string_cameligo source = let%bind raw = trace (simple_error "parsing") @@ Parser.Cameligo.parse_string source in - let%bind simplified = + let%bind imperative = trace (simple_error "abstracting") @@ Abstracter.Cameligo.abstr_program raw - in ok simplified + in ok imperative let parsify_string syntax source = let%bind parsify = diff --git a/src/main/compile/of_simplified.ml b/src/main/compile/of_core.ml similarity index 59% rename from src/main/compile/of_simplified.ml rename to src/main/compile/of_core.ml index 01e3a4562..c6c48c299 100644 --- a/src/main/compile/of_simplified.ml +++ b/src/main/compile/of_core.ml @@ -4,7 +4,7 @@ type form = | Contract of string | Env -let compile (cform: form) (program : Ast_simplified.program) : (Ast_typed.program * Typer.Solver.state) result = +let compile (cform: form) (program : Ast_core.program) : (Ast_typed.program * Typer.Solver.state) result = let%bind (prog_typed , state) = Typer.type_program program in let () = Typer.Solver.discard_state state in let%bind applied = Self_ast_typed.all_program prog_typed in @@ -13,31 +13,31 @@ let compile (cform: form) (program : Ast_simplified.program) : (Ast_typed.progra | Env -> ok applied in ok @@ (applied', state) -let compile_expression ?(env = Ast_typed.Environment.full_empty) ~(state : Typer.Solver.state) (e : Ast_simplified.expression) +let compile_expression ?(env = Ast_typed.Environment.full_empty) ~(state : Typer.Solver.state) (e : Ast_core.expression) : (Ast_typed.expression * Typer.Solver.state) result = let%bind (ae_typed,state) = Typer.type_expression_subst env state e in let () = Typer.Solver.discard_state state in let%bind ae_typed' = Self_ast_typed.all_expression ae_typed in ok @@ (ae_typed',state) -let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simplified.expression result = +let apply (entry_point : string) (param : Ast_core.expression) : Ast_core.expression result = let name = Var.of_name entry_point in - let entry_point_var : Ast_simplified.expression = - { expression_content = Ast_simplified.E_variable name ; + let entry_point_var : Ast_core.expression = + { expression_content = Ast_core.E_variable name ; location = Virtual "generated entry-point variable" } in - let applied : Ast_simplified.expression = - { expression_content = Ast_simplified.E_application {expr1=entry_point_var; expr2=param} ; + let applied : Ast_core.expression = + { expression_content = Ast_core.E_application {expr1=entry_point_var; expr2=param} ; location = Virtual "generated application" } in ok applied -let pretty_print formatter (program : Ast_simplified.program) = - Ast_simplified.PP.program formatter program +let pretty_print formatter (program : Ast_core.program) = + Ast_core.PP.program formatter program -let list_declarations (program : Ast_simplified.program) : string list = +let list_declarations (program : Ast_core.program) : string list = List.fold_left (fun prev el -> let open Location in - let open Ast_simplified in + let open Ast_core in match el.wrap_content with | Declaration_constant (var,_,_,_) -> (Var.to_name var)::prev | _ -> prev) diff --git a/src/main/compile/of_abstracted.ml b/src/main/compile/of_imperative.ml similarity index 79% rename from src/main/compile/of_abstracted.ml rename to src/main/compile/of_imperative.ml index b56b1991d..cc84ff4d7 100644 --- a/src/main/compile/of_abstracted.ml +++ b/src/main/compile/of_imperative.ml @@ -6,10 +6,10 @@ type form = | Contract of string | Env -let compile (program : program) : Ast_complex.program result = +let compile (program : program) : Ast_sugar.program result = remove_instruction_in_program program -let compile_expression (e : expression) : Ast_complex.expression result = +let compile_expression (e : expression) : Ast_sugar.expression result = remove_instruction_in_expression e let pretty_print formatter (program : program) = diff --git a/src/main/compile/of_complex.ml b/src/main/compile/of_sugar.ml similarity index 74% rename from src/main/compile/of_complex.ml rename to src/main/compile/of_sugar.ml index 390737bbd..9073bf615 100644 --- a/src/main/compile/of_complex.ml +++ b/src/main/compile/of_sugar.ml @@ -1,15 +1,15 @@ open Trace -open Ast_complex +open Ast_sugar open Simplifier type form = | Contract of string | Env -let compile (program : program) : Ast_simplified.program result = +let compile (program : program) : Ast_core.program result = simplify_program program -let compile_expression (e : expression) : Ast_simplified.expression result = +let compile_expression (e : expression) : Ast_core.expression result = simplify_expression e let pretty_print formatter (program : program) = diff --git a/src/main/compile/utils.ml b/src/main/compile/utils.ml new file mode 100644 index 000000000..ab8ac6503 --- /dev/null +++ b/src/main/compile/utils.ml @@ -0,0 +1,65 @@ +open Trace + +let to_imperatve f stx = + let%bind imperative = Of_source.compile f (Syntax_name stx) in + ok @@ imperative + +let to_sugar f stx = + let%bind imperative = to_imperatve f stx in + let%bind sugar = Of_imperative.compile imperative in + ok @@ sugar + +let to_core f stx = + let%bind sugar = to_sugar f stx in + let%bind core = Of_sugar.compile sugar in + ok @@ core + +let type_file f stx env = + let%bind core = to_core f stx in + let%bind typed,state = Of_core.compile env core in + ok @@ (typed,state) + +let to_mini_c f stx env = + let%bind typed, _ = type_file f stx env in + let%bind mini_c = Of_typed.compile typed in + ok @@ mini_c + +let compile_file f stx ep = + let%bind typed, _ = type_file f stx @@ Contract ep in + let%bind mini_c = Of_typed.compile typed in + let%bind michelson = Of_mini_c.aggregate_and_compile_contract mini_c ep in + let%bind contract = Of_michelson.build_contract michelson in + ok @@ contract + +let type_expression source_file syntax expression env state = + let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) source_file in + let%bind imperative_exp = Of_source.compile_expression v_syntax expression in + let%bind sugar_exp = Of_imperative.compile_expression imperative_exp in + let%bind core_exp = Of_sugar.compile_expression sugar_exp in + let%bind (typed_exp,state) = Of_core.compile_expression ~env ~state core_exp in + ok @@ (typed_exp,state) + +let expression_to_mini_c source_file syntax expression env state = + let%bind (typed_exp,_) = type_expression source_file syntax expression env state in + let%bind mini_c_exp = Of_typed.compile_expression typed_exp in + ok @@ mini_c_exp + +let compile_expression source_file syntax expression env state = + let%bind mini_c_exp = expression_to_mini_c source_file syntax expression env state in + let%bind compiled = Of_mini_c.compile_expression mini_c_exp in + ok @@ compiled + +let compile_and_aggregate_expression source_file syntax expression env state mini_c_prg = + let%bind mini_c_exp = expression_to_mini_c source_file syntax expression env state in + let%bind compiled = Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c_exp in + ok @@ compiled + +let compile_storage storage input source_file syntax env state mini_c_prg = + let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in + let%bind imperative = Of_source.compile_contract_input storage input v_syntax in + let%bind sugar = Of_imperative.compile_expression imperative in + let%bind core = Of_sugar.compile_expression sugar in + let%bind typed,_ = Of_core.compile_expression ~env ~state core in + let%bind mini_c = Of_typed.compile_expression typed in + let%bind compiled = Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c in + ok @@ compiled diff --git a/src/main/run/dune b/src/main/run/dune index ad6ef9cc5..55644e553 100644 --- a/src/main/run/dune +++ b/src/main/run/dune @@ -8,7 +8,7 @@ abstracter self_ast_imperative simplifier - ast_simplified + ast_core typer_new typer ast_typed diff --git a/src/passes/2-abstracter/camligo.ml.old b/src/passes/2-abstracter/camligo.ml.old index deb987624..7789d796d 100644 --- a/src/passes/2-abstracter/camligo.ml.old +++ b/src/passes/2-abstracter/camligo.ml.old @@ -1,7 +1,7 @@ open Trace open Function module I = Parser.Cameligo.Ast -module O = Ast_simplified +module O = Ast_core open O.Combinators let unwrap : type a . a Location.wrap -> a = Location.unwrap diff --git a/src/passes/2-abstracter/pascaligo.mli b/src/passes/2-abstracter/pascaligo.mli index 652c77d99..ec68d93c9 100644 --- a/src/passes/2-abstracter/pascaligo.mli +++ b/src/passes/2-abstracter/pascaligo.mli @@ -6,10 +6,10 @@ open Ast_imperative module Raw = Parser.Pascaligo.AST module SMap = Map.String -(** Convert a concrete PascaLIGO expression AST to the simplified +(** Convert a concrete PascaLIGO expression AST to the imperative expression AST used by the compiler. *) val abstr_expression : Raw.expr -> expr result -(** Convert a concrete PascaLIGO program AST to the simplified program +(** Convert a concrete PascaLIGO program AST to the miperative program AST used by the compiler. *) val abstr_program : Raw.ast -> program result diff --git a/src/passes/4-Instruction_remover/dune b/src/passes/4-Instruction_remover/dune index eb702bf26..8b3b3e071 100644 --- a/src/passes/4-Instruction_remover/dune +++ b/src/passes/4-Instruction_remover/dune @@ -4,7 +4,7 @@ (libraries simple-utils ast_imperative - ast_complex + ast_sugar proto-alpha-utils ) (preprocess diff --git a/src/passes/4-Instruction_remover/instruction_remover.ml b/src/passes/4-Instruction_remover/instruction_remover.ml index 816ed47b9..7943419c2 100644 --- a/src/passes/4-Instruction_remover/instruction_remover.ml +++ b/src/passes/4-Instruction_remover/instruction_remover.ml @@ -1,5 +1,5 @@ module I = Ast_imperative -module O = Ast_complex +module O = Ast_sugar open Trace let rec idle_type_expression : I.type_expression -> O.type_expression result = diff --git a/src/passes/5-self_ast_complex/dune b/src/passes/5-self_ast_complex/dune index 819a5ad1f..33b51be08 100644 --- a/src/passes/5-self_ast_complex/dune +++ b/src/passes/5-self_ast_complex/dune @@ -1,9 +1,9 @@ (library - (name self_ast_complex) - (public_name ligo.self_ast_complex) + (name self_ast_sugar) + (public_name ligo.self_ast_sugar) (libraries simple-utils - ast_complex + ast_sugar proto-alpha-utils ) (preprocess diff --git a/src/passes/6-simplifier/dune b/src/passes/6-simplifier/dune index a693dcd19..78556f444 100644 --- a/src/passes/6-simplifier/dune +++ b/src/passes/6-simplifier/dune @@ -3,8 +3,8 @@ (public_name ligo.simplifier) (libraries simple-utils - ast_complex - ast_simplified + ast_sugar + ast_core proto-alpha-utils ) (preprocess diff --git a/src/passes/6-simplifier/simplifier.ml b/src/passes/6-simplifier/simplifier.ml index fd396705e..3b70281ee 100644 --- a/src/passes/6-simplifier/simplifier.ml +++ b/src/passes/6-simplifier/simplifier.ml @@ -1,5 +1,5 @@ -module I = Ast_complex -module O = Ast_simplified +module I = Ast_sugar +module O = Ast_core open Trace let rec idle_type_expression : I.type_expression -> O.type_expression result = diff --git a/src/passes/7-self_ast_simplified/dune b/src/passes/7-self_ast_simplified/dune index aef575249..e51afd86e 100644 --- a/src/passes/7-self_ast_simplified/dune +++ b/src/passes/7-self_ast_simplified/dune @@ -1,9 +1,9 @@ (library - (name self_ast_simplified) - (public_name ligo.self_ast_simplified) + (name self_ast_core) + (public_name ligo.self_ast_core) (libraries simple-utils - ast_simplified + ast_core proto-alpha-utils ) (preprocess diff --git a/src/passes/8-typer-new/dune b/src/passes/8-typer-new/dune index 645a7053f..b7bbee5f4 100644 --- a/src/passes/8-typer-new/dune +++ b/src/passes/8-typer-new/dune @@ -4,7 +4,7 @@ (libraries simple-utils tezos-utils - ast_simplified + ast_core ast_typed operators UnionFind diff --git a/src/passes/8-typer-new/solver.ml b/src/passes/8-typer-new/solver.ml index aad418cb5..328cfe015 100644 --- a/src/passes/8-typer-new/solver.ml +++ b/src/passes/8-typer-new/solver.ml @@ -3,7 +3,7 @@ open Trace module Core = Typesystem.Core module Wrap = struct - module I = Ast_simplified + module I = Ast_core module T = Ast_typed module O = Core diff --git a/src/passes/8-typer-new/typer.ml b/src/passes/8-typer-new/typer.ml index a796d0ede..555ec8ae8 100644 --- a/src/passes/8-typer-new/typer.ml +++ b/src/passes/8-typer-new/typer.ml @@ -1,6 +1,6 @@ open Trace -module I = Ast_simplified +module I = Ast_core module O = Ast_typed open O.Combinators @@ -872,7 +872,7 @@ let untype_type_value (t:O.type_expression) : (I.type_expression) result = (* TODO: we ended up with two versions of type_program… ??? *) (* -Apply type_declaration on all the node of the AST_simplified from the root p +Apply type_declaration on all the node of the AST_core from the root p *) let type_program_returns_state ((env, state, p) : environment * Solver.state * I.program) : (environment * Solver.state * O.program) result = let aux ((e : environment), (s : Solver.state) , (ds : O.declaration Location.wrap list)) (d:I.declaration Location.wrap) = @@ -950,10 +950,10 @@ let type_program' : I.program -> O.program result = fun p -> ok p' (* - Tranform a Ast_typed type_expression into an ast_simplified type_expression + Tranform a Ast_typed type_expression into an ast_core type_expression *) let rec untype_type_expression (t:O.type_expression) : (I.type_expression) result = - (* TODO: or should we use t.simplified if present? *) + (* TODO: or should we use t.core if present? *) let%bind t = match t.type_content with | O.T_sum x -> let%bind x' = Stage_common.Helpers.bind_map_cmap untype_type_expression x in @@ -999,13 +999,13 @@ let rec untype_type_expression (t:O.type_expression) : (I.type_expression) resul in ok @@ I.make_t t -(* match t.simplified with *) +(* match t.core with *) (* | Some s -> ok s *) (* | _ -> fail @@ internal_assertion_failure "trying to untype generated type" *) (* - Tranform a Ast_typed literal into an ast_simplified literal + Tranform a Ast_typed literal into an ast_core literal *) let untype_literal (l:O.literal) : I.literal result = let open I in @@ -1027,7 +1027,7 @@ let untype_literal (l:O.literal) : I.literal result = | Literal_operation s -> ok (Literal_operation s) (* - Tranform a Ast_typed expression into an ast_simplified matching + Tranform a Ast_typed expression into an ast_core matching *) let rec untype_expression (e:O.expression) : (I.expression) result = let open I in @@ -1107,7 +1107,7 @@ and untype_lambda ty {binder; result} : I.lambda result = ok ({binder;input_type = Some input_type; output_type = Some output_type; result}: I.lambda) (* - Tranform a Ast_typed matching into an ast_simplified matching + Tranform a Ast_typed matching into an ast_core matching *) and untype_matching : (O.expression -> I.expression result) -> O.matching_expr -> I.matching_expr result = fun f m -> let open I in diff --git a/src/passes/8-typer-new/typer.ml.old b/src/passes/8-typer-new/typer.ml.old index db842716a..66b918235 100644 --- a/src/passes/8-typer-new/typer.ml.old +++ b/src/passes/8-typer-new/typer.ml.old @@ -1,6 +1,6 @@ open Trace -module I = Ast_simplified +module I = Ast_core module O = Ast_typed open O.Combinators @@ -736,7 +736,7 @@ and type_constant (name:string) (lst:O.type_expression list) (tv_opt:O.type_expr typer lst tv_opt let untype_type_expression (t:O.type_expression) : (I.type_expression) result = - match t.simplified with + match t.core with | Some s -> ok s | _ -> fail @@ internal_assertion_failure "trying to untype generated type" diff --git a/src/passes/8-typer-new/typer.mli b/src/passes/8-typer-new/typer.mli index 29b7cad08..6e24e7359 100644 --- a/src/passes/8-typer-new/typer.mli +++ b/src/passes/8-typer-new/typer.mli @@ -1,6 +1,6 @@ open Trace -module I = Ast_simplified +module I = Ast_core module O = Ast_typed module Environment = O.Environment diff --git a/src/passes/8-typer-old/dune b/src/passes/8-typer-old/dune index 29e48c79e..faec4e901 100644 --- a/src/passes/8-typer-old/dune +++ b/src/passes/8-typer-old/dune @@ -4,7 +4,7 @@ (libraries simple-utils tezos-utils - ast_simplified + ast_core ast_typed typer_new operators diff --git a/src/passes/8-typer-old/typer.ml b/src/passes/8-typer-old/typer.ml index e1cf018e2..52586508d 100644 --- a/src/passes/8-typer-old/typer.ml +++ b/src/passes/8-typer-old/typer.ml @@ -1,6 +1,6 @@ open Trace -module I = Ast_simplified +module I = Ast_core module O = Ast_typed open O.Combinators diff --git a/src/passes/8-typer-old/typer.mli b/src/passes/8-typer-old/typer.mli index 9b1e986da..d1bf21393 100644 --- a/src/passes/8-typer-old/typer.mli +++ b/src/passes/8-typer-old/typer.mli @@ -1,6 +1,6 @@ open Trace -module I = Ast_simplified +module I = Ast_core module O = Ast_typed module Environment = O.Environment diff --git a/src/passes/8-typer/dune b/src/passes/8-typer/dune index 35c5e807d..f6072da39 100644 --- a/src/passes/8-typer/dune +++ b/src/passes/8-typer/dune @@ -4,7 +4,7 @@ (libraries simple-utils tezos-utils - ast_simplified + ast_core ast_typed typer_old typer_new diff --git a/src/passes/8-typer/typer.ml b/src/passes/8-typer/typer.ml index 8ab5576a0..48f1ac011 100644 --- a/src/passes/8-typer/typer.ml +++ b/src/passes/8-typer/typer.ml @@ -1,6 +1,6 @@ let use_new_typer = false -module I = Ast_simplified +module I = Ast_core module O = Ast_typed module Environment = O.Environment diff --git a/src/passes/8-typer/typer.mli b/src/passes/8-typer/typer.mli index bb8ac3094..bf4c11f4d 100644 --- a/src/passes/8-typer/typer.mli +++ b/src/passes/8-typer/typer.mli @@ -2,7 +2,7 @@ val use_new_typer : bool open Trace -module I = Ast_simplified +module I = Ast_core module O = Ast_typed module Environment = O.Environment diff --git a/src/passes/operators/dune b/src/passes/operators/dune index 4eb539830..fa69f6257 100644 --- a/src/passes/operators/dune +++ b/src/passes/operators/dune @@ -5,8 +5,8 @@ simple-utils tezos-utils ast_imperative - ast_complex - ast_simplified + ast_sugar + ast_core ast_typed typesystem mini_c diff --git a/src/passes/operators/operators.ml b/src/passes/operators/operators.ml index abd16ae55..cf6f04e5c 100644 --- a/src/passes/operators/operators.ml +++ b/src/passes/operators/operators.ml @@ -17,7 +17,7 @@ module Abstracter = struct Constants are special names that have their own case in the AST. E_constant for regular constants, and T_constant for type constants. Both types are - defined in `Ast_simplified/types.ml`. + defined in `Ast_core/types.ml`. For instance, "2 + 2" in Pascaligo is translated to `E_constant ("ADD" , [ E_literal (Literal_int 2) ; E_literal (Literal_int 2) ; diff --git a/src/stages/1-ast_imperative/combinators.ml b/src/stages/1-ast_imperative/combinators.ml index a37a1b7ef..ceacdcc4e 100644 --- a/src/stages/1-ast_imperative/combinators.ml +++ b/src/stages/1-ast_imperative/combinators.ml @@ -237,7 +237,7 @@ let tuple_of_record (m: _ LMap.t) = let get_e_tuple = fun t -> match t with | E_record r -> ok @@ tuple_of_record r - | _ -> simple_fail "ast_simplified: get_e_tuple: not a tuple" + | _ -> simple_fail "ast_core: get_e_tuple: not a tuple" (* Same as get_e_pair *) let extract_pair : expression -> (expression * expression) result = fun e -> diff --git a/src/stages/1-ast_imperative/types.ml b/src/stages/1-ast_imperative/types.ml index 75d17207f..6d64cafd1 100644 --- a/src/stages/1-ast_imperative/types.ml +++ b/src/stages/1-ast_imperative/types.ml @@ -8,7 +8,7 @@ end include Stage_common.Types -(*include Ast_generic_type(Ast_simplified_parameter) +(*include Ast_generic_type(Ast_core_parameter) *) include Ast_generic_type (Ast_imperative_parameter) diff --git a/src/stages/2-ast_complex/PP.ml b/src/stages/2-ast_sugar/PP.ml similarity index 99% rename from src/stages/2-ast_complex/PP.ml rename to src/stages/2-ast_sugar/PP.ml index d6e949751..c1288c6f3 100644 --- a/src/stages/2-ast_complex/PP.ml +++ b/src/stages/2-ast_sugar/PP.ml @@ -4,7 +4,7 @@ open Format open PP_helpers include Stage_common.PP -include Ast_PP_type(Ast_complex_parameter) +include Ast_PP_type(Ast_sugar_parameter) let expression_variable ppf (ev : expression_variable) : unit = fprintf ppf "%a" Var.pp ev diff --git a/src/stages/2-ast_complex/ast_complex.ml b/src/stages/2-ast_sugar/ast_sugar.ml similarity index 100% rename from src/stages/2-ast_complex/ast_complex.ml rename to src/stages/2-ast_sugar/ast_sugar.ml diff --git a/src/stages/2-ast_complex/combinators.ml b/src/stages/2-ast_sugar/combinators.ml similarity index 99% rename from src/stages/2-ast_complex/combinators.ml rename to src/stages/2-ast_sugar/combinators.ml index 9ac673a3c..04a336e93 100644 --- a/src/stages/2-ast_complex/combinators.ml +++ b/src/stages/2-ast_sugar/combinators.ml @@ -237,7 +237,7 @@ let tuple_of_record (m: _ LMap.t) = let get_e_tuple = fun t -> match t with | E_record r -> ok @@ tuple_of_record r - | _ -> simple_fail "ast_simplified: get_e_tuple: not a tuple" + | _ -> simple_fail "ast_core: get_e_tuple: not a tuple" (* Same as get_e_pair *) let extract_pair : expression -> (expression * expression) result = fun e -> diff --git a/src/stages/2-ast_complex/combinators.mli b/src/stages/2-ast_sugar/combinators.mli similarity index 100% rename from src/stages/2-ast_complex/combinators.mli rename to src/stages/2-ast_sugar/combinators.mli diff --git a/src/stages/2-ast_complex/dune b/src/stages/2-ast_sugar/dune similarity index 77% rename from src/stages/2-ast_complex/dune rename to src/stages/2-ast_sugar/dune index 4e1dac4af..6f1ca6fef 100644 --- a/src/stages/2-ast_complex/dune +++ b/src/stages/2-ast_sugar/dune @@ -1,6 +1,6 @@ (library - (name ast_complex) - (public_name ligo.ast_complex) + (name ast_sugar) + (public_name ligo.ast_sugar) (libraries simple-utils tezos-utils diff --git a/src/stages/2-ast_complex/misc.ml b/src/stages/2-ast_sugar/misc.ml similarity index 100% rename from src/stages/2-ast_complex/misc.ml rename to src/stages/2-ast_sugar/misc.ml diff --git a/src/stages/2-ast_complex/misc.mli b/src/stages/2-ast_sugar/misc.mli similarity index 100% rename from src/stages/2-ast_complex/misc.mli rename to src/stages/2-ast_sugar/misc.mli diff --git a/src/stages/2-ast_complex/types.ml b/src/stages/2-ast_sugar/types.ml similarity index 95% rename from src/stages/2-ast_complex/types.ml rename to src/stages/2-ast_sugar/types.ml index 70a348975..dffb887bb 100644 --- a/src/stages/2-ast_complex/types.ml +++ b/src/stages/2-ast_sugar/types.ml @@ -2,15 +2,15 @@ module Location = Simple_utils.Location -module Ast_complex_parameter = struct +module Ast_sugar_parameter = struct type type_meta = unit end include Stage_common.Types -(*include Ast_generic_type(Ast_simplified_parameter) +(*include Ast_generic_type(Ast_core_parameter) *) -include Ast_generic_type (Ast_complex_parameter) +include Ast_generic_type (Ast_sugar_parameter) type inline = bool type program = declaration Location.wrap list diff --git a/src/stages/3-ast_simplified/PP.ml b/src/stages/3-ast_core/PP.ml similarity index 99% rename from src/stages/3-ast_simplified/PP.ml rename to src/stages/3-ast_core/PP.ml index fa4404307..bd1f13ad5 100644 --- a/src/stages/3-ast_simplified/PP.ml +++ b/src/stages/3-ast_core/PP.ml @@ -4,7 +4,7 @@ open Format open PP_helpers include Stage_common.PP -include Ast_PP_type(Ast_simplified_parameter) +include Ast_PP_type(Ast_core_parameter) let expression_variable ppf (ev : expression_variable) : unit = fprintf ppf "%a" Var.pp ev diff --git a/src/stages/3-ast_simplified/ast_simplified.ml b/src/stages/3-ast_core/ast_core.ml similarity index 100% rename from src/stages/3-ast_simplified/ast_simplified.ml rename to src/stages/3-ast_core/ast_core.ml diff --git a/src/stages/3-ast_simplified/combinators.ml b/src/stages/3-ast_core/combinators.ml similarity index 99% rename from src/stages/3-ast_simplified/combinators.ml rename to src/stages/3-ast_core/combinators.ml index 2a5e60aff..9ea3f592c 100644 --- a/src/stages/3-ast_simplified/combinators.ml +++ b/src/stages/3-ast_core/combinators.ml @@ -237,7 +237,7 @@ let tuple_of_record (m: _ LMap.t) = let get_e_tuple = fun t -> match t with | E_record r -> ok @@ tuple_of_record r - | _ -> simple_fail "ast_simplified: get_e_tuple: not a tuple" + | _ -> simple_fail "ast_core: get_e_tuple: not a tuple" (* Same as get_e_pair *) let extract_pair : expression -> (expression * expression) result = fun e -> diff --git a/src/stages/3-ast_simplified/combinators.mli b/src/stages/3-ast_core/combinators.mli similarity index 100% rename from src/stages/3-ast_simplified/combinators.mli rename to src/stages/3-ast_core/combinators.mli diff --git a/src/stages/3-ast_simplified/dune b/src/stages/3-ast_core/dune similarity index 75% rename from src/stages/3-ast_simplified/dune rename to src/stages/3-ast_core/dune index f6c961536..ce45b1899 100644 --- a/src/stages/3-ast_simplified/dune +++ b/src/stages/3-ast_core/dune @@ -1,6 +1,6 @@ (library - (name ast_simplified) - (public_name ligo.ast_simplified) + (name ast_core) + (public_name ligo.ast_core) (libraries simple-utils tezos-utils diff --git a/src/stages/3-ast_simplified/misc.ml b/src/stages/3-ast_core/misc.ml similarity index 100% rename from src/stages/3-ast_simplified/misc.ml rename to src/stages/3-ast_core/misc.ml diff --git a/src/stages/3-ast_simplified/misc.mli b/src/stages/3-ast_core/misc.mli similarity index 100% rename from src/stages/3-ast_simplified/misc.mli rename to src/stages/3-ast_core/misc.mli diff --git a/src/stages/3-ast_simplified/types.ml b/src/stages/3-ast_core/types.ml similarity index 95% rename from src/stages/3-ast_simplified/types.ml rename to src/stages/3-ast_core/types.ml index ef2e32f36..07a36d361 100644 --- a/src/stages/3-ast_simplified/types.ml +++ b/src/stages/3-ast_core/types.ml @@ -2,15 +2,15 @@ module Location = Simple_utils.Location -module Ast_simplified_parameter = struct +module Ast_core_parameter = struct type type_meta = unit end include Stage_common.Types -(*include Ast_generic_type(Ast_simplified_parameter) +(*include Ast_generic_type(Ast_core_parameter) *) -include Ast_generic_type (Ast_simplified_parameter) +include Ast_generic_type (Ast_core_parameter) type inline = bool type program = declaration Location.wrap list diff --git a/src/stages/4-ast_typed/combinators.ml b/src/stages/4-ast_typed/combinators.ml index d6f1e8da5..e9071df97 100644 --- a/src/stages/4-ast_typed/combinators.ml +++ b/src/stages/4-ast_typed/combinators.ml @@ -23,7 +23,7 @@ module Errors = struct error (thunk "No declaration with the given name") message end -let make_t type_content simplified = { type_content ; type_meta=simplified } +let make_t type_content core = { type_content ; type_meta=core } let make_a_e ?(location = Location.generated) expression_content type_expression environment = { expression_content ; type_expression ; diff --git a/src/stages/4-ast_typed/dune b/src/stages/4-ast_typed/dune index 7eed79e47..d33c8dac6 100644 --- a/src/stages/4-ast_typed/dune +++ b/src/stages/4-ast_typed/dune @@ -4,7 +4,7 @@ (libraries simple-utils tezos-utils - ast_simplified ; Is that a good idea? + ast_core ; Is that a good idea? stage_common ) (preprocess diff --git a/src/stages/4-ast_typed/types.ml b/src/stages/4-ast_typed/types.ml index af143aa89..b5a35061f 100644 --- a/src/stages/4-ast_typed/types.ml +++ b/src/stages/4-ast_typed/types.ml @@ -1,6 +1,6 @@ [@@@warning "-30"] -module S = Ast_simplified +module S = Ast_core include Stage_common.Types module Ast_typed_type_parameter = struct diff --git a/src/stages/typesystem/misc.ml b/src/stages/typesystem/misc.ml index 223a94610..dcb46929b 100644 --- a/src/stages/typesystem/misc.ml +++ b/src/stages/typesystem/misc.ml @@ -89,24 +89,24 @@ module Substitution = struct let _TODO = substs in failwith "TODO: T_function" - and s_abstr_type_content : Ast_simplified.type_content w = fun ~substs -> function - | Ast_simplified.T_sum _ -> failwith "TODO: subst: unimplemented case s_type_expression sum" - | Ast_simplified.T_record _ -> failwith "TODO: subst: unimplemented case s_type_expression record" - | Ast_simplified.T_arrow _ -> failwith "TODO: subst: unimplemented case s_type_expression arrow" - | Ast_simplified.T_variable _ -> failwith "TODO: subst: unimplemented case s_type_expression variable" - | Ast_simplified.T_operator op -> + and s_abstr_type_content : Ast_core.type_content w = fun ~substs -> function + | Ast_core.T_sum _ -> failwith "TODO: subst: unimplemented case s_type_expression sum" + | Ast_core.T_record _ -> failwith "TODO: subst: unimplemented case s_type_expression record" + | Ast_core.T_arrow _ -> failwith "TODO: subst: unimplemented case s_type_expression arrow" + | Ast_core.T_variable _ -> failwith "TODO: subst: unimplemented case s_type_expression variable" + | Ast_core.T_operator op -> let%bind op = - Ast_simplified.bind_map_type_operator + Ast_core.bind_map_type_operator (s_abstr_type_expression ~substs) op in (* TODO: when we have generalized operators, we might need to subst the operator name itself? *) - ok @@ Ast_simplified.T_operator op - | Ast_simplified.T_constant constant -> - ok @@ Ast_simplified.T_constant constant + ok @@ Ast_core.T_operator op + | Ast_core.T_constant constant -> + ok @@ Ast_core.T_constant constant - and s_abstr_type_expression : Ast_simplified.type_expression w = fun ~substs {type_content;type_meta} -> + and s_abstr_type_expression : Ast_core.type_expression w = fun ~substs {type_content;type_meta} -> let%bind type_content = s_abstr_type_content ~substs type_content in - ok @@ Ast_simplified.{type_content;type_meta} + ok @@ Ast_core.{type_content;type_meta} and s_type_expression : T.type_expression w = fun ~substs { type_content; type_meta } -> let%bind type_content = s_type_content ~substs type_content in diff --git a/src/test/coase_tests.ml b/src/test/coase_tests.ml index b773764f9..73520c60e 100644 --- a/src/test/coase_tests.ml +++ b/src/test/coase_tests.ml @@ -4,10 +4,7 @@ open Trace open Test_helpers let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") in ok @@ (typed,state) let get_program = @@ -30,7 +27,7 @@ let compile_main () = Ligo.Compile.Of_michelson.build_contract michelson_prg in ok () -open Ast_simplified +open Ast_core let card owner = e_record_ez [ @@ -231,7 +228,7 @@ let sell () = let expected_storage = let cards = List.hds @@ cards_ez first_owner n in basic 99 1000 cards (2 * n) in - Ast_simplified.Misc.assert_value_eq (expected_storage , storage) + Ast_core.Misc.assert_value_eq (expected_storage , storage) in let%bind () = let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in diff --git a/src/test/hash_lock_tests.ml b/src/test/hash_lock_tests.ml index 9ebfe3618..d6bfd7aed 100644 --- a/src/test/hash_lock_tests.ml +++ b/src/test/hash_lock_tests.ml @@ -1,12 +1,9 @@ open Trace open Test_helpers -open Ast_simplified +open Ast_core let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") in ok @@ (typed,state) let get_program = diff --git a/src/test/id_tests.ml b/src/test/id_tests.ml index bedc465db..8632c78e0 100644 --- a/src/test/id_tests.ml +++ b/src/test/id_tests.ml @@ -1,13 +1,10 @@ open Trace open Test_helpers -open Ast_simplified +open Ast_core let mtype_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") in ok (typed,state) let get_program = diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 9fcb5f261..8b84434ed 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1,28 +1,18 @@ open Trace open Test_helpers -open Ast_simplified.Combinators +open Ast_core.Combinators let retype_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "reasonligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in - let () = Typer.Solver.discard_state state in + let%bind typed,state = Ligo.Compile.Utils.type_file f "reasonligo" Env in let () = Typer.Solver.discard_state state in ok typed let mtype_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" Env in let () = Typer.Solver.discard_state state in ok typed let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" Env in let () = Typer.Solver.discard_state state in ok typed @@ -434,52 +424,52 @@ let bytes_arithmetic () : unit result = let%bind () = expect_eq program "slice_op" tata at in let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" ba in - let%bind b1 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foo in + let%bind b1 = Test_helpers.run_typed_program_with_core_input program "hasherman" foo in let%bind () = expect_eq program "hasherman" foo b1 in - let%bind b3 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in + let%bind b3 = Test_helpers.run_typed_program_with_core_input program "hasherman" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b3 , b1) in ok () let crypto () : unit result = let%bind program = type_file "./contracts/crypto.ligo" in let%bind foo = e_bytes_hex "0f00" in let%bind foototo = e_bytes_hex "0f007070" in - let%bind b1 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foo in + let%bind b1 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foo in let%bind () = expect_eq program "hasherman512" foo b1 in - let%bind b2 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b2 , b1) in - let%bind b4 = Test_helpers.run_typed_program_with_simplified_input program "hasherman_blake" foo in + let%bind b2 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b2 , b1) in + let%bind b4 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foo in let%bind () = expect_eq program "hasherman_blake" foo b4 in - let%bind b5 = Test_helpers.run_typed_program_with_simplified_input program "hasherman_blake" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b5 , b4) in + let%bind b5 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b5 , b4) in ok () let crypto_mligo () : unit result = let%bind program = mtype_file "./contracts/crypto.mligo" in let%bind foo = e_bytes_hex "0f00" in let%bind foototo = e_bytes_hex "0f007070" in - let%bind b1 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foo in + let%bind b1 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foo in let%bind () = expect_eq program "hasherman512" foo b1 in - let%bind b2 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b2 , b1) in - let%bind b4 = Test_helpers.run_typed_program_with_simplified_input program "hasherman_blake" foo in + let%bind b2 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b2 , b1) in + let%bind b4 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foo in let%bind () = expect_eq program "hasherman_blake" foo b4 in - let%bind b5 = Test_helpers.run_typed_program_with_simplified_input program "hasherman_blake" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b5 , b4) in + let%bind b5 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b5 , b4) in ok () let crypto_religo () : unit result = let%bind program = retype_file "./contracts/crypto.religo" in let%bind foo = e_bytes_hex "0f00" in let%bind foototo = e_bytes_hex "0f007070" in - let%bind b1 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foo in + let%bind b1 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foo in let%bind () = expect_eq program "hasherman512" foo b1 in - let%bind b2 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b2 , b1) in - let%bind b4 = Test_helpers.run_typed_program_with_simplified_input program "hasherman_blake" foo in + let%bind b2 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b2 , b1) in + let%bind b4 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foo in let%bind () = expect_eq program "hasherman_blake" foo b4 in - let%bind b5 = Test_helpers.run_typed_program_with_simplified_input program "hasherman_blake" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b5 , b4) in + let%bind b5 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b5 , b4) in ok () let bytes_arithmetic_mligo () : unit result = @@ -496,10 +486,10 @@ let bytes_arithmetic_mligo () : unit result = let%bind () = expect_eq program "slice_op" tata at in let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" ba in - let%bind b1 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foo in + let%bind b1 = Test_helpers.run_typed_program_with_core_input program "hasherman" foo in let%bind () = expect_eq program "hasherman" foo b1 in - let%bind b3 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in + let%bind b3 = Test_helpers.run_typed_program_with_core_input program "hasherman" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b3 , b1) in ok () let bytes_arithmetic_religo () : unit result = @@ -516,10 +506,10 @@ let bytes_arithmetic_religo () : unit result = let%bind () = expect_eq program "slice_op" tata at in let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" ba in - let%bind b1 = Test_helpers.run_typed_program_with_simplified_input program"hasherman" foo in + let%bind b1 = Test_helpers.run_typed_program_with_core_input program"hasherman" foo in let%bind () = expect_eq program "hasherman" foo b1 in - let%bind b3 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foototo in - let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in + let%bind b3 = Test_helpers.run_typed_program_with_core_input program "hasherman" foototo in + let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b3 , b1) in ok () let set_arithmetic () : unit result = @@ -984,7 +974,7 @@ let reoption () : unit result = let map_ type_f path : unit result = let%bind program = type_f path in let ez lst = - let open Ast_simplified.Combinators in + let open Ast_core.Combinators in let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in e_typed_map lst' t_int t_int in @@ -1073,7 +1063,7 @@ let map_ type_f path : unit result = let big_map_ type_f path : unit result = let%bind program = type_f path in let ez lst = - let open Ast_simplified.Combinators in + let open Ast_core.Combinators in let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in (e_typed_big_map lst' t_int t_int) in @@ -1286,7 +1276,7 @@ let loop () : unit result = expect_eq program "inner_capture_in_conditional_block" input expected in let%bind () = let ez lst = - let open Ast_simplified.Combinators in + let open Ast_core.Combinators in let lst' = List.map (fun (x, y) -> e_string x, e_int y) lst in e_typed_map lst' t_string t_int in @@ -2041,13 +2031,13 @@ let get_contract_ligo () : unit result = let%bind program = type_file "./contracts/get_contract.ligo" in let%bind () = let make_input = fun _n -> e_unit () in - let make_expected : int -> Ast_simplified.expression -> unit result = fun _n result -> + let make_expected : int -> Ast_core.expression -> unit result = fun _n result -> let%bind (ops , storage) = get_e_pair result.expression_content in let%bind () = let%bind lst = get_e_list ops.expression_content in Assert.assert_list_size lst 1 in let expected_storage = e_unit () in - Ast_simplified.Misc.assert_value_eq (expected_storage , storage) + Ast_core.Misc.assert_value_eq (expected_storage , storage) in let%bind () = let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in diff --git a/src/test/md_file_tests.ml b/src/test/md_file_tests.ml index 042c6ebaa..6114e9126 100644 --- a/src/test/md_file_tests.ml +++ b/src/test/md_file_tests.ml @@ -68,10 +68,10 @@ let compile_groups _filename grp_list = (fun ((s,grp),contents) -> trace (failed_to_compile_md_file _filename (s,grp,contents)) @@ let%bind v_syntax = Compile.Helpers.syntax_to_variant (Syntax_name s) None in - let%bind abstracted = Compile.Of_source.compile_string contents v_syntax in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,_ = Compile.Of_simplified.compile Env simplified in + let%bind imperative = Compile.Of_source.compile_string contents v_syntax in + let%bind sugar = Ligo.Compile.Of_imperative.compile imperative in + let%bind core = Ligo.Compile.Of_sugar.compile sugar in + let%bind typed,_ = Compile.Of_core.compile Env core in let%bind mini_c = Compile.Of_typed.compile typed in bind_map_list (fun ((_, _, exp),_) -> Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp) diff --git a/src/test/multisig_tests.ml b/src/test/multisig_tests.ml index 0866302c0..4410df2eb 100644 --- a/src/test/multisig_tests.ml +++ b/src/test/multisig_tests.ml @@ -6,10 +6,7 @@ let mfile = "./contracts/multisig.mligo" let refile = "./contracts/multisig.religo" let type_file f s = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name s) in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f s (Contract "main") in ok @@ (typed,state) let get_program f st = @@ -31,7 +28,7 @@ let compile_main f s () = Ligo.Compile.Of_michelson.build_contract michelson_prg in ok () -open Ast_simplified +open Ast_core let init_storage threshold counter pkeys = let keys = List.map diff --git a/src/test/multisig_v2_tests.ml b/src/test/multisig_v2_tests.ml index 01248c2dd..0ce171034 100644 --- a/src/test/multisig_v2_tests.ml +++ b/src/test/multisig_v2_tests.ml @@ -2,10 +2,7 @@ open Trace open Test_helpers let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") in ok @@ (typed,state) let get_program = @@ -27,7 +24,7 @@ let compile_main () = Ligo.Compile.Of_michelson.build_contract michelson_prg in ok () -open Ast_simplified +open Ast_core let empty_op_list = (e_typed_list [] t_operation) diff --git a/src/test/pledge_tests.ml b/src/test/pledge_tests.ml index 7d8d0abcf..f1dc76459 100644 --- a/src/test/pledge_tests.ml +++ b/src/test/pledge_tests.ml @@ -1,13 +1,10 @@ open Trace open Test_helpers -open Ast_simplified +open Ast_core let retype_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "reasonligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile Env simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "reasonligo" Env in ok (typed,state) let get_program = diff --git a/src/test/replaceable_id_tests.ml b/src/test/replaceable_id_tests.ml index b3623025c..67cdd9402 100644 --- a/src/test/replaceable_id_tests.ml +++ b/src/test/replaceable_id_tests.ml @@ -2,10 +2,7 @@ open Trace open Test_helpers let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") in ok @@ (typed,state) let get_program = @@ -26,7 +23,7 @@ let compile_main () = (* fails if the given entry point is not a valid contract *) Ligo.Compile.Of_michelson.build_contract michelson_prg in ok () -open Ast_simplified +open Ast_core let empty_op_list = (e_typed_list [] t_operation) diff --git a/src/test/test_helpers.ml b/src/test/test_helpers.ml index f7ca0f320..fc1227472 100644 --- a/src/test/test_helpers.ml +++ b/src/test/test_helpers.ml @@ -30,13 +30,13 @@ let test name f = let test_suite name lst = Test_suite (name , lst) -open Ast_simplified +open Ast_core let pack_payload (program:Ast_typed.program) (payload:expression) : bytes result = let%bind code = let env = Ast_typed.program_environment program in - let%bind (typed,_) = Compile.Of_simplified.compile_expression + let%bind (typed,_) = Compile.Of_core.compile_expression ~env ~state:(Typer.Solver.initial_state) payload in let%bind mini_c = Compile.Of_typed.compile_expression typed in Compile.Of_mini_c.compile_expression mini_c in @@ -77,24 +77,24 @@ let sha_256_hash pl = let open Proto_alpha_utils.Memory_proto_alpha.Alpha_environment in Raw_hashes.sha256 pl -open Ast_simplified.Combinators +open Ast_core.Combinators -let typed_program_with_simplified_input_to_michelson +let typed_program_with_core_input_to_michelson (program: Ast_typed.program) (entry_point: string) - (input: Ast_simplified.expression) : Compiler.compiled_expression result = + (input: Ast_core.expression) : Compiler.compiled_expression result = Printexc.record_backtrace true; let env = Ast_typed.program_environment program in let state = Typer.Solver.initial_state in - let%bind app = Compile.Of_simplified.apply entry_point input in - let%bind (typed_app,_) = Compile.Of_simplified.compile_expression ~env ~state app in + let%bind app = Compile.Of_core.apply entry_point input in + let%bind (typed_app,_) = Compile.Of_core.compile_expression ~env ~state app in let%bind compiled_applied = Compile.Of_typed.compile_expression typed_app in let%bind mini_c_prg = Compile.Of_typed.compile program in Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg compiled_applied -let run_typed_program_with_simplified_input ?options +let run_typed_program_with_core_input ?options (program: Ast_typed.program) (entry_point: string) - (input: Ast_simplified.expression) : Ast_simplified.expression result = - let%bind michelson_program = typed_program_with_simplified_input_to_michelson program entry_point input in + (input: Ast_core.expression) : Ast_core.expression result = + let%bind michelson_program = typed_program_with_core_input_to_michelson program entry_point input in let%bind michelson_output = Ligo.Run.Of_michelson.run_no_failwith ?options michelson_program.expr michelson_program.expr_ty in Uncompile.uncompile_typed_program_entry_function_result program entry_point michelson_output @@ -106,7 +106,7 @@ let expect ?options program entry_point input expecter = error title content in trace run_error @@ - run_typed_program_with_simplified_input ?options program entry_point input in + run_typed_program_with_core_input ?options program entry_point input in expecter result let expect_fail ?options program entry_point input = @@ -117,10 +117,10 @@ let expect_fail ?options program entry_point input = in trace run_error @@ Assert.assert_fail @@ - run_typed_program_with_simplified_input ?options program entry_point input + run_typed_program_with_core_input ?options program entry_point input let expect_string_failwith ?options program entry_point input expected_failwith = - let%bind michelson_program = typed_program_with_simplified_input_to_michelson program entry_point input in + let%bind michelson_program = typed_program_with_core_input_to_michelson program entry_point input in let%bind err = Ligo.Run.Of_michelson.run_failwith ?options michelson_program.expr michelson_program.expr_ty in match err with @@ -132,11 +132,11 @@ let expect_eq ?options program entry_point input expected = let expect_error = let title () = "expect result" in let content () = Format.asprintf "Expected %a, got %a" - Ast_simplified.PP.expression expected - Ast_simplified.PP.expression result in + Ast_core.PP.expression expected + Ast_core.PP.expression result in error title content in trace expect_error @@ - Ast_simplified.Misc.assert_value_eq (expected , result) in + Ast_core.Misc.assert_value_eq (expected , result) in expect ?options program entry_point input expecter let expect_evaluate program entry_point expecter = @@ -154,7 +154,7 @@ let expect_evaluate program entry_point expecter = let expect_eq_evaluate program entry_point expected = let expecter = fun result -> - Ast_simplified.Misc.assert_value_eq (expected , result) in + Ast_core.Misc.assert_value_eq (expected , result) in expect_evaluate program entry_point expecter let expect_n_aux ?options lst program entry_point make_input make_expecter = @@ -183,7 +183,7 @@ let expect_eq_exp_trace_aux ?options explst program entry_point make_input make_ let aux exp = let%bind input = make_input exp in let%bind expected = make_expected exp in - let pps = Format.asprintf "%a" Ast_simplified.PP.expression exp in + let pps = Format.asprintf "%a" Ast_core.PP.expression exp in trace (simple_error ("expect_eq_exp " ^ pps )) @@ let result = expect_eq ?options program entry_point input expected in result @@ -195,7 +195,7 @@ let expect_failwith_exp_trace_aux ?options explst program entry_point make_input let aux exp = let%bind input = make_input exp in let%bind expected = make_expected_failwith exp in - let pps = Format.asprintf "%a" Ast_simplified.PP.expression exp in + let pps = Format.asprintf "%a" Ast_core.PP.expression exp in trace (simple_error ("expect_eq_exp " ^ pps )) @@ let result = expect_string_failwith ?options program entry_point input expected in result @@ -237,7 +237,7 @@ let expect_eq_n_int a b c = expect_eq_n a b e_int (fun n -> e_int (c n)) let expect_eq_b_bool a b c = - let open Ast_simplified.Combinators in + let open Ast_core.Combinators in expect_eq_b a b (fun bool -> e_bool (c bool)) diff --git a/src/test/time_lock_repeat_tests.ml b/src/test/time_lock_repeat_tests.ml index 35c70cfa3..f2610dadb 100644 --- a/src/test/time_lock_repeat_tests.ml +++ b/src/test/time_lock_repeat_tests.ml @@ -1,12 +1,9 @@ open Trace open Test_helpers -open Ast_simplified +open Ast_core let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") in ok @@ (typed,state) let get_program = diff --git a/src/test/time_lock_tests.ml b/src/test/time_lock_tests.ml index d5247b3cd..37f936a29 100644 --- a/src/test/time_lock_tests.ml +++ b/src/test/time_lock_tests.ml @@ -2,10 +2,7 @@ open Trace open Test_helpers let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") in ok @@ (typed,state) let get_program = @@ -27,7 +24,7 @@ let compile_main () = Ligo.Compile.Of_michelson.build_contract michelson_prg in ok () -open Ast_simplified +open Ast_core let empty_op_list = (e_typed_list [] t_operation) let empty_message = e_lambda (Var.of_name "arguments") diff --git a/src/test/typer_tests.ml b/src/test/typer_tests.ml index df0817ba8..57b06a7b7 100644 --- a/src/test/typer_tests.ml +++ b/src/test/typer_tests.ml @@ -1,10 +1,10 @@ open Trace -open Ast_simplified +open Ast_core open Test_helpers module Typed = Ast_typed module Typer = Typer -module Simplified = Ast_simplified +module Simplified = Ast_core let int () : unit result = let open Combinators in @@ -72,7 +72,7 @@ end (* TODO: deep types (e.g. record of record) TODO: negative tests (expected type error) *) -let main = test_suite "Typer (from simplified AST)" [ +let main = test_suite "Typer (from core AST)" [ test "int" int ; test "unit" TestExpressions.unit ; test "int2" TestExpressions.int ; diff --git a/src/test/vote_tests.ml b/src/test/vote_tests.ml index c572ce340..1fc2c5cd6 100644 --- a/src/test/vote_tests.ml +++ b/src/test/vote_tests.ml @@ -2,10 +2,7 @@ open Trace open Test_helpers let type_file f = - let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in - let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in - let%bind simplified = Ligo.Compile.Of_complex.compile complex in - let%bind typed,state = Ligo.Compile.Of_simplified.compile (Contract "main") simplified in + let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") in ok @@ (typed,state) let get_program = @@ -18,7 +15,7 @@ let get_program = ok (program , state) ) -open Ast_simplified +open Ast_core let init_storage name = e_record_ez [ ("title" , e_string name) ; @@ -41,14 +38,14 @@ let yea = e_constructor "Vote" (e_constructor "Yea" (e_unit ())) let init_vote () = let%bind (program , _) = get_program () in let%bind result = - Test_helpers.run_typed_program_with_simplified_input + Test_helpers.run_typed_program_with_core_input program "main" (e_pair yea (init_storage "basic")) in let%bind (_, storage) = extract_pair result in let%bind storage' = extract_record storage in (* let votes = List.assoc (Label "voters") storage' in let%bind votes' = extract_map votes in *) let yea = List.assoc (Label "yea") storage' in - let%bind () = Ast_simplified.Misc.assert_value_eq (yea, e_nat 1) in + let%bind () = Ast_core.Misc.assert_value_eq (yea, e_nat 1) in ok () let main = test_suite "Vote" [