diff options
author | Adam Chlipala <adamc@hcoop.net> | 2008-07-17 10:13:18 -0400 |
---|---|---|
committer | Adam Chlipala <adamc@hcoop.net> | 2008-07-17 10:13:18 -0400 |
commit | 1e03bdf0b6f423870abcf5e54ae7f2bdf08e3e49 (patch) | |
tree | 39ac50f2c17e5c8068db2294a5bc3ee89e88cf1a /src | |
parent | dcfd6390610712e9d498cdb4e466eb932a6bb138 (diff) |
Explifying (non-mutual) 'val rec'
Diffstat (limited to 'src')
-rw-r--r-- | src/corify.sml | 4 | ||||
-rw-r--r-- | src/expl.sml | 1 | ||||
-rw-r--r-- | src/expl_env.sml | 1 | ||||
-rw-r--r-- | src/expl_print.sml | 36 | ||||
-rw-r--r-- | src/explify.sml | 2 |
5 files changed, 30 insertions, 14 deletions
diff --git a/src/corify.sml b/src/corify.sml index 55d9a95a..b17cad24 100644 --- a/src/corify.sml +++ b/src/corify.sml @@ -384,6 +384,7 @@ 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.DSgn _ => ([], st) @@ -531,7 +532,8 @@ and corifyStr ((str, _), st) = fun maxName ds = foldl (fn ((d, _), n) => case d of L.DCon (_, n', _, _) => Int.max (n, n') - | L.DVal (_, n', _ , _) => Int.max (n, n') + | L.DVal (_, n', _, _) => Int.max (n, n') + | L.DValRec vis => foldl (fn ((_, n', _, _), n) => Int.max (n, n)) n vis | L.DSgn (_, n', _) => Int.max (n, n') | L.DStr (_, n', _, str) => Int.max (n, Int.max (n', maxNameStr str)) | L.DFfiStr (_, n', _) => Int.max (n, n') diff --git a/src/expl.sml b/src/expl.sml index d6ceb35b..2bb25929 100644 --- a/src/expl.sml +++ b/src/expl.sml @@ -97,6 +97,7 @@ and sgn = sgn' located datatype decl' = DCon of string * int * kind * con | DVal of string * int * con * exp + | DValRec of (string * int * con * exp) list | DSgn of string * int * sgn | DStr of string * int * sgn * str | DFfiStr of string * int * sgn diff --git a/src/expl_env.sml b/src/expl_env.sml index b9c95605..1871e560 100644 --- a/src/expl_env.sml +++ b/src/expl_env.sml @@ -240,6 +240,7 @@ fun declBinds env (d, _) = case d of DCon (x, n, k, c) => pushCNamed env x n k (SOME c) | DVal (x, n, t, _) => pushENamed env x n t + | DValRec vis => foldl (fn ((x, n, t, _), env) => pushENamed env x n t) env vis | DSgn (x, n, sgn) => pushSgnNamed env x n sgn | DStr (x, n, sgn, _) => pushStrNamed env x n sgn | DFfiStr (x, n, sgn) => pushStrNamed env x n sgn diff --git a/src/expl_print.sml b/src/expl_print.sml index 1e8f514a..095a6e24 100644 --- a/src/expl_print.sml +++ b/src/expl_print.sml @@ -345,7 +345,17 @@ and p_sgn env (sgn, _) = p_list_sep (string ".") string (m1x :: ms @ [x]) end -fun p_decl env ((d, _) : decl) = +fun p_vali env (x, n, t, e) = box [p_named x n, + space, + string ":", + space, + p_con env t, + space, + string "=", + space, + p_exp env e] + +fun p_decl env (dAll as (d, _) : decl) = case d of DCon (x, n, k, c) => box [string "con", space, @@ -358,17 +368,19 @@ fun p_decl env ((d, _) : decl) = string "=", space, p_con env c] - | DVal (x, n, t, e) => box [string "val", - space, - p_named x n, - space, - string ":", - space, - p_con env t, - space, - string "=", - space, - p_exp env e] + | DVal vi => box [string "val", + space, + p_vali env vi] + | DValRec vis => + let + val env = E.declBinds env dAll + in + box [string "val", + space, + string "rec", + space, + p_list_sep (box [newline, string "and", space]) (p_vali env) vis] + end | DSgn (x, n, sgn) => box [string "signature", space, diff --git a/src/explify.sml b/src/explify.sml index 2bab60df..db6b429d 100644 --- a/src/explify.sml +++ b/src/explify.sml @@ -111,7 +111,7 @@ fun explifyDecl (d, loc : EM.span) = case d of L.DCon (x, n, k, c) => SOME (L'.DCon (x, n, explifyKind k, explifyCon c), loc) | L.DVal (x, n, t, e) => SOME (L'.DVal (x, n, explifyCon t, explifyExp e), loc) - | L.DValRec _ => raise Fail "Expliofy DValRec" + | L.DValRec vis => SOME (L'.DValRec (map (fn (x, n, t, e) => (x, n, explifyCon t, explifyExp e)) vis), loc) | L.DSgn (x, n, sgn) => SOME (L'.DSgn (x, n, explifySgn sgn), loc) | L.DStr (x, n, sgn, str) => SOME (L'.DStr (x, n, explifySgn sgn, explifyStr str), loc) |