Mercurial > urweb
comparison src/mono_env.sml @ 25:0a762c73824d
Monoize
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 10 Jun 2008 13:14:45 -0400 |
parents | |
children | d3cc191cb25f |
comparison
equal
deleted
inserted
replaced
24:ea15905e598d | 25:0a762c73824d |
---|---|
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 MonoEnv :> MONO_ENV = struct | |
29 | |
30 open Mono | |
31 | |
32 structure IM = IntBinaryMap | |
33 | |
34 | |
35 exception UnboundRel of int | |
36 exception UnboundNamed of int | |
37 | |
38 type env = { | |
39 namedT : (string * typ option) IM.map, | |
40 | |
41 relE : (string * typ) list, | |
42 namedE : (string * typ * exp option) IM.map | |
43 } | |
44 | |
45 val empty = { | |
46 namedT = IM.empty, | |
47 | |
48 relE = [], | |
49 namedE = IM.empty | |
50 } | |
51 | |
52 fun pushTNamed (env : env) x n co = | |
53 {namedT = IM.insert (#namedT env, n, (x, co)), | |
54 | |
55 relE = #relE env, | |
56 namedE = #namedE env} | |
57 | |
58 fun lookupTNamed (env : env) n = | |
59 case IM.find (#namedT env, n) of | |
60 NONE => raise UnboundNamed n | |
61 | SOME x => x | |
62 | |
63 fun pushERel (env : env) x t = | |
64 {namedT = #namedT env, | |
65 | |
66 relE = (x, t) :: #relE env, | |
67 namedE = #namedE env} | |
68 | |
69 fun lookupERel (env : env) n = | |
70 (List.nth (#relE env, n)) | |
71 handle Subscript => raise UnboundRel n | |
72 | |
73 fun pushENamed (env : env) x n t eo = | |
74 {namedT = #namedT env, | |
75 | |
76 relE = #relE env, | |
77 namedE = IM.insert (#namedE env, n, (x, t, eo))} | |
78 | |
79 fun lookupENamed (env : env) n = | |
80 case IM.find (#namedE env, n) of | |
81 NONE => raise UnboundNamed n | |
82 | SOME x => x | |
83 | |
84 fun declBinds env (d, _) = | |
85 case d of | |
86 DVal (x, n, t, e) => pushENamed env x n t (SOME e) | |
87 | |
88 fun bbind env x = | |
89 case ElabEnv.lookupC ElabEnv.basis x of | |
90 ElabEnv.NotBound => raise Fail "MonoEnv.bbind: Not bound" | |
91 | ElabEnv.Rel _ => raise Fail "MonoEnv.bbind: Rel" | |
92 | ElabEnv.Named (n, _) => pushTNamed env x n NONE | |
93 | |
94 val basis = empty | |
95 val basis = bbind basis "int" | |
96 val basis = bbind basis "float" | |
97 val basis = bbind basis "string" | |
98 | |
99 end |