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