Mercurial > urweb
comparison src/explify.sml @ 38:d16ef24de78b
Explify
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Thu, 19 Jun 2008 10:06:59 -0400 |
parents | |
children | 1405d8c26790 |
comparison
equal
deleted
inserted
replaced
37:367f058aba23 | 38:d16ef24de78b |
---|---|
1 (* Copyright (c) 2008, Adam Chlipala | |
2 * All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are met: | |
6 * | |
7 * - Redistributions of source code must retain the above copyright notice, | |
8 * this list of conditions and the following disclaimer. | |
9 * - Redistributions in binary form must reproduce the above copyright notice, | |
10 * this list of conditions and the following disclaimer in the documentation | |
11 * and/or other materials provided with the distribution. | |
12 * - The names of contributors may not be used to endorse or promote products | |
13 * derived from this software without specific prior written permission. | |
14 * | |
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
25 * POSSIBILITY OF SUCH DAMAGE. | |
26 *) | |
27 | |
28 structure Explify :> EXPLIFY = struct | |
29 | |
30 structure EM = ErrorMsg | |
31 structure L = Elab | |
32 structure L' = Expl | |
33 | |
34 fun explifyKind (k, loc) = | |
35 case k of | |
36 L.KType => (L'.KType, loc) | |
37 | L.KArrow (k1, k2) => (L'.KArrow (explifyKind k1, explifyKind k2), loc) | |
38 | L.KName => (L'.KName, loc) | |
39 | L.KRecord k => (L'.KRecord (explifyKind k), loc) | |
40 | |
41 | L.KError => raise Fail ("explifyKind: KError at " ^ EM.spanToString loc) | |
42 | L.KUnif (_, ref (SOME k)) => explifyKind k | |
43 | L.KUnif _ => raise Fail ("explifyKind: KUnif at " ^ EM.spanToString loc) | |
44 | |
45 fun explifyCon (c, loc) = | |
46 case c of | |
47 L.TFun (t1, t2) => (L'.TFun (explifyCon t1, explifyCon t2), loc) | |
48 | L.TCFun (_, x, k, t) => (L'.TCFun (x, explifyKind k, explifyCon t), loc) | |
49 | L.TRecord c => (L'.TRecord (explifyCon c), loc) | |
50 | |
51 | L.CRel n => (L'.CRel n, loc) | |
52 | L.CNamed n => (L'.CNamed n, loc) | |
53 | L.CModProj (m, ms, x) => (L'.CModProj (m, ms, x), loc) | |
54 | |
55 | L.CApp (c1, c2) => (L'.CApp (explifyCon c1, explifyCon c2), loc) | |
56 | L.CAbs (x, k, c) => (L'.CAbs (x, explifyKind k, explifyCon c), loc) | |
57 | |
58 | L.CName s => (L'.CName s, loc) | |
59 | |
60 | L.CRecord (k, xcs) => (L'.CRecord (explifyKind k, map (fn (c1, c2) => (explifyCon c1, explifyCon c2)) xcs), loc) | |
61 | L.CConcat (c1, c2) => (L'.CConcat (explifyCon c1, explifyCon c2), loc) | |
62 | |
63 | L.CError => raise Fail ("explifyCon: CError at " ^ EM.spanToString loc) | |
64 | L.CUnif (_, _, ref (SOME c)) => explifyCon c | |
65 | L.CUnif _ => raise Fail ("explifyCon: CUnif at " ^ EM.spanToString loc) | |
66 | |
67 fun explifyExp (e, loc) = | |
68 case e of | |
69 L.EPrim p => (L'.EPrim p, loc) | |
70 | L.ERel n => (L'.ERel n, loc) | |
71 | L.ENamed n => (L'.ENamed n, loc) | |
72 | L.EModProj (m, ms, x) => (L'.EModProj (m, ms, x), loc) | |
73 | L.EApp (e1, e2) => (L'.EApp (explifyExp e1, explifyExp e2), loc) | |
74 | L.EAbs (x, dom, ran, e1) => (L'.EAbs (x, explifyCon dom, explifyCon ran, explifyExp e1), loc) | |
75 | L.ECApp (e1, c) => (L'.ECApp (explifyExp e1, explifyCon c), loc) | |
76 | L.ECAbs (_, x, k, e1) => (L'.ECAbs (x, explifyKind k, explifyExp e1), loc) | |
77 | |
78 | L.ERecord xes => (L'.ERecord (map (fn (c, e, t) => (explifyCon c, explifyExp e, explifyCon t)) xes), loc) | |
79 | L.EField (e1, c, {field, rest}) => (L'.EField (explifyExp e1, explifyCon c, | |
80 {field = explifyCon field, rest = explifyCon rest}), loc) | |
81 | |
82 | L.EError => raise Fail ("explifyExp: EError at " ^ EM.spanToString loc) | |
83 | |
84 fun explifySgi (sgi, loc) = | |
85 case sgi of | |
86 L.SgiConAbs (x, n, k) => (L'.SgiConAbs (x, n, explifyKind k), loc) | |
87 | L.SgiCon (x, n, k, c) => (L'.SgiCon (x, n, explifyKind k, explifyCon c), loc) | |
88 | L.SgiVal (x, n, c) => (L'.SgiVal (x, n, explifyCon c), loc) | |
89 | L.SgiStr (x, n, sgn) => (L'.SgiStr (x, n, explifySgn sgn), loc) | |
90 | |
91 and explifySgn (sgn, loc) = | |
92 case sgn of | |
93 L.SgnConst sgis => (L'.SgnConst (map explifySgi sgis), loc) | |
94 | L.SgnVar n => (L'.SgnVar n, loc) | |
95 | L.SgnError => raise Fail ("explifySgn: SgnError at " ^ EM.spanToString loc) | |
96 | |
97 fun explifyDecl (d, loc : EM.span) = | |
98 case d of | |
99 L.DCon (x, n, k, c) => (L'.DCon (x, n, explifyKind k, explifyCon c), loc) | |
100 | L.DVal (x, n, t, e) => (L'.DVal (x, n, explifyCon t, explifyExp e), loc) | |
101 | |
102 | L.DSgn (x, n, sgn) => (L'.DSgn (x, n, explifySgn sgn), loc) | |
103 | L.DStr (x, n, sgn, str) => (L'.DStr (x, n, explifySgn sgn, explifyStr str), loc) | |
104 | |
105 and explifyStr (str, loc) = | |
106 case str of | |
107 L.StrConst ds => (L'.StrConst (map explifyDecl ds), loc) | |
108 | L.StrVar n => (L'.StrVar n, loc) | |
109 | L.StrProj (str, s) => (L'.StrProj (explifyStr str, s), loc) | |
110 | L.StrError => raise Fail ("explifyStr: StrError at " ^ EM.spanToString loc) | |
111 | |
112 val explify = map explifyDecl | |
113 | |
114 end |