Skip to content

Commit 0f53d03

Browse files
author
Tohava
committed
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
1 parent ac4c5ae commit 0f53d03

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

src/boot/fe/ast.ml

Lines changed: 57 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ and stmt = stmt' identified
247247
and stmt_alt_tag =
248248
{
249249
alt_tag_lval: lval;
250-
alt_tag_arms: arm array;
250+
alt_tag_arms: tag_arm array;
251251
}
252252

253253
and stmt_alt_type =
254254
{
255255
alt_type_lval: lval;
256-
alt_type_arms: (ident * slot * stmt) array;
256+
alt_type_arms: type_arm array;
257257
alt_type_else: stmt option;
258258
}
259259

@@ -318,8 +318,11 @@ and pat =
318318
| PAT_slot of ((slot identified) * ident)
319319
| PAT_wild
320320

321-
and arm' = pat * block
322-
and arm = arm' identified
321+
and tag_arm' = pat * block
322+
and tag_arm = tag_arm' identified
323+
324+
and type_arm' = ident * slot * block
325+
and type_arm = type_arm' identified
323326

324327
and atom =
325328
ATOM_literal of (lit identified)
@@ -646,6 +649,16 @@ and fmt_iso (ff:Format.formatter) (tiso:ty_iso) : unit =
646649
done;
647650
fmt ff "@]]@]"
648651

652+
and fmt_constrained ff (ty, constrs) : unit =
653+
fmt ff "@[";
654+
fmt_ty ff ty;
655+
fmt ff " : ";
656+
fmt ff "@[";
657+
fmt_constrs ff constrs;
658+
fmt ff "@]";
659+
fmt ff "@]";
660+
661+
649662
and fmt_ty (ff:Format.formatter) (t:ty) : unit =
650663
match t with
651664
TY_any -> fmt ff "any"
@@ -687,7 +700,7 @@ and fmt_ty (ff:Format.formatter) (t:ty) : unit =
687700
| TY_tag ttag -> fmt_tag ff ttag
688701
| TY_iso tiso -> fmt_iso ff tiso
689702
| TY_idx idx -> fmt ff "<idx#%d>" idx
690-
| TY_constrained _ -> fmt ff "?constrained?"
703+
| TY_constrained ctrd -> fmt_constrained ff ctrd
691704

692705
| TY_obj (effect, fns) ->
693706
fmt_obox ff;
@@ -707,7 +720,13 @@ and fmt_ty (ff:Format.formatter) (t:ty) : unit =
707720

708721

709722
and fmt_constrs (ff:Format.formatter) (cc:constr array) : unit =
710-
Array.iter (fmt_constr ff) cc
723+
for i = 0 to (Array.length cc) - 1
724+
do
725+
if i != 0
726+
then fmt ff ",@ ";
727+
fmt_constr ff cc.(i)
728+
done;
729+
(* Array.iter (fmt_constr ff) cc *)
711730

712731
and fmt_decl_constrs (ff:Format.formatter) (cc:constr array) : unit =
713732
if Array.length cc = 0
@@ -1204,25 +1223,45 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
12041223
fmt_lval ff at.alt_tag_lval;
12051224
fmt ff ") ";
12061225
fmt_obr ff;
1207-
Array.iter (fmt_arm ff) at.alt_tag_arms;
1226+
Array.iter (fmt_tag_arm ff) at.alt_tag_arms;
12081227
fmt_cbb ff;
12091228

1210-
| STMT_alt_type _ -> fmt ff "?stmt_alt_type?"
1229+
| STMT_alt_type at ->
1230+
fmt_obox ff;
1231+
fmt ff "alt type (";
1232+
fmt_lval ff at.alt_type_lval;
1233+
fmt ff ") ";
1234+
fmt_obr ff;
1235+
Array.iter (fmt_type_arm ff) at.alt_type_arms;
1236+
fmt_cbb ff;
1237+
12111238
| STMT_alt_port _ -> fmt ff "?stmt_alt_port?"
12121239
| STMT_note _ -> fmt ff "?stmt_note?"
12131240
| STMT_slice _ -> fmt ff "?stmt_slice?"
12141241
end
12151242

1216-
and fmt_arm (ff:Format.formatter) (arm:arm) : unit =
1217-
let (pat, block) = arm.node in
1218-
fmt ff "@\n";
1219-
fmt_obox ff;
1220-
fmt ff "case (";
1221-
fmt_pat ff pat;
1222-
fmt ff ") ";
1223-
fmt_obr ff;
1224-
fmt_stmts ff block.node;
1225-
fmt_cbb ff;
1243+
and fmt_arm
1244+
(ff:Format.formatter)
1245+
(fmt_arm_case_expr : Format.formatter -> unit)
1246+
(block : block)
1247+
: unit =
1248+
fmt ff "@\n";
1249+
fmt_obox ff;
1250+
fmt ff "case (";
1251+
fmt_arm_case_expr ff;
1252+
fmt ff ") ";
1253+
fmt_obr ff;
1254+
fmt_stmts ff block.node;
1255+
fmt_cbb ff;
1256+
1257+
and fmt_tag_arm (ff:Format.formatter) (tag_arm:tag_arm) : unit =
1258+
let (pat, block) = tag_arm.node in
1259+
fmt_arm ff (fun ff -> fmt_pat ff pat) block;
1260+
1261+
and fmt_type_arm (ff:Format.formatter) (type_arm:type_arm) : unit =
1262+
let (_, slot, block) = type_arm.node in
1263+
fmt_arm ff (fun ff -> fmt_slot ff slot) block;
1264+
12261265

12271266
and fmt_pat (ff:Format.formatter) (pat:pat) : unit =
12281267
match pat with

src/boot/me/dead.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ let dead_code_visitor
7070

7171
| Ast.STMT_alt_type { Ast.alt_type_arms = arms;
7272
Ast.alt_type_else = alt_type_else } ->
73-
let arm_ids = Array.map (fun (_, _, block) -> block.id) arms in
73+
let arm_ids = Array.map (fun { node = (_, _, block) } ->
74+
block.id) arms in
7475
let else_ids =
7576
begin
7677
match alt_type_else with

0 commit comments

Comments
 (0)