From 0f53d0313912b56be77b267f98daa2569ebb37ea Mon Sep 17 00:00:00 2001 From: Tohava Date: Thu, 5 Aug 2010 03:44:29 +0300 Subject: [PATCH 1/4] Added AST logging, and modified AST for consistent handling of alt stmts. - Modified the arm types, instead of a single arm type, there are now 2 (soon to be 3) arm types, one for each type of alt statement - Added AST logging for constrained type (see fmt_constrained) - Added AST logging for STMT_alt_type - Created a generic fmt_arm for use with all alt statements --- src/boot/fe/ast.ml | 75 ++++++++++++++++++++++++++++++++++----------- src/boot/me/dead.ml | 3 +- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index 651b1e653d7..d4ace045439 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -247,13 +247,13 @@ and stmt = stmt' identified and stmt_alt_tag = { alt_tag_lval: lval; - alt_tag_arms: arm array; + alt_tag_arms: tag_arm array; } and stmt_alt_type = { alt_type_lval: lval; - alt_type_arms: (ident * slot * stmt) array; + alt_type_arms: type_arm array; alt_type_else: stmt option; } @@ -318,8 +318,11 @@ and pat = | PAT_slot of ((slot identified) * ident) | PAT_wild -and arm' = pat * block -and arm = arm' identified +and tag_arm' = pat * block +and tag_arm = tag_arm' identified + +and type_arm' = ident * slot * block +and type_arm = type_arm' identified and atom = ATOM_literal of (lit identified) @@ -646,6 +649,16 @@ and fmt_iso (ff:Format.formatter) (tiso:ty_iso) : unit = done; fmt ff "@]]@]" +and fmt_constrained ff (ty, constrs) : unit = + fmt ff "@["; + fmt_ty ff ty; + fmt ff " : "; + fmt ff "@["; + fmt_constrs ff constrs; + fmt ff "@]"; + fmt ff "@]"; + + and fmt_ty (ff:Format.formatter) (t:ty) : unit = match t with TY_any -> fmt ff "any" @@ -687,7 +700,7 @@ and fmt_ty (ff:Format.formatter) (t:ty) : unit = | TY_tag ttag -> fmt_tag ff ttag | TY_iso tiso -> fmt_iso ff tiso | TY_idx idx -> fmt ff "" idx - | TY_constrained _ -> fmt ff "?constrained?" + | TY_constrained ctrd -> fmt_constrained ff ctrd | TY_obj (effect, fns) -> fmt_obox ff; @@ -707,7 +720,13 @@ and fmt_ty (ff:Format.formatter) (t:ty) : unit = and fmt_constrs (ff:Format.formatter) (cc:constr array) : unit = - Array.iter (fmt_constr ff) cc + for i = 0 to (Array.length cc) - 1 + do + if i != 0 + then fmt ff ",@ "; + fmt_constr ff cc.(i) + done; + (* Array.iter (fmt_constr ff) cc *) and fmt_decl_constrs (ff:Format.formatter) (cc:constr array) : unit = if Array.length cc = 0 @@ -1204,25 +1223,45 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit = fmt_lval ff at.alt_tag_lval; fmt ff ") "; fmt_obr ff; - Array.iter (fmt_arm ff) at.alt_tag_arms; + Array.iter (fmt_tag_arm ff) at.alt_tag_arms; fmt_cbb ff; - | STMT_alt_type _ -> fmt ff "?stmt_alt_type?" + | STMT_alt_type at -> + fmt_obox ff; + fmt ff "alt type ("; + fmt_lval ff at.alt_type_lval; + fmt ff ") "; + fmt_obr ff; + Array.iter (fmt_type_arm ff) at.alt_type_arms; + fmt_cbb ff; + | STMT_alt_port _ -> fmt ff "?stmt_alt_port?" | STMT_note _ -> fmt ff "?stmt_note?" | STMT_slice _ -> fmt ff "?stmt_slice?" end -and fmt_arm (ff:Format.formatter) (arm:arm) : unit = - let (pat, block) = arm.node in - fmt ff "@\n"; - fmt_obox ff; - fmt ff "case ("; - fmt_pat ff pat; - fmt ff ") "; - fmt_obr ff; - fmt_stmts ff block.node; - fmt_cbb ff; +and fmt_arm + (ff:Format.formatter) + (fmt_arm_case_expr : Format.formatter -> unit) + (block : block) + : unit = + fmt ff "@\n"; + fmt_obox ff; + fmt ff "case ("; + fmt_arm_case_expr ff; + fmt ff ") "; + fmt_obr ff; + fmt_stmts ff block.node; + fmt_cbb ff; + +and fmt_tag_arm (ff:Format.formatter) (tag_arm:tag_arm) : unit = + let (pat, block) = tag_arm.node in + fmt_arm ff (fun ff -> fmt_pat ff pat) block; + +and fmt_type_arm (ff:Format.formatter) (type_arm:type_arm) : unit = + let (_, slot, block) = type_arm.node in + fmt_arm ff (fun ff -> fmt_slot ff slot) block; + and fmt_pat (ff:Format.formatter) (pat:pat) : unit = match pat with diff --git a/src/boot/me/dead.ml b/src/boot/me/dead.ml index 61aa846a50c..7ef4bf8e3e3 100644 --- a/src/boot/me/dead.ml +++ b/src/boot/me/dead.ml @@ -70,7 +70,8 @@ let dead_code_visitor | Ast.STMT_alt_type { Ast.alt_type_arms = arms; Ast.alt_type_else = alt_type_else } -> - let arm_ids = Array.map (fun (_, _, block) -> block.id) arms in + let arm_ids = Array.map (fun { node = (_, _, block) } -> + block.id) arms in let else_ids = begin match alt_type_else with From 4bc173fd3c66bb5b072b6452df8cb383b789c464 Mon Sep 17 00:00:00 2001 From: Tohava Date: Fri, 6 Aug 2010 16:11:15 +0300 Subject: [PATCH 2/4] Added AST pretty printing for slice expression --- src/boot/fe/ast.ml | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index d4ace045439..9cad5ce539e 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -1237,7 +1237,13 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit = | STMT_alt_port _ -> fmt ff "?stmt_alt_port?" | STMT_note _ -> fmt ff "?stmt_note?" - | STMT_slice _ -> fmt ff "?stmt_slice?" + | STMT_slice (dst, src, slice) -> + fmt_lval ff dst; + fmt ff " = "; + fmt_lval ff src; + fmt ff "."; + fmt_slice ff slice; + fmt ff ";"; end and fmt_arm @@ -1275,6 +1281,27 @@ and fmt_pat (ff:Format.formatter) (pat:pat) : unit = | PAT_wild -> fmt ff "_" +and fmt_slice (ff:Format.formatter) (slice:slice) : unit = + let fmt_slice_start = (match slice.slice_start with + None -> (fun ff -> fmt ff "0") + | Some atom -> (fun ff -> fmt_atom ff atom)) in + fmt ff "(@["; + fmt_slice_start ff; + begin + match slice.slice_len with + None -> fmt ff "," + | Some slice_len -> + fmt ff ",@ @["; + fmt_slice_start ff; + fmt ff " +@ "; + fmt_atom ff slice_len; + fmt ff "@]"; + end; + fmt ff "@])"; + + + + and fmt_decl_param (ff:Format.formatter) (param:ty_param) : unit = let (ident, (i, e)) = param in fmt_effect ff e; From 7d38caf9c38b15bbf110893e73df6d92b1457d5c Mon Sep 17 00:00:00 2001 From: Tohava Date: Fri, 6 Aug 2010 17:15:55 +0300 Subject: [PATCH 3/4] Added forgotten handling for alt_type_else, and also for stmt_note --- src/boot/fe/ast.ml | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index 9cad5ce539e..efbd62ae202 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -254,7 +254,14 @@ and stmt_alt_type = { alt_type_lval: lval; alt_type_arms: type_arm array; - alt_type_else: stmt option; + alt_type_else: block option; + } + +and stmt_alt_port = + { + (* else lval is a timeout value. *) + alt_port_arms: (lval * lval) array; + alt_port_else: (lval * block) option; } and block' = stmt array @@ -264,12 +271,6 @@ and stmt_decl = DECL_mod_item of (ident * mod_item) | DECL_slot of (slot_key * (slot identified)) -and stmt_alt_port = - { - (* else lval is a timeout value. *) - alt_port_arms: (lval * lval) array; - alt_port_else: (lval * stmt) option; - } and stmt_while = { @@ -1233,10 +1234,25 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit = fmt ff ") "; fmt_obr ff; Array.iter (fmt_type_arm ff) at.alt_type_arms; + begin + match at.alt_type_else with + None -> () + | Some block -> + fmt ff "@\n"; + fmt_obox ff; + fmt ff "case (_) "; + fmt_obr ff; + fmt_stmts ff block.node; + fmt_cbb ff; + end; fmt_cbb ff; - | STMT_alt_port _ -> fmt ff "?stmt_alt_port?" - | STMT_note _ -> fmt ff "?stmt_note?" + | STMT_note at -> + begin + fmt ff "note "; + fmt_atom ff at; + fmt ff ";" + end | STMT_slice (dst, src, slice) -> fmt_lval ff dst; fmt ff " = "; @@ -1245,7 +1261,7 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit = fmt_slice ff slice; fmt ff ";"; end - + and fmt_arm (ff:Format.formatter) (fmt_arm_case_expr : Format.formatter -> unit) From b1c86beea8a79e0b101596ea65f90b1b7e70bd64 Mon Sep 17 00:00:00 2001 From: Or Brostovski Date: Sat, 7 Aug 2010 13:36:35 +0300 Subject: [PATCH 4/4] Added AST pretty printing for communication alt statement, closes issue 19. --- src/boot/fe/ast.ml | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/src/boot/fe/ast.ml b/src/boot/fe/ast.ml index efbd62ae202..6cd1114aaa2 100644 --- a/src/boot/fe/ast.ml +++ b/src/boot/fe/ast.ml @@ -260,8 +260,8 @@ and stmt_alt_type = and stmt_alt_port = { (* else lval is a timeout value. *) - alt_port_arms: (lval * lval) array; - alt_port_else: (lval * block) option; + alt_port_arms: port_arm array; + alt_port_else: (atom * block) option; } and block' = stmt array @@ -325,6 +325,13 @@ and tag_arm = tag_arm' identified and type_arm' = ident * slot * block and type_arm = type_arm' identified +and port_arm' = port_case * block +and port_arm = port_arm' identified + +and port_case = + PORT_CASE_send of (lval * lval) + | PORT_CASE_recv of (lval * lval) + and atom = ATOM_literal of (lit identified) | ATOM_lval of lval @@ -495,7 +502,6 @@ let sane_name (n:name) : bool = (***********************************************************************) -(* FIXME (issue #19): finish all parts with ?foo? as their output. *) let fmt_ident (ff:Format.formatter) (i:ident) : unit = fmt ff "%s" i @@ -1246,7 +1252,25 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit = fmt_cbb ff; end; fmt_cbb ff; - | STMT_alt_port _ -> fmt ff "?stmt_alt_port?" + | STMT_alt_port at -> + fmt_obox ff; + fmt ff "alt "; + fmt_obr ff; + Array.iter (fmt_port_arm ff) at.alt_port_arms; + begin + match at.alt_port_else with + None -> () + | Some (timeout, block) -> + fmt ff "@\n"; + fmt_obox ff; + fmt ff "case (_) "; + fmt_atom ff timeout; + fmt ff " "; + fmt_obr ff; + fmt_stmts ff block.node; + fmt_cbb ff; + end; + fmt_cbb ff; | STMT_note at -> begin fmt ff "note "; @@ -1284,6 +1308,16 @@ and fmt_type_arm (ff:Format.formatter) (type_arm:type_arm) : unit = let (_, slot, block) = type_arm.node in fmt_arm ff (fun ff -> fmt_slot ff slot) block; +and fmt_port_arm (ff:Format.formatter) (port_arm:port_arm) : unit = + let (port_case, block) = port_arm.node in + fmt_arm ff (fun ff -> fmt_port_case ff port_case) block; + +and fmt_port_case (ff:Format.formatter) (port_case:port_case) : unit = + let stmt' = match port_case with + PORT_CASE_send params -> STMT_send params + | PORT_CASE_recv params -> STMT_recv params in + fmt_stmt ff {node = stmt'; id = Node 0}; + and fmt_pat (ff:Format.formatter) (pat:pat) : unit = match pat with