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