summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core.sml1
-rw-r--r--src/core_env.sml1
-rw-r--r--src/core_print.sml52
-rw-r--r--src/core_util.sml24
-rw-r--r--src/corify.sml20
-rw-r--r--src/monoize.sml1
-rw-r--r--src/shake.sml3
-rw-r--r--src/tag.sml1
8 files changed, 75 insertions, 28 deletions
diff --git a/src/core.sml b/src/core.sml
index 69eafd33..448113cc 100644
--- a/src/core.sml
+++ b/src/core.sml
@@ -83,6 +83,7 @@ withtype exp = exp' located
datatype decl' =
DCon of string * int * kind * con
| DVal of string * int * con * exp * string
+ | DValRec of (string * int * con * exp * string) list
| DExport of int
withtype decl = decl' located
diff --git a/src/core_env.sml b/src/core_env.sml
index 5a24a82a..5c59d9a2 100644
--- a/src/core_env.sml
+++ b/src/core_env.sml
@@ -123,6 +123,7 @@ fun declBinds env (d, _) =
case d of
DCon (x, n, k, c) => pushCNamed env x n k (SOME c)
| DVal (x, n, t, e, s) => pushENamed env x n t (SOME e) s
+ | DValRec vis => foldl (fn ((x, n, t, e, s), env) => pushENamed env x n t (SOME e) s) env vis
| DExport _ => env
end
diff --git a/src/core_print.sml b/src/core_print.sml
index 60ad619f..3436d313 100644
--- a/src/core_print.sml
+++ b/src/core_print.sml
@@ -240,7 +240,31 @@ fun p_exp' par env (e, _) =
and p_exp env = p_exp' false env
-fun p_decl env ((d, _) : decl) =
+fun p_vali env (x, n, t, e, s) =
+ let
+ val xp = if !debug then
+ box [string x,
+ string "__",
+ string (Int.toString n)]
+ else
+ string x
+ in
+ box [xp,
+ space,
+ string "as",
+ space,
+ string s,
+ space,
+ string ":",
+ space,
+ p_con env t,
+ space,
+ string "=",
+ space,
+ p_exp env e]
+ end
+
+fun p_decl env (dAll as (d, _) : decl) =
case d of
DCon (x, n, k, c) =>
let
@@ -263,30 +287,18 @@ fun p_decl env ((d, _) : decl) =
space,
p_con env c]
end
- | DVal (x, n, t, e, s) =>
+ | DVal vi => box [string "val",
+ space,
+ p_vali env vi]
+ | DValRec vis =>
let
- val xp = if !debug then
- box [string x,
- string "__",
- string (Int.toString n)]
- else
- string x
+ val env = E.declBinds env dAll
in
box [string "val",
space,
- xp,
- space,
- string "as",
- space,
- string s,
- space,
- string ":",
- space,
- p_con env t,
- space,
- string "=",
+ string "rec",
space,
- p_exp env e]
+ p_list_sep (box [newline, string "and", space]) (p_vali env) vis]
end
| DExport n => box [string "export",
space,
diff --git a/src/core_util.sml b/src/core_util.sml
index 427a313d..db2fc9f9 100644
--- a/src/core_util.sml
+++ b/src/core_util.sml
@@ -380,13 +380,22 @@ fun mapfoldB {kind = fk, con = fc, exp = fe, decl = fd, bind} =
S.map2 (mfc ctx c,
fn c' =>
(DCon (x, n, k', c'), loc)))
- | DVal (x, n, t, e, s) =>
- S.bind2 (mfc ctx t,
- fn t' =>
- S.map2 (mfe ctx e,
- fn e' =>
- (DVal (x, n, t', e', s), loc)))
+ | DVal vi =>
+ S.map2 (mfvi ctx vi,
+ fn vi' =>
+ (DVal vi', loc))
+ | DValRec vis =>
+ S.map2 (ListUtil.mapfold (mfvi ctx) vis,
+ fn vis' =>
+ (DValRec vis', loc))
| DExport _ => S.return2 dAll
+
+ and mfvi ctx (x, n, t, e, s) =
+ S.bind2 (mfc ctx t,
+ fn t' =>
+ S.map2 (mfe ctx e,
+ fn e' =>
+ (x, n, t', e', s)))
in
mfd
end
@@ -435,6 +444,9 @@ fun mapfoldB (all as {bind, ...}) =
case #1 d' of
DCon (x, n, k, c) => bind (ctx, NamedC (x, n, k, SOME c))
| DVal (x, n, t, e, s) => bind (ctx, NamedE (x, n, t, SOME e, s))
+ | DValRec vis =>
+ foldl (fn ((x, n, t, e, s), ctx) => bind (ctx, NamedE (x, n, t, SOME e, s)))
+ ctx vis
| DExport _ => ctx
in
S.map2 (mff ctx' ds',
diff --git a/src/corify.sml b/src/corify.sml
index b17cad24..41b0e825 100644
--- a/src/corify.sml
+++ b/src/corify.sml
@@ -384,8 +384,24 @@ fun corifyDecl ((d, loc : EM.span), st) =
in
([(L'.DVal (x, n, corifyCon st t, corifyExp st e, s), loc)], st)
end
- | L.DValRec _ => raise Fail "Explify DValRec"
-
+ | L.DValRec vis =>
+ let
+ val (vis, st) = ListUtil.foldlMap
+ (fn ((x, n, t, e), st) =>
+ let
+ val (st, n) = St.bindVal st x n
+ val s =
+ if String.isPrefix "wrap_" x then
+ String.extract (x, 5, NONE)
+ else
+ x
+ in
+ ((x, n, corifyCon st t, corifyExp st e, s), st)
+ end)
+ st vis
+ in
+ ([(L'.DValRec vis, loc)], st)
+ end
| L.DSgn _ => ([], st)
| L.DStr (x, n, _, (L.StrFun (_, na, _, _, str), _)) =>
diff --git a/src/monoize.sml b/src/monoize.sml
index b314d1d6..1d39357e 100644
--- a/src/monoize.sml
+++ b/src/monoize.sml
@@ -248,6 +248,7 @@ fun monoDecl env (all as (d, loc)) =
L.DCon _ => NONE
| L.DVal (x, n, t, e, s) => SOME (Env.pushENamed env x n t (SOME e) s,
(L'.DVal (x, n, monoType env t, monoExp env e, s), loc))
+ | L.DValRec _ => raise Fail "Monoize DValRec"
| L.DExport n =>
let
val (_, t, _, s) = Env.lookupENamed env n
diff --git a/src/shake.sml b/src/shake.sml
index b7ce58d7..038dc8f9 100644
--- a/src/shake.sml
+++ b/src/shake.sml
@@ -49,6 +49,8 @@ fun shake file =
val (cdef, edef) = foldl (fn ((DCon (_, n, _, c), _), (cdef, edef)) => (IM.insert (cdef, n, c), edef)
| ((DVal (_, n, t, e, _), _), (cdef, edef)) => (cdef, IM.insert (edef, n, (t, e)))
+ | ((DValRec vis, _), (cdef, edef)) =>
+ (cdef, foldl (fn ((_, n, t, e, _), edef) => IM.insert (edef, n, (t, e))) edef vis)
| ((DExport _, _), acc) => acc)
(IM.empty, IM.empty) file
@@ -99,6 +101,7 @@ fun shake file =
in
List.filter (fn (DCon (_, n, _, _), _) => IS.member (#con s, n)
| (DVal (_, n, _, _, _), _) => IS.member (#exp s, n)
+ | (DValRec vis, _) => List.exists (fn (_, n, _, _, _) => IS.member (#exp s, n)) vis
| (DExport _, _) => true) file
end
diff --git a/src/tag.sml b/src/tag.sml
index e451281a..301e0977 100644
--- a/src/tag.sml
+++ b/src/tag.sml
@@ -132,6 +132,7 @@ fun tag file =
case d of
DCon (_, n, _, _) => Int.max (n, count)
| DVal (_, n, _, _, _) => Int.max (n, count)
+ | DValRec vis => foldl (fn ((_, n, _, _, _), count) => Int.max (n, count)) count vis
| DExport _ => count) 0 file
fun doDecl (d as (d', loc), (env, count, tags, byTag)) =