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