rename AST to imperative, sugar and core. Factor code in compile

This commit is contained in:
Pierre-Emmanuel Wulfman 2020-03-16 14:28:05 +01:00
parent 6dfd2dac32
commit 8b3877a92c
67 changed files with 292 additions and 331 deletions

View File

@ -6,7 +6,7 @@ title: Middle End
The Middle-End is the core of LIGO. It is also composed of three parts. The Middle-End is the core of LIGO. It is also composed of three parts.
## Common AST ## 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 wholl write new parsers or editor support for Front-end related things. 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 wholl 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 ## 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. 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. As time passes, we want to make the type-system stronger, to encode arbitrarily complex properties in an extensible manner.

View File

@ -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. 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 ## How To Write A Test For LIGO

View File

@ -140,10 +140,7 @@ module Run = Ligo.Run.Of_michelson
let compile_file = let compile_file =
let f source_file entry_point syntax display_format disable_typecheck michelson_format = let f source_file entry_point syntax display_format disable_typecheck michelson_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed,_ = Compile.Utils.type_file source_file syntax (Contract entry_point) 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 mini_c = Compile.Of_typed.compile typed 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 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 let%bind contract = Compile.Of_michelson.build_contract ~disable_typecheck michelson in
@ -170,10 +167,8 @@ let print_cst =
let print_ast = let print_ast =
let f source_file syntax display_format = ( let f source_file syntax display_format = (
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind core = Compile.Utils.to_core source_file syntax in
let%bind complex = Compile.Of_abstracted.compile abstracted in ok @@ Format.asprintf "%a\n" Compile.Of_core.pretty_print core
let%bind simplified = Compile.Of_complex.compile complex in
ok @@ Format.asprintf "%a\n" Compile.Of_simplified.pretty_print simplified
) )
in in
let term = Term.(const f $ source_file 0 $ syntax $ display_format) 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 print_typed_ast =
let f source_file syntax display_format = ( let f source_file syntax display_format = (
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed,_ = Compile.Utils.type_file source_file syntax Env 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
ok @@ Format.asprintf "%a\n" Compile.Of_typed.pretty_print typed ok @@ Format.asprintf "%a\n" Compile.Of_typed.pretty_print typed
) )
in in
@ -199,10 +191,7 @@ let print_typed_ast =
let print_mini_c = let print_mini_c =
let f source_file syntax display_format = ( let f source_file syntax display_format = (
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed,_ = Compile.Utils.type_file source_file syntax Env 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 mini_c = Compile.Of_typed.compile typed in let%bind mini_c = Compile.Of_typed.compile typed in
ok @@ Format.asprintf "%a\n" Compile.Of_mini_c.pretty_print mini_c 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 measure_contract =
let f source_file entry_point syntax display_format = let f source_file entry_point syntax display_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind contract = Compile.Utils.compile_file source_file syntax entry_point 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 open Tezos_utils in let open Tezos_utils in
ok @@ Format.asprintf "%d bytes\n" (Michelson.measure contract) ok @@ Format.asprintf "%d bytes\n" (Michelson.measure contract)
in in
@ -234,10 +217,7 @@ let measure_contract =
let compile_parameter = let compile_parameter =
let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format = let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed_prg,state = Compile.Utils.type_file source_file syntax (Contract entry_point) 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 mini_c_prg = Compile.Of_typed.compile 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 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 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 *) (* fails if the given entry point is not a valid contract *)
Compile.Of_michelson.build_contract michelson_prg in 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 (typed_param,_) = Compile.Utils.type_expression (Some source_file) syntax expression env state 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 mini_c_param = Compile.Of_typed.compile_expression typed_param 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 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 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 @@ toplevel ~display_format @@
let%bind (decl_list,state,env) = match init_file with let%bind (decl_list,state,env) = match init_file with
| Some init_file -> | Some init_file ->
let%bind abstracted = Compile.Of_source.compile init_file (Syntax_name syntax) in let%bind typed_prg,state = Compile.Utils.type_file init_file syntax Env 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 mini_c_prg = Compile.Of_typed.compile typed_prg in let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
let env = Ast_typed.program_environment typed_prg in let env = Ast_typed.program_environment typed_prg in
ok (mini_c_prg,state,env) ok (mini_c_prg,state,env)
| None -> ok ([],Typer.Solver.initial_state,Ast_typed.Environment.full_empty) in | 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 (typed_exp,_) = Compile.Utils.type_expression init_file syntax expression env state 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 mini_c_exp = Compile.Of_typed.compile_expression typed_exp 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 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 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 let%bind failstring = Run.failwith_to_string fail_res in
ok @@ Format.asprintf "%s" failstring ok @@ Format.asprintf "%s" failstring
| Success value' -> | Success value' ->
let%bind simplified_output = Uncompile.uncompile_expression typed_exp.type_expression value' in let%bind core_output = Uncompile.uncompile_expression typed_exp.type_expression value' in
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression simplified_output ok @@ Format.asprintf "%a\n" Ast_core.PP.expression core_output
in in
let term = let term =
Term.(const f $ expression "EXPRESSION" 0 $ init_file $ syntax $ amount $ balance $ sender $ source $ predecessor_timestamp $ display_format ) in 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 temp_ligo_interpreter =
let f source_file syntax display_format = let f source_file syntax display_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed,_ = Compile.Utils.type_file source_file syntax Env 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 res = Compile.Of_typed.some_interpret typed in let%bind res = Compile.Of_typed.some_interpret typed in
ok @@ Format.asprintf "%s\n" res ok @@ Format.asprintf "%s\n" res
in in
@ -320,10 +286,7 @@ let temp_ligo_interpreter =
let compile_storage = let compile_storage =
let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format = let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed_prg,state = Compile.Utils.type_file source_file syntax (Contract entry_point) 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 mini_c_prg = Compile.Of_typed.compile 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 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 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 *) (* fails if the given entry point is not a valid contract *)
Compile.Of_michelson.build_contract michelson_prg in 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 (typed_param,_) = Compile.Utils.type_expression (Some source_file) syntax expression env state 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 mini_c_param = Compile.Of_typed.compile_expression typed_param 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 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 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 dry_run =
let f source_file entry_point storage input amount balance sender source predecessor_timestamp syntax display_format = let f source_file entry_point storage input amount balance sender source predecessor_timestamp syntax display_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed_prg,state = Compile.Utils.type_file source_file syntax (Contract entry_point) 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 env = Ast_typed.program_environment typed_prg in let env = Ast_typed.program_environment typed_prg in
let%bind mini_c_prg = Compile.Of_typed.compile 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 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 *) (* fails if the given entry point is not a valid contract *)
Compile.Of_michelson.build_contract michelson_prg in 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 compiled_params = Compile.Utils.compile_storage storage input source_file syntax env state mini_c_prg 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 args_michelson = Run.evaluate_expression compiled_params.expr compiled_params.expr_ty 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 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 let%bind failstring = Run.failwith_to_string fail_res in
ok @@ Format.asprintf "%s" failstring ok @@ Format.asprintf "%s" failstring
| Success michelson_output -> | Success michelson_output ->
let%bind simplified_output = Uncompile.uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in let%bind core_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 core_output
in in
let term = 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 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 run_function =
let f source_file entry_point parameter amount balance sender source predecessor_timestamp syntax display_format = let f source_file entry_point parameter amount balance sender source predecessor_timestamp syntax display_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in let%bind typed_prg,state = Compile.Utils.type_file source_file syntax Env 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 env = Ast_typed.program_environment typed_prg in let env = Ast_typed.program_environment typed_prg in
let%bind mini_c_prg = Compile.Of_typed.compile 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 v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in
let%bind complex_param = Compile.Of_abstracted.compile_expression abstracted_param in let%bind imperative_param = Compile.Of_source.compile_expression v_syntax parameter in
let%bind simplified_param = Compile.Of_complex.compile_expression complex_param in let%bind sugar_param = Compile.Of_imperative.compile_expression imperative_param in
let%bind app = Compile.Of_simplified.apply entry_point simplified_param in let%bind core_param = Compile.Of_sugar.compile_expression sugar_param in
let%bind (typed_app,_) = Compile.Of_simplified.compile_expression ~env ~state app 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 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 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 ok @@ Format.asprintf "%s" failstring
| Success michelson_output -> | Success michelson_output ->
let%bind simplified_output = Uncompile.uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in 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 in
let term = let term =
Term.(const f $ source_file 0 $ entry_point 1 $ expression "PARAMETER" 2 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format) in 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 evaluate_value =
let f source_file entry_point amount balance sender source predecessor_timestamp syntax display_format = let f source_file entry_point amount balance sender source predecessor_timestamp syntax display_format =
toplevel ~display_format @@ toplevel ~display_format @@
let%bind abstracted = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind typed_prg,_ = Compile.Utils.type_file source_file syntax Env 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 mini_c = Compile.Of_typed.compile typed_prg 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 (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 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 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 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 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 in
let term = let term =
Term.(const f $ source_file 0 $ entry_point 1 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format) in 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 compile_expression =
let f expression syntax display_format michelson_format = let f expression syntax display_format michelson_format =
toplevel ~display_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 env = Ast_typed.Environment.full_empty in
let state = Typer.Solver.initial_state in let state = Typer.Solver.initial_state in
let%bind abstracted = Compile.Of_source.compile_expression v_syntax expression in let%bind compiled_exp = Compile.Utils.compile_expression None syntax expression env state 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 value = Run.evaluate_expression compiled_exp.expr compiled_exp.expr_ty 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 ok @@ Format.asprintf "%a\n" (Main.Display.michelson_pp michelson_format) value
in in
@ -478,10 +416,8 @@ let dump_changelog =
let list_declarations = let list_declarations =
let f source_file syntax = let f source_file syntax =
toplevel ~display_format:(`Human_readable) @@ toplevel ~display_format:(`Human_readable) @@
let%bind abstracted_prg = Compile.Of_source.compile source_file (Syntax_name syntax) in let%bind core_prg = Compile.Utils.to_core source_file syntax in
let%bind complex_prg = Compile.Of_abstracted.compile abstracted_prg in let json_decl = List.map (fun decl -> `String decl) @@ Compile.Of_core.list_declarations core_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
ok @@ J.to_string @@ `Assoc [ ("source_file", `String source_file) ; ("declarations", `List json_decl) ] ok @@ J.to_string @@ `Assoc [ ("source_file", `String source_file) ; ("declarations", `List json_decl) ]
in in
let term = let term =

View File

@ -9,11 +9,11 @@
ast_imperative ast_imperative
self_ast_imperative self_ast_imperative
instruction_remover instruction_remover
ast_complex ast_sugar
self_ast_complex self_ast_sugar
simplifier simplifier
ast_simplified ast_core
self_ast_simplified self_ast_core
typer_new typer_new
typer typer
ast_typed ast_typed

View File

@ -23,55 +23,55 @@ let parsify_pascaligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing") @@ trace (simple_error "parsing") @@
Parser.Pascaligo.parse_file source in Parser.Pascaligo.parse_file source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting") @@ trace (simple_error "abstracting") @@
Abstracter.Pascaligo.abstr_program raw Abstracter.Pascaligo.abstr_program raw
in ok simplified in ok imperative
let parsify_expression_pascaligo source = let parsify_expression_pascaligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing expression") @@ trace (simple_error "parsing expression") @@
Parser.Pascaligo.parse_expression source in Parser.Pascaligo.parse_expression source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting expression") @@ trace (simple_error "abstracting expression") @@
Abstracter.Pascaligo.abstr_expression raw Abstracter.Pascaligo.abstr_expression raw
in ok simplified in ok imperative
let parsify_cameligo source = let parsify_cameligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing") @@ trace (simple_error "parsing") @@
Parser.Cameligo.parse_file source in Parser.Cameligo.parse_file source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting") @@ trace (simple_error "abstracting") @@
Abstracter.Cameligo.abstr_program raw Abstracter.Cameligo.abstr_program raw
in ok simplified in ok imperative
let parsify_expression_cameligo source = let parsify_expression_cameligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing expression") @@ trace (simple_error "parsing expression") @@
Parser.Cameligo.parse_expression source in Parser.Cameligo.parse_expression source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting expression") @@ trace (simple_error "abstracting expression") @@
Abstracter.Cameligo.abstr_expression raw Abstracter.Cameligo.abstr_expression raw
in ok simplified in ok imperative
let parsify_reasonligo source = let parsify_reasonligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing") @@ trace (simple_error "parsing") @@
Parser.Reasonligo.parse_file source in Parser.Reasonligo.parse_file source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting") @@ trace (simple_error "abstracting") @@
Abstracter.Cameligo.abstr_program raw Abstracter.Cameligo.abstr_program raw
in ok simplified in ok imperative
let parsify_expression_reasonligo source = let parsify_expression_reasonligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing expression") @@ trace (simple_error "parsing expression") @@
Parser.Reasonligo.parse_expression source in Parser.Reasonligo.parse_expression source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting expression") @@ trace (simple_error "abstracting expression") @@
Abstracter.Cameligo.abstr_expression raw Abstracter.Cameligo.abstr_expression raw
in ok simplified in ok imperative
let parsify syntax source = let parsify syntax source =
let%bind parsify = let%bind parsify =
@ -96,28 +96,28 @@ let parsify_string_reasonligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing") @@ trace (simple_error "parsing") @@
Parser.Reasonligo.parse_string source in Parser.Reasonligo.parse_string source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting") @@ trace (simple_error "abstracting") @@
Abstracter.Cameligo.abstr_program raw Abstracter.Cameligo.abstr_program raw
in ok simplified in ok imperative
let parsify_string_pascaligo source = let parsify_string_pascaligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing") @@ trace (simple_error "parsing") @@
Parser.Pascaligo.parse_string source in Parser.Pascaligo.parse_string source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting") @@ trace (simple_error "abstracting") @@
Abstracter.Pascaligo.abstr_program raw Abstracter.Pascaligo.abstr_program raw
in ok simplified in ok imperative
let parsify_string_cameligo source = let parsify_string_cameligo source =
let%bind raw = let%bind raw =
trace (simple_error "parsing") @@ trace (simple_error "parsing") @@
Parser.Cameligo.parse_string source in Parser.Cameligo.parse_string source in
let%bind simplified = let%bind imperative =
trace (simple_error "abstracting") @@ trace (simple_error "abstracting") @@
Abstracter.Cameligo.abstr_program raw Abstracter.Cameligo.abstr_program raw
in ok simplified in ok imperative
let parsify_string syntax source = let parsify_string syntax source =
let%bind parsify = let%bind parsify =

View File

@ -4,7 +4,7 @@ type form =
| Contract of string | Contract of string
| Env | 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%bind (prog_typed , state) = Typer.type_program program in
let () = Typer.Solver.discard_state state in let () = Typer.Solver.discard_state state in
let%bind applied = Self_ast_typed.all_program prog_typed 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 | Env -> ok applied in
ok @@ (applied', state) 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 = : (Ast_typed.expression * Typer.Solver.state) result =
let%bind (ae_typed,state) = Typer.type_expression_subst env state e in let%bind (ae_typed,state) = Typer.type_expression_subst env state e in
let () = Typer.Solver.discard_state state in let () = Typer.Solver.discard_state state in
let%bind ae_typed' = Self_ast_typed.all_expression ae_typed in let%bind ae_typed' = Self_ast_typed.all_expression ae_typed in
ok @@ (ae_typed',state) 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 name = Var.of_name entry_point in
let entry_point_var : Ast_simplified.expression = let entry_point_var : Ast_core.expression =
{ expression_content = Ast_simplified.E_variable name ; { expression_content = Ast_core.E_variable name ;
location = Virtual "generated entry-point variable" } in location = Virtual "generated entry-point variable" } in
let applied : Ast_simplified.expression = let applied : Ast_core.expression =
{ expression_content = Ast_simplified.E_application {expr1=entry_point_var; expr2=param} ; { expression_content = Ast_core.E_application {expr1=entry_point_var; expr2=param} ;
location = Virtual "generated application" } in location = Virtual "generated application" } in
ok applied ok applied
let pretty_print formatter (program : Ast_simplified.program) = let pretty_print formatter (program : Ast_core.program) =
Ast_simplified.PP.program formatter 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 List.fold_left
(fun prev el -> (fun prev el ->
let open Location in let open Location in
let open Ast_simplified in let open Ast_core in
match el.wrap_content with match el.wrap_content with
| Declaration_constant (var,_,_,_) -> (Var.to_name var)::prev | Declaration_constant (var,_,_,_) -> (Var.to_name var)::prev
| _ -> prev) | _ -> prev)

View File

@ -6,10 +6,10 @@ type form =
| Contract of string | Contract of string
| Env | Env
let compile (program : program) : Ast_complex.program result = let compile (program : program) : Ast_sugar.program result =
remove_instruction_in_program program 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 remove_instruction_in_expression e
let pretty_print formatter (program : program) = let pretty_print formatter (program : program) =

View File

@ -1,15 +1,15 @@
open Trace open Trace
open Ast_complex open Ast_sugar
open Simplifier open Simplifier
type form = type form =
| Contract of string | Contract of string
| Env | Env
let compile (program : program) : Ast_simplified.program result = let compile (program : program) : Ast_core.program result =
simplify_program program simplify_program program
let compile_expression (e : expression) : Ast_simplified.expression result = let compile_expression (e : expression) : Ast_core.expression result =
simplify_expression e simplify_expression e
let pretty_print formatter (program : program) = let pretty_print formatter (program : program) =

65
src/main/compile/utils.ml Normal file
View File

@ -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

View File

@ -8,7 +8,7 @@
abstracter abstracter
self_ast_imperative self_ast_imperative
simplifier simplifier
ast_simplified ast_core
typer_new typer_new
typer typer
ast_typed ast_typed

View File

@ -1,7 +1,7 @@
open Trace open Trace
open Function open Function
module I = Parser.Cameligo.Ast module I = Parser.Cameligo.Ast
module O = Ast_simplified module O = Ast_core
open O.Combinators open O.Combinators
let unwrap : type a . a Location.wrap -> a = Location.unwrap let unwrap : type a . a Location.wrap -> a = Location.unwrap

View File

@ -6,10 +6,10 @@ open Ast_imperative
module Raw = Parser.Pascaligo.AST module Raw = Parser.Pascaligo.AST
module SMap = Map.String 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. *) expression AST used by the compiler. *)
val abstr_expression : Raw.expr -> expr result 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. *) AST used by the compiler. *)
val abstr_program : Raw.ast -> program result val abstr_program : Raw.ast -> program result

View File

@ -4,7 +4,7 @@
(libraries (libraries
simple-utils simple-utils
ast_imperative ast_imperative
ast_complex ast_sugar
proto-alpha-utils proto-alpha-utils
) )
(preprocess (preprocess

View File

@ -1,5 +1,5 @@
module I = Ast_imperative module I = Ast_imperative
module O = Ast_complex module O = Ast_sugar
open Trace open Trace
let rec idle_type_expression : I.type_expression -> O.type_expression result = let rec idle_type_expression : I.type_expression -> O.type_expression result =

View File

@ -1,9 +1,9 @@
(library (library
(name self_ast_complex) (name self_ast_sugar)
(public_name ligo.self_ast_complex) (public_name ligo.self_ast_sugar)
(libraries (libraries
simple-utils simple-utils
ast_complex ast_sugar
proto-alpha-utils proto-alpha-utils
) )
(preprocess (preprocess

View File

@ -3,8 +3,8 @@
(public_name ligo.simplifier) (public_name ligo.simplifier)
(libraries (libraries
simple-utils simple-utils
ast_complex ast_sugar
ast_simplified ast_core
proto-alpha-utils proto-alpha-utils
) )
(preprocess (preprocess

View File

@ -1,5 +1,5 @@
module I = Ast_complex module I = Ast_sugar
module O = Ast_simplified module O = Ast_core
open Trace open Trace
let rec idle_type_expression : I.type_expression -> O.type_expression result = let rec idle_type_expression : I.type_expression -> O.type_expression result =

View File

@ -1,9 +1,9 @@
(library (library
(name self_ast_simplified) (name self_ast_core)
(public_name ligo.self_ast_simplified) (public_name ligo.self_ast_core)
(libraries (libraries
simple-utils simple-utils
ast_simplified ast_core
proto-alpha-utils proto-alpha-utils
) )
(preprocess (preprocess

View File

@ -4,7 +4,7 @@
(libraries (libraries
simple-utils simple-utils
tezos-utils tezos-utils
ast_simplified ast_core
ast_typed ast_typed
operators operators
UnionFind UnionFind

View File

@ -3,7 +3,7 @@ open Trace
module Core = Typesystem.Core module Core = Typesystem.Core
module Wrap = struct module Wrap = struct
module I = Ast_simplified module I = Ast_core
module T = Ast_typed module T = Ast_typed
module O = Core module O = Core

View File

@ -1,6 +1,6 @@
open Trace open Trace
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
open O.Combinators 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… ??? *) (* 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 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) = 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' 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 = 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 let%bind t = match t.type_content with
| O.T_sum x -> | O.T_sum x ->
let%bind x' = Stage_common.Helpers.bind_map_cmap untype_type_expression x in 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 in
ok @@ I.make_t t ok @@ I.make_t t
(* match t.simplified with *) (* match t.core with *)
(* | Some s -> ok s *) (* | Some s -> ok s *)
(* | _ -> fail @@ internal_assertion_failure "trying to untype generated type" *) (* | _ -> 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 untype_literal (l:O.literal) : I.literal result =
let open I in let open I in
@ -1027,7 +1027,7 @@ let untype_literal (l:O.literal) : I.literal result =
| Literal_operation s -> ok (Literal_operation s) | 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 rec untype_expression (e:O.expression) : (I.expression) result =
let open I in 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) 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 -> and untype_matching : (O.expression -> I.expression result) -> O.matching_expr -> I.matching_expr result = fun f m ->
let open I in let open I in

View File

@ -1,6 +1,6 @@
open Trace open Trace
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
open O.Combinators 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 typer lst tv_opt
let untype_type_expression (t:O.type_expression) : (I.type_expression) result = let untype_type_expression (t:O.type_expression) : (I.type_expression) result =
match t.simplified with match t.core with
| Some s -> ok s | Some s -> ok s
| _ -> fail @@ internal_assertion_failure "trying to untype generated type" | _ -> fail @@ internal_assertion_failure "trying to untype generated type"

View File

@ -1,6 +1,6 @@
open Trace open Trace
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
module Environment = O.Environment module Environment = O.Environment

View File

@ -4,7 +4,7 @@
(libraries (libraries
simple-utils simple-utils
tezos-utils tezos-utils
ast_simplified ast_core
ast_typed ast_typed
typer_new typer_new
operators operators

View File

@ -1,6 +1,6 @@
open Trace open Trace
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
open O.Combinators open O.Combinators

View File

@ -1,6 +1,6 @@
open Trace open Trace
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
module Environment = O.Environment module Environment = O.Environment

View File

@ -4,7 +4,7 @@
(libraries (libraries
simple-utils simple-utils
tezos-utils tezos-utils
ast_simplified ast_core
ast_typed ast_typed
typer_old typer_old
typer_new typer_new

View File

@ -1,6 +1,6 @@
let use_new_typer = false let use_new_typer = false
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
module Environment = O.Environment module Environment = O.Environment

View File

@ -2,7 +2,7 @@ val use_new_typer : bool
open Trace open Trace
module I = Ast_simplified module I = Ast_core
module O = Ast_typed module O = Ast_typed
module Environment = O.Environment module Environment = O.Environment

View File

@ -5,8 +5,8 @@
simple-utils simple-utils
tezos-utils tezos-utils
ast_imperative ast_imperative
ast_complex ast_sugar
ast_simplified ast_core
ast_typed ast_typed
typesystem typesystem
mini_c mini_c

View File

@ -17,7 +17,7 @@ module Abstracter = struct
Constants are special names that have their own case in the AST. E_constant 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 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" , [ For instance, "2 + 2" in Pascaligo is translated to `E_constant ("ADD" , [
E_literal (Literal_int 2) ; E_literal (Literal_int 2) ;
E_literal (Literal_int 2) ; E_literal (Literal_int 2) ;

View File

@ -237,7 +237,7 @@ let tuple_of_record (m: _ LMap.t) =
let get_e_tuple = fun t -> let get_e_tuple = fun t ->
match t with match t with
| E_record r -> ok @@ tuple_of_record r | 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 *) (* Same as get_e_pair *)
let extract_pair : expression -> (expression * expression) result = fun e -> let extract_pair : expression -> (expression * expression) result = fun e ->

View File

@ -8,7 +8,7 @@ end
include Stage_common.Types 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) include Ast_generic_type (Ast_imperative_parameter)

View File

@ -4,7 +4,7 @@ open Format
open PP_helpers open PP_helpers
include Stage_common.PP 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 = let expression_variable ppf (ev : expression_variable) : unit =
fprintf ppf "%a" Var.pp ev fprintf ppf "%a" Var.pp ev

View File

@ -237,7 +237,7 @@ let tuple_of_record (m: _ LMap.t) =
let get_e_tuple = fun t -> let get_e_tuple = fun t ->
match t with match t with
| E_record r -> ok @@ tuple_of_record r | 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 *) (* Same as get_e_pair *)
let extract_pair : expression -> (expression * expression) result = fun e -> let extract_pair : expression -> (expression * expression) result = fun e ->

View File

@ -1,6 +1,6 @@
(library (library
(name ast_complex) (name ast_sugar)
(public_name ligo.ast_complex) (public_name ligo.ast_sugar)
(libraries (libraries
simple-utils simple-utils
tezos-utils tezos-utils

View File

@ -2,15 +2,15 @@
module Location = Simple_utils.Location module Location = Simple_utils.Location
module Ast_complex_parameter = struct module Ast_sugar_parameter = struct
type type_meta = unit type type_meta = unit
end end
include Stage_common.Types 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 inline = bool
type program = declaration Location.wrap list type program = declaration Location.wrap list

View File

@ -4,7 +4,7 @@ open Format
open PP_helpers open PP_helpers
include Stage_common.PP 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 = let expression_variable ppf (ev : expression_variable) : unit =
fprintf ppf "%a" Var.pp ev fprintf ppf "%a" Var.pp ev

View File

@ -237,7 +237,7 @@ let tuple_of_record (m: _ LMap.t) =
let get_e_tuple = fun t -> let get_e_tuple = fun t ->
match t with match t with
| E_record r -> ok @@ tuple_of_record r | 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 *) (* Same as get_e_pair *)
let extract_pair : expression -> (expression * expression) result = fun e -> let extract_pair : expression -> (expression * expression) result = fun e ->

View File

@ -1,6 +1,6 @@
(library (library
(name ast_simplified) (name ast_core)
(public_name ligo.ast_simplified) (public_name ligo.ast_core)
(libraries (libraries
simple-utils simple-utils
tezos-utils tezos-utils

View File

@ -2,15 +2,15 @@
module Location = Simple_utils.Location module Location = Simple_utils.Location
module Ast_simplified_parameter = struct module Ast_core_parameter = struct
type type_meta = unit type type_meta = unit
end end
include Stage_common.Types 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 inline = bool
type program = declaration Location.wrap list type program = declaration Location.wrap list

View File

@ -23,7 +23,7 @@ module Errors = struct
error (thunk "No declaration with the given name") message error (thunk "No declaration with the given name") message
end 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 = { let make_a_e ?(location = Location.generated) expression_content type_expression environment = {
expression_content ; expression_content ;
type_expression ; type_expression ;

View File

@ -4,7 +4,7 @@
(libraries (libraries
simple-utils simple-utils
tezos-utils tezos-utils
ast_simplified ; Is that a good idea? ast_core ; Is that a good idea?
stage_common stage_common
) )
(preprocess (preprocess

View File

@ -1,6 +1,6 @@
[@@@warning "-30"] [@@@warning "-30"]
module S = Ast_simplified module S = Ast_core
include Stage_common.Types include Stage_common.Types
module Ast_typed_type_parameter = struct module Ast_typed_type_parameter = struct

View File

@ -89,24 +89,24 @@ module Substitution = struct
let _TODO = substs in let _TODO = substs in
failwith "TODO: T_function" failwith "TODO: T_function"
and s_abstr_type_content : Ast_simplified.type_content w = fun ~substs -> function and s_abstr_type_content : Ast_core.type_content w = fun ~substs -> function
| Ast_simplified.T_sum _ -> failwith "TODO: subst: unimplemented case s_type_expression sum" | Ast_core.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_core.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_core.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_core.T_variable _ -> failwith "TODO: subst: unimplemented case s_type_expression variable"
| Ast_simplified.T_operator op -> | Ast_core.T_operator op ->
let%bind op = let%bind op =
Ast_simplified.bind_map_type_operator Ast_core.bind_map_type_operator
(s_abstr_type_expression ~substs) (s_abstr_type_expression ~substs)
op in op in
(* TODO: when we have generalized operators, we might need to subst the operator name itself? *) (* TODO: when we have generalized operators, we might need to subst the operator name itself? *)
ok @@ Ast_simplified.T_operator op ok @@ Ast_core.T_operator op
| Ast_simplified.T_constant constant -> | Ast_core.T_constant constant ->
ok @@ Ast_simplified.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 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 } -> 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 let%bind type_content = s_type_content ~substs type_content in

View File

@ -4,10 +4,7 @@ open Trace
open Test_helpers open Test_helpers
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =
@ -30,7 +27,7 @@ let compile_main () =
Ligo.Compile.Of_michelson.build_contract michelson_prg in Ligo.Compile.Of_michelson.build_contract michelson_prg in
ok () ok ()
open Ast_simplified open Ast_core
let card owner = let card owner =
e_record_ez [ e_record_ez [
@ -231,7 +228,7 @@ let sell () =
let expected_storage = let expected_storage =
let cards = List.hds @@ cards_ez first_owner n in let cards = List.hds @@ cards_ez first_owner n in
basic 99 1000 cards (2 * 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 in
let%bind () = let%bind () =
let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in

View File

@ -1,12 +1,9 @@
open Trace open Trace
open Test_helpers open Test_helpers
open Ast_simplified open Ast_core
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =

View File

@ -1,13 +1,10 @@
open Trace open Trace
open Test_helpers open Test_helpers
open Ast_simplified open Ast_core
let mtype_file f = let mtype_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") 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
ok (typed,state) ok (typed,state)
let get_program = let get_program =

View File

@ -1,28 +1,18 @@
open Trace open Trace
open Test_helpers open Test_helpers
open Ast_simplified.Combinators open Ast_core.Combinators
let retype_file f = let retype_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "reasonligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "reasonligo" Env 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 () = Typer.Solver.discard_state state in let () = Typer.Solver.discard_state state in
ok typed ok typed
let mtype_file f = let mtype_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" Env 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 () = Typer.Solver.discard_state state in
ok typed ok typed
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" Env 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 () = Typer.Solver.discard_state state in
ok typed ok typed
@ -434,52 +424,52 @@ let bytes_arithmetic () : unit result =
let%bind () = expect_eq program "slice_op" tata at in 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" foo in
let%bind () = expect_fail program "slice_op" ba 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 () = expect_eq program "hasherman" foo b1 in
let%bind b3 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foototo in let%bind b3 = Test_helpers.run_typed_program_with_core_input program "hasherman" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b3 , b1) in
ok () ok ()
let crypto () : unit result = let crypto () : unit result =
let%bind program = type_file "./contracts/crypto.ligo" in let%bind program = type_file "./contracts/crypto.ligo" in
let%bind foo = e_bytes_hex "0f00" in let%bind foo = e_bytes_hex "0f00" in
let%bind foototo = e_bytes_hex "0f007070" 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 () = expect_eq program "hasherman512" foo b1 in
let%bind b2 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foototo in let%bind b2 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b2 , b1) in let%bind () = Assert.assert_fail @@ Ast_core.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 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 () = 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 b5 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b5 , b4) in let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b5 , b4) in
ok () ok ()
let crypto_mligo () : unit result = let crypto_mligo () : unit result =
let%bind program = mtype_file "./contracts/crypto.mligo" in let%bind program = mtype_file "./contracts/crypto.mligo" in
let%bind foo = e_bytes_hex "0f00" in let%bind foo = e_bytes_hex "0f00" in
let%bind foototo = e_bytes_hex "0f007070" 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 () = expect_eq program "hasherman512" foo b1 in
let%bind b2 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foototo in let%bind b2 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b2 , b1) in let%bind () = Assert.assert_fail @@ Ast_core.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 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 () = 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 b5 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b5 , b4) in let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b5 , b4) in
ok () ok ()
let crypto_religo () : unit result = let crypto_religo () : unit result =
let%bind program = retype_file "./contracts/crypto.religo" in let%bind program = retype_file "./contracts/crypto.religo" in
let%bind foo = e_bytes_hex "0f00" in let%bind foo = e_bytes_hex "0f00" in
let%bind foototo = e_bytes_hex "0f007070" 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 () = expect_eq program "hasherman512" foo b1 in
let%bind b2 = Test_helpers.run_typed_program_with_simplified_input program "hasherman512" foototo in let%bind b2 = Test_helpers.run_typed_program_with_core_input program "hasherman512" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b2 , b1) in let%bind () = Assert.assert_fail @@ Ast_core.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 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 () = 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 b5 = Test_helpers.run_typed_program_with_core_input program "hasherman_blake" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b5 , b4) in let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b5 , b4) in
ok () ok ()
let bytes_arithmetic_mligo () : unit result = 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_eq program "slice_op" tata at in
let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" foo in
let%bind () = expect_fail program "slice_op" ba 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 () = expect_eq program "hasherman" foo b1 in
let%bind b3 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foototo in let%bind b3 = Test_helpers.run_typed_program_with_core_input program "hasherman" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b3 , b1) in
ok () ok ()
let bytes_arithmetic_religo () : unit result = 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_eq program "slice_op" tata at in
let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" foo in
let%bind () = expect_fail program "slice_op" ba 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 () = expect_eq program "hasherman" foo b1 in
let%bind b3 = Test_helpers.run_typed_program_with_simplified_input program "hasherman" foototo in let%bind b3 = Test_helpers.run_typed_program_with_core_input program "hasherman" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in let%bind () = Assert.assert_fail @@ Ast_core.Misc.assert_value_eq (b3 , b1) in
ok () ok ()
let set_arithmetic () : unit result = let set_arithmetic () : unit result =
@ -984,7 +974,7 @@ let reoption () : unit result =
let map_ type_f path : unit result = let map_ type_f path : unit result =
let%bind program = type_f path in let%bind program = type_f path in
let ez lst = 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 let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
e_typed_map lst' t_int t_int e_typed_map lst' t_int t_int
in in
@ -1073,7 +1063,7 @@ let map_ type_f path : unit result =
let big_map_ type_f path : unit result = let big_map_ type_f path : unit result =
let%bind program = type_f path in let%bind program = type_f path in
let ez lst = 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 let lst' = List.map (fun (x, y) -> e_int x, e_int y) lst in
(e_typed_big_map lst' t_int t_int) (e_typed_big_map lst' t_int t_int)
in in
@ -1286,7 +1276,7 @@ let loop () : unit result =
expect_eq program "inner_capture_in_conditional_block" input expected in expect_eq program "inner_capture_in_conditional_block" input expected in
let%bind () = let%bind () =
let ez lst = 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 let lst' = List.map (fun (x, y) -> e_string x, e_int y) lst in
e_typed_map lst' t_string t_int e_typed_map lst' t_string t_int
in in
@ -2041,13 +2031,13 @@ let get_contract_ligo () : unit result =
let%bind program = type_file "./contracts/get_contract.ligo" in let%bind program = type_file "./contracts/get_contract.ligo" in
let%bind () = let%bind () =
let make_input = fun _n -> e_unit () in 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 (ops , storage) = get_e_pair result.expression_content in
let%bind () = let%bind () =
let%bind lst = get_e_list ops.expression_content in let%bind lst = get_e_list ops.expression_content in
Assert.assert_list_size lst 1 in Assert.assert_list_size lst 1 in
let expected_storage = e_unit () 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 in
let%bind () = let%bind () =
let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in let amount = Memory_proto_alpha.Protocol.Alpha_context.Tez.zero in

View File

@ -68,10 +68,10 @@ let compile_groups _filename grp_list =
(fun ((s,grp),contents) -> (fun ((s,grp),contents) ->
trace (failed_to_compile_md_file _filename (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 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 imperative = Compile.Of_source.compile_string contents v_syntax in
let%bind complex = Ligo.Compile.Of_abstracted.compile abstracted in let%bind sugar = Ligo.Compile.Of_imperative.compile imperative in
let%bind simplified = Ligo.Compile.Of_complex.compile complex in let%bind core = Ligo.Compile.Of_sugar.compile sugar in
let%bind typed,_ = Compile.Of_simplified.compile Env simplified in let%bind typed,_ = Compile.Of_core.compile Env core in
let%bind mini_c = Compile.Of_typed.compile typed in let%bind mini_c = Compile.Of_typed.compile typed in
bind_map_list bind_map_list
(fun ((_, _, exp),_) -> Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp) (fun ((_, _, exp),_) -> Compile.Of_mini_c.aggregate_and_compile_expression mini_c exp)

View File

@ -6,10 +6,7 @@ let mfile = "./contracts/multisig.mligo"
let refile = "./contracts/multisig.religo" let refile = "./contracts/multisig.religo"
let type_file f s = let type_file f s =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name s) in let%bind typed,state = Ligo.Compile.Utils.type_file f s (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program f st = let get_program f st =
@ -31,7 +28,7 @@ let compile_main f s () =
Ligo.Compile.Of_michelson.build_contract michelson_prg in Ligo.Compile.Of_michelson.build_contract michelson_prg in
ok () ok ()
open Ast_simplified open Ast_core
let init_storage threshold counter pkeys = let init_storage threshold counter pkeys =
let keys = List.map let keys = List.map

View File

@ -2,10 +2,7 @@ open Trace
open Test_helpers open Test_helpers
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =
@ -27,7 +24,7 @@ let compile_main () =
Ligo.Compile.Of_michelson.build_contract michelson_prg in Ligo.Compile.Of_michelson.build_contract michelson_prg in
ok () ok ()
open Ast_simplified open Ast_core
let empty_op_list = let empty_op_list =
(e_typed_list [] t_operation) (e_typed_list [] t_operation)

View File

@ -1,13 +1,10 @@
open Trace open Trace
open Test_helpers open Test_helpers
open Ast_simplified open Ast_core
let retype_file f = let retype_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "reasonligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "reasonligo" Env 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
ok (typed,state) ok (typed,state)
let get_program = let get_program =

View File

@ -2,10 +2,7 @@ open Trace
open Test_helpers open Test_helpers
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =
@ -26,7 +23,7 @@ let compile_main () =
(* fails if the given entry point is not a valid contract *) (* fails if the given entry point is not a valid contract *)
Ligo.Compile.Of_michelson.build_contract michelson_prg in Ligo.Compile.Of_michelson.build_contract michelson_prg in
ok () ok ()
open Ast_simplified open Ast_core
let empty_op_list = let empty_op_list =
(e_typed_list [] t_operation) (e_typed_list [] t_operation)

View File

@ -30,13 +30,13 @@ let test name f =
let test_suite name lst = Test_suite (name , lst) 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 pack_payload (program:Ast_typed.program) (payload:expression) : bytes result =
let%bind code = let%bind code =
let env = Ast_typed.program_environment program in 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 ~env ~state:(Typer.Solver.initial_state) payload in
let%bind mini_c = Compile.Of_typed.compile_expression typed in let%bind mini_c = Compile.Of_typed.compile_expression typed in
Compile.Of_mini_c.compile_expression mini_c 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 let open Proto_alpha_utils.Memory_proto_alpha.Alpha_environment in
Raw_hashes.sha256 pl 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) (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; Printexc.record_backtrace true;
let env = Ast_typed.program_environment program in let env = Ast_typed.program_environment program in
let state = Typer.Solver.initial_state in let state = Typer.Solver.initial_state in
let%bind app = Compile.Of_simplified.apply entry_point input in let%bind app = Compile.Of_core.apply entry_point input in
let%bind (typed_app,_) = Compile.Of_simplified.compile_expression ~env ~state app 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 compiled_applied = Compile.Of_typed.compile_expression typed_app in
let%bind mini_c_prg = Compile.Of_typed.compile program 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 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) (program: Ast_typed.program) (entry_point: string)
(input: Ast_simplified.expression) : Ast_simplified.expression result = (input: Ast_core.expression) : Ast_core.expression result =
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 michelson_output = Ligo.Run.Of_michelson.run_no_failwith ?options michelson_program.expr michelson_program.expr_ty 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 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 error title content
in in
trace run_error @@ 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 expecter result
let expect_fail ?options program entry_point input = let expect_fail ?options program entry_point input =
@ -117,10 +117,10 @@ let expect_fail ?options program entry_point input =
in in
trace run_error @@ trace run_error @@
Assert.assert_fail @@ 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 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 let%bind err = Ligo.Run.Of_michelson.run_failwith
?options michelson_program.expr michelson_program.expr_ty in ?options michelson_program.expr michelson_program.expr_ty in
match err with match err with
@ -132,11 +132,11 @@ let expect_eq ?options program entry_point input expected =
let expect_error = let expect_error =
let title () = "expect result" in let title () = "expect result" in
let content () = Format.asprintf "Expected %a, got %a" let content () = Format.asprintf "Expected %a, got %a"
Ast_simplified.PP.expression expected Ast_core.PP.expression expected
Ast_simplified.PP.expression result in Ast_core.PP.expression result in
error title content in error title content in
trace expect_error @@ 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 expect ?options program entry_point input expecter
let expect_evaluate program entry_point 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 expect_eq_evaluate program entry_point expected =
let expecter = fun result -> 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 expect_evaluate program entry_point expecter
let expect_n_aux ?options lst program entry_point make_input make_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 aux exp =
let%bind input = make_input exp in let%bind input = make_input exp in
let%bind expected = make_expected 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 )) @@ trace (simple_error ("expect_eq_exp " ^ pps )) @@
let result = expect_eq ?options program entry_point input expected in let result = expect_eq ?options program entry_point input expected in
result result
@ -195,7 +195,7 @@ let expect_failwith_exp_trace_aux ?options explst program entry_point make_input
let aux exp = let aux exp =
let%bind input = make_input exp in let%bind input = make_input exp in
let%bind expected = make_expected_failwith 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 )) @@ trace (simple_error ("expect_eq_exp " ^ pps )) @@
let result = expect_string_failwith ?options program entry_point input expected in let result = expect_string_failwith ?options program entry_point input expected in
result 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)) expect_eq_n a b e_int (fun n -> e_int (c n))
let expect_eq_b_bool a b c = 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)) expect_eq_b a b (fun bool -> e_bool (c bool))

