add interpret command
This commit is contained in:
parent
a53d8ffadf
commit
a80ffae897
@ -163,6 +163,31 @@ let compile_parameter =
|
|||||||
let doc = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract." in
|
let doc = "Subcommand: compile parameters to a michelson expression. The resulting michelson expression can be passed as an argument in a transaction which calls a contract." in
|
||||||
(term , Term.info ~doc cmdname)
|
(term , Term.info ~doc cmdname)
|
||||||
|
|
||||||
|
let interpret =
|
||||||
|
let f expression source_file syntax amount sender source display_format =
|
||||||
|
toplevel ~display_format @@
|
||||||
|
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
|
||||||
|
let%bind typed_prg,state = Compile.Of_simplified.compile simplified in
|
||||||
|
let%bind mini_c_prg = Compile.Of_typed.compile typed_prg in
|
||||||
|
let env = Ast_typed.program_environment typed_prg in
|
||||||
|
|
||||||
|
let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) (Some source_file) in
|
||||||
|
let%bind simplified_exp = Compile.Of_source.compile_expression v_syntax expression in
|
||||||
|
let%bind (typed_exp,_) = Compile.Of_simplified.compile_expression ~env ~state simplified_exp in
|
||||||
|
let%bind mini_c_exp = Compile.Of_typed.compile_expression typed_exp in
|
||||||
|
let%bind compiled_exp = Compile.Of_mini_c.aggregate_and_compile_expression mini_c_prg mini_c_exp in
|
||||||
|
let%bind options = Run.make_dry_run_options {amount ; sender ; source } in
|
||||||
|
let%bind value = Run.run ~options compiled_exp.expr compiled_exp.expr_ty in
|
||||||
|
let%bind simplified_output = Uncompile.uncompile_expression typed_exp.type_annotation value in
|
||||||
|
ok @@ Format.asprintf "%a\n" Ast_simplified.PP.expression simplified_output
|
||||||
|
in
|
||||||
|
let term =
|
||||||
|
Term.(const f $ expression "EXPRESSION" 0 $ source_file 1 $ syntax $ amount $ sender $ source $ display_format ) in
|
||||||
|
let cmdname = "interpret" in
|
||||||
|
let doc = "Subcommand: interpret the expression in the context initialized by the provided source file." in
|
||||||
|
(term , Term.info ~doc cmdname)
|
||||||
|
|
||||||
|
|
||||||
let compile_storage =
|
let compile_storage =
|
||||||
let f source_file entry_point expression syntax display_format michelson_format =
|
let f source_file entry_point expression syntax display_format michelson_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
@ -296,6 +321,7 @@ let run ?argv () =
|
|||||||
compile_parameter ;
|
compile_parameter ;
|
||||||
compile_storage ;
|
compile_storage ;
|
||||||
compile_expression ;
|
compile_expression ;
|
||||||
|
interpret ;
|
||||||
dry_run ;
|
dry_run ;
|
||||||
run_function ;
|
run_function ;
|
||||||
evaluate_value ;
|
evaluate_value ;
|
||||||
|
@ -37,6 +37,10 @@ let%expect_test _ =
|
|||||||
evaluate-value
|
evaluate-value
|
||||||
Subcommand: evaluate a given definition.
|
Subcommand: evaluate a given definition.
|
||||||
|
|
||||||
|
interpret
|
||||||
|
Subcommand: interpret the expression in the context initialized by
|
||||||
|
the provided source file.
|
||||||
|
|
||||||
measure-contract
|
measure-contract
|
||||||
Subcommand: measure a contract's compiled size in bytes.
|
Subcommand: measure a contract's compiled size in bytes.
|
||||||
|
|
||||||
@ -84,6 +88,10 @@ let%expect_test _ =
|
|||||||
evaluate-value
|
evaluate-value
|
||||||
Subcommand: evaluate a given definition.
|
Subcommand: evaluate a given definition.
|
||||||
|
|
||||||
|
interpret
|
||||||
|
Subcommand: interpret the expression in the context initialized by
|
||||||
|
the provided source file.
|
||||||
|
|
||||||
measure-contract
|
measure-contract
|
||||||
Subcommand: measure a contract's compiled size in bytes.
|
Subcommand: measure a contract's compiled size in bytes.
|
||||||
|
|
||||||
|
@ -17,3 +17,8 @@ let uncompile_typed_program_entry_expression_result program entry ex_ty_value =
|
|||||||
|
|
||||||
let uncompile_typed_program_entry_function_result program entry ex_ty_value =
|
let uncompile_typed_program_entry_function_result program entry ex_ty_value =
|
||||||
uncompile_value Function program entry ex_ty_value
|
uncompile_value Function program entry ex_ty_value
|
||||||
|
|
||||||
|
let uncompile_expression type_value ex_ty_value =
|
||||||
|
let%bind mini_c = Compiler.Uncompiler.translate_value ex_ty_value in
|
||||||
|
let%bind typed = Transpiler.untranspile mini_c type_value in
|
||||||
|
Typer.untype_expression typed
|
Loading…
Reference in New Issue
Block a user