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
2019-06-13 03:43:16 +04:00
let doc = " $(docv) is the path to the .ligo or .mligo file of the contract. " 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
2019-06-11 00:16:08 +04:00
let doc = " $(docv) is the syntax that will be used. Currently supported syntaxes are \" pascaligo \" and \" cameligo \" . By default, the syntax is guessed from the extension (.ligo and .mligo, 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
let doc = " $(docv) is the syntax that will be used. Currently supported syntaxes are \" pascaligo \" and \" cameligo \" . By default, the syntax is guessed from the extension (.ligo and .mligo, respectively). " in
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
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
2019-06-12 23:13:06 +04:00
let amount =
let open Arg in
let info =
let docv = " AMOUNT " in
2019-12-19 21:59:00 +04:00
let doc = " $(docv) is the amount the michelson interpreter will use. " in
2019-06-12 23:13:06 +04:00
info ~ docv ~ doc [ " amount " ] 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
2019-12-19 21:59:00 +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
2019-12-19 21:59:00 +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
2019-12-19 21:59:00 +04:00
let predecessor_timestamp =
let open Arg in
let info =
let docv = " PREDECESSOR_TIMESTAMP " in
2020-01-04 02:01:46 +04:00
let doc = " $(docv) is the pedecessor_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 =
2019-09-27 20:33:32 +04:00
let f source_file entry_point syntax display_format michelson_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
let % bind simplified = Compile . Of_source . compile source_file ( Syntax_name syntax ) in
let % bind typed , _ = Compile . Of_simplified . compile simplified in
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
2019-12-18 19:34:29 +04:00
let % bind contract = Compile . Of_michelson . build_contract 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 =
2019-09-27 20:33:32 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ syntax $ display_format $ michelson_code_format ) in
2019-06-05 21:17:42 +04:00
let cmdname = " compile-contract " in
2019-11-21 21:44:27 +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
2019-11-26 03:30:12 +04:00
let measure_contract =
let f source_file entry_point syntax display_format =
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
let % bind simplified = Compile . Of_source . compile source_file ( Syntax_name syntax ) in
let % bind typed , _ = Compile . Of_simplified . compile simplified in
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
2019-12-18 19:34:29 +04:00
let % bind contract = Compile . Of_michelson . build_contract michelson 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
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-01-03 21:09:16 +04:00
let f source_file entry_point expression syntax amount sender source predecessor_timestamp display_format michelson_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
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
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
let % bind v_syntax = Helpers . syntax_to_variant ( Syntax_name syntax ) ( Some source_file ) in
let % bind simplified_param = Compile . Of_source . compile_expression v_syntax expression in
let % bind ( typed_param , _ ) = Compile . Of_simplified . compile_expression ~ env ~ state simplified_param in
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-01-03 21:09:16 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; sender ; source } in
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-01-03 21:09:16 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " PARAMETER " 2 $ syntax $ amount $ sender $ source $ predecessor_timestamp $ display_format $ michelson_code_format ) in
2019-06-05 21:17:42 +04:00
let cmdname = " compile-parameter " in
2019-11-21 21:44:27 +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 =
2019-12-19 21:59:00 +04:00
let f expression init_file syntax amount 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 ->
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
2019-12-11 23:42:52 +04:00
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
2019-12-12 14:36:59 +04:00
let % bind compiled_exp = Compile . Of_mini_c . aggregate_and_compile_expression decl_list mini_c_exp in
2019-12-19 21:59:00 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; sender ; source } in
2019-12-11 23:42:52 +04:00
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 =
2019-12-19 21:59:00 +04:00
Term . ( const f $ expression " EXPRESSION " 0 $ init_file $ syntax $ amount $ sender $ source $ predecessor_timestamp $ display_format ) in
2019-12-11 23:42:52 +04:00
let cmdname = " interpret " in
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
2019-05-13 00:56:22 +04:00
let compile_storage =
2020-01-03 21:09:16 +04:00
let f source_file entry_point expression syntax amount sender source predecessor_timestamp display_format michelson_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
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
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
let % bind v_syntax = Helpers . syntax_to_variant ( Syntax_name syntax ) ( Some source_file ) in
let % bind simplified_param = Compile . Of_source . compile_expression v_syntax expression in
let % bind ( typed_param , _ ) = Compile . Of_simplified . compile_expression ~ env ~ state simplified_param in
let % bind mini_c_param = Compile . Of_typed . compile_expression typed_param in
let % bind compiled_param = Compile . Of_mini_c . compile_expression 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-01-03 21:09:16 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; sender ; source } in
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-01-03 21:09:16 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " STORAGE " 2 $ syntax $ amount $ sender $ source $ predecessor_timestamp $ display_format $ michelson_code_format ) in
2019-06-05 21:17:42 +04:00
let cmdname = " compile-storage " in
2019-11-21 21:44:27 +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 =
2019-12-19 21:59:00 +04:00
let f source_file entry_point storage input amount sender source predecessor_timestamp syntax display_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
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 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
let % bind v_syntax = Helpers . syntax_to_variant ( Syntax_name syntax ) ( Some source_file ) in
let % bind simplified = Compile . Of_source . compile_contract_input storage input v_syntax in
let % bind typed , _ = Compile . Of_simplified . compile_expression ~ env ~ state simplified in
let % bind mini_c = Compile . Of_typed . compile_expression typed in
let % bind compiled_params = Compile . Of_mini_c . compile_expression mini_c in
let % bind args_michelson = Run . evaluate_expression compiled_params . expr compiled_params . expr_ty in
2019-12-19 21:59:00 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; sender ; source } in
2019-12-09 22:51:10 +04:00
let % bind michelson_output = Run . run_contract ~ options michelson_prg . expr michelson_prg . expr_ty args_michelson in
let % bind simplified_output = Uncompile . uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in
2019-11-30 01:22:56 +04:00
ok @@ Format . asprintf " %a \n " Ast_simplified . PP . expression simplified_output
2019-06-09 16:08:37 +04:00
in
let term =
2019-12-19 21:59:00 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " PARAMETER " 2 $ expression " STORAGE " 3 $ amount $ sender $ source $ predecessor_timestamp $ syntax $ display_format ) in
2019-06-09 16:08:37 +04:00
let cmdname = " dry-run " in
2019-11-21 21:06:25 +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 =
2019-12-19 21:59:00 +04:00
let f source_file entry_point parameter amount sender source predecessor_timestamp syntax display_format =
2019-09-20 13:59:44 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
let % bind v_syntax = Helpers . syntax_to_variant ( Syntax_name syntax ) ( Some source_file ) in
let % bind simplified_prg = Compile . Of_source . compile source_file ( Syntax_name syntax ) in
let % bind typed_prg , state = Compile . Of_simplified . compile simplified_prg in
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
let % bind simplified_param = Compile . Of_source . compile_expression v_syntax parameter in
2019-12-11 22:15:25 +04:00
let % bind app = Compile . Of_simplified . apply entry_point simplified_param in
let % bind ( typed_app , _ ) = Compile . Of_simplified . compile_expression ~ env ~ state app in
let % bind compiled_applied = Compile . Of_typed . compile_expression typed_app in
2019-12-09 22:51:10 +04:00
2019-12-11 22:15:25 +04:00
let % bind michelson = Compile . Of_mini_c . aggregate_and_compile_expression mini_c_prg compiled_applied in
2019-12-19 21:59:00 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; sender ; source } in
2019-12-09 22:51:10 +04:00
let % bind michelson_output = Run . run ~ options michelson . expr michelson . expr_ty in
let % bind simplified_output = Uncompile . uncompile_typed_program_entry_function_result typed_prg entry_point michelson_output in
2019-11-30 01:22:56 +04:00
ok @@ Format . asprintf " %a \n " Ast_simplified . PP . expression simplified_output
2019-06-11 21:57:07 +04:00
in
let term =
2019-12-19 21:59:00 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ expression " PARAMETER " 2 $ amount $ sender $ source $ predecessor_timestamp $ syntax $ display_format ) in
2019-06-11 21:57:07 +04:00
let cmdname = " run-function " in
2019-11-21 21:06:25 +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 =
2019-12-19 21:59:00 +04:00
let f source_file entry_point amount sender source predecessor_timestamp syntax display_format =
2019-10-10 11:55:15 +04:00
toplevel ~ display_format @@
2019-12-09 22:51:10 +04:00
let % bind simplified = Compile . Of_source . compile source_file ( Syntax_name syntax ) in
let % bind typed_prg , _ = Compile . Of_simplified . compile simplified in
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
2019-12-19 21:59:00 +04:00
let % bind options = Run . make_dry_run_options { predecessor_timestamp ; amount ; sender ; source } in
2019-12-09 22:51:10 +04:00
let % bind michelson_output = Run . run ~ options compiled . expr compiled . expr_ty in
let % bind simplified_output = Uncompile . uncompile_typed_program_entry_expression_result typed_prg entry_point michelson_output in
2019-11-30 01:22:56 +04:00
ok @@ Format . asprintf " %a \n " Ast_simplified . PP . expression simplified_output
2019-10-10 11:55:15 +04:00
in
let term =
2019-12-19 21:59:00 +04:00
Term . ( const f $ source_file 0 $ entry_point 1 $ amount $ sender $ source $ predecessor_timestamp $ syntax $ display_format ) in
2019-10-10 11:55:15 +04:00
let cmdname = " evaluate-value " in
2019-11-21 21:06:25 +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-11-30 01:22:56 +04:00
let % bind v_syntax = Helpers . syntax_to_variant ( Syntax_name syntax ) ( None ) in
2019-12-09 22:51:10 +04:00
let env = Ast_typed . Environment . full_empty in
let state = Typer . Solver . initial_state in
let % bind simplified = Compile . Of_source . compile_expression v_syntax expression in
let % bind ( typed_exp , _ ) = Compile . Of_simplified . compile_expression ~ env ~ state simplified in
let % bind mini_c_exp = Compile . Of_typed . compile_expression typed_exp in
let % bind compiled_exp = Compile . Of_mini_c . compile_expression mini_c_exp in
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
2019-11-21 21:06:25 +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-11-22 00:06:34 +04:00
let run ? argv () =
Term . eval_choice ? argv main [
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 ;
2019-06-11 21:57:07 +04:00
]