2019-05-13 00:56:22 +04:00
open Cmdliner
open Trace
2019-06-28 16:05:04 +04:00
open Cli_helpers
2019-05-13 00:56:22 +04:00
2019-12-07 18:11:33 +04:00
let version =
Format . asprintf
" Rolling release \n Hash: %s \n Date: %s \n CI job id: %s "
Version . hash
Version . commit_date
Version . job_id
2019-05-13 00:56:22 +04:00
let main =
2019-11-21 21:44:27 +04:00
let man =
[ ` S " MORE HELP " ;
` P " Use `$(mname) $(i,COMMAND) --help' for help on a single command. " ] in
2019-12-07 18:11:33 +04:00
( Term . ( ret ( const ( ` Help ( ` Auto , None ) ) ) ) , Term . info " ligo " ~ version ~ man )
2019-05-13 00:56:22 +04:00
2019-09-27 20:33:32 +04:00
let source_file n =
2019-05-30 02:09:40 +04:00
let open Arg in
let info =
let docv = " SOURCE_FILE " in
2020-01-27 19:05:47 +04:00
let doc = " $(docv) is the path to the smart contract file. " in
2019-05-30 02:09:40 +04:00
info ~ docv ~ doc [] in
2019-06-09 16:08:37 +04:00
required @@ pos n ( some string ) None info
2019-05-30 02:09:40 +04:00
2019-06-09 16:08:37 +04:00
let entry_point n =
2019-05-30 02:09:40 +04:00
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
2019-06-09 16:08:37 +04:00
required @@ pos n ( some string ) ( Some " main " ) info
2019-05-30 02:09:40 +04:00
2019-06-12 03:28:38 +04:00
let expression purpose n =
2019-05-30 02:09:40 +04:00
let open Arg in
2019-06-12 03:28:38 +04:00
let docv = purpose ^ " _EXPRESSION " in
2019-05-30 02:09:40 +04:00
let doc = " $(docv) is the expression that will be compiled. " in
let info = info ~ docv ~ doc [] in
2019-06-09 16:08:37 +04:00
required @@ pos n ( some string ) None info
2019-05-30 02:09:40 +04:00
let syntax =
let open Arg in
let info =
let docv = " SYNTAX " in
2020-01-27 19:05:47 +04:00
let doc = " $(docv) is the syntax that will be used. Currently supported syntaxes are \" pascaligo \" , \" cameligo \" and \" reasonligo \" . By default, the syntax is guessed from the extension (.ligo, .mligo, .religo respectively). " in
2019-06-06 13:30:29 +04:00
info ~ docv ~ doc [ " syntax " ; " s " ] in
2019-06-11 00:16:08 +04:00
value @@ opt string " auto " info
2019-05-30 02:09:40 +04:00
2019-11-30 01:22:56 +04:00
let req_syntax n =
let open Arg in
let info =
let docv = " SYNTAX " in
2020-01-29 22:01:05 +04:00
let doc = " $(docv) is the syntax that will be used. Currently supported syntaxes are \" pascaligo \" , \" cameligo \" and \" reasonligo \" . By default, the syntax is guessed from the extension (.ligo, .mligo, .religo respectively). " in
2019-11-30 01:22:56 +04:00
info ~ docv ~ doc [] in
required @@ pos n ( some string ) None info
2019-12-12 14:36:59 +04:00
let init_file =
let open Arg in
let info =
let docv = " INIT_FILE " in
2020-01-27 19:05:47 +04:00
let doc = " $(docv) is the path to smart contract file to be used for context initialization. " in
2019-12-12 14:36:59 +04:00
info ~ docv ~ doc [ " init-file " ] in
value @@ opt ( some string ) None info
2019-06-12 23:13:06 +04:00
let amount =
let open Arg in
let info =
let docv = " AMOUNT " in
2020-03-05 23:52:47 +04:00
let doc = " $(docv) is the amount the Michelson interpreter will use for the transaction. " in
2019-06-12 23:13:06 +04:00
info ~ docv ~ doc [ " amount " ] in
value @@ opt string " 0 " info
2020-03-05 23:52:47 +04:00
let balance =
let open Arg in
let info =
let docv = " BALANCE " in
let doc = " $(docv) is the balance the Michelson interpreter will use for the contract balance. " in
info ~ docv ~ doc [ " balance " ] in
value @@ opt string " 0 " info
2019-09-27 20:33:32 +04:00
let sender =
let open Arg in
let info =
let docv = " SENDER " in
2020-01-27 19:05:47 +04:00
let doc = " $(docv) is the sender the Michelson interpreter transaction will use. " in
2019-09-27 20:33:32 +04:00
info ~ docv ~ doc [ " sender " ] in
value @@ opt ( some string ) None info
let source =
let open Arg in
let info =
let docv = " SOURCE " in
2020-01-27 19:05:47 +04:00
let doc = " $(docv) is the source the Michelson interpreter transaction will use. " in
2019-09-27 20:33:32 +04:00
info ~ docv ~ doc [ " source " ] in
value @@ opt ( some string ) None info
2020-03-12 23:16:50 +04:00
let disable_michelson_typechecking =
let open Arg in
let info =
let doc = " disable Michelson typecking, this might produce ill-typed Michelson code. " in
info ~ doc [ " disable-michelson-typechecking " ] in
value @@ flag info
2019-12-19 21:59:00 +04:00
let predecessor_timestamp =
let open Arg in
let info =
let docv = " PREDECESSOR_TIMESTAMP " in
2020-01-27 19:05:47 +04:00
let doc = " $(docv) is the predecessor_timestamp (now value minus one minute) the Michelson interpreter will use (e.g. '2000-01-01T10:10:10Z') " in
2019-12-19 21:59:00 +04:00
info ~ docv ~ doc [ " predecessor-timestamp " ] in
value @@ opt ( some string ) None info
2019-09-20 13:59:44 +04:00
let display_format =
let open Arg in
let info =
let docv = " DISPLAY_FORMAT " in
let doc = " $(docv) is the format that will be used by the CLI. Available formats are 'dev', 'json', and 'human-readable' (default). When human-readable lacks details (we are still tweaking it), please contact us and use another format in the meanwhile. " in
info ~ docv ~ doc [ " format " ; " display-format " ] in
2019-10-26 21:57:22 +04:00
value @@
opt
( enum [ ( " human-readable " , ` Human_readable ) ; ( " dev " , ` Dev ) ; ( " json " , ` Json ) ] )
` Human_readable
info
2019-09-20 13:59:44 +04:00
2019-09-20 20:56:55 +04:00
let michelson_code_format =
let open Arg in
let info =
let docv = " MICHELSON_FORMAT " in
2019-10-26 21:57:22 +04:00
let doc = " $(docv) is the format that will be used by compile-contract for the resulting Michelson. Available formats are 'text' (default), 'json' and 'hex'. " in
2019-09-20 20:56:55 +04:00
info ~ docv ~ doc [ " michelson-format " ] in
2019-10-26 21:57:22 +04:00
value @@
opt
( enum [ ( " text " , ` Text ) ; ( " json " , ` Json ) ; ( " hex " , ` Hex ) ] )
` Text info
2019-09-20 20:56:55 +04:00
2019-11-30 01:22:56 +04:00
module Helpers = Ligo . Compile . Helpers
2019-12-09 22:51:10 +04:00
module Compile = Ligo . Compile
2019-11-30 01:22:56 +04:00
module Uncompile = Ligo . Uncompile
module Run = Ligo . Run . Of_michelson
2019-05-13 00:56:22 +04:00
let compile_file =
2020-03-12 23:16:50 +04:00
let f source_file entry_point syntax display_format disable_typecheck michelson_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed , _ = Compile . Utils . type_file source_file syntax ( Contract entry_point ) in
2019-12-09 22:51:10 +04:00
let % bind mini_c = Compile . Of_typed . compile typed in
2019-12-10 18:55:48 +04:00
let % bind michelson = Compile . Of_mini_c . aggregate_and_compile_contract mini_c entry_point in
2020-03-12 23:16:50 +04:00
let % bind contract = Compile . Of_michelson . build_contract ~ disable_typecheck michelson in
2019-09-20 20:56:55 +04:00
ok @@ Format . asprintf " %a \n " ( Main . Display . michelson_pp michelson_format ) contract
2019-05-13 00:56:22 +04:00
in
let term =
2020-03-12 23:16:50 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ syntax $ display_format $ disable_michelson_typechecking $ michelson_code_format ) in
2019-06-05 21:17:42 +04:00
let cmdname = " compile-contract " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Compile a contract. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-05-13 00:56:22 +04:00
2020-04-12 17:26:47 +04:00
let preprocess =
let f source_file syntax display_format = (
toplevel ~ display_format @@
let % bind pp =
Compile . Of_source . preprocess source_file ( Syntax_name syntax ) in
ok @@ Format . asprintf " %s \n " ( Buffer . contents pp )
) in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
let cmdname = " preprocess " in
let doc = " Subcommand: Preprocess the source file. \n Warning: Intended for development of LIGO and can break at any time. " in
( Term . ret term , Term . info ~ doc cmdname )
2020-01-27 19:05:47 +04:00
let print_cst =
2020-01-21 16:24:51 +04:00
let f source_file syntax display_format = (
toplevel ~ display_format @@
2020-01-27 19:05:47 +04:00
let % bind pp = Compile . Of_source . pretty_print source_file ( Syntax_name syntax ) in
2020-01-21 16:24:51 +04:00
ok @@ Format . asprintf " %s \n " ( Buffer . contents pp )
)
in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
2020-01-27 19:05:47 +04:00
let cmdname = " print-cst " in
let doc = " Subcommand: Print the CST. \n Warning: Intended for development of LIGO and can break at any time. " in
2020-01-21 16:24:51 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2020-01-27 19:05:47 +04:00
let print_ast =
2020-03-23 19:07:40 +04:00
let f source_file syntax display_format = (
toplevel ~ display_format @@
let % bind imperative = Compile . Utils . to_imperatve source_file syntax in
ok @@ Format . asprintf " %a \n " Compile . Of_imperative . pretty_print imperative
)
in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
let cmdname = " print-ast " in
let doc = " Subcommand: Print the AST. \n Warning: Intended for development of LIGO and can break at any time. " in
( Term . ret term , Term . info ~ doc cmdname )
let print_ast_sugar =
let f source_file syntax display_format = (
toplevel ~ display_format @@
let % bind sugar = Compile . Utils . to_sugar source_file syntax in
ok @@ Format . asprintf " %a \n " Compile . Of_sugar . pretty_print sugar
)
in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
let cmdname = " print-ast-sugar " in
let doc = " Subcommand: Print the AST. \n Warning: Intended for development of LIGO and can break at any time. " in
( Term . ret term , Term . info ~ doc cmdname )
let print_ast_core =
2020-01-21 16:24:51 +04:00
let f source_file syntax display_format = (
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind core = Compile . Utils . to_core source_file syntax in
ok @@ Format . asprintf " %a \n " Compile . Of_core . pretty_print core
2020-01-21 16:24:51 +04:00
)
in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
2020-03-23 19:07:40 +04:00
let cmdname = " print-ast-core " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Print the AST. \n Warning: Intended for development of LIGO and can break at any time. " in
2020-01-21 16:24:51 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2020-03-23 19:07:40 +04:00
let print_ast_typed =
2020-01-21 16:24:51 +04:00
let f source_file syntax display_format = (
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed , _ = Compile . Utils . type_file source_file syntax Env in
2020-01-27 19:05:47 +04:00
ok @@ Format . asprintf " %a \n " Compile . Of_typed . pretty_print typed
2020-01-21 16:24:51 +04:00
)
in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
2020-03-23 19:07:40 +04:00
let cmdname = " print-ast-typed " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Print the typed AST. \n Warning: Intended for development of LIGO and can break at any time. " in
2020-01-21 16:24:51 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2020-01-27 19:05:47 +04:00
let print_mini_c =
2020-01-21 16:24:51 +04:00
let f source_file syntax display_format = (
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed , _ = Compile . Utils . type_file source_file syntax Env in
2020-01-21 16:24:51 +04:00
let % bind mini_c = Compile . Of_typed . compile typed in
2020-01-27 19:05:47 +04:00
ok @@ Format . asprintf " %a \n " Compile . Of_mini_c . pretty_print mini_c
2020-01-21 16:24:51 +04:00
)
in
let term = Term . ( const f $ source_file 0 $ syntax $ display_format ) in
2020-01-27 19:05:47 +04:00
let cmdname = " print-mini-c " in
let doc = " Subcommand: Print Mini-C. Warning: Intended for development of LIGO and can break at any time. " in
2020-01-21 16:24:51 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-11-26 03:30:12 +04:00
let measure_contract =
let f source_file entry_point syntax display_format =
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind contract = Compile . Utils . compile_file source_file syntax entry_point in
2019-11-26 03:30:12 +04:00
let open Tezos_utils in
ok @@ Format . asprintf " %d bytes \n " ( Michelson . measure contract )
in
let term =
Term . ( const f $ source_file 0 $ entry_point 1 $ syntax $ display_format ) in
let cmdname = " measure-contract " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Measure a contract's compiled size in bytes. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-11-26 03:30:12 +04:00
2019-05-13 00:56:22 +04:00
let compile_parameter =
2020-03-05 23:52:47 +04:00
let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed_prg , state = Compile . Utils . type_file source_file syntax ( Contract entry_point ) in
2019-12-09 22:51:10 +04:00
let % bind mini_c_prg = Compile . Of_typed . compile typed_prg in
2019-12-10 18:55:48 +04:00
let % bind michelson_prg = Compile . Of_mini_c . aggregate_and_compile_contract mini_c_prg entry_point in
2019-12-09 22:51:10 +04:00
let env = Ast_typed . program_environment typed_prg in
let % bind ( _ contract : Tezos_utils . Michelson . michelson ) =
(* fails if the given entry point is not a valid contract *)
2019-12-18 19:34:29 +04:00
Compile . Of_michelson . build_contract michelson_prg in
2019-12-09 22:51:10 +04:00
2020-03-16 17:28:05 +04:00
let % bind ( typed_param , _ ) = Compile . Utils . type_expression ( Some source_file ) syntax expression env state in
2019-12-09 22:51:10 +04:00
let % bind mini_c_param = Compile . Of_typed . compile_expression typed_param in
2019-12-11 22:15:25 +04:00
let % bind compiled_param = Compile . Of_mini_c . aggregate_and_compile_expression mini_c_prg mini_c_param in
2019-12-18 19:34:29 +04:00
let % bind () = Compile . Of_typed . assert_equal_contract_type Check_parameter entry_point typed_prg typed_param in
let % bind () = Compile . Of_michelson . assert_equal_contract_type Check_parameter michelson_prg compiled_param in
2020-03-05 23:52:47 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; balance ; sender ; source } in
2020-01-03 21:09:16 +04:00
let % bind value = Run . evaluate_expression ~ options compiled_param . expr compiled_param . expr_ty in
2019-10-31 18:50:51 +04:00
ok @@ Format . asprintf " %a \n " ( Main . Display . michelson_pp michelson_format ) value
2019-05-13 00:56:22 +04:00
in
let term =
2020-03-05 23:52:47 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " PARAMETER " 2 $ syntax $ amount $ balance $ sender $ source $ predecessor_timestamp $ display_format $ michelson_code_format ) in
2019-06-05 21:17:42 +04:00
let cmdname = " compile-parameter " in
2020-01-27 19:05:47 +04:00
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
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-05-13 00:56:22 +04:00
2019-12-11 23:42:52 +04:00
let interpret =
2020-03-05 23:52:47 +04:00
let f expression init_file syntax amount balance sender source predecessor_timestamp display_format =
2019-12-11 23:42:52 +04:00
toplevel ~ display_format @@
2019-12-12 14:36:59 +04:00
let % bind ( decl_list , state , env ) = match init_file with
| Some init_file ->
2020-03-16 17:28:05 +04:00
let % bind typed_prg , state = Compile . Utils . type_file init_file syntax Env in
2019-12-12 14:36:59 +04:00
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
2020-01-27 19:05:47 +04:00
2020-03-16 17:28:05 +04:00
let % bind ( typed_exp , _ ) = Compile . Utils . type_expression init_file syntax expression env state in
2020-01-17 19:30:36 +04:00
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
2020-03-05 23:52:47 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; balance ; sender ; source } in
2020-01-17 19:30:36 +04:00
let % bind runres = Run . run_expression ~ options compiled_exp . expr compiled_exp . expr_ty in
match runres with
| Fail fail_res ->
let % bind failstring = Run . failwith_to_string fail_res in
ok @@ Format . asprintf " %s " failstring
| Success value ' ->
2020-03-16 17:28:05 +04:00
let % bind core_output = Uncompile . uncompile_expression typed_exp . type_expression value ' in
ok @@ Format . asprintf " %a \n " Ast_core . PP . expression core_output
2019-12-11 23:42:52 +04:00
in
let term =
2020-03-05 23:52:47 +04:00
Term . ( const f $ expression " EXPRESSION " 0 $ init_file $ syntax $ amount $ balance $ sender $ source $ predecessor_timestamp $ display_format ) in
2019-12-11 23:42:52 +04:00
let cmdname = " interpret " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Interpret the expression in the context initialized by the provided source file. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-12-11 23:42:52 +04:00
2020-02-07 16:07:57 +04:00
let temp_ligo_interpreter =
let f source_file syntax display_format =
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed , _ = Compile . Utils . type_file source_file syntax Env in
2020-02-07 16:07:57 +04:00
let % bind res = Compile . Of_typed . some_interpret typed in
ok @@ Format . asprintf " %s \n " res
in
let term =
Term . ( const f $ source_file 0 $ syntax $ display_format ) in
let cmdname = " ligo-interpret " in
let doc = " Subcommand: (temporary / dev only) uses LIGO interpret. " in
( Term . ret term , Term . info ~ doc cmdname )
2019-12-11 23:42:52 +04:00
2019-05-13 00:56:22 +04:00
let compile_storage =
2020-03-05 23:52:47 +04:00
let f source_file entry_point expression syntax amount balance sender source predecessor_timestamp display_format michelson_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed_prg , state = Compile . Utils . type_file source_file syntax ( Contract entry_point ) in
2019-12-09 22:51:10 +04:00
let % bind mini_c_prg = Compile . Of_typed . compile typed_prg in
2019-12-10 18:55:48 +04:00
let % bind michelson_prg = Compile . Of_mini_c . aggregate_and_compile_contract mini_c_prg entry_point in
2019-12-09 22:51:10 +04:00
let env = Ast_typed . program_environment typed_prg in
let % bind ( _ contract : Tezos_utils . Michelson . michelson ) =
(* fails if the given entry point is not a valid contract *)
2019-12-18 19:34:29 +04:00
Compile . Of_michelson . build_contract michelson_prg in
2019-12-09 22:51:10 +04:00
2020-03-16 17:28:05 +04:00
let % bind ( typed_param , _ ) = Compile . Utils . type_expression ( Some source_file ) syntax expression env state in
2019-12-09 22:51:10 +04:00
let % bind mini_c_param = Compile . Of_typed . compile_expression typed_param in
2020-01-27 14:36:51 +04:00
let % bind compiled_param = Compile . Of_mini_c . aggregate_and_compile_expression mini_c_prg mini_c_param in
2019-12-18 19:34:29 +04:00
let % bind () = Compile . Of_typed . assert_equal_contract_type Check_storage entry_point typed_prg typed_param in
let % bind () = Compile . Of_michelson . assert_equal_contract_type Check_storage michelson_prg compiled_param in
2020-03-05 23:52:47 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; balance ; sender ; source } in
2020-01-03 21:09:16 +04:00
let % bind value = Run . evaluate_expression ~ options compiled_param . expr compiled_param . expr_ty in
2019-10-31 18:50:51 +04:00
ok @@ Format . asprintf " %a \n " ( Main . Display . michelson_pp michelson_format ) value
2019-05-13 00:56:22 +04:00
in
let term =
2020-03-05 23:52:47 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " STORAGE " 2 $ syntax $ amount $ balance $ sender $ source $ predecessor_timestamp $ display_format $ michelson_code_format ) in
2019-06-05 21:17:42 +04:00
let cmdname = " compile-storage " in
2020-01-27 19:05:47 +04:00
let doc = " 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. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-05-13 00:56:22 +04:00
2019-06-09 16:08:37 +04:00
let dry_run =
2020-03-05 23:52:47 +04:00
let f source_file entry_point storage input amount balance sender source predecessor_timestamp syntax display_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed_prg , state = Compile . Utils . type_file source_file syntax ( Contract entry_point ) in
2019-12-09 22:51:10 +04:00
let env = Ast_typed . program_environment typed_prg in
let % bind mini_c_prg = Compile . Of_typed . compile typed_prg in
2019-12-10 18:55:48 +04:00
let % bind michelson_prg = Compile . Of_mini_c . aggregate_and_compile_contract mini_c_prg entry_point in
2019-12-09 22:51:10 +04:00
let % bind ( _ contract : Tezos_utils . Michelson . michelson ) =
(* fails if the given entry point is not a valid contract *)
2019-12-18 19:34:29 +04:00
Compile . Of_michelson . build_contract michelson_prg in
2019-12-09 22:51:10 +04:00
2020-03-16 17:28:05 +04:00
let % bind compiled_params = Compile . Utils . compile_storage storage input source_file syntax env state mini_c_prg in
2019-12-09 22:51:10 +04:00
let % bind args_michelson = Run . evaluate_expression compiled_params . expr compiled_params . expr_ty in
2020-03-05 23:52:47 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; balance ; sender ; source } in
2020-01-17 19:30:36 +04:00
let % bind runres = Run . run_contract ~ options michelson_prg . expr michelson_prg . expr_ty args_michelson in
match runres with
| Fail fail_res ->
let % bind failstring = Run . failwith_to_string fail_res in
ok @@ Format . asprintf " %s " failstring
| Success michelson_output ->
2020-03-16 17:28:05 +04:00
let % bind core_output = Uncompile . uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in
ok @@ Format . asprintf " %a \n " Ast_core . PP . expression core_output
2019-06-09 16:08:37 +04:00
in
let term =
2020-03-05 23:52:47 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " PARAMETER " 2 $ expression " STORAGE " 3 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format ) in
2019-06-09 16:08:37 +04:00
let cmdname = " dry-run " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Run a smart-contract with the given storage and input. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-05-13 00:56:22 +04:00
2019-06-11 21:57:07 +04:00
let run_function =
2020-03-05 23:52:47 +04:00
let f source_file entry_point parameter amount balance sender source predecessor_timestamp syntax display_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed_prg , state = Compile . Utils . type_file source_file syntax Env in
2019-12-09 22:51:10 +04:00
let env = Ast_typed . program_environment typed_prg in
2019-12-10 18:55:48 +04:00
let % bind mini_c_prg = Compile . Of_typed . compile typed_prg in
2019-12-09 22:51:10 +04:00
2019-12-04 21:30:52 +04:00
2020-03-16 17:28:05 +04:00
let % bind v_syntax = Helpers . syntax_to_variant ( Syntax_name syntax ) ( Some source_file ) in
let % bind imperative_param = Compile . Of_source . compile_expression v_syntax parameter in
let % bind sugar_param = Compile . Of_imperative . compile_expression imperative_param in
let % bind core_param = Compile . Of_sugar . compile_expression sugar_param in
let % bind app = Compile . Of_core . apply entry_point core_param in
let % bind ( typed_app , _ ) = Compile . Of_core . compile_expression ~ env ~ state app in
2019-12-11 22:15:25 +04:00
let % bind compiled_applied = Compile . Of_typed . compile_expression typed_app in
2019-12-09 22:51:10 +04:00
2020-01-17 19:30:36 +04:00
let % bind michelson = Compile . Of_mini_c . aggregate_and_compile_expression mini_c_prg compiled_applied in
2020-03-05 23:52:47 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; balance ; sender ; source } in
2020-01-17 19:30:36 +04:00
let % bind runres = Run . run_expression ~ options michelson . expr michelson . expr_ty in
match runres with
| Fail fail_res ->
let % bind failstring = Run . failwith_to_string fail_res in
ok @@ Format . asprintf " %s " failstring
| Success michelson_output ->
2020-03-16 17:53:56 +04:00
let % bind core_output = Uncompile . uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in
ok @@ Format . asprintf " %a \n " Ast_core . PP . expression core_output
2019-06-11 21:57:07 +04:00
in
let term =
2020-03-05 23:52:47 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " PARAMETER " 2 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format ) in
2019-06-11 21:57:07 +04:00
let cmdname = " run-function " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Run a function with the given parameter. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-06-11 21:57:07 +04:00
let evaluate_value =
2020-03-05 23:52:47 +04:00
let f source_file entry_point amount balance sender source predecessor_timestamp syntax display_format =
2019-10-10 11:55:15 +04:00
toplevel ~ display_format @@
2020-03-16 17:28:05 +04:00
let % bind typed_prg , _ = Compile . Utils . type_file source_file syntax Env in
2019-12-09 22:51:10 +04:00
let % bind mini_c = Compile . Of_typed . compile typed_prg in
2019-12-10 18:55:48 +04:00
let % bind ( exp , _ ) = Mini_c . get_entry mini_c entry_point in
2019-12-11 22:15:25 +04:00
let % bind compiled = Compile . Of_mini_c . aggregate_and_compile_expression mini_c exp in
2020-03-05 23:52:47 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; balance ; sender ; source } in
2020-01-17 19:30:36 +04:00
let % bind michelson_output = Run . run_no_failwith ~ options compiled . expr compiled . expr_ty in
2020-03-17 19:04:27 +04:00
let % bind core_output = Uncompile . uncompile_typed_program_entry_expression_result typed_prg entry_point michelson_output in
2020-03-16 17:53:56 +04:00
ok @@ Format . asprintf " %a \n " Ast_core . PP . expression core_output
2019-10-10 11:55:15 +04:00
in
let term =
2020-03-05 23:52:47 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ amount $ balance $ sender $ source $ predecessor_timestamp $ syntax $ display_format ) in
2019-10-10 11:55:15 +04:00
let cmdname = " evaluate-value " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Evaluate a given definition. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-06-11 21:57:07 +04:00
2019-09-25 12:49:14 +04:00
let compile_expression =
2019-10-31 18:50:51 +04:00
let f expression syntax display_format michelson_format =
2019-09-25 12:49:14 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
let env = Ast_typed . Environment . full_empty in
let state = Typer . Solver . initial_state in
2020-03-16 17:28:05 +04:00
let % bind compiled_exp = Compile . Utils . compile_expression None syntax expression env state in
2019-12-09 22:51:10 +04:00
let % bind value = Run . evaluate_expression compiled_exp . expr compiled_exp . expr_ty in
2019-10-31 18:50:51 +04:00
ok @@ Format . asprintf " %a \n " ( Main . Display . michelson_pp michelson_format ) value
2019-09-25 12:49:14 +04:00
in
let term =
2019-11-30 01:22:56 +04:00
Term . ( const f $ expression " " 1 $ req_syntax 0 $ display_format $ michelson_code_format ) in
2019-09-25 12:49:14 +04:00
let cmdname = " compile-expression " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: Compile to a michelson value. " in
2019-12-16 21:37:52 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-09-25 12:49:14 +04:00
2020-01-08 14:54:21 +04:00
let dump_changelog =
let f display_format = toplevel ~ display_format @@ ( ok @@ [ % blob " ../../CHANGELOG.md " ] ) in
let term =
Term . ( const f $ display_format ) in
let cmdname = " changelog " in
let doc = " Dump the LIGO changelog to stdout. " in
( Term . ret term , Term . info ~ doc cmdname )
2019-12-20 18:52:49 +04:00
let list_declarations =
let f source_file syntax =
toplevel ~ display_format : ( ` Human_readable ) @@
2020-03-16 17:28:05 +04:00
let % bind core_prg = Compile . Utils . to_core source_file syntax in
let json_decl = List . map ( fun decl -> ` String decl ) @@ Compile . Of_core . list_declarations core_prg in
2019-12-20 18:52:49 +04:00
ok @@ J . to_string @@ ` Assoc [ ( " source_file " , ` String source_file ) ; ( " declarations " , ` List json_decl ) ]
in
let term =
Term . ( const f $ source_file 0 $ syntax ) in
let cmdname = " list-declarations " in
2020-01-27 19:05:47 +04:00
let doc = " Subcommand: List all the top-level declarations. " in
2019-12-20 18:52:49 +04:00
( Term . ret term , Term . info ~ doc cmdname )
2019-11-22 00:06:34 +04:00
let run ? argv () =
Term . eval_choice ? argv main [
2020-02-07 16:07:57 +04:00
temp_ligo_interpreter ;
2019-06-11 21:57:07 +04:00
compile_file ;
2019-11-26 03:30:12 +04:00
measure_contract ;
2019-06-11 21:57:07 +04:00
compile_parameter ;
compile_storage ;
2019-09-25 12:49:14 +04:00
compile_expression ;
2019-12-11 23:42:52 +04:00
interpret ;
2019-06-11 21:57:07 +04:00
dry_run ;
run_function ;
evaluate_value ;
2020-01-08 14:54:21 +04:00
dump_changelog ;
2020-01-21 16:24:51 +04:00
print_cst ;
print_ast ;
2020-03-23 19:07:40 +04:00
print_ast_sugar ;
print_ast_core ;
print_ast_typed ;
2019-12-20 18:52:49 +04:00
print_mini_c ;
list_declarations ;
2020-04-12 17:26:47 +04:00
preprocess
2019-06-11 21:57:07 +04:00
]