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