add interpret command

This commit is contained in:
Lesenechal Remi 2019-12-11 20:42:52 +01:00
parent a53d8ffadf
commit a80ffae897
3 changed files with 40 additions and 1 deletions

View File

@ -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
(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 f source_file entry_point expression syntax display_format michelson_format =
toplevel ~display_format @@
@ -296,6 +321,7 @@ let run ?argv () =
compile_parameter ;
compile_storage ;
compile_expression ;
interpret ;
dry_run ;
run_function ;
evaluate_value ;

View File

@ -37,6 +37,10 @@ let%expect_test _ =
evaluate-value
Subcommand: evaluate a given definition.
interpret
Subcommand: interpret the expression in the context initialized by
the provided source file.
measure-contract
Subcommand: measure a contract's compiled size in bytes.
@ -84,6 +88,10 @@ let%expect_test _ =
evaluate-value
Subcommand: evaluate a given definition.
interpret
Subcommand: interpret the expression in the context initialized by
the provided source file.
measure-contract
Subcommand: measure a contract's compiled size in bytes.

View File

@ -16,4 +16,9 @@ let uncompile_typed_program_entry_expression_result program entry ex_ty_value =
uncompile_value Expression 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