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