diff options
Diffstat (limited to 'src/cjr_print.sml')
-rw-r--r-- | src/cjr_print.sml | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml index 2c2133d6..2471ce59 100644 --- a/src/cjr_print.sml +++ b/src/cjr_print.sml @@ -163,9 +163,7 @@ fun p_con_named env n = fun p_pat_preamble env (p, _) = case p of - PWild => (box [], - env) - | PVar (x, t) => (box [p_typ env t, + PVar (x, t) => (box [p_typ env t, space, string "__uwr_", p_ident x, @@ -194,8 +192,7 @@ fun p_patCon env pc = fun p_patMatch (env, disc) (p, loc) = case p of - PWild => string "1" - | PVar _ => string "1" + PVar _ => string "1" | PPrim (Prim.Int n) => box [string ("(" ^ disc), space, string "==", @@ -318,9 +315,7 @@ fun p_patMatch (env, disc) (p, loc) = fun p_patBind (env, disc) (p, loc) = case p of - PWild => - (box [], env) - | PVar (x, t) => + PVar (x, t) => (box [p_typ env t, space, string "__uwr_", @@ -2356,7 +2351,7 @@ fun p_fun isRec env (fx, n, args, ran, e) = val global_initializers : Print.PD.pp_desc list ref = ref [] -fun p_decl env (dAll as (d, _) : decl) = +fun p_decl env (dAll as (d, loc) : decl) = case d of DStruct (n, xts) => let @@ -2378,9 +2373,6 @@ fun p_decl env (dAll as (d, _) : decl) = end | DDatatype dts => let - val dts = ListMergeSort.sort (fn ((dk1, _, _, _), (dk2, _, _, _)) => - dk1 = Enum andalso dk2 <> Enum) dts - fun p_one (Enum, x, n, xncs) = box [string "enum", space, @@ -2605,6 +2597,23 @@ fun p_file env (ds, ps) = self := NONE; global_initializers := []) + (* First, pull out all of the enumerated types, to be declared first. *) + val (ds, enums) = ListUtil.foldlMapPartial (fn (d, enums) => + case #1 d of + DDatatype dts => + let + val (enum, other) = List.partition (fn (Enum, _, _, _) => true + | _ => false) dts + in + (SOME (DDatatype other, #2 d), + List.revAppend (enum, enums)) + end + | DDatatypeForward (Enum, _, _) => (NONE, enums) + | _ => (SOME d, enums)) + [] ds + + val ds = (DDatatype enums, ErrorMsg.dummySpan) :: ds + val (pds, env) = ListUtil.foldlMap (fn (d, env) => let val d' = p_decl env d |