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