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