diff --git a/src/bin/cli.ml b/src/bin/cli.ml index 4c97be407..1118ac02c 100644 --- a/src/bin/cli.ml +++ b/src/bin/cli.ml @@ -131,4 +131,40 @@ 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 ; dry_run ] +let run_function = + let f source entry_point parameter syntax = + toplevel @@ + let%bind output = + Ligo.Run.run_function source entry_point parameter 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 $ syntax) in + let cmdname = "run-function" in + let docs = "Subcommand: run a function with the given parameter." in + (term , Term.info ~docs cmdname) + +let evaluate_value = + let f source entry_point syntax = + toplevel @@ + let%bind output = + Ligo.Run.evaluate_value source entry_point syntax in + Format.printf "%a\n" Ast_simplified.PP.expression output ; + ok () + in + let term = + Term.(const f $ source 0 $ entry_point 1 $ syntax) in + let cmdname = "evaluate-value" in + let docs = "Subcommand: evaluate a given definition." in + (term , Term.info ~docs cmdname) + + +let () = Term.exit @@ Term.eval_choice main [ + compile_file ; + compile_parameter ; + compile_storage ; + dry_run ; + run_function ; + evaluate_value ; + ] diff --git a/src/main/run_source.ml b/src/main/run_source.ml index e3377472e..79f71ce97 100644 --- a/src/main/run_source.ml +++ b/src/main/run_source.ml @@ -217,12 +217,23 @@ let type_file ?(debug_simplify = false) ?(debug_typed = false) )) ; ok typed - let run_contract source entry_point storage input syntax = let%bind typed = - type_file source entry_point in + type_file syntax source in let%bind storage_simpl = - parsify_expression storage syntax in + parsify_expression syntax storage in let%bind input_simpl = - parsify_expression input syntax in + parsify_expression syntax input in Run_simplified.run_simplityped typed entry_point (Ast_simplified.e_pair storage_simpl input_simpl) + +let run_function source entry_point parameter syntax = + let%bind typed = + type_file syntax source in + let%bind parameter' = + parsify_expression syntax parameter in + Run_simplified.run_simplityped typed entry_point parameter' + +let evaluate_value source entry_point syntax = + let%bind typed = + type_file syntax source in + Run_simplified.evaluate_simplityped typed entry_point