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@251
|
1005
|
adamc@565
|
1006 | L.ECApp ((L.EFfi ("Basis", "source"), _), t) =>
|
adamc@565
|
1007 let
|
adamc@565
|
1008 val t = monoType env t
|
adamc@565
|
1009 in
|
adamc@577
|
1010 ((L'.EAbs ("x", t, (L'.TFun ((L'.TRecord [], loc), (L'.TSource, loc)), loc),
|
adamc@577
|
1011 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TSource, loc),
|
adamc@577
|
1012 (L'.EFfiApp ("Basis", "new_client_source",
|
adamc@590
|
1013 [(L'.EJavaScript (L'.Source t, (L'.ERel 1, loc), NONE), loc)]),
|
adamc@578
|
1014 loc)), loc)),
|
adamc@565
|
1015 loc),
|
adamc@565
|
1016 fm)
|
adamc@565
|
1017 end
|
adamc@575
|
1018 | L.ECApp ((L.EFfi ("Basis", "set"), _), t) =>
|
adamc@575
|
1019 let
|
adamc@575
|
1020 val t = monoType env t
|
adamc@575
|
1021 in
|
adamc@577
|
1022 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@575
|
1023 (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc)), loc),
|
adamc@575
|
1024 (L'.EAbs ("v", t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc),
|
adamc@575
|
1025 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@575
|
1026 (L'.EFfiApp ("Basis", "set_client_source",
|
adamc@577
|
1027 [(L'.ERel 2, loc),
|
adamc@590
|
1028 (L'.EJavaScript (L'.Source t,
|
adamc@590
|
1029 (L'.ERel 1, loc), NONE), loc)]),
|
adamc@575
|
1030 loc)), loc)), loc)), loc),
|
adamc@575
|
1031 fm)
|
adamc@575
|
1032 end
|
adamc@601
|
1033 | L.ECApp ((L.EFfi ("Basis", "get"), _), t) =>
|
adamc@601
|
1034 let
|
adamc@601
|
1035 val t = monoType env t
|
adamc@601
|
1036 in
|
adamc@601
|
1037 ((L'.EAbs ("src", (L'.TSource, loc),
|
adamc@601
|
1038 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@601
|
1039 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@601
|
1040 (L'.EFfiApp ("Basis", "get_client_source",
|
adamc@601
|
1041 [(L'.ERel 1, loc)]),
|
adamc@601
|
1042 loc)), loc)), loc),
|
adamc@601
|
1043 fm)
|
adamc@601
|
1044 end
|
adamc@565
|
1045
|
adamc@694
|
1046 | L.EFfiApp ("Basis", "spawn", [e]) =>
|
adamc@694
|
1047 let
|
adamc@694
|
1048 val (e, fm) = monoExp (env, st, fm) e
|
adamc@694
|
1049 in
|
adamc@694
|
1050 ((L'.EApp (e, (L'.ERecord [], loc)), loc), fm)
|
adamc@694
|
1051 end
|
adamc@694
|
1052
|
adamc@568
|
1053 | L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), _), _), t), _),
|
adamc@568
|
1054 (L.EFfi ("Basis", "signal_monad"), _)) =>
|
adamc@568
|
1055 let
|
adamc@568
|
1056 val t = monoType env t
|
adamc@568
|
1057 in
|
adamc@568
|
1058 ((L'.EAbs ("x", t, (L'.TSignal t, loc),
|
adamc@568
|
1059 (L'.ESignalReturn (L'.ERel 0, loc), loc)), loc),
|
adamc@568
|
1060 fm)
|
adamc@568
|
1061 end
|
adamc@572
|
1062 | L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), t1), _), t2), _),
|
adamc@572
|
1063 (L.EFfi ("Basis", "signal_monad"), _)) =>
|
adamc@572
|
1064 let
|
adamc@572
|
1065 val t1 = monoType env t1
|
adamc@572
|
1066 val t2 = monoType env t2
|
adamc@572
|
1067 val un = (L'.TRecord [], loc)
|
adamc@572
|
1068 val mt1 = (L'.TSignal t1, loc)
|
adamc@572
|
1069 val mt2 = (L'.TSignal t2, loc)
|
adamc@572
|
1070 in
|
adamc@572
|
1071 ((L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), mt2), loc),
|
adamc@572
|
1072 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), mt2,
|
adamc@572
|
1073 (L'.ESignalBind ((L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@572
|
1074 fm)
|
adamc@572
|
1075 end
|
adamc@574
|
1076 | L.ECApp ((L.EFfi ("Basis", "signal"), _), t) =>
|
adamc@574
|
1077 let
|
adamc@574
|
1078 val t = monoType env t
|
adamc@574
|
1079 in
|
adamc@574
|
1080 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TSignal t, loc),
|
adamc@574
|
1081 (L'.ESignalSource (L'.ERel 0, loc), loc)), loc),
|
adamc@574
|
1082 fm)
|
adamc@574
|
1083 end
|
adamc@568
|
1084
|
adamc@462
|
1085 | L.ECApp ((L.EFfi ("Basis", "getCookie"), _), t) =>
|
adamc@462
|
1086 let
|
adamc@462
|
1087 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1088 val un = (L'.TRecord [], loc)
|
adamc@462
|
1089 val t = monoType env t
|
adamc@462
|
1090 in
|
adamc@462
|
1091 ((L'.EAbs ("c", s, (L'.TFun (un, s), loc),
|
adamc@462
|
1092 (L'.EAbs ("_", un, s,
|
adamc@463
|
1093 (L'.EUnurlify ((L'.EFfiApp ("Basis", "get_cookie", [(L'.ERel 1, loc)]), loc),
|
adamc@463
|
1094 t),
|
adamc@463
|
1095 loc)), loc)), loc),
|
adamc@462
|
1096 fm)
|
adamc@462
|
1097 end
|
adamc@462
|
1098
|
adamc@462
|
1099 | L.ECApp ((L.EFfi ("Basis", "setCookie"), _), t) =>
|
adamc@462
|
1100 let
|
adamc@462
|
1101 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1102 val un = (L'.TRecord [], loc)
|
adamc@462
|
1103 val t = monoType env t
|
adamc@462
|
1104 val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
|
adamc@462
|
1105 in
|
adamc@462
|
1106 ((L'.EAbs ("c", s, (L'.TFun (t, (L'.TFun (un, un), loc)), loc),
|
adamc@462
|
1107 (L'.EAbs ("v", t, (L'.TFun (un, un), loc),
|
adamc@462
|
1108 (L'.EAbs ("_", un, un,
|
adamc@466
|
1109 (L'.EFfiApp ("Basis", "set_cookie", [(L'.EPrim (Prim.String (!urlPrefix)),
|
adamc@466
|
1110 loc),
|
adamc@466
|
1111 (L'.ERel 2, loc),
|
adamc@466
|
1112 e]), loc)),
|
adamc@462
|
1113 loc)), loc)), loc),
|
adamc@462
|
1114 fm)
|
adamc@462
|
1115 end
|
adamc@462
|
1116
|
adamc@668
|
1117 | L.ECApp ((L.EFfi ("Basis", "channel"), _), t) =>
|
adamc@668
|
1118 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "channel"), loc),
|
adamc@668
|
1119 (L'.EFfiApp ("Basis", "new_channel", [(L'.ERecord [], loc)]), loc)), loc),
|
adamc@668
|
1120 fm)
|
adamc@668
|
1121 | L.ECApp ((L.EFfi ("Basis", "send"), _), t) =>
|
adamc@668
|
1122 let
|
adamc@668
|
1123 val t = monoType env t
|
adamc@668
|
1124 val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
|
adamc@668
|
1125 in
|
adamc@668
|
1126 ((L'.EAbs ("ch", (L'.TFfi ("Basis", "channel"), loc),
|
adamc@668
|
1127 (L'.TFun (t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc)), loc),
|
adamc@668
|
1128 (L'.EAbs ("v", t, (L'.TFun ((L'.TRecord [], loc), (L'.TRecord [], loc)), loc),
|
adamc@668
|
1129 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@668
|
1130 (L'.EFfiApp ("Basis", "send",
|
adamc@668
|
1131 [(L'.ERel 2, loc),
|
adamc@668
|
1132 e]),
|
adamc@668
|
1133 loc)), loc)), loc)), loc),
|
adamc@668
|
1134 fm)
|
adamc@668
|
1135 end
|
adamc@668
|
1136
|
adamc@307
|
1137 | L.EFfiApp ("Basis", "dml", [e]) =>
|
adamc@307
|
1138 let
|
adamc@307
|
1139 val (e, fm) = monoExp (env, st, fm) e
|
adamc@307
|
1140 in
|
adamc@468
|
1141 ((L'.EDml e, loc),
|
adamc@307
|
1142 fm)
|
adamc@307
|
1143 end
|
adamc@308
|
1144
|
adamc@307
|
1145 | L.ECApp ((L.EFfi ("Basis", "insert"), _), fields) =>
|
adamc@307
|
1146 (case monoType env (L.TRecord fields, loc) of
|
adamc@307
|
1147 (L'.TRecord fields, _) =>
|
adamc@307
|
1148 let
|
adamc@307
|
1149 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@307
|
1150 val fields = map (fn (x, _) => (x, s)) fields
|
adamc@307
|
1151 val rt = (L'.TRecord fields, loc)
|
adamc@307
|
1152 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@307
|
1153 in
|
adamc@307
|
1154 ((L'.EAbs ("tab", s, (L'.TFun (rt, s), loc),
|
adamc@307
|
1155 (L'.EAbs ("fs", rt, s,
|
adamc@598
|
1156 strcat [sc "INSERT INTO ",
|
adamc@598
|
1157 (L'.ERel 1, loc),
|
adamc@598
|
1158 sc " (",
|
adamc@598
|
1159 strcatComma (map (fn (x, _) => sc ("uw_" ^ x)) fields),
|
adamc@598
|
1160 sc ") VALUES (",
|
adamc@598
|
1161 strcatComma (map (fn (x, _) =>
|
adamc@598
|
1162 (L'.EField ((L'.ERel 0, loc),
|
adamc@598
|
1163 x), loc)) fields),
|
adamc@598
|
1164 sc ")"]), loc)), loc),
|
adamc@307
|
1165 fm)
|
adamc@307
|
1166 end
|
adamc@307
|
1167 | _ => poly ())
|
adamc@307
|
1168
|
adamc@403
|
1169 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "update"), _), _), _), changed) =>
|
adamc@308
|
1170 (case monoType env (L.TRecord changed, loc) of
|
adamc@308
|
1171 (L'.TRecord changed, _) =>
|
adamc@308
|
1172 let
|
adamc@308
|
1173 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@308
|
1174 val changed = map (fn (x, _) => (x, s)) changed
|
adamc@308
|
1175 val rt = (L'.TRecord changed, loc)
|
adamc@308
|
1176 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@308
|
1177 in
|
adamc@308
|
1178 ((L'.EAbs ("fs", rt, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@308
|
1179 (L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@308
|
1180 (L'.EAbs ("e", s, s,
|
adamc@598
|
1181 strcat [sc "UPDATE ",
|
adamc@598
|
1182 (L'.ERel 1, loc),
|
adamc@598
|
1183 sc " AS T SET ",
|
adamc@598
|
1184 strcatComma (map (fn (x, _) =>
|
adamc@598
|
1185 strcat [sc ("uw_" ^ x
|
adamc@598
|
1186 ^ " = "),
|
adamc@598
|
1187 (L'.EField
|
adamc@598
|
1188 ((L'.ERel 2,
|
adamc@598
|
1189 loc),
|
adamc@598
|
1190 x), loc)])
|
adamc@598
|
1191 changed),
|
adamc@598
|
1192 sc " WHERE ",
|
adamc@598
|
1193 (L'.ERel 0, loc)]), loc)), loc)), loc),
|
adamc@308
|
1194 fm)
|
adamc@308
|
1195 end
|
adamc@308
|
1196 | _ => poly ())
|
adamc@308
|
1197
|
adamc@309
|
1198 | L.ECApp ((L.EFfi ("Basis", "delete"), _), _) =>
|
adamc@309
|
1199 let
|
adamc@309
|
1200 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@309
|
1201 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@309
|
1202 in
|
adamc@309
|
1203 ((L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@309
|
1204 (L'.EAbs ("e", s, s,
|
adamc@598
|
1205 strcat [sc "DELETE FROM ",
|
adamc@598
|
1206 (L'.ERel 1, loc),
|
adamc@598
|
1207 sc " AS T WHERE ",
|
adamc@598
|
1208 (L'.ERel 0, loc)]), loc)), loc),
|
adamc@309
|
1209 fm)
|
adamc@309
|
1210 end
|
adamc@309
|
1211
|
adamc@252
|
1212 | L.ECApp (
|
adamc@252
|
1213 (L.ECApp (
|
adamc@252
|
1214 (L.ECApp ((L.EFfi ("Basis", "query"), _), (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1215 exps), _),
|
adamc@252
|
1216 state) =>
|
adamc@252
|
1217 (case monoType env (L.TRecord exps, loc) of
|
adamc@252
|
1218 (L'.TRecord exps, _) =>
|
adamc@252
|
1219 let
|
adamc@252
|
1220 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1221 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1222 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1223 | _ => NONE)
|
adamc@252
|
1224 | _ => NONE) tables
|
adamc@252
|
1225 in
|
adamc@252
|
1226 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1227 poly ()
|
adamc@252
|
1228 else
|
adamc@252
|
1229 let
|
adamc@252
|
1230 val tables = List.mapPartial (fn x => x) tables
|
adamc@252
|
1231 val state = monoType env state
|
adamc@252
|
1232 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1233 val un = (L'.TRecord [], loc)
|
adamc@252
|
1234
|
adamc@252
|
1235 val rt = exps @ map (fn (x, xts) => (x, (L'.TRecord xts, loc))) tables
|
adamc@252
|
1236 val ft = (L'.TFun ((L'.TRecord rt, loc),
|
adamc@252
|
1237 (L'.TFun (state,
|
adamc@252
|
1238 (L'.TFun (un, state), loc)),
|
adamc@252
|
1239 loc)), loc)
|
adamc@252
|
1240
|
adamc@267
|
1241 val body' = (L'.EApp (
|
adamc@267
|
1242 (L'.EApp (
|
adamc@267
|
1243 (L'.EApp ((L'.ERel 4, loc),
|
adamc@267
|
1244 (L'.ERel 1, loc)), loc),
|
adamc@267
|
1245 (L'.ERel 0, loc)), loc),
|
adamc@267
|
1246 (L'.ERecord [], loc)), loc)
|
adamc@252
|
1247
|
adamc@252
|
1248 val body = (L'.EQuery {exps = exps,
|
adamc@252
|
1249 tables = tables,
|
adamc@252
|
1250 state = state,
|
adamc@252
|
1251 query = (L'.ERel 3, loc),
|
adamc@252
|
1252 body = body',
|
adamc@252
|
1253 initial = (L'.ERel 1, loc)},
|
adamc@252
|
1254 loc)
|
adamc@252
|
1255 in
|
adamc@252
|
1256 ((L'.EAbs ("q", s, (L'.TFun (ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc)), loc),
|
adamc@252
|
1257 (L'.EAbs ("f", ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc),
|
adamc@252
|
1258 (L'.EAbs ("i", state, (L'.TFun (un, state), loc),
|
adamc@252
|
1259 (L'.EAbs ("_", un, state,
|
adamc@252
|
1260 body), loc)), loc)), loc)), loc), fm)
|
adamc@252
|
1261 end
|
adamc@252
|
1262 end
|
adamc@252
|
1263 | _ => poly ())
|
adamc@252
|
1264
|
adamc@252
|
1265 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_query"), _), _), _), _), _), _) =>
|
adamc@252
|
1266 let
|
adamc@252
|
1267 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1268 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1269 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1270 in
|
adamc@252
|
1271 ((L'.EAbs ("r",
|
adamc@252
|
1272 (L'.TRecord [("Rows", s), ("OrderBy", s), ("Limit", s), ("Offset", s)], loc),
|
adamc@252
|
1273 s,
|
adamc@598
|
1274 strcat [gf "Rows",
|
adamc@598
|
1275 (L'.ECase (gf "OrderBy",
|
adamc@598
|
1276 [((L'.PPrim (Prim.String ""), loc), sc ""),
|
adamc@598
|
1277 ((L'.PWild, loc),
|
adamc@598
|
1278 strcat [sc " ORDER BY ",
|
adamc@598
|
1279 gf "OrderBy"])],
|
adamc@598
|
1280 {disc = s, result = s}), loc),
|
adamc@598
|
1281 gf "Limit",
|
adamc@598
|
1282 gf "Offset"]), loc), fm)
|
adamc@252
|
1283 end
|
adamc@252
|
1284
|
adamc@252
|
1285 | L.ECApp (
|
adamc@252
|
1286 (L.ECApp (
|
adamc@252
|
1287 (L.ECApp (
|
adamc@252
|
1288 (L.ECApp (
|
adamc@252
|
1289 (L.EFfi ("Basis", "sql_query1"), _),
|
adamc@252
|
1290 (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1291 (L.CRecord (_, grouped), _)), _),
|
adamc@252
|
1292 (L.CRecord (_, stables), _)), _),
|
adamc@252
|
1293 sexps) =>
|
adamc@252
|
1294 let
|
adamc@252
|
1295 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1296 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1297 val un = (L'.TRecord [], loc)
|
adamc@252
|
1298 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1299
|
adamc@252
|
1300 fun doTables tables =
|
adamc@252
|
1301 let
|
adamc@252
|
1302 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1303 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1304 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1305 | _ => NONE)
|
adamc@252
|
1306 | _ => NONE) tables
|
adamc@252
|
1307 in
|
adamc@252
|
1308 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1309 NONE
|
adamc@252
|
1310 else
|
adamc@260
|
1311 let
|
adamc@260
|
1312 val tables = List.mapPartial (fn x => x) tables
|
adamc@260
|
1313 val tables = ListMergeSort.sort
|
adamc@260
|
1314 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1315 tables
|
adamc@260
|
1316 val tables = map (fn (x, xts) =>
|
adamc@260
|
1317 (x, ListMergeSort.sort
|
adamc@260
|
1318 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1319 xts)) tables
|
adamc@260
|
1320 in
|
adamc@260
|
1321 SOME tables
|
adamc@260
|
1322 end
|
adamc@252
|
1323 end
|
adamc@252
|
1324 in
|
adamc@252
|
1325 case (doTables tables, doTables grouped, doTables stables, monoType env (L.TRecord sexps, loc)) of
|
adamc@252
|
1326 (SOME tables, SOME grouped, SOME stables, (L'.TRecord sexps, _)) =>
|
adamc@441
|
1327 let
|
adamc@441
|
1328 val sexps = ListMergeSort.sort
|
adamc@441
|
1329 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER) sexps
|
adamc@441
|
1330 in
|
adamc@441
|
1331 ((L'.EAbs ("r",
|
adamc@441
|
1332 (L'.TRecord [("From", (L'.TRecord (map (fn (x, _) => (x, s)) tables), loc)),
|
adamc@441
|
1333 ("Where", s),
|
adamc@441
|
1334 ("GroupBy", un),
|
adamc@441
|
1335 ("Having", s),
|
adamc@441
|
1336 ("SelectFields", un),
|
adamc@441
|
1337 ("SelectExps", (L'.TRecord (map (fn (x, _) => (x, s)) sexps), loc))],
|
adamc@441
|
1338 loc),
|
adamc@441
|
1339 s,
|
adamc@598
|
1340 strcat [sc "SELECT ",
|
adamc@598
|
1341 strcatComma (map (fn (x, t) =>
|
adamc@598
|
1342 strcat [
|
adamc@598
|
1343 (L'.EField (gf "SelectExps", x), loc),
|
adamc@598
|
1344 sc (" AS _" ^ x)
|
adamc@598
|
1345 ]) sexps
|
adamc@598
|
1346 @ map (fn (x, xts) =>
|
adamc@598
|
1347 strcatComma
|
adamc@598
|
1348 (map (fn (x', _) =>
|
adamc@598
|
1349 sc (x ^ ".uw_" ^ x'))
|
adamc@598
|
1350 xts)) stables),
|
adamc@598
|
1351 sc " FROM ",
|
adamc@598
|
1352 strcatComma (map (fn (x, _) => strcat [(L'.EField (gf "From", x), loc),
|
adamc@598
|
1353 sc (" AS " ^ x)]) tables),
|
adamc@598
|
1354 (L'.ECase (gf "Where",
|
adamc@598
|
1355 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@598
|
1356 sc ""),
|
adamc@598
|
1357 ((L'.PWild, loc),
|
adamc@598
|
1358 strcat [sc " WHERE ", gf "Where"])],
|
adamc@598
|
1359 {disc = s,
|
adamc@598
|
1360 result = s}), loc),
|
adamc@598
|
1361
|
adamc@598
|
1362 if List.all (fn (x, xts) =>
|
adamc@598
|
1363 case List.find (fn (x', _) => x' = x) grouped of
|
adamc@598
|
1364 NONE => List.null xts
|
adamc@598
|
1365 | SOME (_, xts') =>
|
adamc@598
|
1366 List.all (fn (x, _) =>
|
adamc@598
|
1367 List.exists (fn (x', _) => x' = x)
|
adamc@598
|
1368 xts') xts) tables then
|
adamc@598
|
1369 sc ""
|
adamc@598
|
1370 else
|
adamc@598
|
1371 strcat [
|
adamc@598
|
1372 sc " GROUP BY ",
|
adamc@598
|
1373 strcatComma (map (fn (x, xts) =>
|
adamc@598
|
1374 strcatComma
|
adamc@598
|
1375 (map (fn (x', _) =>
|
adamc@598
|
1376 sc (x ^ ".uw_" ^ x'))
|
adamc@598
|
1377 xts)) grouped)
|
adamc@598
|
1378 ],
|
adamc@259
|
1379
|
adamc@598
|
1380 (L'.ECase (gf "Having",
|
adamc@598
|
1381 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@598
|
1382 sc ""),
|
adamc@598
|
1383 ((L'.PWild, loc),
|
adamc@598
|
1384 strcat [sc " HAVING ", gf "Having"])],
|
adamc@598
|
1385 {disc = s,
|
adamc@598
|
1386 result = s}), loc)
|
adamc@441
|
1387 ]), loc),
|
adamc@441
|
1388 fm)
|
adamc@441
|
1389 end
|
adamc@252
|
1390 | _ => poly ()
|
adamc@252
|
1391 end
|
adamc@252
|
1392
|
adamc@252
|
1393 | L.ECApp (
|
adamc@252
|
1394 (L.ECApp (
|
adamc@252
|
1395 (L.ECApp (
|
adamc@252
|
1396 (L.ECApp (
|
adamc@252
|
1397 (L.EFfi ("Basis", "sql_inject"), _),
|
adamc@252
|
1398 _), _),
|
adamc@252
|
1399 _), _),
|
adamc@252
|
1400 _), _),
|
adamc@252
|
1401 t) =>
|
adamc@252
|
1402 let
|
adamc@252
|
1403 val t = monoType env t
|
adamc@252
|
1404 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1405 in
|
adamc@252
|
1406 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@252
|
1407 (L'.ERel 0, loc)), loc), fm)
|
adamc@252
|
1408 end
|
adamc@252
|
1409
|
adamc@253
|
1410 | L.EFfi ("Basis", "sql_int") =>
|
adamc@253
|
1411 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1412 (L'.EFfiApp ("Basis", "sqlifyInt", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1413 fm)
|
adamc@253
|
1414 | L.EFfi ("Basis", "sql_float") =>
|
adamc@253
|
1415 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1416 (L'.EFfiApp ("Basis", "sqlifyFloat", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1417 fm)
|
adamc@253
|
1418 | L.EFfi ("Basis", "sql_bool") =>
|
adamc@253
|
1419 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1420 (L'.EFfiApp ("Basis", "sqlifyBool", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1421 fm)
|
adamc@253
|
1422 | L.EFfi ("Basis", "sql_string") =>
|
adamc@253
|
1423 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1424 (L'.EFfiApp ("Basis", "sqlifyString", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1425 fm)
|
adamc@439
|
1426 | L.EFfi ("Basis", "sql_time") =>
|
adamc@439
|
1427 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@439
|
1428 (L'.EFfiApp ("Basis", "sqlifyTime", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@439
|
1429 fm)
|
adamc@678
|
1430 | L.ECApp ((L.EFfi ("Basis", "sql_channel"), _), _) =>
|
adamc@678
|
1431 ((L'.EAbs ("x", (L'.TFfi ("Basis", "channel"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@678
|
1432 (L'.EFfiApp ("Basis", "sqlifyChannel", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@678
|
1433 fm)
|
adamc@682
|
1434 | L.EFfi ("Basis", "sql_client") =>
|
adamc@682
|
1435 ((L'.EAbs ("x", (L'.TFfi ("Basis", "client"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@682
|
1436 (L'.EFfiApp ("Basis", "sqlifyClient", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@682
|
1437 fm)
|
adamc@676
|
1438 | L.ECApp ((L.EFfi ("Basis", "sql_prim"), _), t) =>
|
adamc@676
|
1439 let
|
adamc@676
|
1440 val t = monoType env t
|
adamc@676
|
1441 val tf = (L'.TFun (t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@676
|
1442 in
|
adamc@676
|
1443 ((L'.EAbs ("f", tf, tf, (L'.ERel 0, loc)), loc),
|
adamc@676
|
1444 fm)
|
adamc@676
|
1445 end
|
adamc@676
|
1446 | L.ECApp ((L.EFfi ("Basis", "sql_option_prim"), _), t) =>
|
adamc@676
|
1447 let
|
adamc@676
|
1448 val t = monoType env t
|
adamc@676
|
1449 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@676
|
1450 in
|
adamc@676
|
1451 ((L'.EAbs ("f",
|
adamc@676
|
1452 (L'.TFun (t, s), loc),
|
adamc@676
|
1453 (L'.TFun ((L'.TOption t, loc), s), loc),
|
adamc@676
|
1454 (L'.EAbs ("x",
|
adamc@676
|
1455 (L'.TOption t, loc),
|
adamc@676
|
1456 s,
|
adamc@676
|
1457 (L'.ECase ((L'.ERel 0, loc),
|
adamc@676
|
1458 [((L'.PNone t, loc),
|
adamc@676
|
1459 (L'.EPrim (Prim.String "NULL"), loc)),
|
adamc@676
|
1460 ((L'.PSome (t, (L'.PVar ("y", t), loc)), loc),
|
adamc@676
|
1461 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc))],
|
adamc@676
|
1462 {disc = (L'.TOption t, loc),
|
adamc@676
|
1463 result = s}), loc)), loc)), loc),
|
adamc@676
|
1464 fm)
|
adamc@676
|
1465 end
|
adamc@253
|
1466
|
adamc@252
|
1467 | L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) =>
|
adamc@252
|
1468 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1469 | L.ECApp ((L.EFfi ("Basis", "sql_subset_all"), _), _) =>
|
adamc@252
|
1470 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1471
|
adamc@252
|
1472 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_order_by_Nil"), _), _), _), _) =>
|
adamc@252
|
1473 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@261
|
1474 | L.ECApp (
|
adamc@261
|
1475 (L.ECApp (
|
adamc@261
|
1476 (L.ECApp (
|
adamc@261
|
1477 (L.EFfi ("Basis", "sql_order_by_Cons"), _),
|
adamc@261
|
1478 _), _),
|
adamc@261
|
1479 _), _),
|
adamc@261
|
1480 _) =>
|
adamc@261
|
1481 let
|
adamc@261
|
1482 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@261
|
1483 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@261
|
1484 in
|
adamc@268
|
1485 ((L'.EAbs ("e1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@268
|
1486 (L'.EAbs ("d", s, (L'.TFun (s, s), loc),
|
adamc@268
|
1487 (L'.EAbs ("e2", s, s,
|
adamc@268
|
1488 (L'.ECase ((L'.ERel 0, loc),
|
adamc@268
|
1489 [((L'.PPrim (Prim.String ""), loc),
|
adamc@598
|
1490 strcat [(L'.ERel 2, loc),
|
adamc@598
|
1491 (L'.ERel 1, loc)]),
|
adamc@268
|
1492 ((L'.PWild, loc),
|
adamc@598
|
1493 strcat [(L'.ERel 2, loc),
|
adamc@598
|
1494 (L'.ERel 1, loc),
|
adamc@598
|
1495 sc ", ",
|
adamc@598
|
1496 (L'.ERel 0, loc)])],
|
adamc@268
|
1497 {disc = s, result = s}), loc)), loc)), loc)), loc),
|
adamc@261
|
1498 fm)
|
adamc@261
|
1499 end
|
adamc@252
|
1500
|
adamc@252
|
1501 | L.EFfi ("Basis", "sql_no_limit") =>
|
adamc@252
|
1502 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@262
|
1503 | L.EFfiApp ("Basis", "sql_limit", [e]) =>
|
adamc@262
|
1504 let
|
adamc@262
|
1505 val (e, fm) = monoExp (env, st, fm) e
|
adamc@262
|
1506 in
|
adamc@598
|
1507 (strcat [
|
adamc@262
|
1508 (L'.EPrim (Prim.String " LIMIT "), loc),
|
adamc@262
|
1509 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@262
|
1510 ],
|
adamc@262
|
1511 fm)
|
adamc@262
|
1512 end
|
adamc@262
|
1513
|
adamc@252
|
1514 | L.EFfi ("Basis", "sql_no_offset") =>
|
adamc@252
|
1515 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@263
|
1516 | L.EFfiApp ("Basis", "sql_offset", [e]) =>
|
adamc@263
|
1517 let
|
adamc@263
|
1518 val (e, fm) = monoExp (env, st, fm) e
|
adamc@263
|
1519 in
|
adamc@598
|
1520 (strcat [
|
adamc@263
|
1521 (L'.EPrim (Prim.String " OFFSET "), loc),
|
adamc@263
|
1522 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@263
|
1523 ],
|
adamc@263
|
1524 fm)
|
adamc@263
|
1525 end
|
adamc@253
|
1526
|
adamc@559
|
1527 | L.ECApp ((L.EFfi ("Basis", "sql_eq"), _), _) =>
|
adamc@253
|
1528 ((L'.EPrim (Prim.String "="), loc), fm)
|
adamc@559
|
1529 | L.ECApp ((L.EFfi ("Basis", "sql_ne"), _), _) =>
|
adamc@253
|
1530 ((L'.EPrim (Prim.String "<>"), loc), fm)
|
adamc@559
|
1531 | L.ECApp ((L.EFfi ("Basis", "sql_lt"), _), _) =>
|
adamc@253
|
1532 ((L'.EPrim (Prim.String "<"), loc), fm)
|
adamc@559
|
1533 | L.ECApp ((L.EFfi ("Basis", "sql_le"), _), _) =>
|
adamc@253
|
1534 ((L'.EPrim (Prim.String "<="), loc), fm)
|
adamc@559
|
1535 | L.ECApp ((L.EFfi ("Basis", "sql_gt"), _), _) =>
|
adamc@253
|
1536 ((L'.EPrim (Prim.String ">"), loc), fm)
|
adamc@559
|
1537 | L.ECApp ((L.EFfi ("Basis", "sql_ge"), _), _) =>
|
adamc@253
|
1538 ((L'.EPrim (Prim.String ">="), loc), fm)
|
adamc@253
|
1539
|
adamc@559
|
1540 | L.ECApp ((L.EFfi ("Basis", "sql_plus"), _), _) =>
|
adamc@559
|
1541 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1542 (L'.EPrim (Prim.String "+"), loc)), loc), fm)
|
adamc@559
|
1543 | L.ECApp ((L.EFfi ("Basis", "sql_minus"), _), _) =>
|
adamc@559
|
1544 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1545 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@559
|
1546 | L.ECApp ((L.EFfi ("Basis", "sql_times"), _), _) =>
|
adamc@559
|
1547 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1548 (L'.EPrim (Prim.String "*"), loc)), loc), fm)
|
adamc@559
|
1549 | L.ECApp ((L.EFfi ("Basis", "sql_div"), _), _) =>
|
adamc@559
|
1550 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1551 (L'.EPrim (Prim.String "/"), loc)), loc), fm)
|
adamc@559
|
1552 | L.EFfi ("Basis", "sql_mod") =>
|
adamc@559
|
1553 ((L'.EPrim (Prim.String "%"), loc), fm)
|
adamc@559
|
1554
|
adamc@253
|
1555 | L.ECApp (
|
adamc@253
|
1556 (L.ECApp (
|
adamc@253
|
1557 (L.ECApp (
|
adamc@253
|
1558 (L.ECApp (
|
adamc@254
|
1559 (L.ECApp (
|
adamc@264
|
1560 (L.EFfi ("Basis", "sql_unary"), _),
|
adamc@264
|
1561 _), _),
|
adamc@264
|
1562 _), _),
|
adamc@264
|
1563 _), _),
|
adamc@264
|
1564 _), _),
|
adamc@264
|
1565 _) =>
|
adamc@264
|
1566 let
|
adamc@264
|
1567 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@264
|
1568 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@264
|
1569 in
|
adamc@264
|
1570 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@264
|
1571 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@598
|
1572 strcat [sc "(",
|
adamc@598
|
1573 (L'.ERel 1, loc),
|
adamc@598
|
1574 sc " ",
|
adamc@598
|
1575 (L'.ERel 0, loc),
|
adamc@598
|
1576 sc ")"]), loc)), loc),
|
adamc@264
|
1577 fm)
|
adamc@264
|
1578 end
|
adamc@264
|
1579 | L.EFfi ("Basis", "sql_not") => ((L'.EPrim (Prim.String "NOT"), loc), fm)
|
adamc@559
|
1580 | L.ECApp ((L.EFfi ("Basis", "sql_neg"), _), _) =>
|
adamc@559
|
1581 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1582 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@264
|
1583
|
adamc@264
|
1584 | L.ECApp (
|
adamc@264
|
1585 (L.ECApp (
|
adamc@264
|
1586 (L.ECApp (
|
adamc@264
|
1587 (L.ECApp (
|
adamc@264
|
1588 (L.ECApp (
|
adamc@254
|
1589 (L.ECApp (
|
adamc@254
|
1590 (L.EFfi ("Basis", "sql_binary"), _),
|
adamc@254
|
1591 _), _),
|
adamc@254
|
1592 _), _),
|
adamc@254
|
1593 _), _),
|
adamc@254
|
1594 _), _),
|
adamc@254
|
1595 _), _),
|
adamc@254
|
1596 _) =>
|
adamc@254
|
1597 let
|
adamc@254
|
1598 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@254
|
1599 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@254
|
1600 in
|
adamc@254
|
1601 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@254
|
1602 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@254
|
1603 (L'.EAbs ("e2", s, s,
|
adamc@598
|
1604 strcat [sc "(",
|
adamc@598
|
1605 (L'.ERel 1, loc),
|
adamc@598
|
1606 sc " ",
|
adamc@598
|
1607 (L'.ERel 2, loc),
|
adamc@598
|
1608 sc " ",
|
adamc@598
|
1609 (L'.ERel 0, loc),
|
adamc@598
|
1610 sc ")"]), loc)), loc)), loc),
|
adamc@254
|
1611 fm)
|
adamc@254
|
1612 end
|
adamc@254
|
1613 | L.EFfi ("Basis", "sql_and") => ((L'.EPrim (Prim.String "AND"), loc), fm)
|
adamc@254
|
1614 | L.EFfi ("Basis", "sql_or") => ((L'.EPrim (Prim.String "OR"), loc), fm)
|
adamc@254
|
1615
|
adamc@254
|
1616 | L.ECApp (
|
adamc@254
|
1617 (L.ECApp (
|
adamc@254
|
1618 (L.ECApp (
|
adamc@254
|
1619 (L.ECApp (
|
adamc@253
|
1620 (L.ECApp (
|
adamc@253
|
1621 (L.ECApp (
|
adamc@253
|
1622 (L.ECApp (
|
adamc@253
|
1623 (L.EFfi ("Basis", "sql_field"), _),
|
adamc@253
|
1624 _), _),
|
adamc@253
|
1625 _), _),
|
adamc@253
|
1626 _), _),
|
adamc@253
|
1627 _), _),
|
adamc@253
|
1628 _), _),
|
adamc@253
|
1629 (L.CName tab, _)), _),
|
adamc@311
|
1630 (L.CName field, _)) => ((L'.EPrim (Prim.String (tab ^ ".uw_" ^ field)), loc), fm)
|
adamc@260
|
1631
|
adamc@260
|
1632 | L.ECApp (
|
adamc@260
|
1633 (L.ECApp (
|
adamc@260
|
1634 (L.ECApp (
|
adamc@260
|
1635 (L.ECApp (
|
adamc@261
|
1636 (L.ECApp (
|
adamc@261
|
1637 (L.EFfi ("Basis", "sql_exp"), _),
|
adamc@261
|
1638 _), _),
|
adamc@261
|
1639 _), _),
|
adamc@261
|
1640 _), _),
|
adamc@261
|
1641 _), _),
|
adamc@261
|
1642 (L.CName nm, _)) => ((L'.EPrim (Prim.String ("_" ^ nm)), loc), fm)
|
adamc@261
|
1643
|
adamc@261
|
1644 | L.ECApp (
|
adamc@261
|
1645 (L.ECApp (
|
adamc@261
|
1646 (L.ECApp (
|
adamc@261
|
1647 (L.ECApp (
|
adamc@260
|
1648 (L.EFfi ("Basis", "sql_relop"), _),
|
adamc@260
|
1649 _), _),
|
adamc@260
|
1650 _), _),
|
adamc@260
|
1651 _), _),
|
adamc@260
|
1652 _) =>
|
adamc@260
|
1653 let
|
adamc@260
|
1654 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@260
|
1655 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@260
|
1656 in
|
adamc@260
|
1657 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@260
|
1658 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@260
|
1659 (L'.EAbs ("e2", s, s,
|
adamc@598
|
1660 strcat [sc "((",
|
adamc@598
|
1661 (L'.ERel 1, loc),
|
adamc@598
|
1662 sc ") ",
|
adamc@598
|
1663 (L'.ERel 2, loc),
|
adamc@598
|
1664 sc " (",
|
adamc@598
|
1665 (L'.ERel 0, loc),
|
adamc@598
|
1666 sc "))"]), loc)), loc)), loc),
|
adamc@260
|
1667 fm)
|
adamc@260
|
1668 end
|
adamc@260
|
1669
|
adamc@260
|
1670 | L.EFfi ("Basis", "sql_union") => ((L'.EPrim (Prim.String "UNION"), loc), fm)
|
adamc@260
|
1671 | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm)
|
adamc@260
|
1672 | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)
|
adamc@260
|
1673
|
adamc@265
|
1674 | L.ECApp (
|
adamc@265
|
1675 (L.ECApp (
|
adamc@265
|
1676 (L.ECApp (
|
adamc@265
|
1677 (L.EFfi ("Basis", "sql_count"), _),
|
adamc@265
|
1678 _), _),
|
adamc@265
|
1679 _), _),
|
adamc@544
|
1680 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc),
|
adamc@265
|
1681 fm)
|
adamc@266
|
1682
|
adamc@266
|
1683 | L.ECApp (
|
adamc@266
|
1684 (L.ECApp (
|
adamc@266
|
1685 (L.ECApp (
|
adamc@266
|
1686 (L.ECApp (
|
adamc@266
|
1687 (L.EFfi ("Basis", "sql_aggregate"), _),
|
adamc@266
|
1688 _), _),
|
adamc@266
|
1689 _), _),
|
adamc@266
|
1690 _), _),
|
adamc@266
|
1691 _) =>
|
adamc@266
|
1692 let
|
adamc@266
|
1693 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@266
|
1694 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@266
|
1695 in
|
adamc@266
|
1696 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@266
|
1697 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@598
|
1698 strcat [(L'.ERel 1, loc),
|
adamc@598
|
1699 sc "(",
|
adamc@598
|
1700 (L'.ERel 0, loc),
|
adamc@598
|
1701 sc ")"]), loc)), loc),
|
adamc@266
|
1702 fm)
|
adamc@266
|
1703 end
|
adamc@266
|
1704
|
adamc@266
|
1705 | L.EFfi ("Basis", "sql_summable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1706 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1707 | L.ECApp ((L.EFfi ("Basis", "sql_avg"), _), _) =>
|
adamc@266
|
1708 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1709 (L'.EPrim (Prim.String "AVG"), loc)), loc),
|
adamc@266
|
1710 fm)
|
adamc@266
|
1711 | L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _) =>
|
adamc@266
|
1712 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1713 (L'.EPrim (Prim.String "SUM"), loc)), loc),
|
adamc@266
|
1714 fm)
|
adamc@266
|
1715
|
adamc@559
|
1716 | L.EFfi ("Basis", "sql_arith_int") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
1717 | L.EFfi ("Basis", "sql_arith_float") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
1718
|
adamc@266
|
1719 | L.EFfi ("Basis", "sql_maxable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1720 | L.EFfi ("Basis", "sql_maxable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1721 | L.EFfi ("Basis", "sql_maxable_string") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1722 | L.ECApp ((L.EFfi ("Basis", "sql_max"), _), _) =>
|
adamc@266
|
1723 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1724 (L'.EPrim (Prim.String "MAX"), loc)), loc),
|
adamc@266
|
1725 fm)
|
adamc@266
|
1726 | L.ECApp ((L.EFfi ("Basis", "sql_min"), _), _) =>
|
adamc@266
|
1727 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1728 (L'.EPrim (Prim.String "MIN"), loc)), loc),
|
adamc@266
|
1729 fm)
|
adamc@266
|
1730
|
adamc@268
|
1731 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@268
|
1732 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
|
adamc@268
|
1733
|
adamc@441
|
1734 | L.ECApp (
|
adamc@441
|
1735 (L.ECApp (
|
adamc@441
|
1736 (L.ECApp (
|
adamc@441
|
1737 (L.ECApp (
|
adamc@441
|
1738 (L.EFfi ("Basis", "sql_nfunc"), _),
|
adamc@441
|
1739 _), _),
|
adamc@441
|
1740 _), _),
|
adamc@441
|
1741 _), _),
|
adamc@441
|
1742 _) =>
|
adamc@441
|
1743 let
|
adamc@441
|
1744 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@441
|
1745 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@441
|
1746 in
|
adamc@441
|
1747 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc),
|
adamc@441
|
1748 fm)
|
adamc@441
|
1749 end
|
adamc@441
|
1750 | L.EFfi ("Basis", "sql_current_timestamp") => ((L'.EPrim (Prim.String "CURRENT_TIMESTAMP"), loc), fm)
|
adamc@441
|
1751
|
adamc@470
|
1752 | (L.ECApp (
|
adamc@470
|
1753 (L.ECApp (
|
adamc@470
|
1754 (L.ECApp (
|
adamc@470
|
1755 (L.ECApp (
|
adamc@470
|
1756 (L.EFfi ("Basis", "sql_is_null"), _), _),
|
adamc@470
|
1757 _), _),
|
adamc@470
|
1758 _), _),
|
adamc@470
|
1759 _), _)) =>
|
adamc@470
|
1760 let
|
adamc@470
|
1761 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@470
|
1762 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@470
|
1763 in
|
adamc@470
|
1764 ((L'.EAbs ("s", s, s,
|
adamc@598
|
1765 strcat [sc "(",
|
adamc@598
|
1766 (L'.ERel 0, loc),
|
adamc@598
|
1767 sc " IS NULL)"]), loc),
|
adamc@470
|
1768 fm)
|
adamc@470
|
1769 end
|
adamc@470
|
1770
|
adamc@338
|
1771 | L.EFfiApp ("Basis", "nextval", [e]) =>
|
adamc@338
|
1772 let
|
adamc@338
|
1773 val (e, fm) = monoExp (env, st, fm) e
|
adamc@338
|
1774 in
|
adamc@465
|
1775 ((L'.ENextval e, loc), fm)
|
adamc@338
|
1776 end
|
adamc@338
|
1777
|
adamc@139
|
1778 | L.EApp (
|
adamc@139
|
1779 (L.ECApp (
|
adamc@141
|
1780 (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _),
|
adamc@139
|
1781 _), _),
|
adamc@179
|
1782 se) =>
|
adamc@179
|
1783 let
|
adamc@179
|
1784 val (se, fm) = monoExp (env, st, fm) se
|
adamc@179
|
1785 in
|
adamc@179
|
1786 ((L'.EFfiApp ("Basis", "htmlifyString", [se]), loc), fm)
|
adamc@179
|
1787 end
|
adamc@179
|
1788
|
adamc@95
|
1789 | L.EApp (
|
adamc@95
|
1790 (L.EApp (
|
adamc@95
|
1791 (L.ECApp (
|
adamc@95
|
1792 (L.ECApp (
|
adamc@95
|
1793 (L.ECApp (
|
adamc@139
|
1794 (L.ECApp (
|
adamc@140
|
1795 (L.EFfi ("Basis", "join"),
|
adamc@139
|
1796 _), _), _),
|
adamc@139
|
1797 _), _),
|
adamc@95
|
1798 _), _),
|
adamc@95
|
1799 _), _),
|
adamc@95
|
1800 xml1), _),
|
adamc@179
|
1801 xml2) =>
|
adamc@179
|
1802 let
|
adamc@179
|
1803 val (xml1, fm) = monoExp (env, st, fm) xml1
|
adamc@179
|
1804 val (xml2, fm) = monoExp (env, st, fm) xml2
|
adamc@179
|
1805 in
|
adamc@179
|
1806 ((L'.EStrcat (xml1, xml2), loc), fm)
|
adamc@179
|
1807 end
|
adamc@95
|
1808
|
adamc@95
|
1809 | L.EApp (
|
adamc@95
|
1810 (L.EApp (
|
adamc@104
|
1811 (L.EApp (
|
adamc@95
|
1812 (L.ECApp (
|
adamc@104
|
1813 (L.ECApp (
|
adamc@104
|
1814 (L.ECApp (
|
adamc@104
|
1815 (L.ECApp (
|
adamc@139
|
1816 (L.ECApp (
|
adamc@139
|
1817 (L.ECApp (
|
adamc@139
|
1818 (L.ECApp (
|
adamc@139
|
1819 (L.ECApp (
|
adamc@139
|
1820 (L.EFfi ("Basis", "tag"),
|
adamc@139
|
1821 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@104
|
1822 attrs), _),
|
adamc@95
|
1823 tag), _),
|
adamc@95
|
1824 xml) =>
|
adamc@95
|
1825 let
|
adamc@140
|
1826 fun getTag' (e, _) =
|
adamc@140
|
1827 case e of
|
adamc@143
|
1828 L.EFfi ("Basis", tag) => (tag, [])
|
adamc@143
|
1829 | L.ECApp (e, t) => let
|
adamc@143
|
1830 val (tag, ts) = getTag' e
|
adamc@143
|
1831 in
|
adamc@143
|
1832 (tag, ts @ [t])
|
adamc@143
|
1833 end
|
adamc@140
|
1834 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@140
|
1835 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
1836 ("", []))
|
adamc@140
|
1837
|
adamc@95
|
1838 fun getTag (e, _) =
|
adamc@95
|
1839 case e of
|
adamc@143
|
1840 L.EFfiApp ("Basis", tag, [(L.ERecord [], _)]) => (tag, [])
|
adamc@140
|
1841 | L.EApp (e, (L.ERecord [], _)) => getTag' e
|
adamc@95
|
1842 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@95
|
1843 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
1844 ("", []))
|
adamc@95
|
1845
|
adamc@143
|
1846 val (tag, targs) = getTag tag
|
adamc@95
|
1847
|
adamc@179
|
1848 val (attrs, fm) = monoExp (env, st, fm) attrs
|
adamc@598
|
1849 val attrs = case #1 attrs of
|
adamc@598
|
1850 L'.ERecord xes => xes
|
adamc@598
|
1851 | _ => raise Fail "Non-record attributes!"
|
adamc@104
|
1852
|
adamc@668
|
1853 fun findOnload (attrs, acc) =
|
adamc@668
|
1854 case attrs of
|
adamc@668
|
1855 [] => (NONE, acc)
|
adamc@668
|
1856 | ("Onload", e, _) :: rest => (SOME e, List.revAppend (acc, rest))
|
adamc@668
|
1857 | x :: rest => findOnload (rest, x :: acc)
|
adamc@679
|
1858
|
adamc@668
|
1859 val (onload, attrs) = findOnload (attrs, [])
|
adamc@668
|
1860
|
adamc@606
|
1861 fun lowercaseFirst "" = ""
|
adamc@606
|
1862 | lowercaseFirst s = String.str (Char.toLower (String.sub (s, 0)))
|
adamc@606
|
1863 ^ String.extract (s, 1, NONE)
|
adamc@606
|
1864
|
adamc@143
|
1865 fun tagStart tag =
|
adamc@598
|
1866 let
|
adamc@598
|
1867 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@598
|
1868 in
|
adamc@598
|
1869 foldl (fn (("Action", _, _), acc) => acc
|
adamc@598
|
1870 | (("Source", _, _), acc) => acc
|
adamc@598
|
1871 | ((x, e, t), (s, fm)) =>
|
adamc@598
|
1872 case t of
|
adamc@598
|
1873 (L'.TFfi ("Basis", "bool"), _) =>
|
adamc@598
|
1874 let
|
adamc@598
|
1875 val s' = " " ^ lowercaseFirst x
|
adamc@598
|
1876 in
|
adamc@598
|
1877 ((L'.ECase (e,
|
adamc@598
|
1878 [((L'.PCon (L'.Enum,
|
adamc@598
|
1879 L'.PConFfi {mod = "Basis",
|
adamc@598
|
1880 datatyp = "bool",
|
adamc@598
|
1881 con = "True",
|
adamc@598
|
1882 arg = NONE},
|
adamc@598
|
1883 NONE), loc),
|
adamc@598
|
1884 (L'.EStrcat (s,
|
adamc@598
|
1885 (L'.EPrim (Prim.String s'), loc)), loc)),
|
adamc@598
|
1886 ((L'.PCon (L'.Enum,
|
adamc@598
|
1887 L'.PConFfi {mod = "Basis",
|
adamc@598
|
1888 datatyp = "bool",
|
adamc@598
|
1889 con = "False",
|
adamc@598
|
1890 arg = NONE},
|
adamc@598
|
1891 NONE), loc),
|
adamc@598
|
1892 s)],
|
adamc@598
|
1893 {disc = (L'.TFfi ("Basis", "bool"), loc),
|
adamc@598
|
1894 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@598
|
1895 fm)
|
adamc@598
|
1896 end
|
adamc@598
|
1897 | (L'.TFun _, _) =>
|
adamc@598
|
1898 let
|
adamc@598
|
1899 val s' = " " ^ lowercaseFirst x ^ "='"
|
adamc@651
|
1900 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
|
adamc@598
|
1901 in
|
adamc@598
|
1902 ((L'.EStrcat (s,
|
adamc@598
|
1903 (L'.EStrcat (
|
adamc@598
|
1904 (L'.EPrim (Prim.String s'), loc),
|
adamc@598
|
1905 (L'.EStrcat (
|
adamc@598
|
1906 (L'.EJavaScript (L'.Attribute, e, NONE), loc),
|
adamc@598
|
1907 (L'.EPrim (Prim.String "'"), loc)), loc)),
|
adamc@598
|
1908 loc)), loc),
|
adamc@598
|
1909 fm)
|
adamc@598
|
1910 end
|
adamc@598
|
1911 | _ =>
|
adamc@598
|
1912 let
|
adamc@598
|
1913 val fooify =
|
adamc@598
|
1914 case x of
|
adamc@598
|
1915 "Href" => urlifyExp
|
adamc@598
|
1916 | "Link" => urlifyExp
|
adamc@598
|
1917 | _ => attrifyExp
|
adamc@120
|
1918
|
adamc@598
|
1919 val xp = " " ^ lowercaseFirst x ^ "=\""
|
adamc@179
|
1920
|
adamc@598
|
1921 val (e, fm) = fooify env fm (e, t)
|
adamc@598
|
1922 in
|
adamc@598
|
1923 ((L'.EStrcat (s,
|
adamc@598
|
1924 (L'.EStrcat ((L'.EPrim (Prim.String xp), loc),
|
adamc@598
|
1925 (L'.EStrcat (e,
|
adamc@598
|
1926 (L'.EPrim (Prim.String "\""),
|
adamc@598
|
1927 loc)),
|
adamc@598
|
1928 loc)),
|
adamc@598
|
1929 loc)), loc),
|
adamc@598
|
1930 fm)
|
adamc@598
|
1931 end)
|
adamc@598
|
1932 (s, fm) attrs
|
adamc@598
|
1933 end
|
adamc@104
|
1934
|
adamc@143
|
1935 fun input typ =
|
adamc@143
|
1936 case targs of
|
adamc@155
|
1937 [_, (L.CName name, _)] =>
|
adamc@179
|
1938 let
|
adamc@179
|
1939 val (ts, fm) = tagStart "input"
|
adamc@179
|
1940 in
|
adamc@179
|
1941 ((L'.EStrcat (ts,
|
adamc@179
|
1942 (L'.EPrim (Prim.String (" type=\"" ^ typ ^ "\" name=\"" ^ name ^ "\"/>")),
|
adamc@179
|
1943 loc)), loc), fm)
|
adamc@179
|
1944 end
|
adamc@143
|
1945 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
1946 raise Fail "No name passed to input tag")
|
adamc@104
|
1947
|
adamc@565
|
1948 fun normal (tag, extra, extraInner) =
|
adamc@143
|
1949 let
|
adamc@179
|
1950 val (tagStart, fm) = tagStart tag
|
adamc@152
|
1951 val tagStart = case extra of
|
adamc@152
|
1952 NONE => tagStart
|
adamc@152
|
1953 | SOME extra => (L'.EStrcat (tagStart, extra), loc)
|
adamc@152
|
1954
|
adamc@143
|
1955 fun normal () =
|
adamc@179
|
1956 let
|
adamc@179
|
1957 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@565
|
1958 val xml = case extraInner of
|
adamc@679
|
1959 NONE => xml
|
adamc@679
|
1960 | SOME ei => (L'.EStrcat (ei, xml), loc)
|
adamc@179
|
1961 in
|
adamc@179
|
1962 ((L'.EStrcat ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String ">"), loc)), loc),
|
adamc@179
|
1963 (L'.EStrcat (xml,
|
adamc@179
|
1964 (L'.EPrim (Prim.String (String.concat ["</", tag, ">"])),
|
adamc@179
|
1965 loc)), loc)),
|
adamc@179
|
1966 loc),
|
adamc@179
|
1967 fm)
|
adamc@179
|
1968 end
|
adamc@143
|
1969 in
|
adamc@143
|
1970 case xml of
|
adamc@143
|
1971 (L.EApp ((L.ECApp (
|
adamc@143
|
1972 (L.ECApp ((L.EFfi ("Basis", "cdata"), _),
|
adamc@143
|
1973 _), _),
|
adamc@143
|
1974 _), _),
|
adamc@143
|
1975 (L.EPrim (Prim.String s), _)), _) =>
|
adamc@143
|
1976 if CharVector.all Char.isSpace s then
|
adamc@179
|
1977 ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String "/>"), loc)), loc), fm)
|
adamc@143
|
1978 else
|
adamc@143
|
1979 normal ()
|
adamc@143
|
1980 | _ => normal ()
|
adamc@143
|
1981 end
|
adamc@606
|
1982
|
adamc@606
|
1983 fun setAttrs jexp =
|
adamc@606
|
1984 let
|
adamc@606
|
1985 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@606
|
1986
|
adamc@606
|
1987 val assgns = List.mapPartial
|
adamc@606
|
1988 (fn ("Source", _, _) => NONE
|
adamc@606
|
1989 | (x, e, _) =>
|
adamc@606
|
1990 SOME (strcat [str ("d." ^ lowercaseFirst x ^ "="),
|
adamc@606
|
1991 (L'.EJavaScript (L'.Script, e, NONE), loc),
|
adamc@606
|
1992 str ";"]))
|
adamc@606
|
1993 attrs
|
adamc@606
|
1994 in
|
adamc@606
|
1995 case assgns of
|
adamc@606
|
1996 [] => jexp
|
adamc@606
|
1997 | _ => strcat (str "var d="
|
adamc@606
|
1998 :: jexp
|
adamc@606
|
1999 :: str ";"
|
adamc@606
|
2000 :: assgns)
|
adamc@606
|
2001 end
|
adamc@152
|
2002 in
|
adamc@152
|
2003 case tag of
|
adamc@679
|
2004 "body" => let
|
adamc@668
|
2005 val onload = case onload of
|
adamc@668
|
2006 NONE => (L'.EPrim (Prim.String ""), loc)
|
adamc@668
|
2007 | SOME e =>
|
adamc@668
|
2008 let
|
adamc@668
|
2009 val e = (L'.EApp (e, (L'.ERecord [], loc)), loc)
|
adamc@668
|
2010 in
|
adamc@668
|
2011 (L'.EJavaScript (L'.Attribute, e, NONE), loc)
|
adamc@679
|
2012 end
|
adamc@668
|
2013 in
|
adamc@668
|
2014 normal ("body",
|
adamc@694
|
2015 SOME (L'.EStrcat ((L'.EPrim (Prim.String " onload='"), loc),
|
adamc@694
|
2016 (L'.EStrcat ((L'.EFfiApp ("Basis", "get_settings",
|
adamc@694
|
2017 [(L'.ERecord [], loc)]), loc),
|
adamc@694
|
2018 (L'.EStrcat (onload,
|
adamc@694
|
2019 (L'.EPrim (Prim.String "'"),
|
adamc@694
|
2020 loc)), loc)), loc)), loc),
|
adamc@668
|
2021 SOME (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]), loc))
|
adamc@668
|
2022 end
|
adamc@568
|
2023
|
adamc@568
|
2024 | "dyn" =>
|
adamc@598
|
2025 (case attrs of
|
adamc@598
|
2026 [("Signal", (L'.EApp ((L'.EAbs (_, _, _, (L'.ESignalReturn (L'.ERel 0, _), _)), _),
|
adamc@598
|
2027 e), _), _)] => (e, fm)
|
adamc@598
|
2028 | [("Signal", e, _)] =>
|
adamc@568
|
2029 ((L'.EStrcat
|
adamc@603
|
2030 ((L'.EPrim (Prim.String "<span><script type=\"text/javascript\">dyn("), loc),
|
adamc@578
|
2031 (L'.EStrcat ((L'.EJavaScript (L'.Script, e, NONE), loc),
|
adamc@603
|
2032 (L'.EPrim (Prim.String ")</script></span>"), loc)), loc)), loc),
|
adamc@568
|
2033 fm)
|
adamc@568
|
2034 | _ => raise Fail "Monoize: Bad dyn attributes")
|
adamc@565
|
2035
|
adamc@565
|
2036 | "submit" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@601
|
2037 | "button" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@152
|
2038
|
adamc@152
|
2039 | "textbox" =>
|
adamc@152
|
2040 (case targs of
|
adamc@152
|
2041 [_, (L.CName name, _)] =>
|
adamc@598
|
2042 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@598
|
2043 NONE =>
|
adamc@598
|
2044 let
|
adamc@598
|
2045 val (ts, fm) = tagStart "input"
|
adamc@598
|
2046 in
|
adamc@598
|
2047 ((L'.EStrcat (ts,
|
adamc@598
|
2048 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\"/>")),
|
adamc@598
|
2049 loc)), loc), fm)
|
adamc@598
|
2050 end
|
adamc@598
|
2051 | SOME (_, src, _) =>
|
adamc@646
|
2052 (strcat [str "<span><script type=\"text/javascript\">inp(\"input\",",
|
adamc@598
|
2053 (L'.EJavaScript (L'.Script, src, NONE), loc),
|
adamc@646
|
2054 str ")</script></span>"],
|
adamc@598
|
2055 fm))
|
adamc@152
|
2056 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@598
|
2057 raise Fail "No name passed to textbox tag"))
|
adamc@155
|
2058 | "password" => input "password"
|
adamc@361
|
2059 | "textarea" =>
|
adamc@152
|
2060 (case targs of
|
adamc@152
|
2061 [_, (L.CName name, _)] =>
|
adamc@179
|
2062 let
|
adamc@179
|
2063 val (ts, fm) = tagStart "textarea"
|
adamc@179
|
2064 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
2065 in
|
adamc@179
|
2066 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@179
|
2067 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")), loc)), loc),
|
adamc@179
|
2068 (L'.EStrcat (xml,
|
adamc@179
|
2069 (L'.EPrim (Prim.String "</textarea>"),
|
adamc@179
|
2070 loc)), loc)),
|
adamc@179
|
2071 loc), fm)
|
adamc@179
|
2072 end
|
adamc@152
|
2073 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
2074 raise Fail "No name passed to ltextarea tag"))
|
adamc@153
|
2075
|
adamc@190
|
2076 | "checkbox" => input "checkbox"
|
adamc@190
|
2077
|
adamc@153
|
2078 | "radio" =>
|
adamc@153
|
2079 (case targs of
|
adamc@153
|
2080 [_, (L.CName name, _)] =>
|
adamc@179
|
2081 monoExp (env, St.setRadioGroup (st, name), fm) xml
|
adamc@153
|
2082 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
2083 raise Fail "No name passed to radio tag"))
|
adamc@153
|
2084 | "radioOption" =>
|
adamc@153
|
2085 (case St.radioGroup st of
|
adamc@153
|
2086 NONE => raise Fail "No name for radioGroup"
|
adamc@153
|
2087 | SOME name =>
|
adamc@153
|
2088 normal ("input",
|
adamc@565
|
2089 SOME (L'.EPrim (Prim.String (" type=\"radio\" name=\"" ^ name ^ "\"")), loc),
|
adamc@565
|
2090 NONE))
|
adamc@152
|
2091
|
adamc@361
|
2092 | "select" =>
|
adamc@154
|
2093 (case targs of
|
adamc@154
|
2094 [_, (L.CName name, _)] =>
|
adamc@179
|
2095 let
|
adamc@179
|
2096 val (ts, fm) = tagStart "select"
|
adamc@179
|
2097 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
2098 in
|
adamc@179
|
2099 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@598
|
2100 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")),
|
adamc@598
|
2101 loc)), loc),
|
adamc@179
|
2102 (L'.EStrcat (xml,
|
adamc@179
|
2103 (L'.EPrim (Prim.String "</select>"),
|
adamc@179
|
2104 loc)), loc)),
|
adamc@179
|
2105 loc),
|
adamc@179
|
2106 fm)
|
adamc@179
|
2107 end
|
adamc@154
|
2108 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@154
|
2109 raise Fail "No name passed to lselect tag"))
|
adamc@154
|
2110
|
adamc@601
|
2111 | "ctextbox" =>
|
adamc@601
|
2112 (case List.find (fn ("Source", _, _) => true | _ => false) attrs of
|
adamc@601
|
2113 NONE =>
|
adamc@601
|
2114 let
|
adamc@601
|
2115 val (ts, fm) = tagStart "input"
|
adamc@601
|
2116 in
|
adamc@601
|
2117 ((L'.EStrcat (ts,
|
adamc@601
|
2118 (L'.EPrim (Prim.String "/>"), loc)),
|
adamc@601
|
2119 loc), fm)
|
adamc@601
|
2120 end
|
adamc@601
|
2121 | SOME (_, src, _) =>
|
adamc@606
|
2122 let
|
adamc@606
|
2123 val sc = strcat [str "inp(\"input\",",
|
adamc@606
|
2124 (L'.EJavaScript (L'.Script, src, NONE), loc),
|
adamc@606
|
2125 str ")"]
|
adamc@606
|
2126 val sc = setAttrs sc
|
adamc@606
|
2127 in
|
adamc@646
|
2128 (strcat [str "<span><script type=\"text/javascript\">",
|
adamc@606
|
2129 sc,
|
adamc@646
|
2130 str "</script></span>"],
|
adamc@606
|
2131 fm)
|
adamc@606
|
2132 end)
|
adamc@154
|
2133
|
adamc@565
|
2134 | "tabl" => normal ("table", NONE, NONE)
|
adamc@565
|
2135 | _ => normal (tag, NONE, NONE)
|
adamc@95
|
2136 end
|
adamc@94
|
2137
|
adamc@141
|
2138 | L.EApp ((L.ECApp (
|
adamc@361
|
2139 (L.ECApp ((L.EFfi ("Basis", "form"), _), _), _),
|
adamc@141
|
2140 _), _),
|
adamc@141
|
2141 xml) =>
|
adamc@143
|
2142 let
|
adamc@143
|
2143 fun findSubmit (e, _) =
|
adamc@143
|
2144 case e of
|
adamc@143
|
2145 L.EApp (
|
adamc@143
|
2146 (L.EApp (
|
adamc@143
|
2147 (L.ECApp (
|
adamc@143
|
2148 (L.ECApp (
|
adamc@143
|
2149 (L.ECApp (
|
adamc@143
|
2150 (L.ECApp (
|
adamc@143
|
2151 (L.EFfi ("Basis", "join"),
|
adamc@143
|
2152 _), _), _),
|
adamc@143
|
2153 _), _),
|
adamc@143
|
2154 _), _),
|
adamc@143
|
2155 _), _),
|
adamc@143
|
2156 xml1), _),
|
adamc@143
|
2157 xml2) => (case findSubmit xml1 of
|
adamc@143
|
2158 Error => Error
|
adamc@143
|
2159 | NotFound => findSubmit xml2
|
adamc@143
|
2160 | Found e =>
|
adamc@143
|
2161 case findSubmit xml2 of
|
adamc@143
|
2162 NotFound => Found e
|
adamc@143
|
2163 | _ => Error)
|
adamc@143
|
2164 | L.EApp (
|
adamc@143
|
2165 (L.EApp (
|
adamc@143
|
2166 (L.EApp (
|
adamc@143
|
2167 (L.ECApp (
|
adamc@143
|
2168 (L.ECApp (
|
adamc@143
|
2169 (L.ECApp (
|
adamc@143
|
2170 (L.ECApp (
|
adamc@143
|
2171 (L.ECApp (
|
adamc@143
|
2172 (L.ECApp (
|
adamc@143
|
2173 (L.ECApp (
|
adamc@143
|
2174 (L.ECApp (
|
adamc@143
|
2175 (L.EFfi ("Basis", "tag"),
|
adamc@143
|
2176 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@143
|
2177 attrs), _),
|
adamc@143
|
2178 _), _),
|
adamc@143
|
2179 xml) =>
|
adamc@143
|
2180 (case #1 attrs of
|
adamc@143
|
2181 L.ERecord xes =>
|
adamc@143
|
2182 (case ListUtil.search (fn ((L.CName "Action", _), e, t) => SOME (e, t)
|
adamc@143
|
2183 | _ => NONE) xes of
|
adamc@143
|
2184 NONE => findSubmit xml
|
adamc@143
|
2185 | SOME et =>
|
adamc@143
|
2186 case findSubmit xml of
|
adamc@143
|
2187 NotFound => Found et
|
adamc@143
|
2188 | _ => Error)
|
adamc@143
|
2189 | _ => findSubmit xml)
|
adamc@143
|
2190 | _ => NotFound
|
adamc@143
|
2191
|
adamc@598
|
2192 val (action, fm) = case findSubmit xml of
|
adamc@598
|
2193 NotFound => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@143
|
2194 | Error => raise Fail "Not ready for multi-submit lforms yet"
|
adamc@598
|
2195 | Found (action, actionT) =>
|
adamc@598
|
2196 let
|
adamc@598
|
2197 val actionT = monoType env actionT
|
adamc@598
|
2198 val (action, fm) = monoExp (env, st, fm) action
|
adamc@598
|
2199 val (action, fm) = urlifyExp env fm (action, actionT)
|
adamc@598
|
2200 in
|
adamc@598
|
2201 ((L'.EStrcat ((L'.EPrim (Prim.String " action=\""), loc),
|
adamc@598
|
2202 (L'.EStrcat (action,
|
adamc@598
|
2203 (L'.EPrim (Prim.String "\""), loc)), loc)), loc),
|
adamc@598
|
2204 fm)
|
adamc@598
|
2205 end
|
adamc@598
|
2206
|
adamc@179
|
2207 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@143
|
2208 in
|
adamc@598
|
2209 ((L'.EStrcat ((L'.EStrcat ((L'.EPrim (Prim.String "<form"), loc),
|
adamc@179
|
2210 (L'.EStrcat (action,
|
adamc@598
|
2211 (L'.EPrim (Prim.String ">"), loc)), loc)), loc),
|
adamc@179
|
2212 (L'.EStrcat (xml,
|
adamc@179
|
2213 (L'.EPrim (Prim.String "</form>"), loc)), loc)), loc),
|
adamc@179
|
2214 fm)
|
adamc@143
|
2215 end
|
adamc@141
|
2216
|
adamc@148
|
2217 | L.EApp ((L.ECApp (
|
adamc@148
|
2218 (L.ECApp (
|
adamc@148
|
2219 (L.ECApp (
|
adamc@148
|
2220 (L.ECApp (
|
adamc@148
|
2221 (L.EFfi ("Basis", "useMore"), _), _), _),
|
adamc@148
|
2222 _), _),
|
adamc@148
|
2223 _), _),
|
adamc@148
|
2224 _), _),
|
adamc@179
|
2225 xml) => monoExp (env, st, fm) xml
|
adamc@148
|
2226
|
adamc@283
|
2227 | L.ECApp ((L.EFfi ("Basis", "error"), _), t) =>
|
adamc@283
|
2228 let
|
adamc@283
|
2229 val t = monoType env t
|
adamc@283
|
2230 in
|
adamc@283
|
2231 ((L'.EAbs ("s", (L'.TFfi ("Basis", "string"), loc), t,
|
adamc@283
|
2232 (L'.EError ((L'.ERel 0, loc), t), loc)), loc),
|
adamc@283
|
2233 fm)
|
adamc@283
|
2234 end
|
adamc@283
|
2235
|
adamc@179
|
2236 | L.EApp (e1, e2) =>
|
adamc@179
|
2237 let
|
adamc@179
|
2238 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@179
|
2239 val (e2, fm) = monoExp (env, st, fm) e2
|
adamc@179
|
2240 in
|
adamc@179
|
2241 ((L'.EApp (e1, e2), loc), fm)
|
adamc@179
|
2242 end
|
adamc@26
|
2243 | L.EAbs (x, dom, ran, e) =>
|
adamc@179
|
2244 let
|
adamc@179
|
2245 val (e, fm) = monoExp (Env.pushERel env x dom, st, fm) e
|
adamc@179
|
2246 in
|
adamc@179
|
2247 ((L'.EAbs (x, monoType env dom, monoType env ran, e), loc), fm)
|
adamc@179
|
2248 end
|
adamc@25
|
2249 | L.ECApp _ => poly ()
|
adamc@25
|
2250 | L.ECAbs _ => poly ()
|
adamc@25
|
2251
|
adamc@252
|
2252 | L.EFfi mx => ((L'.EFfi mx, loc), fm)
|
adamc@252
|
2253 | L.EFfiApp (m, x, es) =>
|
adamc@252
|
2254 let
|
adamc@252
|
2255 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@252
|
2256 in
|
adamc@252
|
2257 ((L'.EFfiApp (m, x, es), loc), fm)
|
adamc@252
|
2258 end
|
adamc@252
|
2259
|
adamc@179
|
2260 | L.ERecord xes =>
|
adamc@179
|
2261 let
|
adamc@179
|
2262 val (xes, fm) = ListUtil.foldlMap
|
adamc@179
|
2263 (fn ((x, e, t), fm) =>
|
adamc@179
|
2264 let
|
adamc@179
|
2265 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2266 in
|
adamc@179
|
2267 ((monoName env x,
|
adamc@179
|
2268 e,
|
adamc@179
|
2269 monoType env t), fm)
|
adamc@179
|
2270 end) fm xes
|
adamc@179
|
2271 in
|
adamc@179
|
2272 ((L'.ERecord xes, loc), fm)
|
adamc@179
|
2273 end
|
adamc@179
|
2274 | L.EField (e, x, _) =>
|
adamc@179
|
2275 let
|
adamc@179
|
2276 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2277 in
|
adamc@179
|
2278 ((L'.EField (e, monoName env x), loc), fm)
|
adamc@179
|
2279 end
|
adamc@445
|
2280 | L.EConcat _ => poly ()
|
adamc@149
|
2281 | L.ECut _ => poly ()
|
adamc@493
|
2282 | L.ECutMulti _ => poly ()
|
adamc@177
|
2283
|
adamc@182
|
2284 | L.ECase (e, pes, {disc, result}) =>
|
adamc@179
|
2285 let
|
adamc@179
|
2286 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2287 val (pes, fm) = ListUtil.foldlMap
|
adamc@179
|
2288 (fn ((p, e), fm) =>
|
adamc@179
|
2289 let
|
adamc@179
|
2290 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2291 in
|
adamc@182
|
2292 ((monoPat env p, e), fm)
|
adamc@179
|
2293 end) fm pes
|
adamc@179
|
2294 in
|
adamc@182
|
2295 ((L'.ECase (e, pes, {disc = monoType env disc, result = monoType env result}), loc), fm)
|
adamc@179
|
2296 end
|
adamc@177
|
2297
|
adamc@179
|
2298 | L.EWrite e =>
|
adamc@179
|
2299 let
|
adamc@179
|
2300 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2301 in
|
adamc@252
|
2302 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@252
|
2303 (L'.EWrite (liftExpInExp 0 e), loc)), loc), fm)
|
adamc@179
|
2304 end
|
adamc@110
|
2305
|
adamc@179
|
2306 | L.EClosure (n, es) =>
|
adamc@179
|
2307 let
|
adamc@179
|
2308 val (es, fm) = ListUtil.foldlMap (fn (e, fm) =>
|
adamc@179
|
2309 monoExp (env, st, fm) e)
|
adamc@179
|
2310 fm es
|
adamc@179
|
2311 in
|
adamc@179
|
2312 ((L'.EClosure (n, es), loc), fm)
|
adamc@179
|
2313 end
|
adamc@450
|
2314
|
adamc@450
|
2315 | L.ELet (x, t, e1, e2) =>
|
adamc@450
|
2316 let
|
adamc@450
|
2317 val t' = monoType env t
|
adamc@450
|
2318 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@450
|
2319 val (e2, fm) = monoExp (Env.pushERel env x t, st, fm) e2
|
adamc@450
|
2320 in
|
adamc@450
|
2321 ((L'.ELet (x, t', e1, e2), loc), fm)
|
adamc@450
|
2322 end
|
adamc@607
|
2323
|
adamc@609
|
2324 | L.EServerCall (n, es, ek, t) =>
|
adamc@608
|
2325 let
|
adamc@609
|
2326 val t = monoType env t
|
adamc@614
|
2327 val (_, ft, _, name) = Env.lookupENamed env n
|
adamc@608
|
2328 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@614
|
2329
|
adamc@614
|
2330 fun encodeArgs (es, ft, acc, fm) =
|
adamc@614
|
2331 case (es, ft) of
|
adamc@614
|
2332 ([], _) => (rev acc, fm)
|
adamc@614
|
2333 | (e :: es, (L.TFun (dom, ran), _)) =>
|
adamc@614
|
2334 let
|
adamc@614
|
2335 val (e, fm) = urlifyExp env fm (e, monoType env dom)
|
adamc@614
|
2336 in
|
adamc@614
|
2337 encodeArgs (es, ran, e
|
adamc@614
|
2338 :: (L'.EPrim (Prim.String "/"), loc)
|
adamc@614
|
2339 :: acc, fm)
|
adamc@614
|
2340 end
|
adamc@614
|
2341 | _ => raise Fail "Monoize: Not enough arguments visible in RPC function type"
|
adamc@614
|
2342
|
adamc@614
|
2343 val (call, fm) = encodeArgs (es, ft, [], fm)
|
adamc@614
|
2344 val call = foldl (fn (e, call) => (L'.EStrcat (call, e), loc))
|
adamc@614
|
2345 (L'.EPrim (Prim.String name), loc) call
|
adamc@614
|
2346
|
adamc@608
|
2347 val (ek, fm) = monoExp (env, st, fm) ek
|
adamc@609
|
2348
|
adamc@609
|
2349 val ekf = (L'.EAbs ("f",
|
adamc@609
|
2350 (L'.TFun (t,
|
adamc@609
|
2351 (L'.TFun ((L'.TRecord [], loc),
|
adamc@609
|
2352 (L'.TRecord [], loc)), loc)), loc),
|
adamc@609
|
2353 (L'.TFun (t,
|
adamc@609
|
2354 (L'.TRecord [], loc)), loc),
|
adamc@609
|
2355 (L'.EAbs ("x",
|
adamc@609
|
2356 t,
|
adamc@609
|
2357 (L'.TRecord [], loc),
|
adamc@609
|
2358 (L'.EApp ((L'.EApp ((L'.ERel 1, loc),
|
adamc@609
|
2359 (L'.ERel 0, loc)), loc),
|
adamc@609
|
2360 (L'.ERecord [], loc)), loc)), loc)), loc)
|
adamc@609
|
2361 val ek = (L'.EApp (ekf, ek), loc)
|
adamc@651
|
2362 val e = (L'.EServerCall (call, ek, t), loc)
|
adamc@651
|
2363 val e = liftExpInExp 0 e
|
adamc@651
|
2364 val unit = (L'.TRecord [], loc)
|
adamc@651
|
2365 val e = (L'.EAbs ("_", unit, unit, e), loc)
|
adamc@608
|
2366 in
|
adamc@651
|
2367 (e, fm)
|
adamc@608
|
2368 end
|
adamc@626
|
2369
|
adamc@626
|
2370 | L.EKAbs _ => poly ()
|
adamc@626
|
2371 | L.EKApp _ => poly ()
|
adamc@25
|
2372 end
|
adamc@25
|
2373
|
adamc@179
|
2374 fun monoDecl (env, fm) (all as (d, loc)) =
|
adamc@25
|
2375 let
|
adamc@25
|
2376 fun poly () =
|
adamc@25
|
2377 (E.errorAt loc "Unsupported declaration";
|
adamc@25
|
2378 Print.eprefaces' [("Declaration", CorePrint.p_decl env all)];
|
adamc@25
|
2379 NONE)
|
adamc@25
|
2380 in
|
adamc@25
|
2381 case d of
|
adamc@25
|
2382 L.DCon _ => NONE
|
adamc@193
|
2383 | L.DDatatype (x, n, [], xncs) =>
|
adamc@193
|
2384 let
|
adamc@196
|
2385 val env' = Env.declBinds env all
|
adamc@196
|
2386 val d = (L'.DDatatype (x, n, map (fn (x, n, to) => (x, n, Option.map (monoType env') to)) xncs), loc)
|
adamc@164
|
2387 in
|
adamc@273
|
2388 SOME (env', fm, [d])
|
adamc@193
|
2389 end
|
adamc@193
|
2390 | L.DDatatype _ => poly ()
|
adamc@179
|
2391 | L.DVal (x, n, t, e, s) =>
|
adamc@179
|
2392 let
|
adamc@179
|
2393 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
2394 in
|
adamc@179
|
2395 SOME (Env.pushENamed env x n t NONE s,
|
adamc@179
|
2396 fm,
|
adamc@273
|
2397 [(L'.DVal (x, n, monoType env t, e, s), loc)])
|
adamc@179
|
2398 end
|
adamc@128
|
2399 | L.DValRec vis =>
|
adamc@128
|
2400 let
|
adamc@128
|
2401 val env = foldl (fn ((x, n, t, e, s), env) => Env.pushENamed env x n t NONE s) env vis
|
adamc@179
|
2402
|
adamc@179
|
2403 val (vis, fm) = ListUtil.foldlMap
|
adamc@179
|
2404 (fn ((x, n, t, e, s), fm) =>
|
adamc@179
|
2405 let
|
adamc@179
|
2406 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
2407 in
|
adamc@179
|
2408 ((x, n, monoType env t, e, s), fm)
|
adamc@179
|
2409 end)
|
adamc@179
|
2410 fm vis
|
adamc@128
|
2411 in
|
adamc@128
|
2412 SOME (env,
|
adamc@179
|
2413 fm,
|
adamc@273
|
2414 [(L'.DValRec vis, loc)])
|
adamc@128
|
2415 end
|
adamc@144
|
2416 | L.DExport (ek, n) =>
|
adamc@115
|
2417 let
|
adamc@120
|
2418 val (_, t, _, s) = Env.lookupENamed env n
|
adamc@120
|
2419
|
adamc@609
|
2420 fun unwind (t, args) =
|
adamc@609
|
2421 case #1 t of
|
adamc@609
|
2422 L.TFun (dom, ran) => unwind (ran, dom :: args)
|
adamc@314
|
2423 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@609
|
2424 unwind (t, (L.TRecord (L.CRecord ((L.KType, loc), []), loc), loc) :: args)
|
adamc@609
|
2425 | _ => (rev args, t)
|
adamc@120
|
2426
|
adamc@609
|
2427 val (ts, ran) = unwind (t, [])
|
adamc@609
|
2428 val ts = map (monoType env) ts
|
adamc@609
|
2429 val ran = monoType env ran
|
adamc@115
|
2430 in
|
adamc@609
|
2431 SOME (env, fm, [(L'.DExport (ek, s, n, ts, ran), loc)])
|
adamc@115
|
2432 end
|
adamc@273
|
2433 | L.DTable (x, n, (L.CRecord (_, xts), _), s) =>
|
adamc@251
|
2434 let
|
adamc@251
|
2435 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@251
|
2436 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@311
|
2437 val s = "uw_" ^ s
|
adamc@251
|
2438 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@273
|
2439
|
adamc@273
|
2440 val xts = map (fn (x, t) => (monoName env x, monoType env t)) xts
|
adamc@251
|
2441 in
|
adamc@251
|
2442 SOME (Env.pushENamed env x n t NONE s,
|
adamc@251
|
2443 fm,
|
adamc@273
|
2444 [(L'.DTable (s, xts), loc),
|
adamc@273
|
2445 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@251
|
2446 end
|
adamc@273
|
2447 | L.DTable _ => poly ()
|
adamc@338
|
2448 | L.DSequence (x, n, s) =>
|
adamc@338
|
2449 let
|
adamc@338
|
2450 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@338
|
2451 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
2452 val s = "uw_" ^ s
|
adamc@338
|
2453 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@338
|
2454 in
|
adamc@338
|
2455 SOME (Env.pushENamed env x n t NONE s,
|
adamc@338
|
2456 fm,
|
adamc@338
|
2457 [(L'.DSequence s, loc),
|
adamc@338
|
2458 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@338
|
2459 end
|
adamc@683
|
2460 | L.DDatabase _ => NONE
|
adamc@462
|
2461 | L.DCookie (x, n, t, s) =>
|
adamc@462
|
2462 let
|
adamc@462
|
2463 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@462
|
2464 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
2465 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@462
|
2466 in
|
adamc@462
|
2467 SOME (Env.pushENamed env x n t NONE s,
|
adamc@462
|
2468 fm,
|
adamc@462
|
2469 [(L'.DVal (x, n, t', e, s), loc)])
|
adamc@462
|
2470 end
|
adamc@25
|
2471 end
|
adamc@25
|
2472
|
adamc@683
|
2473 datatype expungable = Client | Channel
|
adamc@683
|
2474
|
adamc@683
|
2475 fun monoize env file =
|
adamc@25
|
2476 let
|
adamc@385
|
2477 val p = !urlPrefix
|
adamc@385
|
2478 val () =
|
adamc@385
|
2479 if p = "" then
|
adamc@385
|
2480 urlPrefix := "/"
|
adamc@385
|
2481 else if String.sub (p, size p - 1) <> #"/" then
|
adamc@385
|
2482 urlPrefix := p ^ "/"
|
adamc@385
|
2483 else
|
adamc@385
|
2484 ()
|
adamc@385
|
2485
|
adamc@683
|
2486 val loc = E.dummySpan
|
adamc@683
|
2487 val client = (L'.TFfi ("Basis", "client"), loc)
|
adamc@683
|
2488 val unit = (L'.TRecord [], loc)
|
adamc@687
|
2489
|
adamc@687
|
2490 fun calcClientish xts =
|
adamc@687
|
2491 foldl (fn ((x : L.con, t : L.con), st as (nullable, notNullable)) =>
|
adamc@687
|
2492 case #1 x of
|
adamc@687
|
2493 L.CName x =>
|
adamc@687
|
2494 (case #1 t of
|
adamc@687
|
2495 L.CFfi ("Basis", "client") =>
|
adamc@687
|
2496 (nullable, (x, Client) :: notNullable)
|
adamc@687
|
2497 | L.CApp ((L.CFfi ("Basis", "option"), _),
|
adamc@687
|
2498 (L.CFfi ("Basis", "client"), _)) =>
|
adamc@687
|
2499 ((x, Client) :: nullable, notNullable)
|
adamc@687
|
2500 | L.CApp ((L.CFfi ("Basis", "channel"), _), _) =>
|
adamc@687
|
2501 (nullable, (x, Channel) :: notNullable)
|
adamc@687
|
2502 | L.CApp ((L.CFfi ("Basis", "option"), _),
|
adamc@687
|
2503 (L.CApp ((L.CFfi ("Basis", "channel"), _), _), _)) =>
|
adamc@687
|
2504 ((x, Channel) :: nullable, notNullable)
|
adamc@687
|
2505 | _ => st)
|
adamc@687
|
2506 | _ => st) ([], []) xts
|
adamc@687
|
2507
|
adamc@683
|
2508 fun expunger () =
|
adamc@683
|
2509 let
|
adamc@683
|
2510 val target = (L'.EFfiApp ("Basis", "sqlifyClient", [(L'.ERel 0, loc)]), loc)
|
adamc@683
|
2511
|
adamc@683
|
2512 fun doTable (tab, xts, e) =
|
adamc@683
|
2513 case xts of
|
adamc@683
|
2514 L.CRecord (_, xts) =>
|
adamc@683
|
2515 let
|
adamc@687
|
2516 val (nullable, notNullable) = calcClientish xts
|
adamc@683
|
2517
|
adamc@684
|
2518 fun cond (x, v) =
|
adamc@684
|
2519 (L'.EStrcat ((L'.EPrim (Prim.String ("uw_" ^ x
|
adamc@684
|
2520 ^ (case v of
|
adamc@684
|
2521 Client => ""
|
adamc@684
|
2522 | Channel => " >> 32")
|
adamc@684
|
2523 ^ " = ")), loc),
|
adamc@684
|
2524 target), loc)
|
adamc@684
|
2525
|
adamc@684
|
2526 val e =
|
adamc@684
|
2527 foldl (fn ((x, v), e) =>
|
adamc@684
|
2528 (L'.ESeq (
|
adamc@684
|
2529 (L'.EDml (L'.EStrcat (
|
adamc@684
|
2530 (L'.EPrim (Prim.String ("UPDATE uw_"
|
adamc@684
|
2531 ^ tab
|
adamc@684
|
2532 ^ " SET uw_"
|
adamc@684
|
2533 ^ x
|
adamc@684
|
2534 ^ " = NULL WHERE ")), loc),
|
adamc@684
|
2535 cond (x, v)), loc), loc),
|
adamc@684
|
2536 e), loc))
|
adamc@684
|
2537 e nullable
|
adamc@684
|
2538
|
adamc@683
|
2539 val e =
|
adamc@683
|
2540 case notNullable of
|
adamc@683
|
2541 [] => e
|
adamc@683
|
2542 | eb :: ebs =>
|
adamc@684
|
2543 (L'.ESeq (
|
adamc@684
|
2544 (L'.EDml (foldl
|
adamc@684
|
2545 (fn (eb, s) =>
|
adamc@684
|
2546 (L'.EStrcat (s,
|
adamc@687
|
2547 (L'.EStrcat ((L'.EPrim (Prim.String " OR "),
|
adamc@684
|
2548 loc),
|
adamc@684
|
2549 cond eb), loc)), loc))
|
adamc@684
|
2550 (L'.EStrcat ((L'.EPrim (Prim.String ("DELETE FROM uw_"
|
adamc@684
|
2551 ^ tab
|
adamc@684
|
2552 ^ " WHERE ")), loc),
|
adamc@684
|
2553 cond eb), loc)
|
adamc@684
|
2554 ebs), loc),
|
adamc@684
|
2555 e), loc)
|
adamc@683
|
2556 in
|
adamc@683
|
2557 e
|
adamc@683
|
2558 end
|
adamc@683
|
2559 | _ => e
|
adamc@683
|
2560
|
adamc@683
|
2561 val e = (L'.ERecord [], loc)
|
adamc@683
|
2562 in
|
adamc@683
|
2563 foldl (fn ((d, _), e) =>
|
adamc@683
|
2564 case d of
|
adamc@683
|
2565 L.DTable (_, _, xts, tab) => doTable (tab, #1 xts, e)
|
adamc@683
|
2566 | _ => e) e file
|
adamc@683
|
2567 end
|
adamc@683
|
2568
|
adamc@687
|
2569 fun initializer () =
|
adamc@687
|
2570 let
|
adamc@687
|
2571 fun doTable (tab, xts, e) =
|
adamc@687
|
2572 case xts of
|
adamc@687
|
2573 L.CRecord (_, xts) =>
|
adamc@687
|
2574 let
|
adamc@687
|
2575 val (nullable, notNullable) = calcClientish xts
|
adamc@687
|
2576
|
adamc@687
|
2577 val e =
|
adamc@687
|
2578 case nullable of
|
adamc@687
|
2579 [] => e
|
adamc@687
|
2580 | (x, _) :: ebs =>
|
adamc@687
|
2581 (L'.ESeq (
|
adamc@687
|
2582 (L'.EDml (L'.EPrim (Prim.String
|
adamc@687
|
2583 (foldl (fn ((x, _), s) =>
|
adamc@687
|
2584 s ^ ", uw_" ^ x ^ " = NULL")
|
adamc@687
|
2585 ("UPDATE uw_"
|
adamc@687
|
2586 ^ tab
|
adamc@687
|
2587 ^ " SET uw_"
|
adamc@687
|
2588 ^ x
|
adamc@687
|
2589 ^ " = NULL")
|
adamc@687
|
2590 ebs)), loc), loc),
|
adamc@687
|
2591 e), loc)
|
adamc@687
|
2592
|
adamc@687
|
2593 val e =
|
adamc@687
|
2594 case notNullable of
|
adamc@687
|
2595 [] => e
|
adamc@687
|
2596 | eb :: ebs =>
|
adamc@687
|
2597 (L'.ESeq (
|
adamc@687
|
2598 (L'.EDml (L'.EPrim (Prim.String ("DELETE FROM uw_"
|
adamc@687
|
2599 ^ tab)), loc), loc),
|
adamc@687
|
2600 e), loc)
|
adamc@687
|
2601 in
|
adamc@687
|
2602 e
|
adamc@687
|
2603 end
|
adamc@687
|
2604 | _ => e
|
adamc@687
|
2605
|
adamc@687
|
2606 val e = (L'.ERecord [], loc)
|
adamc@687
|
2607 in
|
adamc@687
|
2608 foldl (fn ((d, _), e) =>
|
adamc@687
|
2609 case d of
|
adamc@687
|
2610 L.DTable (_, _, xts, tab) => doTable (tab, #1 xts, e)
|
adamc@687
|
2611 | _ => e) e file
|
adamc@687
|
2612 end
|
adamc@687
|
2613
|
adamc@179
|
2614 val (_, _, ds) = List.foldl (fn (d, (env, fm, ds)) =>
|
adamc@683
|
2615 case #1 d of
|
adamc@683
|
2616 L.DDatabase s =>
|
adamc@683
|
2617 let
|
adamc@687
|
2618 val (nExp, fm) = Fm.freshName fm
|
adamc@687
|
2619 val (nIni, fm) = Fm.freshName fm
|
adamc@687
|
2620
|
adamc@687
|
2621 val dExp = L'.DVal ("expunger",
|
adamc@687
|
2622 nExp,
|
adamc@687
|
2623 (L'.TFun (client, unit), loc),
|
adamc@687
|
2624 (L'.EAbs ("cli", client, unit, expunger ()), loc),
|
adamc@687
|
2625 "expunger")
|
adamc@687
|
2626 val dIni = L'.DVal ("initializer",
|
adamc@687
|
2627 nIni,
|
adamc@687
|
2628 (L'.TFun (unit, unit), loc),
|
adamc@687
|
2629 (L'.EAbs ("_", unit, unit, initializer ()), loc),
|
adamc@687
|
2630 "initializer")
|
adamc@683
|
2631 in
|
adamc@687
|
2632 (env, Fm.enter fm, (L'.DDatabase {name = s,
|
adamc@687
|
2633 expunge = nExp,
|
adamc@687
|
2634 initialize = nIni}, loc)
|
adamc@687
|
2635 :: (dExp, loc)
|
adamc@687
|
2636 :: (dIni, loc)
|
adamc@683
|
2637 :: ds)
|
adamc@683
|
2638 end
|
adamc@683
|
2639 | _ =>
|
adamc@683
|
2640 case monoDecl (env, fm) d of
|
adamc@683
|
2641 NONE => (env, fm, ds)
|
adamc@683
|
2642 | SOME (env, fm, ds') =>
|
adamc@683
|
2643 (env,
|
adamc@683
|
2644 Fm.enter fm,
|
adamc@683
|
2645 ds' @ Fm.decls fm @ ds))
|
adamc@683
|
2646 (env, Fm.empty (CoreUtil.File.maxName file + 1), []) file
|
adamc@25
|
2647 in
|
adamc@25
|
2648 rev ds
|
adamc@25
|
2649 end
|
adamc@25
|
2650
|
adamc@25
|
2651 end
|