Merge.
This commit is contained in:
commit
95205609f8
@ -24,51 +24,51 @@ ${pre}`;
|
|||||||
const CAMELIGO_EXAMPLE = `${pre}ocaml
|
const CAMELIGO_EXAMPLE = `${pre}ocaml
|
||||||
type storage = int
|
type storage = int
|
||||||
|
|
||||||
(* variant defining pseudo multi-entrypoint
|
(* variant defining pseudo multi-entrypoint actions *)
|
||||||
actions *)
|
|
||||||
type action =
|
type action =
|
||||||
| Increment of int
|
| Increment of int
|
||||||
| Decrement 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
|
let main (p,s: action * storage) =
|
||||||
based on the action provided *)
|
|
||||||
let%entry main(p : action) storage =
|
|
||||||
let storage =
|
let storage =
|
||||||
match p with
|
match p with
|
||||||
| Increment n -> add storage n
|
| Increment n -> add s n
|
||||||
| Decrement n -> subtract storage n
|
| Decrement n -> sub s n
|
||||||
in (([] : operation list), storage)
|
in ([] : operation list), storage
|
||||||
${pre}`;
|
${pre}`;
|
||||||
|
|
||||||
|
|
||||||
const REASONLIGO_EXAMPLE = `${pre}reasonligo
|
const REASONLIGO_EXAMPLE = `${pre}reasonligo
|
||||||
type storage = int;
|
type storage = int;
|
||||||
|
|
||||||
/* variant defining pseudo multi-entrypoint
|
/* variant defining pseudo multi-entrypoint actions */
|
||||||
actions */
|
|
||||||
type action =
|
type action =
|
||||||
| Increment(int)
|
| Increment(int)
|
||||||
| Decrement(int);
|
| Decrement(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
|
let main2 = (p: action, storage) => {
|
||||||
based on the action provided */
|
|
||||||
let main = (p: action, storage) => {
|
|
||||||
let storage =
|
let storage =
|
||||||
switch (p) {
|
switch (p) {
|
||||||
| Increment(n) => add(storage, n)
|
| Increment(n) => add(storage, n)
|
||||||
| Decrement(n) => subtract(storage, n)
|
| Decrement(n) => sub(storage, n)
|
||||||
};
|
};
|
||||||
([]: list(operation), storage);
|
([]: list(operation), storage);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let main = (x: (action, storage)) => main2(x[0],x[1]);
|
||||||
|
|
||||||
${pre}`;
|
${pre}`;
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,6 +138,57 @@ let compile_file =
|
|||||||
let doc = "Subcommand: compile a contract." in
|
let doc = "Subcommand: compile a contract." in
|
||||||
(Term.ret term , Term.info ~doc cmdname)
|
(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 measure_contract =
|
||||||
let f source_file entry_point syntax display_format =
|
let f source_file entry_point syntax display_format =
|
||||||
toplevel ~display_format @@
|
toplevel ~display_format @@
|
||||||
@ -371,4 +422,8 @@ let run ?argv () =
|
|||||||
run_function ;
|
run_function ;
|
||||||
evaluate_value ;
|
evaluate_value ;
|
||||||
dump_changelog ;
|
dump_changelog ;
|
||||||
|
print_cst ;
|
||||||
|
print_ast ;
|
||||||
|
print_typed_ast ;
|
||||||
|
print_mini_c
|
||||||
]
|
]
|
||||||
|
@ -47,6 +47,22 @@ let%expect_test _ =
|
|||||||
measure-contract
|
measure-contract
|
||||||
Subcommand: measure a contract's compiled size in bytes.
|
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
|
run-function
|
||||||
Subcommand: run a function with the given parameter.
|
Subcommand: run a function with the given parameter.
|
||||||
|
|
||||||
@ -104,6 +120,22 @@ let%expect_test _ =
|
|||||||
measure-contract
|
measure-contract
|
||||||
Subcommand: measure a contract's compiled size in bytes.
|
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
|
run-function
|
||||||
Subcommand: run a function with the given parameter.
|
Subcommand: run a function with the given parameter.
|
||||||
|
|
||||||
|
@ -133,3 +133,41 @@ let parsify_string = fun (syntax : v_syntax) source_filename ->
|
|||||||
let%bind parsified = parsify source_filename in
|
let%bind parsified = parsify source_filename in
|
||||||
let%bind applied = Self_ast_simplified.all_program parsified in
|
let%bind applied = Self_ast_simplified.all_program parsified in
|
||||||
ok applied
|
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
|
@ -32,3 +32,6 @@ let aggregate_and_compile_contract = fun (program : Types.program) name ->
|
|||||||
|
|
||||||
let aggregate_and_compile_expression = fun program exp ->
|
let aggregate_and_compile_expression = fun program exp ->
|
||||||
aggregate_and_compile program (ExpressionForm exp)
|
aggregate_and_compile program (ExpressionForm exp)
|
||||||
|
|
||||||
|
let pretty_print program =
|
||||||
|
Mini_c.PP.program program
|
@ -18,3 +18,6 @@ let apply (entry_point : string) (param : Ast_simplified.expression) : Ast_simpl
|
|||||||
{ expression = Ast_simplified.E_application (entry_point_var, param) ;
|
{ expression = Ast_simplified.E_application (entry_point_var, param) ;
|
||||||
location = Virtual "generated application" } in
|
location = Virtual "generated application" } in
|
||||||
ok applied
|
ok applied
|
||||||
|
|
||||||
|
let pretty_print formatter (program : Ast_simplified.program) =
|
||||||
|
Ast_simplified.PP.program formatter program
|
@ -18,3 +18,6 @@ let compile_contract_input : string -> string -> v_syntax -> Ast_simplified.expr
|
|||||||
fun storage parameter syntax ->
|
fun storage parameter syntax ->
|
||||||
let%bind (storage,parameter) = bind_map_pair (compile_expression syntax) (storage,parameter) in
|
let%bind (storage,parameter) = bind_map_pair (compile_expression syntax) (storage,parameter) in
|
||||||
ok @@ Ast_simplified.e_pair storage parameter
|
ok @@ Ast_simplified.e_pair storage parameter
|
||||||
|
|
||||||
|
let pretty_print source_filename syntax =
|
||||||
|
Helpers.pretty_print syntax source_filename
|
@ -22,3 +22,6 @@ let assert_equal_contract_type : check_type -> string -> Ast_typed.program -> As
|
|||||||
| _ -> dummy_fail
|
| _ -> dummy_fail
|
||||||
)
|
)
|
||||||
| _ -> dummy_fail )
|
| _ -> dummy_fail )
|
||||||
|
|
||||||
|
let pretty_print ppf program =
|
||||||
|
Ast_typed.PP.program ppf program
|
@ -1,3 +1,5 @@
|
|||||||
|
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)
|
||||||
|
|
||||||
type storage = int
|
type storage = int
|
||||||
|
|
||||||
(* variant defining pseudo multi-entrypoint actions *)
|
(* 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 *)
|
(* 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 =
|
let storage =
|
||||||
match ps.0 with
|
match p with
|
||||||
| Increment n -> add ps.1 n
|
| Increment n -> add s n
|
||||||
| Decrement n -> sub ps.1 n
|
| Decrement n -> sub s n
|
||||||
in ([] : operation list), storage
|
in ([] : operation list), storage
|
||||||
|
|
||||||
|
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)
|
||||||
|
|
||||||
type storage = int;
|
type storage = int;
|
||||||
|
|
||||||
/* variant defining pseudo multi-entrypoint actions */
|
/* 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]);
|
let main = (x: (action, storage)) => main2(x[0],x[1]);
|
||||||
|
|
||||||
|
(* IF YOU CHANGE THIS, CHANGE THE EXAMPLE ON THE FRONT PAGE OF THE WEBSITE *)
|
||||||
|
Loading…
Reference in New Issue
Block a user