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