From d8b7a12c690d7cea4bd0ae7a808b3e6bb555c06f Mon Sep 17 00:00:00 2001 From: galfour Date: Sun, 15 Sep 2019 13:12:19 +0200 Subject: [PATCH] more refactoring --- src/bin/cli_helpers.ml | 2 +- src/main/compile/of_mini_c.ml | 3 + src/main/compile/of_simplified.ml | 21 +- src/main/compile/of_source.ml | 35 +++ src/main/compile/of_typed.ml | 98 ++++++--- src/main/{run => }/display.ml | 0 src/main/run/dune | 1 + src/main/run/main.ml | 137 ------------ .../{from_michelson.ml => of_michelson.ml} | 0 src/main/run/{run_mini_c.ml => of_mini_c.ml} | 6 +- src/main/run/of_simplified.ml | 31 +++ src/main/run/of_source.ml | 92 ++++++++ src/main/run/of_typed.ml | 34 +++ src/main/run/run.ml | 4 + src/main/run/run_simplified.ml | 27 --- src/main/run/run_source.ml | 207 ------------------ src/main/run/run_typed.ml | 71 ------ {test => src/test}/.gitignore | 0 {test => src/test}/bin_tests.ml | 0 {test => src/test}/coase_tests.ml | 0 {test => src/test}/compiler_tests.ml | 0 {test => src/test}/contracts/amount.mligo | 0 {test => src/test}/contracts/annotation.ligo | 0 {test => src/test}/contracts/arithmetic.ligo | 0 {test => src/test}/contracts/assign.ligo | 0 {test => src/test}/contracts/basic.mligo | 0 .../test}/contracts/bitwise_arithmetic.ligo | 0 .../test}/contracts/boolean_operators.ligo | 0 .../test}/contracts/bytes_arithmetic.ligo | 0 {test => src/test}/contracts/closure-1.ligo | 0 {test => src/test}/contracts/closure-2.ligo | 0 {test => src/test}/contracts/closure-3.ligo | 0 {test => src/test}/contracts/closure.ligo | 0 {test => src/test}/contracts/coase.ligo | 0 .../test}/contracts/condition-simple.ligo | 0 {test => src/test}/contracts/condition.ligo | 0 {test => src/test}/contracts/counter.ligo | 0 {test => src/test}/contracts/counter.mligo | 0 .../test}/contracts/declaration-local.ligo | 0 .../test}/contracts/declarations.ligo | 0 .../test}/contracts/dispatch-counter.ligo | 0 .../test}/contracts/error_syntax.ligo | 0 {test => src/test}/contracts/error_type.ligo | 0 {test => src/test}/contracts/failwith.mligo | 0 .../test}/contracts/function-complex.ligo | 0 .../test}/contracts/function-shared.ligo | 0 {test => src/test}/contracts/function.ligo | 0 .../test}/contracts/guess_string.mligo | 0 .../test}/contracts/heap-instance.ligo | 0 {test => src/test}/contracts/heap.ligo | 0 {test => src/test}/contracts/high-order.ligo | 0 {test => src/test}/contracts/included.ligo | 0 {test => src/test}/contracts/includer.ligo | 0 {test => src/test}/contracts/lambda.ligo | 0 {test => src/test}/contracts/lambda.mligo | 0 {test => src/test}/contracts/lambda2.mligo | 0 {test => src/test}/contracts/letin.mligo | 0 {test => src/test}/contracts/list.ligo | 0 {test => src/test}/contracts/list.mligo | 0 {test => src/test}/contracts/loop.ligo | 0 {test => src/test}/contracts/map.ligo | 0 {test => src/test}/contracts/match.ligo | 0 {test => src/test}/contracts/match.mligo | 0 {test => src/test}/contracts/match_bis.mligo | 0 .../test}/contracts/multiple-parameters.ligo | 0 {test => src/test}/contracts/new-syntax.mligo | 0 {test => src/test}/contracts/option.ligo | 0 .../contracts/parser-bad-reported-term.ligo | 0 .../test}/contracts/quote-declaration.ligo | 0 .../test}/contracts/quote-declarations.ligo | 0 {test => src/test}/contracts/record.ligo | 0 {test => src/test}/contracts/record.mligo | 0 .../test}/contracts/set_arithmetic-1.ligo | 0 .../test}/contracts/set_arithmetic.ligo | 0 {test => src/test}/contracts/shadow.ligo | 0 {test => src/test}/contracts/string.ligo | 0 .../test}/contracts/string_arithmetic.ligo | 0 .../test}/contracts/super-counter.ligo | 0 .../test}/contracts/super-counter.mligo | 0 {test => src/test}/contracts/toto.ligo | 0 {test => src/test}/contracts/tuple.ligo | 0 {test => src/test}/contracts/type-alias.ligo | 0 {test => src/test}/contracts/unit.ligo | 0 .../test}/contracts/variant-matching.ligo | 0 {test => src/test}/contracts/variant.ligo | 0 {test => src/test}/contracts/vote.mligo | 0 {test => src/test}/contracts/website1.ligo | 0 {test => src/test}/contracts/website2.ligo | 0 {test => src/test}/dune | 0 {test => src/test}/heap_tests.ml | 0 {test => src/test}/integration_tests.ml | 0 {test => src/test}/manual_test.ml | 0 {test => src/test}/multifix_tests.ml | 0 {test => src/test}/test.ml | 0 {test => src/test}/test_helpers.ml | 0 {test => src/test}/transpiler_tests.ml | 0 {test => src/test}/typer_tests.ml | 0 {test => src/test}/vote_tests.ml | 0 98 files changed, 288 insertions(+), 481 deletions(-) rename src/main/{run => }/display.ml (100%) delete mode 100644 src/main/run/main.ml rename src/main/run/{from_michelson.ml => of_michelson.ml} (100%) rename src/main/run/{run_mini_c.ml => of_mini_c.ml} (86%) create mode 100644 src/main/run/of_simplified.ml create mode 100644 src/main/run/of_source.ml create mode 100644 src/main/run/of_typed.ml create mode 100644 src/main/run/run.ml delete mode 100644 src/main/run/run_simplified.ml delete mode 100644 src/main/run/run_source.ml delete mode 100644 src/main/run/run_typed.ml rename {test => src/test}/.gitignore (100%) rename {test => src/test}/bin_tests.ml (100%) rename {test => src/test}/coase_tests.ml (100%) rename {test => src/test}/compiler_tests.ml (100%) rename {test => src/test}/contracts/amount.mligo (100%) rename {test => src/test}/contracts/annotation.ligo (100%) rename {test => src/test}/contracts/arithmetic.ligo (100%) rename {test => src/test}/contracts/assign.ligo (100%) rename {test => src/test}/contracts/basic.mligo (100%) rename {test => src/test}/contracts/bitwise_arithmetic.ligo (100%) rename {test => src/test}/contracts/boolean_operators.ligo (100%) rename {test => src/test}/contracts/bytes_arithmetic.ligo (100%) rename {test => src/test}/contracts/closure-1.ligo (100%) rename {test => src/test}/contracts/closure-2.ligo (100%) rename {test => src/test}/contracts/closure-3.ligo (100%) rename {test => src/test}/contracts/closure.ligo (100%) rename {test => src/test}/contracts/coase.ligo (100%) rename {test => src/test}/contracts/condition-simple.ligo (100%) rename {test => src/test}/contracts/condition.ligo (100%) rename {test => src/test}/contracts/counter.ligo (100%) rename {test => src/test}/contracts/counter.mligo (100%) rename {test => src/test}/contracts/declaration-local.ligo (100%) rename {test => src/test}/contracts/declarations.ligo (100%) rename {test => src/test}/contracts/dispatch-counter.ligo (100%) rename {test => src/test}/contracts/error_syntax.ligo (100%) rename {test => src/test}/contracts/error_type.ligo (100%) rename {test => src/test}/contracts/failwith.mligo (100%) rename {test => src/test}/contracts/function-complex.ligo (100%) rename {test => src/test}/contracts/function-shared.ligo (100%) rename {test => src/test}/contracts/function.ligo (100%) rename {test => src/test}/contracts/guess_string.mligo (100%) rename {test => src/test}/contracts/heap-instance.ligo (100%) rename {test => src/test}/contracts/heap.ligo (100%) rename {test => src/test}/contracts/high-order.ligo (100%) rename {test => src/test}/contracts/included.ligo (100%) rename {test => src/test}/contracts/includer.ligo (100%) rename {test => src/test}/contracts/lambda.ligo (100%) rename {test => src/test}/contracts/lambda.mligo (100%) rename {test => src/test}/contracts/lambda2.mligo (100%) rename {test => src/test}/contracts/letin.mligo (100%) rename {test => src/test}/contracts/list.ligo (100%) rename {test => src/test}/contracts/list.mligo (100%) rename {test => src/test}/contracts/loop.ligo (100%) rename {test => src/test}/contracts/map.ligo (100%) rename {test => src/test}/contracts/match.ligo (100%) rename {test => src/test}/contracts/match.mligo (100%) rename {test => src/test}/contracts/match_bis.mligo (100%) rename {test => src/test}/contracts/multiple-parameters.ligo (100%) rename {test => src/test}/contracts/new-syntax.mligo (100%) rename {test => src/test}/contracts/option.ligo (100%) rename {test => src/test}/contracts/parser-bad-reported-term.ligo (100%) rename {test => src/test}/contracts/quote-declaration.ligo (100%) rename {test => src/test}/contracts/quote-declarations.ligo (100%) rename {test => src/test}/contracts/record.ligo (100%) rename {test => src/test}/contracts/record.mligo (100%) rename {test => src/test}/contracts/set_arithmetic-1.ligo (100%) rename {test => src/test}/contracts/set_arithmetic.ligo (100%) rename {test => src/test}/contracts/shadow.ligo (100%) rename {test => src/test}/contracts/string.ligo (100%) rename {test => src/test}/contracts/string_arithmetic.ligo (100%) rename {test => src/test}/contracts/super-counter.ligo (100%) rename {test => src/test}/contracts/super-counter.mligo (100%) rename {test => src/test}/contracts/toto.ligo (100%) rename {test => src/test}/contracts/tuple.ligo (100%) rename {test => src/test}/contracts/type-alias.ligo (100%) rename {test => src/test}/contracts/unit.ligo (100%) rename {test => src/test}/contracts/variant-matching.ligo (100%) rename {test => src/test}/contracts/variant.ligo (100%) rename {test => src/test}/contracts/vote.mligo (100%) rename {test => src/test}/contracts/website1.ligo (100%) rename {test => src/test}/contracts/website2.ligo (100%) rename {test => src/test}/dune (100%) rename {test => src/test}/heap_tests.ml (100%) rename {test => src/test}/integration_tests.ml (100%) rename {test => src/test}/manual_test.ml (100%) rename {test => src/test}/multifix_tests.ml (100%) rename {test => src/test}/test.ml (100%) rename {test => src/test}/test_helpers.ml (100%) rename {test => src/test}/transpiler_tests.ml (100%) rename {test => src/test}/typer_tests.ml (100%) rename {test => src/test}/vote_tests.ml (100%) diff --git a/src/bin/cli_helpers.ml b/src/bin/cli_helpers.ml index 068f2bf1d..28a565e40 100644 --- a/src/bin/cli_helpers.ml +++ b/src/bin/cli_helpers.ml @@ -4,6 +4,6 @@ let toplevel x = match x with | Trace.Ok ((), annotations) -> ignore annotations; () | Error ss -> ( - Format.printf "%a%!" Ligo.Display.error_pp (ss ()) + Format.printf "%a%!" Display.error_pp (ss ()) ) diff --git a/src/main/compile/of_mini_c.ml b/src/main/compile/of_mini_c.ml index ea964be97..ffd31b259 100644 --- a/src/main/compile/of_mini_c.ml +++ b/src/main/compile/of_mini_c.ml @@ -10,3 +10,6 @@ let compile_expression : expression -> Michelson.t result = fun e -> let compile_function : anon_function -> type_value -> type_value -> Compiler.Program.compiled_program result = fun f in_ty out_ty -> Compiler.Program.translate_entry f (in_ty , out_ty) + +let uncompile_value : Proto_alpha_utils.Memory_proto_alpha.X.ex_typed_value -> value result = fun x -> + Compiler.Uncompiler.translate_value x diff --git a/src/main/compile/of_simplified.ml b/src/main/compile/of_simplified.ml index 27bf6ebef..f6c4500ac 100644 --- a/src/main/compile/of_simplified.ml +++ b/src/main/compile/of_simplified.ml @@ -10,6 +10,23 @@ let compile_expression_entry (program : program) entry_point : Compiler.Program. let%bind typed_program = Typer.type_program program in Of_typed.compile_expression_entry typed_program entry_point -let compile_expression ae : Michelson.t result = - let%bind typed = Typer.type_expression Ast_typed.Environment.full_empty ae in +let compile_expression ?(env = Ast_typed.Environment.full_empty) ae : Michelson.t result = + let%bind typed = Typer.type_expression env ae in Of_typed.compile_expression typed + +let uncompile_typed_program_entry_expression_result program entry ex_ty_value = + let%bind output_type = + let%bind (entry_expression , _ ) = Of_typed.get_entry program entry in + ok entry_expression.type_annotation + in + let%bind typed = Of_typed.uncompile_value ex_ty_value output_type in + Typer.untype_expression typed + +let uncompile_typed_program_entry_function_result program entry ex_ty_value = + let%bind output_type = + let%bind (entry_expression , _ ) = Of_typed.get_entry program entry in + let%bind (_ , output_type) = Ast_typed.get_t_function entry_expression.type_annotation in + ok output_type + in + let%bind typed = Of_typed.uncompile_value ex_ty_value output_type in + Typer.untype_expression typed diff --git a/src/main/compile/of_source.ml b/src/main/compile/of_source.ml index a4fd4e814..9d6005e4d 100644 --- a/src/main/compile/of_source.ml +++ b/src/main/compile/of_source.ml @@ -17,3 +17,38 @@ let compile_file_parameter : string -> string -> string -> s_syntax -> Michelson let%bind syntax = syntax_to_variant syntax (Some source_filename) in let%bind simplified = parsify_expression syntax expression in Of_simplified.compile_expression simplified + +let compile_file_expression : string -> string -> string -> s_syntax -> Michelson.t result = + fun source_filename _entry_point expression syntax -> + let%bind syntax = syntax_to_variant syntax (Some source_filename) in + let%bind simplified = parsify_expression syntax expression in + Of_simplified.compile_expression simplified + +let compile_file_storage : string -> string -> string -> s_syntax -> Michelson.t result = + fun source_filename _entry_point expression syntax -> + let%bind syntax = syntax_to_variant syntax (Some source_filename) in + let%bind simplified = parsify_expression syntax expression in + Of_simplified.compile_expression simplified + +let compile_file_contract_args = + fun source_filename _entry_point storage parameter syntax -> + let%bind syntax = syntax_to_variant syntax (Some source_filename) in + let%bind storage_simplified = parsify_expression syntax storage in + let%bind parameter_simplified = parsify_expression syntax parameter in + let args = Ast_simplified.e_pair storage_simplified parameter_simplified in + Of_simplified.compile_expression args + +let type_file ?(debug_simplify = false) ?(debug_typed = false) + syntax (source_filename:string) : Ast_typed.program result = + let%bind syntax = syntax_to_variant syntax (Some source_filename) in + let%bind simpl = parsify syntax source_filename in + (if debug_simplify then + Format.(printf "Simplified : %a\n%!" Ast_simplified.PP.program simpl) + ) ; + let%bind typed = + trace (simple_error "typing") @@ + Typer.type_program simpl in + (if debug_typed then ( + Format.(printf "Typed : %a\n%!" Ast_typed.PP.program typed) + )) ; + ok typed diff --git a/src/main/compile/of_typed.ml b/src/main/compile/of_typed.ml index 96adc461c..962543444 100644 --- a/src/main/compile/of_typed.ml +++ b/src/main/compile/of_typed.ml @@ -51,6 +51,27 @@ let compile_function expr = in Of_mini_c.compile_function f in_ty out_ty + +let get_entry (lst : program) (name : string) : (annotated_expression * int) result = + let%bind entry_expression = + trace_option (Errors.missing_entry_point name) @@ + let aux x = + let (Declaration_constant (an , _)) = Location.unwrap x in + if (an.name = name) + then Some an.annotated_expression + else None + in + List.find_map aux lst + in + let entry_index = + let aux x = + let (Declaration_constant (an , _)) = Location.unwrap x in + an.name = name + in + List.find_index aux lst + in + ok (entry_expression , entry_index) + (* Assume the following code: ``` @@ -68,50 +89,61 @@ let compile_function expr = x + y ``` - To do so, each declaration `const variable = expr` is translated in - a function `body -> let variable = expr in body`. Those functions are - then applied in order, which yields `let x = 42 in let y = 120 in ...`. - The entry-point can be an expression, which is then functionalized if `to_functionalize` is set to true. *) -let aggregate_declarations_for_entry (lst : program) (name : string) (to_functionalize : bool) : annotated_expression result = - let rec aux acc (lst : program) = - let%bind acc = acc in - match lst with - | [] -> fail @@ Errors.missing_entry_point name - | hd :: tl -> ( - let (Declaration_constant (an , (pre_env , _))) = Location.unwrap hd in - if (an.name <> name) then ( - let next = fun expr -> - let cur = e_a_let_in an.name an.annotated_expression expr pre_env in - acc cur in - aux (ok next) tl - ) else ( - match (an.annotated_expression.expression , to_functionalize) with - | (E_lambda l , false) -> ( - let l' = { l with body = acc l.body } in - let e' = { an.annotated_expression with expression = E_lambda l' } in - ok e' - ) - | (_ , true) -> ( - ok @@ functionalize @@ acc an.annotated_expression - ) - | _ -> fail @@ Errors.not_functional_main an.annotated_expression.location - ) - ) +let get_aggregated_entry (lst : program) (name : string) (to_functionalize : bool) : annotated_expression result = + let%bind (entry_expression , entry_index) = get_entry lst name in + let pre_declarations = + let sub_program = List.until entry_index lst in + let aux x = Location.unwrap x in + List.map aux sub_program in - let%bind l = aux (ok (fun x -> x)) lst in - ok l + let wrapper = + let aux prec cur = + let (Declaration_constant (an , (pre_env , _))) = cur in + e_a_let_in an.name an.annotated_expression prec pre_env + in + fun expr -> List.fold_right' aux expr pre_declarations + in + match (entry_expression.expression , to_functionalize) with + | (E_lambda l , false) -> ( + let l' = { l with body = wrapper l.body } in + let e' = { entry_expression with expression = E_lambda l' } in + ok e' + ) + | (_ , true) -> ( + ok @@ functionalize @@ wrapper entry_expression + ) + | _ -> fail @@ Errors.not_functional_main entry_expression.location let compile_function_entry : program -> string -> _ = fun p entry -> - let%bind expr = aggregate_declarations_for_entry p entry false in + let%bind expr = get_aggregated_entry p entry false in compile_function expr let compile_expression_entry : program -> string -> _ = fun p entry -> - let%bind expr = aggregate_declarations_for_entry p entry true in + let%bind expr = get_aggregated_entry p entry true in compile_function expr let compile_expression_as_function : annotated_expression -> Compiler.Program.compiled_program result = fun e -> let expr = functionalize e in compile_function expr + +let uncompile_value : _ -> _ -> annotated_expression result = fun x ty -> + let%bind mini_c = Of_mini_c.uncompile_value x in + Transpiler.untranspile mini_c ty + +let uncompile_entry_function_result = fun program entry ex_ty_value -> + let%bind output_type = + let%bind (entry_expression , _ ) = get_entry program entry in + let%bind (_ , output_type) = get_t_function entry_expression.type_annotation in + ok output_type + in + uncompile_value ex_ty_value output_type + +let uncompile_entry_expression_result = fun program entry ex_ty_value -> + let%bind output_type = + let%bind (entry_expression , _ ) = get_entry program entry in + ok entry_expression.type_annotation + in + uncompile_value ex_ty_value output_type diff --git a/src/main/run/display.ml b/src/main/display.ml similarity index 100% rename from src/main/run/display.ml rename to src/main/display.ml diff --git a/src/main/run/dune b/src/main/run/dune index 330bf32d5..34f7986af 100644 --- a/src/main/run/dune +++ b/src/main/run/dune @@ -13,6 +13,7 @@ mini_c operators compiler + compile ) (preprocess (pps ppx_let) diff --git a/src/main/run/main.ml b/src/main/run/main.ml deleted file mode 100644 index 1c4afcd58..000000000 --- a/src/main/run/main.ml +++ /dev/null @@ -1,137 +0,0 @@ -module Run_mini_c = Run_mini_c - -(* open Trace *) -module Parser = Parser -module AST_Raw = Parser.Pascaligo.AST -module AST_Simplified = Ast_simplified -module AST_Typed = Ast_typed -module Mini_c = Mini_c -module Typer = Typer -module Transpiler = Transpiler - -module Run = struct - include Run_source - include Run_simplified - include Run_typed - include Run_mini_c -end - -module Display = Display - -(* module Parser_multifix = Multifix - * module Simplify_multifix = Simplify_multifix *) - - -(* let simplify (p:AST_Raw.t) : Ast_simplified.program result = Simplify.Pascaligo.simpl_program p - * let simplify_expr (e:AST_Raw.expr) : Ast_simplified.expression result = Simplify.Pascaligo.simpl_expression e - * let unparse_simplified_expr (e:AST_Simplified.expression) : string result = - * ok @@ Format.asprintf "%a" AST_Simplified.PP.expression e - * - * let type_ (p:AST_Simplified.program) : AST_Typed.program result = Typer.type_program p - * let type_expression ?(env:Typer.Environment.t = Typer.Environment.full_empty) - * (e:AST_Simplified.expression) : AST_Typed.annotated_expression result = - * Typer.type_expression env e - * let untype_expression (e:AST_Typed.annotated_expression) : AST_Simplified.expression result = Typer.untype_expression e - * - * let transpile (p:AST_Typed.program) : Mini_c.program result = Transpiler.translate_program p - * let transpile_entry (p:AST_Typed.program) (name:string) : Mini_c.anon_function result = Transpiler.translate_entry p name - * let transpile_expression (e:AST_Typed.annotated_expression) : Mini_c.expression result = Transpiler.translate_annotated_expression e - * - * let untranspile_value (v : Mini_c.value) (e:AST_Typed.type_value) : AST_Typed.annotated_expression result = - * Transpiler.untranspile v e - * - * let compile : Mini_c.program -> string -> Compiler.Program.compiled_program result = Compiler.Program.translate_program - * - * let easy_evaluate_typed (entry:string) (program:AST_Typed.program) : AST_Typed.annotated_expression result = - * let%bind result = - * let%bind mini_c_main = - * transpile_entry program entry in - * Run_mini_c.run_entry mini_c_main (Mini_c.Combinators.d_unit) in - * let%bind typed_result = - * let%bind typed_main = Ast_typed.get_entry program entry in - * untranspile_value result typed_main.type_annotation in - * ok typed_result - * - * - * let easy_evaluate_typed = trace_f_2_ez easy_evaluate_typed (thunk "easy evaluate typed") - * - * - * let easy_run_typed - * ?(debug_mini_c = false) ?options (entry:string) - * (program:AST_Typed.program) (input:AST_Typed.annotated_expression) : AST_Typed.annotated_expression result = - * let%bind () = - * let open Ast_typed in - * let%bind (Declaration_constant (d , _)) = get_declaration_by_name program entry in - * let%bind (arg_ty , _) = - * trace_strong (simple_error "entry-point doesn't have a function type") @@ - * get_t_function @@ get_type_annotation d.annotated_expression in - * Ast_typed.assert_type_value_eq (arg_ty , (Ast_typed.get_type_annotation input)) - * in - * - * let%bind mini_c_main = - * trace (simple_error "transpile mini_c entry") @@ - * transpile_entry program entry in - * (if debug_mini_c then - * Format.(printf "Mini_c : %a\n%!" Mini_c.PP.function_ mini_c_main) - * ) ; - * - * let%bind mini_c_value = transpile_value input in - * - * let%bind mini_c_result = - * let error = - * let title () = "run Mini_c" in - * let content () = - * Format.asprintf "\n%a" Mini_c.PP.function_ mini_c_main - * in - * error title content in - * trace error @@ - * Run_mini_c.run_entry ?options mini_c_main mini_c_value in - * let%bind typed_result = - * let%bind main_result_type = - * let%bind typed_main = Ast_typed.get_functional_entry program entry in - * match (snd typed_main).type_value' with - * | T_function (_, result) -> ok result - * | _ -> simple_fail "main doesn't have fun type" in - * untranspile_value mini_c_result main_result_type in - * ok typed_result - * - * let easy_run_typed_simplified - * ?(debug_mini_c = false) ?(debug_michelson = false) ?options (entry:string) - * (program:AST_Typed.program) (input:Ast_simplified.expression) : Ast_simplified.expression result = - * let%bind mini_c_main = - * trace (simple_error "transpile mini_c entry") @@ - * transpile_entry program entry in - * (if debug_mini_c then - * Format.(printf "Mini_c : %a\n%!" Mini_c.PP.function_ mini_c_main) - * ) ; - * - * let%bind typed_value = - * let env = - * let last_declaration = Location.unwrap List.(hd @@ rev program) in - * match last_declaration with - * | Declaration_constant (_ , (_ , post_env)) -> post_env - * in - * type_expression ~env input in - * let%bind mini_c_value = transpile_value typed_value in - * - * let%bind mini_c_result = - * let error = - * let title () = "run Mini_c" in - * let content () = - * Format.asprintf "\n%a" Mini_c.PP.function_ mini_c_main - * in - * error title content in - * trace error @@ - * Run_mini_c.run_entry ~debug_michelson ?options mini_c_main mini_c_value in - * let%bind typed_result = - * let%bind main_result_type = - * let%bind typed_main = Ast_typed.get_functional_entry program entry in - * match (snd typed_main).type_value' with - * | T_function (_, result) -> ok result - * | _ -> simple_fail "main doesn't have fun type" in - * untranspile_value mini_c_result main_result_type in - * let%bind annotated_result = untype_expression typed_result in - * ok annotated_result *) - - -(* module Contract = Contract *) diff --git a/src/main/run/from_michelson.ml b/src/main/run/of_michelson.ml similarity index 100% rename from src/main/run/from_michelson.ml rename to src/main/run/of_michelson.ml diff --git a/src/main/run/run_mini_c.ml b/src/main/run/of_mini_c.ml similarity index 86% rename from src/main/run/run_mini_c.ml rename to src/main/run/of_mini_c.ml index 06864c223..8e22c8a54 100644 --- a/src/main/run/run_mini_c.ml +++ b/src/main/run/of_mini_c.ml @@ -16,7 +16,7 @@ type options = { input_type : type_value ; output_type : type_value ; input : value ; - michelson_options : From_michelson.options ; + michelson_options : Of_michelson.options ; } let run_entry ?(debug_michelson = false) ?options (entry : anon_function) ty (input:value) : value result = @@ -31,7 +31,7 @@ let run_entry ?(debug_michelson = false) ?options (entry : anon_function) ty (in Format.printf "Input Type: %a\n" PP.type_ (fst ty) ; Format.printf "Compiled Input: %a\n" Michelson.pp input_michelson ; ) ; - let%bind ex_ty_value = From_michelson.run ?options compiled input_michelson in + let%bind ex_ty_value = Of_michelson.run ?options compiled input_michelson in if debug_michelson then ( let (Ex_typed_value (ty , v)) = ex_ty_value in ignore @@ @@ -41,5 +41,5 @@ let run_entry ?(debug_michelson = false) ?options (entry : anon_function) ty (in Format.printf "Compiled Output: %a\n" Michelson.pp michelson_value ; ok () ) ; - let%bind (result : value) = Compiler.Uncompiler.translate_value ex_ty_value in + let%bind (result : value) = Compile.Of_mini_c.uncompile_value ex_ty_value in ok result diff --git a/src/main/run/of_simplified.ml b/src/main/run/of_simplified.ml new file mode 100644 index 000000000..22e3d7026 --- /dev/null +++ b/src/main/run/of_simplified.ml @@ -0,0 +1,31 @@ +open Trace +open Ast_simplified + +let get_final_environment program = + let last_declaration = Location.unwrap List.(hd @@ rev program) in + let (Ast_typed.Declaration_constant (_ , (_ , post_env))) = last_declaration in + post_env + +let run_typed_program + ?options + (program : Ast_typed.program) (entry : string) + (input : expression) : expression result = + let%bind code = Compile.Of_typed.compile_function_entry program entry in + let%bind input = + let env = get_final_environment program in + Compile.Of_simplified.compile_expression ~env input + in + let%bind ex_ty_value = Of_michelson.run ?options code input in + Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry ex_ty_value + +let evaluate_typed_program_entry + ?options + (program : Ast_typed.program) (entry : string) + : Ast_simplified.expression result = + let%bind code = Compile.Of_typed.compile_expression_entry program entry in + let%bind input = + let fake_input = Ast_typed.(e_a_unit Environment.full_empty) in + Compile.Of_typed.compile_expression fake_input + in + let%bind ex_ty_value = Of_michelson.run ?options code input in + Compile.Of_simplified.uncompile_typed_program_entry_expression_result program entry ex_ty_value diff --git a/src/main/run/of_source.ml b/src/main/run/of_source.ml new file mode 100644 index 000000000..55a455f9e --- /dev/null +++ b/src/main/run/of_source.ml @@ -0,0 +1,92 @@ +open Trace + +include struct + open Ast_simplified + + let assert_entry_point_defined : program -> string -> unit result = + fun program entry_point -> + let aux : declaration -> bool = fun declaration -> + match declaration with + | Declaration_type _ -> false + | Declaration_constant (name , _ , _) -> name = entry_point + in + trace_strong (simple_error "no entry-point with given name") @@ + Assert.assert_true @@ List.exists aux @@ List.map Location.unwrap program +end + +include struct + open Ast_typed + open Combinators + + let get_entry_point_type : type_value -> (type_value * type_value) result = fun t -> + let%bind (arg , result) = + trace_strong (simple_error "entry-point doesn't have a function type") @@ + get_t_function t in + let%bind (arg' , storage_param) = + trace_strong (simple_error "entry-point doesn't have 2 parameters") @@ + get_t_pair arg in + let%bind (ops , storage_result) = + trace_strong (simple_error "entry-point doesn't have 2 results") @@ + get_t_pair result in + let%bind () = + trace_strong (simple_error "entry-point doesn't have a list of operation as first result") @@ + assert_t_list_operation ops in + let%bind () = + trace_strong (simple_error "entry-point doesn't identical type (storage) for second parameter and second result") @@ + assert_type_value_eq (storage_param , storage_result) in + ok (arg' , storage_param) + + let get_entry_point : program -> string -> (type_value * type_value) result = fun p e -> + let%bind declaration = get_declaration_by_name p e in + match declaration with + | Declaration_constant (d , _) -> get_entry_point_type d.annotated_expression.type_annotation + + let assert_valid_entry_point = fun p e -> + let%bind _ = get_entry_point p e in + ok () +end + +let run_contract ?amount source_filename entry_point storage parameter syntax = + let%bind program = Compile.Of_source.type_file syntax source_filename in + let%bind code = Compile.Of_typed.compile_function_entry program entry_point in + let%bind args = Compile.Of_source.compile_file_contract_args source_filename entry_point storage parameter syntax in + let%bind ex_value_ty = + let options = + let open Proto_alpha_utils.Memory_proto_alpha in + let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in + (make_options ?amount ()) + in + Of_michelson.run ~options code args + in + Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry_point ex_value_ty + +let run_function ?amount source_filename entry_point input syntax = + let%bind program = Compile.Of_source.type_file syntax source_filename in + let%bind code = Compile.Of_typed.compile_function_entry program entry_point in + let%bind args = Compile.Of_source.compile_file_expression source_filename entry_point input syntax in + let%bind ex_value_ty = + let options = + let open Proto_alpha_utils.Memory_proto_alpha in + let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in + (make_options ?amount ()) + in + Of_michelson.run ~options code args + in + Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry_point ex_value_ty + +let evaluate ?amount source_filename entry_point syntax = + let%bind program = Compile.Of_source.type_file syntax source_filename in + let%bind code = Compile.Of_typed.compile_expression_entry program entry_point in + let%bind input = + let fake_input = Ast_simplified.e_unit () in + Compile.Of_simplified.compile_expression fake_input + in + let%bind ex_value_ty = + let options = + let open Proto_alpha_utils.Memory_proto_alpha in + let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in + (make_options ?amount ()) + in + Of_michelson.run ~options code input + in + Compile.Of_simplified.uncompile_typed_program_entry_expression_result program entry_point ex_value_ty diff --git a/src/main/run/of_typed.ml b/src/main/run/of_typed.ml new file mode 100644 index 000000000..a7bbcb88c --- /dev/null +++ b/src/main/run/of_typed.ml @@ -0,0 +1,34 @@ +open Trace +open Ast_typed + +let run_function ?options f input = + let%bind code = Compile.Of_typed.compile_function f in + let%bind input = Compile.Of_typed.compile_expression input in + let%bind ex_ty_value = Of_michelson.run ?options code input in + let%bind ty = + let%bind (_ , output_ty) = get_t_function f.type_annotation in + ok output_ty + in + Compile.Of_typed.uncompile_value ex_ty_value ty + +let run_entry + ?options (entry : string) + (program : Ast_typed.program) (input : Ast_typed.annotated_expression) : Ast_typed.annotated_expression result = + let%bind code = Compile.Of_typed.compile_function_entry program entry in + let%bind input = Compile.Of_typed.compile_expression input in + let%bind ex_ty_value = Of_michelson.run ?options code input in + Compile.Of_typed.uncompile_entry_function_result program entry ex_ty_value + +let evaluate ?options (e : annotated_expression) : annotated_expression result = + let%bind code = Compile.Of_typed.compile_expression_as_function e in + let fake_input = e_a_unit Environment.full_empty in + let%bind input = Compile.Of_typed.compile_expression fake_input in + let%bind ex_ty_value = Of_michelson.run ?options code input in + Compile.Of_typed.uncompile_value ex_ty_value e.type_annotation + +let evaluate_entry ?options program entry = + let%bind code = Compile.Of_typed.compile_expression_entry program entry in + let fake_input = e_a_unit Environment.full_empty in + let%bind input = Compile.Of_typed.compile_expression fake_input in + let%bind ex_ty_value = Of_michelson.run ?options code input in + Compile.Of_typed.uncompile_entry_expression_result program entry ex_ty_value diff --git a/src/main/run/run.ml b/src/main/run/run.ml new file mode 100644 index 000000000..10ca5ed1d --- /dev/null +++ b/src/main/run/run.ml @@ -0,0 +1,4 @@ +module Of_typed = Of_typed +module Of_simplified = Of_simplified +module Of_mini_c = Of_mini_c +module Of_michelson = Of_michelson diff --git a/src/main/run/run_simplified.ml b/src/main/run/run_simplified.ml deleted file mode 100644 index 4faf34aaf..000000000 --- a/src/main/run/run_simplified.ml +++ /dev/null @@ -1,27 +0,0 @@ -open Trace - -let run_simplityped - ?options - ?(debug_mini_c = false) ?(debug_michelson = false) - (program : Ast_typed.program) (entry : string) - (input : Ast_simplified.expression) : Ast_simplified.expression result = - let%bind typed_input = - let env = - let last_declaration = Location.unwrap List.(hd @@ rev program) in - match last_declaration with - | Declaration_constant (_ , (_ , post_env)) -> post_env - in - Typer.type_expression env input in - let%bind typed_result = - Run_typed.run_typed ?options ~debug_mini_c ~debug_michelson entry program typed_input in - let%bind annotated_result = Typer.untype_expression typed_result in - ok annotated_result - -let evaluate_simplityped - ?options - ?(debug_mini_c = false) ?(debug_michelson = false) - (program : Ast_typed.program) (entry : string) - : Ast_simplified.expression result = - let%bind typed_result = Run_typed.evaluate_typed ?options ~debug_mini_c ~debug_michelson entry program in - let%bind annotated_result = Typer.untype_expression typed_result in - ok annotated_result diff --git a/src/main/run/run_source.ml b/src/main/run/run_source.ml deleted file mode 100644 index 214d1e091..000000000 --- a/src/main/run/run_source.ml +++ /dev/null @@ -1,207 +0,0 @@ -open Trace - -include struct - open Ast_simplified - - let assert_entry_point_defined : program -> string -> unit result = - fun program entry_point -> - let aux : declaration -> bool = fun declaration -> - match declaration with - | Declaration_type _ -> false - | Declaration_constant (name , _ , _) -> name = entry_point - in - trace_strong (simple_error "no entry-point with given name") @@ - Assert.assert_true @@ List.exists aux @@ List.map Location.unwrap program -end - -include struct - open Ast_typed - open Combinators - - let get_entry_point_type : type_value -> (type_value * type_value) result = fun t -> - let%bind (arg , result) = - trace_strong (simple_error "entry-point doesn't have a function type") @@ - get_t_function t in - let%bind (arg' , storage_param) = - trace_strong (simple_error "entry-point doesn't have 2 parameters") @@ - get_t_pair arg in - let%bind (ops , storage_result) = - trace_strong (simple_error "entry-point doesn't have 2 results") @@ - get_t_pair result in - let%bind () = - trace_strong (simple_error "entry-point doesn't have a list of operation as first result") @@ - assert_t_list_operation ops in - let%bind () = - trace_strong (simple_error "entry-point doesn't identical type (storage) for second parameter and second result") @@ - assert_type_value_eq (storage_param , storage_result) in - ok (arg' , storage_param) - - let get_entry_point : program -> string -> (type_value * type_value) result = fun p e -> - let%bind declaration = get_declaration_by_name p e in - match declaration with - | Declaration_constant (d , _) -> get_entry_point_type d.annotated_expression.type_annotation - - let assert_valid_entry_point = fun p e -> - let%bind _ = get_entry_point p e in - ok () -end - -let transpile_value - (e:Ast_typed.annotated_expression) : (Mini_c.value * _) result = - let%bind (f , ty) = - let open Transpiler in - let (f , _) = functionalize e in - let%bind main = translate_main f e.location in - ok main - in - - let input = Mini_c.Combinators.d_unit in - let%bind r = Run_mini_c.run_entry f ty input in - ok (r , snd ty) - -open Helpers - -let compile_contract_file : string -> string -> s_syntax -> string result = fun source_filename entry_point syntax -> - let%bind syntax = syntax_to_variant syntax (Some source_filename) in - let%bind simplified = parsify syntax source_filename in - let%bind () = - assert_entry_point_defined simplified entry_point in - let%bind typed = - trace (simple_error "typing") @@ - Typer.type_program simplified in - let%bind (mini_c , mini_c_ty) = - trace (simple_error "transpiling") @@ - Transpiler.translate_entry typed entry_point in - let%bind michelson = - trace (simple_error "compiling") @@ - Compiler.translate_contract mini_c mini_c_ty in - let str = - Format.asprintf "%a" Michelson.pp_stripped michelson in - ok str - -let compile_contract_parameter : string -> string -> string -> s_syntax -> string result = fun source_filename entry_point expression syntax -> - let%bind syntax = syntax_to_variant syntax (Some source_filename) in - let%bind (program , parameter_tv) = - let%bind simplified = parsify syntax source_filename in - let%bind () = - assert_entry_point_defined simplified entry_point in - let%bind typed = - trace (simple_error "typing file") @@ - Typer.type_program simplified in - let%bind (param_ty , _) = - get_entry_point typed entry_point in - ok (typed , param_ty) - in - let%bind expr = - let%bind typed = - let%bind simplified = parsify_expression syntax expression in - let env = - let last_declaration = Location.unwrap List.(hd @@ rev program) in - match last_declaration with - | Declaration_constant (_ , (_ , post_env)) -> post_env - in - trace (simple_error "typing expression") @@ - Typer.type_expression env simplified in - let%bind () = - trace (simple_error "expression type doesn't match type parameter") @@ - Ast_typed.assert_type_value_eq (parameter_tv , typed.type_annotation) in - let%bind (mini_c , mini_c_ty) = - trace (simple_error "transpiling expression") @@ - transpile_value typed in - let%bind michelson = - trace (simple_error "compiling expression") @@ - Compiler.translate_value mini_c mini_c_ty in - let str = - Format.asprintf "%a" Michelson.pp_stripped michelson in - ok str - in - ok expr - - -let compile_contract_storage : string -> string -> string -> s_syntax -> string result = fun source_filename entry_point expression syntax -> - let%bind syntax = syntax_to_variant syntax (Some source_filename) in - let%bind (program , storage_tv) = - let%bind simplified = parsify syntax source_filename in - let%bind () = - assert_entry_point_defined simplified entry_point in - let%bind typed = - trace (simple_error "typing file") @@ - Typer.type_program simplified in - let%bind (_ , storage_ty) = - get_entry_point typed entry_point in - ok (typed , storage_ty) - in - let%bind expr = - let%bind simplified = parsify_expression syntax expression in - let%bind typed = - let env = - let last_declaration = Location.unwrap List.(hd @@ rev program) in - match last_declaration with - | Declaration_constant (_ , (_ , post_env)) -> post_env - in - trace (simple_error "typing expression") @@ - Typer.type_expression env simplified in - let%bind () = - trace (simple_error "expression type doesn't match type storage") @@ - Ast_typed.assert_type_value_eq (storage_tv , typed.type_annotation) in - let%bind (mini_c , mini_c_ty) = - trace (simple_error "transpiling expression") @@ - transpile_value typed in - let%bind michelson = - trace (simple_error "compiling expression") @@ - Compiler.translate_value mini_c mini_c_ty in - let str = - Format.asprintf "%a" Michelson.pp_stripped michelson in - ok str - in - ok expr - -let type_file ?(debug_simplify = false) ?(debug_typed = false) - syntax (source_filename:string) : Ast_typed.program result = - let%bind simpl = parsify syntax source_filename in - (if debug_simplify then - Format.(printf "Simplified : %a\n%!" Ast_simplified.PP.program simpl) - ) ; - let%bind typed = - trace (simple_error "typing") @@ - Typer.type_program simpl in - (if debug_typed then ( - Format.(printf "Typed : %a\n%!" Ast_typed.PP.program typed) - )) ; - ok typed - -let run_contract ?amount source_filename entry_point storage input syntax = - let%bind syntax = syntax_to_variant syntax (Some source_filename) in - let%bind typed = - type_file syntax source_filename in - let%bind storage_simpl = - parsify_expression syntax storage in - let%bind input_simpl = - parsify_expression syntax input in - let options = - let open Proto_alpha_utils.Memory_proto_alpha in - let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in - (make_options ?amount ()) in - Run_simplified.run_simplityped ~options typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl) - -let run_function ?amount source_filename entry_point parameter syntax = - let%bind syntax = syntax_to_variant syntax (Some source_filename) in - let%bind typed = - type_file syntax source_filename in - let%bind parameter' = - parsify_expression syntax parameter in - let options = - let open Proto_alpha_utils.Memory_proto_alpha in - let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in - (make_options ?amount ()) in - Run_simplified.run_simplityped ~options typed entry_point parameter' - -let evaluate_value ?amount source_filename entry_point syntax = - let%bind syntax = syntax_to_variant syntax (Some source_filename) in - let%bind typed = - type_file syntax source_filename in - let options = - let open Proto_alpha_utils.Memory_proto_alpha in - let amount = Option.bind (fun amount -> Protocol.Alpha_context.Tez.of_string amount) amount in - (make_options ?amount ()) in - Run_simplified.evaluate_simplityped ~options typed entry_point diff --git a/src/main/run/run_typed.ml b/src/main/run/run_typed.ml deleted file mode 100644 index 0f41fe6fa..000000000 --- a/src/main/run/run_typed.ml +++ /dev/null @@ -1,71 +0,0 @@ -open Trace -open Ast_typed - -let evaluate (e : annotated_expression) : annotated_expression result = - let%bind (f , ty) = - let open Transpiler in - let (f , _) = functionalize e in - let%bind main = translate_main f e.location in - ok main - in - - let input = Mini_c.Combinators.d_unit in - let%bind r = Run_mini_c.run_entry f ty input in - ok r - -let evaluate_typed - ?(debug_mini_c = false) ?(debug_michelson = false) - ?options (entry:string) (program:Ast_typed.program) : Ast_typed.annotated_expression result = - trace (simple_error "easy evaluate typed") @@ - let%bind result = - let%bind (mini_c_main , ty) = - Transpiler.translate_entry program entry in - (if debug_mini_c then - Format.(printf "Mini_c : %a\n%!" Mini_c.PP.function_ mini_c_main) - ) ; - Run_mini_c.run_entry ?options ~debug_michelson mini_c_main ty (Mini_c.Combinators.d_unit) - in - let%bind typed_result = - let%bind typed_main = Ast_typed.get_entry program entry in - Transpiler.untranspile result typed_main.type_annotation in - ok typed_result - -let run_typed - ?(debug_mini_c = false) ?(debug_michelson = false) ?options (entry:string) - (program : Ast_typed.program) (input : Ast_typed.annotated_expression) : Ast_typed.annotated_expression result = - let%bind - let%bind () = - let open Ast_typed in - let%bind (Declaration_constant (d , _)) = get_declaration_by_name program entry in - let%bind (arg_ty , _) = - trace_strong (simple_error "entry-point doesn't have a function type") @@ - get_t_function @@ get_type_annotation d.annotated_expression in - Ast_typed.assert_type_value_eq (arg_ty , (Ast_typed.get_type_annotation input)) - in - - let%bind (mini_c_main , ty) = - trace (simple_error "transpile mini_c entry") @@ - Transpiler.translate_entry program entry in - (if debug_mini_c then - Format.(printf "Mini_c : %a\n%!" Mini_c.PP.function_ mini_c_main) - ) ; - - let%bind mini_c_value = transpile_value input in - - let%bind mini_c_result = - let error = - let title () = "run Mini_c" in - let content () = - Format.asprintf "\n%a" Mini_c.PP.function_ mini_c_main - in - error title content in - trace error @@ - Run_mini_c.run_entry ~debug_michelson ?options mini_c_main ty mini_c_value in - let%bind typed_result = - let%bind main_result_type = - let%bind typed_main = Ast_typed.get_functional_entry program entry in - match (snd typed_main).type_value' with - | T_function (_, result) -> ok result - | _ -> simple_fail "main doesn't have fun type" in - Transpiler.untranspile mini_c_result main_result_type in - ok typed_result diff --git a/test/.gitignore b/src/test/.gitignore similarity index 100% rename from test/.gitignore rename to src/test/.gitignore diff --git a/test/bin_tests.ml b/src/test/bin_tests.ml similarity index 100% rename from test/bin_tests.ml rename to src/test/bin_tests.ml diff --git a/test/coase_tests.ml b/src/test/coase_tests.ml similarity index 100% rename from test/coase_tests.ml rename to src/test/coase_tests.ml diff --git a/test/compiler_tests.ml b/src/test/compiler_tests.ml similarity index 100% rename from test/compiler_tests.ml rename to src/test/compiler_tests.ml diff --git a/test/contracts/amount.mligo b/src/test/contracts/amount.mligo similarity index 100% rename from test/contracts/amount.mligo rename to src/test/contracts/amount.mligo diff --git a/test/contracts/annotation.ligo b/src/test/contracts/annotation.ligo similarity index 100% rename from test/contracts/annotation.ligo rename to src/test/contracts/annotation.ligo diff --git a/test/contracts/arithmetic.ligo b/src/test/contracts/arithmetic.ligo similarity index 100% rename from test/contracts/arithmetic.ligo rename to src/test/contracts/arithmetic.ligo diff --git a/test/contracts/assign.ligo b/src/test/contracts/assign.ligo similarity index 100% rename from test/contracts/assign.ligo rename to src/test/contracts/assign.ligo diff --git a/test/contracts/basic.mligo b/src/test/contracts/basic.mligo similarity index 100% rename from test/contracts/basic.mligo rename to src/test/contracts/basic.mligo diff --git a/test/contracts/bitwise_arithmetic.ligo b/src/test/contracts/bitwise_arithmetic.ligo similarity index 100% rename from test/contracts/bitwise_arithmetic.ligo rename to src/test/contracts/bitwise_arithmetic.ligo diff --git a/test/contracts/boolean_operators.ligo b/src/test/contracts/boolean_operators.ligo similarity index 100% rename from test/contracts/boolean_operators.ligo rename to src/test/contracts/boolean_operators.ligo diff --git a/test/contracts/bytes_arithmetic.ligo b/src/test/contracts/bytes_arithmetic.ligo similarity index 100% rename from test/contracts/bytes_arithmetic.ligo rename to src/test/contracts/bytes_arithmetic.ligo diff --git a/test/contracts/closure-1.ligo b/src/test/contracts/closure-1.ligo similarity index 100% rename from test/contracts/closure-1.ligo rename to src/test/contracts/closure-1.ligo diff --git a/test/contracts/closure-2.ligo b/src/test/contracts/closure-2.ligo similarity index 100% rename from test/contracts/closure-2.ligo rename to src/test/contracts/closure-2.ligo diff --git a/test/contracts/closure-3.ligo b/src/test/contracts/closure-3.ligo similarity index 100% rename from test/contracts/closure-3.ligo rename to src/test/contracts/closure-3.ligo diff --git a/test/contracts/closure.ligo b/src/test/contracts/closure.ligo similarity index 100% rename from test/contracts/closure.ligo rename to src/test/contracts/closure.ligo diff --git a/test/contracts/coase.ligo b/src/test/contracts/coase.ligo similarity index 100% rename from test/contracts/coase.ligo rename to src/test/contracts/coase.ligo diff --git a/test/contracts/condition-simple.ligo b/src/test/contracts/condition-simple.ligo similarity index 100% rename from test/contracts/condition-simple.ligo rename to src/test/contracts/condition-simple.ligo diff --git a/test/contracts/condition.ligo b/src/test/contracts/condition.ligo similarity index 100% rename from test/contracts/condition.ligo rename to src/test/contracts/condition.ligo diff --git a/test/contracts/counter.ligo b/src/test/contracts/counter.ligo similarity index 100% rename from test/contracts/counter.ligo rename to src/test/contracts/counter.ligo diff --git a/test/contracts/counter.mligo b/src/test/contracts/counter.mligo similarity index 100% rename from test/contracts/counter.mligo rename to src/test/contracts/counter.mligo diff --git a/test/contracts/declaration-local.ligo b/src/test/contracts/declaration-local.ligo similarity index 100% rename from test/contracts/declaration-local.ligo rename to src/test/contracts/declaration-local.ligo diff --git a/test/contracts/declarations.ligo b/src/test/contracts/declarations.ligo similarity index 100% rename from test/contracts/declarations.ligo rename to src/test/contracts/declarations.ligo diff --git a/test/contracts/dispatch-counter.ligo b/src/test/contracts/dispatch-counter.ligo similarity index 100% rename from test/contracts/dispatch-counter.ligo rename to src/test/contracts/dispatch-counter.ligo diff --git a/test/contracts/error_syntax.ligo b/src/test/contracts/error_syntax.ligo similarity index 100% rename from test/contracts/error_syntax.ligo rename to src/test/contracts/error_syntax.ligo diff --git a/test/contracts/error_type.ligo b/src/test/contracts/error_type.ligo similarity index 100% rename from test/contracts/error_type.ligo rename to src/test/contracts/error_type.ligo diff --git a/test/contracts/failwith.mligo b/src/test/contracts/failwith.mligo similarity index 100% rename from test/contracts/failwith.mligo rename to src/test/contracts/failwith.mligo diff --git a/test/contracts/function-complex.ligo b/src/test/contracts/function-complex.ligo similarity index 100% rename from test/contracts/function-complex.ligo rename to src/test/contracts/function-complex.ligo diff --git a/test/contracts/function-shared.ligo b/src/test/contracts/function-shared.ligo similarity index 100% rename from test/contracts/function-shared.ligo rename to src/test/contracts/function-shared.ligo diff --git a/test/contracts/function.ligo b/src/test/contracts/function.ligo similarity index 100% rename from test/contracts/function.ligo rename to src/test/contracts/function.ligo diff --git a/test/contracts/guess_string.mligo b/src/test/contracts/guess_string.mligo similarity index 100% rename from test/contracts/guess_string.mligo rename to src/test/contracts/guess_string.mligo diff --git a/test/contracts/heap-instance.ligo b/src/test/contracts/heap-instance.ligo similarity index 100% rename from test/contracts/heap-instance.ligo rename to src/test/contracts/heap-instance.ligo diff --git a/test/contracts/heap.ligo b/src/test/contracts/heap.ligo similarity index 100% rename from test/contracts/heap.ligo rename to src/test/contracts/heap.ligo diff --git a/test/contracts/high-order.ligo b/src/test/contracts/high-order.ligo similarity index 100% rename from test/contracts/high-order.ligo rename to src/test/contracts/high-order.ligo diff --git a/test/contracts/included.ligo b/src/test/contracts/included.ligo similarity index 100% rename from test/contracts/included.ligo rename to src/test/contracts/included.ligo diff --git a/test/contracts/includer.ligo b/src/test/contracts/includer.ligo similarity index 100% rename from test/contracts/includer.ligo rename to src/test/contracts/includer.ligo diff --git a/test/contracts/lambda.ligo b/src/test/contracts/lambda.ligo similarity index 100% rename from test/contracts/lambda.ligo rename to src/test/contracts/lambda.ligo diff --git a/test/contracts/lambda.mligo b/src/test/contracts/lambda.mligo similarity index 100% rename from test/contracts/lambda.mligo rename to src/test/contracts/lambda.mligo diff --git a/test/contracts/lambda2.mligo b/src/test/contracts/lambda2.mligo similarity index 100% rename from test/contracts/lambda2.mligo rename to src/test/contracts/lambda2.mligo diff --git a/test/contracts/letin.mligo b/src/test/contracts/letin.mligo similarity index 100% rename from test/contracts/letin.mligo rename to src/test/contracts/letin.mligo diff --git a/test/contracts/list.ligo b/src/test/contracts/list.ligo similarity index 100% rename from test/contracts/list.ligo rename to src/test/contracts/list.ligo diff --git a/test/contracts/list.mligo b/src/test/contracts/list.mligo similarity index 100% rename from test/contracts/list.mligo rename to src/test/contracts/list.mligo diff --git a/test/contracts/loop.ligo b/src/test/contracts/loop.ligo similarity index 100% rename from test/contracts/loop.ligo rename to src/test/contracts/loop.ligo diff --git a/test/contracts/map.ligo b/src/test/contracts/map.ligo similarity index 100% rename from test/contracts/map.ligo rename to src/test/contracts/map.ligo diff --git a/test/contracts/match.ligo b/src/test/contracts/match.ligo similarity index 100% rename from test/contracts/match.ligo rename to src/test/contracts/match.ligo diff --git a/test/contracts/match.mligo b/src/test/contracts/match.mligo similarity index 100% rename from test/contracts/match.mligo rename to src/test/contracts/match.mligo diff --git a/test/contracts/match_bis.mligo b/src/test/contracts/match_bis.mligo similarity index 100% rename from test/contracts/match_bis.mligo rename to src/test/contracts/match_bis.mligo diff --git a/test/contracts/multiple-parameters.ligo b/src/test/contracts/multiple-parameters.ligo similarity index 100% rename from test/contracts/multiple-parameters.ligo rename to src/test/contracts/multiple-parameters.ligo diff --git a/test/contracts/new-syntax.mligo b/src/test/contracts/new-syntax.mligo similarity index 100% rename from test/contracts/new-syntax.mligo rename to src/test/contracts/new-syntax.mligo diff --git a/test/contracts/option.ligo b/src/test/contracts/option.ligo similarity index 100% rename from test/contracts/option.ligo rename to src/test/contracts/option.ligo diff --git a/test/contracts/parser-bad-reported-term.ligo b/src/test/contracts/parser-bad-reported-term.ligo similarity index 100% rename from test/contracts/parser-bad-reported-term.ligo rename to src/test/contracts/parser-bad-reported-term.ligo diff --git a/test/contracts/quote-declaration.ligo b/src/test/contracts/quote-declaration.ligo similarity index 100% rename from test/contracts/quote-declaration.ligo rename to src/test/contracts/quote-declaration.ligo diff --git a/test/contracts/quote-declarations.ligo b/src/test/contracts/quote-declarations.ligo similarity index 100% rename from test/contracts/quote-declarations.ligo rename to src/test/contracts/quote-declarations.ligo diff --git a/test/contracts/record.ligo b/src/test/contracts/record.ligo similarity index 100% rename from test/contracts/record.ligo rename to src/test/contracts/record.ligo diff --git a/test/contracts/record.mligo b/src/test/contracts/record.mligo similarity index 100% rename from test/contracts/record.mligo rename to src/test/contracts/record.mligo diff --git a/test/contracts/set_arithmetic-1.ligo b/src/test/contracts/set_arithmetic-1.ligo similarity index 100% rename from test/contracts/set_arithmetic-1.ligo rename to src/test/contracts/set_arithmetic-1.ligo diff --git a/test/contracts/set_arithmetic.ligo b/src/test/contracts/set_arithmetic.ligo similarity index 100% rename from test/contracts/set_arithmetic.ligo rename to src/test/contracts/set_arithmetic.ligo diff --git a/test/contracts/shadow.ligo b/src/test/contracts/shadow.ligo similarity index 100% rename from test/contracts/shadow.ligo rename to src/test/contracts/shadow.ligo diff --git a/test/contracts/string.ligo b/src/test/contracts/string.ligo similarity index 100% rename from test/contracts/string.ligo rename to src/test/contracts/string.ligo diff --git a/test/contracts/string_arithmetic.ligo b/src/test/contracts/string_arithmetic.ligo similarity index 100% rename from test/contracts/string_arithmetic.ligo rename to src/test/contracts/string_arithmetic.ligo diff --git a/test/contracts/super-counter.ligo b/src/test/contracts/super-counter.ligo similarity index 100% rename from test/contracts/super-counter.ligo rename to src/test/contracts/super-counter.ligo diff --git a/test/contracts/super-counter.mligo b/src/test/contracts/super-counter.mligo similarity index 100% rename from test/contracts/super-counter.mligo rename to src/test/contracts/super-counter.mligo diff --git a/test/contracts/toto.ligo b/src/test/contracts/toto.ligo similarity index 100% rename from test/contracts/toto.ligo rename to src/test/contracts/toto.ligo diff --git a/test/contracts/tuple.ligo b/src/test/contracts/tuple.ligo similarity index 100% rename from test/contracts/tuple.ligo rename to src/test/contracts/tuple.ligo diff --git a/test/contracts/type-alias.ligo b/src/test/contracts/type-alias.ligo similarity index 100% rename from test/contracts/type-alias.ligo rename to src/test/contracts/type-alias.ligo diff --git a/test/contracts/unit.ligo b/src/test/contracts/unit.ligo similarity index 100% rename from test/contracts/unit.ligo rename to src/test/contracts/unit.ligo diff --git a/test/contracts/variant-matching.ligo b/src/test/contracts/variant-matching.ligo similarity index 100% rename from test/contracts/variant-matching.ligo rename to src/test/contracts/variant-matching.ligo diff --git a/test/contracts/variant.ligo b/src/test/contracts/variant.ligo similarity index 100% rename from test/contracts/variant.ligo rename to src/test/contracts/variant.ligo diff --git a/test/contracts/vote.mligo b/src/test/contracts/vote.mligo similarity index 100% rename from test/contracts/vote.mligo rename to src/test/contracts/vote.mligo diff --git a/test/contracts/website1.ligo b/src/test/contracts/website1.ligo similarity index 100% rename from test/contracts/website1.ligo rename to src/test/contracts/website1.ligo diff --git a/test/contracts/website2.ligo b/src/test/contracts/website2.ligo similarity index 100% rename from test/contracts/website2.ligo rename to src/test/contracts/website2.ligo diff --git a/test/dune b/src/test/dune similarity index 100% rename from test/dune rename to src/test/dune diff --git a/test/heap_tests.ml b/src/test/heap_tests.ml similarity index 100% rename from test/heap_tests.ml rename to src/test/heap_tests.ml diff --git a/test/integration_tests.ml b/src/test/integration_tests.ml similarity index 100% rename from test/integration_tests.ml rename to src/test/integration_tests.ml diff --git a/test/manual_test.ml b/src/test/manual_test.ml similarity index 100% rename from test/manual_test.ml rename to src/test/manual_test.ml diff --git a/test/multifix_tests.ml b/src/test/multifix_tests.ml similarity index 100% rename from test/multifix_tests.ml rename to src/test/multifix_tests.ml diff --git a/test/test.ml b/src/test/test.ml similarity index 100% rename from test/test.ml rename to src/test/test.ml diff --git a/test/test_helpers.ml b/src/test/test_helpers.ml similarity index 100% rename from test/test_helpers.ml rename to src/test/test_helpers.ml diff --git a/test/transpiler_tests.ml b/src/test/transpiler_tests.ml similarity index 100% rename from test/transpiler_tests.ml rename to src/test/transpiler_tests.ml diff --git a/test/typer_tests.ml b/src/test/typer_tests.ml similarity index 100% rename from test/typer_tests.ml rename to src/test/typer_tests.ml diff --git a/test/vote_tests.ml b/src/test/vote_tests.ml similarity index 100% rename from test/vote_tests.ml rename to src/test/vote_tests.ml