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