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