Merge branch 'feature/cli-interpret' into 'dev'
Feature/cli interpret See merge request ligolang/ligo!249
This commit is contained in:
commit
e558d23658
@ -7,9 +7,7 @@ dry_run_output=$(./scripts/ligo_ci.sh dry-run src/test/contracts/website2.ligo m
|
||||
|
||||
expected_compiled_parameter="(Right 1)";
|
||||
expected_compiled_storage=1;
|
||||
expected_dry_run_output="tuple[ list[]
|
||||
2
|
||||
]";
|
||||
expected_dry_run_output="( [] , 2 )";
|
||||
|
||||
if [ "$compiled_storage" != "$expected_compiled_storage" ]; then
|
||||
echo "Expected $expected_compiled_storage as compile-storage output, got $compiled_storage instead";
|
||||
|
@ -47,6 +47,14 @@ let req_syntax n =
|
||||
info ~docv ~doc [] in
|
||||
required @@ pos n (some string) None info
|
||||
|
||||
let init_file =
|
||||
let open Arg in
|
||||
let info =
|
||||
let docv = "INIT_FILE" in
|
||||
let doc = "$(docv) is the path to the .ligo or .mligo file to be used for context initialization." in
|
||||
info ~docv ~doc ["init-file"] in
|
||||
value @@ opt (some string) None info
|
||||
|
||||
let amount =
|
||||
let open Arg in
|
||||
let info =
|
||||
@ -163,6 +171,35 @@ 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 init_file syntax amount sender source display_format =
|
||||
toplevel ~display_format @@
|
||||
let%bind (decl_list,state,env) = match init_file with
|
||||
| Some init_file ->
|
||||
let%bind simplified = Compile.Of_source.compile init_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
|
||||
ok (mini_c_prg,state,env)
|
||||
| None -> ok ([],Typer.Solver.initial_state,Ast_typed.Environment.full_empty) in
|
||||
|
||||
let%bind v_syntax = Helpers.syntax_to_variant (Syntax_name syntax) init_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 decl_list 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 $ init_file $ 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 +333,7 @@ let run ?argv () =
|
||||
compile_parameter ;
|
||||
compile_storage ;
|
||||
compile_expression ;
|
||||
interpret ;
|
||||
dry_run ;
|
||||
run_function ;
|
||||
evaluate_value ;
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
@ -5,7 +5,10 @@ include Stage_common.PP
|
||||
|
||||
let list_sep_d x ppf lst = match lst with
|
||||
| [] -> ()
|
||||
| _ -> fprintf ppf "@; @[<v>%a@]@;" (list_sep x (tag "@;")) lst
|
||||
| _ -> fprintf ppf " @[<v>%a@] " (list_sep x (tag " ; ")) lst
|
||||
let tuple_sep_d x ppf lst = match lst with
|
||||
| [] -> ()
|
||||
| _ -> fprintf ppf " @[<v>%a@] " (list_sep x (tag " , ")) lst
|
||||
|
||||
let rec te' ppf (te : type_expression type_expression') : unit =
|
||||
type_expression' type_expression ppf te
|
||||
@ -19,13 +22,13 @@ let rec expression ppf (e:expression) = match e.expression with
|
||||
| E_application (f, arg) -> fprintf ppf "(%a)@(%a)" expression f expression arg
|
||||
| E_constructor (c, ae) -> fprintf ppf "%a(%a)" constructor c expression ae
|
||||
| E_constant (b, lst) -> fprintf ppf "%a(%a)" constant b (list_sep_d expression) lst
|
||||
| E_tuple lst -> fprintf ppf "tuple[%a]" (list_sep_d expression) lst
|
||||
| E_tuple lst -> fprintf ppf "(%a)" (tuple_sep_d expression) lst
|
||||
| E_accessor (ae, p) -> fprintf ppf "%a.%a" expression ae access_path p
|
||||
| E_record m -> fprintf ppf "record[%a]" (lmap_sep expression (const " , ")) m
|
||||
| E_map m -> fprintf ppf "map[%a]" (list_sep_d assoc_expression) m
|
||||
| E_record m -> fprintf ppf "{%a}" (lrecord_sep expression (const " , ")) m
|
||||
| E_map m -> fprintf ppf "[%a]" (list_sep_d assoc_expression) m
|
||||
| E_big_map m -> fprintf ppf "big_map[%a]" (list_sep_d assoc_expression) m
|
||||
| E_list lst -> fprintf ppf "list[%a]" (list_sep_d expression) lst
|
||||
| E_set lst -> fprintf ppf "set[%a]" (list_sep_d expression) lst
|
||||
| E_list lst -> fprintf ppf "[%a]" (list_sep_d expression) lst
|
||||
| E_set lst -> fprintf ppf "{%a}" (list_sep_d expression) lst
|
||||
| E_look_up (ds, ind) -> fprintf ppf "(%a)[%a]" expression ds expression ind
|
||||
| E_lambda {binder;input_type;output_type;result} ->
|
||||
fprintf ppf "lambda (%a:%a) : %a return %a"
|
||||
|
@ -128,6 +128,11 @@ let lmap_sep value sep ppf m =
|
||||
let new_pp ppf (k, v) = fprintf ppf "%a -> %a" label k value v in
|
||||
fprintf ppf "%a" (list_sep new_pp sep) lst
|
||||
|
||||
let lrecord_sep value sep ppf m =
|
||||
let lst = Types.LMap.to_kv_list m in
|
||||
let new_pp ppf (k, v) = fprintf ppf "%a = %a" label k value v in
|
||||
fprintf ppf "%a" (list_sep new_pp sep) lst
|
||||
|
||||
let list_sep_d x = list_sep x (const " , ")
|
||||
let cmap_sep_d x = cmap_sep x (const " , ")
|
||||
let lmap_sep_d x = lmap_sep x (const " , ")
|
||||
|
@ -8,6 +8,7 @@ val label : formatter -> label -> unit
|
||||
val constant : formatter -> constant -> unit
|
||||
val cmap_sep : (formatter -> 'a -> unit) -> (formatter -> unit -> unit) -> formatter -> 'a CMap.t -> unit
|
||||
val lmap_sep : (formatter -> 'a -> unit) -> (formatter -> unit -> unit) -> formatter -> 'a LMap.t -> unit
|
||||
val lrecord_sep : (formatter -> 'a -> unit) -> (formatter -> unit -> unit) -> formatter -> 'a LMap.t -> unit
|
||||
val type_expression' : (formatter -> 'a -> unit) -> formatter -> 'a type_expression' -> unit
|
||||
val type_operator : (formatter -> 'a -> unit) -> formatter -> 'a type_operator -> unit
|
||||
val type_constant : formatter -> type_constant -> unit
|
||||
|
Loading…
Reference in New Issue
Block a user