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