This commit is contained in:
Sander Spies 2020-01-21 14:14:23 +01:00
commit 95205609f8
10 changed files with 171 additions and 26 deletions

View File

@ -24,51 +24,51 @@ ${pre}`;
const CAMELIGO_EXAMPLE = `${pre}ocaml
type storage = int
(* variant defining pseudo multi-entrypoint
actions *)
(* variant defining pseudo multi-entrypoint actions *)
type action =
| Increment of int
| Decrement of int
| Increment of int
| Decrement of int
let add (a: int) (b: int): int = a + b
let add (a: int) (b: int) : int = a + b
let sub (a: int) (b: int) : int = a - b
let subtract (a: int) (b: int): int = a - b
(* real entrypoint that re-routes the flow based on the action provided *)
(* real entrypoint that re-routes the flow
based on the action provided *)
let%entry main(p : action) storage =
let storage =
match p with
| Increment n -> add storage n
| Decrement n -> subtract storage n
in (([] : operation list), storage)
let main (p,s: action * storage) =
let storage =
match p with
| Increment n -> add s n
| Decrement n -> sub s n
in ([] : operation list), storage
${pre}`;
const REASONLIGO_EXAMPLE = `${pre}reasonligo
type storage = int;
/* variant defining pseudo multi-entrypoint
actions */
/* variant defining pseudo multi-entrypoint actions */
type action =
| Increment(int)
| Decrement(int);
let add = (a: int, b: int): int => a + b;
let sub = (a: int, b: int): int => a - b;
let subtract = (a: int, b: int): int => a - b;
/* real entrypoint that re-routes the flow based on the action provided */
/* real entrypoint that re-routes the flow
based on the action provided */
let main = (p: action, storage) => {
let main2 = (p: action, storage) => {
let storage =
switch (p) {
| Increment(n) => add(storage, n)
| Decrement(n) => subtract(storage, n)
| Decrement(n) => sub(storage, n)
};
([]: list(operation), storage);
};
let main = (x: (action, storage)) => main2(x[0],x[1]);
${pre}`;

View File

@ -138,6 +138,57 @@ let compile_file =
let doc = "Subcommand: compile a contract." in
(Term.ret term , Term.info ~doc cmdname)
let print_cst =
let f source_file syntax display_format = (
toplevel ~display_format @@
let%bind pp = Compile.Of_source.pretty_print 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 = "print-cst" in
let doc = "Subcommand: print the cst. Warning: intended for development of LIGO and can break at any time." in
(Term.ret term, Term.info ~doc cmdname)
let print_ast =
let f source_file syntax display_format = (
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
ok @@ Format.asprintf "%a\n" Compile.Of_simplified.pretty_print simplified
)
in
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
let cmdname = "print-ast" in
let doc = "Subcommand: print the ast. Warning: intended for development of LIGO and can break at any time." in
(Term.ret term, Term.info ~doc cmdname)
let print_typed_ast =
let f source_file syntax display_format = (
toplevel ~display_format @@
let%bind simplified = Compile.Of_source.compile source_file (Syntax_name syntax) in
let%bind typed,_ = Compile.Of_simplified.compile simplified in
ok @@ Format.asprintf "%a\n" Compile.Of_typed.pretty_print typed
)
in
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
let cmdname = "print-typed-ast" in
let doc = "Subcommand: print the typed ast. Warning: intended for development of LIGO and can break at any time." in
(Term.ret term, Term.info ~doc cmdname)
let print_mini_c =
let f source_file syntax display_format = (
toplevel ~display_format @@
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
ok @@ Format.asprintf "%a\n" Compile.Of_mini_c.pretty_print mini_c
)
in
let term = Term.(const f $ source_file 0 $ syntax $ display_format) in
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
(Term.ret term, Term.info ~doc cmdname)
let measure_contract =
let f source_file entry_point syntax display_format =
toplevel ~display_format @@
@ -371,4 +422,8 @@ let run ?argv () =
run_function ;
evaluate_value ;
dump_changelog ;
print_cst ;
print_ast ;
print_typed_ast ;
print_mini_c
]

View File

@ -47,6 +47,22 @@ let%expect_test _ =
measure-contract
Subcommand: measure a contract's compiled size in bytes.
print-ast
Subcommand: print the ast. Warning: intended for development of
LIGO and can break at any time.
print-cst
Subcommand: print the cst. Warning: intended for development of
LIGO and can break at any time.
print-mini-c
Subcommand: print mini c. Warning: intended for development of
LIGO and can break at any time.
print-typed-ast
Subcommand: print the typed ast. Warning: intended for development
of LIGO and can break at any time.
run-function
Subcommand: run a function with the given parameter.
@ -104,6 +120,22 @@ let%expect_test _ =
measure-contract
Subcommand: measure a contract's compiled size in bytes.
print-ast
Subcommand: print the ast. Warning: intended for development of
LIGO and can break at any time.
print-cst
Subcommand: print the cst. Warning: intended for development of
LIGO and can break at any time.
print-mini-c
Subcommand: print mini c. Warning: intended for development of
LIGO and can break at any time.
print-typed-ast
Subcommand: print the typed ast. Warning: intended for development
of LIGO and can break at any time.
run-function
Subcommand: run a function with the given parameter.

View File

@ -133,3 +133,41 @@ let parsify_string = fun (syntax : v_syntax) source_filename ->
let%bind parsified = parsify source_filename in
let%bind applied = Self_ast_simplified.all_program parsified in
ok applied
let pretty_print_pascaligo = fun source ->
let%bind ast = Parser.Pascaligo.parse_file source in
let buffer = Buffer.create 59 in
let state = Parser.Pascaligo.ParserLog.mk_state
~offsets:true
~mode:`Byte
~buffer in
Parser.Pascaligo.ParserLog.pp_ast state ast;
ok buffer
let pretty_print_cameligo = fun source ->
let%bind ast = Parser.Cameligo.parse_file source in
let buffer = Buffer.create 59 in
let state = Parser.Cameligo.ParserLog.mk_state
~offsets:true
~mode:`Byte
~buffer in
Parser.Cameligo.ParserLog.pp_ast state ast;
ok buffer
let pretty_print_reasonligo = fun source ->
let%bind ast = Parser.Reasonligo.parse_file source in
let buffer = Buffer.create 59 in
let state = Parser.Reasonligo.ParserLog.mk_state
~offsets:true
~mode:`Byte
~buffer in
Parser.Reasonligo.ParserLog.pp_ast state ast;
ok buffer
let pretty_print = fun syntax source_filename ->
let%bind v_syntax = syntax_to_variant syntax (Some source_filename) in
(match v_syntax with
| Pascaligo -> pretty_print_pascaligo
| Cameligo -> pretty_print_cameligo
| ReasonLIGO -> pretty_print_reasonligo)
source_filename

View File

@ -32,3 +32,6 @@ let aggregate_and_compile_contract = fun (program : Types.program) name ->
let aggregate_and_compile_expression = fun program exp ->
aggregate_and_compile program (ExpressionForm exp)
let pretty_print program =
Mini_c.PP.program program

View File

@ -18,3 +18,6 @@ let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simpl
{ expression = Ast_simplified.E_application (entry_point_var, param) ;
location = Virtual "generated application" } in
ok applied
let pretty_print formatter (program : Ast_simplified.program) =
Ast_simplified.PP.program formatter program

View File

@ -18,3 +18,6 @@ let compile_contract_input : string -> string -> v_syntax -> Ast_simplified.expr
fun storage parameter syntax ->
let%bind (storage,parameter) = bind_map_pair (compile_expression syntax) (storage,parameter) in
ok @@ Ast_simplified.e_pair storage parameter
let pretty_print source_filename syntax =
Helpers.pretty_print syntax source_filename

View File

@ -21,4 +21,7 @@ let assert_equal_contract_type : check_type -> string -> Ast_typed.program -> As
)
| _ -> dummy_fail
)
| _ -> dummy_fail )
| _ -> dummy_fail )
let pretty_print ppf program =
Ast_typed.PP.program ppf program

View File

@ -1,3 +1,5 @@
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)
type storage = int
(* variant defining pseudo multi-entrypoint actions *)
@ -11,9 +13,11 @@ let sub (a: int) (b: int) : int = a - b
(* real entrypoint that re-routes the flow based on the action provided *)
let main (ps: action * storage) =
let main (p,s: action * storage) =
let storage =
match ps.0 with
| Increment n -> add ps.1 n
| Decrement n -> sub ps.1 n
match p with
| Increment n -> add s n
| Decrement n -> sub s n
in ([] : operation list), storage
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)

View File

@ -1,3 +1,5 @@
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)
type storage = int;
/* variant defining pseudo multi-entrypoint actions */
@ -21,3 +23,5 @@ let main2 = (p: action, storage) => {
};
let main = (x: (action, storage)) => main2(x[0],x[1]);
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)