adamc@1043
|
1 (* Copyright (c) 2008-2009, Adam Chlipala
|
adamc@25
|
2 * All rights reserved.
|
adamc@25
|
3 *
|
adamc@25
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@25
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@25
|
6 *
|
adamc@25
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@25
|
8 * this list of conditions and the following disclaimer.
|
adamc@25
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@25
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@25
|
11 * and/or other materials provided with the distribution.
|
adamc@25
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@25
|
13 * derived from this software without specific prior written permission.
|
adamc@25
|
14 *
|
adamc@25
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@25
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@25
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@25
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@25
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@25
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@25
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@25
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@25
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@25
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@25
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@25
|
26 *)
|
adamc@25
|
27
|
adamc@25
|
28 structure Monoize :> MONOIZE = struct
|
adamc@25
|
29
|
adamc@25
|
30 structure E = ErrorMsg
|
adamc@25
|
31 structure Env = CoreEnv
|
adamc@25
|
32
|
adamc@25
|
33 structure L = Core
|
adamc@25
|
34 structure L' = Mono
|
adamc@25
|
35
|
adamc@196
|
36 structure IM = IntBinaryMap
|
adamc@735
|
37 structure IS = IntBinarySet
|
adamc@196
|
38
|
adamc@984
|
39 structure SS = BinarySetFn(struct
|
adamc@984
|
40 type ord_key = string
|
adamc@984
|
41 val compare = String.compare
|
adamc@984
|
42 end)
|
adamc@984
|
43
|
adamc@984
|
44 val singletons = SS.addList (SS.empty,
|
adamc@984
|
45 ["link",
|
adamc@984
|
46 "br",
|
adamc@984
|
47 "p",
|
adamc@984
|
48 "hr",
|
adamc@984
|
49 "input",
|
adamc@984
|
50 "button"])
|
adamc@984
|
51
|
adamc@196
|
52 val dummyTyp = (L'.TDatatype (0, ref (L'.Enum, [])), E.dummySpan)
|
adamc@25
|
53
|
adamc@252
|
54 structure U = MonoUtil
|
adamc@252
|
55
|
adamc@252
|
56 val liftExpInExp =
|
adamc@252
|
57 U.Exp.mapB {typ = fn t => t,
|
adamc@252
|
58 exp = fn bound => fn e =>
|
adamc@252
|
59 case e of
|
adamc@252
|
60 L'.ERel xn =>
|
adamc@252
|
61 if xn < bound then
|
adamc@252
|
62 e
|
adamc@252
|
63 else
|
adamc@252
|
64 L'.ERel (xn + 1)
|
adamc@252
|
65 | _ => e,
|
adamc@252
|
66 bind = fn (bound, U.Exp.RelE _) => bound + 1
|
adamc@252
|
67 | (bound, _) => bound}
|
adamc@252
|
68
|
adamc@25
|
69 fun monoName env (all as (c, loc)) =
|
adamc@25
|
70 let
|
adamc@25
|
71 fun poly () =
|
adamc@25
|
72 (E.errorAt loc "Unsupported name constructor";
|
adamc@25
|
73 Print.eprefaces' [("Constructor", CorePrint.p_con env all)];
|
adamc@25
|
74 "")
|
adamc@25
|
75 in
|
adamc@25
|
76 case c of
|
adamc@25
|
77 L.CName s => s
|
adamc@25
|
78 | _ => poly ()
|
adamc@25
|
79 end
|
adamc@25
|
80
|
adamc@877
|
81 fun lowercaseFirst "" = ""
|
adamc@877
|
82 | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0)))
|
adamc@877
|
83 ^ String.extract (s, 1, NONE)
|
adamc@877
|
84
|
adamc@877
|
85 fun monoNameLc env c = lowercaseFirst (monoName env c)
|
adamc@877
|
86
|
adamc@292
|
87 fun readType' (t, loc) = (L'.TFun ((L'.TFfi ("Basis", "string"), loc),
|
adamc@292
|
88 (L'.TOption t, loc)), loc)
|
adamc@292
|
89 fun readErrType (t, loc) = (L'.TFun ((L'.TFfi ("Basis", "string"), loc),
|
adamc@292
|
90 t), loc)
|
adamc@292
|
91 fun readType (t, loc) =
|
adamc@292
|
92 (L'.TRecord [("Read", readType' (t, loc)),
|
adamc@292
|
93 ("ReadError", readErrType (t, loc))],
|
adamc@292
|
94 loc)
|
adamc@292
|
95
|
adamc@196
|
96 fun monoType env =
|
adamc@25
|
97 let
|
adamc@196
|
98 fun mt env dtmap (all as (c, loc)) =
|
adamc@196
|
99 let
|
adamc@196
|
100 fun poly () =
|
adamc@196
|
101 (E.errorAt loc "Unsupported type constructor";
|
adamc@196
|
102 Print.eprefaces' [("Constructor", CorePrint.p_con env all)];
|
adamc@196
|
103 dummyTyp)
|
adamc@196
|
104 in
|
adamc@196
|
105 case c of
|
adamc@196
|
106 L.TFun (c1, c2) => (L'.TFun (mt env dtmap c1, mt env dtmap c2), loc)
|
adamc@196
|
107 | L.TCFun _ => poly ()
|
adamc@196
|
108 | L.TRecord (L.CRecord ((L.KType, _), xcs), _) =>
|
adamc@905
|
109 let
|
adamc@905
|
110 val xcs = map (fn (x, t) => (monoName env x, mt env dtmap t)) xcs
|
adamc@905
|
111 val xcs = ListMergeSort.sort (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER) xcs
|
adamc@905
|
112 in
|
adamc@905
|
113 (L'.TRecord xcs, loc)
|
adamc@905
|
114 end
|
adamc@196
|
115 | L.TRecord _ => poly ()
|
adamc@196
|
116
|
adamc@288
|
117 | L.CApp ((L.CFfi ("Basis", "option"), _), t) =>
|
adamc@288
|
118 (L'.TOption (mt env dtmap t), loc)
|
adamc@757
|
119 | L.CApp ((L.CFfi ("Basis", "list"), _), t) =>
|
adamc@757
|
120 (L'.TList (mt env dtmap t), loc)
|
adamc@288
|
121
|
adamc@820
|
122 | L.CApp ((L.CFfi ("Basis", "monad"), _), _) =>
|
adamc@820
|
123 (L'.TRecord [], loc)
|
adamc@820
|
124
|
adamc@387
|
125 | L.CApp ((L.CFfi ("Basis", "eq"), _), t) =>
|
adamc@387
|
126 let
|
adamc@387
|
127 val t = mt env dtmap t
|
adamc@387
|
128 in
|
adamc@387
|
129 (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)
|
adamc@387
|
130 end
|
adamc@389
|
131 | L.CApp ((L.CFfi ("Basis", "num"), _), t) =>
|
adamc@389
|
132 let
|
adamc@389
|
133 val t = mt env dtmap t
|
adamc@389
|
134 in
|
adamc@417
|
135 (L'.TRecord [("Zero", t),
|
adamc@417
|
136 ("Neg", (L'.TFun (t, t), loc)),
|
adamc@389
|
137 ("Plus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
138 ("Minus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
139 ("Times", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
140 ("Div", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
141 ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))],
|
adamc@389
|
142 loc)
|
adamc@389
|
143 end
|
adamc@391
|
144 | L.CApp ((L.CFfi ("Basis", "ord"), _), t) =>
|
adamc@391
|
145 let
|
adamc@391
|
146 val t = mt env dtmap t
|
adamc@391
|
147 in
|
adamc@391
|
148 (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
149 ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))],
|
adamc@391
|
150 loc)
|
adamc@391
|
151 end
|
adamc@286
|
152 | L.CApp ((L.CFfi ("Basis", "show"), _), t) =>
|
adamc@286
|
153 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@290
|
154 | L.CApp ((L.CFfi ("Basis", "read"), _), t) =>
|
adamc@292
|
155 readType (mt env dtmap t, loc)
|
adamc@286
|
156
|
adamc@717
|
157 | L.CFfi ("Basis", "url") => (L'.TFfi ("Basis", "string"), loc)
|
adamc@741
|
158 | L.CFfi ("Basis", "mimeType") => (L'.TFfi ("Basis", "string"), loc)
|
adamc@720
|
159 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "xml"), _), _), _), _), _), _) =>
|
adamc@196
|
160 (L'.TFfi ("Basis", "string"), loc)
|
adamc@196
|
161 | L.CApp ((L.CApp ((L.CFfi ("Basis", "xhtml"), _), _), _), _) =>
|
adamc@196
|
162 (L'.TFfi ("Basis", "string"), loc)
|
adamc@721
|
163 | L.CFfi ("Basis", "css_class") => (L'.TFfi ("Basis", "string"), loc)
|
adamc@196
|
164
|
adamc@251
|
165 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@252
|
166 (L'.TFun ((L'.TRecord [], loc), mt env dtmap t), loc)
|
adamc@565
|
167 | L.CApp ((L.CFfi ("Basis", "source"), _), t) =>
|
adamc@577
|
168 (L'.TSource, loc)
|
adamc@568
|
169 | L.CApp ((L.CFfi ("Basis", "signal"), _), t) =>
|
adamc@568
|
170 (L'.TSignal (mt env dtmap t), loc)
|
adamc@462
|
171 | L.CApp ((L.CFfi ("Basis", "http_cookie"), _), _) =>
|
adamc@462
|
172 (L'.TFfi ("Basis", "string"), loc)
|
adamc@705
|
173 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_table"), _), _), _), _) =>
|
adamc@252
|
174 (L'.TFfi ("Basis", "string"), loc)
|
adamc@823
|
175 | L.CApp ((L.CFfi ("Basis", "sql_view"), _), _) =>
|
adamc@823
|
176 (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
177 | L.CFfi ("Basis", "sql_sequence") =>
|
adamc@338
|
178 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
179 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query"), _), _), _), _) =>
|
adamc@252
|
180 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
181 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _) =>
|
adamc@252
|
182 (L'.TFfi ("Basis", "string"), loc)
|
adamc@748
|
183 | L.CApp ((L.CFfi ("Basis", "sql_from_items"), _), _) =>
|
adamc@748
|
184 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
185 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _) =>
|
adamc@252
|
186 (L'.TFfi ("Basis", "string"), loc)
|
adamc@707
|
187 | L.CApp ((L.CApp ((L.CFfi ("Basis", "primary_key"), _), _), _), _) =>
|
adamc@707
|
188 (L'.TFfi ("Basis", "string"), loc)
|
adamc@704
|
189 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_constraints"), _), _), _), _) =>
|
adamc@704
|
190 (L'.TFfi ("Basis", "sql_constraints"), loc)
|
adamc@705
|
191 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_constraint"), _), _), _), _) =>
|
adamc@704
|
192 (L'.TFfi ("Basis", "string"), loc)
|
adamc@712
|
193 | L.CApp ((L.CApp ((L.CFfi ("Basis", "linkable"), _), _), _), _) =>
|
adamc@712
|
194 (L'.TRecord [], loc)
|
adamc@709
|
195 | L.CApp ((L.CApp ((L.CFfi ("Basis", "matching"), _), _), _), _) =>
|
adamc@709
|
196 let
|
adamc@709
|
197 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
198 in
|
adamc@709
|
199 (L'.TRecord [("1", string), ("2", string)], loc)
|
adamc@709
|
200 end
|
adamc@709
|
201 | L.CApp ((L.CFfi ("Basis", "propagation_mode"), _), _) =>
|
adamc@709
|
202 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
203
|
adamc@252
|
204 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_subset"), _), _), _), _) =>
|
adamc@252
|
205 (L'.TRecord [], loc)
|
adamc@252
|
206 | L.CFfi ("Basis", "sql_relop") =>
|
adamc@252
|
207 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
208 | L.CFfi ("Basis", "sql_direction") =>
|
adamc@252
|
209 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
210 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_order_by"), _), _), _), _) =>
|
adamc@252
|
211 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
212 | L.CFfi ("Basis", "sql_limit") =>
|
adamc@252
|
213 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
214 | L.CFfi ("Basis", "sql_offset") =>
|
adamc@252
|
215 (L'.TFfi ("Basis", "string"), loc)
|
adamc@753
|
216 | L.CApp ((L.CApp ((L.CFfi ("Basis", "fieldsOf"), _), _), _), _) =>
|
adamc@753
|
217 (L'.TRecord [], loc)
|
adamc@252
|
218
|
adamc@676
|
219 | L.CApp ((L.CFfi ("Basis", "sql_injectable_prim"), _), t) =>
|
adamc@676
|
220 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@252
|
221 | L.CApp ((L.CFfi ("Basis", "sql_injectable"), _), t) =>
|
adamc@252
|
222 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@750
|
223 | L.CApp ((L.CApp ((L.CFfi ("Basis", "nullify"), _), _), _), _) =>
|
adamc@750
|
224 (L'.TRecord [], loc)
|
adamc@252
|
225 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) =>
|
adamc@252
|
226 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
227 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_binary"), _), _), _), _), _), _) =>
|
adamc@252
|
228 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
229 | L.CApp ((L.CFfi ("Basis", "sql_aggregate"), _), t) =>
|
adamc@252
|
230 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
231 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) =>
|
adamc@252
|
232 (L'.TRecord [], loc)
|
adamc@252
|
233 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) =>
|
adamc@252
|
234 (L'.TRecord [], loc)
|
adamc@559
|
235 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) =>
|
adamc@559
|
236 (L'.TRecord [], loc)
|
adamc@441
|
237 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) =>
|
adamc@441
|
238 (L'.TFfi ("Basis", "string"), loc)
|
adamc@746
|
239 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_ufunc"), _), _), _), _) =>
|
adamc@746
|
240 (L'.TFfi ("Basis", "string"), loc)
|
adamc@251
|
241
|
adamc@668
|
242 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) =>
|
adamc@668
|
243 (L'.TFfi ("Basis", "channel"), loc)
|
adamc@668
|
244
|
adamc@196
|
245 | L.CRel _ => poly ()
|
adamc@196
|
246 | L.CNamed n =>
|
adamc@196
|
247 (case IM.find (dtmap, n) of
|
adamc@196
|
248 SOME r => (L'.TDatatype (n, r), loc)
|
adamc@196
|
249 | NONE =>
|
adamc@196
|
250 let
|
adamc@196
|
251 val r = ref (L'.Default, [])
|
adamc@196
|
252 val (_, xs, xncs) = Env.lookupDatatype env n
|
adamc@196
|
253
|
adamc@196
|
254 val dtmap' = IM.insert (dtmap, n, r)
|
adamc@196
|
255
|
adamc@196
|
256 val xncs = map (fn (x, n, to) => (x, n, Option.map (mt env dtmap') to)) xncs
|
adamc@196
|
257 in
|
adamc@196
|
258 case xs of
|
adamc@198
|
259 [] =>(r := (ElabUtil.classifyDatatype xncs, xncs);
|
adamc@196
|
260 (L'.TDatatype (n, r), loc))
|
adamc@196
|
261 | _ => poly ()
|
adamc@196
|
262 end)
|
adamc@196
|
263 | L.CFfi mx => (L'.TFfi mx, loc)
|
adamc@196
|
264 | L.CApp _ => poly ()
|
adamc@196
|
265 | L.CAbs _ => poly ()
|
adamc@196
|
266
|
adamc@196
|
267 | L.CName _ => poly ()
|
adamc@196
|
268
|
adamc@196
|
269 | L.CRecord _ => poly ()
|
adamc@196
|
270 | L.CConcat _ => poly ()
|
adamc@621
|
271 | L.CMap _ => poly ()
|
adamc@196
|
272 | L.CUnit => poly ()
|
adamc@214
|
273
|
adamc@214
|
274 | L.CTuple _ => poly ()
|
adamc@214
|
275 | L.CProj _ => poly ()
|
adamc@626
|
276
|
adamc@626
|
277 | L.CKAbs _ => poly ()
|
adamc@626
|
278 | L.CKApp _ => poly ()
|
adamc@626
|
279 | L.TKFun _ => poly ()
|
adamc@196
|
280 end
|
adamc@25
|
281 in
|
adamc@196
|
282 mt env IM.empty
|
adamc@25
|
283 end
|
adamc@25
|
284
|
adamc@25
|
285 val dummyExp = (L'.EPrim (Prim.Int 0), E.dummySpan)
|
adamc@25
|
286
|
adamc@179
|
287 structure IM = IntBinaryMap
|
adamc@179
|
288
|
adamc@179
|
289 datatype foo_kind =
|
adamc@179
|
290 Attr
|
adamc@179
|
291 | Url
|
adamc@179
|
292
|
adamc@179
|
293 fun fk2s fk =
|
adamc@179
|
294 case fk of
|
adamc@179
|
295 Attr => "attr"
|
adamc@179
|
296 | Url => "url"
|
adamc@179
|
297
|
adamc@179
|
298 structure Fm :> sig
|
adamc@179
|
299 type t
|
adamc@179
|
300
|
adamc@179
|
301 val empty : int -> t
|
adamc@179
|
302
|
adamc@179
|
303 val lookup : t -> foo_kind -> int -> (int -> t -> L'.decl * t) -> t * int
|
adamc@758
|
304 val lookupList : t -> foo_kind -> L'.typ -> (int -> t -> L'.decl * t) -> t * int
|
adamc@179
|
305 val enter : t -> t
|
adamc@179
|
306 val decls : t -> L'.decl list
|
adamc@683
|
307
|
adamc@683
|
308 val freshName : t -> int * t
|
adamc@179
|
309 end = struct
|
adamc@179
|
310
|
adamc@179
|
311 structure M = BinaryMapFn(struct
|
adamc@179
|
312 type ord_key = foo_kind
|
adamc@179
|
313 fun compare x =
|
adamc@179
|
314 case x of
|
adamc@179
|
315 (Attr, Attr) => EQUAL
|
adamc@179
|
316 | (Attr, _) => LESS
|
adamc@179
|
317 | (_, Attr) => GREATER
|
adamc@179
|
318
|
adamc@179
|
319 | (Url, Url) => EQUAL
|
adamc@179
|
320 end)
|
adamc@179
|
321
|
adamc@758
|
322 structure TM = BinaryMapFn(struct
|
adamc@758
|
323 type ord_key = L'.typ
|
adamc@758
|
324 val compare = MonoUtil.Typ.compare
|
adamc@758
|
325 end)
|
adamc@758
|
326
|
adamc@179
|
327 type t = {
|
adamc@179
|
328 count : int,
|
adamc@179
|
329 map : int IM.map M.map,
|
adamc@758
|
330 listMap : int TM.map M.map,
|
adamc@179
|
331 decls : L'.decl list
|
adamc@179
|
332 }
|
adamc@179
|
333
|
adamc@179
|
334 fun empty count = {
|
adamc@179
|
335 count = count,
|
adamc@179
|
336 map = M.empty,
|
adamc@758
|
337 listMap = M.empty,
|
adamc@179
|
338 decls = []
|
adamc@179
|
339 }
|
adamc@179
|
340
|
adamc@758
|
341 fun enter ({count, map, listMap, ...} : t) = {count = count, map = map, listMap = listMap, decls = []}
|
adamc@758
|
342 fun freshName {count, map, listMap, decls} = (count, {count = count + 1, map = map, listMap = listMap, decls = decls})
|
adamc@179
|
343 fun decls ({decls, ...} : t) = decls
|
adamc@179
|
344
|
adamc@758
|
345 fun lookup (t as {count, map, listMap, decls}) k n thunk =
|
adamc@120
|
346 let
|
adamc@179
|
347 val im = Option.getOpt (M.find (map, k), IM.empty)
|
adamc@179
|
348 in
|
adamc@179
|
349 case IM.find (im, n) of
|
adamc@179
|
350 NONE =>
|
adamc@179
|
351 let
|
adamc@179
|
352 val n' = count
|
adamc@758
|
353 val (d, {count, map, listMap, decls}) =
|
adamc@758
|
354 thunk count {count = count + 1,
|
adamc@758
|
355 map = M.insert (map, k, IM.insert (im, n, n')),
|
adamc@758
|
356 listMap = listMap,
|
adamc@758
|
357 decls = decls}
|
adamc@179
|
358 in
|
adamc@179
|
359 ({count = count,
|
adamc@179
|
360 map = map,
|
adamc@758
|
361 listMap = listMap,
|
adamc@758
|
362 decls = d :: decls}, n')
|
adamc@758
|
363 end
|
adamc@758
|
364 | SOME n' => (t, n')
|
adamc@758
|
365 end
|
adamc@758
|
366
|
adamc@758
|
367 fun lookupList (t as {count, map, listMap, decls}) k tp thunk =
|
adamc@758
|
368 let
|
adamc@758
|
369 val tm = Option.getOpt (M.find (listMap, k), TM.empty)
|
adamc@758
|
370 in
|
adamc@758
|
371 case TM.find (tm, tp) of
|
adamc@758
|
372 NONE =>
|
adamc@758
|
373 let
|
adamc@758
|
374 val n' = count
|
adamc@758
|
375 val (d, {count, map, listMap, decls}) =
|
adamc@758
|
376 thunk count {count = count + 1,
|
adamc@758
|
377 map = map,
|
adamc@758
|
378 listMap = M.insert (listMap, k, TM.insert (tm, tp, n')),
|
adamc@758
|
379 decls = decls}
|
adamc@758
|
380 in
|
adamc@758
|
381 ({count = count,
|
adamc@758
|
382 map = map,
|
adamc@758
|
383 listMap = listMap,
|
adamc@179
|
384 decls = d :: decls}, n')
|
adamc@179
|
385 end
|
adamc@179
|
386 | SOME n' => (t, n')
|
adamc@179
|
387 end
|
adamc@179
|
388
|
adamc@179
|
389 end
|
adamc@185
|
390
|
adamc@185
|
391
|
adamc@185
|
392 fun capitalize s =
|
adamc@185
|
393 if s = "" then
|
adamc@185
|
394 s
|
adamc@185
|
395 else
|
adamc@185
|
396 str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adamc@179
|
397
|
adamc@1065
|
398 val inTag = ref false
|
adamc@1065
|
399
|
adamc@179
|
400 fun fooifyExp fk env =
|
adamc@179
|
401 let
|
adamc@179
|
402 fun fooify fm (e, tAll as (t, loc)) =
|
adamc@120
|
403 case #1 e of
|
adamc@120
|
404 L'.EClosure (fnam, [(L'.ERecord [], _)]) =>
|
adamc@120
|
405 let
|
adamc@120
|
406 val (_, _, _, s) = Env.lookupENamed env fnam
|
adamc@120
|
407 in
|
adamc@764
|
408 ((L'.EPrim (Prim.String (Settings.getUrlPrefix () ^ s)), loc), fm)
|
adamc@120
|
409 end
|
adamc@120
|
410 | L'.EClosure (fnam, args) =>
|
adamc@120
|
411 let
|
adamc@120
|
412 val (_, ft, _, s) = Env.lookupENamed env fnam
|
adamc@120
|
413 val ft = monoType env ft
|
adamc@111
|
414
|
adamc@179
|
415 fun attrify (args, ft, e, fm) =
|
adamc@120
|
416 case (args, ft) of
|
adamc@179
|
417 ([], _) => (e, fm)
|
adamc@120
|
418 | (arg :: args, (L'.TFun (t, ft), _)) =>
|
adamc@179
|
419 let
|
adamc@179
|
420 val (arg', fm) = fooify fm (arg, t)
|
adamc@179
|
421 in
|
adamc@179
|
422 attrify (args, ft,
|
adamc@179
|
423 (L'.EStrcat (e,
|
adamc@179
|
424 (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc),
|
adamc@179
|
425 arg'), loc)), loc),
|
adamc@179
|
426 fm)
|
adamc@179
|
427 end
|
adamc@120
|
428 | _ => (E.errorAt loc "Type mismatch encoding attribute";
|
adamc@179
|
429 (e, fm))
|
adamc@120
|
430 in
|
adamc@764
|
431 attrify (args, ft, (L'.EPrim (Prim.String (Settings.getUrlPrefix () ^ s)), loc), fm)
|
adamc@120
|
432 end
|
adamc@120
|
433 | _ =>
|
adamc@120
|
434 case t of
|
adamc@185
|
435 L'.TFfi (m, x) => ((L'.EFfiApp (m, fk2s fk ^ "ify" ^ capitalize x, [e]), loc), fm)
|
adamc@200
|
436
|
adamc@179
|
437 | L'.TRecord [] => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@200
|
438 | L'.TRecord ((x, t) :: xts) =>
|
adamc@200
|
439 let
|
adamc@200
|
440 val (se, fm) = fooify fm ((L'.EField (e, x), loc), t)
|
adamc@200
|
441 in
|
adamc@200
|
442 foldl (fn ((x, t), (se, fm)) =>
|
adamc@200
|
443 let
|
adamc@200
|
444 val (se', fm) = fooify fm ((L'.EField (e, x), loc), t)
|
adamc@200
|
445 in
|
adamc@200
|
446 ((L'.EStrcat (se,
|
adamc@200
|
447 (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc),
|
adamc@200
|
448 se'), loc)), loc),
|
adamc@200
|
449 fm)
|
adamc@200
|
450 end) (se, fm) xts
|
adamc@200
|
451 end
|
adamc@111
|
452
|
adamc@196
|
453 | L'.TDatatype (i, ref (dk, _)) =>
|
adamc@179
|
454 let
|
adamc@179
|
455 fun makeDecl n fm =
|
adamc@179
|
456 let
|
adamc@193
|
457 val (x, _, xncs) = Env.lookupDatatype env i
|
adamc@179
|
458
|
adamc@179
|
459 val (branches, fm) =
|
adamc@179
|
460 ListUtil.foldlMap
|
adamc@179
|
461 (fn ((x, n, to), fm) =>
|
adamc@179
|
462 case to of
|
adamc@179
|
463 NONE =>
|
adamc@188
|
464 (((L'.PCon (dk, L'.PConVar n, NONE), loc),
|
adamc@179
|
465 (L'.EPrim (Prim.String x), loc)),
|
adamc@179
|
466 fm)
|
adamc@179
|
467 | SOME t =>
|
adamc@179
|
468 let
|
adamc@182
|
469 val t = monoType env t
|
adamc@182
|
470 val (arg, fm) = fooify fm ((L'.ERel 0, loc), t)
|
adamc@179
|
471 in
|
adamc@188
|
472 (((L'.PCon (dk, L'.PConVar n, SOME (L'.PVar ("a", t), loc)), loc),
|
adamc@179
|
473 (L'.EStrcat ((L'.EPrim (Prim.String (x ^ "/")), loc),
|
adamc@179
|
474 arg), loc)),
|
adamc@179
|
475 fm)
|
adamc@179
|
476 end)
|
adamc@179
|
477 fm xncs
|
adamc@179
|
478
|
adamc@179
|
479 val dom = tAll
|
adamc@179
|
480 val ran = (L'.TFfi ("Basis", "string"), loc)
|
adamc@179
|
481 in
|
adamc@179
|
482 ((L'.DValRec [(fk2s fk ^ "ify_" ^ x,
|
adamc@179
|
483 n,
|
adamc@179
|
484 (L'.TFun (dom, ran), loc),
|
adamc@179
|
485 (L'.EAbs ("x",
|
adamc@179
|
486 dom,
|
adamc@179
|
487 ran,
|
adamc@179
|
488 (L'.ECase ((L'.ERel 0, loc),
|
adamc@179
|
489 branches,
|
adamc@182
|
490 {disc = dom,
|
adamc@182
|
491 result = ran}), loc)), loc),
|
adamc@179
|
492 "")], loc),
|
adamc@179
|
493 fm)
|
adamc@179
|
494 end
|
adamc@179
|
495
|
adamc@179
|
496 val (fm, n) = Fm.lookup fm fk i makeDecl
|
adamc@179
|
497 in
|
adamc@179
|
498 ((L'.EApp ((L'.ENamed n, loc), e), loc), fm)
|
adamc@179
|
499 end
|
adamc@164
|
500
|
adamc@471
|
501 | L'.TOption t =>
|
adamc@471
|
502 let
|
adamc@471
|
503 val (body, fm) = fooify fm ((L'.ERel 0, loc), t)
|
adamc@471
|
504 in
|
adamc@471
|
505 ((L'.ECase (e,
|
adamc@471
|
506 [((L'.PNone t, loc),
|
adamc@471
|
507 (L'.EPrim (Prim.String "None"), loc)),
|
adamc@471
|
508
|
adamc@471
|
509 ((L'.PSome (t, (L'.PVar ("x", t), loc)), loc),
|
adamc@471
|
510 (L'.EStrcat ((L'.EPrim (Prim.String "Some/"), loc),
|
adamc@471
|
511 body), loc))],
|
adamc@471
|
512 {disc = tAll,
|
adamc@471
|
513 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@471
|
514 fm)
|
adamc@471
|
515 end
|
adamc@471
|
516
|
adamc@758
|
517 | L'.TList t =>
|
adamc@758
|
518 let
|
adamc@758
|
519 fun makeDecl n fm =
|
adamc@758
|
520 let
|
adamc@758
|
521 val rt = (L'.TRecord [("1", t), ("2", (L'.TList t, loc))], loc)
|
adamc@758
|
522 val (arg, fm) = fooify fm ((L'.ERel 0, loc), rt)
|
adamc@758
|
523
|
adamc@758
|
524 val branches = [((L'.PNone rt, loc),
|
adamc@758
|
525 (L'.EPrim (Prim.String "Nil"), loc)),
|
adamc@758
|
526 ((L'.PSome (rt, (L'.PVar ("a", rt), loc)), loc),
|
adamc@758
|
527 (L'.EStrcat ((L'.EPrim (Prim.String "Cons/"), loc),
|
adamc@758
|
528 arg), loc))]
|
adamc@758
|
529
|
adamc@758
|
530 val dom = tAll
|
adamc@758
|
531 val ran = (L'.TFfi ("Basis", "string"), loc)
|
adamc@758
|
532 in
|
adamc@758
|
533 ((L'.DValRec [(fk2s fk ^ "ify_list",
|
adamc@758
|
534 n,
|
adamc@758
|
535 (L'.TFun (dom, ran), loc),
|
adamc@758
|
536 (L'.EAbs ("x",
|
adamc@758
|
537 dom,
|
adamc@758
|
538 ran,
|
adamc@758
|
539 (L'.ECase ((L'.ERel 0, loc),
|
adamc@758
|
540 branches,
|
adamc@758
|
541 {disc = dom,
|
adamc@758
|
542 result = ran}), loc)), loc),
|
adamc@758
|
543 "")], loc),
|
adamc@758
|
544 fm)
|
adamc@758
|
545 end
|
adamc@758
|
546
|
adamc@758
|
547 val (fm, n) = Fm.lookupList fm fk t makeDecl
|
adamc@758
|
548 in
|
adamc@758
|
549 ((L'.EApp ((L'.ENamed n, loc), e), loc), fm)
|
adamc@758
|
550 end
|
adamc@758
|
551
|
adamc@490
|
552 | _ => (E.errorAt loc "Don't know how to encode attribute/URL type";
|
adamc@120
|
553 Print.eprefaces' [("Type", MonoPrint.p_typ MonoEnv.empty tAll)];
|
adamc@179
|
554 (dummyExp, fm))
|
adamc@120
|
555 in
|
adamc@120
|
556 fooify
|
adamc@120
|
557 end
|
adamc@120
|
558
|
adamc@179
|
559 val attrifyExp = fooifyExp Attr
|
adamc@179
|
560 val urlifyExp = fooifyExp Url
|
adamc@105
|
561
|
adamc@143
|
562 datatype 'a failable_search =
|
adamc@143
|
563 Found of 'a
|
adamc@143
|
564 | NotFound
|
adamc@143
|
565 | Error
|
adamc@143
|
566
|
adamc@153
|
567 structure St :> sig
|
adamc@153
|
568 type t
|
adamc@153
|
569
|
adamc@153
|
570 val empty : t
|
adamc@153
|
571
|
adamc@153
|
572 val radioGroup : t -> string option
|
adamc@153
|
573 val setRadioGroup : t * string -> t
|
adamc@153
|
574 end = struct
|
adamc@153
|
575
|
adamc@153
|
576 type t = {
|
adamc@153
|
577 radioGroup : string option
|
adamc@153
|
578 }
|
adamc@153
|
579
|
adamc@153
|
580 val empty = {radioGroup = NONE}
|
adamc@153
|
581
|
adamc@153
|
582 fun radioGroup (t : t) = #radioGroup t
|
adamc@153
|
583
|
adamc@153
|
584 fun setRadioGroup (t : t, x) = {radioGroup = SOME x}
|
adamc@153
|
585
|
adamc@153
|
586 end
|
adamc@153
|
587
|
adamc@186
|
588 fun monoPatCon env pc =
|
adamc@178
|
589 case pc of
|
adamc@178
|
590 L.PConVar n => L'.PConVar n
|
adamc@188
|
591 | L.PConFfi {mod = m, datatyp, con, arg, ...} => L'.PConFfi {mod = m, datatyp = datatyp, con = con,
|
adamc@188
|
592 arg = Option.map (monoType env) arg}
|
adamc@178
|
593
|
adamc@193
|
594 val dummyPat = (L'.PPrim (Prim.Int 0), ErrorMsg.dummySpan)
|
adamc@193
|
595
|
adamc@757
|
596
|
adamc@757
|
597 fun listify t = (L'.TRecord [("1", t), ("2", (L'.TList t, #2 t))], #2 t)
|
adamc@757
|
598
|
adamc@193
|
599 fun monoPat env (all as (p, loc)) =
|
adamc@193
|
600 let
|
adamc@193
|
601 fun poly () =
|
adamc@193
|
602 (E.errorAt loc "Unsupported pattern";
|
adamc@193
|
603 Print.eprefaces' [("Pattern", CorePrint.p_pat env all)];
|
adamc@193
|
604 dummyPat)
|
adamc@193
|
605 in
|
adamc@193
|
606 case p of
|
adamc@193
|
607 L.PWild => (L'.PWild, loc)
|
adamc@193
|
608 | L.PVar (x, t) => (L'.PVar (x, monoType env t), loc)
|
adamc@193
|
609 | L.PPrim p => (L'.PPrim p, loc)
|
adamc@193
|
610 | L.PCon (dk, pc, [], po) => (L'.PCon (dk, monoPatCon env pc, Option.map (monoPat env) po), loc)
|
adamc@757
|
611 | L.PCon (L.Option, L.PConFfi {mod = "Basis", datatyp = "list", ...}, [t], NONE) =>
|
adamc@757
|
612 (L'.PNone (listify (monoType env t)), loc)
|
adamc@757
|
613 | L.PCon (L.Option, L.PConFfi {mod = "Basis", datatyp = "list", ...}, [t], SOME p) =>
|
adamc@757
|
614 (L'.PSome (listify (monoType env t), monoPat env p), loc)
|
adamc@288
|
615 | L.PCon (L.Option, _, [t], NONE) => (L'.PNone (monoType env t), loc)
|
adamc@757
|
616 | L.PCon (L.Option, pc, [t], SOME p) => (L'.PSome (monoType env t, monoPat env p), loc)
|
adamc@193
|
617 | L.PCon _ => poly ()
|
adamc@193
|
618 | L.PRecord xps => (L'.PRecord (map (fn (x, p, t) => (x, monoPat env p, monoType env t)) xps), loc)
|
adamc@193
|
619 end
|
adamc@178
|
620
|
adamc@252
|
621 fun strcat loc es =
|
adamc@252
|
622 case es of
|
adamc@252
|
623 [] => (L'.EPrim (Prim.String ""), loc)
|
adamc@252
|
624 | [e] => e
|
adamc@252
|
625 | _ =>
|
adamc@252
|
626 let
|
adamc@252
|
627 val e2 = List.last es
|
adamc@252
|
628 val es = List.take (es, length es - 1)
|
adamc@252
|
629 val e1 = List.last es
|
adamc@252
|
630 val es = List.take (es, length es - 1)
|
adamc@252
|
631 in
|
adamc@252
|
632 foldr (fn (e, e') => (L'.EStrcat (e, e'), loc))
|
adamc@252
|
633 (L'.EStrcat (e1, e2), loc) es
|
adamc@252
|
634 end
|
adamc@252
|
635
|
adamc@252
|
636 fun strcatComma loc es =
|
adamc@252
|
637 case es of
|
adamc@252
|
638 [] => (L'.EPrim (Prim.String ""), loc)
|
adamc@252
|
639 | [e] => e
|
adamc@252
|
640 | _ =>
|
adamc@252
|
641 let
|
adamc@252
|
642 val e1 = List.last es
|
adamc@252
|
643 val es = List.take (es, length es - 1)
|
adamc@252
|
644 in
|
adamc@252
|
645 foldr (fn (e, e') =>
|
adamc@265
|
646 case (e, e') of
|
adamc@265
|
647 ((L'.EPrim (Prim.String ""), _), _) => e'
|
adamc@265
|
648 | (_, (L'.EPrim (Prim.String ""), _)) => e
|
adamc@252
|
649 | _ =>
|
adamc@252
|
650 (L'.EStrcat (e,
|
adamc@252
|
651 (L'.EStrcat ((L'.EPrim (Prim.String ", "), loc), e'), loc)), loc))
|
adamc@252
|
652 e1 es
|
adamc@252
|
653 end
|
adamc@252
|
654
|
adamc@252
|
655 fun strcatR loc e xs = strcatComma loc (map (fn (x, _) => (L'.EField (e, x), loc)) xs)
|
adamc@252
|
656
|
adamc@735
|
657 val readCookie = ref IS.empty
|
adamc@735
|
658
|
adamc@877
|
659 fun isBlobby (t : L.con) =
|
adamc@877
|
660 case #1 t of
|
adamc@877
|
661 L.CFfi ("Basis", "string") => true
|
adamc@877
|
662 | L.CFfi ("Basis", "blob") => true
|
adamc@877
|
663 | _ => false
|
adamc@877
|
664
|
adamc@179
|
665 fun monoExp (env, st, fm) (all as (e, loc)) =
|
adamc@25
|
666 let
|
adamc@598
|
667 val strcat = strcat loc
|
adamc@598
|
668 val strcatComma = strcatComma loc
|
adamc@598
|
669 fun str s = (L'.EPrim (Prim.String s), loc)
|
adamc@598
|
670
|
adamc@25
|
671 fun poly () =
|
adamc@25
|
672 (E.errorAt loc "Unsupported expression";
|
adamc@25
|
673 Print.eprefaces' [("Expression", CorePrint.p_exp env all)];
|
adamc@179
|
674 (dummyExp, fm))
|
adamc@389
|
675
|
adamc@389
|
676 fun numTy t =
|
adamc@417
|
677 (L'.TRecord [("Zero", t),
|
adamc@417
|
678 ("Neg", (L'.TFun (t, t), loc)),
|
adamc@389
|
679 ("Plus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
680 ("Minus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
681 ("Times", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
682 ("Div", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
683 ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc)
|
adamc@417
|
684 fun numEx (t, zero, neg, plus, minus, times, dv, md) =
|
adamc@417
|
685 ((L'.ERecord [("Zero", (L'.EPrim zero, loc), t),
|
adamc@417
|
686 ("Neg", neg, (L'.TFun (t, t), loc)),
|
adamc@389
|
687 ("Plus", plus, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
688 ("Minus", minus, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
689 ("Times", times, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
690 ("Div", dv, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
691 ("Mod", md, (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc), fm)
|
adamc@391
|
692
|
adamc@391
|
693 fun ordTy t =
|
adamc@391
|
694 (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
695 ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))], loc)
|
adamc@391
|
696 fun ordEx (t, lt, le) =
|
adamc@391
|
697 ((L'.ERecord [("Lt", lt, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
698 ("Le", le, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))],
|
adamc@391
|
699 loc), fm)
|
adamc@750
|
700
|
adamc@750
|
701 fun outerRec xts =
|
adamc@750
|
702 (L'.TRecord (map (fn ((L.CName x, _), (L.CRecord (_, xts), _)) =>
|
adamc@750
|
703 (x, (L'.TRecord (map (fn (x', _) => (x, (L'.TRecord [], loc))) xts), loc))
|
adamc@750
|
704 | (x, all as (_, loc)) =>
|
adamc@750
|
705 (E.errorAt loc "Unsupported record field constructor";
|
adamc@750
|
706 Print.eprefaces' [("Name", CorePrint.p_con env x),
|
adamc@750
|
707 ("Constructor", CorePrint.p_con env all)];
|
adamc@750
|
708 ("", dummyTyp))) xts), loc)
|
adamc@25
|
709 in
|
adamc@25
|
710 case e of
|
adamc@179
|
711 L.EPrim p => ((L'.EPrim p, loc), fm)
|
adamc@179
|
712 | L.ERel n => ((L'.ERel n, loc), fm)
|
adamc@179
|
713 | L.ENamed n => ((L'.ENamed n, loc), fm)
|
adamc@193
|
714 | L.ECon (dk, pc, [], eo) =>
|
adamc@193
|
715 let
|
adamc@179
|
716 val (eo, fm) =
|
adamc@179
|
717 case eo of
|
adamc@179
|
718 NONE => (NONE, fm)
|
adamc@179
|
719 | SOME e =>
|
adamc@179
|
720 let
|
adamc@179
|
721 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
722 in
|
adamc@179
|
723 (SOME e, fm)
|
adamc@179
|
724 end
|
adamc@179
|
725 in
|
adamc@188
|
726 ((L'.ECon (dk, monoPatCon env pc, eo), loc), fm)
|
adamc@193
|
727 end
|
adamc@757
|
728 | L.ECon (L.Option, L.PConFfi {mod = "Basis", datatyp = "list", ...}, [t], NONE) =>
|
adamc@757
|
729 ((L'.ENone (listify (monoType env t)), loc), fm)
|
adamc@757
|
730 | L.ECon (L.Option, L.PConFfi {mod = "Basis", datatyp = "list", ...}, [t], SOME e) =>
|
adamc@757
|
731 let
|
adamc@757
|
732 val (e, fm) = monoExp (env, st, fm) e
|
adamc@757
|
733 in
|
adamc@757
|
734 ((L'.ESome (listify (monoType env t), e), loc), fm)
|
adamc@757
|
735 end
|
adamc@297
|
736 | L.ECon (L.Option, _, [t], NONE) =>
|
adamc@297
|
737 ((L'.ENone (monoType env t), loc), fm)
|
adamc@297
|
738 | L.ECon (L.Option, _, [t], SOME e) =>
|
adamc@297
|
739 let
|
adamc@297
|
740 val (e, fm) = monoExp (env, st, fm) e
|
adamc@297
|
741 in
|
adamc@297
|
742 ((L'.ESome (monoType env t, e), loc), fm)
|
adamc@297
|
743 end
|
adamc@193
|
744 | L.ECon _ => poly ()
|
adamc@94
|
745
|
adamc@387
|
746 | L.ECApp ((L.EFfi ("Basis", "eq"), _), t) =>
|
adamc@387
|
747 let
|
adamc@387
|
748 val t = monoType env t
|
adamc@387
|
749 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@387
|
750 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@387
|
751 in
|
adamc@387
|
752 ((L'.EAbs ("f", dom, dom,
|
adamc@387
|
753 (L'.ERel 0, loc)), loc), fm)
|
adamc@387
|
754 end
|
adamc@387
|
755 | L.ECApp ((L.EFfi ("Basis", "ne"), _), t) =>
|
adamc@387
|
756 let
|
adamc@387
|
757 val t = monoType env t
|
adamc@387
|
758 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@387
|
759 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@387
|
760 in
|
adamc@387
|
761 ((L'.EAbs ("f", dom, dom,
|
adamc@387
|
762 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@387
|
763 (L'.EAbs ("y", t, b,
|
adamc@387
|
764 (L'.EUnop ("!", (L'.EApp ((L'.EApp ((L'.ERel 2, loc),
|
adamc@387
|
765 (L'.ERel 1, loc)), loc),
|
adamc@387
|
766 (L'.ERel 0, loc)), loc)), loc)),
|
adamc@387
|
767 loc)),
|
adamc@387
|
768 loc)),
|
adamc@387
|
769 loc), fm)
|
adamc@387
|
770 end
|
adamc@387
|
771 | L.EFfi ("Basis", "eq_int") =>
|
adamc@387
|
772 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@387
|
773 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@387
|
774 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@387
|
775 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@387
|
776 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@387
|
777 fm)
|
adamc@394
|
778 | L.EFfi ("Basis", "eq_float") =>
|
adamc@394
|
779 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
780 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
781 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
782 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
783 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@394
|
784 fm)
|
adamc@388
|
785 | L.EFfi ("Basis", "eq_bool") =>
|
adamc@388
|
786 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
787 (L'.TFun ((L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@388
|
788 (L'.EAbs ("y", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
789 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
790 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@388
|
791 fm)
|
adamc@388
|
792 | L.EFfi ("Basis", "eq_string") =>
|
adamc@388
|
793 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc),
|
adamc@388
|
794 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@388
|
795 (L'.EAbs ("y", (L'.TFfi ("Basis", "string"), loc),
|
adamc@388
|
796 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
797 (L'.EBinop ("!strcmp", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@388
|
798 fm)
|
adamc@821
|
799 | L.EFfi ("Basis", "eq_char") =>
|
adamc@821
|
800 ((L'.EAbs ("x", (L'.TFfi ("Basis", "char"), loc),
|
adamc@821
|
801 (L'.TFun ((L'.TFfi ("Basis", "char"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@821
|
802 (L'.EAbs ("y", (L'.TFfi ("Basis", "char"), loc),
|
adamc@821
|
803 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@821
|
804 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@821
|
805 fm)
|
adamc@437
|
806 | L.EFfi ("Basis", "eq_time") =>
|
adamc@437
|
807 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
808 (L'.TFun ((L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@437
|
809 (L'.EAbs ("y", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
810 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@437
|
811 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@437
|
812 fm)
|
adamc@844
|
813
|
adamc@422
|
814 | L.ECApp ((L.EFfi ("Basis", "mkEq"), _), t) =>
|
adamc@422
|
815 let
|
adamc@422
|
816 val t = monoType env t
|
adamc@422
|
817 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@422
|
818 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@422
|
819 in
|
adamc@422
|
820 ((L'.EAbs ("f", dom, dom,
|
adamc@422
|
821 (L'.ERel 0, loc)), loc), fm)
|
adamc@422
|
822 end
|
adamc@387
|
823
|
adamc@417
|
824 | L.ECApp ((L.EFfi ("Basis", "zero"), _), t) =>
|
adamc@417
|
825 let
|
adamc@417
|
826 val t = monoType env t
|
adamc@417
|
827 in
|
adamc@417
|
828 ((L'.EAbs ("r", numTy t, t,
|
adamc@417
|
829 (L'.EField ((L'.ERel 0, loc), "Zero"), loc)), loc), fm)
|
adamc@417
|
830 end
|
adamc@389
|
831 | L.ECApp ((L.EFfi ("Basis", "neg"), _), t) =>
|
adamc@389
|
832 let
|
adamc@389
|
833 val t = monoType env t
|
adamc@389
|
834 in
|
adamc@389
|
835 ((L'.EAbs ("r", numTy t, (L'.TFun (t, t), loc),
|
adamc@389
|
836 (L'.EField ((L'.ERel 0, loc), "Neg"), loc)), loc), fm)
|
adamc@389
|
837 end
|
adamc@389
|
838 | L.ECApp ((L.EFfi ("Basis", "plus"), _), t) =>
|
adamc@389
|
839 let
|
adamc@389
|
840 val t = monoType env t
|
adamc@389
|
841 in
|
adamc@389
|
842 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
843 (L'.EField ((L'.ERel 0, loc), "Plus"), loc)), loc), fm)
|
adamc@389
|
844 end
|
adamc@389
|
845 | L.ECApp ((L.EFfi ("Basis", "minus"), _), t) =>
|
adamc@389
|
846 let
|
adamc@389
|
847 val t = monoType env t
|
adamc@389
|
848 in
|
adamc@389
|
849 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
850 (L'.EField ((L'.ERel 0, loc), "Minus"), loc)), loc), fm)
|
adamc@389
|
851 end
|
adamc@389
|
852 | L.ECApp ((L.EFfi ("Basis", "times"), _), t) =>
|
adamc@389
|
853 let
|
adamc@389
|
854 val t = monoType env t
|
adamc@389
|
855 in
|
adamc@389
|
856 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
857 (L'.EField ((L'.ERel 0, loc), "Times"), loc)), loc), fm)
|
adamc@389
|
858 end
|
adamc@775
|
859 | L.ECApp ((L.EFfi ("Basis", "divide"), _), t) =>
|
adamc@389
|
860 let
|
adamc@389
|
861 val t = monoType env t
|
adamc@389
|
862 in
|
adamc@389
|
863 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
864 (L'.EField ((L'.ERel 0, loc), "Div"), loc)), loc), fm)
|
adamc@389
|
865 end
|
adamc@389
|
866 | L.ECApp ((L.EFfi ("Basis", "mod"), _), t) =>
|
adamc@389
|
867 let
|
adamc@389
|
868 val t = monoType env t
|
adamc@389
|
869 in
|
adamc@389
|
870 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
871 (L'.EField ((L'.ERel 0, loc), "Mod"), loc)), loc), fm)
|
adamc@389
|
872 end
|
adamc@389
|
873 | L.EFfi ("Basis", "num_int") =>
|
adamc@389
|
874 let
|
adamc@389
|
875 fun intBin s =
|
adamc@389
|
876 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
877 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "int"), loc)), loc),
|
adamc@389
|
878 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
879 (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
880 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@389
|
881 in
|
adamc@389
|
882 numEx ((L'.TFfi ("Basis", "int"), loc),
|
adamc@417
|
883 Prim.Int (Int64.fromInt 0),
|
adamc@389
|
884 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
885 (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
886 (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc),
|
adamc@389
|
887 intBin "+",
|
adamc@389
|
888 intBin "-",
|
adamc@389
|
889 intBin "*",
|
adamc@389
|
890 intBin "/",
|
adamc@389
|
891 intBin "%")
|
adamc@389
|
892 end
|
adamc@390
|
893 | L.EFfi ("Basis", "num_float") =>
|
adamc@390
|
894 let
|
adamc@390
|
895 fun floatBin s =
|
adamc@390
|
896 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
897 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "float"), loc)), loc),
|
adamc@390
|
898 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
899 (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
900 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@390
|
901 in
|
adamc@390
|
902 numEx ((L'.TFfi ("Basis", "float"), loc),
|
adamc@417
|
903 Prim.Float 0.0,
|
adamc@390
|
904 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
905 (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
906 (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc),
|
adamc@390
|
907 floatBin "+",
|
adamc@390
|
908 floatBin "-",
|
adamc@390
|
909 floatBin "*",
|
adamc@390
|
910 floatBin "/",
|
adamc@390
|
911 floatBin "fmod")
|
adamc@390
|
912 end
|
adamc@391
|
913
|
adamc@391
|
914 | L.ECApp ((L.EFfi ("Basis", "lt"), _), t) =>
|
adamc@391
|
915 let
|
adamc@391
|
916 val t = monoType env t
|
adamc@391
|
917 in
|
adamc@391
|
918 ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc),
|
adamc@391
|
919 (L'.EField ((L'.ERel 0, loc), "Lt"), loc)), loc), fm)
|
adamc@391
|
920 end
|
adamc@391
|
921 | L.ECApp ((L.EFfi ("Basis", "le"), _), t) =>
|
adamc@391
|
922 let
|
adamc@391
|
923 val t = monoType env t
|
adamc@391
|
924 in
|
adamc@391
|
925 ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc),
|
adamc@391
|
926 (L'.EField ((L'.ERel 0, loc), "Le"), loc)), loc), fm)
|
adamc@391
|
927 end
|
adamc@392
|
928 | L.ECApp ((L.EFfi ("Basis", "gt"), _), t) =>
|
adamc@392
|
929 let
|
adamc@392
|
930 val t = monoType env t
|
adamc@392
|
931 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@392
|
932 in
|
adamc@392
|
933 ((L'.EAbs ("f", ordTy t, (L'.TFun (t, (L'.TFun (t, b), loc)), loc),
|
adamc@392
|
934 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@392
|
935 (L'.EAbs ("y", t, b,
|
adamc@392
|
936 (L'.EUnop ("!",
|
adamc@392
|
937 (L'.EApp ((L'.EApp ((L'.EField ((L'.ERel 2, loc),
|
adamc@392
|
938 "Le"), loc),
|
adamc@392
|
939 (L'.ERel 1, loc)), loc),
|
adamc@392
|
940 (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@392
|
941 loc)),
|
adamc@392
|
942 loc), fm)
|
adamc@392
|
943 end
|
adamc@392
|
944 | L.ECApp ((L.EFfi ("Basis", "ge"), _), t) =>
|
adamc@392
|
945 let
|
adamc@392
|
946 val t = monoType env t
|
adamc@392
|
947 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@392
|
948 in
|
adamc@392
|
949 ((L'.EAbs ("f", ordTy t, (L'.TFun (t, (L'.TFun (t, b), loc)), loc),
|
adamc@392
|
950 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@392
|
951 (L'.EAbs ("y", t, b,
|
adamc@392
|
952 (L'.EUnop ("!",
|
adamc@392
|
953 (L'.EApp ((L'.EApp ((L'.EField ((L'.ERel 2, loc),
|
adamc@392
|
954 "Lt"), loc),
|
adamc@392
|
955 (L'.ERel 1, loc)), loc),
|
adamc@392
|
956 (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@392
|
957 loc)),
|
adamc@392
|
958 loc), fm)
|
adamc@392
|
959 end
|
adamc@391
|
960 | L.EFfi ("Basis", "ord_int") =>
|
adamc@391
|
961 let
|
adamc@391
|
962 fun intBin s =
|
adamc@391
|
963 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
964 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@391
|
965 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
966 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@391
|
967 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@391
|
968 in
|
adamc@391
|
969 ordEx ((L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
970 intBin "<",
|
adamc@391
|
971 intBin "<=")
|
adamc@391
|
972 end
|
adamc@394
|
973 | L.EFfi ("Basis", "ord_float") =>
|
adamc@394
|
974 let
|
adamc@394
|
975 fun floatBin s =
|
adamc@394
|
976 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
977 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
978 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
979 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
980 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@394
|
981 in
|
adamc@394
|
982 ordEx ((L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
983 floatBin "<",
|
adamc@394
|
984 floatBin "<=")
|
adamc@394
|
985 end
|
adamc@394
|
986 | L.EFfi ("Basis", "ord_bool") =>
|
adamc@394
|
987 let
|
adamc@394
|
988 fun boolBin s =
|
adamc@394
|
989 (L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
990 (L'.TFun ((L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
991 (L'.EAbs ("y", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
992 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
993 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@394
|
994 in
|
adamc@394
|
995 ordEx ((L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
996 boolBin "<",
|
adamc@394
|
997 boolBin "<=")
|
adamc@394
|
998 end
|
adamc@395
|
999 | L.EFfi ("Basis", "ord_string") =>
|
adamc@395
|
1000 let
|
adamc@395
|
1001 fun boolBin s =
|
adamc@395
|
1002 (L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
1003 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@395
|
1004 (L'.EAbs ("y", (L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
1005 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@395
|
1006 (L'.EBinop (s,
|
adamc@395
|
1007 (L'.EBinop ("strcmp",
|
adamc@395
|
1008 (L'.ERel 1, loc),
|
adamc@395
|
1009 (L'.ERel 0, loc)), loc),
|
adamc@395
|
1010 (L'.EPrim (Prim.Int (Int64.fromInt 0)), loc)), loc)), loc)), loc)
|
adamc@395
|
1011 in
|
adamc@395
|
1012 ordEx ((L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
1013 boolBin "<",
|
adamc@395
|
1014 boolBin "<=")
|
adamc@395
|
1015 end
|
adamc@821
|
1016 | L.EFfi ("Basis", "ord_char") =>
|
adamc@821
|
1017 let
|
adamc@821
|
1018 fun charBin s =
|
adamc@821
|
1019 (L'.EAbs ("x", (L'.TFfi ("Basis", "char"), loc),
|
adamc@821
|
1020 (L'.TFun ((L'.TFfi ("Basis", "char"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@821
|
1021 (L'.EAbs ("y", (L'.TFfi ("Basis", "char"), loc),
|
adamc@821
|
1022 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@821
|
1023 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@821
|
1024 in
|
adamc@821
|
1025 ordEx ((L'.TFfi ("Basis", "char"), loc),
|
adamc@821
|
1026 charBin "<",
|
adamc@821
|
1027 charBin "<=")
|
adamc@821
|
1028 end
|
adamc@437
|
1029 | L.EFfi ("Basis", "ord_time") =>
|
adamc@437
|
1030 let
|
adamc@437
|
1031 fun boolBin s =
|
adamc@437
|
1032 (L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
1033 (L'.TFun ((L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@437
|
1034 (L'.EAbs ("y", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
1035 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@437
|
1036 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@437
|
1037 in
|
adamc@437
|
1038 ordEx ((L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
1039 boolBin "<",
|
adamc@437
|
1040 boolBin "<=")
|
adamc@437
|
1041 end
|
adamc@961
|
1042 | L.ECApp ((L.EFfi ("Basis", "mkOrd"), _), t) =>
|
adamc@961
|
1043 let
|
adamc@961
|
1044 val t = monoType env t
|
adamc@961
|
1045 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@961
|
1046 val dom = ordTy t
|
adamc@961
|
1047 in
|
adamc@961
|
1048 ((L'.EAbs ("f", dom, dom,
|
adamc@961
|
1049 (L'.ERel 0, loc)), loc), fm)
|
adamc@961
|
1050 end
|
adamc@389
|
1051
|
adamc@286
|
1052 | L.ECApp ((L.EFfi ("Basis", "show"), _), t) =>
|
adamc@286
|
1053 let
|
adamc@286
|
1054 val t = monoType env t
|
adamc@286
|
1055 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@286
|
1056 in
|
adamc@286
|
1057 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@286
|
1058 (L'.ERel 0, loc)), loc), fm)
|
adamc@286
|
1059 end
|
adamc@286
|
1060 | L.EFfi ("Basis", "show_int") =>
|
adamc@286
|
1061 ((L'.EFfi ("Basis", "intToString"), loc), fm)
|
adamc@286
|
1062 | L.EFfi ("Basis", "show_float") =>
|
adamc@286
|
1063 ((L'.EFfi ("Basis", "floatToString"), loc), fm)
|
adamc@286
|
1064 | L.EFfi ("Basis", "show_string") =>
|
adamc@286
|
1065 let
|
adamc@286
|
1066 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@286
|
1067 in
|
adamc@286
|
1068 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), fm)
|
adamc@286
|
1069 end
|
adamc@1065
|
1070 | L.EFfi ("Basis", "show_url") =>
|
adamc@1065
|
1071 let
|
adamc@1065
|
1072 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@1065
|
1073 in
|
adamc@1065
|
1074 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), fm)
|
adamc@1065
|
1075 end
|
adamc@821
|
1076 | L.EFfi ("Basis", "show_char") =>
|
adamc@821
|
1077 ((L'.EFfi ("Basis", "charToString"), loc), fm)
|
adamc@286
|
1078 | L.EFfi ("Basis", "show_bool") =>
|
adamc@286
|
1079 ((L'.EFfi ("Basis", "boolToString"), loc), fm)
|
adamc@436
|
1080 | L.EFfi ("Basis", "show_time") =>
|
adamc@436
|
1081 ((L'.EFfi ("Basis", "timeToString"), loc), fm)
|
adamc@727
|
1082 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "show_xml"), _), _),_), _), _), _) =>
|
adamc@727
|
1083 let
|
adamc@727
|
1084 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@727
|
1085 in
|
adamc@727
|
1086 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), fm)
|
adamc@727
|
1087 end
|
adamc@452
|
1088 | L.ECApp ((L.EFfi ("Basis", "mkShow"), _), t) =>
|
adamc@452
|
1089 let
|
adamc@452
|
1090 val t = monoType env t
|
adamc@452
|
1091 val b = (L'.TFfi ("Basis", "string"), loc)
|
adamc@452
|
1092 val dom = (L'.TFun (t, b), loc)
|
adamc@452
|
1093 in
|
adamc@452
|
1094 ((L'.EAbs ("f", dom, dom,
|
adamc@452
|
1095 (L'.ERel 0, loc)), loc), fm)
|
adamc@452
|
1096 end
|
adamc@286
|
1097
|
adamc@290
|
1098 | L.ECApp ((L.EFfi ("Basis", "read"), _), t) =>
|
adamc@290
|
1099 let
|
adamc@290
|
1100 val t = monoType env t
|
adamc@290
|
1101 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@290
|
1102 in
|
adamc@292
|
1103 ((L'.EAbs ("f", readType (t, loc), readType' (t, loc),
|
adamc@292
|
1104 (L'.EField ((L'.ERel 0, loc), "Read"), loc)), loc), fm)
|
adamc@292
|
1105 end
|
adamc@292
|
1106 | L.ECApp ((L.EFfi ("Basis", "readError"), _), t) =>
|
adamc@292
|
1107 let
|
adamc@292
|
1108 val t = monoType env t
|
adamc@292
|
1109 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@292
|
1110 in
|
adamc@292
|
1111 ((L'.EAbs ("f", readType (t, loc), readErrType (t, loc),
|
adamc@292
|
1112 (L'.EField ((L'.ERel 0, loc), "ReadError"), loc)), loc), fm)
|
adamc@290
|
1113 end
|
adamc@777
|
1114 | L.ECApp ((L.EFfi ("Basis", "mkRead"), _), t) =>
|
adamc@777
|
1115 let
|
adamc@777
|
1116 val t = monoType env t
|
adamc@777
|
1117 val b = (L'.TFfi ("Basis", "string"), loc)
|
adamc@777
|
1118 val b' = (L'.TOption b, loc)
|
adamc@777
|
1119 val dom = (L'.TFun (t, b), loc)
|
adamc@777
|
1120 val dom' = (L'.TFun (t, b'), loc)
|
adamc@777
|
1121 in
|
adamc@777
|
1122 ((L'.EAbs ("f", dom, (L'.TFun (dom', readType (t, loc)), loc),
|
adamc@777
|
1123 (L'.EAbs ("f'", dom', readType (t, loc),
|
adamc@777
|
1124 (L'.ERecord [("Read", (L'.ERel 0, loc), dom),
|
adamc@777
|
1125 ("ReadError", (L'.ERel 1, loc), dom')], loc)), loc)), loc),
|
adamc@777
|
1126 fm)
|
adamc@777
|
1127 end
|
adamc@290
|
1128 | L.EFfi ("Basis", "read_int") =>
|
adamc@292
|
1129 let
|
adamc@292
|
1130 val t = (L'.TFfi ("Basis", "int"), loc)
|
adamc@292
|
1131 in
|
adamc@292
|
1132 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToInt"), loc), readType' (t, loc)),
|
adamc@292
|
1133 ("ReadError", (L'.EFfi ("Basis", "stringToInt_error"), loc), readErrType (t, loc))],
|
adamc@292
|
1134 loc),
|
adamc@292
|
1135 fm)
|
adamc@292
|
1136 end
|
adamc@290
|
1137 | L.EFfi ("Basis", "read_float") =>
|
adamc@292
|
1138 let
|
adamc@292
|
1139 val t = (L'.TFfi ("Basis", "float"), loc)
|
adamc@292
|
1140 in
|
adamc@292
|
1141 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToFloat"), loc), readType' (t, loc)),
|
adamc@292
|
1142 ("ReadError", (L'.EFfi ("Basis", "stringToFloat_error"), loc), readErrType (t, loc))],
|
adamc@292
|
1143 loc),
|
adamc@292
|
1144 fm)
|
adamc@292
|
1145 end
|
adamc@290
|
1146 | L.EFfi ("Basis", "read_string") =>
|
adamc@290
|
1147 let
|
adamc@290
|
1148 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@290
|
1149 in
|
adamc@292
|
1150 ((L'.ERecord [("Read", (L'.EAbs ("s", s, (L'.TOption s, loc),
|
adamc@292
|
1151 (L'.ESome (s, (L'.ERel 0, loc)), loc)), loc), readType' (s, loc)),
|
adamc@292
|
1152 ("ReadError", (L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), readErrType (s, loc))], loc),
|
adamc@292
|
1153 fm)
|
adamc@290
|
1154 end
|
adamc@821
|
1155 | L.EFfi ("Basis", "read_char") =>
|
adamc@821
|
1156 let
|
adamc@821
|
1157 val t = (L'.TFfi ("Basis", "char"), loc)
|
adamc@821
|
1158 in
|
adamc@821
|
1159 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToChar"), loc), readType' (t, loc)),
|
adamc@821
|
1160 ("ReadError", (L'.EFfi ("Basis", "stringToChar_error"), loc), readErrType (t, loc))],
|
adamc@821
|
1161 loc),
|
adamc@821
|
1162 fm)
|
adamc@821
|
1163 end
|
adamc@290
|
1164 | L.EFfi ("Basis", "read_bool") =>
|
adamc@292
|
1165 let
|
adamc@292
|
1166 val t = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@292
|
1167 in
|
adamc@292
|
1168 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToBool"), loc), readType' (t, loc)),
|
adamc@292
|
1169 ("ReadError", (L'.EFfi ("Basis", "stringToBool_error"), loc), readErrType (t, loc))],
|
adamc@292
|
1170 loc),
|
adamc@292
|
1171 fm)
|
adamc@292
|
1172 end
|
adamc@436
|
1173 | L.EFfi ("Basis", "read_time") =>
|
adamc@436
|
1174 let
|
adamc@436
|
1175 val t = (L'.TFfi ("Basis", "time"), loc)
|
adamc@436
|
1176 in
|
adamc@436
|
1177 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToTime"), loc), readType' (t, loc)),
|
adamc@436
|
1178 ("ReadError", (L'.EFfi ("Basis", "stringToTime_error"), loc), readErrType (t, loc))],
|
adamc@436
|
1179 loc),
|
adamc@436
|
1180 fm)
|
adamc@436
|
1181 end
|
adamc@290
|
1182
|
adamc@820
|
1183 | L.EFfi ("Basis", "transaction_monad") => ((L'.ERecord [], loc), fm)
|
adamc@820
|
1184 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), (L.CFfi ("Basis", "transaction"), _)), _), t) =>
|
adamc@252
|
1185 let
|
adamc@252
|
1186 val t = monoType env t
|
adamc@252
|
1187 in
|
adamc@820
|
1188 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), t), loc)), loc),
|
adamc@820
|
1189 (L'.EAbs ("x", t,
|
adamc@820
|
1190 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@820
|
1191 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@820
|
1192 (L'.ERel 1, loc)), loc)), loc)), loc),
|
adamc@820
|
1193 fm)
|
adamc@252
|
1194 end
|
adamc@820
|
1195 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), (L.CFfi ("Basis", "transaction"), _)), _),
|
adamc@820
|
1196 t1), _), t2) =>
|
adamc@251
|
1197 let
|
adamc@251
|
1198 val t1 = monoType env t1
|
adamc@251
|
1199 val t2 = monoType env t2
|
adamc@251
|
1200 val un = (L'.TRecord [], loc)
|
adamc@252
|
1201 val mt1 = (L'.TFun (un, t1), loc)
|
adamc@252
|
1202 val mt2 = (L'.TFun (un, t2), loc)
|
adamc@251
|
1203 in
|
adamc@820
|
1204 ((L'.EAbs ("_", un,
|
adamc@820
|
1205 (L'.TFun (mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc)), loc)), loc),
|
adamc@820
|
1206 (L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc)), loc),
|
adamc@820
|
1207 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc),
|
adamc@820
|
1208 (L'.EAbs ("_", un, un,
|
adamc@820
|
1209 (L'.ELet ("r", t1, (L'.EApp ((L'.ERel 2, loc),
|
adamc@820
|
1210 (L'.ERecord [], loc)), loc),
|
adamc@820
|
1211 (L'.EApp (
|
adamc@820
|
1212 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc),
|
adamc@820
|
1213 (L'.ERecord [], loc)),
|
adamc@820
|
1214 loc)), loc)), loc)), loc)), loc)), loc),
|
adamc@251
|
1215 fm)
|
adamc@251
|
1216 end
|
adamc@697
|
1217
|
adamc@1021
|
1218 | L.EApp ((L.ECApp ((L.EFfi ("Basis", "recv"), _), t1), _), ch) =>
|
adamc@670
|
1219 let
|
adamc@1021
|
1220 val un = (L'.TRecord [], loc)
|
adamc@670
|
1221 val t1 = monoType env t1
|
adamc@670
|
1222 val (ch, fm) = monoExp (env, st, fm) ch
|
adamc@670
|
1223 in
|
adamc@1021
|
1224 ((L'.EAbs ("_", un, un, (L'.ERecv (liftExpInExp 0 ch, t1), loc)), loc), fm)
|
adamc@670
|
1225 end
|
adamc@697
|
1226 | L.EFfiApp ("Basis", "recv", _) => poly ()
|
adamc@697
|
1227
|
adamc@1021
|
1228 | L.EFfiApp ("Basis", "sleep", [n]) =>
|
adamc@695
|
1229 let
|
adamc@695
|
1230 val (n, fm) = monoExp (env, st, fm) n
|
adamc@695
|
1231 in
|
adamc@1021
|
1232 ((L'.ESleep n, loc), fm)
|
adamc@695
|
1233 end
|
adamc@697
|
1234 | L.EFfiApp ("Basis", "sleep", _) => poly ()
|
adamc@251
|
1235
|
adamc@565
|
1236 | L.ECApp ((L.EFfi ("Basis", "source"), _), t) =>
|
adamc@565
|
1237 let
|
adamc@565
|
1238 val t = monoType env t
|
adamc@565
|
1239 in
|
adamc@577
|
1240 ((L'.EAbs ("x", t, (L'.TFun ((L'.TRecord [], loc), (L'.TSource, loc)), loc),
|
adamc@577
|
1241 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TSource, loc),
|
adamc@577
|
1242 (L'.EFfiApp ("Basis", "new_client_source",
|
adamc@815
|
1243 [(L'.EJavaScript (L'.Source t, (L'.ERel 1, loc)), loc)]),
|
adamc@578
|
1244 loc)), loc)),
|
adamc@565
|
1245 loc),
|
adamc@565
|
1246 fm)
|
adamc@565
|
1247 end
|
adamc@575
|
1248 | L.ECApp ((L.EFfi ("Basis", "set"), _), t) =>
|
adamc@575
|
1249 let
|
adamc@575
|
1250 val t = monoType env t
|
adamc@575
|
1251 in
|
adamc@577
|
1252 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@575
|
1253 (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc)), loc),
|
adamc@575
|
1254 (L'.EAbs ("v", t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc),
|
adamc@575
|
1255 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@575
|
1256 (L'.EFfiApp ("Basis", "set_client_source",
|
adamc@577
|
1257 [(L'.ERel 2, loc),
|
adamc@590
|
1258 (L'.EJavaScript (L'.Source t,
|
adamc@815
|
1259 (L'.ERel 1, loc)), loc)]),
|
adamc@575
|
1260 loc)), loc)), loc)), loc),
|
adamc@575
|
1261 fm)
|
adamc@575
|
1262 end
|
adamc@601
|
1263 | L.ECApp ((L.EFfi ("Basis", "get"), _), t) =>
|
adamc@601
|
1264 let
|
adamc@601
|
1265 val t = monoType env t
|
adamc@601
|
1266 in
|
adamc@601
|
1267 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@601
|
1268 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@601
|
1269 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@601
|
1270 (L'.EFfiApp ("Basis", "get_client_source",
|
adamc@601
|
1271 [(L'.ERel 1, loc)]),
|
adamc@601
|
1272 loc)), loc)), loc),
|
adamc@601
|
1273 fm)
|
adamc@601
|
1274 end
|
adamc@841
|
1275 | L.ECApp ((L.EFfi ("Basis", "current"), _), t) =>
|
adamc@841
|
1276 let
|
adamc@841
|
1277 val t = monoType env t
|
adamc@841
|
1278 in
|
adamc@841
|
1279 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@841
|
1280 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@841
|
1281 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@841
|
1282 (L'.EFfiApp ("Basis", "current",
|
adamc@841
|
1283 [(L'.ERel 1, loc)]),
|
adamc@841
|
1284 loc)), loc)), loc),
|
adamc@841
|
1285 fm)
|
adamc@841
|
1286 end
|
adamc@565
|
1287
|
adamc@694
|
1288 | L.EFfiApp ("Basis", "spawn", [e]) =>
|
adamc@694
|
1289 let
|
adamc@694
|
1290 val (e, fm) = monoExp (env, st, fm) e
|
adamc@694
|
1291 in
|
adamc@1021
|
1292 ((L'.ESpawn e, loc), fm)
|
adamc@694
|
1293 end
|
adamc@694
|
1294
|
adamc@820
|
1295 | L.EFfi ("Basis", "signal_monad") => ((L'.ERecord [], loc), fm)
|
adamc@820
|
1296 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), (L.CFfi ("Basis", "signal"), _)), _), t) =>
|
adamc@568
|
1297 let
|
adamc@568
|
1298 val t = monoType env t
|
adamc@568
|
1299 in
|
adamc@820
|
1300 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (t, (L'.TSignal t, loc)), loc),
|
adamc@820
|
1301 (L'.EAbs ("x", t, (L'.TSignal t, loc),
|
adamc@820
|
1302 (L'.ESignalReturn (L'.ERel 0, loc), loc)), loc)), loc),
|
adamc@568
|
1303 fm)
|
adamc@568
|
1304 end
|
adamc@820
|
1305 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), (L.CFfi ("Basis", "signal"), _)), _),
|
adamc@820
|
1306 t1), _), t2) =>
|
adamc@572
|
1307 let
|
adamc@572
|
1308 val t1 = monoType env t1
|
adamc@572
|
1309 val t2 = monoType env t2
|
adamc@572
|
1310 val un = (L'.TRecord [], loc)
|
adamc@572
|
1311 val mt1 = (L'.TSignal t1, loc)
|
adamc@572
|
1312 val mt2 = (L'.TSignal t2, loc)
|
adamc@572
|
1313 in
|
adamc@820
|
1314 ((L'.EAbs ("_", un, (L'.TFun (mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), mt2), loc)), loc),
|
adamc@820
|
1315 (L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), mt2), loc),
|
adamc@820
|
1316 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), mt2,
|
adamc@820
|
1317 (L'.ESignalBind ((L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@820
|
1318 loc),
|
adamc@572
|
1319 fm)
|
adamc@572
|
1320 end
|
adamc@574
|
1321 | L.ECApp ((L.EFfi ("Basis", "signal"), _), t) =>
|
adamc@574
|
1322 let
|
adamc@574
|
1323 val t = monoType env t
|
adamc@574
|
1324 in
|
adamc@574
|
1325 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TSignal t, loc),
|
adamc@574
|
1326 (L'.ESignalSource (L'.ERel 0, loc), loc)), loc),
|
adamc@574
|
1327 fm)
|
adamc@574
|
1328 end
|
adamc@568
|
1329
|
adamc@462
|
1330 | L.ECApp ((L.EFfi ("Basis", "getCookie"), _), t) =>
|
adamc@462
|
1331 let
|
adamc@462
|
1332 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1333 val un = (L'.TRecord [], loc)
|
adamc@462
|
1334 val t = monoType env t
|
adamc@462
|
1335 in
|
adamc@462
|
1336 ((L'.EAbs ("c", s, (L'.TFun (un, s), loc),
|
adamc@462
|
1337 (L'.EAbs ("_", un, s,
|
adamc@463
|
1338 (L'.EUnurlify ((L'.EFfiApp ("Basis", "get_cookie", [(L'.ERel 1, loc)]), loc),
|
adamc@463
|
1339 t),
|
adamc@463
|
1340 loc)), loc)), loc),
|
adamc@462
|
1341 fm)
|
adamc@462
|
1342 end
|
adamc@462
|
1343
|
adamc@462
|
1344 | L.ECApp ((L.EFfi ("Basis", "setCookie"), _), t) =>
|
adamc@462
|
1345 let
|
adamc@462
|
1346 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1347 val un = (L'.TRecord [], loc)
|
adamc@462
|
1348 val t = monoType env t
|
adamc@1050
|
1349 val rt = (L'.TRecord [("Value", t),
|
adamc@1050
|
1350 ("Expires", (L'.TOption (L'.TFfi ("Basis", "time"),
|
adamc@1050
|
1351 loc), loc)),
|
adamc@1050
|
1352 ("Secure", (L'.TFfi ("Basis", "bool"), loc))], loc)
|
adamc@1050
|
1353
|
adamc@1050
|
1354 fun fd x = (L'.EField ((L'.ERel 1, loc), x), loc)
|
adamc@1050
|
1355 val (e, fm) = urlifyExp env fm (fd "Value", t)
|
adamc@462
|
1356 in
|
adamc@1050
|
1357 ((L'.EAbs ("c", s, (L'.TFun (rt, (L'.TFun (un, un), loc)), loc),
|
adamc@1050
|
1358 (L'.EAbs ("r", rt, (L'.TFun (un, un), loc),
|
adamc@462
|
1359 (L'.EAbs ("_", un, un,
|
adamc@764
|
1360 (L'.EFfiApp ("Basis", "set_cookie", [(L'.EPrim (Prim.String
|
adamc@764
|
1361 (Settings.getUrlPrefix ())),
|
adamc@466
|
1362 loc),
|
adamc@466
|
1363 (L'.ERel 2, loc),
|
adamc@1050
|
1364 e,
|
adamc@1050
|
1365 fd "Expires",
|
adamc@1050
|
1366 fd "Secure"])
|
adamc@1050
|
1367 , loc)), loc)), loc)), loc),
|
adamc@1050
|
1368 fm)
|
adamc@1050
|
1369 end
|
adamc@1050
|
1370
|
adamc@1050
|
1371 | L.ECApp ((L.EFfi ("Basis", "clearCookie"), _), t) =>
|
adamc@1050
|
1372 let
|
adamc@1050
|
1373 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@1050
|
1374 val un = (L'.TRecord [], loc)
|
adamc@1050
|
1375 in
|
adamc@1050
|
1376 ((L'.EAbs ("c", s, (L'.TFun (un, un), loc),
|
adamc@1050
|
1377 (L'.EAbs ("_", un, un,
|
adamc@1050
|
1378 (L'.EFfiApp ("Basis", "clear_cookie",
|
adamc@1050
|
1379 [(L'.EPrim (Prim.String
|
adamc@1050
|
1380 (Settings.getUrlPrefix ())),
|
adamc@1050
|
1381 loc),
|
adamc@1050
|
1382 (L'.ERel 1, loc)]),
|
adamc@462
|
1383 loc)), loc)), loc),
|
adamc@462
|
1384 fm)
|
adamc@1050
|
1385 end
|
adamc@462
|
1386
|
adamc@668
|
1387 | L.ECApp ((L.EFfi ("Basis", "channel"), _), t) =>
|
adamc@668
|
1388 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "channel"), loc),
|
adamc@668
|
1389 (L'.EFfiApp ("Basis", "new_channel", [(L'.ERecord [], loc)]), loc)), loc),
|
adamc@668
|
1390 fm)
|
adamc@668
|
1391 | L.ECApp ((L.EFfi ("Basis", "send"), _), t) =>
|
adamc@668
|
1392 let
|
adamc@668
|
1393 val t = monoType env t
|
adamc@668
|
1394 val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
|
adamc@668
|
1395 in
|
adamc@668
|
1396 ((L'.EAbs ("ch", (L'.TFfi ("Basis", "channel"), loc),
|
adamc@668
|
1397 (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc)), loc),
|
adamc@668
|
1398 (L'.EAbs ("v", t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc),
|
adamc@668
|
1399 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@668
|
1400 (L'.EFfiApp ("Basis", "send",
|
adamc@668
|
1401 [(L'.ERel 2, loc),
|
adamc@668
|
1402 e]),
|
adamc@668
|
1403 loc)), loc)), loc)), loc),
|
adamc@668
|
1404 fm)
|
adamc@668
|
1405 end
|
adamc@668
|
1406
|
adamc@707
|
1407 | L.ECApp ((L.EFfi ("Basis", "no_primary_key"), _), _) =>
|
adamc@707
|
1408 ((L'.EPrim (Prim.String ""), loc),
|
adamc@707
|
1409 fm)
|
adamc@707
|
1410 | L.ECApp (
|
adamc@707
|
1411 (L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "primary_key"), _), _), _), t), _),
|
adamc@707
|
1412 nm), _),
|
adamc@707
|
1413 (L.CRecord (_, unique), _)) =>
|
adamc@707
|
1414 let
|
adamc@707
|
1415 val unique = (nm, t) :: unique
|
adamc@707
|
1416 val witnesses = (L'.TRecord (map (fn (nm, _) => (monoName env nm, (L'.TRecord [], loc))) unique), loc)
|
adamc@707
|
1417 in
|
adamc@707
|
1418 ((L'.EAbs ("_", witnesses, (L'.TFfi ("Basis", "string"), loc),
|
adamc@707
|
1419 (L'.EPrim (Prim.String
|
adamc@707
|
1420 (String.concatWith ", "
|
adamc@877
|
1421 (map (fn (x, _) =>
|
adamc@877
|
1422 "uw_" ^ monoNameLc env x
|
adamc@877
|
1423 ^ (if #textKeysNeedLengths (Settings.currentDbms ())
|
adamc@877
|
1424 andalso isBlobby t then
|
adamc@877
|
1425 "(767)"
|
adamc@877
|
1426 else
|
adamc@877
|
1427 "")) unique))),
|
adamc@707
|
1428 loc)), loc),
|
adamc@707
|
1429 fm)
|
adamc@707
|
1430 end
|
adamc@707
|
1431
|
adamc@704
|
1432 | L.ECApp ((L.EFfi ("Basis", "no_constraint"), _), _) =>
|
adamc@704
|
1433 ((L'.ERecord [], loc),
|
adamc@704
|
1434 fm)
|
adamc@705
|
1435 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "one_constraint"), _), _), _), _), _), (L.CName name, _)) =>
|
adamc@704
|
1436 ((L'.EAbs ("c",
|
adamc@704
|
1437 (L'.TFfi ("Basis", "string"), loc),
|
adamc@704
|
1438 (L'.TFfi ("Basis", "sql_constraints"), loc),
|
adamc@704
|
1439 (L'.ERecord [(name, (L'.ERel 0, loc), (L'.TFfi ("Basis", "string"), loc))], loc)), loc),
|
adamc@704
|
1440 fm)
|
adamc@705
|
1441 | L.ECApp (
|
adamc@705
|
1442 (L.ECApp (
|
adamc@705
|
1443 (L.ECApp (
|
adamc@705
|
1444 (L.EFfi ("Basis", "join_constraints"), _),
|
adamc@705
|
1445 _), _),
|
adamc@705
|
1446 _), _),
|
adamc@705
|
1447 _) =>
|
adamc@704
|
1448 let
|
adamc@704
|
1449 val constraints = (L'.TFfi ("Basis", "sql_constraints"), loc)
|
adamc@704
|
1450 in
|
adamc@704
|
1451 ((L'.EAbs ("cs1", constraints, (L'.TFun (constraints, constraints), loc),
|
adamc@704
|
1452 (L'.EAbs ("cs2", constraints, constraints,
|
adamc@704
|
1453 (L'.EStrcat ((L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@704
|
1454 fm)
|
adamc@704
|
1455 end
|
adamc@704
|
1456
|
adamc@705
|
1457 | L.ECApp (
|
adamc@705
|
1458 (L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "unique"), _), _), _), t), _),
|
adamc@705
|
1459 nm), _),
|
adamc@705
|
1460 (L.CRecord (_, unique), _)) =>
|
adamc@705
|
1461 let
|
adamc@705
|
1462 val unique = (nm, t) :: unique
|
adamc@705
|
1463 in
|
adamc@705
|
1464 ((L'.EPrim (Prim.String ("UNIQUE ("
|
adamc@877
|
1465 ^ String.concatWith ", "
|
adamc@877
|
1466 (map (fn (x, t) => "uw_" ^ monoNameLc env x
|
adamc@877
|
1467 ^ (if #textKeysNeedLengths (Settings.currentDbms ())
|
adamc@877
|
1468 andalso isBlobby t then
|
adamc@877
|
1469 "(767)"
|
adamc@877
|
1470 else
|
adamc@877
|
1471 "")) unique)
|
adamc@705
|
1472 ^ ")")), loc),
|
adamc@705
|
1473 fm)
|
adamc@705
|
1474 end
|
adamc@704
|
1475
|
adamc@712
|
1476 | L.ECApp ((L.EFfi ("Basis", "linkable_same"), loc), _) =>
|
adamc@712
|
1477 ((L'.ERecord [], loc), fm)
|
adamc@712
|
1478 | L.ECApp ((L.EFfi ("Basis", "linkable_from_nullable"), loc), _) =>
|
adamc@712
|
1479 ((L'.ERecord [], loc), fm)
|
adamc@712
|
1480 | L.ECApp ((L.EFfi ("Basis", "linkable_to_nullable"), loc), _) =>
|
adamc@712
|
1481 ((L'.ERecord [], loc), fm)
|
adamc@712
|
1482
|
adamc@709
|
1483 | L.EFfi ("Basis", "mat_nil") =>
|
adamc@709
|
1484 let
|
adamc@709
|
1485 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
1486 val stringE = (L'.EPrim (Prim.String ""), loc)
|
adamc@709
|
1487 in
|
adamc@709
|
1488 ((L'.ERecord [("1", stringE, string),
|
adamc@709
|
1489 ("2", stringE, string)], loc), fm)
|
adamc@709
|
1490 end
|
adamc@709
|
1491 | L.ECApp (
|
adamc@709
|
1492 (L.ECApp (
|
adamc@709
|
1493 (L.ECApp (
|
adamc@709
|
1494 (L.ECApp (
|
adamc@709
|
1495 (L.ECApp (
|
adamc@712
|
1496 (L.ECApp (
|
adamc@712
|
1497 (L.EFfi ("Basis", "mat_cons"), _),
|
adamc@712
|
1498 _), _),
|
adamc@709
|
1499 _), _),
|
adamc@709
|
1500 _), _),
|
adamc@709
|
1501 _), _),
|
adamc@709
|
1502 (L.CName nm1, _)), _),
|
adamc@709
|
1503 (L.CName nm2, _)) =>
|
adamc@709
|
1504 let
|
adamc@709
|
1505 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
1506 val mat = (L'.TRecord [("1", string), ("2", string)], loc)
|
adamc@709
|
1507 in
|
adamc@712
|
1508 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (mat, mat), loc),
|
adamc@712
|
1509 (L'.EAbs ("m", mat, mat,
|
adamc@712
|
1510 (L'.ECase ((L'.EField ((L'.ERel 0, loc), "1"), loc),
|
adamc@712
|
1511 [((L'.PPrim (Prim.String ""), loc),
|
adamc@877
|
1512 (L'.ERecord [("1", (L'.EPrim (Prim.String ("uw_" ^ lowercaseFirst nm1)),
|
adamc@712
|
1513 loc), string),
|
adamc@877
|
1514 ("2", (L'.EPrim (Prim.String ("uw_" ^ lowercaseFirst nm2)),
|
adamc@712
|
1515 loc), string)], loc)),
|
adamc@712
|
1516 ((L'.PWild, loc),
|
adamc@712
|
1517 (L'.ERecord [("1", (L'.EStrcat (
|
adamc@877
|
1518 (L'.EPrim (Prim.String ("uw_" ^ lowercaseFirst nm1
|
adamc@877
|
1519 ^ ", ")),
|
adamc@712
|
1520 loc),
|
adamc@712
|
1521 (L'.EField ((L'.ERel 0, loc), "1"), loc)),
|
adamc@712
|
1522 loc), string),
|
adamc@712
|
1523 ("2", (L'.EStrcat (
|
adamc@877
|
1524 (L'.EPrim (Prim.String ("uw_" ^ lowercaseFirst nm2
|
adamc@877
|
1525 ^ ", ")), loc),
|
adamc@712
|
1526 (L'.EField ((L'.ERel 0, loc), "2"), loc)),
|
adamc@712
|
1527 loc), string)],
|
adamc@712
|
1528 loc))],
|
adamc@712
|
1529 {disc = string,
|
adamc@712
|
1530 result = mat}), loc)), loc)), loc),
|
adamc@709
|
1531 fm)
|
adamc@709
|
1532 end
|
adamc@709
|
1533
|
adamc@709
|
1534 | L.ECApp ((L.EFfi ("Basis", "restrict"), _), _) => ((L'.EPrim (Prim.String "RESTRICT"), loc), fm)
|
adamc@709
|
1535 | L.ECApp ((L.EFfi ("Basis", "cascade"), _), _) => ((L'.EPrim (Prim.String "CASCADE"), loc), fm)
|
adamc@709
|
1536 | L.ECApp ((L.EFfi ("Basis", "no_action"), _), _) => ((L'.EPrim (Prim.String "NO ACTION"), loc), fm)
|
adamc@709
|
1537 | L.ECApp ((L.EFfi ("Basis", "set_null"), _), _) => ((L'.EPrim (Prim.String "SET NULL"), loc), fm)
|
adamc@709
|
1538
|
adamc@709
|
1539 | L.ECApp (
|
adamc@709
|
1540 (L.ECApp (
|
adamc@709
|
1541 (L.ECApp (
|
adamc@709
|
1542 (L.ECApp (
|
adamc@709
|
1543 (L.ECApp (
|
adamc@709
|
1544 (L.ECApp (
|
adamc@709
|
1545 (L.ECApp (
|
adamc@709
|
1546 (L.ECApp (
|
adamc@709
|
1547 (L.EFfi ("Basis", "foreign_key"), _),
|
adamc@709
|
1548 _), _),
|
adamc@709
|
1549 _), _),
|
adamc@709
|
1550 _), _),
|
adamc@709
|
1551 _), _),
|
adamc@709
|
1552 _), _),
|
adamc@709
|
1553 _), _),
|
adamc@709
|
1554 _), _),
|
adamc@709
|
1555 _) =>
|
adamc@709
|
1556 let
|
adamc@709
|
1557 val unit = (L'.TRecord [], loc)
|
adamc@709
|
1558 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
1559 val mat = (L'.TRecord [("1", string), ("2", string)], loc)
|
adamc@709
|
1560 val recd = (L'.TRecord [("OnDelete", string),
|
adamc@709
|
1561 ("OnUpdate", string)], loc)
|
adamc@709
|
1562
|
adamc@709
|
1563 fun strcat [] = raise Fail "Monoize.strcat"
|
adamc@709
|
1564 | strcat [e] = e
|
adamc@709
|
1565 | strcat (e1 :: es) = (L'.EStrcat (e1, strcat es), loc)
|
adamc@709
|
1566
|
adamc@709
|
1567 fun prop (fd, kw) =
|
adamc@709
|
1568 (L'.ECase ((L'.EField ((L'.ERel 0, loc), fd), loc),
|
adamc@709
|
1569 [((L'.PPrim (Prim.String "NO ACTION"), loc),
|
adamc@709
|
1570 (L'.EPrim (Prim.String ""), loc)),
|
adamc@709
|
1571 ((L'.PWild, loc),
|
adamc@709
|
1572 strcat [(L'.EPrim (Prim.String (" ON " ^ kw ^ " ")), loc),
|
adamc@709
|
1573 (L'.EField ((L'.ERel 0, loc), fd), loc)])],
|
adamc@709
|
1574 {disc = string,
|
adamc@709
|
1575 result = string}), loc)
|
adamc@709
|
1576 in
|
adamc@709
|
1577 ((L'.EAbs ("m", mat, (L'.TFun (string, (L'.TFun (recd, string), loc)), loc),
|
adamc@709
|
1578 (L'.EAbs ("tab", string, (L'.TFun (recd, string), loc),
|
adamc@709
|
1579 (L'.EAbs ("pr", recd, string,
|
adamc@709
|
1580 strcat [(L'.EPrim (Prim.String "FOREIGN KEY ("), loc),
|
adamc@709
|
1581 (L'.EField ((L'.ERel 2, loc), "1"), loc),
|
adamc@709
|
1582 (L'.EPrim (Prim.String ") REFERENCES "), loc),
|
adamc@709
|
1583 (L'.ERel 1, loc),
|
adamc@709
|
1584 (L'.EPrim (Prim.String " ("), loc),
|
adamc@709
|
1585 (L'.EField ((L'.ERel 2, loc), "2"), loc),
|
adamc@709
|
1586 (L'.EPrim (Prim.String ")"), loc),
|
adamc@709
|
1587 prop ("OnDelete", "DELETE"),
|
adamc@709
|
1588 prop ("OnUpdate", "UPDATE")]), loc)), loc)), loc),
|
adamc@709
|
1589 fm)
|
adamc@709
|
1590 end
|
adamc@709
|
1591
|
adamc@714
|
1592 | L.ECApp ((L.EFfi ("Basis", "check"), _), _) =>
|
adamc@714
|
1593 let
|
adamc@714
|
1594 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@714
|
1595 in
|
adamc@714
|
1596 ((L'.EAbs ("e", string, string,
|
adamc@714
|
1597 (L'.EStrcat ((L'.EPrim (Prim.String "CHECK "), loc),
|
adamc@714
|
1598 (L'.EFfiApp ("Basis", "checkString",
|
adamc@714
|
1599 [(L'.ERel 0, loc)]), loc)), loc)), loc),
|
adamc@714
|
1600 fm)
|
adamc@714
|
1601 end
|
adamc@714
|
1602
|
adamc@307
|
1603 | L.EFfiApp ("Basis", "dml", [e]) =>
|
adamc@307
|
1604 let
|
adamc@307
|
1605 val (e, fm) = monoExp (env, st, fm) e
|
adamc@307
|
1606 in
|
adamc@468
|
1607 ((L'.EDml e, loc),
|
adamc@307
|
1608 fm)
|
adamc@307
|
1609 end
|
adamc@308
|
1610
|
adamc@705
|
1611 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "insert"), _), fields), _), _) =>
|
adamc@307
|
1612 (case monoType env (L.TRecord fields, loc) of
|
adamc@307
|
1613 (L'.TRecord fields, _) =>
|
adamc@307
|
1614 let
|
adamc@307
|
1615 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@307
|
1616 val fields = map (fn (x, _) => (x, s)) fields
|
adamc@307
|
1617 val rt = (L'.TRecord fields, loc)
|
adamc@307
|
1618 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@307
|
1619 in
|
adamc@307
|
1620 ((L'.EAbs ("tab", s, (L'.TFun (rt, s), loc),
|
adamc@307
|
1621 (L'.EAbs ("fs", rt, s,
|
adamc@598
|
1622 strcat [sc "INSERT INTO ",
|
adamc@598
|
1623 (L'.ERel 1, loc),
|
adamc@598
|
1624 sc " (",
|
adamc@598
|
1625 strcatComma (map (fn (x, _) => sc ("uw_" ^ x)) fields),
|
adamc@598
|
1626 sc ") VALUES (",
|
adamc@598
|
1627 strcatComma (map (fn (x, _) =>
|
adamc@598
|
1628 (L'.EField ((L'.ERel 0, loc),
|
adamc@598
|
1629 x), loc)) fields),
|
adamc@598
|
1630 sc ")"]), loc)), loc),
|
adamc@307
|
1631 fm)
|
adamc@307
|
1632 end
|
adamc@307
|
1633 | _ => poly ())
|
adamc@307
|
1634
|
adamc@705
|
1635 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "update"), _), _), _), _), _), changed) =>
|
adamc@308
|
1636 (case monoType env (L.TRecord changed, loc) of
|
adamc@308
|
1637 (L'.TRecord changed, _) =>
|
adamc@308
|
1638 let
|
adamc@308
|
1639 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@308
|
1640 val changed = map (fn (x, _) => (x, s)) changed
|
adamc@308
|
1641 val rt = (L'.TRecord changed, loc)
|
adamc@308
|
1642 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@308
|
1643 in
|
adamc@308
|
1644 ((L'.EAbs ("fs", rt, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@308
|
1645 (L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@308
|
1646 (L'.EAbs ("e", s, s,
|
adamc@886
|
1647 if #supportsUpdateAs (Settings.currentDbms ()) then
|
adamc@886
|
1648 strcat [sc "UPDATE ",
|
adamc@886
|
1649 (L'.ERel 1, loc),
|
adamc@986
|
1650 sc " AS T_T SET ",
|
adamc@886
|
1651 strcatComma (map (fn (x, _) =>
|
adamc@886
|
1652 strcat [sc ("uw_" ^ x
|
adamc@886
|
1653 ^ " = "),
|
adamc@886
|
1654 (L'.EField
|
adamc@886
|
1655 ((L'.ERel 2,
|
adamc@886
|
1656 loc),
|
adamc@886
|
1657 x), loc)])
|
adamc@886
|
1658 changed),
|
adamc@886
|
1659 sc " WHERE ",
|
adamc@886
|
1660 (L'.ERel 0, loc)]
|
adamc@886
|
1661 else
|
adamc@886
|
1662 strcat [sc "UPDATE ",
|
adamc@886
|
1663 (L'.ERel 1, loc),
|
adamc@886
|
1664 sc " SET ",
|
adamc@886
|
1665 strcatComma (map (fn (x, _) =>
|
adamc@886
|
1666 strcat [sc ("uw_" ^ x
|
adamc@886
|
1667 ^ " = "),
|
adamc@886
|
1668 (L'.EField
|
adamc@886
|
1669 ((L'.ERel 2,
|
adamc@886
|
1670 loc),
|
adamc@886
|
1671 x), loc)])
|
adamc@886
|
1672 changed),
|
adamc@886
|
1673 sc " WHERE ",
|
adamc@886
|
1674 (L'.EFfiApp ("Basis", "unAs", [(L'.ERel 0, loc)]), loc)]),
|
adamc@886
|
1675 loc)), loc)), loc),
|
adamc@308
|
1676 fm)
|
adamc@308
|
1677 end
|
adamc@308
|
1678 | _ => poly ())
|
adamc@308
|
1679
|
adamc@705
|
1680 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "delete"), _), _), _), _) =>
|
adamc@309
|
1681 let
|
adamc@309
|
1682 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@309
|
1683 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@309
|
1684 in
|
adamc@309
|
1685 ((L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@309
|
1686 (L'.EAbs ("e", s, s,
|
adamc@874
|
1687 if #supportsDeleteAs (Settings.currentDbms ()) then
|
adamc@874
|
1688 strcat [sc "DELETE FROM ",
|
adamc@874
|
1689 (L'.ERel 1, loc),
|
adamc@986
|
1690 sc " AS T_T WHERE ",
|
adamc@874
|
1691 (L'.ERel 0, loc)]
|
adamc@874
|
1692 else
|
adamc@874
|
1693 strcat [sc "DELETE FROM ",
|
adamc@874
|
1694 (L'.ERel 1, loc),
|
adamc@874
|
1695 sc " WHERE ",
|
adamc@874
|
1696 (L'.EFfiApp ("Basis", "unAs", [(L'.ERel 0, loc)]), loc)]), loc)), loc),
|
adamc@309
|
1697 fm)
|
adamc@309
|
1698 end
|
adamc@309
|
1699
|
adamc@252
|
1700 | L.ECApp (
|
adamc@252
|
1701 (L.ECApp (
|
adamc@252
|
1702 (L.ECApp ((L.EFfi ("Basis", "query"), _), (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1703 exps), _),
|
adamc@252
|
1704 state) =>
|
adamc@252
|
1705 (case monoType env (L.TRecord exps, loc) of
|
adamc@252
|
1706 (L'.TRecord exps, _) =>
|
adamc@252
|
1707 let
|
adamc@252
|
1708 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1709 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1710 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1711 | _ => NONE)
|
adamc@252
|
1712 | _ => NONE) tables
|
adamc@252
|
1713 in
|
adamc@252
|
1714 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1715 poly ()
|
adamc@252
|
1716 else
|
adamc@252
|
1717 let
|
adamc@252
|
1718 val tables = List.mapPartial (fn x => x) tables
|
adamc@252
|
1719 val state = monoType env state
|
adamc@252
|
1720 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1721 val un = (L'.TRecord [], loc)
|
adamc@252
|
1722
|
adamc@252
|
1723 val rt = exps @ map (fn (x, xts) => (x, (L'.TRecord xts, loc))) tables
|
adamc@252
|
1724 val ft = (L'.TFun ((L'.TRecord rt, loc),
|
adamc@252
|
1725 (L'.TFun (state,
|
adamc@252
|
1726 (L'.TFun (un, state), loc)),
|
adamc@252
|
1727 loc)), loc)
|
adamc@252
|
1728
|
adamc@267
|
1729 val body' = (L'.EApp (
|
adamc@267
|
1730 (L'.EApp (
|
adamc@267
|
1731 (L'.EApp ((L'.ERel 4, loc),
|
adamc@267
|
1732 (L'.ERel 1, loc)), loc),
|
adamc@267
|
1733 (L'.ERel 0, loc)), loc),
|
adamc@267
|
1734 (L'.ERecord [], loc)), loc)
|
adamc@252
|
1735
|
adamc@252
|
1736 val body = (L'.EQuery {exps = exps,
|
adamc@252
|
1737 tables = tables,
|
adamc@252
|
1738 state = state,
|
adamc@252
|
1739 query = (L'.ERel 3, loc),
|
adamc@252
|
1740 body = body',
|
adamc@252
|
1741 initial = (L'.ERel 1, loc)},
|
adamc@252
|
1742 loc)
|
adamc@252
|
1743 in
|
adamc@252
|
1744 ((L'.EAbs ("q", s, (L'.TFun (ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc)), loc),
|
adamc@252
|
1745 (L'.EAbs ("f", ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc),
|
adamc@252
|
1746 (L'.EAbs ("i", state, (L'.TFun (un, state), loc),
|
adamc@252
|
1747 (L'.EAbs ("_", un, state,
|
adamc@252
|
1748 body), loc)), loc)), loc)), loc), fm)
|
adamc@252
|
1749 end
|
adamc@252
|
1750 end
|
adamc@252
|
1751 | _ => poly ())
|
adamc@252
|
1752
|
adamc@252
|
1753 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_query"), _), _), _), _), _), _) =>
|
adamc@252
|
1754 let
|
adamc@252
|
1755 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1756 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1757 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1758 in
|
adamc@252
|
1759 ((L'.EAbs ("r",
|
adamc@252
|
1760 (L'.TRecord [("Rows", s), ("OrderBy", s), ("Limit", s), ("Offset", s)], loc),
|
adamc@252
|
1761 s,
|
adamc@598
|
1762 strcat [gf "Rows",
|
adamc@598
|
1763 (L'.ECase (gf "OrderBy",
|
adamc@598
|
1764 [((L'.PPrim (Prim.String ""), loc), sc ""),
|
adamc@598
|
1765 ((L'.PWild, loc),
|
adamc@598
|
1766 strcat [sc " ORDER BY ",
|
adamc@598
|
1767 gf "OrderBy"])],
|
adamc@598
|
1768 {disc = s, result = s}), loc),
|
adamc@598
|
1769 gf "Limit",
|
adamc@598
|
1770 gf "Offset"]), loc), fm)
|
adamc@252
|
1771 end
|
adamc@252
|
1772
|
adamc@252
|
1773 | L.ECApp (
|
adamc@252
|
1774 (L.ECApp (
|
adamc@252
|
1775 (L.ECApp (
|
adamc@252
|
1776 (L.ECApp (
|
adamc@252
|
1777 (L.EFfi ("Basis", "sql_query1"), _),
|
adamc@252
|
1778 (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1779 (L.CRecord (_, grouped), _)), _),
|
adamc@252
|
1780 (L.CRecord (_, stables), _)), _),
|
adamc@252
|
1781 sexps) =>
|
adamc@252
|
1782 let
|
adamc@252
|
1783 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1784 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@993
|
1785 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@252
|
1786 val un = (L'.TRecord [], loc)
|
adamc@252
|
1787 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1788
|
adamc@252
|
1789 fun doTables tables =
|
adamc@252
|
1790 let
|
adamc@252
|
1791 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1792 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1793 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1794 | _ => NONE)
|
adamc@252
|
1795 | _ => NONE) tables
|
adamc@252
|
1796 in
|
adamc@252
|
1797 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1798 NONE
|
adamc@252
|
1799 else
|
adamc@260
|
1800 let
|
adamc@260
|
1801 val tables = List.mapPartial (fn x => x) tables
|
adamc@260
|
1802 val tables = ListMergeSort.sort
|
adamc@260
|
1803 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1804 tables
|
adamc@260
|
1805 val tables = map (fn (x, xts) =>
|
adamc@260
|
1806 (x, ListMergeSort.sort
|
adamc@260
|
1807 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1808 xts)) tables
|
adamc@260
|
1809 in
|
adamc@260
|
1810 SOME tables
|
adamc@260
|
1811 end
|
adamc@252
|
1812 end
|
adamc@252
|
1813 in
|
adamc@252
|
1814 case (doTables tables, doTables grouped, doTables stables, monoType env (L.TRecord sexps, loc)) of
|
adamc@252
|
1815 (SOME tables, SOME grouped, SOME stables, (L'.TRecord sexps, _)) =>
|
adamc@441
|
1816 let
|
adamc@441
|
1817 val sexps = ListMergeSort.sort
|
adamc@441
|
1818 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER) sexps
|
adamc@441
|
1819 in
|
adamc@441
|
1820 ((L'.EAbs ("r",
|
adamc@993
|
1821 (L'.TRecord [("Distinct", b),
|
adamc@993
|
1822 ("From", s),
|
adamc@441
|
1823 ("Where", s),
|
adamc@441
|
1824 ("GroupBy", un),
|
adamc@441
|
1825 ("Having", s),
|
adamc@441
|
1826 ("SelectFields", un),
|
adamc@441
|
1827 ("SelectExps", (L'.TRecord (map (fn (x, _) => (x, s)) sexps), loc))],
|
adamc@441
|
1828 loc),
|
adamc@441
|
1829 s,
|
adamc@598
|
1830 strcat [sc "SELECT ",
|
adamc@993
|
1831 (L'.ECase (gf "Distinct",
|
adamc@993
|
1832 [((L'.PCon (L'.Enum,
|
adamc@993
|
1833 L'.PConFfi {mod = "Basis",
|
adamc@993
|
1834 datatyp = "bool",
|
adamc@993
|
1835 con = "True",
|
adamc@993
|
1836 arg = NONE},
|
adamc@993
|
1837 NONE), loc),
|
adamc@993
|
1838 (L'.EPrim (Prim.String "DISTINCT "), loc)),
|
adamc@993
|
1839 ((L'.PCon (L'.Enum,
|
adamc@993
|
1840 L'.PConFfi {mod = "Basis",
|
adamc@993
|
1841 datatyp = "bool",
|
adamc@993
|
1842 con = "False",
|
adamc@993
|
1843 arg = NONE},
|
adamc@993
|
1844 NONE), loc),
|
adamc@993
|
1845 (L'.EPrim (Prim.String ""), loc))],
|
adamc@993
|
1846 {disc = b, result = s}), loc),
|
adamc@598
|
1847 strcatComma (map (fn (x, t) =>
|
adamc@598
|
1848 strcat [
|
adamc@598
|
1849 (L'.EField (gf "SelectExps", x), loc),
|
adamc@598
|
1850 sc (" AS _" ^ x)
|
adamc@598
|
1851 ]) sexps
|
adamc@598
|
1852 @ map (fn (x, xts) =>
|
adamc@598
|
1853 strcatComma
|
adamc@598
|
1854 (map (fn (x', _) =>
|
adamc@986
|
1855 sc ("T_" ^ x
|
adamc@986
|
1856 ^ ".uw_"
|
adamc@986
|
1857 ^ x'))
|
adamc@598
|
1858 xts)) stables),
|
adamc@598
|
1859 sc " FROM ",
|
adamc@748
|
1860 gf "From",
|
adamc@598
|
1861 (L'.ECase (gf "Where",
|
adamc@598
|
1862 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@598
|
1863 sc ""),
|
adamc@598
|
1864 ((L'.PWild, loc),
|
adamc@598
|
1865 strcat [sc " WHERE ", gf "Where"])],
|
adamc@598
|
1866 {disc = s,
|
adamc@598
|
1867 result = s}), loc),
|
adamc@598
|
1868
|
adamc@598
|
1869 if List.all (fn (x, xts) =>
|
adamc@598
|
1870 case List.find (fn (x', _) => x' = x) grouped of
|
adamc@598
|
1871 NONE => List.null xts
|
adamc@598
|
1872 | SOME (_, xts') =>
|
adamc@598
|
1873 List.all (fn (x, _) =>
|
adamc@598
|
1874 List.exists (fn (x', _) => x' = x)
|
adamc@598
|
1875 xts') xts) tables then
|
adamc@598
|
1876 sc ""
|
adamc@598
|
1877 else
|
adamc@598
|
1878 strcat [
|
adamc@598
|
1879 sc " GROUP BY ",
|
adamc@598
|
1880 strcatComma (map (fn (x, xts) =>
|
adamc@598
|
1881 strcatComma
|
adamc@598
|
1882 (map (fn (x', _) =>
|
adamc@986
|
1883 sc ("T_" ^ x
|
adamc@986
|
1884 ^ ".uw_"
|
adamc@986
|
1885 ^ x'))
|
adamc@598
|
1886 xts)) grouped)
|
adamc@598
|
1887 ],
|
adamc@259
|
1888
|
adamc@598
|
1889 (L'.ECase (gf "Having",
|
adamc@1014
|
1890 [((L'.PPrim (Prim.String
|
adamc@1014
|
1891 (#trueString (Settings.currentDbms ()))), loc),
|
adamc@598
|
1892 sc ""),
|
adamc@598
|
1893 ((L'.PWild, loc),
|
adamc@598
|
1894 strcat [sc " HAVING ", gf "Having"])],
|
adamc@598
|
1895 {disc = s,
|
adamc@598
|
1896 result = s}), loc)
|
adamc@441
|
1897 ]), loc),
|
adamc@441
|
1898 fm)
|
adamc@441
|
1899 end
|
adamc@252
|
1900 | _ => poly ()
|
adamc@252
|
1901 end
|
adamc@252
|
1902
|
adamc@252
|
1903 | L.ECApp (
|
adamc@252
|
1904 (L.ECApp (
|
adamc@252
|
1905 (L.ECApp (
|
adamc@252
|
1906 (L.ECApp (
|
adamc@252
|
1907 (L.EFfi ("Basis", "sql_inject"), _),
|
adamc@252
|
1908 _), _),
|
adamc@252
|
1909 _), _),
|
adamc@252
|
1910 _), _),
|
adamc@252
|
1911 t) =>
|
adamc@252
|
1912 let
|
adamc@252
|
1913 val t = monoType env t
|
adamc@252
|
1914 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1915 in
|
adamc@252
|
1916 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@252
|
1917 (L'.ERel 0, loc)), loc), fm)
|
adamc@252
|
1918 end
|
adamc@252
|
1919
|
adamc@253
|
1920 | L.EFfi ("Basis", "sql_int") =>
|
adamc@253
|
1921 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1922 (L'.EFfiApp ("Basis", "sqlifyInt", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1923 fm)
|
adamc@253
|
1924 | L.EFfi ("Basis", "sql_float") =>
|
adamc@253
|
1925 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1926 (L'.EFfiApp ("Basis", "sqlifyFloat", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1927 fm)
|
adamc@253
|
1928 | L.EFfi ("Basis", "sql_bool") =>
|
adamc@253
|
1929 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1930 (L'.EFfiApp ("Basis", "sqlifyBool", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1931 fm)
|
adamc@253
|
1932 | L.EFfi ("Basis", "sql_string") =>
|
adamc@253
|
1933 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1934 (L'.EFfiApp ("Basis", "sqlifyString", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1935 fm)
|
adamc@1011
|
1936 | L.EFfi ("Basis", "sql_char") =>
|
adamc@1011
|
1937 ((L'.EAbs ("x", (L'.TFfi ("Basis", "char"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@1011
|
1938 (L'.EFfiApp ("Basis", "sqlifyChar", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@1011
|
1939 fm)
|
adamc@439
|
1940 | L.EFfi ("Basis", "sql_time") =>
|
adamc@439
|
1941 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@439
|
1942 (L'.EFfiApp ("Basis", "sqlifyTime", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@439
|
1943 fm)
|
adamc@737
|
1944 | L.EFfi ("Basis", "sql_blob") =>
|
adamc@737
|
1945 ((L'.EAbs ("x", (L'.TFfi ("Basis", "blob"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@737
|
1946 (L'.EFfiApp ("Basis", "sqlifyBlob", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@737
|
1947 fm)
|
adamc@678
|
1948 | L.ECApp ((L.EFfi ("Basis", "sql_channel"), _), _) =>
|
adamc@678
|
1949 ((L'.EAbs ("x", (L'.TFfi ("Basis", "channel"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@678
|
1950 (L'.EFfiApp ("Basis", "sqlifyChannel", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@678
|
1951 fm)
|
adamc@682
|
1952 | L.EFfi ("Basis", "sql_client") =>
|
adamc@682
|
1953 ((L'.EAbs ("x", (L'.TFfi ("Basis", "client"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@682
|
1954 (L'.EFfiApp ("Basis", "sqlifyClient", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@682
|
1955 fm)
|
adamc@676
|
1956 | L.ECApp ((L.EFfi ("Basis", "sql_prim"), _), t) =>
|
adamc@676
|
1957 let
|
adamc@676
|
1958 val t = monoType env t
|
adamc@676
|
1959 val tf = (L'.TFun (t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@676
|
1960 in
|
adamc@676
|
1961 ((L'.EAbs ("f", tf, tf, (L'.ERel 0, loc)), loc),
|
adamc@676
|
1962 fm)
|
adamc@676
|
1963 end
|
adamc@676
|
1964 | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) =>
|
adamc@676
|
1965 let
|
adamc@676
|
1966 val t = monoType env t
|
adamc@676
|
1967 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@676
|
1968 in
|
adamc@676
|
1969 ((L'.EAbs ("f",
|
adamc@676
|
1970 (L'.TFun (t, s), loc),
|
adamc@676
|
1971 (L'.TFun ((L'.TOption t, loc), s), loc),
|
adamc@676
|
1972 (L'.EAbs ("x",
|
adamc@676
|
1973 (L'.TOption t, loc),
|
adamc@676
|
1974 s,
|
adamc@676
|
1975 (L'.ECase ((L'.ERel 0, loc),
|
adamc@676
|
1976 [((L'.PNone t, loc),
|
adamc@676
|
1977 (L'.EPrim (Prim.String "NULL"), loc)),
|
adamc@676
|
1978 ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc),
|
adamc@676
|
1979 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))],
|
adamc@676
|
1980 {disc = (L'.TOption t, loc),
|
adamc@676
|
1981 result = s}), loc)), loc)), loc),
|
adamc@676
|
1982 fm)
|
adamc@676
|
1983 end
|
adamc@253
|
1984
|
adamc@750
|
1985 | L.ECApp ((L.EFfi ("Basis", "nullify_option"), _), _) =>
|
adamc@750
|
1986 ((L'.ERecord [], loc), fm)
|
adamc@750
|
1987 | L.ECApp ((L.EFfi ("Basis", "nullify_prim"), _), _) =>
|
adamc@750
|
1988 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@750
|
1989 (L'.ERecord [], loc)), loc),
|
adamc@750
|
1990 fm)
|
adamc@750
|
1991
|
adamc@252
|
1992 | L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) =>
|
adamc@252
|
1993 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1994 | L.ECApp ((L.EFfi ("Basis", "sql_subset_all"), _), _) =>
|
adamc@252
|
1995 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1996
|
adamc@753
|
1997 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "fieldsOf_table"), _), _), _), _) =>
|
adamc@753
|
1998 ((L'.ERecord [], loc), fm)
|
adamc@753
|
1999 | L.ECApp ((L.EFfi ("Basis", "fieldsOf_view"), _), _) =>
|
adamc@753
|
2000 ((L'.ERecord [], loc), fm)
|
adamc@753
|
2001
|
adamc@753
|
2002 | L.ECApp ((L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_table"), _), _), _), _), _), _), _),
|
adamc@753
|
2003 (L.CName name, _)) =>
|
adamc@748
|
2004 let
|
adamc@748
|
2005 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@748
|
2006 in
|
adamc@748
|
2007 ((L'.EAbs ("tab", s, s,
|
adamc@748
|
2008 strcat [(L'.ERel 0, loc),
|
adamc@986
|
2009 (L'.EPrim (Prim.String (" AS T_" ^ name)), loc)]), loc),
|
adamc@748
|
2010 fm)
|
adamc@748
|
2011 end
|
adamc@748
|
2012 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_from_comma"), _), _), _), _) =>
|
adamc@748
|
2013 let
|
adamc@748
|
2014 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@748
|
2015 in
|
adamc@748
|
2016 ((L'.EAbs ("tab1", s, (L'.TFun (s, s), loc),
|
adamc@748
|
2017 (L'.EAbs ("tab2", s, s,
|
adamc@748
|
2018 strcat [(L'.ERel 1, loc),
|
adamc@748
|
2019 (L'.EPrim (Prim.String ", "), loc),
|
adamc@748
|
2020 (L'.ERel 0, loc)]), loc)), loc),
|
adamc@748
|
2021 fm)
|
adamc@748
|
2022 end
|
adamc@749
|
2023 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_inner_join"), _), _), _), _) =>
|
adamc@749
|
2024 let
|
adamc@749
|
2025 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@749
|
2026 in
|
adamc@749
|
2027 ((L'.EAbs ("tab1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@749
|
2028 (L'.EAbs ("tab2", s, (L'.TFun (s, s), loc),
|
adamc@749
|
2029 (L'.EAbs ("on", s, s,
|
adamc@749
|
2030 strcat [(L'.EPrim (Prim.String "("), loc),
|
adamc@749
|
2031 (L'.ERel 2, loc),
|
adamc@749
|
2032 (L'.EPrim (Prim.String " JOIN "), loc),
|
adamc@749
|
2033 (L'.ERel 1, loc),
|
adamc@749
|
2034 (L'.EPrim (Prim.String " ON "), loc),
|
adamc@749
|
2035 (L'.ERel 0, loc),
|
adamc@749
|
2036 (L'.EPrim (Prim.String ")"), loc)]), loc)), loc)), loc),
|
adamc@749
|
2037 fm)
|
adamc@749
|
2038 end
|
adamc@750
|
2039 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_left_join"), _), _), _), (L.CRecord (_, right), _)) =>
|
adamc@750
|
2040 let
|
adamc@750
|
2041 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@750
|
2042 in
|
adamc@750
|
2043 ((L'.EAbs ("_", outerRec right,
|
adamc@750
|
2044 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
|
adamc@750
|
2045 (L'.EAbs ("tab1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@750
|
2046 (L'.EAbs ("tab2", s, (L'.TFun (s, s), loc),
|
adamc@750
|
2047 (L'.EAbs ("on", s, s,
|
adamc@750
|
2048 strcat [(L'.EPrim (Prim.String "("), loc),
|
adamc@750
|
2049 (L'.ERel 2, loc),
|
adamc@750
|
2050 (L'.EPrim (Prim.String " LEFT JOIN "), loc),
|
adamc@750
|
2051 (L'.ERel 1, loc),
|
adamc@750
|
2052 (L'.EPrim (Prim.String " ON "), loc),
|
adamc@750
|
2053 (L'.ERel 0, loc),
|
adamc@750
|
2054 (L'.EPrim (Prim.String ")"), loc)]),
|
adamc@750
|
2055 loc)), loc)), loc)), loc),
|
adamc@750
|
2056 fm)
|
adamc@750
|
2057 end
|
adamc@751
|
2058 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_right_join"), _), (L.CRecord (_, left), _)), _), _) =>
|
adamc@751
|
2059 let
|
adamc@751
|
2060 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@751
|
2061 in
|
adamc@751
|
2062 ((L'.EAbs ("_", outerRec left,
|
adamc@751
|
2063 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
|
adamc@751
|
2064 (L'.EAbs ("tab1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@751
|
2065 (L'.EAbs ("tab2", s, (L'.TFun (s, s), loc),
|
adamc@751
|
2066 (L'.EAbs ("on", s, s,
|
adamc@751
|
2067 strcat [(L'.EPrim (Prim.String "("), loc),
|
adamc@751
|
2068 (L'.ERel 2, loc),
|
adamc@751
|
2069 (L'.EPrim (Prim.String " RIGHT JOIN "), loc),
|
adamc@751
|
2070 (L'.ERel 1, loc),
|
adamc@751
|
2071 (L'.EPrim (Prim.String " ON "), loc),
|
adamc@751
|
2072 (L'.ERel 0, loc),
|
adamc@751
|
2073 (L'.EPrim (Prim.String ")"), loc)]),
|
adamc@751
|
2074 loc)), loc)), loc)), loc),
|
adamc@751
|
2075 fm)
|
adamc@751
|
2076 end
|
adamc@751
|
2077 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_full_join"), _), (L.CRecord (_, left), _)), _),
|
adamc@751
|
2078 (L.CRecord (_, right), _)) =>
|
adamc@751
|
2079 let
|
adamc@751
|
2080 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@751
|
2081 in
|
adamc@751
|
2082 ((L'.EAbs ("_", outerRec (left @ right),
|
adamc@751
|
2083 (L'.TFun (s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc)), loc),
|
adamc@751
|
2084 (L'.EAbs ("tab1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@751
|
2085 (L'.EAbs ("tab2", s, (L'.TFun (s, s), loc),
|
adamc@751
|
2086 (L'.EAbs ("on", s, s,
|
adamc@751
|
2087 strcat [(L'.EPrim (Prim.String "("), loc),
|
adamc@751
|
2088 (L'.ERel 2, loc),
|
adamc@751
|
2089 (L'.EPrim (Prim.String " FULL JOIN "), loc),
|
adamc@751
|
2090 (L'.ERel 1, loc),
|
adamc@751
|
2091 (L'.EPrim (Prim.String " ON "), loc),
|
adamc@751
|
2092 (L'.ERel 0, loc),
|
adamc@751
|
2093 (L'.EPrim (Prim.String ")"), loc)]),
|
adamc@751
|
2094 loc)), loc)), loc)), loc),
|
adamc@751
|
2095 fm)
|
adamc@751
|
2096 end
|
adamc@748
|
2097
|
adamc@252
|
2098 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_order_by_Nil"), _), _), _), _) =>
|
adamc@252
|
2099 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@261
|
2100 | L.ECApp (
|
adamc@261
|
2101 (L.ECApp (
|
adamc@261
|
2102 (L.ECApp (
|
adamc@261
|
2103 (L.EFfi ("Basis", "sql_order_by_Cons"), _),
|
adamc@261
|
2104 _), _),
|
adamc@261
|
2105 _), _),
|
adamc@261
|
2106 _) =>
|
adamc@261
|
2107 let
|
adamc@261
|
2108 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@261
|
2109 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@261
|
2110 in
|
adamc@268
|
2111 ((L'.EAbs ("e1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@268
|
2112 (L'.EAbs ("d", s, (L'.TFun (s, s), loc),
|
adamc@268
|
2113 (L'.EAbs ("e2", s, s,
|
adamc@268
|
2114 (L'.ECase ((L'.ERel 0, loc),
|
adamc@268
|
2115 [((L'.PPrim (Prim.String ""), loc),
|
adamc@598
|
2116 strcat [(L'.ERel 2, loc),
|
adamc@598
|
2117 (L'.ERel 1, loc)]),
|
adamc@268
|
2118 ((L'.PWild, loc),
|
adamc@598
|
2119 strcat [(L'.ERel 2, loc),
|
adamc@598
|
2120 (L'.ERel 1, loc),
|
adamc@598
|
2121 sc ", ",
|
adamc@598
|
2122 (L'.ERel 0, loc)])],
|
adamc@268
|
2123 {disc = s, result = s}), loc)), loc)), loc)), loc),
|
adamc@261
|
2124 fm)
|
adamc@261
|
2125 end
|
adamc@252
|
2126
|
adamc@252
|
2127 | L.EFfi ("Basis", "sql_no_limit") =>
|
adamc@252
|
2128 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@262
|
2129 | L.EFfiApp ("Basis", "sql_limit", [e]) =>
|
adamc@262
|
2130 let
|
adamc@262
|
2131 val (e, fm) = monoExp (env, st, fm) e
|
adamc@262
|
2132 in
|
adamc@598
|
2133 (strcat [
|
adamc@262
|
2134 (L'.EPrim (Prim.String " LIMIT "), loc),
|
adamc@262
|
2135 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@262
|
2136 ],
|
adamc@262
|
2137 fm)
|
adamc@262
|
2138 end
|
adamc@262
|
2139
|
adamc@252
|
2140 | L.EFfi ("Basis", "sql_no_offset") =>
|
adamc@252
|
2141 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@263
|
2142 | L.EFfiApp ("Basis", "sql_offset", [e]) =>
|
adamc@263
|
2143 let
|
adamc@263
|
2144 val (e, fm) = monoExp (env, st, fm) e
|
adamc@263
|
2145 in
|
adamc@598
|
2146 (strcat [
|
adamc@263
|
2147 (L'.EPrim (Prim.String " OFFSET "), loc),
|
adamc@263
|
2148 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@263
|
2149 ],
|
adamc@263
|
2150 fm)
|
adamc@263
|
2151 end
|
adamc@253
|
2152
|
adamc@559
|
2153 | L.ECApp ((L.EFfi ("Basis", "sql_eq"), _), _) =>
|
adamc@253
|
2154 ((L'.EPrim (Prim.String "="), loc), fm)
|
adamc@559
|
2155 | L.ECApp ((L.EFfi ("Basis", "sql_ne"), _), _) =>
|
adamc@253
|
2156 ((L'.EPrim (Prim.String "<>"), loc), fm)
|
adamc@559
|
2157 | L.ECApp ((L.EFfi ("Basis", "sql_lt"), _), _) =>
|
adamc@253
|
2158 ((L'.EPrim (Prim.String "<"), loc), fm)
|
adamc@559
|
2159 | L.ECApp ((L.EFfi ("Basis", "sql_le"), _), _) =>
|
adamc@253
|
2160 ((L'.EPrim (Prim.String "<="), loc), fm)
|
adamc@559
|
2161 | L.ECApp ((L.EFfi ("Basis", "sql_gt"), _), _) =>
|
adamc@253
|
2162 ((L'.EPrim (Prim.String ">"), loc), fm)
|
adamc@559
|
2163 | L.ECApp ((L.EFfi ("Basis", "sql_ge"), _), _) =>
|
adamc@253
|
2164 ((L'.EPrim (Prim.String ">="), loc), fm)
|
adamc@253
|
2165
|
adamc@559
|
2166 | L.ECApp ((L.EFfi ("Basis", "sql_plus"), _), _) =>
|
adamc@559
|
2167 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
2168 (L'.EPrim (Prim.String "+"), loc)), loc), fm)
|
adamc@559
|
2169 | L.ECApp ((L.EFfi ("Basis", "sql_minus"), _), _) =>
|
adamc@559
|
2170 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
2171 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@559
|
2172 | L.ECApp ((L.EFfi ("Basis", "sql_times"), _), _) =>
|
adamc@559
|
2173 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
2174 (L'.EPrim (Prim.String "*"), loc)), loc), fm)
|
adamc@559
|
2175 | L.ECApp ((L.EFfi ("Basis", "sql_div"), _), _) =>
|
adamc@559
|
2176 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
2177 (L'.EPrim (Prim.String "/"), loc)), loc), fm)
|
adamc@559
|
2178 | L.EFfi ("Basis", "sql_mod") =>
|
adamc@559
|
2179 ((L'.EPrim (Prim.String "%"), loc), fm)
|
adamc@559
|
2180
|
adamc@253
|
2181 | L.ECApp (
|
adamc@253
|
2182 (L.ECApp (
|
adamc@253
|
2183 (L.ECApp (
|
adamc@253
|
2184 (L.ECApp (
|
adamc@254
|
2185 (L.ECApp (
|
adamc@264
|
2186 (L.EFfi ("Basis", "sql_unary"), _),
|
adamc@264
|
2187 _), _),
|
adamc@264
|
2188 _), _),
|
adamc@264
|
2189 _), _),
|
adamc@264
|
2190 _), _),
|
adamc@264
|
2191 _) =>
|
adamc@264
|
2192 let
|
adamc@264
|
2193 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@264
|
2194 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@264
|
2195 in
|
adamc@264
|
2196 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@264
|
2197 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@598
|
2198 strcat [sc "(",
|
adamc@598
|
2199 (L'.ERel 1, loc),
|
adamc@598
|
2200 sc " ",
|
adamc@598
|
2201 (L'.ERel 0, loc),
|
adamc@598
|
2202 sc ")"]), loc)), loc),
|
adamc@264
|
2203 fm)
|
adamc@264
|
2204 end
|
adamc@264
|
2205 | L.EFfi ("Basis", "sql_not") => ((L'.EPrim (Prim.String "NOT"), loc), fm)
|
adamc@559
|
2206 | L.ECApp ((L.EFfi ("Basis", "sql_neg"), _), _) =>
|
adamc@559
|
2207 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
2208 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@264
|
2209
|
adamc@264
|
2210 | L.ECApp (
|
adamc@264
|
2211 (L.ECApp (
|
adamc@264
|
2212 (L.ECApp (
|
adamc@264
|
2213 (L.ECApp (
|
adamc@264
|
2214 (L.ECApp (
|
adamc@254
|
2215 (L.ECApp (
|
adamc@254
|
2216 (L.EFfi ("Basis", "sql_binary"), _),
|
adamc@254
|
2217 _), _),
|
adamc@254
|
2218 _), _),
|
adamc@254
|
2219 _), _),
|
adamc@254
|
2220 _), _),
|
adamc@254
|
2221 _), _),
|
adamc@254
|
2222 _) =>
|
adamc@254
|
2223 let
|
adamc@254
|
2224 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@254
|
2225 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@254
|
2226 in
|
adamc@254
|
2227 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@254
|
2228 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@254
|
2229 (L'.EAbs ("e2", s, s,
|
adamc@598
|
2230 strcat [sc "(",
|
adamc@598
|
2231 (L'.ERel 1, loc),
|
adamc@598
|
2232 sc " ",
|
adamc@598
|
2233 (L'.ERel 2, loc),
|
adamc@598
|
2234 sc " ",
|
adamc@598
|
2235 (L'.ERel 0, loc),
|
adamc@598
|
2236 sc ")"]), loc)), loc)), loc),
|
adamc@254
|
2237 fm)
|
adamc@254
|
2238 end
|
adamc@254
|
2239 | L.EFfi ("Basis", "sql_and") => ((L'.EPrim (Prim.String "AND"), loc), fm)
|
adamc@254
|
2240 | L.EFfi ("Basis", "sql_or") => ((L'.EPrim (Prim.String "OR"), loc), fm)
|
adamc@254
|
2241
|
adamc@254
|
2242 | L.ECApp (
|
adamc@254
|
2243 (L.ECApp (
|
adamc@254
|
2244 (L.ECApp (
|
adamc@254
|
2245 (L.ECApp (
|
adamc@253
|
2246 (L.ECApp (
|
adamc@253
|
2247 (L.ECApp (
|
adamc@253
|
2248 (L.ECApp (
|
adamc@253
|
2249 (L.EFfi ("Basis", "sql_field"), _),
|
adamc@253
|
2250 _), _),
|
adamc@253
|
2251 _), _),
|
adamc@253
|
2252 _), _),
|
adamc@253
|
2253 _), _),
|
adamc@253
|
2254 _), _),
|
adamc@253
|
2255 (L.CName tab, _)), _),
|
adamc@986
|
2256 (L.CName field, _)) => ((L'.EPrim (Prim.String ("T_" ^ tab ^ ".uw_" ^ lowercaseFirst field)), loc), fm)
|
adamc@260
|
2257
|
adamc@260
|
2258 | L.ECApp (
|
adamc@260
|
2259 (L.ECApp (
|
adamc@260
|
2260 (L.ECApp (
|
adamc@260
|
2261 (L.ECApp (
|
adamc@261
|
2262 (L.ECApp (
|
adamc@261
|
2263 (L.EFfi ("Basis", "sql_exp"), _),
|
adamc@261
|
2264 _), _),
|
adamc@261
|
2265 _), _),
|
adamc@261
|
2266 _), _),
|
adamc@261
|
2267 _), _),
|
adamc@877
|
2268 (L.CName nm, _)) => ((L'.EPrim (Prim.String ("_" ^ lowercaseFirst nm)), loc), fm)
|
adamc@261
|
2269
|
adamc@261
|
2270 | L.ECApp (
|
adamc@261
|
2271 (L.ECApp (
|
adamc@261
|
2272 (L.ECApp (
|
adamc@261
|
2273 (L.ECApp (
|
adamc@260
|
2274 (L.EFfi ("Basis", "sql_relop"), _),
|
adamc@260
|
2275 _), _),
|
adamc@260
|
2276 _), _),
|
adamc@260
|
2277 _), _),
|
adamc@260
|
2278 _) =>
|
adamc@260
|
2279 let
|
adamc@260
|
2280 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@260
|
2281 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@260
|
2282 in
|
adamc@260
|
2283 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@260
|
2284 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@260
|
2285 (L'.EAbs ("e2", s, s,
|
adamc@598
|
2286 strcat [sc "((",
|
adamc@598
|
2287 (L'.ERel 1, loc),
|
adamc@598
|
2288 sc ") ",
|
adamc@598
|
2289 (L'.ERel 2, loc),
|
adamc@598
|
2290 sc " (",
|
adamc@598
|
2291 (L'.ERel 0, loc),
|
adamc@598
|
2292 sc "))"]), loc)), loc)), loc),
|
adamc@260
|
2293 fm)
|
adamc@260
|
2294 end
|
adamc@260
|
2295
|
adamc@260
|
2296 | L.EFfi ("Basis", "sql_union") => ((L'.EPrim (Prim.String "UNION"), loc), fm)
|
adamc@260
|
2297 | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm)
|
adamc@260
|
2298 | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)
|
adamc@260
|
2299
|
adamc@265
|
2300 | L.ECApp (
|
adamc@265
|
2301 (L.ECApp (
|
adamc@265
|
2302 (L.ECApp (
|
adamc@265
|
2303 (L.EFfi ("Basis", "sql_count"), _),
|
adamc@265
|
2304 _), _),
|
adamc@265
|
2305 _), _),
|
adamc@544
|
2306 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc),
|
adamc@265
|
2307 fm)
|
adamc@266
|
2308
|
adamc@266
|
2309 | L.ECApp (
|
adamc@266
|
2310 (L.ECApp (
|
adamc@266
|
2311 (L.ECApp (
|
adamc@266
|
2312 (L.ECApp (
|
adamc@266
|
2313 (L.EFfi ("Basis", "sql_aggregate"), _),
|
adamc@266
|
2314 _), _),
|
adamc@266
|
2315 _), _),
|
adamc@266
|
2316 _), _),
|
adamc@266
|
2317 _) =>
|
adamc@266
|
2318 let
|
adamc@266
|
2319 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@266
|
2320 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@266
|
2321 in
|
adamc@266
|
2322 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@266
|
2323 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@598
|
2324 strcat [(L'.ERel 1, loc),
|
adamc@598
|
2325 sc "(",
|
adamc@598
|
2326 (L'.ERel 0, loc),
|
adamc@598
|
2327 sc ")"]), loc)), loc),
|
adamc@266
|
2328 fm)
|
adamc@266
|
2329 end
|
adamc@266
|
2330
|
adamc@266
|
2331 | L.EFfi ("Basis", "sql_summable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
2332 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
2333 | L.ECApp ((L.EFfi ("Basis", "sql_avg"), _), _) =>
|
adamc@266
|
2334 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
2335 (L'.EPrim (Prim.String "AVG"), loc)), loc),
|
adamc@266
|
2336 fm)
|
adamc@266
|
2337 | L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _) =>
|
adamc@266
|
2338 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
2339 (L'.EPrim (Prim.String "SUM"), loc)), loc),
|
adamc@266
|
2340 fm)
|
adamc@266
|
2341
|
adamc@559
|
2342 | L.EFfi ("Basis", "sql_arith_int") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
2343 | L.EFfi ("Basis", "sql_arith_float") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
2344
|
adamc@266
|
2345 | L.EFfi ("Basis", "sql_maxable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
2346 | L.EFfi ("Basis", "sql_maxable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
2347 | L.EFfi ("Basis", "sql_maxable_string") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
2348 | L.ECApp ((L.EFfi ("Basis", "sql_max"), _), _) =>
|
adamc@266
|
2349 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
2350 (L'.EPrim (Prim.String "MAX"), loc)), loc),
|
adamc@266
|
2351 fm)
|
adamc@266
|
2352 | L.ECApp ((L.EFfi ("Basis", "sql_min"), _), _) =>
|
adamc@266
|
2353 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
2354 (L'.EPrim (Prim.String "MIN"), loc)), loc),
|
adamc@266
|
2355 fm)
|
adamc@266
|
2356
|
adamc@268
|
2357 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@268
|
2358 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
|
adamc@268
|
2359
|
adamc@441
|
2360 | L.ECApp (
|
adamc@441
|
2361 (L.ECApp (
|
adamc@441
|
2362 (L.ECApp (
|
adamc@441
|
2363 (L.ECApp (
|
adamc@441
|
2364 (L.EFfi ("Basis", "sql_nfunc"), _),
|
adamc@441
|
2365 _), _),
|
adamc@441
|
2366 _), _),
|
adamc@441
|
2367 _), _),
|
adamc@441
|
2368 _) =>
|
adamc@441
|
2369 let
|
adamc@441
|
2370 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@441
|
2371 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@441
|
2372 in
|
adamc@441
|
2373 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc),
|
adamc@441
|
2374 fm)
|
adamc@441
|
2375 end
|
adamc@441
|
2376 | L.EFfi ("Basis", "sql_current_timestamp") => ((L'.EPrim (Prim.String "CURRENT_TIMESTAMP"), loc), fm)
|
adamc@441
|
2377
|
adamc@746
|
2378 | L.ECApp (
|
adamc@746
|
2379 (L.ECApp (
|
adamc@746
|
2380 (L.ECApp (
|
adamc@746
|
2381 (L.ECApp (
|
adamc@746
|
2382 (L.ECApp (
|
adamc@746
|
2383 (L.EFfi ("Basis", "sql_ufunc"), _),
|
adamc@746
|
2384 _), _),
|
adamc@746
|
2385 _), _),
|
adamc@746
|
2386 _), _),
|
adamc@746
|
2387 _), _),
|
adamc@746
|
2388 _) =>
|
adamc@746
|
2389 let
|
adamc@746
|
2390 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@746
|
2391 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@746
|
2392 in
|
adamc@746
|
2393 ((L'.EAbs ("f", s, (L'.TFun (s, s), loc),
|
adamc@746
|
2394 (L'.EAbs ("x", s, s,
|
adamc@746
|
2395 strcat [(L'.ERel 1, loc),
|
adamc@746
|
2396 sc "(",
|
adamc@746
|
2397 (L'.ERel 0, loc),
|
adamc@746
|
2398 sc ")"]), loc)), loc),
|
adamc@746
|
2399 fm)
|
adamc@746
|
2400 end
|
adamc@890
|
2401 | L.EFfi ("Basis", "sql_octet_length") =>
|
adamc@890
|
2402 ((L'.EPrim (Prim.String (if #supportsOctetLength (Settings.currentDbms ()) then
|
adamc@890
|
2403 "octet_length"
|
adamc@890
|
2404 else
|
adamc@890
|
2405 "length")), loc), fm)
|
adamc@746
|
2406
|
adamc@470
|
2407 | (L.ECApp (
|
adamc@470
|
2408 (L.ECApp (
|
adamc@470
|
2409 (L.ECApp (
|
adamc@470
|
2410 (L.ECApp (
|
adamc@470
|
2411 (L.EFfi ("Basis", "sql_is_null"), _), _),
|
adamc@470
|
2412 _), _),
|
adamc@470
|
2413 _), _),
|
adamc@470
|
2414 _), _)) =>
|
adamc@470
|
2415 let
|
adamc@470
|
2416 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@470
|
2417 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@470
|
2418 in
|
adamc@470
|
2419 ((L'.EAbs ("s", s, s,
|
adamc@598
|
2420 strcat [sc "(",
|
adamc@598
|
2421 (L'.ERel 0, loc),
|
adamc@598
|
2422 sc " IS NULL)"]), loc),
|
adamc@470
|
2423 fm)
|
adamc@470
|
2424 end
|
adamc@470
|
2425
|
adamc@338
|
2426 | L.EFfiApp ("Basis", "nextval", [e]) =>
|
adamc@338
|
2427 let
|
adamc@338
|
2428 val (e, fm) = monoExp (env, st, fm) e
|
adamc@338
|
2429 in
|
adamc@465
|
2430 ((L'.ENextval e, loc), fm)
|
adamc@338
|
2431 end
|
adamc@338
|
2432
|
adamc@139
|
2433 | L.EApp (
|
adamc@139
|
2434 (L.ECApp (
|
adamc@720
|
2435 (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _),
|
adamc@139
|
2436 _), _),
|
adamc@179
|
2437 se) =>
|
adamc@179
|
2438 let
|
adamc@179
|
2439 val (se, fm) = monoExp (env, st, fm) se
|
adamc@179
|
2440 in
|
adamc@179
|
2441 ((L'.EFfiApp ("Basis", "htmlifyString", [se]), loc), fm)
|
adamc@179
|
2442 end
|
adamc@179
|
2443
|
adamc@95
|
2444 | L.EApp (
|
adamc@95
|
2445 (L.EApp (
|
adamc@720
|
2446 (L.ECApp (
|
adamc@720
|
2447 (L.ECApp (
|
adamc@95
|
2448 (L.ECApp (
|
adamc@139
|
2449 (L.ECApp (
|
adamc@720
|
2450 (L.EFfi ("Basis", "join"),
|
adamc@720
|
2451 _), _), _),
|
adamc@139
|
2452 _), _),
|
adamc@720
|
2453 _), _),
|
adamc@720
|
2454 _), _),
|
adamc@720
|
2455 xml1), _),
|
adamc@720
|
2456 xml2) =>
|
adamc@179
|
2457 let
|
adamc@179
|
2458 val (xml1, fm) = monoExp (env, st, fm) xml1
|
adamc@179
|
2459 val (xml2, fm) = monoExp (env, st, fm) xml2
|
adamc@179
|
2460 in
|
adamc@179
|
2461 ((L'.EStrcat (xml1, xml2), loc), fm)
|
adamc@179
|
2462 end
|
adamc@95
|
2463
|
adamc@95
|
2464 | L.EApp (
|
adamc@95
|
2465 (L.EApp (
|
adamc@104
|
2466 (L.EApp (
|
adamc@721
|
2467 (L.EApp (
|
adamc@720
|
2468 (L.ECApp (
|
adamc@104
|
2469 (L.ECApp (
|
adamc@104
|
2470 (L.ECApp (
|
adamc@139
|
2471 (L.ECApp (
|
adamc@139
|
2472 (L.ECApp (
|
adamc@139
|
2473 (L.ECApp (
|
adamc@139
|
2474 (L.ECApp (
|
adamc@721
|
2475 (L.ECApp (
|
adamc@721
|
2476 (L.EFfi ("Basis", "tag"),
|
adamc@721
|
2477 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@721
|
2478 class), _),
|
adamc@720
|
2479 attrs), _),
|
adamc@720
|
2480 tag), _),
|
adamc@95
|
2481 xml) =>
|
adamc@95
|
2482 let
|
adamc@1065
|
2483 val inT = !inTag
|
adamc@1065
|
2484 val () = inTag := true
|
adamc@1065
|
2485
|
adamc@140
|
2486 fun getTag' (e, _) =
|
adamc@140
|
2487 case e of
|
adamc@143
|
2488 L.EFfi ("Basis", tag) => (tag, [])
|
adamc@143
|
2489 | L.ECApp (e, t) => let
|
adamc@143
|
2490 val (tag, ts) = getTag' e
|
adamc@143
|
2491 in
|
adamc@143
|
2492 (tag, ts @ [t])
|
adamc@143
|
2493 end
|
adamc@140
|
2494 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@140
|
2495 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
2496 ("", []))
|
adamc@140
|
2497
|
adamc@95
|
2498 fun getTag (e, _) =
|
adamc@95
|
2499 case e of
|
adamc@143
|
2500 L.EFfiApp ("Basis", tag, [(L.ERecord [], _)]) => (tag, [])
|
adamc@140
|
2501 | L.EApp (e, (L.ERecord [], _)) => getTag' e
|
adamc@95
|
2502 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@95
|
2503 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
2504 ("", []))
|
adamc@95
|
2505
|
adamc@143
|
2506 val (tag, targs) = getTag tag
|
adamc@95
|
2507
|
adamc@179
|
2508 val (attrs, fm) = monoExp (env, st, fm) attrs
|
adamc@598
|
2509 val attrs = case #1 attrs of
|
adamc@598
|
2510 L'.ERecord xes => xes
|
adamc@598
|
2511 | _ => raise Fail "Non-record attributes!"
|
adamc@104
|
2512
|
adamc@717
|
2513 val attrs =
|
adamc@717
|
2514 if List.exists (fn ("Link", _, _) => true
|
adamc@717
|
2515 | _ => false) attrs then
|
adamc@717
|
2516 List.filter (fn ("Href", _, _) => false
|
adamc@717
|
2517 | _ => true) attrs
|
adamc@717
|
2518 else
|
adamc@717
|
2519 attrs
|
adamc@717
|
2520
|
adamc@1042
|
2521 fun findOnload (attrs, onload, onunload, acc) =
|
adamc@668
|
2522 case attrs of
|
adamc@1042
|
2523 [] => (onload, onunload, acc)
|
adamc@1042
|
2524 | ("Onload", e, _) :: rest => findOnload (rest, SOME e, onunload, acc)
|
adamc@1042
|
2525 | ("Onunload", e, _) :: rest => findOnload (rest, onload, SOME e, acc)
|
adamc@1042
|
2526 | x :: rest => findOnload (rest, onload, onunload, x :: acc)
|
adamc@679
|
2527
|
adamc@1042
|
2528 val (onload, onunload, attrs) = findOnload (attrs, NONE, NONE, [])
|
adamc@668
|
2529
|
adamc@721
|
2530 val (class, fm) = monoExp (env, st, fm) class
|
adamc@721
|
2531
|
adamc@143
|
2532 fun tagStart tag =
|
adamc@598
|
2533 let
|
adamc@721
|
2534 val t = (L'.TFfi ("Basis", "string"), loc)
|
adamc@598
|
2535 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@721
|
2536
|
adamc@721
|
2537 val s = (L'.ECase (class,
|
adamc@721
|
2538 [((L'.PNone t, loc),
|
adamc@721
|
2539 s),
|
adamc@721
|
2540 ((L'.PSome (t, (L'.PVar ("x", t), loc)), loc),
|
adamc@721
|
2541 (L'.EStrcat (s,
|
adamc@721
|
2542 (L'.EStrcat ((L'.EPrim (Prim.String " class=\""), loc),
|
adamc@721
|
2543 (L'.EStrcat ((L'.ERel 0, loc),
|
adamc@721
|
2544 (L'.EPrim (Prim.String "\""), loc)),
|
adamc@721
|
2545 loc)), loc)), loc))],
|
adamc@721
|
2546 {disc = (L'.TOption t, loc),
|
adamc@721
|
2547 result = t}), loc)
|
adamc@598
|
2548 in
|
adamc@598
|
2549 foldl (fn (("Action", _, _), acc) => acc
|
adamc@598
|
2550 | (("Source", _, _), acc) => acc
|
adamc@598
|
2551 | ((x, e, t), (s, fm)) =>
|
adamc@598
|
2552 case t of
|
adamc@598
|
2553 (L'.TFfi ("Basis", "bool"), _) =>
|
adamc@598
|
2554 let
|
adamc@598
|
2555 val s' = " " ^ lowercaseFirst x
|
adamc@598
|
2556 in
|
adamc@598
|
2557 ((L'.ECase (e,
|
adamc@598
|
2558 [((L'.PCon (L'.Enum,
|
adamc@598
|
2559 L'.PConFfi {mod = "Basis",
|
adamc@598
|
2560 datatyp = "bool",
|
adamc@598
|
2561 con = "True",
|
adamc@598
|
2562 arg = NONE},
|
adamc@598
|
2563 NONE), loc),
|
adamc@598
|
2564 (L'.EStrcat (s,
|
adamc@598
|
2565 (L'.EPrim (Prim.String s'), loc)), loc)),
|
adamc@598
|
2566 ((L'.PCon (L'.Enum,
|
adamc@598
|
2567 L'.PConFfi {mod = "Basis",
|
adamc@598
|
2568 datatyp = "bool",
|
adamc@598
|
2569 con = "False",
|
adamc@598
|
2570 arg = NONE},
|
adamc@598
|
2571 NONE), loc),
|
adamc@598
|
2572 s)],
|
adamc@598
|
2573 {disc = (L'.TFfi ("Basis", "bool"), loc),
|
adamc@598
|
2574 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@598
|
2575 fm)
|
adamc@598
|
2576 end
|
adamc@895
|
2577 | (L'.TFun (dom, _), _) =>
|
adamc@598
|
2578 let
|
adamc@598
|
2579 val s' = " " ^ lowercaseFirst x ^ "='"
|
adamc@970
|
2580 val (e, s') =
|
adamc@970
|
2581 case #1 dom of
|
adamc@970
|
2582 L'.TRecord [] => ((L'.EApp (e, (L'.ERecord [], loc)), loc), s')
|
adamc@970
|
2583 | _ => ((L'.EApp ((L'.EApp (e, (L'.EFfiApp ("Basis", "kc", []), loc)),
|
adamc@970
|
2584 loc), (L'.ERecord [], loc)), loc),
|
adamc@970
|
2585 s' ^ "uwe=event;")
|
adamc@970
|
2586 val s' = s' ^ "exec("
|
adamc@598
|
2587 in
|
adamc@598
|
2588 ((L'.EStrcat (s,
|
adamc@598
|
2589 (L'.EStrcat (
|
adamc@598
|
2590 (L'.EPrim (Prim.String s'), loc),
|
adamc@598
|
2591 (L'.EStrcat (
|
adamc@815
|
2592 (L'.EJavaScript (L'.Attribute, e), loc),
|
adamc@970
|
2593 (L'.EPrim (Prim.String ");return false'"), loc)), loc)),
|
adamc@598
|
2594 loc)), loc),
|
adamc@598
|
2595 fm)
|
adamc@598
|
2596 end
|
adamc@598
|
2597 | _ =>
|
adamc@598
|
2598 let
|
adamc@598
|
2599 val fooify =
|
adamc@598
|
2600 case x of
|
adamc@717
|
2601 "Link" => urlifyExp
|
adamc@717
|
2602 | "Action" => urlifyExp
|
adamc@598
|
2603 | _ => attrifyExp
|
adamc@120
|
2604
|
adamc@724
|
2605 val x =
|
adamc@724
|
2606 case x of
|
adamc@724
|
2607 "Typ" => "Type"
|
adamc@907
|
2608 | "Link" => "Href"
|
adamc@724
|
2609 | _ => x
|
adamc@598
|
2610 val xp = " " ^ lowercaseFirst x ^ "=\""
|
adamc@179
|
2611
|
adamc@598
|
2612 val (e, fm) = fooify env fm (e, t)
|
adamc@598
|
2613 in
|
adamc@598
|
2614 ((L'.EStrcat (s,
|
adamc@598
|
2615 (L'.EStrcat ((L'.EPrim (Prim.String xp), loc),
|
adamc@598
|
2616 (L'.EStrcat (e,
|
adamc@598
|
2617 (L'.EPrim (Prim.String "\""),
|
adamc@598
|
2618 loc)),
|
adamc@598
|
2619 loc)),
|
adamc@598
|
2620 loc)), loc),
|
adamc@598
|
2621 fm)
|
adamc@598
|
2622 end)
|
adamc@598
|
2623 (s, fm) attrs
|
adamc@598
|
2624 end
|
adamc@104
|
2625
|
adamc@143
|
2626 fun input typ =
|
adamc@143
|
2627 case targs of
|
adamc@155
|
2628 [_, (L.CName name, _)] =>
|
adamc@179
|
2629 let
|
adamc@179
|
2630 val (ts, fm) = tagStart "input"
|
adamc@179
|
2631 in
|
adamc@179
|
2632 ((L'.EStrcat (ts,
|
adamc@802
|
2633 (L'.EPrim (Prim.String (" type=\"" ^ typ ^ "\" name=\"" ^ name ^ "\" />")),
|
adamc@179
|
2634 loc)), loc), fm)
|
adamc@179
|
2635 end
|
adamc@143
|
2636 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
2637 raise Fail "No name passed to input tag")
|
adamc@104
|
2638
|
adamc@565
|
2639 fun normal (tag, extra, extraInner) =
|
adamc@143
|
2640 let
|
adamc@179
|
2641 val (tagStart, fm) = tagStart tag
|
adamc@152
|
2642 val tagStart = case extra of
|
adamc@152
|
2643 NONE => tagStart
|
adamc@152
|
2644 | SOME extra => (L'.EStrcat (tagStart, extra), loc)
|
adamc@152
|
2645
|
adamc@143
|
2646 fun normal () =
|
adamc@179
|
2647 let
|
adamc@179
|
2648 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@916
|
2649
|
adamc@916
|
2650 val xml = case extraInner of
|
adamc@916
|
2651 NONE => xml
|
adamc@916
|
2652 | SOME ei => (L'.EStrcat (ei, xml), loc)
|
adamc@179
|
2653 in
|
adamc@179
|
2654 ((L'.EStrcat ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String ">"), loc)), loc),
|
adamc@179
|
2655 (L'.EStrcat (xml,
|
adamc@179
|
2656 (L'.EPrim (Prim.String (String.concat ["</", tag, ">"])),
|
adamc@179
|
2657 loc)), loc)),
|
adamc@179
|
2658 loc),
|
adamc@179
|
2659 fm)
|
adamc@179
|
2660 end
|
adamc@984
|
2661
|
adamc@984
|
2662 fun isSingleton () =
|
adamc@984
|
2663 let
|
adamc@984
|
2664 val (bef, aft) = Substring.splitl (not o Char.isSpace) (Substring.full tag)
|
adamc@984
|
2665 in
|
adamc@984
|
2666 SS.member (singletons, if Substring.isEmpty aft then
|
adamc@984
|
2667 tag
|
adamc@984
|
2668 else
|
adamc@984
|
2669 Substring.string bef)
|
adamc@984
|
2670 end
|
adamc@143
|
2671 in
|
adamc@143
|
2672 case xml of
|
adamc@143
|
2673 (L.EApp ((L.ECApp (
|
adamc@143
|
2674 (L.ECApp ((L.EFfi ("Basis", "cdata"), _),
|
adamc@143
|
2675 _), _),
|
adamc@143
|
2676 _), _),
|
adamc@143
|
2677 (L.EPrim (Prim.String s), _)), _) =>
|
adamc@984
|
2678 if CharVector.all Char.isSpace s andalso isSingleton () then
|
adamc@802
|
2679 ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String " />"), loc)), loc), fm)
|
adamc@143
|
2680 else
|
adamc@143
|
2681 normal ()
|
adamc@143
|
2682 | _ => normal ()
|
adamc@143
|
2683 end
|
adamc@606
|
2684
|
adamc@606
|
2685 fun setAttrs jexp =
|
adamc@606
|
2686 let
|
adamc@606
|
2687 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@606
|
2688
|
adamc@606
|
2689 val assgns = List.mapPartial
|
adamc@606
|
2690 (fn ("Source", _, _) => NONE
|
adamc@800
|
2691 | ("Onchange", e, _) =>
|
adamc@970
|
2692 SOME (strcat [str "addOnChange(d,exec(",
|
adamc@815
|
2693 (L'.EJavaScript (L'.Script, e), loc),
|
adamc@970
|
2694 str "))"])
|
adamc@606
|
2695 | (x, e, _) =>
|
adamc@970
|
2696 SOME (strcat [str ("d." ^ lowercaseFirst x ^ "=exec("),
|
adamc@815
|
2697 (L'.EJavaScript (L'.Script, e), loc),
|
adamc@970
|
2698 str ");"]))
|
adamc@606
|
2699 attrs
|
adamc@606
|
2700 in
|
adamc@606
|
2701 case assgns of
|
adamc@606
|
2702 [] => jexp
|
adamc@606
|
2703 | _ => strcat (str "var d="
|
adamc@606
|
2704 :: jexp
|
adamc@606
|
2705 :: str ";"
|
adamc@606
|
2706 :: assgns)
|
adamc@606
|
2707 end
|
adamc@1042
|
2708
|
adamc@1042
|
2709 fun execify e =
|
adamc@1042
|
2710 case e of
|
adamc@1042
|
2711 NONE => (L'.EPrim (Prim.String ""), loc)
|
adamc@1042
|
2712 | SOME e =>
|
adamc@1042
|
2713 let
|
adamc@1042
|
2714 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
|
adamc@1042
|
2715 in
|
adamc@1042
|
2716 (L'.EStrcat ((L'.EPrim (Prim.String "exec("), loc),
|
adamc@1042
|
2717 (L'.EStrcat ((L'.EJavaScript (L'.Attribute, e), loc),
|
adamc@1042
|
2718 (L'.EPrim (Prim.String ")"), loc)), loc)), loc)
|
adamc@1042
|
2719 end
|
adamc@152
|
2720 in
|
adamc@1065
|
2721 (case tag of
|
adamc@1065
|
2722 "body" => let
|
adamc@1065
|
2723 val onload = execify onload
|
adamc@1065
|
2724 val onunload = execify onunload
|
adamc@1065
|
2725 in
|
adamc@1065
|
2726 normal ("body",
|
adamc@1065
|
2727 SOME (L'.EStrcat ((L'.EFfiApp ("Basis", "maybe_onload",
|
adamc@1065
|
2728 [(L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings",
|
adamc@1065
|
2729 [(L'.ERecord [], loc)]), loc),
|
adamc@1065
|
2730 onload), loc)]),
|
adamc@1065
|
2731 loc),
|
adamc@1065
|
2732 (L'.EFfiApp ("Basis", "maybe_onunload",
|
adamc@1065
|
2733 [onunload]),
|
adamc@1065
|
2734 loc)), loc),
|
adamc@1065
|
2735 SOME (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]), loc))
|
adamc@1065
|
2736 end
|
adamc@568
|
2737
|
adamc@1065
|
2738 | "dyn" =>
|
adamc@1065
|
2739 let
|
adamc@1065
|
2740 fun inTag tag = case targs of
|
adamc@1065
|
2741 (L.CRecord (_, ctx), _) :: _ =>
|
adamc@1065
|
2742 List.exists (fn ((L.CName tag', _), _) => tag' = tag
|
adamc@1065
|
2743 | _ => false) ctx
|
adamc@1065
|
2744 | _ => false
|
adamc@1065
|
2745
|
adamc@1065
|
2746 val tag = if inTag "Tr" then
|
adamc@1065
|
2747 "tr"
|
adamc@1065
|
2748 else if inTag "Table" then
|
adamc@1065
|
2749 "table"
|
adamc@1065
|
2750 else
|
adamc@1065
|
2751 "span"
|
adamc@1065
|
2752 in
|
adamc@1065
|
2753 case attrs of
|
adamc@1065
|
2754 [("Signal", e, _)] =>
|
adamc@1065
|
2755 ((L'.EStrcat
|
adamc@1065
|
2756 ((L'.EPrim (Prim.String ("<script type=\"text/javascript\">dyn(\""
|
adamc@1065
|
2757 ^ tag ^ "\", execD(")), loc),
|
adamc@1065
|
2758 (L'.EStrcat ((L'.EJavaScript (L'.Script, e), loc),
|
adamc@1065
|
2759 (L'.EPrim (Prim.String ("))</script>")), loc)), loc)), loc),
|
adamc@1065
|
2760 fm)
|
adamc@1065
|
2761 | _ => raise Fail "Monoize: Bad dyn attributes"
|
adamc@1065
|
2762 end
|
adamc@1065
|
2763
|
adamc@1065
|
2764 | "submit" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@1065
|
2765 | "button" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@1065
|
2766 | "hidden" => input "hidden"
|
adamc@152
|
2767
|
adamc@1065
|
2768 | "textbox" =>
|
adamc@1065
|
2769 (case targs of
|
adamc@1065
|
2770 [_, (L.CName name, _)] =>
|
adamc@1065
|
2771 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@1065
|
2772 NONE =>
|
adamc@1065
|
2773 let
|
adamc@1065
|
2774 val (ts, fm) = tagStart "input"
|
adamc@1065
|
2775 in
|
adamc@1065
|
2776 ((L'.EStrcat (ts,
|
adamc@1065
|
2777 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\" />")),
|
adamc@1065
|
2778 loc)), loc), fm)
|
adamc@1065
|
2779 end
|
adamc@1065
|
2780 | SOME (_, src, _) =>
|
adamc@1065
|
2781 (strcat [str "<script type=\"text/javascript\">inp(exec(",
|
adamc@1065
|
2782 (L'.EJavaScript (L'.Script, src), loc),
|
adamc@1065
|
2783 str "))</script>"],
|
adamc@1065
|
2784 fm))
|
adamc@1065
|
2785 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@1065
|
2786 raise Fail "No name passed to textbox tag"))
|
adamc@1065
|
2787 | "password" => input "password"
|
adamc@1065
|
2788 | "textarea" =>
|
adamc@1065
|
2789 (case targs of
|
adamc@1065
|
2790 [_, (L.CName name, _)] =>
|
adamc@1065
|
2791 let
|
adamc@1065
|
2792 val (ts, fm) = tagStart "textarea"
|
adamc@1065
|
2793 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@1065
|
2794 in
|
adamc@1065
|
2795 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@1065
|
2796 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")), loc)), loc),
|
adamc@1065
|
2797 (L'.EStrcat (xml,
|
adamc@1065
|
2798 (L'.EPrim (Prim.String "</textarea>"),
|
adamc@1065
|
2799 loc)), loc)),
|
adamc@1065
|
2800 loc), fm)
|
adamc@1065
|
2801 end
|
adamc@1065
|
2802 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@1065
|
2803 raise Fail "No name passed to ltextarea tag"))
|
adamc@153
|
2804
|
adamc@1065
|
2805 | "checkbox" => input "checkbox"
|
adamc@1065
|
2806 | "upload" => input "file"
|
adamc@190
|
2807
|
adamc@1065
|
2808 | "radio" =>
|
adamc@1065
|
2809 (case targs of
|
adamc@1065
|
2810 [_, (L.CName name, _)] =>
|
adamc@1065
|
2811 monoExp (env, St.setRadioGroup (st, name), fm) xml
|
adamc@1065
|
2812 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@1065
|
2813 raise Fail "No name passed to radio tag"))
|
adamc@1065
|
2814 | "radioOption" =>
|
adamc@1065
|
2815 (case St.radioGroup st of
|
adamc@1065
|
2816 NONE => raise Fail "No name for radioGroup"
|
adamc@1065
|
2817 | SOME name =>
|
adamc@1065
|
2818 normal ("input",
|
adamc@1065
|
2819 SOME (L'.EPrim (Prim.String (" type=\"radio\" name=\"" ^ name ^ "\"")), loc),
|
adamc@1065
|
2820 NONE))
|
adamc@152
|
2821
|
adamc@1065
|
2822 | "select" =>
|
adamc@1065
|
2823 (case targs of
|
adamc@1065
|
2824 [_, (L.CName name, _)] =>
|
adamc@1065
|
2825 let
|
adamc@1065
|
2826 val (ts, fm) = tagStart "select"
|
adamc@1065
|
2827 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@1065
|
2828 in
|
adamc@1065
|
2829 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@1065
|
2830 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")),
|
adamc@1065
|
2831 loc)), loc),
|
adamc@1065
|
2832 (L'.EStrcat (xml,
|
adamc@1065
|
2833 (L'.EPrim (Prim.String "</select>"),
|
adamc@1065
|
2834 loc)), loc)),
|
adamc@1065
|
2835 loc),
|
adamc@1065
|
2836 fm)
|
adamc@1065
|
2837 end
|
adamc@1065
|
2838 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@1065
|
2839 raise Fail "No name passed to lselect tag"))
|
adamc@154
|
2840
|
adamc@1065
|
2841 | "ctextbox" =>
|
adamc@1065
|
2842 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@1065
|
2843 NONE =>
|
adamc@1065
|
2844 let
|
adamc@1065
|
2845 val (ts, fm) = tagStart "input"
|
adamc@1065
|
2846 in
|
adamc@1065
|
2847 ((L'.EStrcat (ts,
|
adamc@1065
|
2848 (L'.EPrim (Prim.String " />"), loc)),
|
adamc@1065
|
2849 loc), fm)
|
adamc@1065
|
2850 end
|
adamc@1065
|
2851 | SOME (_, src, _) =>
|
adamc@1065
|
2852 let
|
adamc@1065
|
2853 val sc = strcat [str "inp(exec(",
|
adamc@1065
|
2854 (L'.EJavaScript (L'.Script, src), loc),
|
adamc@1065
|
2855 str "))"]
|
adamc@1065
|
2856 val sc = setAttrs sc
|
adamc@1065
|
2857 in
|
adamc@1065
|
2858 (strcat [str "<script type=\"text/javascript\">",
|
adamc@1065
|
2859 sc,
|
adamc@1065
|
2860 str "</script>"],
|
adamc@1065
|
2861 fm)
|
adamc@1065
|
2862 end)
|
adamc@797
|
2863
|
adamc@1065
|
2864 | "ccheckbox" =>
|
adamc@1065
|
2865 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@1065
|
2866 NONE =>
|
adamc@1065
|
2867 let
|
adamc@1065
|
2868 val (ts, fm) = tagStart "input type=\"checkbox\""
|
adamc@1065
|
2869 in
|
adamc@1065
|
2870 ((L'.EStrcat (ts,
|
adamc@1065
|
2871 (L'.EPrim (Prim.String " />"), loc)),
|
adamc@1065
|
2872 loc), fm)
|
adamc@1065
|
2873 end
|
adamc@1065
|
2874 | SOME (_, src, _) =>
|
adamc@1065
|
2875 let
|
adamc@1065
|
2876 val sc = strcat [str "chk(exec(",
|
adamc@1065
|
2877 (L'.EJavaScript (L'.Script, src), loc),
|
adamc@1065
|
2878 str "))"]
|
adamc@1065
|
2879 val sc = setAttrs sc
|
adamc@1065
|
2880 in
|
adamc@1065
|
2881 (strcat [str "<script type=\"text/javascript\">",
|
adamc@1065
|
2882 sc,
|
adamc@1065
|
2883 str "</script>"],
|
adamc@1065
|
2884 fm)
|
adamc@1065
|
2885 end)
|
adamc@817
|
2886
|
adamc@1065
|
2887 | "cselect" =>
|
adamc@1065
|
2888 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@1065
|
2889 NONE =>
|
adamc@1065
|
2890 let
|
adamc@1065
|
2891 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@1065
|
2892 val (ts, fm) = tagStart "select"
|
adamc@1065
|
2893 in
|
adamc@1065
|
2894 (strcat [ts,
|
adamc@1065
|
2895 str ">",
|
adamc@1065
|
2896 xml,
|
adamc@1065
|
2897 str "</select>"],
|
adamc@1065
|
2898 fm)
|
adamc@1065
|
2899 end
|
adamc@1065
|
2900 | SOME (_, src, _) =>
|
adamc@1065
|
2901 let
|
adamc@1065
|
2902 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@797
|
2903
|
adamc@1065
|
2904 val sc = strcat [str "sel(exec(",
|
adamc@1065
|
2905 (L'.EJavaScript (L'.Script, src), loc),
|
adamc@1065
|
2906 str "),exec(",
|
adamc@1065
|
2907 (L'.EJavaScript (L'.Script, xml), loc),
|
adamc@1065
|
2908 str "))"]
|
adamc@1065
|
2909 val sc = setAttrs sc
|
adamc@1065
|
2910 in
|
adamc@1065
|
2911 (strcat [str "<script type=\"text/javascript\">",
|
adamc@1065
|
2912 sc,
|
adamc@1065
|
2913 str "</script>"],
|
adamc@1065
|
2914 fm)
|
adamc@1065
|
2915 end)
|
adamc@154
|
2916
|
adamc@1065
|
2917 | "coption" => normal ("option", NONE, NONE)
|
adamc@797
|
2918
|
adamc@1065
|
2919 | "tabl" => normal ("table", NONE, NONE)
|
adamc@1065
|
2920 | _ => normal (tag, NONE, NONE))
|
adamc@1065
|
2921 before inTag := inT
|
adamc@95
|
2922 end
|
adamc@94
|
2923
|
adamc@141
|
2924 | L.EApp ((L.ECApp (
|
adamc@361
|
2925 (L.ECApp ((L.EFfi ("Basis", "form"), _), _), _),
|
adamc@734
|
2926 (L.CRecord (_, fields), _)), _),
|
adamc@141
|
2927 xml) =>
|
adamc@143
|
2928 let
|
adamc@143
|
2929 fun findSubmit (e, _) =
|
adamc@143
|
2930 case e of
|
adamc@143
|
2931 L.EApp (
|
adamc@143
|
2932 (L.EApp (
|
adamc@143
|
2933 (L.ECApp (
|
adamc@143
|
2934 (L.ECApp (
|
adamc@143
|
2935 (L.ECApp (
|
adamc@143
|
2936 (L.ECApp (
|
adamc@143
|
2937 (L.EFfi ("Basis", "join"),
|
adamc@143
|
2938 _), _), _),
|
adamc@143
|
2939 _), _),
|
adamc@143
|
2940 _), _),
|
adamc@143
|
2941 _), _),
|
adamc@143
|
2942 xml1), _),
|
adamc@143
|
2943 xml2) => (case findSubmit xml1 of
|
adamc@143
|
2944 Error => Error
|
adamc@143
|
2945 | NotFound => findSubmit xml2
|
adamc@143
|
2946 | Found e =>
|
adamc@143
|
2947 case findSubmit xml2 of
|
adamc@143
|
2948 NotFound => Found e
|
adamc@143
|
2949 | _ => Error)
|
adamc@143
|
2950 | L.EApp (
|
adamc@143
|
2951 (L.EApp (
|
adamc@143
|
2952 (L.EApp (
|
adamc@730
|
2953 (L.EApp (
|
adamc@143
|
2954 (L.ECApp (
|
adamc@143
|
2955 (L.ECApp (
|
adamc@143
|
2956 (L.ECApp (
|
adamc@143
|
2957 (L.ECApp (
|
adamc@143
|
2958 (L.ECApp (
|
adamc@143
|
2959 (L.ECApp (
|
adamc@143
|
2960 (L.ECApp (
|
adamc@730
|
2961 (L.ECApp (
|
adamc@730
|
2962 (L.EFfi ("Basis", "tag"),
|
adamc@730
|
2963 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@730
|
2964 _), _),
|
adamc@143
|
2965 attrs), _),
|
adamc@143
|
2966 _), _),
|
adamc@143
|
2967 xml) =>
|
adamc@143
|
2968 (case #1 attrs of
|
adamc@143
|
2969 L.ERecord xes =>
|
adamc@143
|
2970 (case ListUtil.search (fn ((L.CName "Action", _), e, t) => SOME (e, t)
|
adamc@143
|
2971 | _ => NONE) xes of
|
adamc@143
|
2972 NONE => findSubmit xml
|
adamc@143
|
2973 | SOME et =>
|
adamc@143
|
2974 case findSubmit xml of
|
adamc@143
|
2975 NotFound => Found et
|
adamc@143
|
2976 | _ => Error)
|
adamc@143
|
2977 | _ => findSubmit xml)
|
adamc@143
|
2978 | _ => NotFound
|
adamc@143
|
2979
|
adamc@735
|
2980 val (func, action, fm) = case findSubmit xml of
|
adamc@735
|
2981 NotFound => (0, (L'.EPrim (Prim.String ""), loc), fm)
|
adamc@143
|
2982 | Error => raise Fail "Not ready for multi-submit lforms yet"
|
adamc@598
|
2983 | Found (action, actionT) =>
|
adamc@598
|
2984 let
|
adamc@735
|
2985 val func = case #1 action of
|
adamc@735
|
2986 L.EClosure (n, _) => n
|
adamc@735
|
2987 | _ => raise Fail "Monoize: Action is not a closure"
|
adamc@598
|
2988 val actionT = monoType env actionT
|
adamc@598
|
2989 val (action, fm) = monoExp (env, st, fm) action
|
adamc@598
|
2990 val (action, fm) = urlifyExp env fm (action, actionT)
|
adamc@598
|
2991 in
|
adamc@735
|
2992 (func,
|
adamc@735
|
2993 (L'.EStrcat ((L'.EPrim (Prim.String " action=\""), loc),
|
adamc@598
|
2994 (L'.EStrcat (action,
|
adamc@598
|
2995 (L'.EPrim (Prim.String "\""), loc)), loc)), loc),
|
adamc@598
|
2996 fm)
|
adamc@598
|
2997 end
|
adamc@734
|
2998
|
adamc@737
|
2999 val hasUpload = CoreUtil.Exp.exists {kind = fn _ => false,
|
adamc@737
|
3000 con = fn _ => false,
|
adamc@737
|
3001 exp = fn e =>
|
adamc@737
|
3002 case e of
|
adamc@737
|
3003 L.EFfi ("Basis", "upload") => true
|
adamc@737
|
3004 | _ => false} xml
|
adamc@737
|
3005
|
adamc@179
|
3006 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@735
|
3007
|
adamc@735
|
3008 val xml =
|
adamc@735
|
3009 if IS.member (!readCookie, func) then
|
adamc@735
|
3010 let
|
adamc@735
|
3011 fun inFields s = List.exists (fn ((L.CName s', _), _) => s' = s
|
adamc@735
|
3012 | _ => true) fields
|
adamc@735
|
3013
|
adamc@735
|
3014 fun getSigName () =
|
adamc@735
|
3015 let
|
adamc@735
|
3016 fun getSigName' n =
|
adamc@735
|
3017 let
|
adamc@735
|
3018 val s = "Sig" ^ Int.toString n
|
adamc@735
|
3019 in
|
adamc@735
|
3020 if inFields s then
|
adamc@735
|
3021 getSigName' (n + 1)
|
adamc@735
|
3022 else
|
adamc@735
|
3023 s
|
adamc@735
|
3024 end
|
adamc@735
|
3025 in
|
adamc@735
|
3026 if inFields "Sig" then
|
adamc@735
|
3027 getSigName' 0
|
adamc@735
|
3028 else
|
adamc@735
|
3029 "Sig"
|
adamc@735
|
3030 end
|
adamc@735
|
3031
|
adamc@735
|
3032 val sigName = getSigName ()
|
adamc@735
|
3033 val sigSet = (L'.EFfiApp ("Basis", "sigString", [(L'.ERecord [], loc)]), loc)
|
adamc@735
|
3034 val sigSet = (L'.EStrcat ((L'.EPrim (Prim.String ("<input type=\"hidden\" name=\""
|
adamc@735
|
3035 ^ sigName
|
adamc@735
|
3036 ^ "\" value=\"")), loc),
|
adamc@735
|
3037 sigSet), loc)
|
adamc@735
|
3038 val sigSet = (L'.EStrcat (sigSet,
|
adamc@803
|
3039 (L'.EPrim (Prim.String "\" />"), loc)), loc)
|
adamc@735
|
3040 in
|
adamc@735
|
3041 (L'.EStrcat (sigSet, xml), loc)
|
adamc@735
|
3042 end
|
adamc@735
|
3043 else
|
adamc@735
|
3044 xml
|
adamc@737
|
3045
|
adamc@737
|
3046 val action = if hasUpload then
|
adamc@737
|
3047 (L'.EStrcat (action,
|
adamc@737
|
3048 (L'.EPrim (Prim.String " enctype=\"multipart/form-data\""), loc)), loc)
|
adamc@737
|
3049 else
|
adamc@737
|
3050 action
|
adamc@737
|
3051
|
adamc@143
|
3052 in
|
adamc@1026
|
3053 ((L'.EStrcat ((L'.EStrcat ((L'.EPrim (Prim.String "<form method=\"post\""), loc),
|
adamc@179
|
3054 (L'.EStrcat (action,
|
adamc@598
|
3055 (L'.EPrim (Prim.String ">"), loc)), loc)), loc),
|
adamc@179
|
3056 (L'.EStrcat (xml,
|
adamc@179
|
3057 (L'.EPrim (Prim.String "</form>"), loc)), loc)), loc),
|
adamc@179
|
3058 fm)
|
adamc@143
|
3059 end
|
adamc@141
|
3060
|
adamc@756
|
3061 | L.ECApp ((L.ECApp ((L.ECApp ((L.ECApp (
|
adamc@756
|
3062 (L.EFfi ("Basis", "subform"), _), _), _), _),
|
adamc@756
|
3063 _), _), _), (L.CName nm, loc)) =>
|
adamc@756
|
3064 let
|
adamc@756
|
3065 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@756
|
3066 in
|
adamc@756
|
3067 ((L'.EAbs ("xml", s, s,
|
adamc@756
|
3068 strcat [(L'.EPrim (Prim.String ("<input type=\"hidden\" name=\".b\" value=\""
|
adamc@803
|
3069 ^ nm ^ "\" />")), loc),
|
adamc@756
|
3070 (L'.ERel 0, loc),
|
adamc@803
|
3071 (L'.EPrim (Prim.String ("<input type=\"hidden\" name=\".e\" value=\"1\" />")), loc)]),
|
adamc@756
|
3072 loc),
|
adamc@756
|
3073 fm)
|
adamc@756
|
3074 end
|
adamc@756
|
3075
|
adamc@758
|
3076 | L.ECApp ((L.ECApp ((L.ECApp ((L.ECApp (
|
adamc@758
|
3077 (L.EFfi ("Basis", "subforms"), _), _), _), _),
|
adamc@758
|
3078 _), _), _), (L.CName nm, loc)) =>
|
adamc@758
|
3079 let
|
adamc@758
|
3080 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@758
|
3081 in
|
adamc@758
|
3082 ((L'.EAbs ("xml", s, s,
|
adamc@758
|
3083 strcat [(L'.EPrim (Prim.String ("<input type=\"hidden\" name=\".s\" value=\""
|
adamc@803
|
3084 ^ nm ^ "\" />")), loc),
|
adamc@758
|
3085 (L'.ERel 0, loc),
|
adamc@803
|
3086 (L'.EPrim (Prim.String ("<input type=\"hidden\" name=\".e\" value=\"1\" />")), loc)]),
|
adamc@758
|
3087 loc),
|
adamc@758
|
3088 fm)
|
adamc@758
|
3089 end
|
adamc@758
|
3090
|
adamc@758
|
3091 | L.ECApp ((L.ECApp (
|
adamc@758
|
3092 (L.EFfi ("Basis", "entry"), _), _), _), _) =>
|
adamc@758
|
3093 let
|
adamc@758
|
3094 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@758
|
3095 in
|
adamc@758
|
3096 ((L'.EAbs ("xml", s, s,
|
adamc@803
|
3097 strcat [(L'.EPrim (Prim.String ("<input type=\"hidden\" name=\".i\" value=\"1\" />")), loc),
|
adamc@758
|
3098 (L'.ERel 0, loc),
|
adamc@803
|
3099 (L'.EPrim (Prim.String ("<input type=\"hidden\" name=\".e\" value=\"1\" />")), loc)]),
|
adamc@758
|
3100 loc),
|
adamc@758
|
3101 fm)
|
adamc@758
|
3102 end
|
adamc@758
|
3103
|
adamc@148
|
3104 | L.EApp ((L.ECApp (
|
adamc@148
|
3105 (L.ECApp (
|
adamc@148
|
3106 (L.ECApp (
|
adamc@148
|
3107 (L.ECApp (
|
adamc@148
|
3108 (L.EFfi ("Basis", "useMore"), _), _), _),
|
adamc@148
|
3109 _), _),
|
adamc@148
|
3110 _), _),
|
adamc@148
|
3111 _), _),
|
adamc@179
|
3112 xml) => monoExp (env, st, fm) xml
|
adamc@148
|
3113
|
adamc@283
|
3114 | L.ECApp ((L.EFfi ("Basis", "error"), _), t) =>
|
adamc@283
|
3115 let
|
adamc@283
|
3116 val t = monoType env t
|
adamc@283
|
3117 in
|
adamc@283
|
3118 ((L'.EAbs ("s", (L'.TFfi ("Basis", "string"), loc), t,
|
adamc@283
|
3119 (L'.EError ((L'.ERel 0, loc), t), loc)), loc),
|
adamc@283
|
3120 fm)
|
adamc@283
|
3121 end
|
adamc@741
|
3122 | L.ECApp ((L.EFfi ("Basis", "returnBlob"), _), t) =>
|
adamc@741
|
3123 let
|
adamc@741
|
3124 val t = monoType env t
|
adamc@741
|
3125 val un = (L'.TRecord [], loc)
|
adamc@741
|
3126 in
|
adamc@741
|
3127 ((L'.EAbs ("b", (L'.TFfi ("Basis", "blob"), loc),
|
adamc@741
|
3128 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFun (un, t), loc)), loc),
|
adamc@741
|
3129 (L'.EAbs ("mt", (L'.TFfi ("Basis", "string"), loc), (L'.TFun (un, t), loc),
|
adamc@741
|
3130 (L'.EAbs ("_", un, t,
|
adamc@741
|
3131 (L'.EReturnBlob {blob = (L'.ERel 2, loc),
|
adamc@741
|
3132 mimeType = (L'.ERel 1, loc),
|
adamc@741
|
3133 t = t}, loc)), loc)), loc)), loc),
|
adamc@741
|
3134 fm)
|
adamc@741
|
3135 end
|
adamc@1065
|
3136 | L.ECApp ((L.EFfi ("Basis", "redirect"), _), t) =>
|
adamc@1065
|
3137 let
|
adamc@1065
|
3138 val t = monoType env t
|
adamc@1065
|
3139 val un = (L'.TRecord [], loc)
|
adamc@1065
|
3140 in
|
adamc@1065
|
3141 ((L'.EAbs ("url", (L'.TFfi ("Basis", "string"), loc), (L'.TFun (un, t), loc),
|
adamc@1065
|
3142 (L'.EAbs ("_", un, t,
|
adamc@1065
|
3143 (L'.ERedirect ((L'.ERel 1, loc), t), loc)), loc)), loc),
|
adamc@1065
|
3144 fm)
|
adamc@1065
|
3145 end
|
adamc@283
|
3146
|
adamc@179
|
3147 | L.EApp (e1, e2) =>
|
adamc@179
|
3148 let
|
adamc@179
|
3149 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@179
|
3150 val (e2, fm) = monoExp (env, st, fm) e2
|
adamc@179
|
3151 in
|
adamc@179
|
3152 ((L'.EApp (e1, e2), loc), fm)
|
adamc@179
|
3153 end
|
adamc@26
|
3154 | L.EAbs (x, dom, ran, e) =>
|
adamc@179
|
3155 let
|
adamc@179
|
3156 val (e, fm) = monoExp (Env.pushERel env x dom, st, fm) e
|
adamc@179
|
3157 in
|
adamc@179
|
3158 ((L'.EAbs (x, monoType env dom, monoType env ran, e), loc), fm)
|
adamc@179
|
3159 end
|
adamc@25
|
3160 | L.ECApp _ => poly ()
|
adamc@25
|
3161 | L.ECAbs _ => poly ()
|
adamc@25
|
3162
|
adamc@252
|
3163 | L.EFfi mx => ((L'.EFfi mx, loc), fm)
|
adamc@252
|
3164 | L.EFfiApp (m, x, es) =>
|
adamc@252
|
3165 let
|
adamc@252
|
3166 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@252
|
3167 in
|
adamc@252
|
3168 ((L'.EFfiApp (m, x, es), loc), fm)
|
adamc@252
|
3169 end
|
adamc@252
|
3170
|
adamc@179
|
3171 | L.ERecord xes =>
|
adamc@179
|
3172 let
|
adamc@179
|
3173 val (xes, fm) = ListUtil.foldlMap
|
adamc@179
|
3174 (fn ((x, e, t), fm) =>
|
adamc@179
|
3175 let
|
adamc@179
|
3176 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
3177 in
|
adamc@179
|
3178 ((monoName env x,
|
adamc@179
|
3179 e,
|
adamc@179
|
3180 monoType env t), fm)
|
adamc@179
|
3181 end) fm xes
|
adamc@905
|
3182
|
adamc@905
|
3183 val xes = ListMergeSort.sort (fn ((x, _, _), (y, _, _)) => String.compare (x, y) = GREATER) xes
|
adamc@179
|
3184 in
|
adamc@179
|
3185 ((L'.ERecord xes, loc), fm)
|
adamc@179
|
3186 end
|
adamc@179
|
3187 | L.EField (e, x, _) =>
|
adamc@179
|
3188 let
|
adamc@179
|
3189 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
3190 in
|
adamc@179
|
3191 ((L'.EField (e, monoName env x), loc), fm)
|
adamc@179
|
3192 end
|
adamc@445
|
3193 | L.EConcat _ => poly ()
|
adamc@149
|
3194 | L.ECut _ => poly ()
|
adamc@493
|
3195 | L.ECutMulti _ => poly ()
|
adamc@177
|
3196
|
adamc@182
|
3197 | L.ECase (e, pes, {disc, result}) =>
|
adamc@179
|
3198 let
|
adamc@179
|
3199 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
3200 val (pes, fm) = ListUtil.foldlMap
|
adamc@179
|
3201 (fn ((p, e), fm) =>
|
adamc@179
|
3202 let
|
adamc@179
|
3203 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
3204 in
|
adamc@182
|
3205 ((monoPat env p, e), fm)
|
adamc@179
|
3206 end) fm pes
|
adamc@179
|
3207 in
|
adamc@182
|
3208 ((L'.ECase (e, pes, {disc = monoType env disc, result = monoType env result}), loc), fm)
|
adamc@179
|
3209 end
|
adamc@177
|
3210
|
adamc@179
|
3211 | L.EWrite e =>
|
adamc@179
|
3212 let
|
adamc@179
|
3213 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
3214 in
|
adamc@252
|
3215 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@252
|
3216 (L'.EWrite (liftExpInExp 0 e), loc)), loc), fm)
|
adamc@179
|
3217 end
|
adamc@110
|
3218
|
adamc@179
|
3219 | L.EClosure (n, es) =>
|
adamc@179
|
3220 let
|
adamc@179
|
3221 val (es, fm) = ListUtil.foldlMap (fn (e, fm) =>
|
adamc@179
|
3222 monoExp (env, st, fm) e)
|
adamc@1065
|
3223 fm es
|
adamc@1065
|
3224 val e = (L'.EClosure (n, es), loc)
|
adamc@179
|
3225 in
|
adamc@1065
|
3226 if !inTag then
|
adamc@1065
|
3227 (e, fm)
|
adamc@1065
|
3228 else
|
adamc@1065
|
3229 urlifyExp env fm (e, dummyTyp)
|
adamc@179
|
3230 end
|
adamc@450
|
3231
|
adamc@450
|
3232 | L.ELet (x, t, e1, e2) =>
|
adamc@450
|
3233 let
|
adamc@450
|
3234 val t' = monoType env t
|
adamc@450
|
3235 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@450
|
3236 val (e2, fm) = monoExp (Env.pushERel env x t, st, fm) e2
|
adamc@450
|
3237 in
|
adamc@450
|
3238 ((L'.ELet (x, t', e1, e2), loc), fm)
|
adamc@450
|
3239 end
|
adamc@607
|
3240
|
adamc@1020
|
3241 | L.EServerCall (n, es, t) =>
|
adamc@608
|
3242 let
|
adamc@609
|
3243 val t = monoType env t
|
adamc@614
|
3244 val (_, ft, _, name) = Env.lookupENamed env n
|
adamc@608
|
3245 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@614
|
3246
|
adamc@614
|
3247 fun encodeArgs (es, ft, acc, fm) =
|
adamc@614
|
3248 case (es, ft) of
|
adamc@614
|
3249 ([], _) => (rev acc, fm)
|
adamc@614
|
3250 | (e :: es, (L.TFun (dom, ran), _)) =>
|
adamc@614
|
3251 let
|
adamc@614
|
3252 val (e, fm) = urlifyExp env fm (e, monoType env dom)
|
adamc@614
|
3253 in
|
adamc@614
|
3254 encodeArgs (es, ran, e
|
adamc@614
|
3255 :: (L'.EPrim (Prim.String "/"), loc)
|
adamc@614
|
3256 :: acc, fm)
|
adamc@614
|
3257 end
|
adamc@614
|
3258 | _ => raise Fail "Monoize: Not enough arguments visible in RPC function type"
|
adamc@614
|
3259
|
adamc@614
|
3260 val (call, fm) = encodeArgs (es, ft, [], fm)
|
adamc@614
|
3261 val call = foldl (fn (e, call) => (L'.EStrcat (call, e), loc))
|
adamc@614
|
3262 (L'.EPrim (Prim.String name), loc) call
|
adamc@614
|
3263
|
adamc@905
|
3264 val unit = (L'.TRecord [], loc)
|
adamc@905
|
3265
|
adamc@736
|
3266 val eff = if IS.member (!readCookie, n) then
|
adamc@736
|
3267 L'.ReadCookieWrite
|
adamc@736
|
3268 else
|
adamc@736
|
3269 L'.ReadOnly
|
adamc@905
|
3270
|
adamc@1020
|
3271 val e = (L'.EServerCall (call, t, eff), loc)
|
adamc@651
|
3272 val e = liftExpInExp 0 e
|
adamc@651
|
3273 val e = (L'.EAbs ("_", unit, unit, e), loc)
|
adamc@608
|
3274 in
|
adamc@651
|
3275 (e, fm)
|
adamc@608
|
3276 end
|
adamc@626
|
3277
|
adamc@626
|
3278 | L.EKAbs _ => poly ()
|
adamc@626
|
3279 | L.EKApp _ => poly ()
|
adamc@25
|
3280 end
|
adamc@25
|
3281
|
adamc@179
|
3282 fun monoDecl (env, fm) (all as (d, loc)) =
|
adamc@25
|
3283 let
|
adamc@25
|
3284 fun poly () =
|
adamc@25
|
3285 (E.errorAt loc "Unsupported declaration";
|
adamc@25
|
3286 Print.eprefaces' [("Declaration", CorePrint.p_decl env all)];
|
adamc@25
|
3287 NONE)
|
adamc@25
|
3288 in
|
adamc@25
|
3289 case d of
|
adamc@25
|
3290 L.DCon _ => NONE
|
adamc@808
|
3291 | L.DDatatype [("list", n, [_], [("Nil", _, NONE),
|
adamc@808
|
3292 ("Cons", _, SOME (L.TRecord (L.CRecord (_,
|
adamc@808
|
3293 [((L.CName "1", _),
|
adamc@808
|
3294 (L.CRel 0, _)),
|
adamc@808
|
3295 ((L.CName "2", _),
|
adamc@808
|
3296 (L.CApp ((L.CNamed n', _),
|
adamc@808
|
3297 (L.CRel 0, _)),
|
adamc@808
|
3298 _))]), _), _))])] =>
|
adamc@757
|
3299 if n = n' then
|
adamc@757
|
3300 NONE
|
adamc@757
|
3301 else
|
adamc@757
|
3302 poly ()
|
adamc@808
|
3303 | L.DDatatype dts =>
|
adamc@808
|
3304 let
|
adamc@808
|
3305 val env' = Env.declBinds env all
|
adamc@808
|
3306 val dts = map (fn (x, n, [], xncs) =>
|
adamc@808
|
3307 (x, n, map (fn (x, n, to) => (x, n, Option.map (monoType env') to)) xncs)
|
adamc@808
|
3308 | _ => (E.errorAt loc "Polymorphic datatype needed too late";
|
adamc@808
|
3309 Print.eprefaces' [("Declaration", CorePrint.p_decl env all)];
|
adamc@808
|
3310 ("", 0, []))) dts
|
adamc@808
|
3311 val d = (L'.DDatatype dts, loc)
|
adamc@808
|
3312 in
|
adamc@808
|
3313 SOME (env', fm, [d])
|
adamc@808
|
3314 end
|
adamc@179
|
3315 | L.DVal (x, n, t, e, s) =>
|
adamc@179
|
3316 let
|
adamc@179
|
3317 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
3318 in
|
adamc@179
|
3319 SOME (Env.pushENamed env x n t NONE s,
|
adamc@179
|
3320 fm,
|
adamc@273
|
3321 [(L'.DVal (x, n, monoType env t, e, s), loc)])
|
adamc@179
|
3322 end
|
adamc@128
|
3323 | L.DValRec vis =>
|
adamc@128
|
3324 let
|
adamc@128
|
3325 val env = foldl (fn ((x, n, t, e, s), env) => Env.pushENamed env x n t NONE s) env vis
|
adamc@179
|
3326
|
adamc@179
|
3327 val (vis, fm) = ListUtil.foldlMap
|
adamc@179
|
3328 (fn ((x, n, t, e, s), fm) =>
|
adamc@179
|
3329 let
|
adamc@179
|
3330 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
3331 in
|
adamc@179
|
3332 ((x, n, monoType env t, e, s), fm)
|
adamc@179
|
3333 end)
|
adamc@179
|
3334 fm vis
|
adamc@128
|
3335 in
|
adamc@128
|
3336 SOME (env,
|
adamc@179
|
3337 fm,
|
adamc@273
|
3338 [(L'.DValRec vis, loc)])
|
adamc@128
|
3339 end
|
adamc@144
|
3340 | L.DExport (ek, n) =>
|
adamc@115
|
3341 let
|
adamc@120
|
3342 val (_, t, _, s) = Env.lookupENamed env n
|
adamc@120
|
3343
|
adamc@609
|
3344 fun unwind (t, args) =
|
adamc@609
|
3345 case #1 t of
|
adamc@609
|
3346 L.TFun (dom, ran) => unwind (ran, dom :: args)
|
adamc@314
|
3347 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@609
|
3348 unwind (t, (L.TRecord (L.CRecord ((L.KType, loc), []), loc), loc) :: args)
|
adamc@609
|
3349 | _ => (rev args, t)
|
adamc@120
|
3350
|
adamc@609
|
3351 val (ts, ran) = unwind (t, [])
|
adamc@609
|
3352 val ts = map (monoType env) ts
|
adamc@609
|
3353 val ran = monoType env ran
|
adamc@115
|
3354 in
|
adamc@609
|
3355 SOME (env, fm, [(L'.DExport (ek, s, n, ts, ran), loc)])
|
adamc@115
|
3356 end
|
adamc@707
|
3357 | L.DTable (x, n, (L.CRecord (_, xts), _), s, pe, _, ce, _) =>
|
adamc@251
|
3358 let
|
adamc@251
|
3359 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@251
|
3360 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@311
|
3361 val s = "uw_" ^ s
|
adamc@704
|
3362 val e_name = (L'.EPrim (Prim.String s), loc)
|
adamc@273
|
3363
|
adamc@273
|
3364 val xts = map (fn (x, t) => (monoName env x, monoType env t)) xts
|
adamc@704
|
3365
|
adamc@707
|
3366 val (pe, fm) = monoExp (env, St.empty, fm) pe
|
adamc@707
|
3367 val (ce, fm) = monoExp (env, St.empty, fm) ce
|
adamc@251
|
3368 in
|
adamc@251
|
3369 SOME (Env.pushENamed env x n t NONE s,
|
adamc@251
|
3370 fm,
|
adamc@707
|
3371 [(L'.DTable (s, xts, pe, ce), loc),
|
adamc@704
|
3372 (L'.DVal (x, n, t', e_name, s), loc)])
|
adamc@251
|
3373 end
|
adamc@273
|
3374 | L.DTable _ => poly ()
|
adamc@754
|
3375 | L.DView (x, n, s, e, (L.CRecord (_, xts), _)) =>
|
adamc@754
|
3376 let
|
adamc@754
|
3377 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@754
|
3378 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@754
|
3379 val s = "uw_" ^ s
|
adamc@754
|
3380 val e_name = (L'.EPrim (Prim.String s), loc)
|
adamc@754
|
3381
|
adamc@754
|
3382 val xts = map (fn (x, t) => (monoName env x, monoType env t)) xts
|
adamc@754
|
3383
|
adamc@754
|
3384 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@754
|
3385 val e = (L'.EFfiApp ("Basis", "viewify", [e]), loc)
|
adamc@754
|
3386 in
|
adamc@754
|
3387 SOME (Env.pushENamed env x n t NONE s,
|
adamc@754
|
3388 fm,
|
adamc@754
|
3389 [(L'.DView (s, xts, e), loc),
|
adamc@754
|
3390 (L'.DVal (x, n, t', e_name, s), loc)])
|
adamc@754
|
3391 end
|
adamc@754
|
3392 | L.DView _ => poly ()
|
adamc@338
|
3393 | L.DSequence (x, n, s) =>
|
adamc@338
|
3394 let
|
adamc@338
|
3395 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@338
|
3396 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
3397 val s = "uw_" ^ s
|
adamc@338
|
3398 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@338
|
3399 in
|
adamc@338
|
3400 SOME (Env.pushENamed env x n t NONE s,
|
adamc@338
|
3401 fm,
|
adamc@338
|
3402 [(L'.DSequence s, loc),
|
adamc@338
|
3403 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@338
|
3404 end
|
adamc@683
|
3405 | L.DDatabase _ => NONE
|
adamc@462
|
3406 | L.DCookie (x, n, t, s) =>
|
adamc@462
|
3407 let
|
adamc@462
|
3408 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@462
|
3409 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
3410 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@462
|
3411 in
|
adamc@462
|
3412 SOME (Env.pushENamed env x n t NONE s,
|
adamc@462
|
3413 fm,
|
adamc@725
|
3414 [(L'.DCookie s, loc),
|
adamc@725
|
3415 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@462
|
3416 end
|
adamc@720
|
3417 | L.DStyle (x, n, s) =>
|
adamc@718
|
3418 let
|
adamc@718
|
3419 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@718
|
3420 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@718
|
3421 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@718
|
3422 in
|
adamc@718
|
3423 SOME (Env.pushENamed env x n t NONE s,
|
adamc@718
|
3424 fm,
|
adamc@720
|
3425 [(L'.DStyle s, loc),
|
adamc@718
|
3426 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@718
|
3427 end
|
adamc@25
|
3428 end
|
adamc@25
|
3429
|
adamc@683
|
3430 datatype expungable = Client | Channel
|
adamc@683
|
3431
|
adamc@683
|
3432 fun monoize env file =
|
adamc@25
|
3433 let
|
adamc@735
|
3434 (* Calculate which exported functions need cookie signature protection *)
|
adamc@735
|
3435 val rcook = foldl (fn ((d, _), rcook) =>
|
adamc@735
|
3436 case d of
|
adamc@735
|
3437 L.DExport (L.Action L.ReadCookieWrite, n) => IS.add (rcook, n)
|
adamc@735
|
3438 | L.DExport (L.Rpc L.ReadCookieWrite, n) => IS.add (rcook, n)
|
adamc@735
|
3439 | _ => rcook)
|
adamc@735
|
3440 IS.empty file
|
adamc@735
|
3441 val () = readCookie := rcook
|
adamc@735
|
3442
|
adamc@683
|
3443 val loc = E.dummySpan
|
adamc@683
|
3444 val client = (L'.TFfi ("Basis", "client"), loc)
|
adamc@683
|
3445 val unit = (L'.TRecord [], loc)
|
adamc@687
|
3446
|
adamc@687
|
3447 fun calcClientish xts =
|
adamc@687
|
3448 foldl (fn ((x : L.con, t : L.con), st as (nullable, notNullable)) =>
|
adamc@687
|
3449 case #1 x of
|
adamc@687
|
3450 L.CName x =>
|
adamc@687
|
3451 (case #1 t of
|
adamc@687
|
3452 L.CFfi ("Basis", "client") =>
|
adamc@687
|
3453 (nullable, (x, Client) :: notNullable)
|
adamc@687
|
3454 | L.CApp ((L.CFfi ("Basis", "option"), _),
|
adamc@687
|
3455 (L.CFfi ("Basis", "client"), _)) =>
|
adamc@687
|
3456 ((x, Client) :: nullable, notNullable)
|
adamc@687
|
3457 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) =>
|
adamc@687
|
3458 (nullable, (x, Channel) :: notNullable)
|
adamc@687
|
3459 | L.CApp ((L.CFfi ("Basis", "option"), _),
|
adamc@687
|
3460 (L.CApp ((L.CFfi ("Basis", "channel"), _), _), _)) =>
|
adamc@687
|
3461 ((x, Channel) :: nullable, notNullable)
|
adamc@687
|
3462 | _ => st)
|
adamc@687
|
3463 | _ => st) ([], []) xts
|
adamc@687
|
3464
|
adamc@683
|
3465 fun expunger () =
|
adamc@683
|
3466 let
|
adamc@683
|
3467 val target = (L'.EFfiApp ("Basis", "sqlifyClient", [(L'.ERel 0, loc)]), loc)
|
adamc@683
|
3468
|
adamc@683
|
3469 fun doTable (tab, xts, e) =
|
adamc@683
|
3470 case xts of
|
adamc@683
|
3471 L.CRecord (_, xts) =>
|
adamc@683
|
3472 let
|
adamc@687
|
3473 val (nullable, notNullable) = calcClientish xts
|
adamc@683
|
3474
|
adamc@684
|
3475 fun cond (x, v) =
|
adamc@684
|
3476 (L'.EStrcat ((L'.EPrim (Prim.String ("uw_" ^ x
|
adamc@684
|
3477 ^ (case v of
|
adamc@684
|
3478 Client => ""
|
adamc@684
|
3479 | Channel => " >> 32")
|
adamc@684
|
3480 ^ " = ")), loc),
|
adamc@684
|
3481 target), loc)
|
adamc@684
|
3482
|
adamc@684
|
3483 val e =
|
adamc@684
|
3484 foldl (fn ((x, v), e) =>
|
adamc@684
|
3485 (L'.ESeq (
|
adamc@684
|
3486 (L'.EDml (L'.EStrcat (
|
adamc@684
|
3487 (L'.EPrim (Prim.String ("UPDATE uw_"
|
adamc@684
|
3488 ^ tab
|
adamc@684
|
3489 ^ " SET uw_"
|
adamc@684
|
3490 ^ x
|
adamc@684
|
3491 ^ " = NULL WHERE ")), loc),
|
adamc@684
|
3492 cond (x, v)), loc), loc),
|
adamc@684
|
3493 e), loc))
|
adamc@684
|
3494 e nullable
|
adamc@684
|
3495
|
adamc@683
|
3496 val e =
|
adamc@683
|
3497 case notNullable of
|
adamc@683
|
3498 [] => e
|
adamc@683
|
3499 | eb :: ebs =>
|
adamc@684
|
3500 (L'.ESeq (
|
adamc@684
|
3501 (L'.EDml (foldl
|
adamc@684
|
3502 (fn (eb, s) =>
|
adamc@684
|
3503 (L'.EStrcat (s,
|
adamc@687
|
3504 (L'.EStrcat ((L'.EPrim (Prim.String " OR "),
|
adamc@684
|
3505 loc),
|
adamc@684
|
3506 cond eb), loc)), loc))
|
adamc@684
|
3507 (L'.EStrcat ((L'.EPrim (Prim.String ("DELETE FROM uw_"
|
adamc@684
|
3508 ^ tab
|
adamc@684
|
3509 ^ " WHERE ")), loc),
|
adamc@684
|
3510 cond eb), loc)
|
adamc@684
|
3511 ebs), loc),
|
adamc@684
|
3512 e), loc)
|
adamc@683
|
3513 in
|
adamc@683
|
3514 e
|
adamc@683
|
3515 end
|
adamc@683
|
3516 | _ => e
|
adamc@683
|
3517
|
adamc@683
|
3518 val e = (L'.ERecord [], loc)
|
adamc@683
|
3519 in
|
adamc@683
|
3520 foldl (fn ((d, _), e) =>
|
adamc@683
|
3521 case d of
|
adamc@707
|
3522 L.DTable (_, _, xts, tab, _, _, _, _) => doTable (tab, #1 xts, e)
|
adamc@683
|
3523 | _ => e) e file
|
adamc@683
|
3524 end
|
adamc@683
|
3525
|
adamc@687
|
3526 fun initializer () =
|
adamc@687
|
3527 let
|
adamc@687
|
3528 fun doTable (tab, xts, e) =
|
adamc@687
|
3529 case xts of
|
adamc@687
|
3530 L.CRecord (_, xts) =>
|
adamc@687
|
3531 let
|
adamc@687
|
3532 val (nullable, notNullable) = calcClientish xts
|
adamc@687
|
3533
|
adamc@687
|
3534 val e =
|
adamc@687
|
3535 case nullable of
|
adamc@687
|
3536 [] => e
|
adamc@687
|
3537 | (x, _) :: ebs =>
|
adamc@687
|
3538 (L'.ESeq (
|
adamc@687
|
3539 (L'.EDml (L'.EPrim (Prim.String
|
adamc@687
|
3540 (foldl (fn ((x, _), s) =>
|
adamc@687
|
3541 s ^ ", uw_" ^ x ^ " = NULL")
|
adamc@687
|
3542 ("UPDATE uw_"
|
adamc@687
|
3543 ^ tab
|
adamc@687
|
3544 ^ " SET uw_"
|
adamc@687
|
3545 ^ x
|
adamc@687
|
3546 ^ " = NULL")
|
adamc@687
|
3547 ebs)), loc), loc),
|
adamc@687
|
3548 e), loc)
|
adamc@687
|
3549
|
adamc@687
|
3550 val e =
|
adamc@687
|
3551 case notNullable of
|
adamc@687
|
3552 [] => e
|
adamc@687
|
3553 | eb :: ebs =>
|
adamc@687
|
3554 (L'.ESeq (
|
adamc@687
|
3555 (L'.EDml (L'.EPrim (Prim.String ("DELETE FROM uw_"
|
adamc@687
|
3556 ^ tab)), loc), loc),
|
adamc@687
|
3557 e), loc)
|
adamc@687
|
3558 in
|
adamc@687
|
3559 e
|
adamc@687
|
3560 end
|
adamc@687
|
3561 | _ => e
|
adamc@687
|
3562
|
adamc@687
|
3563 val e = (L'.ERecord [], loc)
|
adamc@687
|
3564 in
|
adamc@687
|
3565 foldl (fn ((d, _), e) =>
|
adamc@687
|
3566 case d of
|
adamc@707
|
3567 L.DTable (_, _, xts, tab, _, _, _, _) => doTable (tab, #1 xts, e)
|
adamc@687
|
3568 | _ => e) e file
|
adamc@687
|
3569 end
|
adamc@687
|
3570
|
adamc@179
|
3571 val (_, _, ds) = List.foldl (fn (d, (env, fm, ds)) =>
|
adamc@683
|
3572 case #1 d of
|
adamc@683
|
3573 L.DDatabase s =>
|
adamc@683
|
3574 let
|
adamc@687
|
3575 val (nExp, fm) = Fm.freshName fm
|
adamc@687
|
3576 val (nIni, fm) = Fm.freshName fm
|
adamc@687
|
3577
|
adamc@687
|
3578 val dExp = L'.DVal ("expunger",
|
adamc@687
|
3579 nExp,
|
adamc@687
|
3580 (L'.TFun (client, unit), loc),
|
adamc@687
|
3581 (L'.EAbs ("cli", client, unit, expunger ()), loc),
|
adamc@687
|
3582 "expunger")
|
adamc@687
|
3583 val dIni = L'.DVal ("initializer",
|
adamc@687
|
3584 nIni,
|
adamc@687
|
3585 (L'.TFun (unit, unit), loc),
|
adamc@687
|
3586 (L'.EAbs ("_", unit, unit, initializer ()), loc),
|
adamc@687
|
3587 "initializer")
|
adamc@683
|
3588 in
|
adamc@687
|
3589 (env, Fm.enter fm, (L'.DDatabase {name = s,
|
adamc@687
|
3590 expunge = nExp,
|
adamc@687
|
3591 initialize = nIni}, loc)
|
adamc@687
|
3592 :: (dExp, loc)
|
adamc@687
|
3593 :: (dIni, loc)
|
adamc@683
|
3594 :: ds)
|
adamc@683
|
3595 end
|
adamc@683
|
3596 | _ =>
|
adamc@683
|
3597 case monoDecl (env, fm) d of
|
adamc@683
|
3598 NONE => (env, fm, ds)
|
adamc@683
|
3599 | SOME (env, fm, ds') =>
|
adamc@683
|
3600 (env,
|
adamc@683
|
3601 Fm.enter fm,
|
adamc@683
|
3602 ds' @ Fm.decls fm @ ds))
|
adamc@683
|
3603 (env, Fm.empty (CoreUtil.File.maxName file + 1), []) file
|
adamc@25
|
3604 in
|
adamc@25
|
3605 rev ds
|
adamc@25
|
3606 end
|
adamc@25
|
3607
|
adamc@25
|
3608 end
|