View File

@ -1,12 +1,9 @@
open Trace open Trace
open Test_helpers open Test_helpers
open Ast_simplified open Ast_core
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =

View File

@ -2,10 +2,7 @@ open Trace
open Test_helpers open Test_helpers
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "pascaligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "pascaligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =
@ -27,7 +24,7 @@ let compile_main () =
Ligo.Compile.Of_michelson.build_contract michelson_prg in Ligo.Compile.Of_michelson.build_contract michelson_prg in
ok () ok ()
open Ast_simplified open Ast_core
let empty_op_list = let empty_op_list =
(e_typed_list [] t_operation) (e_typed_list [] t_operation)
let empty_message = e_lambda (Var.of_name "arguments") let empty_message = e_lambda (Var.of_name "arguments")

View File

@ -1,10 +1,10 @@
open Trace open Trace
open Ast_simplified open Ast_core
open Test_helpers open Test_helpers
module Typed = Ast_typed module Typed = Ast_typed
module Typer = Typer module Typer = Typer
module Simplified = Ast_simplified module Simplified = Ast_core
let int () : unit result = let int () : unit result =
let open Combinators in let open Combinators in
@ -72,7 +72,7 @@ end
(* TODO: deep types (e.g. record of record) (* TODO: deep types (e.g. record of record)
TODO: negative tests (expected type error) *) 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 "int" int ;
test "unit" TestExpressions.unit ; test "unit" TestExpressions.unit ;
test "int2" TestExpressions.int ; test "int2" TestExpressions.int ;

View File

@ -2,10 +2,7 @@ open Trace
open Test_helpers open Test_helpers
let type_file f = let type_file f =
let%bind abstracted = Ligo.Compile.Of_source.compile f (Syntax_name "cameligo") in let%bind typed,state = Ligo.Compile.Utils.type_file f "cameligo" (Contract "main") 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
ok @@ (typed,state) ok @@ (typed,state)
let get_program = let get_program =
@ -18,7 +15,7 @@ let get_program =
ok (program , state) ok (program , state)
) )
open Ast_simplified open Ast_core
let init_storage name = e_record_ez [ let init_storage name = e_record_ez [
("title" , e_string name) ; ("title" , e_string name) ;
@ -41,14 +38,14 @@ let yea = e_constructor "Vote" (e_constructor "Yea" (e_unit ()))
let init_vote () = let init_vote () =
let%bind (program , _) = get_program () in let%bind (program , _) = get_program () in
let%bind result = 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 program "main" (e_pair yea (init_storage "basic")) in
let%bind (_, storage) = extract_pair result in let%bind (_, storage) = extract_pair result in
let%bind storage' = extract_record storage in let%bind storage' = extract_record storage in
(* let votes = List.assoc (Label "voters") storage' in (* let votes = List.assoc (Label "voters") storage' in
let%bind votes' = extract_map votes in *) let%bind votes' = extract_map votes in *)
let yea = List.assoc (Label "yea") storage' 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 () ok ()
let main = test_suite "Vote" [ let main = test_suite "Vote" [