summaryrefslogtreecommitdiff
path: root/src/mono_util.sml
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adamc@hcoop.net>2008-11-25 10:05:44 -0500
committerGravatar Adam Chlipala <adamc@hcoop.net>2008-11-25 10:05:44 -0500
commit940865b04fa534983982b261386a3b1926bd5531 (patch)
treefc3097de1fda1a8cf47dbbeaddc9dc1df9ba6035 /src/mono_util.sml
parent261ebaa5168b307ad38825c95d60c5bea5d9858f (diff)
Fusing writes with recursive function calls
Diffstat (limited to 'src/mono_util.sml')
-rw-r--r--src/mono_util.sml21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/mono_util.sml b/src/mono_util.sml
index 14ab1674..2b2476e7 100644
--- a/src/mono_util.sml
+++ b/src/mono_util.sml
@@ -422,6 +422,13 @@ fun fold {typ, exp, decl} s d =
S.Continue (_, s) => s
| S.Return _ => raise Fail "MonoUtil.Decl.fold: Impossible"
+fun map {typ, exp, decl} e =
+ case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
+ exp = fn e => fn () => S.Continue (exp e, ()),
+ decl = fn d => fn () => S.Continue (decl d, ())} e () of
+ S.Return () => raise Fail "MonoUtil.Decl.map: Impossible"
+ | S.Continue (e, ()) => e
+
end
structure File = struct
@@ -490,7 +497,7 @@ fun map {typ, exp, decl} e =
case mapfold {typ = fn c => fn () => S.Continue (typ c, ()),
exp = fn e => fn () => S.Continue (exp e, ()),
decl = fn d => fn () => S.Continue (decl d, ())} e () of
- S.Return () => raise Fail "Mono_util.File.map"
+ S.Return () => raise Fail "MonoUtil.File.map: Impossible"
| S.Continue (e, ()) => e
fun fold {typ, exp, decl} s d =
@@ -500,6 +507,18 @@ fun fold {typ, exp, decl} s d =
S.Continue (_, s) => s
| S.Return _ => raise Fail "MonoUtil.File.fold: Impossible"
+val maxName = foldl (fn ((d, _) : decl, count) =>
+ case d of
+ DDatatype (_, n, ns) =>
+ foldl (fn ((_, n', _), m) => Int.max (n', m))
+ (Int.max (n, count)) ns
+ | DVal (_, n, _, _, _) => Int.max (n, count)
+ | DValRec vis => foldl (fn ((_, n, _, _, _), count) => Int.max (n, count)) count vis
+ | DExport _ => count
+ | DTable _ => count
+ | DSequence _ => count
+ | DDatabase _ => count) 0
+
end
end