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