From 8c12a0ea31c49225df29bb1ad067a05dd7328e29 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Mon, 14 Oct 2019 17:45:52 +0200 Subject: [PATCH 1/8] git ingore .vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 682093b54..cf5ed1f94 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ Version.ml /_opam/ /*.pp.ligo **/.DS_Store +.vscode/ \ No newline at end of file From 8997155a5731ced219c70b2eb528a2251d4f9649 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 17 Oct 2019 20:50:41 -0700 Subject: [PATCH 2/8] Rough draft of single-expr function syntax --- src/passes/1-parser/pascaligo/LexToken.mli | 1 + src/passes/1-parser/pascaligo/LexToken.mll | 5 +++++ src/passes/1-parser/pascaligo/Parser.mly | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/src/passes/1-parser/pascaligo/LexToken.mli b/src/passes/1-parser/pascaligo/LexToken.mli index 1f94e166f..d1709f5a8 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mli +++ b/src/passes/1-parser/pascaligo/LexToken.mli @@ -80,6 +80,7 @@ type t = | Down of Region.t (* "down" *) | Else of Region.t (* "else" *) | End of Region.t (* "end" *) +| Expr of Region.t (* "expr" *) | Fail of Region.t (* "fail" *) | For of Region.t (* "for" *) | From of Region.t (* "from" *) diff --git a/src/passes/1-parser/pascaligo/LexToken.mll b/src/passes/1-parser/pascaligo/LexToken.mll index c27abbb12..4ef7b612b 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mll +++ b/src/passes/1-parser/pascaligo/LexToken.mll @@ -78,6 +78,7 @@ type t = | Down of Region.t (* "down" *) | Else of Region.t (* "else" *) | End of Region.t (* "end" *) +| Expr of Region.t (* "expr" *) | Fail of Region.t (* "fail" *) | For of Region.t (* "for" *) | From of Region.t (* "from" *) @@ -210,6 +211,7 @@ let proj_token = function | Down region -> region, "Down" | Else region -> region, "Else" | End region -> region, "End" +| Expr region -> region, "Expr" | Fail region -> region, "Fail" | For region -> region, "For" | From region -> region, "From" @@ -303,6 +305,7 @@ let to_lexeme = function | Down _ -> "down" | Else _ -> "else" | End _ -> "end" +| Expr _ -> "expr" | Fail _ -> "fail" | For _ -> "for" | From _ -> "from" @@ -364,6 +367,7 @@ let keywords = [ (fun reg -> Down reg); (fun reg -> Else reg); (fun reg -> End reg); + (fun reg -> Expr reg); (fun reg -> For reg); (fun reg -> From reg); (fun reg -> Function reg); @@ -588,6 +592,7 @@ let is_kwd = function | Down _ | Else _ | End _ +| Expr _ | Fail _ | For _ | From _ diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index bd9f63174..6c367e186 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -264,6 +264,25 @@ fun_decl: return = $10; terminator = $11} in {region; value}} + | Function fun_name parameters COLON type_expr Is + Expr expr option(SEMI) { + let stop = + match $9 with + Some region -> region + | None -> expr_to_region $8 in + let region = cover $1 stop + and value = { + kwd_function = $1; + name = $2; + param = $3; + colon = $4; + ret_type = $5; + kwd_is = $6; + kwd_expr = $7; + expr = $8; + terminator = $9; + } + in {region; value}} parameters: par(nsepseq(param_decl,SEMI)) { $1 } From 35a59a086708848dd9f63e4cb071168f5704bc9a Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 17 Oct 2019 21:33:45 -0700 Subject: [PATCH 3/8] Add parser tokens, guru meditation on why the AST types don't work --- src/passes/1-parser/pascaligo/AST.ml | 37 ++++++++++++++-------- src/passes/1-parser/pascaligo/AST.mli | 37 ++++++++++++++-------- src/passes/1-parser/pascaligo/ParToken.mly | 1 + src/passes/1-parser/pascaligo/Parser.mly | 6 ++-- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index 36cbdf637..f6c4aa26d 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -49,6 +49,7 @@ type kwd_contains = Region.t type kwd_down = Region.t type kwd_else = Region.t type kwd_end = Region.t +type kwd_expr = Region.t type kwd_for = Region.t type kwd_from = Region.t type kwd_function = Region.t @@ -210,19 +211,29 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function and procedure declarations *) -and fun_decl = { - kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - local_decls : local_decl list; - block : block reg; - kwd_with : kwd_with; - return : expr; - terminator : semi option -} +and fun_decl = + BlockFun of { + kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + local_decls : local_decl list; + block : block reg; + kwd_with : kwd_with; + return : expr; + terminator : semi option } + | BlocklessFun of + { kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + kwd_expr : kwd_expr; + return : expr; + terminator : semi option } and parameters = (param_decl, semi) nsepseq par reg diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index e18903f55..1e3719845 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -33,6 +33,7 @@ type kwd_contains = Region.t type kwd_down = Region.t type kwd_else = Region.t type kwd_end = Region.t +type kwd_expr = Region.t type kwd_for = Region.t type kwd_from = Region.t type kwd_function = Region.t @@ -201,19 +202,29 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function declarations *) -and fun_decl = { - kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - local_decls : local_decl list; - block : block reg; - kwd_with : kwd_with; - return : expr; - terminator : semi option -} +and fun_decl = + BlockFun of { + kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + local_decls : local_decl list; + block : block reg; + kwd_with : kwd_with; + return : expr; + terminator : semi option } + | BlocklessFun of + { kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + kwd_expr : kwd_expr; + return : expr; + terminator : semi option } and parameters = (param_decl, semi) nsepseq par reg diff --git a/src/passes/1-parser/pascaligo/ParToken.mly b/src/passes/1-parser/pascaligo/ParToken.mly index c236def9e..c5372008e 100644 --- a/src/passes/1-parser/pascaligo/ParToken.mly +++ b/src/passes/1-parser/pascaligo/ParToken.mly @@ -53,6 +53,7 @@ %token Contains (* "contains" *) %token Else (* "else" *) %token End (* "end" *) +%token Expr (* "expr" *) %token For (* "for" *) %token Function (* "function" *) %token From (* "from" *) diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index 6c367e186..fc4456c40 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -263,7 +263,7 @@ fun_decl: kwd_with = $9; return = $10; terminator = $11} - in {region; value}} + in BlockFun {region; value}} | Function fun_name parameters COLON type_expr Is Expr expr option(SEMI) { let stop = @@ -279,10 +279,10 @@ fun_decl: ret_type = $5; kwd_is = $6; kwd_expr = $7; - expr = $8; + return = $8; terminator = $9; } - in {region; value}} + in BlocklessFun {region; value}} parameters: par(nsepseq(param_decl,SEMI)) { $1 } From 2bffba379d9339ca3788de1d4dc73cef1982d58d Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Thu, 17 Oct 2019 22:34:38 -0700 Subject: [PATCH 4/8] Remove anonymous records --- src/passes/1-parser/pascaligo/AST.ml | 26 +++++++++++++++----------- src/passes/1-parser/pascaligo/AST.mli | 26 +++++++++++++++----------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index f6c4aa26d..79ecbc000 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -212,7 +212,10 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function and procedure declarations *) and fun_decl = - BlockFun of { + BlockFun of block_fun reg + | BlocklessFun of blockless_fun reg + +and block_fun = { kwd_function : kwd_function; name : variable; param : parameters; @@ -224,16 +227,17 @@ and fun_decl = kwd_with : kwd_with; return : expr; terminator : semi option } - | BlocklessFun of - { kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - kwd_expr : kwd_expr; - return : expr; - terminator : semi option } + +and blockless_fun = { + kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + kwd_expr : kwd_expr; + return : expr; + terminator : semi option } and parameters = (param_decl, semi) nsepseq par reg diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index 1e3719845..3319ad331 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -203,7 +203,10 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function declarations *) and fun_decl = - BlockFun of { + BlockFun of block_fun reg + | BlocklessFun of blockless_fun reg + +and block_fun = { kwd_function : kwd_function; name : variable; param : parameters; @@ -215,16 +218,17 @@ and fun_decl = kwd_with : kwd_with; return : expr; terminator : semi option } - | BlocklessFun of - { kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - kwd_expr : kwd_expr; - return : expr; - terminator : semi option } + +and blockless_fun = { + kwd_function : kwd_function; + name : variable; + param : parameters; + colon : colon; + ret_type : type_expr; + kwd_is : kwd_is; + kwd_expr : kwd_expr; + return : expr; + terminator : semi option } and parameters = (param_decl, semi) nsepseq par reg From 6e0173a9a77c8840307a1b9cd77dda9d42dc7c82 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Fri, 18 Oct 2019 17:46:20 -0700 Subject: [PATCH 5/8] Fix type error when where blockfun types eat regions --- src/passes/1-parser/pascaligo/AST.ml | 4 ++-- src/passes/1-parser/pascaligo/AST.mli | 4 ++-- src/passes/1-parser/pascaligo/Parser.mly | 6 ++++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index 79ecbc000..6a2185480 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -212,8 +212,8 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function and procedure declarations *) and fun_decl = - BlockFun of block_fun reg - | BlocklessFun of blockless_fun reg + BlockFun of block_fun + | BlocklessFun of blockless_fun and block_fun = { kwd_function : kwd_function; diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index 3319ad331..2b16366eb 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -203,8 +203,8 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function declarations *) and fun_decl = - BlockFun of block_fun reg - | BlocklessFun of blockless_fun reg + BlockFun of block_fun + | BlocklessFun of blockless_fun and block_fun = { kwd_function : kwd_function; diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index fc4456c40..275ed353c 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -263,7 +263,8 @@ fun_decl: kwd_with = $9; return = $10; terminator = $11} - in BlockFun {region; value}} + in {region = region; + value = BlockFun value} } | Function fun_name parameters COLON type_expr Is Expr expr option(SEMI) { let stop = @@ -282,7 +283,8 @@ fun_decl: return = $8; terminator = $9; } - in BlocklessFun {region; value}} + in {region = region; + value = BlocklessFun value} } parameters: par(nsepseq(param_decl,SEMI)) { $1 } From ec67d37f20d122d02fe69f91c24fd2d4355708a0 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Sat, 19 Oct 2019 09:11:18 -0700 Subject: [PATCH 6/8] Gabriel wants to see the code --- src/passes/2-simplify/pascaligo.ml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index e9195e8a5..a234a6d33 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -544,7 +544,23 @@ and simpl_fun_declaration : loc:_ -> Raw.fun_decl -> ((name * type_expression option) * expression) result = fun ~loc x -> let open! Raw in - let {name;param;ret_type;local_decls;block;return} : fun_decl = x in + let (name, param, ret_type, return) = + match x with + | BlockFun f -> (f.name, f.param, f.ret_type, f.return) + | BlocklessFun f -> (f.name, f.param, f.ret_type, f.return) + in + let block = + match x with + | BlockFun f -> f.block + | BlocklessFun _ -> + {region = Region.ghost; + value = { + opening = Raw.keyword; + statements = [(Raw.kwd_skip * Raw.SEMI)]; + terminator = Some Raw.SEMI; + closing = Raw.kwd_end; + } + in (match param.value.inside with a, [] -> ( let%bind input = simpl_param a in From daad15c57dedb8f448eec1663ae4fe2d5f5f5ca3 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Sat, 19 Oct 2019 10:46:24 -0700 Subject: [PATCH 7/8] Write blockless function test and make it pass --- src/passes/1-parser/pascaligo/AST.ml | 23 ++-------- src/passes/1-parser/pascaligo/AST.mli | 23 ++-------- src/passes/1-parser/pascaligo/Parser.mly | 26 +++++------ src/passes/1-parser/pascaligo/ParserLog.ml | 51 ++++++++++++++-------- src/passes/2-simplify/pascaligo.ml | 28 +++++------- src/test/contracts/blockless.ligo | 2 + src/test/integration_tests.ml | 6 +++ 7 files changed, 73 insertions(+), 86 deletions(-) create mode 100644 src/test/contracts/blockless.ligo diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index 6a2185480..fa43bcffe 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -211,34 +211,19 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function and procedure declarations *) -and fun_decl = - BlockFun of block_fun - | BlocklessFun of blockless_fun - -and block_fun = { +and fun_decl = { kwd_function : kwd_function; name : variable; param : parameters; colon : colon; ret_type : type_expr; kwd_is : kwd_is; - local_decls : local_decl list; - block : block reg; - kwd_with : kwd_with; + local_decls : local_decl list option; + block : block reg option; + kwd_with : kwd_with option; return : expr; terminator : semi option } -and blockless_fun = { - kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - kwd_expr : kwd_expr; - return : expr; - terminator : semi option } - and parameters = (param_decl, semi) nsepseq par reg and param_decl = diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index 2b16366eb..9d2774834 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -202,34 +202,19 @@ and type_tuple = (type_expr, comma) nsepseq par reg (* Function declarations *) -and fun_decl = - BlockFun of block_fun - | BlocklessFun of blockless_fun - -and block_fun = { +and fun_decl ={ kwd_function : kwd_function; name : variable; param : parameters; colon : colon; ret_type : type_expr; kwd_is : kwd_is; - local_decls : local_decl list; - block : block reg; - kwd_with : kwd_with; + local_decls : local_decl list option; + block : block reg option; + kwd_with : kwd_with option; return : expr; terminator : semi option } -and blockless_fun = { - kwd_function : kwd_function; - name : variable; - param : parameters; - colon : colon; - ret_type : type_expr; - kwd_is : kwd_is; - kwd_expr : kwd_expr; - return : expr; - terminator : semi option } - and parameters = (param_decl, semi) nsepseq par reg and param_decl = diff --git a/src/passes/1-parser/pascaligo/Parser.mly b/src/passes/1-parser/pascaligo/Parser.mly index 275ed353c..8ef52087c 100644 --- a/src/passes/1-parser/pascaligo/Parser.mly +++ b/src/passes/1-parser/pascaligo/Parser.mly @@ -258,19 +258,18 @@ fun_decl: colon = $4; ret_type = $5; kwd_is = $6; - local_decls = $7; - block = $8; - kwd_with = $9; + local_decls = Some $7; + block = Some $8; + kwd_with = Some $9; return = $10; terminator = $11} - in {region = region; - value = BlockFun value} } + in {region;value}} | Function fun_name parameters COLON type_expr Is - Expr expr option(SEMI) { + expr option(SEMI) { let stop = - match $9 with + match $8 with Some region -> region - | None -> expr_to_region $8 in + | None -> expr_to_region $7 in let region = cover $1 stop and value = { kwd_function = $1; @@ -279,12 +278,13 @@ fun_decl: colon = $4; ret_type = $5; kwd_is = $6; - kwd_expr = $7; - return = $8; - terminator = $9; + local_decls = None; + block = None; + kwd_with = None; + return = $7; + terminator = $8; } - in {region = region; - value = BlocklessFun value} } + in {region;value}} parameters: par(nsepseq(param_decl,SEMI)) { $1 } diff --git a/src/passes/1-parser/pascaligo/ParserLog.ml b/src/passes/1-parser/pascaligo/ParserLog.ml index de4b683c2..77ea682f6 100644 --- a/src/passes/1-parser/pascaligo/ParserLog.ml +++ b/src/passes/1-parser/pascaligo/ParserLog.ml @@ -168,7 +168,10 @@ and print_fun_decl buffer {value; _} = print_token buffer kwd_is "is"; print_local_decls buffer local_decls; print_block buffer block; - print_token buffer kwd_with "with"; + match kwd_with with + | Some kwd_with -> + print_token buffer kwd_with "with"; + | None -> (); print_expr buffer return; print_terminator buffer terminator @@ -196,12 +199,16 @@ and print_param_var buffer {value; _} = print_token buffer colon ":"; print_type_expr buffer param_type -and print_block buffer {value; _} = - let {opening; statements; terminator; closing} = value in - print_block_opening buffer opening; - print_statements buffer statements; - print_terminator buffer terminator; - print_block_closing buffer closing +and print_block buffer reg = + match reg with + | Some reg -> + let value = reg.value in + let {opening; statements; terminator; closing} = value in + print_block_opening buffer opening; + print_statements buffer statements; + print_terminator buffer terminator; + print_block_closing buffer closing + | None -> () and print_block_opening buffer = function Block (kwd_block, lbrace) -> @@ -215,7 +222,10 @@ and print_block_closing buffer = function | End kwd_end -> print_token buffer kwd_end "end" and print_local_decls buffer sequence = - List.iter (print_local_decl buffer) sequence + match sequence with + | Some sequence -> + List.iter (print_local_decl buffer) sequence + | None -> () and print_local_decl buffer = function LocalFun decl -> print_fun_decl buffer decl @@ -272,9 +282,8 @@ and print_if_clause buffer = function | ClauseBlock block -> print_clause_block buffer block and print_clause_block buffer = function - LongBlock block -> - print_block buffer block -| ShortBlock {value; _} -> + LongBlock block -> print_block buffer (Some block) + | ShortBlock {value; _} -> let {lbrace; inside; rbrace} = value in let statements, terminator = inside in print_token buffer lbrace "{"; @@ -325,7 +334,7 @@ and print_while_loop buffer value = let {kwd_while; cond; block} = value in print_token buffer kwd_while "while"; print_expr buffer cond; - print_block buffer block + print_block buffer (Some block) and print_for_loop buffer = function ForInt for_int -> print_for_int buffer for_int @@ -337,7 +346,7 @@ and print_for_int buffer ({value; _} : for_int reg) = print_var_assign buffer assign; print_token buffer kwd_to "to"; print_expr buffer bound; - print_block buffer block + print_block buffer (Some block) and print_var_assign buffer {value; _} = let {name; assign; expr} = value in @@ -356,7 +365,7 @@ and print_for_collect buffer ({value; _} : for_collect reg) = print_token buffer kwd_in "in"; print_collection buffer collection; print_expr buffer expr; - print_block buffer block + print_block buffer (Some block) and print_collection buffer = function Map kwd_map -> @@ -845,7 +854,10 @@ and pp_fun_decl buffer ~pad:(_,pc) decl = let () = let pad = mk_pad 6 4 pc in pp_node buffer ~pad ""; - let statements = decl.block.value.statements in + let statements = + match decl.block with + | Some block -> block.value.statements + | None -> Instr (Skip Region.ghost), [] in pp_statements buffer ~pad statements in let () = let _, pc as pad = mk_pad 6 5 pc in @@ -1225,9 +1237,12 @@ and pp_set_remove buffer ~pad:(_,pc) rem = pp_path buffer ~pad:(mk_pad 2 1 pc) rem.set and pp_local_decls buffer ~pad:(_,pc) decls = - let apply len rank = - pp_local_decl buffer ~pad:(mk_pad len rank pc) - in List.iteri (List.length decls |> apply) decls + match decls with + | Some decls -> + let apply len rank = + pp_local_decl buffer ~pad:(mk_pad len rank pc) + in List.iteri (List.length decls |> apply) decls + | None -> () and pp_local_decl buffer ~pad:(_,pc as pad) = function LocalFun {value; _} -> diff --git a/src/passes/2-simplify/pascaligo.ml b/src/passes/2-simplify/pascaligo.ml index a234a6d33..22a54fc54 100644 --- a/src/passes/2-simplify/pascaligo.ml +++ b/src/passes/2-simplify/pascaligo.ml @@ -544,22 +544,16 @@ and simpl_fun_declaration : loc:_ -> Raw.fun_decl -> ((name * type_expression option) * expression) result = fun ~loc x -> let open! Raw in - let (name, param, ret_type, return) = - match x with - | BlockFun f -> (f.name, f.param, f.ret_type, f.return) - | BlocklessFun f -> (f.name, f.param, f.ret_type, f.return) + let {name;param;ret_type;local_decls;block;return} : fun_decl = x in + let local_decls = + match local_decls with + | Some local_decls -> local_decls + | None -> [] in - let block = - match x with - | BlockFun f -> f.block - | BlocklessFun _ -> - {region = Region.ghost; - value = { - opening = Raw.keyword; - statements = [(Raw.kwd_skip * Raw.SEMI)]; - terminator = Some Raw.SEMI; - closing = Raw.kwd_end; - } + let statements = + match block with + | Some block -> npseq_to_list block.value.statements + | None -> [] in (match param.value.inside with a, [] -> ( @@ -570,7 +564,7 @@ and simpl_fun_declaration : bind_map_list simpl_local_declaration local_decls in let%bind instructions = bind_list @@ List.map simpl_statement - @@ npseq_to_list block.value.statements in + @@ statements in let%bind result = simpl_expression return in let%bind output_type = simpl_type_expression ret_type in let body = local_declarations @ instructions in @@ -601,7 +595,7 @@ and simpl_fun_declaration : bind_map_list simpl_local_declaration local_decls in let%bind instructions = bind_list @@ List.map simpl_statement - @@ npseq_to_list block.value.statements in + @@ statements in let%bind result = simpl_expression return in let%bind output_type = simpl_type_expression ret_type in let body = tpl_declarations @ local_declarations @ instructions in diff --git a/src/test/contracts/blockless.ligo b/src/test/contracts/blockless.ligo new file mode 100644 index 000000000..103b926f0 --- /dev/null +++ b/src/test/contracts/blockless.ligo @@ -0,0 +1,2 @@ +function blockless (const n: int) : int is + n + 10; diff --git a/src/test/integration_tests.ml b/src/test/integration_tests.ml index 89e5ef967..49bfe3797 100644 --- a/src/test/integration_tests.ml +++ b/src/test/integration_tests.ml @@ -15,6 +15,11 @@ let function_ () : unit result = let make_expect = fun n -> n in expect_eq_n_int program "main" make_expect +let blockless () : unit result = + let%bind program = type_file "./contracts/blockless.ligo" in + let make_expect = fun n-> n + 10 in + expect_eq_n_int program "blockless" make_expect + (* Procedures are not supported yet let procedure () : unit result = let%bind program = type_file "./contracts/procedure.ligo" in @@ -894,6 +899,7 @@ let tez_mligo () : unit result = let main = test_suite "Integration (End to End)" [ test "type alias" type_alias ; test "function" function_ ; + test "blockless function" blockless; (* test "procedure" procedure ; *) test "assign" assign ; test "declaration local" declaration_local ; From 09230df60a09d35e552be686da7863734ce02386 Mon Sep 17 00:00:00 2001 From: John David Pressman Date: Sat, 19 Oct 2019 10:55:39 -0700 Subject: [PATCH 8/8] Remove kwd_expr --- src/passes/1-parser/pascaligo/AST.ml | 1 - src/passes/1-parser/pascaligo/AST.mli | 1 - src/passes/1-parser/pascaligo/LexToken.mli | 1 - src/passes/1-parser/pascaligo/LexToken.mll | 5 ----- src/passes/1-parser/pascaligo/ParToken.mly | 1 - 5 files changed, 9 deletions(-) diff --git a/src/passes/1-parser/pascaligo/AST.ml b/src/passes/1-parser/pascaligo/AST.ml index fa43bcffe..3867671da 100644 --- a/src/passes/1-parser/pascaligo/AST.ml +++ b/src/passes/1-parser/pascaligo/AST.ml @@ -49,7 +49,6 @@ type kwd_contains = Region.t type kwd_down = Region.t type kwd_else = Region.t type kwd_end = Region.t -type kwd_expr = Region.t type kwd_for = Region.t type kwd_from = Region.t type kwd_function = Region.t diff --git a/src/passes/1-parser/pascaligo/AST.mli b/src/passes/1-parser/pascaligo/AST.mli index 9d2774834..81c7ab94a 100644 --- a/src/passes/1-parser/pascaligo/AST.mli +++ b/src/passes/1-parser/pascaligo/AST.mli @@ -33,7 +33,6 @@ type kwd_contains = Region.t type kwd_down = Region.t type kwd_else = Region.t type kwd_end = Region.t -type kwd_expr = Region.t type kwd_for = Region.t type kwd_from = Region.t type kwd_function = Region.t diff --git a/src/passes/1-parser/pascaligo/LexToken.mli b/src/passes/1-parser/pascaligo/LexToken.mli index d1709f5a8..1f94e166f 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mli +++ b/src/passes/1-parser/pascaligo/LexToken.mli @@ -80,7 +80,6 @@ type t = | Down of Region.t (* "down" *) | Else of Region.t (* "else" *) | End of Region.t (* "end" *) -| Expr of Region.t (* "expr" *) | Fail of Region.t (* "fail" *) | For of Region.t (* "for" *) | From of Region.t (* "from" *) diff --git a/src/passes/1-parser/pascaligo/LexToken.mll b/src/passes/1-parser/pascaligo/LexToken.mll index 4ef7b612b..c27abbb12 100644 --- a/src/passes/1-parser/pascaligo/LexToken.mll +++ b/src/passes/1-parser/pascaligo/LexToken.mll @@ -78,7 +78,6 @@ type t = | Down of Region.t (* "down" *) | Else of Region.t (* "else" *) | End of Region.t (* "end" *) -| Expr of Region.t (* "expr" *) | Fail of Region.t (* "fail" *) | For of Region.t (* "for" *) | From of Region.t (* "from" *) @@ -211,7 +210,6 @@ let proj_token = function | Down region -> region, "Down" | Else region -> region, "Else" | End region -> region, "End" -| Expr region -> region, "Expr" | Fail region -> region, "Fail" | For region -> region, "For" | From region -> region, "From" @@ -305,7 +303,6 @@ let to_lexeme = function | Down _ -> "down" | Else _ -> "else" | End _ -> "end" -| Expr _ -> "expr" | Fail _ -> "fail" | For _ -> "for" | From _ -> "from" @@ -367,7 +364,6 @@ let keywords = [ (fun reg -> Down reg); (fun reg -> Else reg); (fun reg -> End reg); - (fun reg -> Expr reg); (fun reg -> For reg); (fun reg -> From reg); (fun reg -> Function reg); @@ -592,7 +588,6 @@ let is_kwd = function | Down _ | Else _ | End _ -| Expr _ | Fail _ | For _ | From _ diff --git a/src/passes/1-parser/pascaligo/ParToken.mly b/src/passes/1-parser/pascaligo/ParToken.mly index c5372008e..c236def9e 100644 --- a/src/passes/1-parser/pascaligo/ParToken.mly +++ b/src/passes/1-parser/pascaligo/ParToken.mly @@ -53,7 +53,6 @@ %token Contains (* "contains" *) %token Else (* "else" *) %token End (* "end" *) -%token Expr (* "expr" *) %token For (* "for" *) %token Function (* "function" *) %token From (* "from" *)