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