Skip to content

Commit b1c86be

Browse files
committed
Added AST pretty printing for communication alt statement, closes issue 19.
1 parent 7d38caf commit b1c86be

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/boot/fe/ast.ml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ and stmt_alt_type =
260260
and stmt_alt_port =
261261
{
262262
(* else lval is a timeout value. *)
263-
alt_port_arms: (lval * lval) array;
264-
alt_port_else: (lval * block) option;
263+
alt_port_arms: port_arm array;
264+
alt_port_else: (atom * block) option;
265265
}
266266

267267
and block' = stmt array
@@ -325,6 +325,13 @@ and tag_arm = tag_arm' identified
325325
and type_arm' = ident * slot * block
326326
and type_arm = type_arm' identified
327327

328+
and port_arm' = port_case * block
329+
and port_arm = port_arm' identified
330+
331+
and port_case =
332+
PORT_CASE_send of (lval * lval)
333+
| PORT_CASE_recv of (lval * lval)
334+
328335
and atom =
329336
ATOM_literal of (lit identified)
330337
| ATOM_lval of lval
@@ -495,7 +502,6 @@ let sane_name (n:name) : bool =
495502

496503
(***********************************************************************)
497504

498-
(* FIXME (issue #19): finish all parts with ?foo? as their output. *)
499505

500506
let fmt_ident (ff:Format.formatter) (i:ident) : unit =
501507
fmt ff "%s" i
@@ -1246,7 +1252,25 @@ and fmt_stmt_body (ff:Format.formatter) (s:stmt) : unit =
12461252
fmt_cbb ff;
12471253
end;
12481254
fmt_cbb ff;
1249-
| STMT_alt_port _ -> fmt ff "?stmt_alt_port?"
1255+
| STMT_alt_port at ->
1256+
fmt_obox ff;
1257+
fmt ff "alt ";
1258+
fmt_obr ff;
1259+
Array.iter (fmt_port_arm ff) at.alt_port_arms;
1260+
begin
1261+
match at.alt_port_else with
1262+
None -> ()
1263+
| Some (timeout, block) ->
1264+
fmt ff "@\n";
1265+
fmt_obox ff;
1266+
fmt ff "case (_) ";
1267+
fmt_atom ff timeout;
1268+
fmt ff " ";
1269+
fmt_obr ff;
1270+
fmt_stmts ff block.node;
1271+
fmt_cbb ff;
1272+
end;
1273+
fmt_cbb ff;
12501274
| STMT_note at ->
12511275
begin
12521276
fmt ff "note ";
@@ -1284,6 +1308,16 @@ and fmt_type_arm (ff:Format.formatter) (type_arm:type_arm) : unit =
12841308
let (_, slot, block) = type_arm.node in
12851309
fmt_arm ff (fun ff -> fmt_slot ff slot) block;
12861310

1311+
and fmt_port_arm (ff:Format.formatter) (port_arm:port_arm) : unit =
1312+
let (port_case, block) = port_arm.node in
1313+
fmt_arm ff (fun ff -> fmt_port_case ff port_case) block;
1314+
1315+
and fmt_port_case (ff:Format.formatter) (port_case:port_case) : unit =
1316+
let stmt' = match port_case with
1317+
PORT_CASE_send params -> STMT_send params
1318+
| PORT_CASE_recv params -> STMT_recv params in
1319+
fmt_stmt ff {node = stmt'; id = Node 0};
1320+
12871321

12881322
and fmt_pat (ff:Format.formatter) (pat:pat) : unit =
12891323
match pat with

0 commit comments

Comments
 (0)