further down the road
This commit is contained in:
parent
d8b7a12c69
commit
b619fa1f17
@ -50,8 +50,8 @@ let compile_file =
|
|||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind contract =
|
let%bind contract =
|
||||||
trace (simple_info "compiling contract to michelson") @@
|
trace (simple_info "compiling contract to michelson") @@
|
||||||
Ligo.Run.compile_contract_file source entry_point (Syntax_name syntax) in
|
Ligo.Compile.Of_source.compile_file_contract_entry source entry_point (Syntax_name syntax) in
|
||||||
Format.printf "%s\n" contract ;
|
Format.printf "%a\n" Tezos_utils.Michelson.pp contract ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
@ -65,8 +65,8 @@ let compile_parameter =
|
|||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind value =
|
let%bind value =
|
||||||
trace (simple_error "compile-input") @@
|
trace (simple_error "compile-input") @@
|
||||||
Ligo.Run.compile_contract_parameter source entry_point expression (Syntax_name syntax) in
|
Ligo.Compile.Of_source.compile_file_contract_parameter source entry_point expression (Syntax_name syntax) in
|
||||||
Format.printf "%s\n" value;
|
Format.printf "%a\n" Tezos_utils.Michelson.pp value;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
@ -80,8 +80,8 @@ let compile_storage =
|
|||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind value =
|
let%bind value =
|
||||||
trace (simple_error "compile-storage") @@
|
trace (simple_error "compile-storage") @@
|
||||||
Ligo.Run.compile_contract_storage source entry_point expression (Syntax_name syntax) in
|
Ligo.Compile.Of_source.compile_file_contract_storage source entry_point expression (Syntax_name syntax) in
|
||||||
Format.printf "%s\n" value;
|
Format.printf "%a\n" Tezos_utils.Michelson.pp value;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
let term =
|
let term =
|
||||||
@ -94,7 +94,7 @@ let dry_run =
|
|||||||
let f source entry_point storage input amount syntax =
|
let f source entry_point storage input amount syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind output =
|
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 ;
|
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
@ -108,7 +108,7 @@ let run_function =
|
|||||||
let f source entry_point parameter amount syntax =
|
let f source entry_point parameter amount syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind output =
|
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 ;
|
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
@ -122,7 +122,7 @@ let evaluate_value =
|
|||||||
let f source entry_point amount syntax =
|
let f source entry_point amount syntax =
|
||||||
toplevel @@
|
toplevel @@
|
||||||
let%bind output =
|
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 ;
|
Format.printf "%a\n" Ast_simplified.PP.expression output ;
|
||||||
ok ()
|
ok ()
|
||||||
in
|
in
|
||||||
|
@ -4,6 +4,6 @@ let toplevel x =
|
|||||||
match x with
|
match x with
|
||||||
| Trace.Ok ((), annotations) -> ignore annotations; ()
|
| Trace.Ok ((), annotations) -> ignore annotations; ()
|
||||||
| Error ss -> (
|
| Error ss -> (
|
||||||
Format.printf "%a%!" Display.error_pp (ss ())
|
Format.printf "%a%!" Main.Display.error_pp (ss ())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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
|
let%bind simplified = parse_file_program source_filename syntax in
|
||||||
Of_simplified.compile_function_entry simplified entry_point
|
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 ->
|
fun source_filename _entry_point expression syntax ->
|
||||||
let%bind syntax = syntax_to_variant syntax (Some source_filename) in
|
let%bind syntax = syntax_to_variant syntax (Some source_filename) in
|
||||||
let%bind simplified = parsify_expression syntax expression 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
|
let%bind simplified = parsify_expression syntax expression in
|
||||||
Of_simplified.compile_expression simplified
|
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 ->
|
fun source_filename _entry_point expression syntax ->
|
||||||
let%bind syntax = syntax_to_variant syntax (Some source_filename) in
|
let%bind syntax = syntax_to_variant syntax (Some source_filename) in
|
||||||
let%bind simplified = parsify_expression syntax expression in
|
let%bind simplified = parsify_expression syntax expression in
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
module Run = Run
|
module Run = Run
|
||||||
module Compile = Compile
|
module Compile = Compile
|
||||||
|
module Display = Display
|
||||||
|
@ -18,6 +18,7 @@ let run_typed_program
|
|||||||
let%bind ex_ty_value = Of_michelson.run ?options code 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
|
Compile.Of_simplified.uncompile_typed_program_entry_function_result program entry ex_ty_value
|
||||||
|
|
||||||
|
|
||||||
let evaluate_typed_program_entry
|
let evaluate_typed_program_entry
|
||||||
?options
|
?options
|
||||||
(program : Ast_typed.program) (entry : string)
|
(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 code = Compile.Of_typed.compile_expression_entry program entry in
|
||||||
let%bind input =
|
let%bind input =
|
||||||
let fake_input = Ast_typed.(e_a_unit Environment.full_empty) in
|
let fake_input = Ast_typed.(e_a_unit Environment.full_empty) in
|
||||||
Compile.Of_typed.compile_expression fake_input
|
|
||||||
in
|
in
|
||||||
let%bind ex_ty_value = Of_michelson.run ?options code 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
|
Compile.Of_simplified.uncompile_typed_program_entry_expression_result program entry ex_ty_value
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
module Of_source = Of_source
|
||||||
module Of_typed = Of_typed
|
module Of_typed = Of_typed
|
||||||
module Of_simplified = Of_simplified
|
module Of_simplified = Of_simplified
|
||||||
module Of_mini_c = Of_mini_c
|
module Of_mini_c = Of_mini_c
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
open Trace
|
open Trace
|
||||||
open Ligo.Run
|
|
||||||
open Test_helpers
|
open Test_helpers
|
||||||
|
|
||||||
let compile_contract_basic () : unit result =
|
let compile_contract_basic () : unit result =
|
||||||
let%bind _ =
|
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
|
in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
(* Copyright Coase, Inc 2019 *)
|
(* Copyright Coase, Inc 2019 *)
|
||||||
|
|
||||||
open Trace
|
open Trace
|
||||||
open Ligo.Run
|
|
||||||
open Test_helpers
|
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 get_program =
|
||||||
let s = ref None in
|
let s = ref None in
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
open Trace
|
open Trace
|
||||||
open Ligo.Mini_c
|
open Mini_c
|
||||||
open Combinators
|
open Combinators
|
||||||
open Test_helpers
|
open Test_helpers
|
||||||
|
|
||||||
let run_entry_int (e:anon_function) (n:int) : int result =
|
let run_entry_int (e:anon_function) (n:int) : int result =
|
||||||
let param : value = D_int n in
|
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
|
match result with
|
||||||
| D_int n -> ok n
|
| D_int n -> ok n
|
||||||
| _ -> simple_fail "result is not an int"
|
| _ -> simple_fail "result is not an int"
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
open Trace
|
open Trace
|
||||||
open Ligo.Run
|
|
||||||
open Test_helpers
|
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 get_program =
|
||||||
let s = ref None in
|
let s = ref None in
|
||||||
@ -45,6 +44,8 @@ let dummy n =
|
|||||||
@@ range (n + 1)
|
@@ range (n + 1)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let run_typed = Run.Of_typed.run_entry
|
||||||
|
|
||||||
let is_empty () : unit result =
|
let is_empty () : unit result =
|
||||||
let%bind program = get_program () in
|
let%bind program = get_program () in
|
||||||
let aux n =
|
let aux n =
|
||||||
|
@ -1,11 +1,10 @@
|
|||||||
open Trace
|
open Trace
|
||||||
open Ligo.Run
|
|
||||||
open Test_helpers
|
open Test_helpers
|
||||||
|
|
||||||
open Ast_simplified.Combinators
|
open Ast_simplified.Combinators
|
||||||
|
|
||||||
let mtype_file ?debug_simplify ?debug_typed = type_file ?debug_simplify ?debug_typed Cameligo
|
let mtype_file ?debug_simplify ?debug_typed = Ligo.Compile.Of_source.type_file ?debug_simplify ?debug_typed (Syntax_name "cameligo")
|
||||||
let type_file = type_file Pascaligo
|
let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "pascaligo")
|
||||||
|
|
||||||
let type_alias () : unit result =
|
let type_alias () : unit result =
|
||||||
let%bind program = type_file "./contracts/type-alias.ligo" in
|
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_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 = 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 () = 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
|
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in
|
||||||
ok ()
|
ok ()
|
||||||
|
|
||||||
@ -577,9 +576,9 @@ let guess_string_mligo () : unit result =
|
|||||||
|
|
||||||
let basic_mligo () : unit result =
|
let basic_mligo () : unit result =
|
||||||
let%bind typed = mtype_file ~debug_simplify:true "./contracts/basic.mligo" in
|
let%bind typed = mtype_file ~debug_simplify:true "./contracts/basic.mligo" in
|
||||||
let%bind result = evaluate_typed "foo" typed in
|
let%bind result = Run.Of_typed.evaluate_entry typed "foo" in
|
||||||
Ligo.AST_Typed.assert_value_eq
|
Ast_typed.assert_value_eq
|
||||||
(Ligo.AST_Typed.Combinators.e_a_empty_int (42 + 127), result)
|
(Ast_typed.Combinators.e_a_empty_int (42 + 127), result)
|
||||||
|
|
||||||
let counter_mligo () : unit result =
|
let counter_mligo () : unit result =
|
||||||
let%bind program = mtype_file "./contracts/counter.mligo" in
|
let%bind program = mtype_file "./contracts/counter.mligo" in
|
||||||
|
@ -38,7 +38,7 @@ let expect ?options program entry_point input expecter =
|
|||||||
let content () = Format.asprintf "Entry_point: %s" entry_point in
|
let content () = Format.asprintf "Entry_point: %s" entry_point in
|
||||||
error title content in
|
error title content in
|
||||||
trace run_error @@
|
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
|
expecter result
|
||||||
|
|
||||||
let expect_fail ?options program entry_point input =
|
let expect_fail ?options program entry_point input =
|
||||||
@ -49,7 +49,7 @@ let expect_fail ?options program entry_point input =
|
|||||||
in
|
in
|
||||||
trace run_error @@
|
trace run_error @@
|
||||||
Assert.assert_fail
|
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 =
|
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
|
let content () = Format.asprintf "Entry_point: %s" entry_point in
|
||||||
error title content in
|
error title content in
|
||||||
trace error @@
|
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
|
expecter result
|
||||||
|
|
||||||
let expect_eq_evaluate program entry_point expected =
|
let expect_eq_evaluate program entry_point expected =
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
open Trace
|
open Trace
|
||||||
open Ligo.AST_Simplified
|
open Ast_simplified
|
||||||
open Test_helpers
|
open Test_helpers
|
||||||
|
|
||||||
module Typed = Ligo.AST_Typed
|
module Typed = Ast_typed
|
||||||
module Typer = Ligo.Typer
|
module Typer = Typer
|
||||||
module Simplified = Ligo.AST_Simplified
|
module Simplified = Ast_simplified
|
||||||
|
|
||||||
let int () : unit result =
|
let int () : unit result =
|
||||||
let open Combinators in
|
let open Combinators in
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
open Trace
|
open Trace
|
||||||
open Ligo.Run
|
|
||||||
open Test_helpers
|
open Test_helpers
|
||||||
|
|
||||||
|
let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "cameligo")
|
||||||
|
|
||||||
let get_program =
|
let get_program =
|
||||||
let s = ref None in
|
let s = ref None in
|
||||||
fun () -> match !s with
|
fun () -> match !s with
|
||||||
| Some s -> ok s
|
| Some s -> ok s
|
||||||
| None -> (
|
| None -> (
|
||||||
let%bind program = type_file Cameligo "./contracts/vote.mligo" in
|
let%bind program = type_file "./contracts/vote.mligo" in
|
||||||
s := Some program ;
|
s := Some program ;
|
||||||
ok program
|
ok program
|
||||||
)
|
)
|
||||||
@ -39,7 +40,7 @@ let vote str =
|
|||||||
|
|
||||||
let init_vote () =
|
let init_vote () =
|
||||||
let%bind program = get_program () in
|
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_pair result in
|
||||||
let%bind storage' = extract_record storage in
|
let%bind storage' = extract_record storage in
|
||||||
let votes = List.assoc "candidates" storage' in
|
let votes = List.assoc "candidates" storage' in
|
||||||
|
1
vendors/ligo-utils/simple-utils/x_list.ml
vendored
1
vendors/ligo-utils/simple-utils/x_list.ml
vendored
@ -5,7 +5,6 @@ let rec remove n = function
|
|||||||
| _ :: tl when n = 0 -> tl
|
| _ :: tl when n = 0 -> tl
|
||||||
| hd :: tl -> hd :: remove (n - 1) tl
|
| hd :: tl -> hd :: remove (n - 1) tl
|
||||||
|
|
||||||
|
|
||||||
let map ?(acc = []) f lst =
|
let map ?(acc = []) f lst =
|
||||||
let rec aux acc f = function
|
let rec aux acc f = function
|
||||||
| [] -> acc
|
| [] -> acc
|
||||||
|
Loading…
Reference in New Issue
Block a user