summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2016-01-01 12:07:52 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2016-01-01 12:07:52 -0500
commitc748c02510ce84b457c2c7d288a67b686642bd0d (patch)
treee15f2132fa7534b43acff6188ae3fcccb90eafac
parentf5f93f6efc15ade5945e8572d889f22d198611b9 (diff)
Fix issue with enumerated types and dependency order
-rw-r--r--src/cjr_print.sml21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index 2c2133d6..ee7792a5 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -2356,7 +2356,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 +2378,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 +2602,22 @@ 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.foldlMap (fn (d, enums) =>
+ case #1 d of
+ DDatatype dts =>
+ let
+ val (enum, other) = List.partition (fn (Enum, _, _, _) => true
+ | _ => false) dts
+ in
+ ((DDatatype other, #2 d),
+ List.revAppend (enum, enums))
+ end
+ | _ => (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