adamc@25
|
1 (* Copyright (c) 2008, 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@196
|
37
|
adamc@385
|
38 val urlPrefix = ref "/"
|
adamc@385
|
39
|
adamc@196
|
40 val dummyTyp = (L'.TDatatype (0, ref (L'.Enum, [])), E.dummySpan)
|
adamc@25
|
41
|
adamc@252
|
42 structure U = MonoUtil
|
adamc@252
|
43
|
adamc@252
|
44 val liftExpInExp =
|
adamc@252
|
45 U.Exp.mapB {typ = fn t => t,
|
adamc@252
|
46 exp = fn bound => fn e =>
|
adamc@252
|
47 case e of
|
adamc@252
|
48 L'.ERel xn =>
|
adamc@252
|
49 if xn < bound then
|
adamc@252
|
50 e
|
adamc@252
|
51 else
|
adamc@252
|
52 L'.ERel (xn + 1)
|
adamc@252
|
53 | _ => e,
|
adamc@252
|
54 bind = fn (bound, U.Exp.RelE _) => bound + 1
|
adamc@252
|
55 | (bound, _) => bound}
|
adamc@252
|
56
|
adamc@25
|
57 fun monoName env (all as (c, loc)) =
|
adamc@25
|
58 let
|
adamc@25
|
59 fun poly () =
|
adamc@25
|
60 (E.errorAt loc "Unsupported name constructor";
|
adamc@25
|
61 Print.eprefaces' [("Constructor", CorePrint.p_con env all)];
|
adamc@25
|
62 "")
|
adamc@25
|
63 in
|
adamc@25
|
64 case c of
|
adamc@25
|
65 L.CName s => s
|
adamc@25
|
66 | _ => poly ()
|
adamc@25
|
67 end
|
adamc@25
|
68
|
adamc@292
|
69 fun readType' (t, loc) = (L'.TFun ((L'.TFfi ("Basis", "string"), loc),
|
adamc@292
|
70 (L'.TOption t, loc)), loc)
|
adamc@292
|
71 fun readErrType (t, loc) = (L'.TFun ((L'.TFfi ("Basis", "string"), loc),
|
adamc@292
|
72 t), loc)
|
adamc@292
|
73 fun readType (t, loc) =
|
adamc@292
|
74 (L'.TRecord [("Read", readType' (t, loc)),
|
adamc@292
|
75 ("ReadError", readErrType (t, loc))],
|
adamc@292
|
76 loc)
|
adamc@292
|
77
|
adamc@196
|
78 fun monoType env =
|
adamc@25
|
79 let
|
adamc@196
|
80 fun mt env dtmap (all as (c, loc)) =
|
adamc@196
|
81 let
|
adamc@196
|
82 fun poly () =
|
adamc@196
|
83 (E.errorAt loc "Unsupported type constructor";
|
adamc@196
|
84 Print.eprefaces' [("Constructor", CorePrint.p_con env all)];
|
adamc@196
|
85 dummyTyp)
|
adamc@196
|
86 in
|
adamc@196
|
87 case c of
|
adamc@196
|
88 L.TFun (c1, c2) => (L'.TFun (mt env dtmap c1, mt env dtmap c2), loc)
|
adamc@196
|
89 | L.TCFun _ => poly ()
|
adamc@196
|
90 | L.TRecord (L.CRecord ((L.KType, _), xcs), _) =>
|
adamc@196
|
91 (L'.TRecord (map (fn (x, t) => (monoName env x, mt env dtmap t)) xcs), loc)
|
adamc@196
|
92 | L.TRecord _ => poly ()
|
adamc@196
|
93
|
adamc@288
|
94 | L.CApp ((L.CFfi ("Basis", "option"), _), t) =>
|
adamc@288
|
95 (L'.TOption (mt env dtmap t), loc)
|
adamc@288
|
96
|
adamc@387
|
97 | L.CApp ((L.CFfi ("Basis", "eq"), _), t) =>
|
adamc@387
|
98 let
|
adamc@387
|
99 val t = mt env dtmap t
|
adamc@387
|
100 in
|
adamc@387
|
101 (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)
|
adamc@387
|
102 end
|
adamc@389
|
103 | L.CApp ((L.CFfi ("Basis", "num"), _), t) =>
|
adamc@389
|
104 let
|
adamc@389
|
105 val t = mt env dtmap t
|
adamc@389
|
106 in
|
adamc@417
|
107 (L'.TRecord [("Zero", t),
|
adamc@417
|
108 ("Neg", (L'.TFun (t, t), loc)),
|
adamc@389
|
109 ("Plus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
110 ("Minus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
111 ("Times", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
112 ("Div", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
113 ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))],
|
adamc@389
|
114 loc)
|
adamc@389
|
115 end
|
adamc@391
|
116 | L.CApp ((L.CFfi ("Basis", "ord"), _), t) =>
|
adamc@391
|
117 let
|
adamc@391
|
118 val t = mt env dtmap t
|
adamc@391
|
119 in
|
adamc@391
|
120 (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
121 ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))],
|
adamc@391
|
122 loc)
|
adamc@391
|
123 end
|
adamc@286
|
124 | L.CApp ((L.CFfi ("Basis", "show"), _), t) =>
|
adamc@286
|
125 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@290
|
126 | L.CApp ((L.CFfi ("Basis", "read"), _), t) =>
|
adamc@292
|
127 readType (mt env dtmap t, loc)
|
adamc@286
|
128
|
adamc@717
|
129 | L.CFfi ("Basis", "url") => (L'.TFfi ("Basis", "string"), loc)
|
adamc@720
|
130 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "xml"), _), _), _), _), _), _) =>
|
adamc@196
|
131 (L'.TFfi ("Basis", "string"), loc)
|
adamc@196
|
132 | L.CApp ((L.CApp ((L.CFfi ("Basis", "xhtml"), _), _), _), _) =>
|
adamc@196
|
133 (L'.TFfi ("Basis", "string"), loc)
|
adamc@196
|
134
|
adamc@251
|
135 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@252
|
136 (L'.TFun ((L'.TRecord [], loc), mt env dtmap t), loc)
|
adamc@565
|
137 | L.CApp ((L.CFfi ("Basis", "source"), _), t) =>
|
adamc@577
|
138 (L'.TSource, loc)
|
adamc@568
|
139 | L.CApp ((L.CFfi ("Basis", "signal"), _), t) =>
|
adamc@568
|
140 (L'.TSignal (mt env dtmap t), loc)
|
adamc@462
|
141 | L.CApp ((L.CFfi ("Basis", "http_cookie"), _), _) =>
|
adamc@462
|
142 (L'.TFfi ("Basis", "string"), loc)
|
adamc@705
|
143 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_table"), _), _), _), _) =>
|
adamc@252
|
144 (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
145 | L.CFfi ("Basis", "sql_sequence") =>
|
adamc@338
|
146 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
147 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query"), _), _), _), _) =>
|
adamc@252
|
148 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
149 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _) =>
|
adamc@252
|
150 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
151 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _) =>
|
adamc@252
|
152 (L'.TFfi ("Basis", "string"), loc)
|
adamc@707
|
153 | L.CApp ((L.CApp ((L.CFfi ("Basis", "primary_key"), _), _), _), _) =>
|
adamc@707
|
154 (L'.TFfi ("Basis", "string"), loc)
|
adamc@704
|
155 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_constraints"), _), _), _), _) =>
|
adamc@704
|
156 (L'.TFfi ("Basis", "sql_constraints"), loc)
|
adamc@705
|
157 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_constraint"), _), _), _), _) =>
|
adamc@704
|
158 (L'.TFfi ("Basis", "string"), loc)
|
adamc@712
|
159 | L.CApp ((L.CApp ((L.CFfi ("Basis", "linkable"), _), _), _), _) =>
|
adamc@712
|
160 (L'.TRecord [], loc)
|
adamc@709
|
161 | L.CApp ((L.CApp ((L.CFfi ("Basis", "matching"), _), _), _), _) =>
|
adamc@709
|
162 let
|
adamc@709
|
163 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
164 in
|
adamc@709
|
165 (L'.TRecord [("1", string), ("2", string)], loc)
|
adamc@709
|
166 end
|
adamc@709
|
167 | L.CApp ((L.CFfi ("Basis", "propagation_mode"), _), _) =>
|
adamc@709
|
168 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
169
|
adamc@252
|
170 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_subset"), _), _), _), _) =>
|
adamc@252
|
171 (L'.TRecord [], loc)
|
adamc@252
|
172 | L.CFfi ("Basis", "sql_relop") =>
|
adamc@252
|
173 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
174 | L.CFfi ("Basis", "sql_direction") =>
|
adamc@252
|
175 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
176 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_order_by"), _), _), _), _) =>
|
adamc@252
|
177 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
178 | L.CFfi ("Basis", "sql_limit") =>
|
adamc@252
|
179 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
180 | L.CFfi ("Basis", "sql_offset") =>
|
adamc@252
|
181 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
182
|
adamc@676
|
183 | L.CApp ((L.CFfi ("Basis", "sql_injectable_prim"), _), t) =>
|
adamc@676
|
184 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@252
|
185 | L.CApp ((L.CFfi ("Basis", "sql_injectable"), _), t) =>
|
adamc@252
|
186 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@252
|
187 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) =>
|
adamc@252
|
188 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
189 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_binary"), _), _), _), _), _), _) =>
|
adamc@252
|
190 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
191 | L.CApp ((L.CFfi ("Basis", "sql_aggregate"), _), t) =>
|
adamc@252
|
192 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
193 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) =>
|
adamc@252
|
194 (L'.TRecord [], loc)
|
adamc@252
|
195 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) =>
|
adamc@252
|
196 (L'.TRecord [], loc)
|
adamc@559
|
197 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) =>
|
adamc@559
|
198 (L'.TRecord [], loc)
|
adamc@441
|
199 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) =>
|
adamc@441
|
200 (L'.TFfi ("Basis", "string"), loc)
|
adamc@251
|
201
|
adamc@668
|
202 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) =>
|
adamc@668
|
203 (L'.TFfi ("Basis", "channel"), loc)
|
adamc@668
|
204
|
adamc@196
|
205 | L.CRel _ => poly ()
|
adamc@196
|
206 | L.CNamed n =>
|
adamc@196
|
207 (case IM.find (dtmap, n) of
|
adamc@196
|
208 SOME r => (L'.TDatatype (n, r), loc)
|
adamc@196
|
209 | NONE =>
|
adamc@196
|
210 let
|
adamc@196
|
211 val r = ref (L'.Default, [])
|
adamc@196
|
212 val (_, xs, xncs) = Env.lookupDatatype env n
|
adamc@196
|
213
|
adamc@196
|
214 val dtmap' = IM.insert (dtmap, n, r)
|
adamc@196
|
215
|
adamc@196
|
216 val xncs = map (fn (x, n, to) => (x, n, Option.map (mt env dtmap') to)) xncs
|
adamc@196
|
217 in
|
adamc@196
|
218 case xs of
|
adamc@198
|
219 [] =>(r := (ElabUtil.classifyDatatype xncs, xncs);
|
adamc@196
|
220 (L'.TDatatype (n, r), loc))
|
adamc@196
|
221 | _ => poly ()
|
adamc@196
|
222 end)
|
adamc@196
|
223 | L.CFfi mx => (L'.TFfi mx, loc)
|
adamc@196
|
224 | L.CApp _ => poly ()
|
adamc@196
|
225 | L.CAbs _ => poly ()
|
adamc@196
|
226
|
adamc@196
|
227 | L.CName _ => poly ()
|
adamc@196
|
228
|
adamc@196
|
229 | L.CRecord _ => poly ()
|
adamc@196
|
230 | L.CConcat _ => poly ()
|
adamc@621
|
231 | L.CMap _ => poly ()
|
adamc@196
|
232 | L.CUnit => poly ()
|
adamc@214
|
233
|
adamc@214
|
234 | L.CTuple _ => poly ()
|
adamc@214
|
235 | L.CProj _ => poly ()
|
adamc@626
|
236
|
adamc@626
|
237 | L.CKAbs _ => poly ()
|
adamc@626
|
238 | L.CKApp _ => poly ()
|
adamc@626
|
239 | L.TKFun _ => poly ()
|
adamc@196
|
240 end
|
adamc@25
|
241 in
|
adamc@196
|
242 mt env IM.empty
|
adamc@25
|
243 end
|
adamc@25
|
244
|
adamc@25
|
245 val dummyExp = (L'.EPrim (Prim.Int 0), E.dummySpan)
|
adamc@25
|
246
|
adamc@179
|
247 structure IM = IntBinaryMap
|
adamc@179
|
248
|
adamc@179
|
249 datatype foo_kind =
|
adamc@179
|
250 Attr
|
adamc@179
|
251 | Url
|
adamc@179
|
252
|
adamc@179
|
253 fun fk2s fk =
|
adamc@179
|
254 case fk of
|
adamc@179
|
255 Attr => "attr"
|
adamc@179
|
256 | Url => "url"
|
adamc@179
|
257
|
adamc@179
|
258 structure Fm :> sig
|
adamc@179
|
259 type t
|
adamc@179
|
260
|
adamc@179
|
261 val empty : int -> t
|
adamc@179
|
262
|
adamc@179
|
263 val lookup : t -> foo_kind -> int -> (int -> t -> L'.decl * t) -> t * int
|
adamc@179
|
264 val enter : t -> t
|
adamc@179
|
265 val decls : t -> L'.decl list
|
adamc@683
|
266
|
adamc@683
|
267 val freshName : t -> int * t
|
adamc@179
|
268 end = struct
|
adamc@179
|
269
|
adamc@179
|
270 structure M = BinaryMapFn(struct
|
adamc@179
|
271 type ord_key = foo_kind
|
adamc@179
|
272 fun compare x =
|
adamc@179
|
273 case x of
|
adamc@179
|
274 (Attr, Attr) => EQUAL
|
adamc@179
|
275 | (Attr, _) => LESS
|
adamc@179
|
276 | (_, Attr) => GREATER
|
adamc@179
|
277
|
adamc@179
|
278 | (Url, Url) => EQUAL
|
adamc@179
|
279 end)
|
adamc@179
|
280
|
adamc@179
|
281 type t = {
|
adamc@179
|
282 count : int,
|
adamc@179
|
283 map : int IM.map M.map,
|
adamc@179
|
284 decls : L'.decl list
|
adamc@179
|
285 }
|
adamc@179
|
286
|
adamc@179
|
287 fun empty count = {
|
adamc@179
|
288 count = count,
|
adamc@179
|
289 map = M.empty,
|
adamc@179
|
290 decls = []
|
adamc@179
|
291 }
|
adamc@179
|
292
|
adamc@179
|
293 fun enter ({count, map, ...} : t) = {count = count, map = map, decls = []}
|
adamc@683
|
294 fun freshName {count, map, decls} = (count, {count = count + 1, map = map, decls = decls})
|
adamc@179
|
295 fun decls ({decls, ...} : t) = decls
|
adamc@179
|
296
|
adamc@179
|
297 fun lookup (t as {count, map, decls}) k n thunk =
|
adamc@120
|
298 let
|
adamc@179
|
299 val im = Option.getOpt (M.find (map, k), IM.empty)
|
adamc@179
|
300 in
|
adamc@179
|
301 case IM.find (im, n) of
|
adamc@179
|
302 NONE =>
|
adamc@179
|
303 let
|
adamc@179
|
304 val n' = count
|
adamc@179
|
305 val (d, {count, map, decls}) = thunk count {count = count + 1,
|
adamc@179
|
306 map = M.insert (map, k, IM.insert (im, n, n')),
|
adamc@179
|
307 decls = decls}
|
adamc@179
|
308 in
|
adamc@179
|
309 ({count = count,
|
adamc@179
|
310 map = map,
|
adamc@179
|
311 decls = d :: decls}, n')
|
adamc@179
|
312 end
|
adamc@179
|
313 | SOME n' => (t, n')
|
adamc@179
|
314 end
|
adamc@179
|
315
|
adamc@179
|
316 end
|
adamc@185
|
317
|
adamc@185
|
318
|
adamc@185
|
319 fun capitalize s =
|
adamc@185
|
320 if s = "" then
|
adamc@185
|
321 s
|
adamc@185
|
322 else
|
adamc@185
|
323 str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adamc@179
|
324
|
adamc@179
|
325 fun fooifyExp fk env =
|
adamc@179
|
326 let
|
adamc@179
|
327 fun fooify fm (e, tAll as (t, loc)) =
|
adamc@120
|
328 case #1 e of
|
adamc@120
|
329 L'.EClosure (fnam, [(L'.ERecord [], _)]) =>
|
adamc@120
|
330 let
|
adamc@120
|
331 val (_, _, _, s) = Env.lookupENamed env fnam
|
adamc@120
|
332 in
|
adamc@385
|
333 ((L'.EPrim (Prim.String (!urlPrefix ^ s)), loc), fm)
|
adamc@120
|
334 end
|
adamc@120
|
335 | L'.EClosure (fnam, args) =>
|
adamc@120
|
336 let
|
adamc@120
|
337 val (_, ft, _, s) = Env.lookupENamed env fnam
|
adamc@120
|
338 val ft = monoType env ft
|
adamc@111
|
339
|
adamc@179
|
340 fun attrify (args, ft, e, fm) =
|
adamc@120
|
341 case (args, ft) of
|
adamc@179
|
342 ([], _) => (e, fm)
|
adamc@120
|
343 | (arg :: args, (L'.TFun (t, ft), _)) =>
|
adamc@179
|
344 let
|
adamc@179
|
345 val (arg', fm) = fooify fm (arg, t)
|
adamc@179
|
346 in
|
adamc@179
|
347 attrify (args, ft,
|
adamc@179
|
348 (L'.EStrcat (e,
|
adamc@179
|
349 (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc),
|
adamc@179
|
350 arg'), loc)), loc),
|
adamc@179
|
351 fm)
|
adamc@179
|
352 end
|
adamc@120
|
353 | _ => (E.errorAt loc "Type mismatch encoding attribute";
|
adamc@179
|
354 (e, fm))
|
adamc@120
|
355 in
|
adamc@385
|
356 attrify (args, ft, (L'.EPrim (Prim.String (!urlPrefix ^ s)), loc), fm)
|
adamc@120
|
357 end
|
adamc@120
|
358 | _ =>
|
adamc@120
|
359 case t of
|
adamc@185
|
360 L'.TFfi (m, x) => ((L'.EFfiApp (m, fk2s fk ^ "ify" ^ capitalize x, [e]), loc), fm)
|
adamc@200
|
361
|
adamc@179
|
362 | L'.TRecord [] => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@200
|
363 | L'.TRecord ((x, t) :: xts) =>
|
adamc@200
|
364 let
|
adamc@200
|
365 val (se, fm) = fooify fm ((L'.EField (e, x), loc), t)
|
adamc@200
|
366 in
|
adamc@200
|
367 foldl (fn ((x, t), (se, fm)) =>
|
adamc@200
|
368 let
|
adamc@200
|
369 val (se', fm) = fooify fm ((L'.EField (e, x), loc), t)
|
adamc@200
|
370 in
|
adamc@200
|
371 ((L'.EStrcat (se,
|
adamc@200
|
372 (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc),
|
adamc@200
|
373 se'), loc)), loc),
|
adamc@200
|
374 fm)
|
adamc@200
|
375 end) (se, fm) xts
|
adamc@200
|
376 end
|
adamc@111
|
377
|
adamc@196
|
378 | L'.TDatatype (i, ref (dk, _)) =>
|
adamc@179
|
379 let
|
adamc@179
|
380 fun makeDecl n fm =
|
adamc@179
|
381 let
|
adamc@193
|
382 val (x, _, xncs) = Env.lookupDatatype env i
|
adamc@179
|
383
|
adamc@179
|
384 val (branches, fm) =
|
adamc@179
|
385 ListUtil.foldlMap
|
adamc@179
|
386 (fn ((x, n, to), fm) =>
|
adamc@179
|
387 case to of
|
adamc@179
|
388 NONE =>
|
adamc@188
|
389 (((L'.PCon (dk, L'.PConVar n, NONE), loc),
|
adamc@179
|
390 (L'.EPrim (Prim.String x), loc)),
|
adamc@179
|
391 fm)
|
adamc@179
|
392 | SOME t =>
|
adamc@179
|
393 let
|
adamc@182
|
394 val t = monoType env t
|
adamc@182
|
395 val (arg, fm) = fooify fm ((L'.ERel 0, loc), t)
|
adamc@179
|
396 in
|
adamc@188
|
397 (((L'.PCon (dk, L'.PConVar n, SOME (L'.PVar ("a", t), loc)), loc),
|
adamc@179
|
398 (L'.EStrcat ((L'.EPrim (Prim.String (x ^ "/")), loc),
|
adamc@179
|
399 arg), loc)),
|
adamc@179
|
400 fm)
|
adamc@179
|
401 end)
|
adamc@179
|
402 fm xncs
|
adamc@179
|
403
|
adamc@179
|
404 val dom = tAll
|
adamc@179
|
405 val ran = (L'.TFfi ("Basis", "string"), loc)
|
adamc@179
|
406 in
|
adamc@179
|
407 ((L'.DValRec [(fk2s fk ^ "ify_" ^ x,
|
adamc@179
|
408 n,
|
adamc@179
|
409 (L'.TFun (dom, ran), loc),
|
adamc@179
|
410 (L'.EAbs ("x",
|
adamc@179
|
411 dom,
|
adamc@179
|
412 ran,
|
adamc@179
|
413 (L'.ECase ((L'.ERel 0, loc),
|
adamc@179
|
414 branches,
|
adamc@182
|
415 {disc = dom,
|
adamc@182
|
416 result = ran}), loc)), loc),
|
adamc@179
|
417 "")], loc),
|
adamc@179
|
418 fm)
|
adamc@179
|
419 end
|
adamc@179
|
420
|
adamc@179
|
421 val (fm, n) = Fm.lookup fm fk i makeDecl
|
adamc@179
|
422 in
|
adamc@179
|
423 ((L'.EApp ((L'.ENamed n, loc), e), loc), fm)
|
adamc@179
|
424 end
|
adamc@164
|
425
|
adamc@471
|
426 | L'.TOption t =>
|
adamc@471
|
427 let
|
adamc@471
|
428 val (body, fm) = fooify fm ((L'.ERel 0, loc), t)
|
adamc@471
|
429 in
|
adamc@471
|
430 ((L'.ECase (e,
|
adamc@471
|
431 [((L'.PNone t, loc),
|
adamc@471
|
432 (L'.EPrim (Prim.String "None"), loc)),
|
adamc@471
|
433
|
adamc@471
|
434 ((L'.PSome (t, (L'.PVar ("x", t), loc)), loc),
|
adamc@471
|
435 (L'.EStrcat ((L'.EPrim (Prim.String "Some/"), loc),
|
adamc@471
|
436 body), loc))],
|
adamc@471
|
437 {disc = tAll,
|
adamc@471
|
438 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@471
|
439 fm)
|
adamc@471
|
440 end
|
adamc@471
|
441
|
adamc@490
|
442 | _ => (E.errorAt loc "Don't know how to encode attribute/URL type";
|
adamc@120
|
443 Print.eprefaces' [("Type", MonoPrint.p_typ MonoEnv.empty tAll)];
|
adamc@179
|
444 (dummyExp, fm))
|
adamc@120
|
445 in
|
adamc@120
|
446 fooify
|
adamc@120
|
447 end
|
adamc@120
|
448
|
adamc@179
|
449 val attrifyExp = fooifyExp Attr
|
adamc@179
|
450 val urlifyExp = fooifyExp Url
|
adamc@105
|
451
|
adamc@143
|
452 datatype 'a failable_search =
|
adamc@143
|
453 Found of 'a
|
adamc@143
|
454 | NotFound
|
adamc@143
|
455 | Error
|
adamc@143
|
456
|
adamc@153
|
457 structure St :> sig
|
adamc@153
|
458 type t
|
adamc@153
|
459
|
adamc@153
|
460 val empty : t
|
adamc@153
|
461
|
adamc@153
|
462 val radioGroup : t -> string option
|
adamc@153
|
463 val setRadioGroup : t * string -> t
|
adamc@153
|
464 end = struct
|
adamc@153
|
465
|
adamc@153
|
466 type t = {
|
adamc@153
|
467 radioGroup : string option
|
adamc@153
|
468 }
|
adamc@153
|
469
|
adamc@153
|
470 val empty = {radioGroup = NONE}
|
adamc@153
|
471
|
adamc@153
|
472 fun radioGroup (t : t) = #radioGroup t
|
adamc@153
|
473
|
adamc@153
|
474 fun setRadioGroup (t : t, x) = {radioGroup = SOME x}
|
adamc@153
|
475
|
adamc@153
|
476 end
|
adamc@153
|
477
|
adamc@186
|
478 fun monoPatCon env pc =
|
adamc@178
|
479 case pc of
|
adamc@178
|
480 L.PConVar n => L'.PConVar n
|
adamc@188
|
481 | L.PConFfi {mod = m, datatyp, con, arg, ...} => L'.PConFfi {mod = m, datatyp = datatyp, con = con,
|
adamc@188
|
482 arg = Option.map (monoType env) arg}
|
adamc@178
|
483
|
adamc@193
|
484 val dummyPat = (L'.PPrim (Prim.Int 0), ErrorMsg.dummySpan)
|
adamc@193
|
485
|
adamc@193
|
486 fun monoPat env (all as (p, loc)) =
|
adamc@193
|
487 let
|
adamc@193
|
488 fun poly () =
|
adamc@193
|
489 (E.errorAt loc "Unsupported pattern";
|
adamc@193
|
490 Print.eprefaces' [("Pattern", CorePrint.p_pat env all)];
|
adamc@193
|
491 dummyPat)
|
adamc@193
|
492 in
|
adamc@193
|
493 case p of
|
adamc@193
|
494 L.PWild => (L'.PWild, loc)
|
adamc@193
|
495 | L.PVar (x, t) => (L'.PVar (x, monoType env t), loc)
|
adamc@193
|
496 | L.PPrim p => (L'.PPrim p, loc)
|
adamc@193
|
497 | L.PCon (dk, pc, [], po) => (L'.PCon (dk, monoPatCon env pc, Option.map (monoPat env) po), loc)
|
adamc@288
|
498 | L.PCon (L.Option, _, [t], NONE) => (L'.PNone (monoType env t), loc)
|
adamc@288
|
499 | L.PCon (L.Option, _, [t], SOME p) => (L'.PSome (monoType env t, monoPat env p), loc)
|
adamc@193
|
500 | L.PCon _ => poly ()
|
adamc@193
|
501 | L.PRecord xps => (L'.PRecord (map (fn (x, p, t) => (x, monoPat env p, monoType env t)) xps), loc)
|
adamc@193
|
502 end
|
adamc@178
|
503
|
adamc@252
|
504 fun strcat loc es =
|
adamc@252
|
505 case es of
|
adamc@252
|
506 [] => (L'.EPrim (Prim.String ""), loc)
|
adamc@252
|
507 | [e] => e
|
adamc@252
|
508 | _ =>
|
adamc@252
|
509 let
|
adamc@252
|
510 val e2 = List.last es
|
adamc@252
|
511 val es = List.take (es, length es - 1)
|
adamc@252
|
512 val e1 = List.last es
|
adamc@252
|
513 val es = List.take (es, length es - 1)
|
adamc@252
|
514 in
|
adamc@252
|
515 foldr (fn (e, e') => (L'.EStrcat (e, e'), loc))
|
adamc@252
|
516 (L'.EStrcat (e1, e2), loc) es
|
adamc@252
|
517 end
|
adamc@252
|
518
|
adamc@252
|
519 fun strcatComma loc es =
|
adamc@252
|
520 case es of
|
adamc@252
|
521 [] => (L'.EPrim (Prim.String ""), loc)
|
adamc@252
|
522 | [e] => e
|
adamc@252
|
523 | _ =>
|
adamc@252
|
524 let
|
adamc@252
|
525 val e1 = List.last es
|
adamc@252
|
526 val es = List.take (es, length es - 1)
|
adamc@252
|
527 in
|
adamc@252
|
528 foldr (fn (e, e') =>
|
adamc@265
|
529 case (e, e') of
|
adamc@265
|
530 ((L'.EPrim (Prim.String ""), _), _) => e'
|
adamc@265
|
531 | (_, (L'.EPrim (Prim.String ""), _)) => e
|
adamc@252
|
532 | _ =>
|
adamc@252
|
533 (L'.EStrcat (e,
|
adamc@252
|
534 (L'.EStrcat ((L'.EPrim (Prim.String ", "), loc), e'), loc)), loc))
|
adamc@252
|
535 e1 es
|
adamc@252
|
536 end
|
adamc@252
|
537
|
adamc@252
|
538 fun strcatR loc e xs = strcatComma loc (map (fn (x, _) => (L'.EField (e, x), loc)) xs)
|
adamc@252
|
539
|
adamc@179
|
540 fun monoExp (env, st, fm) (all as (e, loc)) =
|
adamc@25
|
541 let
|
adamc@598
|
542 val strcat = strcat loc
|
adamc@598
|
543 val strcatComma = strcatComma loc
|
adamc@598
|
544 fun str s = (L'.EPrim (Prim.String s), loc)
|
adamc@598
|
545
|
adamc@25
|
546 fun poly () =
|
adamc@25
|
547 (E.errorAt loc "Unsupported expression";
|
adamc@25
|
548 Print.eprefaces' [("Expression", CorePrint.p_exp env all)];
|
adamc@179
|
549 (dummyExp, fm))
|
adamc@389
|
550
|
adamc@389
|
551 fun numTy t =
|
adamc@417
|
552 (L'.TRecord [("Zero", t),
|
adamc@417
|
553 ("Neg", (L'.TFun (t, t), loc)),
|
adamc@389
|
554 ("Plus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
555 ("Minus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
556 ("Times", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
557 ("Div", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
558 ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc)
|
adamc@417
|
559 fun numEx (t, zero, neg, plus, minus, times, dv, md) =
|
adamc@417
|
560 ((L'.ERecord [("Zero", (L'.EPrim zero, loc), t),
|
adamc@417
|
561 ("Neg", neg, (L'.TFun (t, t), loc)),
|
adamc@389
|
562 ("Plus", plus, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
563 ("Minus", minus, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
564 ("Times", times, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
565 ("Div", dv, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
566 ("Mod", md, (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc), fm)
|
adamc@391
|
567
|
adamc@391
|
568 fun ordTy t =
|
adamc@391
|
569 (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
570 ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))], loc)
|
adamc@391
|
571 fun ordEx (t, lt, le) =
|
adamc@391
|
572 ((L'.ERecord [("Lt", lt, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
573 ("Le", le, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))],
|
adamc@391
|
574 loc), fm)
|
adamc@25
|
575 in
|
adamc@25
|
576 case e of
|
adamc@179
|
577 L.EPrim p => ((L'.EPrim p, loc), fm)
|
adamc@179
|
578 | L.ERel n => ((L'.ERel n, loc), fm)
|
adamc@179
|
579 | L.ENamed n => ((L'.ENamed n, loc), fm)
|
adamc@193
|
580 | L.ECon (dk, pc, [], eo) =>
|
adamc@193
|
581 let
|
adamc@179
|
582 val (eo, fm) =
|
adamc@179
|
583 case eo of
|
adamc@179
|
584 NONE => (NONE, fm)
|
adamc@179
|
585 | SOME e =>
|
adamc@179
|
586 let
|
adamc@179
|
587 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
588 in
|
adamc@179
|
589 (SOME e, fm)
|
adamc@179
|
590 end
|
adamc@179
|
591 in
|
adamc@188
|
592 ((L'.ECon (dk, monoPatCon env pc, eo), loc), fm)
|
adamc@193
|
593 end
|
adamc@297
|
594 | L.ECon (L.Option, _, [t], NONE) =>
|
adamc@297
|
595 ((L'.ENone (monoType env t), loc), fm)
|
adamc@297
|
596 | L.ECon (L.Option, _, [t], SOME e) =>
|
adamc@297
|
597 let
|
adamc@297
|
598 val (e, fm) = monoExp (env, st, fm) e
|
adamc@297
|
599 in
|
adamc@297
|
600 ((L'.ESome (monoType env t, e), loc), fm)
|
adamc@297
|
601 end
|
adamc@193
|
602 | L.ECon _ => poly ()
|
adamc@94
|
603
|
adamc@387
|
604 | L.ECApp ((L.EFfi ("Basis", "eq"), _), t) =>
|
adamc@387
|
605 let
|
adamc@387
|
606 val t = monoType env t
|
adamc@387
|
607 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@387
|
608 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@387
|
609 in
|
adamc@387
|
610 ((L'.EAbs ("f", dom, dom,
|
adamc@387
|
611 (L'.ERel 0, loc)), loc), fm)
|
adamc@387
|
612 end
|
adamc@387
|
613 | L.ECApp ((L.EFfi ("Basis", "ne"), _), t) =>
|
adamc@387
|
614 let
|
adamc@387
|
615 val t = monoType env t
|
adamc@387
|
616 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@387
|
617 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@387
|
618 in
|
adamc@387
|
619 ((L'.EAbs ("f", dom, dom,
|
adamc@387
|
620 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@387
|
621 (L'.EAbs ("y", t, b,
|
adamc@387
|
622 (L'.EUnop ("!", (L'.EApp ((L'.EApp ((L'.ERel 2, loc),
|
adamc@387
|
623 (L'.ERel 1, loc)), loc),
|
adamc@387
|
624 (L'.ERel 0, loc)), loc)), loc)),
|
adamc@387
|
625 loc)),
|
adamc@387
|
626 loc)),
|
adamc@387
|
627 loc), fm)
|
adamc@387
|
628 end
|
adamc@387
|
629 | L.EFfi ("Basis", "eq_int") =>
|
adamc@387
|
630 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@387
|
631 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@387
|
632 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@387
|
633 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@387
|
634 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@387
|
635 fm)
|
adamc@394
|
636 | L.EFfi ("Basis", "eq_float") =>
|
adamc@394
|
637 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
638 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
639 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
640 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
641 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@394
|
642 fm)
|
adamc@388
|
643 | L.EFfi ("Basis", "eq_bool") =>
|
adamc@388
|
644 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
645 (L'.TFun ((L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@388
|
646 (L'.EAbs ("y", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
647 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
648 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@388
|
649 fm)
|
adamc@388
|
650 | L.EFfi ("Basis", "eq_string") =>
|
adamc@388
|
651 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc),
|
adamc@388
|
652 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@388
|
653 (L'.EAbs ("y", (L'.TFfi ("Basis", "string"), loc),
|
adamc@388
|
654 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
655 (L'.EBinop ("!strcmp", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@388
|
656 fm)
|
adamc@437
|
657 | L.EFfi ("Basis", "eq_time") =>
|
adamc@437
|
658 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
659 (L'.TFun ((L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@437
|
660 (L'.EAbs ("y", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
661 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@437
|
662 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@437
|
663 fm)
|
adamc@422
|
664 | L.ECApp ((L.EFfi ("Basis", "mkEq"), _), t) =>
|
adamc@422
|
665 let
|
adamc@422
|
666 val t = monoType env t
|
adamc@422
|
667 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@422
|
668 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@422
|
669 in
|
adamc@422
|
670 ((L'.EAbs ("f", dom, dom,
|
adamc@422
|
671 (L'.ERel 0, loc)), loc), fm)
|
adamc@422
|
672 end
|
adamc@387
|
673
|
adamc@417
|
674 | L.ECApp ((L.EFfi ("Basis", "zero"), _), t) =>
|
adamc@417
|
675 let
|
adamc@417
|
676 val t = monoType env t
|
adamc@417
|
677 in
|
adamc@417
|
678 ((L'.EAbs ("r", numTy t, t,
|
adamc@417
|
679 (L'.EField ((L'.ERel 0, loc), "Zero"), loc)), loc), fm)
|
adamc@417
|
680 end
|
adamc@389
|
681 | L.ECApp ((L.EFfi ("Basis", "neg"), _), t) =>
|
adamc@389
|
682 let
|
adamc@389
|
683 val t = monoType env t
|
adamc@389
|
684 in
|
adamc@389
|
685 ((L'.EAbs ("r", numTy t, (L'.TFun (t, t), loc),
|
adamc@389
|
686 (L'.EField ((L'.ERel 0, loc), "Neg"), loc)), loc), fm)
|
adamc@389
|
687 end
|
adamc@389
|
688 | L.ECApp ((L.EFfi ("Basis", "plus"), _), t) =>
|
adamc@389
|
689 let
|
adamc@389
|
690 val t = monoType env t
|
adamc@389
|
691 in
|
adamc@389
|
692 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
693 (L'.EField ((L'.ERel 0, loc), "Plus"), loc)), loc), fm)
|
adamc@389
|
694 end
|
adamc@389
|
695 | L.ECApp ((L.EFfi ("Basis", "minus"), _), t) =>
|
adamc@389
|
696 let
|
adamc@389
|
697 val t = monoType env t
|
adamc@389
|
698 in
|
adamc@389
|
699 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
700 (L'.EField ((L'.ERel 0, loc), "Minus"), loc)), loc), fm)
|
adamc@389
|
701 end
|
adamc@389
|
702 | L.ECApp ((L.EFfi ("Basis", "times"), _), t) =>
|
adamc@389
|
703 let
|
adamc@389
|
704 val t = monoType env t
|
adamc@389
|
705 in
|
adamc@389
|
706 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
707 (L'.EField ((L'.ERel 0, loc), "Times"), loc)), loc), fm)
|
adamc@389
|
708 end
|
adamc@389
|
709 | L.ECApp ((L.EFfi ("Basis", "div"), _), t) =>
|
adamc@389
|
710 let
|
adamc@389
|
711 val t = monoType env t
|
adamc@389
|
712 in
|
adamc@389
|
713 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
714 (L'.EField ((L'.ERel 0, loc), "Div"), loc)), loc), fm)
|
adamc@389
|
715 end
|
adamc@389
|
716 | L.ECApp ((L.EFfi ("Basis", "mod"), _), t) =>
|
adamc@389
|
717 let
|
adamc@389
|
718 val t = monoType env t
|
adamc@389
|
719 in
|
adamc@389
|
720 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
721 (L'.EField ((L'.ERel 0, loc), "Mod"), loc)), loc), fm)
|
adamc@389
|
722 end
|
adamc@389
|
723 | L.EFfi ("Basis", "num_int") =>
|
adamc@389
|
724 let
|
adamc@389
|
725 fun intBin s =
|
adamc@389
|
726 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
727 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "int"), loc)), loc),
|
adamc@389
|
728 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
729 (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
730 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@389
|
731 in
|
adamc@389
|
732 numEx ((L'.TFfi ("Basis", "int"), loc),
|
adamc@417
|
733 Prim.Int (Int64.fromInt 0),
|
adamc@389
|
734 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
735 (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
736 (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc),
|
adamc@389
|
737 intBin "+",
|
adamc@389
|
738 intBin "-",
|
adamc@389
|
739 intBin "*",
|
adamc@389
|
740 intBin "/",
|
adamc@389
|
741 intBin "%")
|
adamc@389
|
742 end
|
adamc@390
|
743 | L.EFfi ("Basis", "num_float") =>
|
adamc@390
|
744 let
|
adamc@390
|
745 fun floatBin s =
|
adamc@390
|
746 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
747 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "float"), loc)), loc),
|
adamc@390
|
748 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
749 (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
750 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@390
|
751 in
|
adamc@390
|
752 numEx ((L'.TFfi ("Basis", "float"), loc),
|
adamc@417
|
753 Prim.Float 0.0,
|
adamc@390
|
754 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
755 (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
756 (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc),
|
adamc@390
|
757 floatBin "+",
|
adamc@390
|
758 floatBin "-",
|
adamc@390
|
759 floatBin "*",
|
adamc@390
|
760 floatBin "/",
|
adamc@390
|
761 floatBin "fmod")
|
adamc@390
|
762 end
|
adamc@391
|
763
|
adamc@391
|
764 | L.ECApp ((L.EFfi ("Basis", "lt"), _), t) =>
|
adamc@391
|
765 let
|
adamc@391
|
766 val t = monoType env t
|
adamc@391
|
767 in
|
adamc@391
|
768 ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc),
|
adamc@391
|
769 (L'.EField ((L'.ERel 0, loc), "Lt"), loc)), loc), fm)
|
adamc@391
|
770 end
|
adamc@391
|
771 | L.ECApp ((L.EFfi ("Basis", "le"), _), t) =>
|
adamc@391
|
772 let
|
adamc@391
|
773 val t = monoType env t
|
adamc@391
|
774 in
|
adamc@391
|
775 ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc),
|
adamc@391
|
776 (L'.EField ((L'.ERel 0, loc), "Le"), loc)), loc), fm)
|
adamc@391
|
777 end
|
adamc@392
|
778 | L.ECApp ((L.EFfi ("Basis", "gt"), _), t) =>
|
adamc@392
|
779 let
|
adamc@392
|
780 val t = monoType env t
|
adamc@392
|
781 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@392
|
782 in
|
adamc@392
|
783 ((L'.EAbs ("f", ordTy t, (L'.TFun (t, (L'.TFun (t, b), loc)), loc),
|
adamc@392
|
784 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@392
|
785 (L'.EAbs ("y", t, b,
|
adamc@392
|
786 (L'.EUnop ("!",
|
adamc@392
|
787 (L'.EApp ((L'.EApp ((L'.EField ((L'.ERel 2, loc),
|
adamc@392
|
788 "Le"), loc),
|
adamc@392
|
789 (L'.ERel 1, loc)), loc),
|
adamc@392
|
790 (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@392
|
791 loc)),
|
adamc@392
|
792 loc), fm)
|
adamc@392
|
793 end
|
adamc@392
|
794 | L.ECApp ((L.EFfi ("Basis", "ge"), _), t) =>
|
adamc@392
|
795 let
|
adamc@392
|
796 val t = monoType env t
|
adamc@392
|
797 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@392
|
798 in
|
adamc@392
|
799 ((L'.EAbs ("f", ordTy t, (L'.TFun (t, (L'.TFun (t, b), loc)), loc),
|
adamc@392
|
800 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@392
|
801 (L'.EAbs ("y", t, b,
|
adamc@392
|
802 (L'.EUnop ("!",
|
adamc@392
|
803 (L'.EApp ((L'.EApp ((L'.EField ((L'.ERel 2, loc),
|
adamc@392
|
804 "Lt"), loc),
|
adamc@392
|
805 (L'.ERel 1, loc)), loc),
|
adamc@392
|
806 (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@392
|
807 loc)),
|
adamc@392
|
808 loc), fm)
|
adamc@392
|
809 end
|
adamc@391
|
810 | L.EFfi ("Basis", "ord_int") =>
|
adamc@391
|
811 let
|
adamc@391
|
812 fun intBin s =
|
adamc@391
|
813 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
814 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@391
|
815 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
816 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@391
|
817 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@391
|
818 in
|
adamc@391
|
819 ordEx ((L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
820 intBin "<",
|
adamc@391
|
821 intBin "<=")
|
adamc@391
|
822 end
|
adamc@394
|
823 | L.EFfi ("Basis", "ord_float") =>
|
adamc@394
|
824 let
|
adamc@394
|
825 fun floatBin s =
|
adamc@394
|
826 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
827 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
828 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
829 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
830 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@394
|
831 in
|
adamc@394
|
832 ordEx ((L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
833 floatBin "<",
|
adamc@394
|
834 floatBin "<=")
|
adamc@394
|
835 end
|
adamc@394
|
836 | L.EFfi ("Basis", "ord_bool") =>
|
adamc@394
|
837 let
|
adamc@394
|
838 fun boolBin s =
|
adamc@394
|
839 (L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
840 (L'.TFun ((L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
841 (L'.EAbs ("y", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
842 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
843 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@394
|
844 in
|
adamc@394
|
845 ordEx ((L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
846 boolBin "<",
|
adamc@394
|
847 boolBin "<=")
|
adamc@394
|
848 end
|
adamc@395
|
849 | L.EFfi ("Basis", "ord_string") =>
|
adamc@395
|
850 let
|
adamc@395
|
851 fun boolBin s =
|
adamc@395
|
852 (L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
853 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@395
|
854 (L'.EAbs ("y", (L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
855 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@395
|
856 (L'.EBinop (s,
|
adamc@395
|
857 (L'.EBinop ("strcmp",
|
adamc@395
|
858 (L'.ERel 1, loc),
|
adamc@395
|
859 (L'.ERel 0, loc)), loc),
|
adamc@395
|
860 (L'.EPrim (Prim.Int (Int64.fromInt 0)), loc)), loc)), loc)), loc)
|
adamc@395
|
861 in
|
adamc@395
|
862 ordEx ((L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
863 boolBin "<",
|
adamc@395
|
864 boolBin "<=")
|
adamc@395
|
865 end
|
adamc@437
|
866 | L.EFfi ("Basis", "ord_time") =>
|
adamc@437
|
867 let
|
adamc@437
|
868 fun boolBin s =
|
adamc@437
|
869 (L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
870 (L'.TFun ((L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@437
|
871 (L'.EAbs ("y", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
872 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@437
|
873 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@437
|
874 in
|
adamc@437
|
875 ordEx ((L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
876 boolBin "<",
|
adamc@437
|
877 boolBin "<=")
|
adamc@437
|
878 end
|
adamc@389
|
879
|
adamc@286
|
880 | L.ECApp ((L.EFfi ("Basis", "show"), _), t) =>
|
adamc@286
|
881 let
|
adamc@286
|
882 val t = monoType env t
|
adamc@286
|
883 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@286
|
884 in
|
adamc@286
|
885 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@286
|
886 (L'.ERel 0, loc)), loc), fm)
|
adamc@286
|
887 end
|
adamc@286
|
888 | L.EFfi ("Basis", "show_int") =>
|
adamc@286
|
889 ((L'.EFfi ("Basis", "intToString"), loc), fm)
|
adamc@286
|
890 | L.EFfi ("Basis", "show_float") =>
|
adamc@286
|
891 ((L'.EFfi ("Basis", "floatToString"), loc), fm)
|
adamc@286
|
892 | L.EFfi ("Basis", "show_string") =>
|
adamc@286
|
893 let
|
adamc@286
|
894 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@286
|
895 in
|
adamc@286
|
896 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), fm)
|
adamc@286
|
897 end
|
adamc@286
|
898 | L.EFfi ("Basis", "show_bool") =>
|
adamc@286
|
899 ((L'.EFfi ("Basis", "boolToString"), loc), fm)
|
adamc@436
|
900 | L.EFfi ("Basis", "show_time") =>
|
adamc@436
|
901 ((L'.EFfi ("Basis", "timeToString"), loc), fm)
|
adamc@452
|
902 | L.ECApp ((L.EFfi ("Basis", "mkShow"), _), t) =>
|
adamc@452
|
903 let
|
adamc@452
|
904 val t = monoType env t
|
adamc@452
|
905 val b = (L'.TFfi ("Basis", "string"), loc)
|
adamc@452
|
906 val dom = (L'.TFun (t, b), loc)
|
adamc@452
|
907 in
|
adamc@452
|
908 ((L'.EAbs ("f", dom, dom,
|
adamc@452
|
909 (L'.ERel 0, loc)), loc), fm)
|
adamc@452
|
910 end
|
adamc@286
|
911
|
adamc@290
|
912 | L.ECApp ((L.EFfi ("Basis", "read"), _), t) =>
|
adamc@290
|
913 let
|
adamc@290
|
914 val t = monoType env t
|
adamc@290
|
915 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@290
|
916 in
|
adamc@292
|
917 ((L'.EAbs ("f", readType (t, loc), readType' (t, loc),
|
adamc@292
|
918 (L'.EField ((L'.ERel 0, loc), "Read"), loc)), loc), fm)
|
adamc@292
|
919 end
|
adamc@292
|
920 | L.ECApp ((L.EFfi ("Basis", "readError"), _), t) =>
|
adamc@292
|
921 let
|
adamc@292
|
922 val t = monoType env t
|
adamc@292
|
923 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@292
|
924 in
|
adamc@292
|
925 ((L'.EAbs ("f", readType (t, loc), readErrType (t, loc),
|
adamc@292
|
926 (L'.EField ((L'.ERel 0, loc), "ReadError"), loc)), loc), fm)
|
adamc@290
|
927 end
|
adamc@290
|
928 | L.EFfi ("Basis", "read_int") =>
|
adamc@292
|
929 let
|
adamc@292
|
930 val t = (L'.TFfi ("Basis", "int"), loc)
|
adamc@292
|
931 in
|
adamc@292
|
932 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToInt"), loc), readType' (t, loc)),
|
adamc@292
|
933 ("ReadError", (L'.EFfi ("Basis", "stringToInt_error"), loc), readErrType (t, loc))],
|
adamc@292
|
934 loc),
|
adamc@292
|
935 fm)
|
adamc@292
|
936 end
|
adamc@290
|
937 | L.EFfi ("Basis", "read_float") =>
|
adamc@292
|
938 let
|
adamc@292
|
939 val t = (L'.TFfi ("Basis", "float"), loc)
|
adamc@292
|
940 in
|
adamc@292
|
941 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToFloat"), loc), readType' (t, loc)),
|
adamc@292
|
942 ("ReadError", (L'.EFfi ("Basis", "stringToFloat_error"), loc), readErrType (t, loc))],
|
adamc@292
|
943 loc),
|
adamc@292
|
944 fm)
|
adamc@292
|
945 end
|
adamc@290
|
946 | L.EFfi ("Basis", "read_string") =>
|
adamc@290
|
947 let
|
adamc@290
|
948 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@290
|
949 in
|
adamc@292
|
950 ((L'.ERecord [("Read", (L'.EAbs ("s", s, (L'.TOption s, loc),
|
adamc@292
|
951 (L'.ESome (s, (L'.ERel 0, loc)), loc)), loc), readType' (s, loc)),
|
adamc@292
|
952 ("ReadError", (L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), readErrType (s, loc))], loc),
|
adamc@292
|
953 fm)
|
adamc@290
|
954 end
|
adamc@290
|
955 | L.EFfi ("Basis", "read_bool") =>
|
adamc@292
|
956 let
|
adamc@292
|
957 val t = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@292
|
958 in
|
adamc@292
|
959 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToBool"), loc), readType' (t, loc)),
|
adamc@292
|
960 ("ReadError", (L'.EFfi ("Basis", "stringToBool_error"), loc), readErrType (t, loc))],
|
adamc@292
|
961 loc),
|
adamc@292
|
962 fm)
|
adamc@292
|
963 end
|
adamc@436
|
964 | L.EFfi ("Basis", "read_time") =>
|
adamc@436
|
965 let
|
adamc@436
|
966 val t = (L'.TFfi ("Basis", "time"), loc)
|
adamc@436
|
967 in
|
adamc@436
|
968 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToTime"), loc), readType' (t, loc)),
|
adamc@436
|
969 ("ReadError", (L'.EFfi ("Basis", "stringToTime_error"), loc), readErrType (t, loc))],
|
adamc@436
|
970 loc),
|
adamc@436
|
971 fm)
|
adamc@436
|
972 end
|
adamc@290
|
973
|
adamc@564
|
974 | L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), _), _), t), _),
|
adamc@564
|
975 (L.EFfi ("Basis", "transaction_monad"), _)) =>
|
adamc@252
|
976 let
|
adamc@252
|
977 val t = monoType env t
|
adamc@252
|
978 in
|
adamc@252
|
979 ((L'.EAbs ("x", t,
|
adamc@252
|
980 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@252
|
981 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@252
|
982 (L'.ERel 1, loc)), loc)), loc), fm)
|
adamc@252
|
983 end
|
adamc@564
|
984 | L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), t1), _), t2), _),
|
adamc@564
|
985 (L.EFfi ("Basis", "transaction_monad"), _)) =>
|
adamc@251
|
986 let
|
adamc@251
|
987 val t1 = monoType env t1
|
adamc@251
|
988 val t2 = monoType env t2
|
adamc@251
|
989 val un = (L'.TRecord [], loc)
|
adamc@252
|
990 val mt1 = (L'.TFun (un, t1), loc)
|
adamc@252
|
991 val mt2 = (L'.TFun (un, t2), loc)
|
adamc@251
|
992 in
|
adamc@572
|
993 ((L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc)), loc),
|
adamc@572
|
994 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc),
|
adamc@252
|
995 (L'.EAbs ("_", un, un,
|
adamc@252
|
996 (L'.ELet ("r", t1, (L'.EApp ((L'.ERel 2, loc),
|
adamc@252
|
997 (L'.ERecord [], loc)), loc),
|
adamc@252
|
998 (L'.EApp (
|
adamc@252
|
999 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc),
|
adamc@252
|
1000 (L'.ERecord [], loc)),
|
adamc@252
|
1001 loc)), loc)), loc)), loc)), loc),
|
adamc@251
|
1002 fm)
|
adamc@251
|
1003 end
|
adamc@697
|
1004
|
adamc@670
|
1005 | L.EApp ((L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), _), _), t2), _),
|
adamc@670
|
1006 (L.EFfi ("Basis", "transaction_monad"), _)), _),
|
adamc@670
|
1007 (L.EApp ((L.ECApp ((L.EFfi ("Basis", "recv"), _), t1), _),
|
adamc@670
|
1008 ch), loc)) =>
|
adamc@670
|
1009 let
|
adamc@670
|
1010 val t1 = monoType env t1
|
adamc@670
|
1011 val t2 = monoType env t2
|
adamc@670
|
1012 val un = (L'.TRecord [], loc)
|
adamc@670
|
1013 val mt2 = (L'.TFun (un, t2), loc)
|
adamc@670
|
1014 val (ch, fm) = monoExp (env, st, fm) ch
|
adamc@670
|
1015 in
|
adamc@670
|
1016 ((L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc),
|
adamc@670
|
1017 (L'.EAbs ("_", un, un,
|
adamc@670
|
1018 (L'.ERecv (liftExpInExp 0 (liftExpInExp 0 ch),
|
adamc@670
|
1019 (L'.ERel 1, loc),
|
adamc@670
|
1020 t1), loc)), loc)), loc),
|
adamc@670
|
1021 fm)
|
adamc@670
|
1022 end
|
adamc@697
|
1023 | L.EFfiApp ("Basis", "recv", _) => poly ()
|
adamc@697
|
1024
|
adamc@695
|
1025 | L.EApp ((L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), _), _), t2), _),
|
adamc@695
|
1026 (L.EFfi ("Basis", "transaction_monad"), _)), _),
|
adamc@695
|
1027 (L.EAbs (_, _, _,
|
adamc@695
|
1028 (L.EFfiApp ("Basis", "sleep", [n]), _)), loc)) =>
|
adamc@695
|
1029 let
|
adamc@695
|
1030 val t2 = monoType env t2
|
adamc@695
|
1031 val un = (L'.TRecord [], loc)
|
adamc@695
|
1032 val mt2 = (L'.TFun (un, t2), loc)
|
adamc@695
|
1033 val (n, fm) = monoExp (env, st, fm) n
|
adamc@695
|
1034 in
|
adamc@695
|
1035 ((L'.EAbs ("m2", (L'.TFun (un, mt2), loc), (L'.TFun (un, un), loc),
|
adamc@695
|
1036 (L'.EAbs ("_", un, un,
|
adamc@697
|
1037 (L'.ESleep (liftExpInExp 0 n, (L'.EApp ((L'.ERel 1, loc),
|
adamc@695
|
1038 (L'.ERecord [], loc)), loc)),
|
adamc@695
|
1039 loc)), loc)), loc),
|
adamc@695
|
1040 fm)
|
adamc@695
|
1041 end
|
adamc@697
|
1042 | L.EFfiApp ("Basis", "sleep", _) => poly ()
|
adamc@251
|
1043
|
adamc@565
|
1044 | L.ECApp ((L.EFfi ("Basis", "source"), _), t) =>
|
adamc@565
|
1045 let
|
adamc@565
|
1046 val t = monoType env t
|
adamc@565
|
1047 in
|
adamc@577
|
1048 ((L'.EAbs ("x", t, (L'.TFun ((L'.TRecord [], loc), (L'.TSource, loc)), loc),
|
adamc@577
|
1049 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TSource, loc),
|
adamc@577
|
1050 (L'.EFfiApp ("Basis", "new_client_source",
|
adamc@590
|
1051 [(L'.EJavaScript (L'.Source t, (L'.ERel 1, loc), NONE), loc)]),
|
adamc@578
|
1052 loc)), loc)),
|
adamc@565
|
1053 loc),
|
adamc@565
|
1054 fm)
|
adamc@565
|
1055 end
|
adamc@575
|
1056 | L.ECApp ((L.EFfi ("Basis", "set"), _), t) =>
|
adamc@575
|
1057 let
|
adamc@575
|
1058 val t = monoType env t
|
adamc@575
|
1059 in
|
adamc@577
|
1060 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@575
|
1061 (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc)), loc),
|
adamc@575
|
1062 (L'.EAbs ("v", t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc),
|
adamc@575
|
1063 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@575
|
1064 (L'.EFfiApp ("Basis", "set_client_source",
|
adamc@577
|
1065 [(L'.ERel 2, loc),
|
adamc@590
|
1066 (L'.EJavaScript (L'.Source t,
|
adamc@590
|
1067 (L'.ERel 1, loc), NONE), loc)]),
|
adamc@575
|
1068 loc)), loc)), loc)), loc),
|
adamc@575
|
1069 fm)
|
adamc@575
|
1070 end
|
adamc@601
|
1071 | L.ECApp ((L.EFfi ("Basis", "get"), _), t) =>
|
adamc@601
|
1072 let
|
adamc@601
|
1073 val t = monoType env t
|
adamc@601
|
1074 in
|
adamc@601
|
1075 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@601
|
1076 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@601
|
1077 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@601
|
1078 (L'.EFfiApp ("Basis", "get_client_source",
|
adamc@601
|
1079 [(L'.ERel 1, loc)]),
|
adamc@601
|
1080 loc)), loc)), loc),
|
adamc@601
|
1081 fm)
|
adamc@601
|
1082 end
|
adamc@565
|
1083
|
adamc@694
|
1084 | L.EFfiApp ("Basis", "spawn", [e]) =>
|
adamc@694
|
1085 let
|
adamc@694
|
1086 val (e, fm) = monoExp (env, st, fm) e
|
adamc@694
|
1087 in
|
adamc@694
|
1088 ((L'.EApp (e, (L'.ERecord [], loc)), loc), fm)
|
adamc@694
|
1089 end
|
adamc@694
|
1090
|
adamc@568
|
1091 | L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), _), _), t), _),
|
adamc@568
|
1092 (L.EFfi ("Basis", "signal_monad"), _)) =>
|
adamc@568
|
1093 let
|
adamc@568
|
1094 val t = monoType env t
|
adamc@568
|
1095 in
|
adamc@568
|
1096 ((L'.EAbs ("x", t, (L'.TSignal t, loc),
|
adamc@568
|
1097 (L'.ESignalReturn (L'.ERel 0, loc), loc)), loc),
|
adamc@568
|
1098 fm)
|
adamc@568
|
1099 end
|
adamc@572
|
1100 | L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), t1), _), t2), _),
|
adamc@572
|
1101 (L.EFfi ("Basis", "signal_monad"), _)) =>
|
adamc@572
|
1102 let
|
adamc@572
|
1103 val t1 = monoType env t1
|
adamc@572
|
1104 val t2 = monoType env t2
|
adamc@572
|
1105 val un = (L'.TRecord [], loc)
|
adamc@572
|
1106 val mt1 = (L'.TSignal t1, loc)
|
adamc@572
|
1107 val mt2 = (L'.TSignal t2, loc)
|
adamc@572
|
1108 in
|
adamc@572
|
1109 ((L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), mt2), loc),
|
adamc@572
|
1110 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), mt2,
|
adamc@572
|
1111 (L'.ESignalBind ((L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@572
|
1112 fm)
|
adamc@572
|
1113 end
|
adamc@574
|
1114 | L.ECApp ((L.EFfi ("Basis", "signal"), _), t) =>
|
adamc@574
|
1115 let
|
adamc@574
|
1116 val t = monoType env t
|
adamc@574
|
1117 in
|
adamc@574
|
1118 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TSignal t, loc),
|
adamc@574
|
1119 (L'.ESignalSource (L'.ERel 0, loc), loc)), loc),
|
adamc@574
|
1120 fm)
|
adamc@574
|
1121 end
|
adamc@568
|
1122
|
adamc@462
|
1123 | L.ECApp ((L.EFfi ("Basis", "getCookie"), _), t) =>
|
adamc@462
|
1124 let
|
adamc@462
|
1125 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1126 val un = (L'.TRecord [], loc)
|
adamc@462
|
1127 val t = monoType env t
|
adamc@462
|
1128 in
|
adamc@462
|
1129 ((L'.EAbs ("c", s, (L'.TFun (un, s), loc),
|
adamc@462
|
1130 (L'.EAbs ("_", un, s,
|
adamc@463
|
1131 (L'.EUnurlify ((L'.EFfiApp ("Basis", "get_cookie", [(L'.ERel 1, loc)]), loc),
|
adamc@463
|
1132 t),
|
adamc@463
|
1133 loc)), loc)), loc),
|
adamc@462
|
1134 fm)
|
adamc@462
|
1135 end
|
adamc@462
|
1136
|
adamc@462
|
1137 | L.ECApp ((L.EFfi ("Basis", "setCookie"), _), t) =>
|
adamc@462
|
1138 let
|
adamc@462
|
1139 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1140 val un = (L'.TRecord [], loc)
|
adamc@462
|
1141 val t = monoType env t
|
adamc@462
|
1142 val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
|
adamc@462
|
1143 in
|
adamc@462
|
1144 ((L'.EAbs ("c", s, (L'.TFun (t, (L'.TFun (un, un), loc)), loc),
|
adamc@462
|
1145 (L'.EAbs ("v", t, (L'.TFun (un, un), loc),
|
adamc@462
|
1146 (L'.EAbs ("_", un, un,
|
adamc@466
|
1147 (L'.EFfiApp ("Basis", "set_cookie", [(L'.EPrim (Prim.String (!urlPrefix)),
|
adamc@466
|
1148 loc),
|
adamc@466
|
1149 (L'.ERel 2, loc),
|
adamc@466
|
1150 e]), loc)),
|
adamc@462
|
1151 loc)), loc)), loc),
|
adamc@462
|
1152 fm)
|
adamc@462
|
1153 end
|
adamc@462
|
1154
|
adamc@668
|
1155 | L.ECApp ((L.EFfi ("Basis", "channel"), _), t) =>
|
adamc@668
|
1156 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "channel"), loc),
|
adamc@668
|
1157 (L'.EFfiApp ("Basis", "new_channel", [(L'.ERecord [], loc)]), loc)), loc),
|
adamc@668
|
1158 fm)
|
adamc@668
|
1159 | L.ECApp ((L.EFfi ("Basis", "send"), _), t) =>
|
adamc@668
|
1160 let
|
adamc@668
|
1161 val t = monoType env t
|
adamc@668
|
1162 val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
|
adamc@668
|
1163 in
|
adamc@668
|
1164 ((L'.EAbs ("ch", (L'.TFfi ("Basis", "channel"), loc),
|
adamc@668
|
1165 (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc)), loc),
|
adamc@668
|
1166 (L'.EAbs ("v", t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc),
|
adamc@668
|
1167 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@668
|
1168 (L'.EFfiApp ("Basis", "send",
|
adamc@668
|
1169 [(L'.ERel 2, loc),
|
adamc@668
|
1170 e]),
|
adamc@668
|
1171 loc)), loc)), loc)), loc),
|
adamc@668
|
1172 fm)
|
adamc@668
|
1173 end
|
adamc@668
|
1174
|
adamc@707
|
1175 | L.ECApp ((L.EFfi ("Basis", "no_primary_key"), _), _) =>
|
adamc@707
|
1176 ((L'.EPrim (Prim.String ""), loc),
|
adamc@707
|
1177 fm)
|
adamc@707
|
1178 | L.ECApp (
|
adamc@707
|
1179 (L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "primary_key"), _), _), _), t), _),
|
adamc@707
|
1180 nm), _),
|
adamc@707
|
1181 (L.CRecord (_, unique), _)) =>
|
adamc@707
|
1182 let
|
adamc@707
|
1183 val unique = (nm, t) :: unique
|
adamc@707
|
1184 val witnesses = (L'.TRecord (map (fn (nm, _) => (monoName env nm, (L'.TRecord [], loc))) unique), loc)
|
adamc@707
|
1185 in
|
adamc@707
|
1186 ((L'.EAbs ("_", witnesses, (L'.TFfi ("Basis", "string"), loc),
|
adamc@707
|
1187 (L'.EPrim (Prim.String
|
adamc@707
|
1188 (String.concatWith ", "
|
adamc@707
|
1189 (map (fn (x, _) => "uw_" ^ monoName env x) unique))),
|
adamc@707
|
1190 loc)), loc),
|
adamc@707
|
1191 fm)
|
adamc@707
|
1192 end
|
adamc@707
|
1193
|
adamc@704
|
1194 | L.ECApp ((L.EFfi ("Basis", "no_constraint"), _), _) =>
|
adamc@704
|
1195 ((L'.ERecord [], loc),
|
adamc@704
|
1196 fm)
|
adamc@705
|
1197 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "one_constraint"), _), _), _), _), _), (L.CName name, _)) =>
|
adamc@704
|
1198 ((L'.EAbs ("c",
|
adamc@704
|
1199 (L'.TFfi ("Basis", "string"), loc),
|
adamc@704
|
1200 (L'.TFfi ("Basis", "sql_constraints"), loc),
|
adamc@704
|
1201 (L'.ERecord [(name, (L'.ERel 0, loc), (L'.TFfi ("Basis", "string"), loc))], loc)), loc),
|
adamc@704
|
1202 fm)
|
adamc@705
|
1203 | L.ECApp (
|
adamc@705
|
1204 (L.ECApp (
|
adamc@705
|
1205 (L.ECApp (
|
adamc@705
|
1206 (L.EFfi ("Basis", "join_constraints"), _),
|
adamc@705
|
1207 _), _),
|
adamc@705
|
1208 _), _),
|
adamc@705
|
1209 _) =>
|
adamc@704
|
1210 let
|
adamc@704
|
1211 val constraints = (L'.TFfi ("Basis", "sql_constraints"), loc)
|
adamc@704
|
1212 in
|
adamc@704
|
1213 ((L'.EAbs ("cs1", constraints, (L'.TFun (constraints, constraints), loc),
|
adamc@704
|
1214 (L'.EAbs ("cs2", constraints, constraints,
|
adamc@704
|
1215 (L'.EStrcat ((L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@704
|
1216 fm)
|
adamc@704
|
1217 end
|
adamc@704
|
1218
|
adamc@705
|
1219 | L.ECApp (
|
adamc@705
|
1220 (L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "unique"), _), _), _), t), _),
|
adamc@705
|
1221 nm), _),
|
adamc@705
|
1222 (L.CRecord (_, unique), _)) =>
|
adamc@705
|
1223 let
|
adamc@705
|
1224 val unique = (nm, t) :: unique
|
adamc@705
|
1225 in
|
adamc@705
|
1226 ((L'.EPrim (Prim.String ("UNIQUE ("
|
adamc@705
|
1227 ^ String.concatWith ", " (map (fn (x, _) => "uw_" ^ monoName env x) unique)
|
adamc@705
|
1228 ^ ")")), loc),
|
adamc@705
|
1229 fm)
|
adamc@705
|
1230 end
|
adamc@704
|
1231
|
adamc@712
|
1232 | L.ECApp ((L.EFfi ("Basis", "linkable_same"), loc), _) =>
|
adamc@712
|
1233 ((L'.ERecord [], loc), fm)
|
adamc@712
|
1234 | L.ECApp ((L.EFfi ("Basis", "linkable_from_nullable"), loc), _) =>
|
adamc@712
|
1235 ((L'.ERecord [], loc), fm)
|
adamc@712
|
1236 | L.ECApp ((L.EFfi ("Basis", "linkable_to_nullable"), loc), _) =>
|
adamc@712
|
1237 ((L'.ERecord [], loc), fm)
|
adamc@712
|
1238
|
adamc@709
|
1239 | L.EFfi ("Basis", "mat_nil") =>
|
adamc@709
|
1240 let
|
adamc@709
|
1241 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
1242 val stringE = (L'.EPrim (Prim.String ""), loc)
|
adamc@709
|
1243 in
|
adamc@709
|
1244 ((L'.ERecord [("1", stringE, string),
|
adamc@709
|
1245 ("2", stringE, string)], loc), fm)
|
adamc@709
|
1246 end
|
adamc@709
|
1247 | L.ECApp (
|
adamc@709
|
1248 (L.ECApp (
|
adamc@709
|
1249 (L.ECApp (
|
adamc@709
|
1250 (L.ECApp (
|
adamc@709
|
1251 (L.ECApp (
|
adamc@712
|
1252 (L.ECApp (
|
adamc@712
|
1253 (L.EFfi ("Basis", "mat_cons"), _),
|
adamc@712
|
1254 _), _),
|
adamc@709
|
1255 _), _),
|
adamc@709
|
1256 _), _),
|
adamc@709
|
1257 _), _),
|
adamc@709
|
1258 (L.CName nm1, _)), _),
|
adamc@709
|
1259 (L.CName nm2, _)) =>
|
adamc@709
|
1260 let
|
adamc@709
|
1261 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
1262 val mat = (L'.TRecord [("1", string), ("2", string)], loc)
|
adamc@709
|
1263 in
|
adamc@712
|
1264 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFun (mat, mat), loc),
|
adamc@712
|
1265 (L'.EAbs ("m", mat, mat,
|
adamc@712
|
1266 (L'.ECase ((L'.EField ((L'.ERel 0, loc), "1"), loc),
|
adamc@712
|
1267 [((L'.PPrim (Prim.String ""), loc),
|
adamc@712
|
1268 (L'.ERecord [("1", (L'.EPrim (Prim.String ("uw_" ^ nm1)),
|
adamc@712
|
1269 loc), string),
|
adamc@712
|
1270 ("2", (L'.EPrim (Prim.String ("uw_" ^ nm2)),
|
adamc@712
|
1271 loc), string)], loc)),
|
adamc@712
|
1272 ((L'.PWild, loc),
|
adamc@712
|
1273 (L'.ERecord [("1", (L'.EStrcat (
|
adamc@712
|
1274 (L'.EPrim (Prim.String ("uw_" ^ nm1 ^ ", ")),
|
adamc@712
|
1275 loc),
|
adamc@712
|
1276 (L'.EField ((L'.ERel 0, loc), "1"), loc)),
|
adamc@712
|
1277 loc), string),
|
adamc@712
|
1278 ("2", (L'.EStrcat (
|
adamc@712
|
1279 (L'.EPrim (Prim.String ("uw_" ^ nm2 ^ ", ")), loc),
|
adamc@712
|
1280 (L'.EField ((L'.ERel 0, loc), "2"), loc)),
|
adamc@712
|
1281 loc), string)],
|
adamc@712
|
1282 loc))],
|
adamc@712
|
1283 {disc = string,
|
adamc@712
|
1284 result = mat}), loc)), loc)), loc),
|
adamc@709
|
1285 fm)
|
adamc@709
|
1286 end
|
adamc@709
|
1287
|
adamc@709
|
1288 | L.ECApp ((L.EFfi ("Basis", "restrict"), _), _) => ((L'.EPrim (Prim.String "RESTRICT"), loc), fm)
|
adamc@709
|
1289 | L.ECApp ((L.EFfi ("Basis", "cascade"), _), _) => ((L'.EPrim (Prim.String "CASCADE"), loc), fm)
|
adamc@709
|
1290 | L.ECApp ((L.EFfi ("Basis", "no_action"), _), _) => ((L'.EPrim (Prim.String "NO ACTION"), loc), fm)
|
adamc@709
|
1291 | L.ECApp ((L.EFfi ("Basis", "set_null"), _), _) => ((L'.EPrim (Prim.String "SET NULL"), loc), fm)
|
adamc@709
|
1292
|
adamc@709
|
1293 | L.ECApp (
|
adamc@709
|
1294 (L.ECApp (
|
adamc@709
|
1295 (L.ECApp (
|
adamc@709
|
1296 (L.ECApp (
|
adamc@709
|
1297 (L.ECApp (
|
adamc@709
|
1298 (L.ECApp (
|
adamc@709
|
1299 (L.ECApp (
|
adamc@709
|
1300 (L.ECApp (
|
adamc@709
|
1301 (L.EFfi ("Basis", "foreign_key"), _),
|
adamc@709
|
1302 _), _),
|
adamc@709
|
1303 _), _),
|
adamc@709
|
1304 _), _),
|
adamc@709
|
1305 _), _),
|
adamc@709
|
1306 _), _),
|
adamc@709
|
1307 _), _),
|
adamc@709
|
1308 _), _),
|
adamc@709
|
1309 _) =>
|
adamc@709
|
1310 let
|
adamc@709
|
1311 val unit = (L'.TRecord [], loc)
|
adamc@709
|
1312 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@709
|
1313 val mat = (L'.TRecord [("1", string), ("2", string)], loc)
|
adamc@709
|
1314 val recd = (L'.TRecord [("OnDelete", string),
|
adamc@709
|
1315 ("OnUpdate", string)], loc)
|
adamc@709
|
1316
|
adamc@709
|
1317 fun strcat [] = raise Fail "Monoize.strcat"
|
adamc@709
|
1318 | strcat [e] = e
|
adamc@709
|
1319 | strcat (e1 :: es) = (L'.EStrcat (e1, strcat es), loc)
|
adamc@709
|
1320
|
adamc@709
|
1321 fun prop (fd, kw) =
|
adamc@709
|
1322 (L'.ECase ((L'.EField ((L'.ERel 0, loc), fd), loc),
|
adamc@709
|
1323 [((L'.PPrim (Prim.String "NO ACTION"), loc),
|
adamc@709
|
1324 (L'.EPrim (Prim.String ""), loc)),
|
adamc@709
|
1325 ((L'.PWild, loc),
|
adamc@709
|
1326 strcat [(L'.EPrim (Prim.String (" ON " ^ kw ^ " ")), loc),
|
adamc@709
|
1327 (L'.EField ((L'.ERel 0, loc), fd), loc)])],
|
adamc@709
|
1328 {disc = string,
|
adamc@709
|
1329 result = string}), loc)
|
adamc@709
|
1330 in
|
adamc@709
|
1331 ((L'.EAbs ("m", mat, (L'.TFun (string, (L'.TFun (recd, string), loc)), loc),
|
adamc@709
|
1332 (L'.EAbs ("tab", string, (L'.TFun (recd, string), loc),
|
adamc@709
|
1333 (L'.EAbs ("pr", recd, string,
|
adamc@709
|
1334 strcat [(L'.EPrim (Prim.String "FOREIGN KEY ("), loc),
|
adamc@709
|
1335 (L'.EField ((L'.ERel 2, loc), "1"), loc),
|
adamc@709
|
1336 (L'.EPrim (Prim.String ") REFERENCES "), loc),
|
adamc@709
|
1337 (L'.ERel 1, loc),
|
adamc@709
|
1338 (L'.EPrim (Prim.String " ("), loc),
|
adamc@709
|
1339 (L'.EField ((L'.ERel 2, loc), "2"), loc),
|
adamc@709
|
1340 (L'.EPrim (Prim.String ")"), loc),
|
adamc@709
|
1341 prop ("OnDelete", "DELETE"),
|
adamc@709
|
1342 prop ("OnUpdate", "UPDATE")]), loc)), loc)), loc),
|
adamc@709
|
1343 fm)
|
adamc@709
|
1344 end
|
adamc@709
|
1345
|
adamc@714
|
1346 | L.ECApp ((L.EFfi ("Basis", "check"), _), _) =>
|
adamc@714
|
1347 let
|
adamc@714
|
1348 val string = (L'.TFfi ("Basis", "string"), loc)
|
adamc@714
|
1349 in
|
adamc@714
|
1350 ((L'.EAbs ("e", string, string,
|
adamc@714
|
1351 (L'.EStrcat ((L'.EPrim (Prim.String "CHECK "), loc),
|
adamc@714
|
1352 (L'.EFfiApp ("Basis", "checkString",
|
adamc@714
|
1353 [(L'.ERel 0, loc)]), loc)), loc)), loc),
|
adamc@714
|
1354 fm)
|
adamc@714
|
1355 end
|
adamc@714
|
1356
|
adamc@307
|
1357 | L.EFfiApp ("Basis", "dml", [e]) =>
|
adamc@307
|
1358 let
|
adamc@307
|
1359 val (e, fm) = monoExp (env, st, fm) e
|
adamc@307
|
1360 in
|
adamc@468
|
1361 ((L'.EDml e, loc),
|
adamc@307
|
1362 fm)
|
adamc@307
|
1363 end
|
adamc@308
|
1364
|
adamc@705
|
1365 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "insert"), _), fields), _), _) =>
|
adamc@307
|
1366 (case monoType env (L.TRecord fields, loc) of
|
adamc@307
|
1367 (L'.TRecord fields, _) =>
|
adamc@307
|
1368 let
|
adamc@307
|
1369 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@307
|
1370 val fields = map (fn (x, _) => (x, s)) fields
|
adamc@307
|
1371 val rt = (L'.TRecord fields, loc)
|
adamc@307
|
1372 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@307
|
1373 in
|
adamc@307
|
1374 ((L'.EAbs ("tab", s, (L'.TFun (rt, s), loc),
|
adamc@307
|
1375 (L'.EAbs ("fs", rt, s,
|
adamc@598
|
1376 strcat [sc "INSERT INTO ",
|
adamc@598
|
1377 (L'.ERel 1, loc),
|
adamc@598
|
1378 sc " (",
|
adamc@598
|
1379 strcatComma (map (fn (x, _) => sc ("uw_" ^ x)) fields),
|
adamc@598
|
1380 sc ") VALUES (",
|
adamc@598
|
1381 strcatComma (map (fn (x, _) =>
|
adamc@598
|
1382 (L'.EField ((L'.ERel 0, loc),
|
adamc@598
|
1383 x), loc)) fields),
|
adamc@598
|
1384 sc ")"]), loc)), loc),
|
adamc@307
|
1385 fm)
|
adamc@307
|
1386 end
|
adamc@307
|
1387 | _ => poly ())
|
adamc@307
|
1388
|
adamc@705
|
1389 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "update"), _), _), _), _), _), changed) =>
|
adamc@308
|
1390 (case monoType env (L.TRecord changed, loc) of
|
adamc@308
|
1391 (L'.TRecord changed, _) =>
|
adamc@308
|
1392 let
|
adamc@308
|
1393 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@308
|
1394 val changed = map (fn (x, _) => (x, s)) changed
|
adamc@308
|
1395 val rt = (L'.TRecord changed, loc)
|
adamc@308
|
1396 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@308
|
1397 in
|
adamc@308
|
1398 ((L'.EAbs ("fs", rt, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@308
|
1399 (L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@308
|
1400 (L'.EAbs ("e", s, s,
|
adamc@598
|
1401 strcat [sc "UPDATE ",
|
adamc@598
|
1402 (L'.ERel 1, loc),
|
adamc@598
|
1403 sc " AS T SET ",
|
adamc@598
|
1404 strcatComma (map (fn (x, _) =>
|
adamc@598
|
1405 strcat [sc ("uw_" ^ x
|
adamc@598
|
1406 ^ " = "),
|
adamc@598
|
1407 (L'.EField
|
adamc@598
|
1408 ((L'.ERel 2,
|
adamc@598
|
1409 loc),
|
adamc@598
|
1410 x), loc)])
|
adamc@598
|
1411 changed),
|
adamc@598
|
1412 sc " WHERE ",
|
adamc@598
|
1413 (L'.ERel 0, loc)]), loc)), loc)), loc),
|
adamc@308
|
1414 fm)
|
adamc@308
|
1415 end
|
adamc@308
|
1416 | _ => poly ())
|
adamc@308
|
1417
|
adamc@705
|
1418 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "delete"), _), _), _), _) =>
|
adamc@309
|
1419 let
|
adamc@309
|
1420 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@309
|
1421 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@309
|
1422 in
|
adamc@309
|
1423 ((L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@309
|
1424 (L'.EAbs ("e", s, s,
|
adamc@598
|
1425 strcat [sc "DELETE FROM ",
|
adamc@598
|
1426 (L'.ERel 1, loc),
|
adamc@598
|
1427 sc " AS T WHERE ",
|
adamc@598
|
1428 (L'.ERel 0, loc)]), loc)), loc),
|
adamc@309
|
1429 fm)
|
adamc@309
|
1430 end
|
adamc@309
|
1431
|
adamc@252
|
1432 | L.ECApp (
|
adamc@252
|
1433 (L.ECApp (
|
adamc@252
|
1434 (L.ECApp ((L.EFfi ("Basis", "query"), _), (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1435 exps), _),
|
adamc@252
|
1436 state) =>
|
adamc@252
|
1437 (case monoType env (L.TRecord exps, loc) of
|
adamc@252
|
1438 (L'.TRecord exps, _) =>
|
adamc@252
|
1439 let
|
adamc@252
|
1440 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1441 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1442 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1443 | _ => NONE)
|
adamc@252
|
1444 | _ => NONE) tables
|
adamc@252
|
1445 in
|
adamc@252
|
1446 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1447 poly ()
|
adamc@252
|
1448 else
|
adamc@252
|
1449 let
|
adamc@252
|
1450 val tables = List.mapPartial (fn x => x) tables
|
adamc@252
|
1451 val state = monoType env state
|
adamc@252
|
1452 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1453 val un = (L'.TRecord [], loc)
|
adamc@252
|
1454
|
adamc@252
|
1455 val rt = exps @ map (fn (x, xts) => (x, (L'.TRecord xts, loc))) tables
|
adamc@252
|
1456 val ft = (L'.TFun ((L'.TRecord rt, loc),
|
adamc@252
|
1457 (L'.TFun (state,
|
adamc@252
|
1458 (L'.TFun (un, state), loc)),
|
adamc@252
|
1459 loc)), loc)
|
adamc@252
|
1460
|
adamc@267
|
1461 val body' = (L'.EApp (
|
adamc@267
|
1462 (L'.EApp (
|
adamc@267
|
1463 (L'.EApp ((L'.ERel 4, loc),
|
adamc@267
|
1464 (L'.ERel 1, loc)), loc),
|
adamc@267
|
1465 (L'.ERel 0, loc)), loc),
|
adamc@267
|
1466 (L'.ERecord [], loc)), loc)
|
adamc@252
|
1467
|
adamc@252
|
1468 val body = (L'.EQuery {exps = exps,
|
adamc@252
|
1469 tables = tables,
|
adamc@252
|
1470 state = state,
|
adamc@252
|
1471 query = (L'.ERel 3, loc),
|
adamc@252
|
1472 body = body',
|
adamc@252
|
1473 initial = (L'.ERel 1, loc)},
|
adamc@252
|
1474 loc)
|
adamc@252
|
1475 in
|
adamc@252
|
1476 ((L'.EAbs ("q", s, (L'.TFun (ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc)), loc),
|
adamc@252
|
1477 (L'.EAbs ("f", ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc),
|
adamc@252
|
1478 (L'.EAbs ("i", state, (L'.TFun (un, state), loc),
|
adamc@252
|
1479 (L'.EAbs ("_", un, state,
|
adamc@252
|
1480 body), loc)), loc)), loc)), loc), fm)
|
adamc@252
|
1481 end
|
adamc@252
|
1482 end
|
adamc@252
|
1483 | _ => poly ())
|
adamc@252
|
1484
|
adamc@252
|
1485 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_query"), _), _), _), _), _), _) =>
|
adamc@252
|
1486 let
|
adamc@252
|
1487 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1488 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1489 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1490 in
|
adamc@252
|
1491 ((L'.EAbs ("r",
|
adamc@252
|
1492 (L'.TRecord [("Rows", s), ("OrderBy", s), ("Limit", s), ("Offset", s)], loc),
|
adamc@252
|
1493 s,
|
adamc@598
|
1494 strcat [gf "Rows",
|
adamc@598
|
1495 (L'.ECase (gf "OrderBy",
|
adamc@598
|
1496 [((L'.PPrim (Prim.String ""), loc), sc ""),
|
adamc@598
|
1497 ((L'.PWild, loc),
|
adamc@598
|
1498 strcat [sc " ORDER BY ",
|
adamc@598
|
1499 gf "OrderBy"])],
|
adamc@598
|
1500 {disc = s, result = s}), loc),
|
adamc@598
|
1501 gf "Limit",
|
adamc@598
|
1502 gf "Offset"]), loc), fm)
|
adamc@252
|
1503 end
|
adamc@252
|
1504
|
adamc@252
|
1505 | L.ECApp (
|
adamc@252
|
1506 (L.ECApp (
|
adamc@252
|
1507 (L.ECApp (
|
adamc@252
|
1508 (L.ECApp (
|
adamc@252
|
1509 (L.EFfi ("Basis", "sql_query1"), _),
|
adamc@252
|
1510 (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1511 (L.CRecord (_, grouped), _)), _),
|
adamc@252
|
1512 (L.CRecord (_, stables), _)), _),
|
adamc@252
|
1513 sexps) =>
|
adamc@252
|
1514 let
|
adamc@252
|
1515 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1516 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1517 val un = (L'.TRecord [], loc)
|
adamc@252
|
1518 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1519
|
adamc@705
|
1520 val tables = List.mapPartial
|
adamc@705
|
1521 (fn (x, (L.CTuple [y, _], _)) => SOME (x, y)
|
adamc@705
|
1522 | _ => (E.errorAt loc "Bad sql_query1 tables pair";
|
adamc@705
|
1523 NONE))
|
adamc@705
|
1524 tables
|
adamc@705
|
1525
|
adamc@252
|
1526 fun doTables tables =
|
adamc@252
|
1527 let
|
adamc@252
|
1528 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1529 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1530 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1531 | _ => NONE)
|
adamc@252
|
1532 | _ => NONE) tables
|
adamc@252
|
1533 in
|
adamc@252
|
1534 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1535 NONE
|
adamc@252
|
1536 else
|
adamc@260
|
1537 let
|
adamc@260
|
1538 val tables = List.mapPartial (fn x => x) tables
|
adamc@260
|
1539 val tables = ListMergeSort.sort
|
adamc@260
|
1540 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1541 tables
|
adamc@260
|
1542 val tables = map (fn (x, xts) =>
|
adamc@260
|
1543 (x, ListMergeSort.sort
|
adamc@260
|
1544 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1545 xts)) tables
|
adamc@260
|
1546 in
|
adamc@260
|
1547 SOME tables
|
adamc@260
|
1548 end
|
adamc@252
|
1549 end
|
adamc@252
|
1550 in
|
adamc@252
|
1551 case (doTables tables, doTables grouped, doTables stables, monoType env (L.TRecord sexps, loc)) of
|
adamc@252
|
1552 (SOME tables, SOME grouped, SOME stables, (L'.TRecord sexps, _)) =>
|
adamc@441
|
1553 let
|
adamc@441
|
1554 val sexps = ListMergeSort.sort
|
adamc@441
|
1555 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER) sexps
|
adamc@441
|
1556 in
|
adamc@441
|
1557 ((L'.EAbs ("r",
|
adamc@441
|
1558 (L'.TRecord [("From", (L'.TRecord (map (fn (x, _) => (x, s)) tables), loc)),
|
adamc@441
|
1559 ("Where", s),
|
adamc@441
|
1560 ("GroupBy", un),
|
adamc@441
|
1561 ("Having", s),
|
adamc@441
|
1562 ("SelectFields", un),
|
adamc@441
|
1563 ("SelectExps", (L'.TRecord (map (fn (x, _) => (x, s)) sexps), loc))],
|
adamc@441
|
1564 loc),
|
adamc@441
|
1565 s,
|
adamc@598
|
1566 strcat [sc "SELECT ",
|
adamc@598
|
1567 strcatComma (map (fn (x, t) =>
|
adamc@598
|
1568 strcat [
|
adamc@598
|
1569 (L'.EField (gf "SelectExps", x), loc),
|
adamc@598
|
1570 sc (" AS _" ^ x)
|
adamc@598
|
1571 ]) sexps
|
adamc@598
|
1572 @ map (fn (x, xts) =>
|
adamc@598
|
1573 strcatComma
|
adamc@598
|
1574 (map (fn (x', _) =>
|
adamc@598
|
1575 sc (x ^ ".uw_" ^ x'))
|
adamc@598
|
1576 xts)) stables),
|
adamc@598
|
1577 sc " FROM ",
|
adamc@598
|
1578 strcatComma (map (fn (x, _) => strcat [(L'.EField (gf "From", x), loc),
|
adamc@598
|
1579 sc (" AS " ^ x)]) tables),
|
adamc@598
|
1580 (L'.ECase (gf "Where",
|
adamc@598
|
1581 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@598
|
1582 sc ""),
|
adamc@598
|
1583 ((L'.PWild, loc),
|
adamc@598
|
1584 strcat [sc " WHERE ", gf "Where"])],
|
adamc@598
|
1585 {disc = s,
|
adamc@598
|
1586 result = s}), loc),
|
adamc@598
|
1587
|
adamc@598
|
1588 if List.all (fn (x, xts) =>
|
adamc@598
|
1589 case List.find (fn (x', _) => x' = x) grouped of
|
adamc@598
|
1590 NONE => List.null xts
|
adamc@598
|
1591 | SOME (_, xts') =>
|
adamc@598
|
1592 List.all (fn (x, _) =>
|
adamc@598
|
1593 List.exists (fn (x', _) => x' = x)
|
adamc@598
|
1594 xts') xts) tables then
|
adamc@598
|
1595 sc ""
|
adamc@598
|
1596 else
|
adamc@598
|
1597 strcat [
|
adamc@598
|
1598 sc " GROUP BY ",
|
adamc@598
|
1599 strcatComma (map (fn (x, xts) =>
|
adamc@598
|
1600 strcatComma
|
adamc@598
|
1601 (map (fn (x', _) =>
|
adamc@598
|
1602 sc (x ^ ".uw_" ^ x'))
|
adamc@598
|
1603 xts)) grouped)
|
adamc@598
|
1604 ],
|
adamc@259
|
1605
|
adamc@598
|
1606 (L'.ECase (gf "Having",
|
adamc@598
|
1607 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@598
|
1608 sc ""),
|
adamc@598
|
1609 ((L'.PWild, loc),
|
adamc@598
|
1610 strcat [sc " HAVING ", gf "Having"])],
|
adamc@598
|
1611 {disc = s,
|
adamc@598
|
1612 result = s}), loc)
|
adamc@441
|
1613 ]), loc),
|
adamc@441
|
1614 fm)
|
adamc@441
|
1615 end
|
adamc@252
|
1616 | _ => poly ()
|
adamc@252
|
1617 end
|
adamc@252
|
1618
|
adamc@252
|
1619 | L.ECApp (
|
adamc@252
|
1620 (L.ECApp (
|
adamc@252
|
1621 (L.ECApp (
|
adamc@252
|
1622 (L.ECApp (
|
adamc@252
|
1623 (L.EFfi ("Basis", "sql_inject"), _),
|
adamc@252
|
1624 _), _),
|
adamc@252
|
1625 _), _),
|
adamc@252
|
1626 _), _),
|
adamc@252
|
1627 t) =>
|
adamc@252
|
1628 let
|
adamc@252
|
1629 val t = monoType env t
|
adamc@252
|
1630 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1631 in
|
adamc@252
|
1632 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@252
|
1633 (L'.ERel 0, loc)), loc), fm)
|
adamc@252
|
1634 end
|
adamc@252
|
1635
|
adamc@253
|
1636 | L.EFfi ("Basis", "sql_int") =>
|
adamc@253
|
1637 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1638 (L'.EFfiApp ("Basis", "sqlifyInt", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1639 fm)
|
adamc@253
|
1640 | L.EFfi ("Basis", "sql_float") =>
|
adamc@253
|
1641 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1642 (L'.EFfiApp ("Basis", "sqlifyFloat", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1643 fm)
|
adamc@253
|
1644 | L.EFfi ("Basis", "sql_bool") =>
|
adamc@253
|
1645 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1646 (L'.EFfiApp ("Basis", "sqlifyBool", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1647 fm)
|
adamc@253
|
1648 | L.EFfi ("Basis", "sql_string") =>
|
adamc@253
|
1649 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1650 (L'.EFfiApp ("Basis", "sqlifyString", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1651 fm)
|
adamc@439
|
1652 | L.EFfi ("Basis", "sql_time") =>
|
adamc@439
|
1653 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@439
|
1654 (L'.EFfiApp ("Basis", "sqlifyTime", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@439
|
1655 fm)
|
adamc@678
|
1656 | L.ECApp ((L.EFfi ("Basis", "sql_channel"), _), _) =>
|
adamc@678
|
1657 ((L'.EAbs ("x", (L'.TFfi ("Basis", "channel"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@678
|
1658 (L'.EFfiApp ("Basis", "sqlifyChannel", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@678
|
1659 fm)
|
adamc@682
|
1660 | L.EFfi ("Basis", "sql_client") =>
|
adamc@682
|
1661 ((L'.EAbs ("x", (L'.TFfi ("Basis", "client"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@682
|
1662 (L'.EFfiApp ("Basis", "sqlifyClient", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@682
|
1663 fm)
|
adamc@676
|
1664 | L.ECApp ((L.EFfi ("Basis", "sql_prim"), _), t) =>
|
adamc@676
|
1665 let
|
adamc@676
|
1666 val t = monoType env t
|
adamc@676
|
1667 val tf = (L'.TFun (t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@676
|
1668 in
|
adamc@676
|
1669 ((L'.EAbs ("f", tf, tf, (L'.ERel 0, loc)), loc),
|
adamc@676
|
1670 fm)
|
adamc@676
|
1671 end
|
adamc@676
|
1672 | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) =>
|
adamc@676
|
1673 let
|
adamc@676
|
1674 val t = monoType env t
|
adamc@676
|
1675 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@676
|
1676 in
|
adamc@676
|
1677 ((L'.EAbs ("f",
|
adamc@676
|
1678 (L'.TFun (t, s), loc),
|
adamc@676
|
1679 (L'.TFun ((L'.TOption t, loc), s), loc),
|
adamc@676
|
1680 (L'.EAbs ("x",
|
adamc@676
|
1681 (L'.TOption t, loc),
|
adamc@676
|
1682 s,
|
adamc@676
|
1683 (L'.ECase ((L'.ERel 0, loc),
|
adamc@676
|
1684 [((L'.PNone t, loc),
|
adamc@676
|
1685 (L'.EPrim (Prim.String "NULL"), loc)),
|
adamc@676
|
1686 ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc),
|
adamc@676
|
1687 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))],
|
adamc@676
|
1688 {disc = (L'.TOption t, loc),
|
adamc@676
|
1689 result = s}), loc)), loc)), loc),
|
adamc@676
|
1690 fm)
|
adamc@676
|
1691 end
|
adamc@253
|
1692
|
adamc@252
|
1693 | L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) =>
|
adamc@252
|
1694 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1695 | L.ECApp ((L.EFfi ("Basis", "sql_subset_all"), _), _) =>
|
adamc@252
|
1696 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1697
|
adamc@252
|
1698 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_order_by_Nil"), _), _), _), _) =>
|
adamc@252
|
1699 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@261
|
1700 | L.ECApp (
|
adamc@261
|
1701 (L.ECApp (
|
adamc@261
|
1702 (L.ECApp (
|
adamc@261
|
1703 (L.EFfi ("Basis", "sql_order_by_Cons"), _),
|
adamc@261
|
1704 _), _),
|
adamc@261
|
1705 _), _),
|
adamc@261
|
1706 _) =>
|
adamc@261
|
1707 let
|
adamc@261
|
1708 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@261
|
1709 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@261
|
1710 in
|
adamc@268
|
1711 ((L'.EAbs ("e1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@268
|
1712 (L'.EAbs ("d", s, (L'.TFun (s, s), loc),
|
adamc@268
|
1713 (L'.EAbs ("e2", s, s,
|
adamc@268
|
1714 (L'.ECase ((L'.ERel 0, loc),
|
adamc@268
|
1715 [((L'.PPrim (Prim.String ""), loc),
|
adamc@598
|
1716 strcat [(L'.ERel 2, loc),
|
adamc@598
|
1717 (L'.ERel 1, loc)]),
|
adamc@268
|
1718 ((L'.PWild, loc),
|
adamc@598
|
1719 strcat [(L'.ERel 2, loc),
|
adamc@598
|
1720 (L'.ERel 1, loc),
|
adamc@598
|
1721 sc ", ",
|
adamc@598
|
1722 (L'.ERel 0, loc)])],
|
adamc@268
|
1723 {disc = s, result = s}), loc)), loc)), loc)), loc),
|
adamc@261
|
1724 fm)
|
adamc@261
|
1725 end
|
adamc@252
|
1726
|
adamc@252
|
1727 | L.EFfi ("Basis", "sql_no_limit") =>
|
adamc@252
|
1728 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@262
|
1729 | L.EFfiApp ("Basis", "sql_limit", [e]) =>
|
adamc@262
|
1730 let
|
adamc@262
|
1731 val (e, fm) = monoExp (env, st, fm) e
|
adamc@262
|
1732 in
|
adamc@598
|
1733 (strcat [
|
adamc@262
|
1734 (L'.EPrim (Prim.String " LIMIT "), loc),
|
adamc@262
|
1735 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@262
|
1736 ],
|
adamc@262
|
1737 fm)
|
adamc@262
|
1738 end
|
adamc@262
|
1739
|
adamc@252
|
1740 | L.EFfi ("Basis", "sql_no_offset") =>
|
adamc@252
|
1741 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@263
|
1742 | L.EFfiApp ("Basis", "sql_offset", [e]) =>
|
adamc@263
|
1743 let
|
adamc@263
|
1744 val (e, fm) = monoExp (env, st, fm) e
|
adamc@263
|
1745 in
|
adamc@598
|
1746 (strcat [
|
adamc@263
|
1747 (L'.EPrim (Prim.String " OFFSET "), loc),
|
adamc@263
|
1748 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@263
|
1749 ],
|
adamc@263
|
1750 fm)
|
adamc@263
|
1751 end
|
adamc@253
|
1752
|
adamc@559
|
1753 | L.ECApp ((L.EFfi ("Basis", "sql_eq"), _), _) =>
|
adamc@253
|
1754 ((L'.EPrim (Prim.String "="), loc), fm)
|
adamc@559
|
1755 | L.ECApp ((L.EFfi ("Basis", "sql_ne"), _), _) =>
|
adamc@253
|
1756 ((L'.EPrim (Prim.String "<>"), loc), fm)
|
adamc@559
|
1757 | L.ECApp ((L.EFfi ("Basis", "sql_lt"), _), _) =>
|
adamc@253
|
1758 ((L'.EPrim (Prim.String "<"), loc), fm)
|
adamc@559
|
1759 | L.ECApp ((L.EFfi ("Basis", "sql_le"), _), _) =>
|
adamc@253
|
1760 ((L'.EPrim (Prim.String "<="), loc), fm)
|
adamc@559
|
1761 | L.ECApp ((L.EFfi ("Basis", "sql_gt"), _), _) =>
|
adamc@253
|
1762 ((L'.EPrim (Prim.String ">"), loc), fm)
|
adamc@559
|
1763 | L.ECApp ((L.EFfi ("Basis", "sql_ge"), _), _) =>
|
adamc@253
|
1764 ((L'.EPrim (Prim.String ">="), loc), fm)
|
adamc@253
|
1765
|
adamc@559
|
1766 | L.ECApp ((L.EFfi ("Basis", "sql_plus"), _), _) =>
|
adamc@559
|
1767 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1768 (L'.EPrim (Prim.String "+"), loc)), loc), fm)
|
adamc@559
|
1769 | L.ECApp ((L.EFfi ("Basis", "sql_minus"), _), _) =>
|
adamc@559
|
1770 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1771 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@559
|
1772 | L.ECApp ((L.EFfi ("Basis", "sql_times"), _), _) =>
|
adamc@559
|
1773 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1774 (L'.EPrim (Prim.String "*"), loc)), loc), fm)
|
adamc@559
|
1775 | L.ECApp ((L.EFfi ("Basis", "sql_div"), _), _) =>
|
adamc@559
|
1776 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1777 (L'.EPrim (Prim.String "/"), loc)), loc), fm)
|
adamc@559
|
1778 | L.EFfi ("Basis", "sql_mod") =>
|
adamc@559
|
1779 ((L'.EPrim (Prim.String "%"), loc), fm)
|
adamc@559
|
1780
|
adamc@253
|
1781 | L.ECApp (
|
adamc@253
|
1782 (L.ECApp (
|
adamc@253
|
1783 (L.ECApp (
|
adamc@253
|
1784 (L.ECApp (
|
adamc@254
|
1785 (L.ECApp (
|
adamc@264
|
1786 (L.EFfi ("Basis", "sql_unary"), _),
|
adamc@264
|
1787 _), _),
|
adamc@264
|
1788 _), _),
|
adamc@264
|
1789 _), _),
|
adamc@264
|
1790 _), _),
|
adamc@264
|
1791 _) =>
|
adamc@264
|
1792 let
|
adamc@264
|
1793 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@264
|
1794 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@264
|
1795 in
|
adamc@264
|
1796 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@264
|
1797 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@598
|
1798 strcat [sc "(",
|
adamc@598
|
1799 (L'.ERel 1, loc),
|
adamc@598
|
1800 sc " ",
|
adamc@598
|
1801 (L'.ERel 0, loc),
|
adamc@598
|
1802 sc ")"]), loc)), loc),
|
adamc@264
|
1803 fm)
|
adamc@264
|
1804 end
|
adamc@264
|
1805 | L.EFfi ("Basis", "sql_not") => ((L'.EPrim (Prim.String "NOT"), loc), fm)
|
adamc@559
|
1806 | L.ECApp ((L.EFfi ("Basis", "sql_neg"), _), _) =>
|
adamc@559
|
1807 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1808 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@264
|
1809
|
adamc@264
|
1810 | L.ECApp (
|
adamc@264
|
1811 (L.ECApp (
|
adamc@264
|
1812 (L.ECApp (
|
adamc@264
|
1813 (L.ECApp (
|
adamc@264
|
1814 (L.ECApp (
|
adamc@254
|
1815 (L.ECApp (
|
adamc@254
|
1816 (L.EFfi ("Basis", "sql_binary"), _),
|
adamc@254
|
1817 _), _),
|
adamc@254
|
1818 _), _),
|
adamc@254
|
1819 _), _),
|
adamc@254
|
1820 _), _),
|
adamc@254
|
1821 _), _),
|
adamc@254
|
1822 _) =>
|
adamc@254
|
1823 let
|
adamc@254
|
1824 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@254
|
1825 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@254
|
1826 in
|
adamc@254
|
1827 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@254
|
1828 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@254
|
1829 (L'.EAbs ("e2", s, s,
|
adamc@598
|
1830 strcat [sc "(",
|
adamc@598
|
1831 (L'.ERel 1, loc),
|
adamc@598
|
1832 sc " ",
|
adamc@598
|
1833 (L'.ERel 2, loc),
|
adamc@598
|
1834 sc " ",
|
adamc@598
|
1835 (L'.ERel 0, loc),
|
adamc@598
|
1836 sc ")"]), loc)), loc)), loc),
|
adamc@254
|
1837 fm)
|
adamc@254
|
1838 end
|
adamc@254
|
1839 | L.EFfi ("Basis", "sql_and") => ((L'.EPrim (Prim.String "AND"), loc), fm)
|
adamc@254
|
1840 | L.EFfi ("Basis", "sql_or") => ((L'.EPrim (Prim.String "OR"), loc), fm)
|
adamc@254
|
1841
|
adamc@254
|
1842 | L.ECApp (
|
adamc@254
|
1843 (L.ECApp (
|
adamc@254
|
1844 (L.ECApp (
|
adamc@254
|
1845 (L.ECApp (
|
adamc@253
|
1846 (L.ECApp (
|
adamc@253
|
1847 (L.ECApp (
|
adamc@253
|
1848 (L.ECApp (
|
adamc@253
|
1849 (L.EFfi ("Basis", "sql_field"), _),
|
adamc@253
|
1850 _), _),
|
adamc@253
|
1851 _), _),
|
adamc@253
|
1852 _), _),
|
adamc@253
|
1853 _), _),
|
adamc@253
|
1854 _), _),
|
adamc@253
|
1855 (L.CName tab, _)), _),
|
adamc@311
|
1856 (L.CName field, _)) => ((L'.EPrim (Prim.String (tab ^ ".uw_" ^ field)), loc), fm)
|
adamc@260
|
1857
|
adamc@260
|
1858 | L.ECApp (
|
adamc@260
|
1859 (L.ECApp (
|
adamc@260
|
1860 (L.ECApp (
|
adamc@260
|
1861 (L.ECApp (
|
adamc@261
|
1862 (L.ECApp (
|
adamc@261
|
1863 (L.EFfi ("Basis", "sql_exp"), _),
|
adamc@261
|
1864 _), _),
|
adamc@261
|
1865 _), _),
|
adamc@261
|
1866 _), _),
|
adamc@261
|
1867 _), _),
|
adamc@261
|
1868 (L.CName nm, _)) => ((L'.EPrim (Prim.String ("_" ^ nm)), loc), fm)
|
adamc@261
|
1869
|
adamc@261
|
1870 | L.ECApp (
|
adamc@261
|
1871 (L.ECApp (
|
adamc@261
|
1872 (L.ECApp (
|
adamc@261
|
1873 (L.ECApp (
|
adamc@260
|
1874 (L.EFfi ("Basis", "sql_relop"), _),
|
adamc@260
|
1875 _), _),
|
adamc@260
|
1876 _), _),
|
adamc@260
|
1877 _), _),
|
adamc@260
|
1878 _) =>
|
adamc@260
|
1879 let
|
adamc@260
|
1880 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@260
|
1881 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@260
|
1882 in
|
adamc@260
|
1883 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@260
|
1884 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@260
|
1885 (L'.EAbs ("e2", s, s,
|
adamc@598
|
1886 strcat [sc "((",
|
adamc@598
|
1887 (L'.ERel 1, loc),
|
adamc@598
|
1888 sc ") ",
|
adamc@598
|
1889 (L'.ERel 2, loc),
|
adamc@598
|
1890 sc " (",
|
adamc@598
|
1891 (L'.ERel 0, loc),
|
adamc@598
|
1892 sc "))"]), loc)), loc)), loc),
|
adamc@260
|
1893 fm)
|
adamc@260
|
1894 end
|
adamc@260
|
1895
|
adamc@260
|
1896 | L.EFfi ("Basis", "sql_union") => ((L'.EPrim (Prim.String "UNION"), loc), fm)
|
adamc@260
|
1897 | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm)
|
adamc@260
|
1898 | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)
|
adamc@260
|
1899
|
adamc@265
|
1900 | L.ECApp (
|
adamc@265
|
1901 (L.ECApp (
|
adamc@265
|
1902 (L.ECApp (
|
adamc@265
|
1903 (L.EFfi ("Basis", "sql_count"), _),
|
adamc@265
|
1904 _), _),
|
adamc@265
|
1905 _), _),
|
adamc@544
|
1906 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc),
|
adamc@265
|
1907 fm)
|
adamc@266
|
1908
|
adamc@266
|
1909 | L.ECApp (
|
adamc@266
|
1910 (L.ECApp (
|
adamc@266
|
1911 (L.ECApp (
|
adamc@266
|
1912 (L.ECApp (
|
adamc@266
|
1913 (L.EFfi ("Basis", "sql_aggregate"), _),
|
adamc@266
|
1914 _), _),
|
adamc@266
|
1915 _), _),
|
adamc@266
|
1916 _), _),
|
adamc@266
|
1917 _) =>
|
adamc@266
|
1918 let
|
adamc@266
|
1919 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@266
|
1920 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@266
|
1921 in
|
adamc@266
|
1922 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@266
|
1923 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@598
|
1924 strcat [(L'.ERel 1, loc),
|
adamc@598
|
1925 sc "(",
|
adamc@598
|
1926 (L'.ERel 0, loc),
|
adamc@598
|
1927 sc ")"]), loc)), loc),
|
adamc@266
|
1928 fm)
|
adamc@266
|
1929 end
|
adamc@266
|
1930
|
adamc@266
|
1931 | L.EFfi ("Basis", "sql_summable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1932 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1933 | L.ECApp ((L.EFfi ("Basis", "sql_avg"), _), _) =>
|
adamc@266
|
1934 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1935 (L'.EPrim (Prim.String "AVG"), loc)), loc),
|
adamc@266
|
1936 fm)
|
adamc@266
|
1937 | L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _) =>
|
adamc@266
|
1938 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1939 (L'.EPrim (Prim.String "SUM"), loc)), loc),
|
adamc@266
|
1940 fm)
|
adamc@266
|
1941
|
adamc@559
|
1942 | L.EFfi ("Basis", "sql_arith_int") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
1943 | L.EFfi ("Basis", "sql_arith_float") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
1944
|
adamc@266
|
1945 | L.EFfi ("Basis", "sql_maxable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1946 | L.EFfi ("Basis", "sql_maxable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1947 | L.EFfi ("Basis", "sql_maxable_string") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1948 | L.ECApp ((L.EFfi ("Basis", "sql_max"), _), _) =>
|
adamc@266
|
1949 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1950 (L'.EPrim (Prim.String "MAX"), loc)), loc),
|
adamc@266
|
1951 fm)
|
adamc@266
|
1952 | L.ECApp ((L.EFfi ("Basis", "sql_min"), _), _) =>
|
adamc@266
|
1953 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1954 (L'.EPrim (Prim.String "MIN"), loc)), loc),
|
adamc@266
|
1955 fm)
|
adamc@266
|
1956
|
adamc@268
|
1957 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@268
|
1958 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
|
adamc@268
|
1959
|
adamc@441
|
1960 | L.ECApp (
|
adamc@441
|
1961 (L.ECApp (
|
adamc@441
|
1962 (L.ECApp (
|
adamc@441
|
1963 (L.ECApp (
|
adamc@441
|
1964 (L.EFfi ("Basis", "sql_nfunc"), _),
|
adamc@441
|
1965 _), _),
|
adamc@441
|
1966 _), _),
|
adamc@441
|
1967 _), _),
|
adamc@441
|
1968 _) =>
|
adamc@441
|
1969 let
|
adamc@441
|
1970 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@441
|
1971 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@441
|
1972 in
|
adamc@441
|
1973 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc),
|
adamc@441
|
1974 fm)
|
adamc@441
|
1975 end
|
adamc@441
|
1976 | L.EFfi ("Basis", "sql_current_timestamp") => ((L'.EPrim (Prim.String "CURRENT_TIMESTAMP"), loc), fm)
|
adamc@441
|
1977
|
adamc@470
|
1978 | (L.ECApp (
|
adamc@470
|
1979 (L.ECApp (
|
adamc@470
|
1980 (L.ECApp (
|
adamc@470
|
1981 (L.ECApp (
|
adamc@470
|
1982 (L.EFfi ("Basis", "sql_is_null"), _), _),
|
adamc@470
|
1983 _), _),
|
adamc@470
|
1984 _), _),
|
adamc@470
|
1985 _), _)) =>
|
adamc@470
|
1986 let
|
adamc@470
|
1987 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@470
|
1988 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@470
|
1989 in
|
adamc@470
|
1990 ((L'.EAbs ("s", s, s,
|
adamc@598
|
1991 strcat [sc "(",
|
adamc@598
|
1992 (L'.ERel 0, loc),
|
adamc@598
|
1993 sc " IS NULL)"]), loc),
|
adamc@470
|
1994 fm)
|
adamc@470
|
1995 end
|
adamc@470
|
1996
|
adamc@338
|
1997 | L.EFfiApp ("Basis", "nextval", [e]) =>
|
adamc@338
|
1998 let
|
adamc@338
|
1999 val (e, fm) = monoExp (env, st, fm) e
|
adamc@338
|
2000 in
|
adamc@465
|
2001 ((L'.ENextval e, loc), fm)
|
adamc@338
|
2002 end
|
adamc@338
|
2003
|
adamc@139
|
2004 | L.EApp (
|
adamc@139
|
2005 (L.ECApp (
|
adamc@720
|
2006 (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _),
|
adamc@139
|
2007 _), _),
|
adamc@179
|
2008 se) =>
|
adamc@179
|
2009 let
|
adamc@179
|
2010 val (se, fm) = monoExp (env, st, fm) se
|
adamc@179
|
2011 in
|
adamc@179
|
2012 ((L'.EFfiApp ("Basis", "htmlifyString", [se]), loc), fm)
|
adamc@179
|
2013 end
|
adamc@179
|
2014
|
adamc@95
|
2015 | L.EApp (
|
adamc@95
|
2016 (L.EApp (
|
adamc@720
|
2017 (L.ECApp (
|
adamc@720
|
2018 (L.ECApp (
|
adamc@95
|
2019 (L.ECApp (
|
adamc@139
|
2020 (L.ECApp (
|
adamc@720
|
2021 (L.EFfi ("Basis", "join"),
|
adamc@720
|
2022 _), _), _),
|
adamc@139
|
2023 _), _),
|
adamc@720
|
2024 _), _),
|
adamc@720
|
2025 _), _),
|
adamc@720
|
2026 xml1), _),
|
adamc@720
|
2027 xml2) =>
|
adamc@179
|
2028 let
|
adamc@179
|
2029 val (xml1, fm) = monoExp (env, st, fm) xml1
|
adamc@179
|
2030 val (xml2, fm) = monoExp (env, st, fm) xml2
|
adamc@179
|
2031 in
|
adamc@179
|
2032 ((L'.EStrcat (xml1, xml2), loc), fm)
|
adamc@179
|
2033 end
|
adamc@95
|
2034
|
adamc@95
|
2035 | L.EApp (
|
adamc@95
|
2036 (L.EApp (
|
adamc@104
|
2037 (L.EApp (
|
adamc@720
|
2038 (L.ECApp (
|
adamc@720
|
2039 (L.ECApp (
|
adamc@104
|
2040 (L.ECApp (
|
adamc@104
|
2041 (L.ECApp (
|
adamc@139
|
2042 (L.ECApp (
|
adamc@139
|
2043 (L.ECApp (
|
adamc@139
|
2044 (L.ECApp (
|
adamc@139
|
2045 (L.ECApp (
|
adamc@720
|
2046 (L.EFfi ("Basis", "tag"),
|
adamc@720
|
2047 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@720
|
2048 attrs), _),
|
adamc@720
|
2049 tag), _),
|
adamc@95
|
2050 xml) =>
|
adamc@95
|
2051 let
|
adamc@140
|
2052 fun getTag' (e, _) =
|
adamc@140
|
2053 case e of
|
adamc@143
|
2054 L.EFfi ("Basis", tag) => (tag, [])
|
adamc@143
|
2055 | L.ECApp (e, t) => let
|
adamc@143
|
2056 val (tag, ts) = getTag' e
|
adamc@143
|
2057 in
|
adamc@143
|
2058 (tag, ts @ [t])
|
adamc@143
|
2059 end
|
adamc@140
|
2060 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@140
|
2061 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
2062 ("", []))
|
adamc@140
|
2063
|
adamc@95
|
2064 fun getTag (e, _) =
|
adamc@95
|
2065 case e of
|
adamc@143
|
2066 L.EFfiApp ("Basis", tag, [(L.ERecord [], _)]) => (tag, [])
|
adamc@140
|
2067 | L.EApp (e, (L.ERecord [], _)) => getTag' e
|
adamc@95
|
2068 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@95
|
2069 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
2070 ("", []))
|
adamc@95
|
2071
|
adamc@143
|
2072 val (tag, targs) = getTag tag
|
adamc@95
|
2073
|
adamc@179
|
2074 val (attrs, fm) = monoExp (env, st, fm) attrs
|
adamc@598
|
2075 val attrs = case #1 attrs of
|
adamc@598
|
2076 L'.ERecord xes => xes
|
adamc@598
|
2077 | _ => raise Fail "Non-record attributes!"
|
adamc@104
|
2078
|
adamc@717
|
2079 val attrs =
|
adamc@717
|
2080 if List.exists (fn ("Link", _, _) => true
|
adamc@717
|
2081 | _ => false) attrs then
|
adamc@717
|
2082 List.filter (fn ("Href", _, _) => false
|
adamc@717
|
2083 | _ => true) attrs
|
adamc@717
|
2084 else
|
adamc@717
|
2085 attrs
|
adamc@717
|
2086
|
adamc@668
|
2087 fun findOnload (attrs, acc) =
|
adamc@668
|
2088 case attrs of
|
adamc@668
|
2089 [] => (NONE, acc)
|
adamc@668
|
2090 | ("Onload", e, _) :: rest => (SOME e, List.revAppend (acc, rest))
|
adamc@668
|
2091 | x :: rest => findOnload (rest, x :: acc)
|
adamc@679
|
2092
|
adamc@668
|
2093 val (onload, attrs) = findOnload (attrs, [])
|
adamc@668
|
2094
|
adamc@606
|
2095 fun lowercaseFirst "" = ""
|
adamc@606
|
2096 | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0)))
|
adamc@606
|
2097 ^ String.extract (s, 1, NONE)
|
adamc@606
|
2098
|
adamc@143
|
2099 fun tagStart tag =
|
adamc@598
|
2100 let
|
adamc@598
|
2101 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@598
|
2102 in
|
adamc@598
|
2103 foldl (fn (("Action", _, _), acc) => acc
|
adamc@598
|
2104 | (("Source", _, _), acc) => acc
|
adamc@598
|
2105 | ((x, e, t), (s, fm)) =>
|
adamc@598
|
2106 case t of
|
adamc@598
|
2107 (L'.TFfi ("Basis", "bool"), _) =>
|
adamc@598
|
2108 let
|
adamc@598
|
2109 val s' = " " ^ lowercaseFirst x
|
adamc@598
|
2110 in
|
adamc@598
|
2111 ((L'.ECase (e,
|
adamc@598
|
2112 [((L'.PCon (L'.Enum,
|
adamc@598
|
2113 L'.PConFfi {mod = "Basis",
|
adamc@598
|
2114 datatyp = "bool",
|
adamc@598
|
2115 con = "True",
|
adamc@598
|
2116 arg = NONE},
|
adamc@598
|
2117 NONE), loc),
|
adamc@598
|
2118 (L'.EStrcat (s,
|
adamc@598
|
2119 (L'.EPrim (Prim.String s'), loc)), loc)),
|
adamc@598
|
2120 ((L'.PCon (L'.Enum,
|
adamc@598
|
2121 L'.PConFfi {mod = "Basis",
|
adamc@598
|
2122 datatyp = "bool",
|
adamc@598
|
2123 con = "False",
|
adamc@598
|
2124 arg = NONE},
|
adamc@598
|
2125 NONE), loc),
|
adamc@598
|
2126 s)],
|
adamc@598
|
2127 {disc = (L'.TFfi ("Basis", "bool"), loc),
|
adamc@598
|
2128 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@598
|
2129 fm)
|
adamc@598
|
2130 end
|
adamc@598
|
2131 | (L'.TFun _, _) =>
|
adamc@598
|
2132 let
|
adamc@598
|
2133 val s' = " " ^ lowercaseFirst x ^ "='"
|
adamc@651
|
2134 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
|
adamc@598
|
2135 in
|
adamc@598
|
2136 ((L'.EStrcat (s,
|
adamc@598
|
2137 (L'.EStrcat (
|
adamc@598
|
2138 (L'.EPrim (Prim.String s'), loc),
|
adamc@598
|
2139 (L'.EStrcat (
|
adamc@598
|
2140 (L'.EJavaScript (L'.Attribute, e, NONE), loc),
|
adamc@598
|
2141 (L'.EPrim (Prim.String "'"), loc)), loc)),
|
adamc@598
|
2142 loc)), loc),
|
adamc@598
|
2143 fm)
|
adamc@598
|
2144 end
|
adamc@598
|
2145 | _ =>
|
adamc@598
|
2146 let
|
adamc@598
|
2147 val fooify =
|
adamc@598
|
2148 case x of
|
adamc@717
|
2149 "Link" => urlifyExp
|
adamc@717
|
2150 | "Action" => urlifyExp
|
adamc@598
|
2151 | _ => attrifyExp
|
adamc@120
|
2152
|
adamc@598
|
2153 val xp = " " ^ lowercaseFirst x ^ "=\""
|
adamc@179
|
2154
|
adamc@598
|
2155 val (e, fm) = fooify env fm (e, t)
|
adamc@598
|
2156 in
|
adamc@598
|
2157 ((L'.EStrcat (s,
|
adamc@598
|
2158 (L'.EStrcat ((L'.EPrim (Prim.String xp), loc),
|
adamc@598
|
2159 (L'.EStrcat (e,
|
adamc@598
|
2160 (L'.EPrim (Prim.String "\""),
|
adamc@598
|
2161 loc)),
|
adamc@598
|
2162 loc)),
|
adamc@598
|
2163 loc)), loc),
|
adamc@598
|
2164 fm)
|
adamc@598
|
2165 end)
|
adamc@598
|
2166 (s, fm) attrs
|
adamc@598
|
2167 end
|
adamc@104
|
2168
|
adamc@143
|
2169 fun input typ =
|
adamc@143
|
2170 case targs of
|
adamc@155
|
2171 [_, (L.CName name, _)] =>
|
adamc@179
|
2172 let
|
adamc@179
|
2173 val (ts, fm) = tagStart "input"
|
adamc@179
|
2174 in
|
adamc@179
|
2175 ((L'.EStrcat (ts,
|
adamc@179
|
2176 (L'.EPrim (Prim.String (" type=\"" ^ typ ^ "\" name=\"" ^ name ^ "\"/>")),
|
adamc@179
|
2177 loc)), loc), fm)
|
adamc@179
|
2178 end
|
adamc@143
|
2179 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
2180 raise Fail "No name passed to input tag")
|
adamc@104
|
2181
|
adamc@565
|
2182 fun normal (tag, extra, extraInner) =
|
adamc@143
|
2183 let
|
adamc@179
|
2184 val (tagStart, fm) = tagStart tag
|
adamc@152
|
2185 val tagStart = case extra of
|
adamc@152
|
2186 NONE => tagStart
|
adamc@152
|
2187 | SOME extra => (L'.EStrcat (tagStart, extra), loc)
|
adamc@152
|
2188
|
adamc@695
|
2189 val xml = case extraInner of
|
adamc@695
|
2190 NONE => xml
|
adamc@695
|
2191 | SOME ei => (L.EFfiApp ("Basis", "strcat", [ei, xml]), loc)
|
adamc@695
|
2192
|
adamc@143
|
2193 fun normal () =
|
adamc@179
|
2194 let
|
adamc@179
|
2195 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
2196 in
|
adamc@179
|
2197 ((L'.EStrcat ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String ">"), loc)), loc),
|
adamc@179
|
2198 (L'.EStrcat (xml,
|
adamc@179
|
2199 (L'.EPrim (Prim.String (String.concat ["</", tag, ">"])),
|
adamc@179
|
2200 loc)), loc)),
|
adamc@179
|
2201 loc),
|
adamc@179
|
2202 fm)
|
adamc@179
|
2203 end
|
adamc@143
|
2204 in
|
adamc@143
|
2205 case xml of
|
adamc@143
|
2206 (L.EApp ((L.ECApp (
|
adamc@143
|
2207 (L.ECApp ((L.EFfi ("Basis", "cdata"), _),
|
adamc@143
|
2208 _), _),
|
adamc@143
|
2209 _), _),
|
adamc@143
|
2210 (L.EPrim (Prim.String s), _)), _) =>
|
adamc@143
|
2211 if CharVector.all Char.isSpace s then
|
adamc@179
|
2212 ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String "/>"), loc)), loc), fm)
|
adamc@143
|
2213 else
|
adamc@143
|
2214 normal ()
|
adamc@143
|
2215 | _ => normal ()
|
adamc@143
|
2216 end
|
adamc@606
|
2217
|
adamc@606
|
2218 fun setAttrs jexp =
|
adamc@606
|
2219 let
|
adamc@606
|
2220 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@606
|
2221
|
adamc@606
|
2222 val assgns = List.mapPartial
|
adamc@606
|
2223 (fn ("Source", _, _) => NONE
|
adamc@606
|
2224 | (x, e, _) =>
|
adamc@606
|
2225 SOME (strcat [str ("d." ^ lowercaseFirst x ^ "="),
|
adamc@606
|
2226 (L'.EJavaScript (L'.Script, e, NONE), loc),
|
adamc@606
|
2227 str ";"]))
|
adamc@606
|
2228 attrs
|
adamc@606
|
2229 in
|
adamc@606
|
2230 case assgns of
|
adamc@606
|
2231 [] => jexp
|
adamc@606
|
2232 | _ => strcat (str "var d="
|
adamc@606
|
2233 :: jexp
|
adamc@606
|
2234 :: str ";"
|
adamc@606
|
2235 :: assgns)
|
adamc@606
|
2236 end
|
adamc@152
|
2237 in
|
adamc@152
|
2238 case tag of
|
adamc@679
|
2239 "body" => let
|
adamc@668
|
2240 val onload = case onload of
|
adamc@668
|
2241 NONE => (L'.EPrim (Prim.String ""), loc)
|
adamc@668
|
2242 | SOME e =>
|
adamc@668
|
2243 let
|
adamc@668
|
2244 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
|
adamc@668
|
2245 in
|
adamc@668
|
2246 (L'.EJavaScript (L'.Attribute, e, NONE), loc)
|
adamc@679
|
2247 end
|
adamc@668
|
2248 in
|
adamc@668
|
2249 normal ("body",
|
adamc@695
|
2250 SOME (L'.EFfiApp ("Basis", "maybe_onload",
|
adamc@695
|
2251 [(L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings",
|
adamc@695
|
2252 [(L'.ERecord [], loc)]), loc),
|
adamc@695
|
2253 onload), loc)]),
|
adamc@695
|
2254 loc),
|
adamc@695
|
2255 SOME (L.EFfiApp ("Basis", "get_script", [(L.ERecord [], loc)]), loc))
|
adamc@668
|
2256 end
|
adamc@568
|
2257
|
adamc@568
|
2258 | "dyn" =>
|
adamc@598
|
2259 (case attrs of
|
adamc@598
|
2260 [("Signal", (L'.EApp ((L'.EAbs (_, _, _, (L'.ESignalReturn (L'.ERel 0, _), _)), _),
|
adamc@598
|
2261 e), _), _)] => (e, fm)
|
adamc@598
|
2262 | [("Signal", e, _)] =>
|
adamc@568
|
2263 ((L'.EStrcat
|
adamc@603
|
2264 ((L'.EPrim (Prim.String "<span><script type=\"text/javascript\">dyn("), loc),
|
adamc@578
|
2265 (L'.EStrcat ((L'.EJavaScript (L'.Script, e, NONE), loc),
|
adamc@603
|
2266 (L'.EPrim (Prim.String ")</script></span>"), loc)), loc)), loc),
|
adamc@568
|
2267 fm)
|
adamc@568
|
2268 | _ => raise Fail "Monoize: Bad dyn attributes")
|
adamc@565
|
2269
|
adamc@565
|
2270 | "submit" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@601
|
2271 | "button" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@152
|
2272
|
adamc@152
|
2273 | "textbox" =>
|
adamc@152
|
2274 (case targs of
|
adamc@152
|
2275 [_, (L.CName name, _)] =>
|
adamc@598
|
2276 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@598
|
2277 NONE =>
|
adamc@598
|
2278 let
|
adamc@598
|
2279 val (ts, fm) = tagStart "input"
|
adamc@598
|
2280 in
|
adamc@598
|
2281 ((L'.EStrcat (ts,
|
adamc@598
|
2282 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\"/>")),
|
adamc@598
|
2283 loc)), loc), fm)
|
adamc@598
|
2284 end
|
adamc@598
|
2285 | SOME (_, src, _) =>
|
adamc@646
|
2286 (strcat [str "<span><script type=\"text/javascript\">inp(\"input\",",
|
adamc@598
|
2287 (L'.EJavaScript (L'.Script, src, NONE), loc),
|
adamc@646
|
2288 str ")</script></span>"],
|
adamc@598
|
2289 fm))
|
adamc@152
|
2290 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@598
|
2291 raise Fail "No name passed to textbox tag"))
|
adamc@155
|
2292 | "password" => input "password"
|
adamc@361
|
2293 | "textarea" =>
|
adamc@152
|
2294 (case targs of
|
adamc@152
|
2295 [_, (L.CName name, _)] =>
|
adamc@179
|
2296 let
|
adamc@179
|
2297 val (ts, fm) = tagStart "textarea"
|
adamc@179
|
2298 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
2299 in
|
adamc@179
|
2300 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@179
|
2301 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")), loc)), loc),
|
adamc@179
|
2302 (L'.EStrcat (xml,
|
adamc@179
|
2303 (L'.EPrim (Prim.String "</textarea>"),
|
adamc@179
|
2304 loc)), loc)),
|
adamc@179
|
2305 loc), fm)
|
adamc@179
|
2306 end
|
adamc@152
|
2307 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
2308 raise Fail "No name passed to ltextarea tag"))
|
adamc@153
|
2309
|
adamc@190
|
2310 | "checkbox" => input "checkbox"
|
adamc@190
|
2311
|
adamc@153
|
2312 | "radio" =>
|
adamc@153
|
2313 (case targs of
|
adamc@153
|
2314 [_, (L.CName name, _)] =>
|
adamc@179
|
2315 monoExp (env, St.setRadioGroup (st, name), fm) xml
|
adamc@153
|
2316 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
2317 raise Fail "No name passed to radio tag"))
|
adamc@153
|
2318 | "radioOption" =>
|
adamc@153
|
2319 (case St.radioGroup st of
|
adamc@153
|
2320 NONE => raise Fail "No name for radioGroup"
|
adamc@153
|
2321 | SOME name =>
|
adamc@153
|
2322 normal ("input",
|
adamc@565
|
2323 SOME (L'.EPrim (Prim.String (" type=\"radio\" name=\"" ^ name ^ "\"")), loc),
|
adamc@565
|
2324 NONE))
|
adamc@152
|
2325
|
adamc@361
|
2326 | "select" =>
|
adamc@154
|
2327 (case targs of
|
adamc@154
|
2328 [_, (L.CName name, _)] =>
|
adamc@179
|
2329 let
|
adamc@179
|
2330 val (ts, fm) = tagStart "select"
|
adamc@179
|
2331 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
2332 in
|
adamc@179
|
2333 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@598
|
2334 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")),
|
adamc@598
|
2335 loc)), loc),
|
adamc@179
|
2336 (L'.EStrcat (xml,
|
adamc@179
|
2337 (L'.EPrim (Prim.String "</select>"),
|
adamc@179
|
2338 loc)), loc)),
|
adamc@179
|
2339 loc),
|
adamc@179
|
2340 fm)
|
adamc@179
|
2341 end
|
adamc@154
|
2342 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@154
|
2343 raise Fail "No name passed to lselect tag"))
|
adamc@154
|
2344
|
adamc@601
|
2345 | "ctextbox" =>
|
adamc@601
|
2346 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@601
|
2347 NONE =>
|
adamc@601
|
2348 let
|
adamc@601
|
2349 val (ts, fm) = tagStart "input"
|
adamc@601
|
2350 in
|
adamc@601
|
2351 ((L'.EStrcat (ts,
|
adamc@601
|
2352 (L'.EPrim (Prim.String "/>"), loc)),
|
adamc@601
|
2353 loc), fm)
|
adamc@601
|
2354 end
|
adamc@601
|
2355 | SOME (_, src, _) =>
|
adamc@606
|
2356 let
|
adamc@606
|
2357 val sc = strcat [str "inp(\"input\",",
|
adamc@606
|
2358 (L'.EJavaScript (L'.Script, src, NONE), loc),
|
adamc@606
|
2359 str ")"]
|
adamc@606
|
2360 val sc = setAttrs sc
|
adamc@606
|
2361 in
|
adamc@646
|
2362 (strcat [str "<span><script type=\"text/javascript\">",
|
adamc@606
|
2363 sc,
|
adamc@646
|
2364 str "</script></span>"],
|
adamc@606
|
2365 fm)
|
adamc@606
|
2366 end)
|
adamc@154
|
2367
|
adamc@565
|
2368 | "tabl" => normal ("table", NONE, NONE)
|
adamc@565
|
2369 | _ => normal (tag, NONE, NONE)
|
adamc@95
|
2370 end
|
adamc@94
|
2371
|
adamc@141
|
2372 | L.EApp ((L.ECApp (
|
adamc@361
|
2373 (L.ECApp ((L.EFfi ("Basis", "form"), _), _), _),
|
adamc@141
|
2374 _), _),
|
adamc@141
|
2375 xml) =>
|
adamc@143
|
2376 let
|
adamc@143
|
2377 fun findSubmit (e, _) =
|
adamc@143
|
2378 case e of
|
adamc@143
|
2379 L.EApp (
|
adamc@143
|
2380 (L.EApp (
|
adamc@143
|
2381 (L.ECApp (
|
adamc@143
|
2382 (L.ECApp (
|
adamc@143
|
2383 (L.ECApp (
|
adamc@143
|
2384 (L.ECApp (
|
adamc@143
|
2385 (L.EFfi ("Basis", "join"),
|
adamc@143
|
2386 _), _), _),
|
adamc@143
|
2387 _), _),
|
adamc@143
|
2388 _), _),
|
adamc@143
|
2389 _), _),
|
adamc@143
|
2390 xml1), _),
|
adamc@143
|
2391 xml2) => (case findSubmit xml1 of
|
adamc@143
|
2392 Error => Error
|
adamc@143
|
2393 | NotFound => findSubmit xml2
|
adamc@143
|
2394 | Found e =>
|
adamc@143
|
2395 case findSubmit xml2 of
|
adamc@143
|
2396 NotFound => Found e
|
adamc@143
|
2397 | _ => Error)
|
adamc@143
|
2398 | L.EApp (
|
adamc@143
|
2399 (L.EApp (
|
adamc@143
|
2400 (L.EApp (
|
adamc@143
|
2401 (L.ECApp (
|
adamc@143
|
2402 (L.ECApp (
|
adamc@143
|
2403 (L.ECApp (
|
adamc@143
|
2404 (L.ECApp (
|
adamc@143
|
2405 (L.ECApp (
|
adamc@143
|
2406 (L.ECApp (
|
adamc@143
|
2407 (L.ECApp (
|
adamc@143
|
2408 (L.ECApp (
|
adamc@143
|
2409 (L.EFfi ("Basis", "tag"),
|
adamc@143
|
2410 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@143
|
2411 attrs), _),
|
adamc@143
|
2412 _), _),
|
adamc@143
|
2413 xml) =>
|
adamc@143
|
2414 (case #1 attrs of
|
adamc@143
|
2415 L.ERecord xes =>
|
adamc@143
|
2416 (case ListUtil.search (fn ((L.CName "Action", _), e, t) => SOME (e, t)
|
adamc@143
|
2417 | _ => NONE) xes of
|
adamc@143
|
2418 NONE => findSubmit xml
|
adamc@143
|
2419 | SOME et =>
|
adamc@143
|
2420 case findSubmit xml of
|
adamc@143
|
2421 NotFound => Found et
|
adamc@143
|
2422 | _ => Error)
|
adamc@143
|
2423 | _ => findSubmit xml)
|
adamc@143
|
2424 | _ => NotFound
|
adamc@143
|
2425
|
adamc@598
|
2426 val (action, fm) = case findSubmit xml of
|
adamc@598
|
2427 NotFound => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@143
|
2428 | Error => raise Fail "Not ready for multi-submit lforms yet"
|
adamc@598
|
2429 | Found (action, actionT) =>
|
adamc@598
|
2430 let
|
adamc@598
|
2431 val actionT = monoType env actionT
|
adamc@598
|
2432 val (action, fm) = monoExp (env, st, fm) action
|
adamc@598
|
2433 val (action, fm) = urlifyExp env fm (action, actionT)
|
adamc@598
|
2434 in
|
adamc@598
|
2435 ((L'.EStrcat ((L'.EPrim (Prim.String " action=\""), loc),
|
adamc@598
|
2436 (L'.EStrcat (action,
|
adamc@598
|
2437 (L'.EPrim (Prim.String "\""), loc)), loc)), loc),
|
adamc@598
|
2438 fm)
|
adamc@598
|
2439 end
|
adamc@598
|
2440
|
adamc@179
|
2441 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@143
|
2442 in
|
adamc@598
|
2443 ((L'.EStrcat ((L'.EStrcat ((L'.EPrim (Prim.String "<form"), loc),
|
adamc@179
|
2444 (L'.EStrcat (action,
|
adamc@598
|
2445 (L'.EPrim (Prim.String ">"), loc)), loc)), loc),
|
adamc@179
|
2446 (L'.EStrcat (xml,
|
adamc@179
|
2447 (L'.EPrim (Prim.String "</form>"), loc)), loc)), loc),
|
adamc@179
|
2448 fm)
|
adamc@143
|
2449 end
|
adamc@141
|
2450
|
adamc@148
|
2451 | L.EApp ((L.ECApp (
|
adamc@148
|
2452 (L.ECApp (
|
adamc@148
|
2453 (L.ECApp (
|
adamc@148
|
2454 (L.ECApp (
|
adamc@148
|
2455 (L.EFfi ("Basis", "useMore"), _), _), _),
|
adamc@148
|
2456 _), _),
|
adamc@148
|
2457 _), _),
|
adamc@148
|
2458 _), _),
|
adamc@179
|
2459 xml) => monoExp (env, st, fm) xml
|
adamc@148
|
2460
|
adamc@283
|
2461 | L.ECApp ((L.EFfi ("Basis", "error"), _), t) =>
|
adamc@283
|
2462 let
|
adamc@283
|
2463 val t = monoType env t
|
adamc@283
|
2464 in
|
adamc@283
|
2465 ((L'.EAbs ("s", (L'.TFfi ("Basis", "string"), loc), t,
|
adamc@283
|
2466 (L'.EError ((L'.ERel 0, loc), t), loc)), loc),
|
adamc@283
|
2467 fm)
|
adamc@283
|
2468 end
|
adamc@283
|
2469
|
adamc@179
|
2470 | L.EApp (e1, e2) =>
|
adamc@179
|
2471 let
|
adamc@179
|
2472 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@179
|
2473 val (e2, fm) = monoExp (env, st, fm) e2
|
adamc@179
|
2474 in
|
adamc@179
|
2475 ((L'.EApp (e1, e2), loc), fm)
|
adamc@179
|
2476 end
|
adamc@26
|
2477 | L.EAbs (x, dom, ran, e) =>
|
adamc@179
|
2478 let
|
adamc@179
|
2479 val (e, fm) = monoExp (Env.pushERel env x dom, st, fm) e
|
adamc@179
|
2480 in
|
adamc@179
|
2481 ((L'.EAbs (x, monoType env dom, monoType env ran, e), loc), fm)
|
adamc@179
|
2482 end
|
adamc@25
|
2483 | L.ECApp _ => poly ()
|
adamc@25
|
2484 | L.ECAbs _ => poly ()
|
adamc@25
|
2485
|
adamc@252
|
2486 | L.EFfi mx => ((L'.EFfi mx, loc), fm)
|
adamc@252
|
2487 | L.EFfiApp (m, x, es) =>
|
adamc@252
|
2488 let
|
adamc@252
|
2489 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@252
|
2490 in
|
adamc@252
|
2491 ((L'.EFfiApp (m, x, es), loc), fm)
|
adamc@252
|
2492 end
|
adamc@252
|
2493
|
adamc@179
|
2494 | L.ERecord xes =>
|
adamc@179
|
2495 let
|
adamc@179
|
2496 val (xes, fm) = ListUtil.foldlMap
|
adamc@179
|
2497 (fn ((x, e, t), fm) =>
|
adamc@179
|
2498 let
|
adamc@179
|
2499 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2500 in
|
adamc@179
|
2501 ((monoName env x,
|
adamc@179
|
2502 e,
|
adamc@179
|
2503 monoType env t), fm)
|
adamc@179
|
2504 end) fm xes
|
adamc@179
|
2505 in
|
adamc@179
|
2506 ((L'.ERecord xes, loc), fm)
|
adamc@179
|
2507 end
|
adamc@179
|
2508 | L.EField (e, x, _) =>
|
adamc@179
|
2509 let
|
adamc@179
|
2510 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2511 in
|
adamc@179
|
2512 ((L'.EField (e, monoName env x), loc), fm)
|
adamc@179
|
2513 end
|
adamc@445
|
2514 | L.EConcat _ => poly ()
|
adamc@149
|
2515 | L.ECut _ => poly ()
|
adamc@493
|
2516 | L.ECutMulti _ => poly ()
|
adamc@177
|
2517
|
adamc@182
|
2518 | L.ECase (e, pes, {disc, result}) =>
|
adamc@179
|
2519 let
|
adamc@179
|
2520 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2521 val (pes, fm) = ListUtil.foldlMap
|
adamc@179
|
2522 (fn ((p, e), fm) =>
|
adamc@179
|
2523 let
|
adamc@179
|
2524 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2525 in
|
adamc@182
|
2526 ((monoPat env p, e), fm)
|
adamc@179
|
2527 end) fm pes
|
adamc@179
|
2528 in
|
adamc@182
|
2529 ((L'.ECase (e, pes, {disc = monoType env disc, result = monoType env result}), loc), fm)
|
adamc@179
|
2530 end
|
adamc@177
|
2531
|
adamc@179
|
2532 | L.EWrite e =>
|
adamc@179
|
2533 let
|
adamc@179
|
2534 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2535 in
|
adamc@252
|
2536 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@252
|
2537 (L'.EWrite (liftExpInExp 0 e), loc)), loc), fm)
|
adamc@179
|
2538 end
|
adamc@110
|
2539
|
adamc@179
|
2540 | L.EClosure (n, es) =>
|
adamc@179
|
2541 let
|
adamc@179
|
2542 val (es, fm) = ListUtil.foldlMap (fn (e, fm) =>
|
adamc@179
|
2543 monoExp (env, st, fm) e)
|
adamc@179
|
2544 fm es
|
adamc@179
|
2545 in
|
adamc@179
|
2546 ((L'.EClosure (n, es), loc), fm)
|
adamc@179
|
2547 end
|
adamc@450
|
2548
|
adamc@450
|
2549 | L.ELet (x, t, e1, e2) =>
|
adamc@450
|
2550 let
|
adamc@450
|
2551 val t' = monoType env t
|
adamc@450
|
2552 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@450
|
2553 val (e2, fm) = monoExp (Env.pushERel env x t, st, fm) e2
|
adamc@450
|
2554 in
|
adamc@450
|
2555 ((L'.ELet (x, t', e1, e2), loc), fm)
|
adamc@450
|
2556 end
|
adamc@607
|
2557
|
adamc@609
|
2558 | L.EServerCall (n, es, ek, t) =>
|
adamc@608
|
2559 let
|
adamc@609
|
2560 val t = monoType env t
|
adamc@614
|
2561 val (_, ft, _, name) = Env.lookupENamed env n
|
adamc@608
|
2562 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@614
|
2563
|
adamc@614
|
2564 fun encodeArgs (es, ft, acc, fm) =
|
adamc@614
|
2565 case (es, ft) of
|
adamc@614
|
2566 ([], _) => (rev acc, fm)
|
adamc@614
|
2567 | (e :: es, (L.TFun (dom, ran), _)) =>
|
adamc@614
|
2568 let
|
adamc@614
|
2569 val (e, fm) = urlifyExp env fm (e, monoType env dom)
|
adamc@614
|
2570 in
|
adamc@614
|
2571 encodeArgs (es, ran, e
|
adamc@614
|
2572 :: (L'.EPrim (Prim.String "/"), loc)
|
adamc@614
|
2573 :: acc, fm)
|
adamc@614
|
2574 end
|
adamc@614
|
2575 | _ => raise Fail "Monoize: Not enough arguments visible in RPC function type"
|
adamc@614
|
2576
|
adamc@614
|
2577 val (call, fm) = encodeArgs (es, ft, [], fm)
|
adamc@614
|
2578 val call = foldl (fn (e, call) => (L'.EStrcat (call, e), loc))
|
adamc@614
|
2579 (L'.EPrim (Prim.String name), loc) call
|
adamc@614
|
2580
|
adamc@608
|
2581 val (ek, fm) = monoExp (env, st, fm) ek
|
adamc@609
|
2582
|
adamc@609
|
2583 val ekf = (L'.EAbs ("f",
|
adamc@609
|
2584 (L'.TFun (t,
|
adamc@609
|
2585 (L'.TFun ((L'.TRecord [], loc),
|
adamc@609
|
2586 (L'.TRecord [], loc)), loc)), loc),
|
adamc@609
|
2587 (L'.TFun (t,
|
adamc@609
|
2588 (L'.TRecord [], loc)), loc),
|
adamc@609
|
2589 (L'.EAbs ("x",
|
adamc@609
|
2590 t,
|
adamc@609
|
2591 (L'.TRecord [], loc),
|
adamc@609
|
2592 (L'.EApp ((L'.EApp ((L'.ERel 1, loc),
|
adamc@609
|
2593 (L'.ERel 0, loc)), loc),
|
adamc@609
|
2594 (L'.ERecord [], loc)), loc)), loc)), loc)
|
adamc@609
|
2595 val ek = (L'.EApp (ekf, ek), loc)
|
adamc@651
|
2596 val e = (L'.EServerCall (call, ek, t), loc)
|
adamc@651
|
2597 val e = liftExpInExp 0 e
|
adamc@651
|
2598 val unit = (L'.TRecord [], loc)
|
adamc@651
|
2599 val e = (L'.EAbs ("_", unit, unit, e), loc)
|
adamc@608
|
2600 in
|
adamc@651
|
2601 (e, fm)
|
adamc@608
|
2602 end
|
adamc@626
|
2603
|
adamc@626
|
2604 | L.EKAbs _ => poly ()
|
adamc@626
|
2605 | L.EKApp _ => poly ()
|
adamc@25
|
2606 end
|
adamc@25
|
2607
|
adamc@179
|
2608 fun monoDecl (env, fm) (all as (d, loc)) =
|
adamc@25
|
2609 let
|
adamc@25
|
2610 fun poly () =
|
adamc@25
|
2611 (E.errorAt loc "Unsupported declaration";
|
adamc@25
|
2612 Print.eprefaces' [("Declaration", CorePrint.p_decl env all)];
|
adamc@25
|
2613 NONE)
|
adamc@25
|
2614 in
|
adamc@25
|
2615 case d of
|
adamc@25
|
2616 L.DCon _ => NONE
|
adamc@193
|
2617 | L.DDatatype (x, n, [], xncs) =>
|
adamc@193
|
2618 let
|
adamc@196
|
2619 val env' = Env.declBinds env all
|
adamc@196
|
2620 val d = (L'.DDatatype (x, n, map (fn (x, n, to) => (x, n, Option.map (monoType env') to)) xncs), loc)
|
adamc@164
|
2621 in
|
adamc@273
|
2622 SOME (env', fm, [d])
|
adamc@193
|
2623 end
|
adamc@193
|
2624 | L.DDatatype _ => poly ()
|
adamc@179
|
2625 | L.DVal (x, n, t, e, s) =>
|
adamc@179
|
2626 let
|
adamc@179
|
2627 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
2628 in
|
adamc@179
|
2629 SOME (Env.pushENamed env x n t NONE s,
|
adamc@179
|
2630 fm,
|
adamc@273
|
2631 [(L'.DVal (x, n, monoType env t, e, s), loc)])
|
adamc@179
|
2632 end
|
adamc@128
|
2633 | L.DValRec vis =>
|
adamc@128
|
2634 let
|
adamc@128
|
2635 val env = foldl (fn ((x, n, t, e, s), env) => Env.pushENamed env x n t NONE s) env vis
|
adamc@179
|
2636
|
adamc@179
|
2637 val (vis, fm) = ListUtil.foldlMap
|
adamc@179
|
2638 (fn ((x, n, t, e, s), fm) =>
|
adamc@179
|
2639 let
|
adamc@179
|
2640 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
2641 in
|
adamc@179
|
2642 ((x, n, monoType env t, e, s), fm)
|
adamc@179
|
2643 end)
|
adamc@179
|
2644 fm vis
|
adamc@128
|
2645 in
|
adamc@128
|
2646 SOME (env,
|
adamc@179
|
2647 fm,
|
adamc@273
|
2648 [(L'.DValRec vis, loc)])
|
adamc@128
|
2649 end
|
adamc@144
|
2650 | L.DExport (ek, n) =>
|
adamc@115
|
2651 let
|
adamc@120
|
2652 val (_, t, _, s) = Env.lookupENamed env n
|
adamc@120
|
2653
|
adamc@609
|
2654 fun unwind (t, args) =
|
adamc@609
|
2655 case #1 t of
|
adamc@609
|
2656 L.TFun (dom, ran) => unwind (ran, dom :: args)
|
adamc@314
|
2657 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@609
|
2658 unwind (t, (L.TRecord (L.CRecord ((L.KType, loc), []), loc), loc) :: args)
|
adamc@609
|
2659 | _ => (rev args, t)
|
adamc@120
|
2660
|
adamc@609
|
2661 val (ts, ran) = unwind (t, [])
|
adamc@609
|
2662 val ts = map (monoType env) ts
|
adamc@609
|
2663 val ran = monoType env ran
|
adamc@115
|
2664 in
|
adamc@609
|
2665 SOME (env, fm, [(L'.DExport (ek, s, n, ts, ran), loc)])
|
adamc@115
|
2666 end
|
adamc@707
|
2667 | L.DTable (x, n, (L.CRecord (_, xts), _), s, pe, _, ce, _) =>
|
adamc@251
|
2668 let
|
adamc@251
|
2669 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@251
|
2670 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@311
|
2671 val s = "uw_" ^ s
|
adamc@704
|
2672 val e_name = (L'.EPrim (Prim.String s), loc)
|
adamc@273
|
2673
|
adamc@273
|
2674 val xts = map (fn (x, t) => (monoName env x, monoType env t)) xts
|
adamc@704
|
2675
|
adamc@707
|
2676 val (pe, fm) = monoExp (env, St.empty, fm) pe
|
adamc@707
|
2677 val (ce, fm) = monoExp (env, St.empty, fm) ce
|
adamc@251
|
2678 in
|
adamc@251
|
2679 SOME (Env.pushENamed env x n t NONE s,
|
adamc@251
|
2680 fm,
|
adamc@707
|
2681 [(L'.DTable (s, xts, pe, ce), loc),
|
adamc@704
|
2682 (L'.DVal (x, n, t', e_name, s), loc)])
|
adamc@251
|
2683 end
|
adamc@273
|
2684 | L.DTable _ => poly ()
|
adamc@338
|
2685 | L.DSequence (x, n, s) =>
|
adamc@338
|
2686 let
|
adamc@338
|
2687 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@338
|
2688 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
2689 val s = "uw_" ^ s
|
adamc@338
|
2690 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@338
|
2691 in
|
adamc@338
|
2692 SOME (Env.pushENamed env x n t NONE s,
|
adamc@338
|
2693 fm,
|
adamc@338
|
2694 [(L'.DSequence s, loc),
|
adamc@338
|
2695 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@338
|
2696 end
|
adamc@683
|
2697 | L.DDatabase _ => NONE
|
adamc@462
|
2698 | L.DCookie (x, n, t, s) =>
|
adamc@462
|
2699 let
|
adamc@462
|
2700 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@462
|
2701 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
2702 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@462
|
2703 in
|
adamc@462
|
2704 SOME (Env.pushENamed env x n t NONE s,
|
adamc@462
|
2705 fm,
|
adamc@462
|
2706 [(L'.DVal (x, n, t', e, s), loc)])
|
adamc@462
|
2707 end
|
adamc@720
|
2708 | L.DStyle (x, n, s) =>
|
adamc@718
|
2709 let
|
adamc@718
|
2710 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@718
|
2711 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@718
|
2712 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@718
|
2713 in
|
adamc@718
|
2714 SOME (Env.pushENamed env x n t NONE s,
|
adamc@718
|
2715 fm,
|
adamc@720
|
2716 [(L'.DStyle s, loc),
|
adamc@718
|
2717 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@718
|
2718 end
|
adamc@25
|
2719 end
|
adamc@25
|
2720
|
adamc@683
|
2721 datatype expungable = Client | Channel
|
adamc@683
|
2722
|
adamc@683
|
2723 fun monoize env file =
|
adamc@25
|
2724 let
|
adamc@385
|
2725 val p = !urlPrefix
|
adamc@385
|
2726 val () =
|
adamc@385
|
2727 if p = "" then
|
adamc@385
|
2728 urlPrefix := "/"
|
adamc@385
|
2729 else if String.sub (p, size p - 1) <> #"/" then
|
adamc@385
|
2730 urlPrefix := p ^ "/"
|
adamc@385
|
2731 else
|
adamc@385
|
2732 ()
|
adamc@385
|
2733
|
adamc@683
|
2734 val loc = E.dummySpan
|
adamc@683
|
2735 val client = (L'.TFfi ("Basis", "client"), loc)
|
adamc@683
|
2736 val unit = (L'.TRecord [], loc)
|
adamc@687
|
2737
|
adamc@687
|
2738 fun calcClientish xts =
|
adamc@687
|
2739 foldl (fn ((x : L.con, t : L.con), st as (nullable, notNullable)) =>
|
adamc@687
|
2740 case #1 x of
|
adamc@687
|
2741 L.CName x =>
|
adamc@687
|
2742 (case #1 t of
|
adamc@687
|
2743 L.CFfi ("Basis", "client") =>
|
adamc@687
|
2744 (nullable, (x, Client) :: notNullable)
|
adamc@687
|
2745 | L.CApp ((L.CFfi ("Basis", "option"), _),
|
adamc@687
|
2746 (L.CFfi ("Basis", "client"), _)) =>
|
adamc@687
|
2747 ((x, Client) :: nullable, notNullable)
|
adamc@687
|
2748 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) =>
|
adamc@687
|
2749 (nullable, (x, Channel) :: notNullable)
|
adamc@687
|
2750 | L.CApp ((L.CFfi ("Basis", "option"), _),
|
adamc@687
|
2751 (L.CApp ((L.CFfi ("Basis", "channel"), _), _), _)) =>
|
adamc@687
|
2752 ((x, Channel) :: nullable, notNullable)
|
adamc@687
|
2753 | _ => st)
|
adamc@687
|
2754 | _ => st) ([], []) xts
|
adamc@687
|
2755
|
adamc@683
|
2756 fun expunger () =
|
adamc@683
|
2757 let
|
adamc@683
|
2758 val target = (L'.EFfiApp ("Basis", "sqlifyClient", [(L'.ERel 0, loc)]), loc)
|
adamc@683
|
2759
|
adamc@683
|
2760 fun doTable (tab, xts, e) =
|
adamc@683
|
2761 case xts of
|
adamc@683
|
2762 L.CRecord (_, xts) =>
|
adamc@683
|
2763 let
|
adamc@687
|
2764 val (nullable, notNullable) = calcClientish xts
|
adamc@683
|
2765
|
adamc@684
|
2766 fun cond (x, v) =
|
adamc@684
|
2767 (L'.EStrcat ((L'.EPrim (Prim.String ("uw_" ^ x
|
adamc@684
|
2768 ^ (case v of
|
adamc@684
|
2769 Client => ""
|
adamc@684
|
2770 | Channel => " >> 32")
|
adamc@684
|
2771 ^ " = ")), loc),
|
adamc@684
|
2772 target), loc)
|
adamc@684
|
2773
|
adamc@684
|
2774 val e =
|
adamc@684
|
2775 foldl (fn ((x, v), e) =>
|
adamc@684
|
2776 (L'.ESeq (
|
adamc@684
|
2777 (L'.EDml (L'.EStrcat (
|
adamc@684
|
2778 (L'.EPrim (Prim.String ("UPDATE uw_"
|
adamc@684
|
2779 ^ tab
|
adamc@684
|
2780 ^ " SET uw_"
|
adamc@684
|
2781 ^ x
|
adamc@684
|
2782 ^ " = NULL WHERE ")), loc),
|
adamc@684
|
2783 cond (x, v)), loc), loc),
|
adamc@684
|
2784 e), loc))
|
adamc@684
|
2785 e nullable
|
adamc@684
|
2786
|
adamc@683
|
2787 val e =
|
adamc@683
|
2788 case notNullable of
|
adamc@683
|
2789 [] => e
|
adamc@683
|
2790 | eb :: ebs =>
|
adamc@684
|
2791 (L'.ESeq (
|
adamc@684
|
2792 (L'.EDml (foldl
|
adamc@684
|
2793 (fn (eb, s) =>
|
adamc@684
|
2794 (L'.EStrcat (s,
|
adamc@687
|
2795 (L'.EStrcat ((L'.EPrim (Prim.String " OR "),
|
adamc@684
|
2796 loc),
|
adamc@684
|
2797 cond eb), loc)), loc))
|
adamc@684
|
2798 (L'.EStrcat ((L'.EPrim (Prim.String ("DELETE FROM uw_"
|
adamc@684
|
2799 ^ tab
|
adamc@684
|
2800 ^ " WHERE ")), loc),
|
adamc@684
|
2801 cond eb), loc)
|
adamc@684
|
2802 ebs), loc),
|
adamc@684
|
2803 e), loc)
|
adamc@683
|
2804 in
|
adamc@683
|
2805 e
|
adamc@683
|
2806 end
|
adamc@683
|
2807 | _ => e
|
adamc@683
|
2808
|
adamc@683
|
2809 val e = (L'.ERecord [], loc)
|
adamc@683
|
2810 in
|
adamc@683
|
2811 foldl (fn ((d, _), e) =>
|
adamc@683
|
2812 case d of
|
adamc@707
|
2813 L.DTable (_, _, xts, tab, _, _, _, _) => doTable (tab, #1 xts, e)
|
adamc@683
|
2814 | _ => e) e file
|
adamc@683
|
2815 end
|
adamc@683
|
2816
|
adamc@687
|
2817 fun initializer () =
|
adamc@687
|
2818 let
|
adamc@687
|
2819 fun doTable (tab, xts, e) =
|
adamc@687
|
2820 case xts of
|
adamc@687
|
2821 L.CRecord (_, xts) =>
|
adamc@687
|
2822 let
|
adamc@687
|
2823 val (nullable, notNullable) = calcClientish xts
|
adamc@687
|
2824
|
adamc@687
|
2825 val e =
|
adamc@687
|
2826 case nullable of
|
adamc@687
|
2827 [] => e
|
adamc@687
|
2828 | (x, _) :: ebs =>
|
adamc@687
|
2829 (L'.ESeq (
|
adamc@687
|
2830 (L'.EDml (L'.EPrim (Prim.String
|
adamc@687
|
2831 (foldl (fn ((x, _), s) =>
|
adamc@687
|
2832 s ^ ", uw_" ^ x ^ " = NULL")
|
adamc@687
|
2833 ("UPDATE uw_"
|
adamc@687
|
2834 ^ tab
|
adamc@687
|
2835 ^ " SET uw_"
|
adamc@687
|
2836 ^ x
|
adamc@687
|
2837 ^ " = NULL")
|
adamc@687
|
2838 ebs)), loc), loc),
|
adamc@687
|
2839 e), loc)
|
adamc@687
|
2840
|
adamc@687
|
2841 val e =
|
adamc@687
|
2842 case notNullable of
|
adamc@687
|
2843 [] => e
|
adamc@687
|
2844 | eb :: ebs =>
|
adamc@687
|
2845 (L'.ESeq (
|
adamc@687
|
2846 (L'.EDml (L'.EPrim (Prim.String ("DELETE FROM uw_"
|
adamc@687
|
2847 ^ tab)), loc), loc),
|
adamc@687
|
2848 e), loc)
|
adamc@687
|
2849 in
|
adamc@687
|
2850 e
|
adamc@687
|
2851 end
|
adamc@687
|
2852 | _ => e
|
adamc@687
|
2853
|
adamc@687
|
2854 val e = (L'.ERecord [], loc)
|
adamc@687
|
2855 in
|
adamc@687
|
2856 foldl (fn ((d, _), e) =>
|
adamc@687
|
2857 case d of
|
adamc@707
|
2858 L.DTable (_, _, xts, tab, _, _, _, _) => doTable (tab, #1 xts, e)
|
adamc@687
|
2859 | _ => e) e file
|
adamc@687
|
2860 end
|
adamc@687
|
2861
|
adamc@179
|
2862 val (_, _, ds) = List.foldl (fn (d, (env, fm, ds)) =>
|
adamc@683
|
2863 case #1 d of
|
adamc@683
|
2864 L.DDatabase s =>
|
adamc@683
|
2865 let
|
adamc@687
|
2866 val (nExp, fm) = Fm.freshName fm
|
adamc@687
|
2867 val (nIni, fm) = Fm.freshName fm
|
adamc@687
|
2868
|
adamc@687
|
2869 val dExp = L'.DVal ("expunger",
|
adamc@687
|
2870 nExp,
|
adamc@687
|
2871 (L'.TFun (client, unit), loc),
|
adamc@687
|
2872 (L'.EAbs ("cli", client, unit, expunger ()), loc),
|
adamc@687
|
2873 "expunger")
|
adamc@687
|
2874 val dIni = L'.DVal ("initializer",
|
adamc@687
|
2875 nIni,
|
adamc@687
|
2876 (L'.TFun (unit, unit), loc),
|
adamc@687
|
2877 (L'.EAbs ("_", unit, unit, initializer ()), loc),
|
adamc@687
|
2878 "initializer")
|
adamc@683
|
2879 in
|
adamc@687
|
2880 (env, Fm.enter fm, (L'.DDatabase {name = s,
|
adamc@687
|
2881 expunge = nExp,
|
adamc@687
|
2882 initialize = nIni}, loc)
|
adamc@687
|
2883 :: (dExp, loc)
|
adamc@687
|
2884 :: (dIni, loc)
|
adamc@683
|
2885 :: ds)
|
adamc@683
|
2886 end
|
adamc@683
|
2887 | _ =>
|
adamc@683
|
2888 case monoDecl (env, fm) d of
|
adamc@683
|
2889 NONE => (env, fm, ds)
|
adamc@683
|
2890 | SOME (env, fm, ds') =>
|
adamc@683
|
2891 (env,
|
adamc@683
|
2892 Fm.enter fm,
|
adamc@683
|
2893 ds' @ Fm.decls fm @ ds))
|
adamc@683
|
2894 (env, Fm.empty (CoreUtil.File.maxName file + 1), []) file
|
adamc@25
|
2895 in
|
adamc@25
|
2896 rev ds
|
adamc@25
|
2897 end
|
adamc@25
|
2898
|
adamc@25
|
2899 end
|