From b619fa1f1712284dbdda65e224cdf7589f5ac4dd Mon Sep 17 00:00:00 2001 From: galfour Date: Wed, 18 Sep 2019 18:49:33 +0200 Subject: [PATCH] further down the road --- src/bin/cli.ml | 18 +++++++++--------- src/bin/cli_helpers.ml | 2 +- src/main/compile/of_source.ml | 10 ++++++++-- src/main/main.ml | 1 + src/main/run/of_simplified.ml | 3 ++- src/main/run/run.ml | 1 + src/passes/1-parser/pascaligo.ml | 2 +- src/test/bin_tests.ml | 3 +-- src/test/coase_tests.ml | 3 +-- src/test/compiler_tests.ml | 4 ++-- src/test/heap_tests.ml | 5 +++-- src/test/integration_tests.ml | 15 +++++++-------- src/test/test_helpers.ml | 6 +++--- src/test/typer_tests.ml | 8 ++++---- src/test/vote_tests.ml | 7 ++++--- vendors/ligo-utils/simple-utils/x_list.ml | 1 - 16 files changed, 48 insertions(+), 41 deletions(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index 11777b504..29fa6247c 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -50,8 +50,8 @@ let compile_file = toplevel @@ let%bind contract = trace (simple_info "compiling contract to michelson") @@ - Ligo.Run.compile_contract_file source entry_point (Syntax_name syntax) in - Format.printf "%s\n" contract ; + Ligo.Compile.Of_source.compile_file_contract_entry source entry_point (Syntax_name syntax) in + Format.printf "%a\n" Tezos_utils.Michelson.pp contract ; ok () in let term = @@ -65,8 +65,8 @@ let compile_parameter = toplevel @@ let%bind value = trace (simple_error "compile-input") @@ - Ligo.Run.compile_contract_parameter source entry_point expression (Syntax_name syntax) in - Format.printf "%s\n" value; + Ligo.Compile.Of_source.compile_file_contract_parameter source entry_point expression (Syntax_name syntax) in + Format.printf "%a\n" Tezos_utils.Michelson.pp value; ok () in let term = @@ -80,8 +80,8 @@ let compile_storage = toplevel @@ let%bind value = trace (simple_error "compile-storage") @@ - Ligo.Run.compile_contract_storage source entry_point expression (Syntax_name syntax) in - Format.printf "%s\n" value; + Ligo.Compile.Of_source.compile_file_contract_storage source entry_point expression (Syntax_name syntax) in + Format.printf "%a\n" Tezos_utils.Michelson.pp value; ok () in let term = @@ -94,7 +94,7 @@ let dry_run = let f source entry_point storage input amount syntax = toplevel @@ let%bind output = - Ligo.Run.run_contract ~amount source entry_point storage input (Syntax_name syntax) in + Ligo.Run.Of_source.run_contract ~amount source entry_point storage input (Syntax_name syntax) in Format.printf "%a\n" Ast_simplified.PP.expression output ; ok () in @@ -108,7 +108,7 @@ let run_function = let f source entry_point parameter amount syntax = toplevel @@ let%bind output = - Ligo.Run.run_function ~amount source entry_point parameter (Syntax_name syntax) in + Ligo.Run.Of_source.run_function ~amount source entry_point parameter (Syntax_name syntax) in Format.printf "%a\n" Ast_simplified.PP.expression output ; ok () in @@ -122,7 +122,7 @@ let evaluate_value = let f source entry_point amount syntax = toplevel @@ let%bind output = - Ligo.Run.evaluate_value ~amount source entry_point (Syntax_name syntax) in + Ligo.Run.Of_source.evaluate ~amount source entry_point (Syntax_name syntax) in Format.printf "%a\n" Ast_simplified.PP.expression output ; ok () in diff --git a/src/bin/cli_helpers.ml b/src/bin/cli_helpers.ml index 28a565e40..ac0354368 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%!" Display.error_pp (ss ()) + Format.printf "%a%!" Main.Display.error_pp (ss ()) ) diff --git a/src/main/compile/of_source.ml b/src/main/compile/of_source.ml index 9d6005e4d..15134ee93 100644 --- a/src/main/compile/of_source.ml +++ b/src/main/compile/of_source.ml @@ -12,7 +12,13 @@ let compile_file_entry : string -> string -> s_syntax -> Compiler.Program.compil let%bind simplified = parse_file_program source_filename syntax in Of_simplified.compile_function_entry simplified entry_point -let compile_file_parameter : string -> string -> string -> s_syntax -> Michelson.t result = +let compile_file_contract_entry : string -> string -> s_syntax -> Michelson.t result = + fun source_filename entry_point syntax -> + let%bind simplified = parse_file_program source_filename syntax in + let%bind f = Of_simplified.compile_function_entry simplified entry_point in + ok f.body + +let compile_file_contract_parameter : 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 @@ -24,7 +30,7 @@ let compile_file_expression : string -> string -> string -> s_syntax -> Michelso 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 = +let compile_file_contract_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 diff --git a/src/main/main.ml b/src/main/main.ml index 5795d1e56..e5214bc31 100644 --- a/src/main/main.ml +++ b/src/main/main.ml @@ -1,2 +1,3 @@ module Run = Run module Compile = Compile +module Display = Display diff --git a/src/main/run/of_simplified.ml b/src/main/run/of_simplified.ml index 22e3d7026..8937fd83f 100644 --- a/src/main/run/of_simplified.ml +++ b/src/main/run/of_simplified.ml @@ -18,6 +18,7 @@ let run_typed_program 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) @@ -25,7 +26,7 @@ let evaluate_typed_program_entry 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/run.ml b/src/main/run/run.ml index 10ca5ed1d..2436e3455 100644 --- a/src/main/run/run.ml +++ b/src/main/run/run.ml @@ -1,3 +1,4 @@ +module Of_source = Of_source module Of_typed = Of_typed module Of_simplified = Of_simplified module Of_mini_c = Of_mini_c diff --git a/src/passes/1-parser/pascaligo.ml b/src/passes/1-parser/pascaligo.ml index 1f95166e2..9fffdcb46 100644 --- a/src/passes/1-parser/pascaligo.ml +++ b/src/passes/1-parser/pascaligo.ml @@ -4,7 +4,7 @@ module Parser = Parser_pascaligo.Parser module AST = Parser_pascaligo.AST module ParserLog = Parser_pascaligo.ParserLog -let parse_file (source: string) : AST.t result = +let parse_file (source: string) : AST.t result = let pp_input = let prefix = Filename.(source |> basename |> remove_extension) and suffix = ".pp.ligo" diff --git a/src/test/bin_tests.ml b/src/test/bin_tests.ml index 2ee1485bc..6e109d6fd 100644 --- a/src/test/bin_tests.ml +++ b/src/test/bin_tests.ml @@ -1,10 +1,9 @@ open Trace -open Ligo.Run open Test_helpers let compile_contract_basic () : unit result = let%bind _ = - compile_contract_file "./contracts/dispatch-counter.ligo" "main" (Syntax_name "pascaligo") + Ligo.Compile.Of_source.compile_file_entry "./contracts/dispatch-counter.ligo" "main" (Syntax_name "pascaligo") in ok () diff --git a/src/test/coase_tests.ml b/src/test/coase_tests.ml index 135f9b429..7b7b38ae8 100644 --- a/src/test/coase_tests.ml +++ b/src/test/coase_tests.ml @@ -1,10 +1,9 @@ (* Copyright Coase, Inc 2019 *) open Trace -open Ligo.Run open Test_helpers -let type_file = type_file Pascaligo +let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "pascaligo") let get_program = let s = ref None in diff --git a/src/test/compiler_tests.ml b/src/test/compiler_tests.ml index 0407c281f..b77c595f5 100644 --- a/src/test/compiler_tests.ml +++ b/src/test/compiler_tests.ml @@ -1,11 +1,11 @@ open Trace -open Ligo.Mini_c +open Mini_c open Combinators open Test_helpers let run_entry_int (e:anon_function) (n:int) : int result = let param : value = D_int n in - let%bind result = Main.Run_mini_c.run_entry e (t_int , t_int) param in + let%bind result = Run.Of_mini_c.run_entry e (t_int , t_int) param in match result with | D_int n -> ok n | _ -> simple_fail "result is not an int" diff --git a/src/test/heap_tests.ml b/src/test/heap_tests.ml index fb3821f27..2b66de488 100644 --- a/src/test/heap_tests.ml +++ b/src/test/heap_tests.ml @@ -1,8 +1,7 @@ open Trace -open Ligo.Run open Test_helpers -let type_file = type_file Pascaligo +let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "pascaligo") let get_program = let s = ref None in @@ -45,6 +44,8 @@ let dummy n = @@ range (n + 1) ) +let run_typed = Run.Of_typed.run_entry + let is_empty () : unit result = let%bind program = get_program () in let aux n = diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 781cb3a53..f2dcd21c1 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -1,11 +1,10 @@ open Trace -open Ligo.Run open Test_helpers open Ast_simplified.Combinators -let mtype_file ?debug_simplify ?debug_typed = type_file ?debug_simplify ?debug_typed Cameligo -let type_file = type_file Pascaligo +let mtype_file ?debug_simplify ?debug_typed = Ligo.Compile.Of_source.type_file ?debug_simplify ?debug_typed (Syntax_name "cameligo") +let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "pascaligo") let type_alias () : unit result = let%bind program = type_file "./contracts/type-alias.ligo" in @@ -184,9 +183,9 @@ let bytes_arithmetic () : unit result = let%bind () = expect_eq program "slice_op" tata at in let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" ba in - let%bind b1 = run_simplityped program "hasherman" foo in + let%bind b1 = Run.Of_simplified.run_typed_program program "hasherman" foo in let%bind () = expect_eq program "hasherman" foo b1 in - let%bind b3 = run_simplityped program "hasherman" foototo in + let%bind b3 = Run.Of_simplified.run_typed_program program "hasherman" foototo in let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in ok () @@ -577,9 +576,9 @@ let guess_string_mligo () : unit result = let basic_mligo () : unit result = let%bind typed = mtype_file ~debug_simplify:true "./contracts/basic.mligo" in - let%bind result = evaluate_typed "foo" typed in - Ligo.AST_Typed.assert_value_eq - (Ligo.AST_Typed.Combinators.e_a_empty_int (42 + 127), result) + let%bind result = Run.Of_typed.evaluate_entry typed "foo" in + Ast_typed.assert_value_eq + (Ast_typed.Combinators.e_a_empty_int (42 + 127), result) let counter_mligo () : unit result = let%bind program = mtype_file "./contracts/counter.mligo" in diff --git a/src/test/test_helpers.ml b/src/test/test_helpers.ml index f1a51a794..8b1bab00b 100644 --- a/src/test/test_helpers.ml +++ b/src/test/test_helpers.ml @@ -38,7 +38,7 @@ let expect ?options program entry_point input expecter = let content () = Format.asprintf "Entry_point: %s" entry_point in error title content in trace run_error @@ - Ligo.Run.run_simplityped ~debug_michelson:true ?options program entry_point input in + Ligo.Run.Of_simplified.run_typed_program ?options program entry_point input in expecter result let expect_fail ?options program entry_point input = @@ -49,7 +49,7 @@ let expect_fail ?options program entry_point input = in trace run_error @@ Assert.assert_fail - @@ Ligo.Run.run_simplityped ~debug_michelson:true ?options program entry_point input + @@ Ligo.Run.Of_simplified.run_typed_program ?options program entry_point input let expect_eq ?options program entry_point input expected = @@ -70,7 +70,7 @@ let expect_evaluate program entry_point expecter = let content () = Format.asprintf "Entry_point: %s" entry_point in error title content in trace error @@ - let%bind result = Ligo.Run.evaluate_simplityped ~debug_mini_c:true ~debug_michelson:true program entry_point in + let%bind result = Ligo.Run.Of_simplified.evaluate_typed_program_entry program entry_point in expecter result let expect_eq_evaluate program entry_point expected = diff --git a/src/test/typer_tests.ml b/src/test/typer_tests.ml index b61da4bd0..b22fb01db 100644 --- a/src/test/typer_tests.ml +++ b/src/test/typer_tests.ml @@ -1,10 +1,10 @@ open Trace -open Ligo.AST_Simplified +open Ast_simplified open Test_helpers -module Typed = Ligo.AST_Typed -module Typer = Ligo.Typer -module Simplified = Ligo.AST_Simplified +module Typed = Ast_typed +module Typer = Typer +module Simplified = Ast_simplified let int () : unit result = let open Combinators in diff --git a/src/test/vote_tests.ml b/src/test/vote_tests.ml index fbcf2b7ee..683169ee2 100644 --- a/src/test/vote_tests.ml +++ b/src/test/vote_tests.ml @@ -1,13 +1,14 @@ open Trace -open Ligo.Run open Test_helpers +let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "cameligo") + let get_program = let s = ref None in fun () -> match !s with | Some s -> ok s | None -> ( - let%bind program = type_file Cameligo "./contracts/vote.mligo" in + let%bind program = type_file "./contracts/vote.mligo" in s := Some program ; ok program ) @@ -39,7 +40,7 @@ let vote str = let init_vote () = let%bind program = get_program () in - let%bind result = Ligo.Run.run_simplityped program "main" (e_pair (vote "Yes") (init_storage "basic")) in + let%bind result = Ligo.Run.Of_simplified.run_typed_program program "main" (e_pair (vote "Yes") (init_storage "basic")) in let%bind (_ , storage) = extract_pair result in let%bind storage' = extract_record storage in let votes = List.assoc "candidates" storage' in diff --git a/vendors/ligo-utils/simple-utils/x_list.ml b/vendors/ligo-utils/simple-utils/x_list.ml index 9037b0e9e..67ee96331 100644 --- a/vendors/ligo-utils/simple-utils/x_list.ml +++ b/vendors/ligo-utils/simple-utils/x_list.ml @@ -5,7 +5,6 @@ let rec remove n = function | _ :: tl when n = 0 -> tl | hd :: tl -> hd :: remove (n - 1) tl - let map ?(acc = []) f lst = let rec aux acc f = function | [] -> acc