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