From 10461764fbe116f437bef87191b52e7d44f44793 Mon Sep 17 00:00:00 2001 From: Galfour Date: Sun, 9 Jun 2019 12:08:37 +0000 Subject: [PATCH 1/4] add dry-run in cli --- src/bin/cli.ml | 31 ++++++++++++++++++++++--------- src/main/run_source.ml | 10 ++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index f7fb287f3..cec0b7ee1 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -41,28 +41,28 @@ let main = let term = Term.(const print_endline $ const "Ligo needs a command. Do ligo --help") in (term , Term.info "ligo") -let source = +let source n = let open Arg in let info = let docv = "SOURCE_FILE" in let doc = "$(docv) is the path to the .ligo file of the contract." in info ~docv ~doc [] in - required @@ pos 0 (some string) None info + required @@ pos n (some string) None info -let entry_point = +let entry_point n = let open Arg in let info = let docv = "ENTRY_POINT" in let doc = "$(docv) is entry-point that will be compiled." in info ~docv ~doc [] in - required @@ pos 1 (some string) (Some "main") info + required @@ pos n (some string) (Some "main") info -let expression = +let expression n = let open Arg in let docv = "EXPRESSION" in let doc = "$(docv) is the expression that will be compiled." in let info = info ~docv ~doc [] in - required @@ pos 2 (some string) None info + required @@ pos n (some string) None info let syntax = let open Arg in @@ -82,7 +82,7 @@ let compile_file = ok () in let term = - Term.(const f $ source $ entry_point $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ syntax) in let cmdname = "compile-contract" in let docs = "Subcommand: compile a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in (term , Term.info ~docs cmdname) @@ -97,7 +97,7 @@ let compile_parameter = ok () in let term = - Term.(const f $ source $ entry_point $ expression $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ syntax) in let cmdname = "compile-parameter" in let docs = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in (term , Term.info ~docs cmdname) @@ -112,10 +112,23 @@ let compile_storage = ok () in let term = - Term.(const f $ source $ entry_point $ expression $ syntax) in + Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ syntax) in let cmdname = "compile-storage" in let docs = "Subcommand: compile an initial storage in ligo syntax to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which originates a contract. See `ligo " ^ cmdname ^ " --help' for a list of options specific to this subcommand." in (term , Term.info ~docs cmdname) +let dry_run = + let f source entry_point storage input syntax = + toplevel @@ + let%bind output = + Ligo.Run.run_contract source entry_point storage input syntax in + Format.printf "%a\n" Ast_simplified.PP.expression output ; + ok () + in + let term = + Term.(const f $ source 0 $ entry_point 1 $ expression 2 $ expression 3 $ syntax) in + let cmdname = "dry-run" in + let docs = "Subcommand: run a smart-contract with the given storage and input." in + (term , Term.info ~docs cmdname) let () = Term.exit @@ Term.eval_choice main [compile_file ; compile_parameter ; compile_storage] diff --git a/src/main/run_source.ml b/src/main/run_source.ml index 26a3cd87e..e3377472e 100644 --- a/src/main/run_source.ml +++ b/src/main/run_source.ml @@ -216,3 +216,13 @@ let type_file ?(debug_simplify = false) ?(debug_typed = false) Format.(printf "Typed : %a\n%!" Ast_typed.PP.program typed) )) ; ok typed + + +let run_contract source entry_point storage input syntax = + let%bind typed = + type_file source entry_point in + let%bind storage_simpl = + parsify_expression storage syntax in + let%bind input_simpl = + parsify_expression input syntax in + Run_simplified.run_simplityped typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl) From 53314c2c0ce2d5fba997d59f5d667e52debab725 Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Mon, 10 Jun 2019 15:19:42 +0200 Subject: [PATCH 2/4] Removed "assert" as reserved. Enabled terminating ";" in lists. --- .gitignore | 1 + src/parser/ligodity/Lexer.mll | 2 +- src/parser/ligodity/Parser.mly | 12 +++++++----- src/parser/ligodity/Version.ml | 1 - 4 files changed, 9 insertions(+), 7 deletions(-) delete mode 100644 src/parser/ligodity/Version.ml diff --git a/.gitignore b/.gitignore index 7483d1710..065477ab1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /dune-project *~ cache/* +Version.ml diff --git a/src/parser/ligodity/Lexer.mll b/src/parser/ligodity/Lexer.mll index 85ae4db48..9c2274f36 100644 --- a/src/parser/ligodity/Lexer.mll +++ b/src/parser/ligodity/Lexer.mll @@ -104,7 +104,7 @@ let keywords = Token.[ "and", None; "as", None; "asr", None; - "assert", None; + (* "assert", None;*) "class", None; "constraint", None; "do", None; diff --git a/src/parser/ligodity/Parser.mly b/src/parser/ligodity/Parser.mly index 76267b6d3..b21f4f1ec 100644 --- a/src/parser/ligodity/Parser.mly +++ b/src/parser/ligodity/Parser.mly @@ -179,11 +179,13 @@ tuple(item): (* Possibly empty semicolon-separated values between brackets *) list_of(item): - lbracket sepseq(item,semi) rbracket { - {opening = LBracket $1; - elements = $2; - terminator = None; - closing = RBracket $3} } + lbracket sep_or_term_list(item,semi) rbracket { + let elements, terminator = $2 in { + opening = LBracket $1; + elements = Some elements; + terminator; + closing = RBracket $3} + } (* Main *) diff --git a/src/parser/ligodity/Version.ml b/src/parser/ligodity/Version.ml deleted file mode 100644 index d89964cb1..000000000 --- a/src/parser/ligodity/Version.ml +++ /dev/null @@ -1 +0,0 @@ -let version = "UNKNOWN" From 37c2152fca1b9d1fc97d432aec6a982ae6399fcd Mon Sep 17 00:00:00 2001 From: Christian Rinderknecht Date: Mon, 10 Jun 2019 19:59:22 +0200 Subject: [PATCH 3/4] Fixed the regression introducted by the previous commit (disallowing empty lists). --- src/parser/ligodity/Parser.mly | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/parser/ligodity/Parser.mly b/src/parser/ligodity/Parser.mly index b21f4f1ec..b453e6fae 100644 --- a/src/parser/ligodity/Parser.mly +++ b/src/parser/ligodity/Parser.mly @@ -186,6 +186,11 @@ list_of(item): terminator; closing = RBracket $3} } +| lbracket rbracket { + {opening = LBracket $1; + elements = None; + terminator = None; + closing = RBracket $2} } (* Main *) From 7b9e3b669946df5c0fc0b6087c7a136d5d91d8e2 Mon Sep 17 00:00:00 2001 From: Galfour Date: Mon, 10 Jun 2019 22:08:56 +0000 Subject: [PATCH 4/4] add dry-run to the bin commands --- src/bin/cli.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/cli.ml b/src/bin/cli.ml index cec0b7ee1..4c97be407 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -131,4 +131,4 @@ let dry_run = let docs = "Subcommand: run a smart-contract with the given storage and input." in (term , Term.info ~docs cmdname) -let () = Term.exit @@ Term.eval_choice main [compile_file ; compile_parameter ; compile_storage] +let () = Term.exit @@ Term.eval_choice main [compile_file ; compile_parameter ; compile_storage ; dry_run ]