adamc@25
|
1 (* Copyright (c) 2008, Adam Chlipala
|
adamc@25
|
2 * All rights reserved.
|
adamc@25
|
3 *
|
adamc@25
|
4 * Redistribution and use in source and binary forms, with or without
|
adamc@25
|
5 * modification, are permitted provided that the following conditions are met:
|
adamc@25
|
6 *
|
adamc@25
|
7 * - Redistributions of source code must retain the above copyright notice,
|
adamc@25
|
8 * this list of conditions and the following disclaimer.
|
adamc@25
|
9 * - Redistributions in binary form must reproduce the above copyright notice,
|
adamc@25
|
10 * this list of conditions and the following disclaimer in the documentation
|
adamc@25
|
11 * and/or other materials provided with the distribution.
|
adamc@25
|
12 * - The names of contributors may not be used to endorse or promote products
|
adamc@25
|
13 * derived from this software without specific prior written permission.
|
adamc@25
|
14 *
|
adamc@25
|
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
adamc@25
|
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
adamc@25
|
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
adamc@25
|
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
adamc@25
|
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
adamc@25
|
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
adamc@25
|
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
adamc@25
|
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
adamc@25
|
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
adamc@25
|
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
adamc@25
|
25 * POSSIBILITY OF SUCH DAMAGE.
|
adamc@25
|
26 *)
|
adamc@25
|
27
|
adamc@25
|
28 structure Monoize :> MONOIZE = struct
|
adamc@25
|
29
|
adamc@25
|
30 structure E = ErrorMsg
|
adamc@25
|
31 structure Env = CoreEnv
|
adamc@25
|
32
|
adamc@25
|
33 structure L = Core
|
adamc@25
|
34 structure L' = Mono
|
adamc@25
|
35
|
adamc@196
|
36 structure IM = IntBinaryMap
|
adamc@196
|
37
|
adamc@385
|
38 val urlPrefix = ref "/"
|
adamc@385
|
39
|
adamc@196
|
40 val dummyTyp = (L'.TDatatype (0, ref (L'.Enum, [])), E.dummySpan)
|
adamc@25
|
41
|
adamc@252
|
42 structure U = MonoUtil
|
adamc@252
|
43
|
adamc@252
|
44 val liftExpInExp =
|
adamc@252
|
45 U.Exp.mapB {typ = fn t => t,
|
adamc@252
|
46 exp = fn bound => fn e =>
|
adamc@252
|
47 case e of
|
adamc@252
|
48 L'.ERel xn =>
|
adamc@252
|
49 if xn < bound then
|
adamc@252
|
50 e
|
adamc@252
|
51 else
|
adamc@252
|
52 L'.ERel (xn + 1)
|
adamc@252
|
53 | _ => e,
|
adamc@252
|
54 bind = fn (bound, U.Exp.RelE _) => bound + 1
|
adamc@252
|
55 | (bound, _) => bound}
|
adamc@252
|
56
|
adamc@25
|
57 fun monoName env (all as (c, loc)) =
|
adamc@25
|
58 let
|
adamc@25
|
59 fun poly () =
|
adamc@25
|
60 (E.errorAt loc "Unsupported name constructor";
|
adamc@25
|
61 Print.eprefaces' [("Constructor", CorePrint.p_con env all)];
|
adamc@25
|
62 "")
|
adamc@25
|
63 in
|
adamc@25
|
64 case c of
|
adamc@25
|
65 L.CName s => s
|
adamc@25
|
66 | _ => poly ()
|
adamc@25
|
67 end
|
adamc@25
|
68
|
adamc@292
|
69 fun readType' (t, loc) = (L'.TFun ((L'.TFfi ("Basis", "string"), loc),
|
adamc@292
|
70 (L'.TOption t, loc)), loc)
|
adamc@292
|
71 fun readErrType (t, loc) = (L'.TFun ((L'.TFfi ("Basis", "string"), loc),
|
adamc@292
|
72 t), loc)
|
adamc@292
|
73 fun readType (t, loc) =
|
adamc@292
|
74 (L'.TRecord [("Read", readType' (t, loc)),
|
adamc@292
|
75 ("ReadError", readErrType (t, loc))],
|
adamc@292
|
76 loc)
|
adamc@292
|
77
|
adamc@196
|
78 fun monoType env =
|
adamc@25
|
79 let
|
adamc@196
|
80 fun mt env dtmap (all as (c, loc)) =
|
adamc@196
|
81 let
|
adamc@196
|
82 fun poly () =
|
adamc@196
|
83 (E.errorAt loc "Unsupported type constructor";
|
adamc@196
|
84 Print.eprefaces' [("Constructor", CorePrint.p_con env all)];
|
adamc@196
|
85 dummyTyp)
|
adamc@196
|
86 in
|
adamc@196
|
87 case c of
|
adamc@196
|
88 L.TFun (c1, c2) => (L'.TFun (mt env dtmap c1, mt env dtmap c2), loc)
|
adamc@196
|
89 | L.TCFun _ => poly ()
|
adamc@196
|
90 | L.TRecord (L.CRecord ((L.KType, _), xcs), _) =>
|
adamc@196
|
91 (L'.TRecord (map (fn (x, t) => (monoName env x, mt env dtmap t)) xcs), loc)
|
adamc@196
|
92 | L.TRecord _ => poly ()
|
adamc@196
|
93
|
adamc@288
|
94 | L.CApp ((L.CFfi ("Basis", "option"), _), t) =>
|
adamc@288
|
95 (L'.TOption (mt env dtmap t), loc)
|
adamc@288
|
96
|
adamc@387
|
97 | L.CApp ((L.CFfi ("Basis", "eq"), _), t) =>
|
adamc@387
|
98 let
|
adamc@387
|
99 val t = mt env dtmap t
|
adamc@387
|
100 in
|
adamc@387
|
101 (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)
|
adamc@387
|
102 end
|
adamc@389
|
103 | L.CApp ((L.CFfi ("Basis", "num"), _), t) =>
|
adamc@389
|
104 let
|
adamc@389
|
105 val t = mt env dtmap t
|
adamc@389
|
106 in
|
adamc@417
|
107 (L'.TRecord [("Zero", t),
|
adamc@417
|
108 ("Neg", (L'.TFun (t, t), loc)),
|
adamc@389
|
109 ("Plus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
110 ("Minus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
111 ("Times", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
112 ("Div", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
113 ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))],
|
adamc@389
|
114 loc)
|
adamc@389
|
115 end
|
adamc@391
|
116 | L.CApp ((L.CFfi ("Basis", "ord"), _), t) =>
|
adamc@391
|
117 let
|
adamc@391
|
118 val t = mt env dtmap t
|
adamc@391
|
119 in
|
adamc@391
|
120 (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
121 ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))],
|
adamc@391
|
122 loc)
|
adamc@391
|
123 end
|
adamc@286
|
124 | L.CApp ((L.CFfi ("Basis", "show"), _), t) =>
|
adamc@286
|
125 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@290
|
126 | L.CApp ((L.CFfi ("Basis", "read"), _), t) =>
|
adamc@292
|
127 readType (mt env dtmap t, loc)
|
adamc@286
|
128
|
adamc@196
|
129 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "xml"), _), _), _), _), _), _) =>
|
adamc@196
|
130 (L'.TFfi ("Basis", "string"), loc)
|
adamc@196
|
131 | L.CApp ((L.CApp ((L.CFfi ("Basis", "xhtml"), _), _), _), _) =>
|
adamc@196
|
132 (L'.TFfi ("Basis", "string"), loc)
|
adamc@196
|
133
|
adamc@251
|
134 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@252
|
135 (L'.TFun ((L'.TRecord [], loc), mt env dtmap t), loc)
|
adamc@565
|
136 | L.CApp ((L.CFfi ("Basis", "source"), _), t) =>
|
adamc@565
|
137 (L'.TFfi ("Basis", "int"), loc)
|
adamc@568
|
138 | L.CApp ((L.CFfi ("Basis", "signal"), _), t) =>
|
adamc@568
|
139 (L'.TSignal (mt env dtmap t), loc)
|
adamc@462
|
140 | L.CApp ((L.CFfi ("Basis", "http_cookie"), _), _) =>
|
adamc@462
|
141 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
142 | L.CApp ((L.CFfi ("Basis", "sql_table"), _), _) =>
|
adamc@252
|
143 (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
144 | L.CFfi ("Basis", "sql_sequence") =>
|
adamc@338
|
145 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
146 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query"), _), _), _), _) =>
|
adamc@252
|
147 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
148 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_query1"), _), _), _), _), _), _) =>
|
adamc@252
|
149 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
150 | L.CApp ((L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_exp"), _), _), _), _), _), _), _), _) =>
|
adamc@252
|
151 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
152
|
adamc@252
|
153 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_subset"), _), _), _), _) =>
|
adamc@252
|
154 (L'.TRecord [], loc)
|
adamc@252
|
155 | L.CFfi ("Basis", "sql_relop") =>
|
adamc@252
|
156 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
157 | L.CFfi ("Basis", "sql_direction") =>
|
adamc@252
|
158 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
159 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_order_by"), _), _), _), _) =>
|
adamc@252
|
160 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
161 | L.CFfi ("Basis", "sql_limit") =>
|
adamc@252
|
162 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
163 | L.CFfi ("Basis", "sql_offset") =>
|
adamc@252
|
164 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
165
|
adamc@252
|
166 | L.CApp ((L.CFfi ("Basis", "sql_injectable"), _), t) =>
|
adamc@252
|
167 (L'.TFun (mt env dtmap t, (L'.TFfi ("Basis", "string"), loc)), loc)
|
adamc@252
|
168 | L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_unary"), _), _), _), _) =>
|
adamc@252
|
169 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
170 | L.CApp ((L.CApp ((L.CApp ((L.CFfi ("Basis", "sql_binary"), _), _), _), _), _), _) =>
|
adamc@252
|
171 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
172 | L.CApp ((L.CFfi ("Basis", "sql_aggregate"), _), t) =>
|
adamc@252
|
173 (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
174 | L.CApp ((L.CFfi ("Basis", "sql_summable"), _), _) =>
|
adamc@252
|
175 (L'.TRecord [], loc)
|
adamc@252
|
176 | L.CApp ((L.CFfi ("Basis", "sql_maxable"), _), _) =>
|
adamc@252
|
177 (L'.TRecord [], loc)
|
adamc@559
|
178 | L.CApp ((L.CFfi ("Basis", "sql_arith"), _), _) =>
|
adamc@559
|
179 (L'.TRecord [], loc)
|
adamc@441
|
180 | L.CApp ((L.CFfi ("Basis", "sql_nfunc"), _), _) =>
|
adamc@441
|
181 (L'.TFfi ("Basis", "string"), loc)
|
adamc@251
|
182
|
adamc@196
|
183 | L.CRel _ => poly ()
|
adamc@196
|
184 | L.CNamed n =>
|
adamc@196
|
185 (case IM.find (dtmap, n) of
|
adamc@196
|
186 SOME r => (L'.TDatatype (n, r), loc)
|
adamc@196
|
187 | NONE =>
|
adamc@196
|
188 let
|
adamc@196
|
189 val r = ref (L'.Default, [])
|
adamc@196
|
190 val (_, xs, xncs) = Env.lookupDatatype env n
|
adamc@196
|
191
|
adamc@196
|
192 val dtmap' = IM.insert (dtmap, n, r)
|
adamc@196
|
193
|
adamc@196
|
194 val xncs = map (fn (x, n, to) => (x, n, Option.map (mt env dtmap') to)) xncs
|
adamc@196
|
195 in
|
adamc@196
|
196 case xs of
|
adamc@198
|
197 [] =>(r := (ElabUtil.classifyDatatype xncs, xncs);
|
adamc@196
|
198 (L'.TDatatype (n, r), loc))
|
adamc@196
|
199 | _ => poly ()
|
adamc@196
|
200 end)
|
adamc@196
|
201 | L.CFfi mx => (L'.TFfi mx, loc)
|
adamc@196
|
202 | L.CApp _ => poly ()
|
adamc@196
|
203 | L.CAbs _ => poly ()
|
adamc@196
|
204
|
adamc@196
|
205 | L.CName _ => poly ()
|
adamc@196
|
206
|
adamc@196
|
207 | L.CRecord _ => poly ()
|
adamc@196
|
208 | L.CConcat _ => poly ()
|
adamc@196
|
209 | L.CFold _ => poly ()
|
adamc@196
|
210 | L.CUnit => poly ()
|
adamc@214
|
211
|
adamc@214
|
212 | L.CTuple _ => poly ()
|
adamc@214
|
213 | L.CProj _ => poly ()
|
adamc@196
|
214 end
|
adamc@25
|
215 in
|
adamc@196
|
216 mt env IM.empty
|
adamc@25
|
217 end
|
adamc@25
|
218
|
adamc@25
|
219 val dummyExp = (L'.EPrim (Prim.Int 0), E.dummySpan)
|
adamc@25
|
220
|
adamc@179
|
221 structure IM = IntBinaryMap
|
adamc@179
|
222
|
adamc@179
|
223 datatype foo_kind =
|
adamc@179
|
224 Attr
|
adamc@179
|
225 | Url
|
adamc@179
|
226
|
adamc@179
|
227 fun fk2s fk =
|
adamc@179
|
228 case fk of
|
adamc@179
|
229 Attr => "attr"
|
adamc@179
|
230 | Url => "url"
|
adamc@179
|
231
|
adamc@179
|
232 structure Fm :> sig
|
adamc@179
|
233 type t
|
adamc@179
|
234
|
adamc@179
|
235 val empty : int -> t
|
adamc@179
|
236
|
adamc@179
|
237 val lookup : t -> foo_kind -> int -> (int -> t -> L'.decl * t) -> t * int
|
adamc@179
|
238 val enter : t -> t
|
adamc@179
|
239 val decls : t -> L'.decl list
|
adamc@179
|
240 end = struct
|
adamc@179
|
241
|
adamc@179
|
242 structure M = BinaryMapFn(struct
|
adamc@179
|
243 type ord_key = foo_kind
|
adamc@179
|
244 fun compare x =
|
adamc@179
|
245 case x of
|
adamc@179
|
246 (Attr, Attr) => EQUAL
|
adamc@179
|
247 | (Attr, _) => LESS
|
adamc@179
|
248 | (_, Attr) => GREATER
|
adamc@179
|
249
|
adamc@179
|
250 | (Url, Url) => EQUAL
|
adamc@179
|
251 end)
|
adamc@179
|
252
|
adamc@179
|
253 type t = {
|
adamc@179
|
254 count : int,
|
adamc@179
|
255 map : int IM.map M.map,
|
adamc@179
|
256 decls : L'.decl list
|
adamc@179
|
257 }
|
adamc@179
|
258
|
adamc@179
|
259 fun empty count = {
|
adamc@179
|
260 count = count,
|
adamc@179
|
261 map = M.empty,
|
adamc@179
|
262 decls = []
|
adamc@179
|
263 }
|
adamc@179
|
264
|
adamc@179
|
265 fun enter ({count, map, ...} : t) = {count = count, map = map, decls = []}
|
adamc@179
|
266 fun decls ({decls, ...} : t) = decls
|
adamc@179
|
267
|
adamc@179
|
268 fun lookup (t as {count, map, decls}) k n thunk =
|
adamc@120
|
269 let
|
adamc@179
|
270 val im = Option.getOpt (M.find (map, k), IM.empty)
|
adamc@179
|
271 in
|
adamc@179
|
272 case IM.find (im, n) of
|
adamc@179
|
273 NONE =>
|
adamc@179
|
274 let
|
adamc@179
|
275 val n' = count
|
adamc@179
|
276 val (d, {count, map, decls}) = thunk count {count = count + 1,
|
adamc@179
|
277 map = M.insert (map, k, IM.insert (im, n, n')),
|
adamc@179
|
278 decls = decls}
|
adamc@179
|
279 in
|
adamc@179
|
280 ({count = count,
|
adamc@179
|
281 map = map,
|
adamc@179
|
282 decls = d :: decls}, n')
|
adamc@179
|
283 end
|
adamc@179
|
284 | SOME n' => (t, n')
|
adamc@179
|
285 end
|
adamc@179
|
286
|
adamc@179
|
287 end
|
adamc@185
|
288
|
adamc@185
|
289
|
adamc@185
|
290 fun capitalize s =
|
adamc@185
|
291 if s = "" then
|
adamc@185
|
292 s
|
adamc@185
|
293 else
|
adamc@185
|
294 str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
|
adamc@179
|
295
|
adamc@179
|
296 fun fooifyExp fk env =
|
adamc@179
|
297 let
|
adamc@179
|
298 fun fooify fm (e, tAll as (t, loc)) =
|
adamc@120
|
299 case #1 e of
|
adamc@120
|
300 L'.EClosure (fnam, [(L'.ERecord [], _)]) =>
|
adamc@120
|
301 let
|
adamc@120
|
302 val (_, _, _, s) = Env.lookupENamed env fnam
|
adamc@120
|
303 in
|
adamc@385
|
304 ((L'.EPrim (Prim.String (!urlPrefix ^ s)), loc), fm)
|
adamc@120
|
305 end
|
adamc@120
|
306 | L'.EClosure (fnam, args) =>
|
adamc@120
|
307 let
|
adamc@120
|
308 val (_, ft, _, s) = Env.lookupENamed env fnam
|
adamc@120
|
309 val ft = monoType env ft
|
adamc@111
|
310
|
adamc@179
|
311 fun attrify (args, ft, e, fm) =
|
adamc@120
|
312 case (args, ft) of
|
adamc@179
|
313 ([], _) => (e, fm)
|
adamc@120
|
314 | (arg :: args, (L'.TFun (t, ft), _)) =>
|
adamc@179
|
315 let
|
adamc@179
|
316 val (arg', fm) = fooify fm (arg, t)
|
adamc@179
|
317 in
|
adamc@179
|
318 attrify (args, ft,
|
adamc@179
|
319 (L'.EStrcat (e,
|
adamc@179
|
320 (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc),
|
adamc@179
|
321 arg'), loc)), loc),
|
adamc@179
|
322 fm)
|
adamc@179
|
323 end
|
adamc@120
|
324 | _ => (E.errorAt loc "Type mismatch encoding attribute";
|
adamc@179
|
325 (e, fm))
|
adamc@120
|
326 in
|
adamc@385
|
327 attrify (args, ft, (L'.EPrim (Prim.String (!urlPrefix ^ s)), loc), fm)
|
adamc@120
|
328 end
|
adamc@120
|
329 | _ =>
|
adamc@120
|
330 case t of
|
adamc@185
|
331 L'.TFfi (m, x) => ((L'.EFfiApp (m, fk2s fk ^ "ify" ^ capitalize x, [e]), loc), fm)
|
adamc@200
|
332
|
adamc@179
|
333 | L'.TRecord [] => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@200
|
334 | L'.TRecord ((x, t) :: xts) =>
|
adamc@200
|
335 let
|
adamc@200
|
336 val (se, fm) = fooify fm ((L'.EField (e, x), loc), t)
|
adamc@200
|
337 in
|
adamc@200
|
338 foldl (fn ((x, t), (se, fm)) =>
|
adamc@200
|
339 let
|
adamc@200
|
340 val (se', fm) = fooify fm ((L'.EField (e, x), loc), t)
|
adamc@200
|
341 in
|
adamc@200
|
342 ((L'.EStrcat (se,
|
adamc@200
|
343 (L'.EStrcat ((L'.EPrim (Prim.String "/"), loc),
|
adamc@200
|
344 se'), loc)), loc),
|
adamc@200
|
345 fm)
|
adamc@200
|
346 end) (se, fm) xts
|
adamc@200
|
347 end
|
adamc@111
|
348
|
adamc@196
|
349 | L'.TDatatype (i, ref (dk, _)) =>
|
adamc@179
|
350 let
|
adamc@179
|
351 fun makeDecl n fm =
|
adamc@179
|
352 let
|
adamc@193
|
353 val (x, _, xncs) = Env.lookupDatatype env i
|
adamc@179
|
354
|
adamc@179
|
355 val (branches, fm) =
|
adamc@179
|
356 ListUtil.foldlMap
|
adamc@179
|
357 (fn ((x, n, to), fm) =>
|
adamc@179
|
358 case to of
|
adamc@179
|
359 NONE =>
|
adamc@188
|
360 (((L'.PCon (dk, L'.PConVar n, NONE), loc),
|
adamc@179
|
361 (L'.EPrim (Prim.String x), loc)),
|
adamc@179
|
362 fm)
|
adamc@179
|
363 | SOME t =>
|
adamc@179
|
364 let
|
adamc@182
|
365 val t = monoType env t
|
adamc@182
|
366 val (arg, fm) = fooify fm ((L'.ERel 0, loc), t)
|
adamc@179
|
367 in
|
adamc@188
|
368 (((L'.PCon (dk, L'.PConVar n, SOME (L'.PVar ("a", t), loc)), loc),
|
adamc@179
|
369 (L'.EStrcat ((L'.EPrim (Prim.String (x ^ "/")), loc),
|
adamc@179
|
370 arg), loc)),
|
adamc@179
|
371 fm)
|
adamc@179
|
372 end)
|
adamc@179
|
373 fm xncs
|
adamc@179
|
374
|
adamc@179
|
375 val dom = tAll
|
adamc@179
|
376 val ran = (L'.TFfi ("Basis", "string"), loc)
|
adamc@179
|
377 in
|
adamc@179
|
378 ((L'.DValRec [(fk2s fk ^ "ify_" ^ x,
|
adamc@179
|
379 n,
|
adamc@179
|
380 (L'.TFun (dom, ran), loc),
|
adamc@179
|
381 (L'.EAbs ("x",
|
adamc@179
|
382 dom,
|
adamc@179
|
383 ran,
|
adamc@179
|
384 (L'.ECase ((L'.ERel 0, loc),
|
adamc@179
|
385 branches,
|
adamc@182
|
386 {disc = dom,
|
adamc@182
|
387 result = ran}), loc)), loc),
|
adamc@179
|
388 "")], loc),
|
adamc@179
|
389 fm)
|
adamc@179
|
390 end
|
adamc@179
|
391
|
adamc@179
|
392 val (fm, n) = Fm.lookup fm fk i makeDecl
|
adamc@179
|
393 in
|
adamc@179
|
394 ((L'.EApp ((L'.ENamed n, loc), e), loc), fm)
|
adamc@179
|
395 end
|
adamc@164
|
396
|
adamc@471
|
397 | L'.TOption t =>
|
adamc@471
|
398 let
|
adamc@471
|
399 val (body, fm) = fooify fm ((L'.ERel 0, loc), t)
|
adamc@471
|
400 in
|
adamc@471
|
401 ((L'.ECase (e,
|
adamc@471
|
402 [((L'.PNone t, loc),
|
adamc@471
|
403 (L'.EPrim (Prim.String "None"), loc)),
|
adamc@471
|
404
|
adamc@471
|
405 ((L'.PSome (t, (L'.PVar ("x", t), loc)), loc),
|
adamc@471
|
406 (L'.EStrcat ((L'.EPrim (Prim.String "Some/"), loc),
|
adamc@471
|
407 body), loc))],
|
adamc@471
|
408 {disc = tAll,
|
adamc@471
|
409 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@471
|
410 fm)
|
adamc@471
|
411 end
|
adamc@471
|
412
|
adamc@490
|
413 | _ => (E.errorAt loc "Don't know how to encode attribute/URL type";
|
adamc@120
|
414 Print.eprefaces' [("Type", MonoPrint.p_typ MonoEnv.empty tAll)];
|
adamc@179
|
415 (dummyExp, fm))
|
adamc@120
|
416 in
|
adamc@120
|
417 fooify
|
adamc@120
|
418 end
|
adamc@120
|
419
|
adamc@179
|
420 val attrifyExp = fooifyExp Attr
|
adamc@179
|
421 val urlifyExp = fooifyExp Url
|
adamc@105
|
422
|
adamc@143
|
423 datatype 'a failable_search =
|
adamc@143
|
424 Found of 'a
|
adamc@143
|
425 | NotFound
|
adamc@143
|
426 | Error
|
adamc@143
|
427
|
adamc@153
|
428 structure St :> sig
|
adamc@153
|
429 type t
|
adamc@153
|
430
|
adamc@153
|
431 val empty : t
|
adamc@153
|
432
|
adamc@153
|
433 val radioGroup : t -> string option
|
adamc@153
|
434 val setRadioGroup : t * string -> t
|
adamc@153
|
435 end = struct
|
adamc@153
|
436
|
adamc@153
|
437 type t = {
|
adamc@153
|
438 radioGroup : string option
|
adamc@153
|
439 }
|
adamc@153
|
440
|
adamc@153
|
441 val empty = {radioGroup = NONE}
|
adamc@153
|
442
|
adamc@153
|
443 fun radioGroup (t : t) = #radioGroup t
|
adamc@153
|
444
|
adamc@153
|
445 fun setRadioGroup (t : t, x) = {radioGroup = SOME x}
|
adamc@153
|
446
|
adamc@153
|
447 end
|
adamc@153
|
448
|
adamc@186
|
449 fun monoPatCon env pc =
|
adamc@178
|
450 case pc of
|
adamc@178
|
451 L.PConVar n => L'.PConVar n
|
adamc@188
|
452 | L.PConFfi {mod = m, datatyp, con, arg, ...} => L'.PConFfi {mod = m, datatyp = datatyp, con = con,
|
adamc@188
|
453 arg = Option.map (monoType env) arg}
|
adamc@178
|
454
|
adamc@193
|
455 val dummyPat = (L'.PPrim (Prim.Int 0), ErrorMsg.dummySpan)
|
adamc@193
|
456
|
adamc@193
|
457 fun monoPat env (all as (p, loc)) =
|
adamc@193
|
458 let
|
adamc@193
|
459 fun poly () =
|
adamc@193
|
460 (E.errorAt loc "Unsupported pattern";
|
adamc@193
|
461 Print.eprefaces' [("Pattern", CorePrint.p_pat env all)];
|
adamc@193
|
462 dummyPat)
|
adamc@193
|
463 in
|
adamc@193
|
464 case p of
|
adamc@193
|
465 L.PWild => (L'.PWild, loc)
|
adamc@193
|
466 | L.PVar (x, t) => (L'.PVar (x, monoType env t), loc)
|
adamc@193
|
467 | L.PPrim p => (L'.PPrim p, loc)
|
adamc@193
|
468 | L.PCon (dk, pc, [], po) => (L'.PCon (dk, monoPatCon env pc, Option.map (monoPat env) po), loc)
|
adamc@288
|
469 | L.PCon (L.Option, _, [t], NONE) => (L'.PNone (monoType env t), loc)
|
adamc@288
|
470 | L.PCon (L.Option, _, [t], SOME p) => (L'.PSome (monoType env t, monoPat env p), loc)
|
adamc@193
|
471 | L.PCon _ => poly ()
|
adamc@193
|
472 | L.PRecord xps => (L'.PRecord (map (fn (x, p, t) => (x, monoPat env p, monoType env t)) xps), loc)
|
adamc@193
|
473 end
|
adamc@178
|
474
|
adamc@252
|
475 fun strcat loc es =
|
adamc@252
|
476 case es of
|
adamc@252
|
477 [] => (L'.EPrim (Prim.String ""), loc)
|
adamc@252
|
478 | [e] => e
|
adamc@252
|
479 | _ =>
|
adamc@252
|
480 let
|
adamc@252
|
481 val e2 = List.last es
|
adamc@252
|
482 val es = List.take (es, length es - 1)
|
adamc@252
|
483 val e1 = List.last es
|
adamc@252
|
484 val es = List.take (es, length es - 1)
|
adamc@252
|
485 in
|
adamc@252
|
486 foldr (fn (e, e') => (L'.EStrcat (e, e'), loc))
|
adamc@252
|
487 (L'.EStrcat (e1, e2), loc) es
|
adamc@252
|
488 end
|
adamc@252
|
489
|
adamc@252
|
490 fun strcatComma loc es =
|
adamc@252
|
491 case es of
|
adamc@252
|
492 [] => (L'.EPrim (Prim.String ""), loc)
|
adamc@252
|
493 | [e] => e
|
adamc@252
|
494 | _ =>
|
adamc@252
|
495 let
|
adamc@252
|
496 val e1 = List.last es
|
adamc@252
|
497 val es = List.take (es, length es - 1)
|
adamc@252
|
498 in
|
adamc@252
|
499 foldr (fn (e, e') =>
|
adamc@265
|
500 case (e, e') of
|
adamc@265
|
501 ((L'.EPrim (Prim.String ""), _), _) => e'
|
adamc@265
|
502 | (_, (L'.EPrim (Prim.String ""), _)) => e
|
adamc@252
|
503 | _ =>
|
adamc@252
|
504 (L'.EStrcat (e,
|
adamc@252
|
505 (L'.EStrcat ((L'.EPrim (Prim.String ", "), loc), e'), loc)), loc))
|
adamc@252
|
506 e1 es
|
adamc@252
|
507 end
|
adamc@252
|
508
|
adamc@252
|
509 fun strcatR loc e xs = strcatComma loc (map (fn (x, _) => (L'.EField (e, x), loc)) xs)
|
adamc@252
|
510
|
adamc@179
|
511 fun monoExp (env, st, fm) (all as (e, loc)) =
|
adamc@25
|
512 let
|
adamc@25
|
513 fun poly () =
|
adamc@25
|
514 (E.errorAt loc "Unsupported expression";
|
adamc@25
|
515 Print.eprefaces' [("Expression", CorePrint.p_exp env all)];
|
adamc@179
|
516 (dummyExp, fm))
|
adamc@389
|
517
|
adamc@389
|
518 fun numTy t =
|
adamc@417
|
519 (L'.TRecord [("Zero", t),
|
adamc@417
|
520 ("Neg", (L'.TFun (t, t), loc)),
|
adamc@389
|
521 ("Plus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
522 ("Minus", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
523 ("Times", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
524 ("Div", (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
525 ("Mod", (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc)
|
adamc@417
|
526 fun numEx (t, zero, neg, plus, minus, times, dv, md) =
|
adamc@417
|
527 ((L'.ERecord [("Zero", (L'.EPrim zero, loc), t),
|
adamc@417
|
528 ("Neg", neg, (L'.TFun (t, t), loc)),
|
adamc@389
|
529 ("Plus", plus, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
530 ("Minus", minus, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
531 ("Times", times, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
532 ("Div", dv, (L'.TFun (t, (L'.TFun (t, t), loc)), loc)),
|
adamc@389
|
533 ("Mod", md, (L'.TFun (t, (L'.TFun (t, t), loc)), loc))], loc), fm)
|
adamc@391
|
534
|
adamc@391
|
535 fun ordTy t =
|
adamc@391
|
536 (L'.TRecord [("Lt", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
537 ("Le", (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))], loc)
|
adamc@391
|
538 fun ordEx (t, lt, le) =
|
adamc@391
|
539 ((L'.ERecord [("Lt", lt, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc)),
|
adamc@391
|
540 ("Le", le, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc))],
|
adamc@391
|
541 loc), fm)
|
adamc@25
|
542 in
|
adamc@25
|
543 case e of
|
adamc@179
|
544 L.EPrim p => ((L'.EPrim p, loc), fm)
|
adamc@179
|
545 | L.ERel n => ((L'.ERel n, loc), fm)
|
adamc@179
|
546 | L.ENamed n => ((L'.ENamed n, loc), fm)
|
adamc@193
|
547 | L.ECon (dk, pc, [], eo) =>
|
adamc@193
|
548 let
|
adamc@179
|
549 val (eo, fm) =
|
adamc@179
|
550 case eo of
|
adamc@179
|
551 NONE => (NONE, fm)
|
adamc@179
|
552 | SOME e =>
|
adamc@179
|
553 let
|
adamc@179
|
554 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
555 in
|
adamc@179
|
556 (SOME e, fm)
|
adamc@179
|
557 end
|
adamc@179
|
558 in
|
adamc@188
|
559 ((L'.ECon (dk, monoPatCon env pc, eo), loc), fm)
|
adamc@193
|
560 end
|
adamc@297
|
561 | L.ECon (L.Option, _, [t], NONE) =>
|
adamc@297
|
562 ((L'.ENone (monoType env t), loc), fm)
|
adamc@297
|
563 | L.ECon (L.Option, _, [t], SOME e) =>
|
adamc@297
|
564 let
|
adamc@297
|
565 val (e, fm) = monoExp (env, st, fm) e
|
adamc@297
|
566 in
|
adamc@297
|
567 ((L'.ESome (monoType env t, e), loc), fm)
|
adamc@297
|
568 end
|
adamc@193
|
569 | L.ECon _ => poly ()
|
adamc@94
|
570
|
adamc@387
|
571 | L.ECApp ((L.EFfi ("Basis", "eq"), _), t) =>
|
adamc@387
|
572 let
|
adamc@387
|
573 val t = monoType env t
|
adamc@387
|
574 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@387
|
575 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@387
|
576 in
|
adamc@387
|
577 ((L'.EAbs ("f", dom, dom,
|
adamc@387
|
578 (L'.ERel 0, loc)), loc), fm)
|
adamc@387
|
579 end
|
adamc@387
|
580 | L.ECApp ((L.EFfi ("Basis", "ne"), _), t) =>
|
adamc@387
|
581 let
|
adamc@387
|
582 val t = monoType env t
|
adamc@387
|
583 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@387
|
584 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@387
|
585 in
|
adamc@387
|
586 ((L'.EAbs ("f", dom, dom,
|
adamc@387
|
587 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@387
|
588 (L'.EAbs ("y", t, b,
|
adamc@387
|
589 (L'.EUnop ("!", (L'.EApp ((L'.EApp ((L'.ERel 2, loc),
|
adamc@387
|
590 (L'.ERel 1, loc)), loc),
|
adamc@387
|
591 (L'.ERel 0, loc)), loc)), loc)),
|
adamc@387
|
592 loc)),
|
adamc@387
|
593 loc)),
|
adamc@387
|
594 loc), fm)
|
adamc@387
|
595 end
|
adamc@387
|
596 | L.EFfi ("Basis", "eq_int") =>
|
adamc@387
|
597 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@387
|
598 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@387
|
599 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@387
|
600 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@387
|
601 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@387
|
602 fm)
|
adamc@394
|
603 | L.EFfi ("Basis", "eq_float") =>
|
adamc@394
|
604 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
605 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
606 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
607 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
608 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@394
|
609 fm)
|
adamc@388
|
610 | L.EFfi ("Basis", "eq_bool") =>
|
adamc@388
|
611 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
612 (L'.TFun ((L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@388
|
613 (L'.EAbs ("y", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
614 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
615 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@388
|
616 fm)
|
adamc@388
|
617 | L.EFfi ("Basis", "eq_string") =>
|
adamc@388
|
618 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc),
|
adamc@388
|
619 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@388
|
620 (L'.EAbs ("y", (L'.TFfi ("Basis", "string"), loc),
|
adamc@388
|
621 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@388
|
622 (L'.EBinop ("!strcmp", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@388
|
623 fm)
|
adamc@437
|
624 | L.EFfi ("Basis", "eq_time") =>
|
adamc@437
|
625 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
626 (L'.TFun ((L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@437
|
627 (L'.EAbs ("y", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
628 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@437
|
629 (L'.EBinop ("==", (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@437
|
630 fm)
|
adamc@422
|
631 | L.ECApp ((L.EFfi ("Basis", "mkEq"), _), t) =>
|
adamc@422
|
632 let
|
adamc@422
|
633 val t = monoType env t
|
adamc@422
|
634 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@422
|
635 val dom = (L'.TFun (t, (L'.TFun (t, b), loc)), loc)
|
adamc@422
|
636 in
|
adamc@422
|
637 ((L'.EAbs ("f", dom, dom,
|
adamc@422
|
638 (L'.ERel 0, loc)), loc), fm)
|
adamc@422
|
639 end
|
adamc@387
|
640
|
adamc@417
|
641 | L.ECApp ((L.EFfi ("Basis", "zero"), _), t) =>
|
adamc@417
|
642 let
|
adamc@417
|
643 val t = monoType env t
|
adamc@417
|
644 in
|
adamc@417
|
645 ((L'.EAbs ("r", numTy t, t,
|
adamc@417
|
646 (L'.EField ((L'.ERel 0, loc), "Zero"), loc)), loc), fm)
|
adamc@417
|
647 end
|
adamc@389
|
648 | L.ECApp ((L.EFfi ("Basis", "neg"), _), t) =>
|
adamc@389
|
649 let
|
adamc@389
|
650 val t = monoType env t
|
adamc@389
|
651 in
|
adamc@389
|
652 ((L'.EAbs ("r", numTy t, (L'.TFun (t, t), loc),
|
adamc@389
|
653 (L'.EField ((L'.ERel 0, loc), "Neg"), loc)), loc), fm)
|
adamc@389
|
654 end
|
adamc@389
|
655 | L.ECApp ((L.EFfi ("Basis", "plus"), _), t) =>
|
adamc@389
|
656 let
|
adamc@389
|
657 val t = monoType env t
|
adamc@389
|
658 in
|
adamc@389
|
659 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
660 (L'.EField ((L'.ERel 0, loc), "Plus"), loc)), loc), fm)
|
adamc@389
|
661 end
|
adamc@389
|
662 | L.ECApp ((L.EFfi ("Basis", "minus"), _), t) =>
|
adamc@389
|
663 let
|
adamc@389
|
664 val t = monoType env t
|
adamc@389
|
665 in
|
adamc@389
|
666 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
667 (L'.EField ((L'.ERel 0, loc), "Minus"), loc)), loc), fm)
|
adamc@389
|
668 end
|
adamc@389
|
669 | L.ECApp ((L.EFfi ("Basis", "times"), _), t) =>
|
adamc@389
|
670 let
|
adamc@389
|
671 val t = monoType env t
|
adamc@389
|
672 in
|
adamc@389
|
673 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
674 (L'.EField ((L'.ERel 0, loc), "Times"), loc)), loc), fm)
|
adamc@389
|
675 end
|
adamc@389
|
676 | L.ECApp ((L.EFfi ("Basis", "div"), _), t) =>
|
adamc@389
|
677 let
|
adamc@389
|
678 val t = monoType env t
|
adamc@389
|
679 in
|
adamc@389
|
680 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
681 (L'.EField ((L'.ERel 0, loc), "Div"), loc)), loc), fm)
|
adamc@389
|
682 end
|
adamc@389
|
683 | L.ECApp ((L.EFfi ("Basis", "mod"), _), t) =>
|
adamc@389
|
684 let
|
adamc@389
|
685 val t = monoType env t
|
adamc@389
|
686 in
|
adamc@389
|
687 ((L'.EAbs ("r", numTy t, (L'.TFun (t, (L'.TFun (t, t), loc)), loc),
|
adamc@389
|
688 (L'.EField ((L'.ERel 0, loc), "Mod"), loc)), loc), fm)
|
adamc@389
|
689 end
|
adamc@389
|
690 | L.EFfi ("Basis", "num_int") =>
|
adamc@389
|
691 let
|
adamc@389
|
692 fun intBin s =
|
adamc@389
|
693 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
694 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "int"), loc)), loc),
|
adamc@389
|
695 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
696 (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
697 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@389
|
698 in
|
adamc@389
|
699 numEx ((L'.TFfi ("Basis", "int"), loc),
|
adamc@417
|
700 Prim.Int (Int64.fromInt 0),
|
adamc@389
|
701 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
702 (L'.TFfi ("Basis", "int"), loc),
|
adamc@389
|
703 (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc),
|
adamc@389
|
704 intBin "+",
|
adamc@389
|
705 intBin "-",
|
adamc@389
|
706 intBin "*",
|
adamc@389
|
707 intBin "/",
|
adamc@389
|
708 intBin "%")
|
adamc@389
|
709 end
|
adamc@390
|
710 | L.EFfi ("Basis", "num_float") =>
|
adamc@390
|
711 let
|
adamc@390
|
712 fun floatBin s =
|
adamc@390
|
713 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
714 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "float"), loc)), loc),
|
adamc@390
|
715 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
716 (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
717 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@390
|
718 in
|
adamc@390
|
719 numEx ((L'.TFfi ("Basis", "float"), loc),
|
adamc@417
|
720 Prim.Float 0.0,
|
adamc@390
|
721 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
722 (L'.TFfi ("Basis", "float"), loc),
|
adamc@390
|
723 (L'.EUnop ("-", (L'.ERel 0, loc)), loc)), loc),
|
adamc@390
|
724 floatBin "+",
|
adamc@390
|
725 floatBin "-",
|
adamc@390
|
726 floatBin "*",
|
adamc@390
|
727 floatBin "/",
|
adamc@390
|
728 floatBin "fmod")
|
adamc@390
|
729 end
|
adamc@391
|
730
|
adamc@391
|
731 | L.ECApp ((L.EFfi ("Basis", "lt"), _), t) =>
|
adamc@391
|
732 let
|
adamc@391
|
733 val t = monoType env t
|
adamc@391
|
734 in
|
adamc@391
|
735 ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc),
|
adamc@391
|
736 (L'.EField ((L'.ERel 0, loc), "Lt"), loc)), loc), fm)
|
adamc@391
|
737 end
|
adamc@391
|
738 | L.ECApp ((L.EFfi ("Basis", "le"), _), t) =>
|
adamc@391
|
739 let
|
adamc@391
|
740 val t = monoType env t
|
adamc@391
|
741 in
|
adamc@391
|
742 ((L'.EAbs ("r", ordTy t, (L'.TFun (t, (L'.TFun (t, (L'.TFfi ("Basis", "bool"), loc)), loc)), loc),
|
adamc@391
|
743 (L'.EField ((L'.ERel 0, loc), "Le"), loc)), loc), fm)
|
adamc@391
|
744 end
|
adamc@392
|
745 | L.ECApp ((L.EFfi ("Basis", "gt"), _), t) =>
|
adamc@392
|
746 let
|
adamc@392
|
747 val t = monoType env t
|
adamc@392
|
748 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@392
|
749 in
|
adamc@392
|
750 ((L'.EAbs ("f", ordTy t, (L'.TFun (t, (L'.TFun (t, b), loc)), loc),
|
adamc@392
|
751 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@392
|
752 (L'.EAbs ("y", t, b,
|
adamc@392
|
753 (L'.EUnop ("!",
|
adamc@392
|
754 (L'.EApp ((L'.EApp ((L'.EField ((L'.ERel 2, loc),
|
adamc@392
|
755 "Le"), loc),
|
adamc@392
|
756 (L'.ERel 1, loc)), loc),
|
adamc@392
|
757 (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@392
|
758 loc)),
|
adamc@392
|
759 loc), fm)
|
adamc@392
|
760 end
|
adamc@392
|
761 | L.ECApp ((L.EFfi ("Basis", "ge"), _), t) =>
|
adamc@392
|
762 let
|
adamc@392
|
763 val t = monoType env t
|
adamc@392
|
764 val b = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@392
|
765 in
|
adamc@392
|
766 ((L'.EAbs ("f", ordTy t, (L'.TFun (t, (L'.TFun (t, b), loc)), loc),
|
adamc@392
|
767 (L'.EAbs ("x", t, (L'.TFun (t, b), loc),
|
adamc@392
|
768 (L'.EAbs ("y", t, b,
|
adamc@392
|
769 (L'.EUnop ("!",
|
adamc@392
|
770 (L'.EApp ((L'.EApp ((L'.EField ((L'.ERel 2, loc),
|
adamc@392
|
771 "Lt"), loc),
|
adamc@392
|
772 (L'.ERel 1, loc)), loc),
|
adamc@392
|
773 (L'.ERel 0, loc)), loc)), loc)), loc)),
|
adamc@392
|
774 loc)),
|
adamc@392
|
775 loc), fm)
|
adamc@392
|
776 end
|
adamc@391
|
777 | L.EFfi ("Basis", "ord_int") =>
|
adamc@391
|
778 let
|
adamc@391
|
779 fun intBin s =
|
adamc@391
|
780 (L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
781 (L'.TFun ((L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@391
|
782 (L'.EAbs ("y", (L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
783 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@391
|
784 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@391
|
785 in
|
adamc@391
|
786 ordEx ((L'.TFfi ("Basis", "int"), loc),
|
adamc@391
|
787 intBin "<",
|
adamc@391
|
788 intBin "<=")
|
adamc@391
|
789 end
|
adamc@394
|
790 | L.EFfi ("Basis", "ord_float") =>
|
adamc@394
|
791 let
|
adamc@394
|
792 fun floatBin s =
|
adamc@394
|
793 (L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
794 (L'.TFun ((L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
795 (L'.EAbs ("y", (L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
796 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
797 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@394
|
798 in
|
adamc@394
|
799 ordEx ((L'.TFfi ("Basis", "float"), loc),
|
adamc@394
|
800 floatBin "<",
|
adamc@394
|
801 floatBin "<=")
|
adamc@394
|
802 end
|
adamc@394
|
803 | L.EFfi ("Basis", "ord_bool") =>
|
adamc@394
|
804 let
|
adamc@394
|
805 fun boolBin s =
|
adamc@394
|
806 (L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
807 (L'.TFun ((L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@394
|
808 (L'.EAbs ("y", (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
809 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
810 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@394
|
811 in
|
adamc@394
|
812 ordEx ((L'.TFfi ("Basis", "bool"), loc),
|
adamc@394
|
813 boolBin "<",
|
adamc@394
|
814 boolBin "<=")
|
adamc@394
|
815 end
|
adamc@395
|
816 | L.EFfi ("Basis", "ord_string") =>
|
adamc@395
|
817 let
|
adamc@395
|
818 fun boolBin s =
|
adamc@395
|
819 (L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
820 (L'.TFun ((L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@395
|
821 (L'.EAbs ("y", (L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
822 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@395
|
823 (L'.EBinop (s,
|
adamc@395
|
824 (L'.EBinop ("strcmp",
|
adamc@395
|
825 (L'.ERel 1, loc),
|
adamc@395
|
826 (L'.ERel 0, loc)), loc),
|
adamc@395
|
827 (L'.EPrim (Prim.Int (Int64.fromInt 0)), loc)), loc)), loc)), loc)
|
adamc@395
|
828 in
|
adamc@395
|
829 ordEx ((L'.TFfi ("Basis", "string"), loc),
|
adamc@395
|
830 boolBin "<",
|
adamc@395
|
831 boolBin "<=")
|
adamc@395
|
832 end
|
adamc@437
|
833 | L.EFfi ("Basis", "ord_time") =>
|
adamc@437
|
834 let
|
adamc@437
|
835 fun boolBin s =
|
adamc@437
|
836 (L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
837 (L'.TFun ((L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "bool"), loc)), loc),
|
adamc@437
|
838 (L'.EAbs ("y", (L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
839 (L'.TFfi ("Basis", "bool"), loc),
|
adamc@437
|
840 (L'.EBinop (s, (L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc)
|
adamc@437
|
841 in
|
adamc@437
|
842 ordEx ((L'.TFfi ("Basis", "time"), loc),
|
adamc@437
|
843 boolBin "<",
|
adamc@437
|
844 boolBin "<=")
|
adamc@437
|
845 end
|
adamc@389
|
846
|
adamc@286
|
847 | L.ECApp ((L.EFfi ("Basis", "show"), _), t) =>
|
adamc@286
|
848 let
|
adamc@286
|
849 val t = monoType env t
|
adamc@286
|
850 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@286
|
851 in
|
adamc@286
|
852 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@286
|
853 (L'.ERel 0, loc)), loc), fm)
|
adamc@286
|
854 end
|
adamc@286
|
855 | L.EFfi ("Basis", "show_int") =>
|
adamc@286
|
856 ((L'.EFfi ("Basis", "intToString"), loc), fm)
|
adamc@286
|
857 | L.EFfi ("Basis", "show_float") =>
|
adamc@286
|
858 ((L'.EFfi ("Basis", "floatToString"), loc), fm)
|
adamc@286
|
859 | L.EFfi ("Basis", "show_string") =>
|
adamc@286
|
860 let
|
adamc@286
|
861 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@286
|
862 in
|
adamc@286
|
863 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), fm)
|
adamc@286
|
864 end
|
adamc@286
|
865 | L.EFfi ("Basis", "show_bool") =>
|
adamc@286
|
866 ((L'.EFfi ("Basis", "boolToString"), loc), fm)
|
adamc@436
|
867 | L.EFfi ("Basis", "show_time") =>
|
adamc@436
|
868 ((L'.EFfi ("Basis", "timeToString"), loc), fm)
|
adamc@452
|
869 | L.ECApp ((L.EFfi ("Basis", "mkShow"), _), t) =>
|
adamc@452
|
870 let
|
adamc@452
|
871 val t = monoType env t
|
adamc@452
|
872 val b = (L'.TFfi ("Basis", "string"), loc)
|
adamc@452
|
873 val dom = (L'.TFun (t, b), loc)
|
adamc@452
|
874 in
|
adamc@452
|
875 ((L'.EAbs ("f", dom, dom,
|
adamc@452
|
876 (L'.ERel 0, loc)), loc), fm)
|
adamc@452
|
877 end
|
adamc@286
|
878
|
adamc@290
|
879 | L.ECApp ((L.EFfi ("Basis", "read"), _), t) =>
|
adamc@290
|
880 let
|
adamc@290
|
881 val t = monoType env t
|
adamc@290
|
882 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@290
|
883 in
|
adamc@292
|
884 ((L'.EAbs ("f", readType (t, loc), readType' (t, loc),
|
adamc@292
|
885 (L'.EField ((L'.ERel 0, loc), "Read"), loc)), loc), fm)
|
adamc@292
|
886 end
|
adamc@292
|
887 | L.ECApp ((L.EFfi ("Basis", "readError"), _), t) =>
|
adamc@292
|
888 let
|
adamc@292
|
889 val t = monoType env t
|
adamc@292
|
890 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@292
|
891 in
|
adamc@292
|
892 ((L'.EAbs ("f", readType (t, loc), readErrType (t, loc),
|
adamc@292
|
893 (L'.EField ((L'.ERel 0, loc), "ReadError"), loc)), loc), fm)
|
adamc@290
|
894 end
|
adamc@290
|
895 | L.EFfi ("Basis", "read_int") =>
|
adamc@292
|
896 let
|
adamc@292
|
897 val t = (L'.TFfi ("Basis", "int"), loc)
|
adamc@292
|
898 in
|
adamc@292
|
899 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToInt"), loc), readType' (t, loc)),
|
adamc@292
|
900 ("ReadError", (L'.EFfi ("Basis", "stringToInt_error"), loc), readErrType (t, loc))],
|
adamc@292
|
901 loc),
|
adamc@292
|
902 fm)
|
adamc@292
|
903 end
|
adamc@290
|
904 | L.EFfi ("Basis", "read_float") =>
|
adamc@292
|
905 let
|
adamc@292
|
906 val t = (L'.TFfi ("Basis", "float"), loc)
|
adamc@292
|
907 in
|
adamc@292
|
908 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToFloat"), loc), readType' (t, loc)),
|
adamc@292
|
909 ("ReadError", (L'.EFfi ("Basis", "stringToFloat_error"), loc), readErrType (t, loc))],
|
adamc@292
|
910 loc),
|
adamc@292
|
911 fm)
|
adamc@292
|
912 end
|
adamc@290
|
913 | L.EFfi ("Basis", "read_string") =>
|
adamc@290
|
914 let
|
adamc@290
|
915 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@290
|
916 in
|
adamc@292
|
917 ((L'.ERecord [("Read", (L'.EAbs ("s", s, (L'.TOption s, loc),
|
adamc@292
|
918 (L'.ESome (s, (L'.ERel 0, loc)), loc)), loc), readType' (s, loc)),
|
adamc@292
|
919 ("ReadError", (L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc), readErrType (s, loc))], loc),
|
adamc@292
|
920 fm)
|
adamc@290
|
921 end
|
adamc@290
|
922 | L.EFfi ("Basis", "read_bool") =>
|
adamc@292
|
923 let
|
adamc@292
|
924 val t = (L'.TFfi ("Basis", "bool"), loc)
|
adamc@292
|
925 in
|
adamc@292
|
926 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToBool"), loc), readType' (t, loc)),
|
adamc@292
|
927 ("ReadError", (L'.EFfi ("Basis", "stringToBool_error"), loc), readErrType (t, loc))],
|
adamc@292
|
928 loc),
|
adamc@292
|
929 fm)
|
adamc@292
|
930 end
|
adamc@436
|
931 | L.EFfi ("Basis", "read_time") =>
|
adamc@436
|
932 let
|
adamc@436
|
933 val t = (L'.TFfi ("Basis", "time"), loc)
|
adamc@436
|
934 in
|
adamc@436
|
935 ((L'.ERecord [("Read", (L'.EFfi ("Basis", "stringToTime"), loc), readType' (t, loc)),
|
adamc@436
|
936 ("ReadError", (L'.EFfi ("Basis", "stringToTime_error"), loc), readErrType (t, loc))],
|
adamc@436
|
937 loc),
|
adamc@436
|
938 fm)
|
adamc@436
|
939 end
|
adamc@290
|
940
|
adamc@564
|
941 | L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), _), _), t), _),
|
adamc@564
|
942 (L.EFfi ("Basis", "transaction_monad"), _)) =>
|
adamc@252
|
943 let
|
adamc@252
|
944 val t = monoType env t
|
adamc@252
|
945 in
|
adamc@252
|
946 ((L'.EAbs ("x", t,
|
adamc@252
|
947 (L'.TFun ((L'.TRecord [], loc), t), loc),
|
adamc@252
|
948 (L'.EAbs ("_", (L'.TRecord [], loc), t,
|
adamc@252
|
949 (L'.ERel 1, loc)), loc)), loc), fm)
|
adamc@252
|
950 end
|
adamc@564
|
951 | L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), t1), _), t2), _),
|
adamc@564
|
952 (L.EFfi ("Basis", "transaction_monad"), _)) =>
|
adamc@251
|
953 let
|
adamc@251
|
954 val t1 = monoType env t1
|
adamc@251
|
955 val t2 = monoType env t2
|
adamc@251
|
956 val un = (L'.TRecord [], loc)
|
adamc@252
|
957 val mt1 = (L'.TFun (un, t1), loc)
|
adamc@252
|
958 val mt2 = (L'.TFun (un, t2), loc)
|
adamc@251
|
959 in
|
adamc@572
|
960 ((L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc)), loc),
|
adamc@572
|
961 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), (L'.TFun (un, un), loc),
|
adamc@252
|
962 (L'.EAbs ("_", un, un,
|
adamc@252
|
963 (L'.ELet ("r", t1, (L'.EApp ((L'.ERel 2, loc),
|
adamc@252
|
964 (L'.ERecord [], loc)), loc),
|
adamc@252
|
965 (L'.EApp (
|
adamc@252
|
966 (L'.EApp ((L'.ERel 2, loc), (L'.ERel 0, loc)), loc),
|
adamc@252
|
967 (L'.ERecord [], loc)),
|
adamc@252
|
968 loc)), loc)), loc)), loc)), loc),
|
adamc@251
|
969 fm)
|
adamc@251
|
970 end
|
adamc@251
|
971
|
adamc@565
|
972 | L.ECApp ((L.EFfi ("Basis", "source"), _), t) =>
|
adamc@565
|
973 let
|
adamc@565
|
974 val t = monoType env t
|
adamc@565
|
975 in
|
adamc@565
|
976 ((L'.EAbs ("x", t, (L'.TFun ((L'.TRecord [], loc), (L'.TFfi ("Basis", "int"), loc)), loc),
|
adamc@565
|
977 (L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "int"), loc),
|
adamc@574
|
978 (L'.EFfiApp ("Basis", "new_client_source", [(L'.ERel 1, loc)]), loc)), loc)),
|
adamc@565
|
979 loc),
|
adamc@565
|
980 fm)
|
adamc@565
|
981 end
|
adamc@565
|
982
|
adamc@568
|
983 | L.EApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "return"), _), _), _), t), _),
|
adamc@568
|
984 (L.EFfi ("Basis", "signal_monad"), _)) =>
|
adamc@568
|
985 let
|
adamc@568
|
986 val t = monoType env t
|
adamc@568
|
987 in
|
adamc@568
|
988 ((L'.EAbs ("x", t, (L'.TSignal t, loc),
|
adamc@568
|
989 (L'.ESignalReturn (L'.ERel 0, loc), loc)), loc),
|
adamc@568
|
990 fm)
|
adamc@568
|
991 end
|
adamc@572
|
992 | L.EApp ((L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "bind"), _), _), _), t1), _), t2), _),
|
adamc@572
|
993 (L.EFfi ("Basis", "signal_monad"), _)) =>
|
adamc@572
|
994 let
|
adamc@572
|
995 val t1 = monoType env t1
|
adamc@572
|
996 val t2 = monoType env t2
|
adamc@572
|
997 val un = (L'.TRecord [], loc)
|
adamc@572
|
998 val mt1 = (L'.TSignal t1, loc)
|
adamc@572
|
999 val mt2 = (L'.TSignal t2, loc)
|
adamc@572
|
1000 in
|
adamc@572
|
1001 ((L'.EAbs ("m1", mt1, (L'.TFun ((L'.TFun (t1, mt2), loc), mt2), loc),
|
adamc@572
|
1002 (L'.EAbs ("m2", (L'.TFun (t1, mt2), loc), mt2,
|
adamc@572
|
1003 (L'.ESignalBind ((L'.ERel 1, loc), (L'.ERel 0, loc)), loc)), loc)), loc),
|
adamc@572
|
1004 fm)
|
adamc@572
|
1005 end
|
adamc@574
|
1006 | L.ECApp ((L.EFfi ("Basis", "signal"), _), t) =>
|
adamc@574
|
1007 let
|
adamc@574
|
1008 val t = monoType env t
|
adamc@574
|
1009 in
|
adamc@574
|
1010 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TSignal t, loc),
|
adamc@574
|
1011 (L'.ESignalSource (L'.ERel 0, loc), loc)), loc),
|
adamc@574
|
1012 fm)
|
adamc@574
|
1013 end
|
adamc@568
|
1014
|
adamc@462
|
1015 | L.ECApp ((L.EFfi ("Basis", "getCookie"), _), t) =>
|
adamc@462
|
1016 let
|
adamc@462
|
1017 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1018 val un = (L'.TRecord [], loc)
|
adamc@462
|
1019 val t = monoType env t
|
adamc@462
|
1020 in
|
adamc@462
|
1021 ((L'.EAbs ("c", s, (L'.TFun (un, s), loc),
|
adamc@462
|
1022 (L'.EAbs ("_", un, s,
|
adamc@463
|
1023 (L'.EUnurlify ((L'.EFfiApp ("Basis", "get_cookie", [(L'.ERel 1, loc)]), loc),
|
adamc@463
|
1024 t),
|
adamc@463
|
1025 loc)), loc)), loc),
|
adamc@462
|
1026 fm)
|
adamc@462
|
1027 end
|
adamc@462
|
1028
|
adamc@462
|
1029 | L.ECApp ((L.EFfi ("Basis", "setCookie"), _), t) =>
|
adamc@462
|
1030 let
|
adamc@462
|
1031 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
1032 val un = (L'.TRecord [], loc)
|
adamc@462
|
1033 val t = monoType env t
|
adamc@462
|
1034 val (e, fm) = urlifyExp env fm ((L'.ERel 1, loc), t)
|
adamc@462
|
1035 in
|
adamc@462
|
1036 ((L'.EAbs ("c", s, (L'.TFun (t, (L'.TFun (un, un), loc)), loc),
|
adamc@462
|
1037 (L'.EAbs ("v", t, (L'.TFun (un, un), loc),
|
adamc@462
|
1038 (L'.EAbs ("_", un, un,
|
adamc@466
|
1039 (L'.EFfiApp ("Basis", "set_cookie", [(L'.EPrim (Prim.String (!urlPrefix)),
|
adamc@466
|
1040 loc),
|
adamc@466
|
1041 (L'.ERel 2, loc),
|
adamc@466
|
1042 e]), loc)),
|
adamc@462
|
1043 loc)), loc)), loc),
|
adamc@462
|
1044 fm)
|
adamc@462
|
1045 end
|
adamc@462
|
1046
|
adamc@307
|
1047 | L.EFfiApp ("Basis", "dml", [e]) =>
|
adamc@307
|
1048 let
|
adamc@307
|
1049 val (e, fm) = monoExp (env, st, fm) e
|
adamc@307
|
1050 in
|
adamc@468
|
1051 ((L'.EDml e, loc),
|
adamc@307
|
1052 fm)
|
adamc@307
|
1053 end
|
adamc@308
|
1054
|
adamc@307
|
1055 | L.ECApp ((L.EFfi ("Basis", "insert"), _), fields) =>
|
adamc@307
|
1056 (case monoType env (L.TRecord fields, loc) of
|
adamc@307
|
1057 (L'.TRecord fields, _) =>
|
adamc@307
|
1058 let
|
adamc@307
|
1059 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@307
|
1060 val fields = map (fn (x, _) => (x, s)) fields
|
adamc@307
|
1061 val rt = (L'.TRecord fields, loc)
|
adamc@307
|
1062 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@307
|
1063 in
|
adamc@307
|
1064 ((L'.EAbs ("tab", s, (L'.TFun (rt, s), loc),
|
adamc@307
|
1065 (L'.EAbs ("fs", rt, s,
|
adamc@307
|
1066 strcat loc [sc "INSERT INTO ",
|
adamc@307
|
1067 (L'.ERel 1, loc),
|
adamc@307
|
1068 sc " (",
|
adamc@311
|
1069 strcatComma loc (map (fn (x, _) => sc ("uw_" ^ x)) fields),
|
adamc@307
|
1070 sc ") VALUES (",
|
adamc@307
|
1071 strcatComma loc (map (fn (x, _) =>
|
adamc@307
|
1072 (L'.EField ((L'.ERel 0, loc),
|
adamc@307
|
1073 x), loc)) fields),
|
adamc@307
|
1074 sc ")"]), loc)), loc),
|
adamc@307
|
1075 fm)
|
adamc@307
|
1076 end
|
adamc@307
|
1077 | _ => poly ())
|
adamc@307
|
1078
|
adamc@403
|
1079 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "update"), _), _), _), changed) =>
|
adamc@308
|
1080 (case monoType env (L.TRecord changed, loc) of
|
adamc@308
|
1081 (L'.TRecord changed, _) =>
|
adamc@308
|
1082 let
|
adamc@308
|
1083 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@308
|
1084 val changed = map (fn (x, _) => (x, s)) changed
|
adamc@308
|
1085 val rt = (L'.TRecord changed, loc)
|
adamc@308
|
1086 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@308
|
1087 in
|
adamc@308
|
1088 ((L'.EAbs ("fs", rt, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@308
|
1089 (L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@308
|
1090 (L'.EAbs ("e", s, s,
|
adamc@308
|
1091 strcat loc [sc "UPDATE ",
|
adamc@308
|
1092 (L'.ERel 1, loc),
|
adamc@308
|
1093 sc " AS T SET ",
|
adamc@308
|
1094 strcatComma loc (map (fn (x, _) =>
|
adamc@311
|
1095 strcat loc [sc ("uw_" ^ x
|
adamc@308
|
1096 ^ " = "),
|
adamc@308
|
1097 (L'.EField
|
adamc@308
|
1098 ((L'.ERel 2,
|
adamc@308
|
1099 loc),
|
adamc@308
|
1100 x), loc)])
|
adamc@308
|
1101 changed),
|
adamc@308
|
1102 sc " WHERE ",
|
adamc@308
|
1103 (L'.ERel 0, loc)]), loc)), loc)), loc),
|
adamc@308
|
1104 fm)
|
adamc@308
|
1105 end
|
adamc@308
|
1106 | _ => poly ())
|
adamc@308
|
1107
|
adamc@309
|
1108 | L.ECApp ((L.EFfi ("Basis", "delete"), _), _) =>
|
adamc@309
|
1109 let
|
adamc@309
|
1110 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@309
|
1111 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@309
|
1112 in
|
adamc@309
|
1113 ((L'.EAbs ("tab", s, (L'.TFun (s, s), loc),
|
adamc@309
|
1114 (L'.EAbs ("e", s, s,
|
adamc@309
|
1115 strcat loc [sc "DELETE FROM ",
|
adamc@309
|
1116 (L'.ERel 1, loc),
|
adamc@309
|
1117 sc " AS T WHERE ",
|
adamc@309
|
1118 (L'.ERel 0, loc)]), loc)), loc),
|
adamc@309
|
1119 fm)
|
adamc@309
|
1120 end
|
adamc@309
|
1121
|
adamc@252
|
1122 | L.ECApp (
|
adamc@252
|
1123 (L.ECApp (
|
adamc@252
|
1124 (L.ECApp ((L.EFfi ("Basis", "query"), _), (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1125 exps), _),
|
adamc@252
|
1126 state) =>
|
adamc@252
|
1127 (case monoType env (L.TRecord exps, loc) of
|
adamc@252
|
1128 (L'.TRecord exps, _) =>
|
adamc@252
|
1129 let
|
adamc@252
|
1130 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1131 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1132 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1133 | _ => NONE)
|
adamc@252
|
1134 | _ => NONE) tables
|
adamc@252
|
1135 in
|
adamc@252
|
1136 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1137 poly ()
|
adamc@252
|
1138 else
|
adamc@252
|
1139 let
|
adamc@252
|
1140 val tables = List.mapPartial (fn x => x) tables
|
adamc@252
|
1141 val state = monoType env state
|
adamc@252
|
1142 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1143 val un = (L'.TRecord [], loc)
|
adamc@252
|
1144
|
adamc@252
|
1145 val rt = exps @ map (fn (x, xts) => (x, (L'.TRecord xts, loc))) tables
|
adamc@252
|
1146 val ft = (L'.TFun ((L'.TRecord rt, loc),
|
adamc@252
|
1147 (L'.TFun (state,
|
adamc@252
|
1148 (L'.TFun (un, state), loc)),
|
adamc@252
|
1149 loc)), loc)
|
adamc@252
|
1150
|
adamc@267
|
1151 val body' = (L'.EApp (
|
adamc@267
|
1152 (L'.EApp (
|
adamc@267
|
1153 (L'.EApp ((L'.ERel 4, loc),
|
adamc@267
|
1154 (L'.ERel 1, loc)), loc),
|
adamc@267
|
1155 (L'.ERel 0, loc)), loc),
|
adamc@267
|
1156 (L'.ERecord [], loc)), loc)
|
adamc@252
|
1157
|
adamc@252
|
1158 val body = (L'.EQuery {exps = exps,
|
adamc@252
|
1159 tables = tables,
|
adamc@252
|
1160 state = state,
|
adamc@252
|
1161 query = (L'.ERel 3, loc),
|
adamc@252
|
1162 body = body',
|
adamc@252
|
1163 initial = (L'.ERel 1, loc)},
|
adamc@252
|
1164 loc)
|
adamc@252
|
1165 in
|
adamc@252
|
1166 ((L'.EAbs ("q", s, (L'.TFun (ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc)), loc),
|
adamc@252
|
1167 (L'.EAbs ("f", ft, (L'.TFun (state, (L'.TFun (un, state), loc)), loc),
|
adamc@252
|
1168 (L'.EAbs ("i", state, (L'.TFun (un, state), loc),
|
adamc@252
|
1169 (L'.EAbs ("_", un, state,
|
adamc@252
|
1170 body), loc)), loc)), loc)), loc), fm)
|
adamc@252
|
1171 end
|
adamc@252
|
1172 end
|
adamc@252
|
1173 | _ => poly ())
|
adamc@252
|
1174
|
adamc@252
|
1175 | L.ECApp ((L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_query"), _), _), _), _), _), _) =>
|
adamc@252
|
1176 let
|
adamc@252
|
1177 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1178 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1179 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1180 in
|
adamc@252
|
1181 ((L'.EAbs ("r",
|
adamc@252
|
1182 (L'.TRecord [("Rows", s), ("OrderBy", s), ("Limit", s), ("Offset", s)], loc),
|
adamc@252
|
1183 s,
|
adamc@252
|
1184 strcat loc [gf "Rows",
|
adamc@261
|
1185 (L'.ECase (gf "OrderBy",
|
adamc@261
|
1186 [((L'.PPrim (Prim.String ""), loc), sc ""),
|
adamc@261
|
1187 ((L'.PWild, loc),
|
adamc@261
|
1188 strcat loc [sc " ORDER BY ",
|
adamc@261
|
1189 gf "OrderBy"])],
|
adamc@261
|
1190 {disc = s, result = s}), loc),
|
adamc@252
|
1191 gf "Limit",
|
adamc@252
|
1192 gf "Offset"]), loc), fm)
|
adamc@252
|
1193 end
|
adamc@252
|
1194
|
adamc@252
|
1195 | L.ECApp (
|
adamc@252
|
1196 (L.ECApp (
|
adamc@252
|
1197 (L.ECApp (
|
adamc@252
|
1198 (L.ECApp (
|
adamc@252
|
1199 (L.EFfi ("Basis", "sql_query1"), _),
|
adamc@252
|
1200 (L.CRecord (_, tables), _)), _),
|
adamc@252
|
1201 (L.CRecord (_, grouped), _)), _),
|
adamc@252
|
1202 (L.CRecord (_, stables), _)), _),
|
adamc@252
|
1203 sexps) =>
|
adamc@252
|
1204 let
|
adamc@252
|
1205 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@252
|
1206 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1207 val un = (L'.TRecord [], loc)
|
adamc@252
|
1208 fun gf s = (L'.EField ((L'.ERel 0, loc), s), loc)
|
adamc@252
|
1209
|
adamc@252
|
1210 fun doTables tables =
|
adamc@252
|
1211 let
|
adamc@252
|
1212 val tables = map (fn ((L.CName x, _), xts) =>
|
adamc@252
|
1213 (case monoType env (L.TRecord xts, loc) of
|
adamc@252
|
1214 (L'.TRecord xts, _) => SOME (x, xts)
|
adamc@252
|
1215 | _ => NONE)
|
adamc@252
|
1216 | _ => NONE) tables
|
adamc@252
|
1217 in
|
adamc@252
|
1218 if List.exists (fn x => x = NONE) tables then
|
adamc@252
|
1219 NONE
|
adamc@252
|
1220 else
|
adamc@260
|
1221 let
|
adamc@260
|
1222 val tables = List.mapPartial (fn x => x) tables
|
adamc@260
|
1223 val tables = ListMergeSort.sort
|
adamc@260
|
1224 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1225 tables
|
adamc@260
|
1226 val tables = map (fn (x, xts) =>
|
adamc@260
|
1227 (x, ListMergeSort.sort
|
adamc@260
|
1228 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER)
|
adamc@260
|
1229 xts)) tables
|
adamc@260
|
1230 in
|
adamc@260
|
1231 SOME tables
|
adamc@260
|
1232 end
|
adamc@252
|
1233 end
|
adamc@252
|
1234 in
|
adamc@252
|
1235 case (doTables tables, doTables grouped, doTables stables, monoType env (L.TRecord sexps, loc)) of
|
adamc@252
|
1236 (SOME tables, SOME grouped, SOME stables, (L'.TRecord sexps, _)) =>
|
adamc@441
|
1237 let
|
adamc@441
|
1238 val sexps = ListMergeSort.sort
|
adamc@441
|
1239 (fn ((x, _), (y, _)) => String.compare (x, y) = GREATER) sexps
|
adamc@441
|
1240 in
|
adamc@441
|
1241 ((L'.EAbs ("r",
|
adamc@441
|
1242 (L'.TRecord [("From", (L'.TRecord (map (fn (x, _) => (x, s)) tables), loc)),
|
adamc@441
|
1243 ("Where", s),
|
adamc@441
|
1244 ("GroupBy", un),
|
adamc@441
|
1245 ("Having", s),
|
adamc@441
|
1246 ("SelectFields", un),
|
adamc@441
|
1247 ("SelectExps", (L'.TRecord (map (fn (x, _) => (x, s)) sexps), loc))],
|
adamc@441
|
1248 loc),
|
adamc@441
|
1249 s,
|
adamc@441
|
1250 strcat loc [sc "SELECT ",
|
adamc@441
|
1251 strcatComma loc (map (fn (x, t) =>
|
adamc@441
|
1252 strcat loc [
|
adamc@441
|
1253 (L'.EField (gf "SelectExps", x), loc),
|
adamc@441
|
1254 sc (" AS _" ^ x)
|
adamc@265
|
1255 ]) sexps
|
adamc@441
|
1256 @ map (fn (x, xts) =>
|
adamc@441
|
1257 strcatComma loc
|
adamc@441
|
1258 (map (fn (x', _) =>
|
adamc@441
|
1259 sc (x ^ ".uw_" ^ x'))
|
adamc@441
|
1260 xts)) stables),
|
adamc@441
|
1261 sc " FROM ",
|
adamc@441
|
1262 strcatComma loc (map (fn (x, _) => strcat loc [(L'.EField (gf "From", x), loc),
|
adamc@441
|
1263 sc (" AS " ^ x)]) tables),
|
adamc@441
|
1264 (L'.ECase (gf "Where",
|
adamc@441
|
1265 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@441
|
1266 sc ""),
|
adamc@441
|
1267 ((L'.PWild, loc),
|
adamc@441
|
1268 strcat loc [sc " WHERE ", gf "Where"])],
|
adamc@441
|
1269 {disc = s,
|
adamc@441
|
1270 result = s}), loc),
|
adamc@441
|
1271
|
adamc@441
|
1272 if List.all (fn (x, xts) =>
|
adamc@441
|
1273 case List.find (fn (x', _) => x' = x) grouped of
|
adamc@441
|
1274 NONE => List.null xts
|
adamc@441
|
1275 | SOME (_, xts') =>
|
adamc@441
|
1276 List.all (fn (x, _) =>
|
adamc@441
|
1277 List.exists (fn (x', _) => x' = x)
|
adamc@441
|
1278 xts') xts) tables then
|
adamc@441
|
1279 sc ""
|
adamc@441
|
1280 else
|
adamc@441
|
1281 strcat loc [
|
adamc@441
|
1282 sc " GROUP BY ",
|
adamc@441
|
1283 strcatComma loc (map (fn (x, xts) =>
|
adamc@441
|
1284 strcatComma loc
|
adamc@441
|
1285 (map (fn (x', _) =>
|
adamc@441
|
1286 sc (x ^ ".uw_" ^ x'))
|
adamc@441
|
1287 xts)) grouped)
|
adamc@441
|
1288 ],
|
adamc@259
|
1289
|
adamc@441
|
1290 (L'.ECase (gf "Having",
|
adamc@441
|
1291 [((L'.PPrim (Prim.String "TRUE"), loc),
|
adamc@441
|
1292 sc ""),
|
adamc@441
|
1293 ((L'.PWild, loc),
|
adamc@441
|
1294 strcat loc [sc " HAVING ", gf "Having"])],
|
adamc@441
|
1295 {disc = s,
|
adamc@441
|
1296 result = s}), loc)
|
adamc@441
|
1297 ]), loc),
|
adamc@441
|
1298 fm)
|
adamc@441
|
1299 end
|
adamc@252
|
1300 | _ => poly ()
|
adamc@252
|
1301 end
|
adamc@252
|
1302
|
adamc@252
|
1303 | L.ECApp (
|
adamc@252
|
1304 (L.ECApp (
|
adamc@252
|
1305 (L.ECApp (
|
adamc@252
|
1306 (L.ECApp (
|
adamc@252
|
1307 (L.EFfi ("Basis", "sql_inject"), _),
|
adamc@252
|
1308 _), _),
|
adamc@252
|
1309 _), _),
|
adamc@252
|
1310 _), _),
|
adamc@252
|
1311 t) =>
|
adamc@252
|
1312 let
|
adamc@252
|
1313 val t = monoType env t
|
adamc@252
|
1314 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@252
|
1315 in
|
adamc@252
|
1316 ((L'.EAbs ("f", (L'.TFun (t, s), loc), (L'.TFun (t, s), loc),
|
adamc@252
|
1317 (L'.ERel 0, loc)), loc), fm)
|
adamc@252
|
1318 end
|
adamc@252
|
1319
|
adamc@253
|
1320 | L.EFfi ("Basis", "sql_int") =>
|
adamc@253
|
1321 ((L'.EAbs ("x", (L'.TFfi ("Basis", "int"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1322 (L'.EFfiApp ("Basis", "sqlifyInt", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1323 fm)
|
adamc@253
|
1324 | L.EFfi ("Basis", "sql_float") =>
|
adamc@253
|
1325 ((L'.EAbs ("x", (L'.TFfi ("Basis", "float"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1326 (L'.EFfiApp ("Basis", "sqlifyFloat", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1327 fm)
|
adamc@253
|
1328 | L.EFfi ("Basis", "sql_bool") =>
|
adamc@253
|
1329 ((L'.EAbs ("x", (L'.TFfi ("Basis", "bool"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1330 (L'.EFfiApp ("Basis", "sqlifyBool", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1331 fm)
|
adamc@253
|
1332 | L.EFfi ("Basis", "sql_string") =>
|
adamc@253
|
1333 ((L'.EAbs ("x", (L'.TFfi ("Basis", "string"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@253
|
1334 (L'.EFfiApp ("Basis", "sqlifyString", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@253
|
1335 fm)
|
adamc@439
|
1336 | L.EFfi ("Basis", "sql_time") =>
|
adamc@439
|
1337 ((L'.EAbs ("x", (L'.TFfi ("Basis", "time"), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@439
|
1338 (L'.EFfiApp ("Basis", "sqlifyTime", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@439
|
1339 fm)
|
adamc@467
|
1340 | L.EFfi ("Basis", "sql_option_int") =>
|
adamc@467
|
1341 ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "int"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@467
|
1342 (L'.EFfiApp ("Basis", "sqlifyIntN", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@467
|
1343 fm)
|
adamc@467
|
1344 | L.EFfi ("Basis", "sql_option_float") =>
|
adamc@467
|
1345 ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "float"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@467
|
1346 (L'.EFfiApp ("Basis", "sqlifyFloatN", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@467
|
1347 fm)
|
adamc@467
|
1348 | L.EFfi ("Basis", "sql_option_bool") =>
|
adamc@467
|
1349 ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "bool"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@467
|
1350 (L'.EFfiApp ("Basis", "sqlifyBoolN", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@467
|
1351 fm)
|
adamc@467
|
1352 | L.EFfi ("Basis", "sql_option_string") =>
|
adamc@467
|
1353 ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "string"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@467
|
1354 (L'.EFfiApp ("Basis", "sqlifyStringN", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@467
|
1355 fm)
|
adamc@467
|
1356 | L.EFfi ("Basis", "sql_option_time") =>
|
adamc@467
|
1357 ((L'.EAbs ("x", (L'.TOption (L'.TFfi ("Basis", "time"), loc), loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@467
|
1358 (L'.EFfiApp ("Basis", "sqlifyTimeN", [(L'.ERel 0, loc)]), loc)), loc),
|
adamc@467
|
1359 fm)
|
adamc@253
|
1360
|
adamc@252
|
1361 | L.ECApp ((L.EFfi ("Basis", "sql_subset"), _), _) =>
|
adamc@252
|
1362 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1363 | L.ECApp ((L.EFfi ("Basis", "sql_subset_all"), _), _) =>
|
adamc@252
|
1364 ((L'.ERecord [], loc), fm)
|
adamc@252
|
1365
|
adamc@252
|
1366 | L.ECApp ((L.ECApp ((L.EFfi ("Basis", "sql_order_by_Nil"), _), _), _), _) =>
|
adamc@252
|
1367 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@261
|
1368 | L.ECApp (
|
adamc@261
|
1369 (L.ECApp (
|
adamc@261
|
1370 (L.ECApp (
|
adamc@261
|
1371 (L.EFfi ("Basis", "sql_order_by_Cons"), _),
|
adamc@261
|
1372 _), _),
|
adamc@261
|
1373 _), _),
|
adamc@261
|
1374 _) =>
|
adamc@261
|
1375 let
|
adamc@261
|
1376 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@261
|
1377 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@261
|
1378 in
|
adamc@268
|
1379 ((L'.EAbs ("e1", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@268
|
1380 (L'.EAbs ("d", s, (L'.TFun (s, s), loc),
|
adamc@268
|
1381 (L'.EAbs ("e2", s, s,
|
adamc@268
|
1382 (L'.ECase ((L'.ERel 0, loc),
|
adamc@268
|
1383 [((L'.PPrim (Prim.String ""), loc),
|
adamc@268
|
1384 strcat loc [(L'.ERel 2, loc),
|
adamc@268
|
1385 (L'.ERel 1, loc)]),
|
adamc@268
|
1386 ((L'.PWild, loc),
|
adamc@268
|
1387 strcat loc [(L'.ERel 2, loc),
|
adamc@268
|
1388 (L'.ERel 1, loc),
|
adamc@268
|
1389 sc ", ",
|
adamc@268
|
1390 (L'.ERel 0, loc)])],
|
adamc@268
|
1391 {disc = s, result = s}), loc)), loc)), loc)), loc),
|
adamc@261
|
1392 fm)
|
adamc@261
|
1393 end
|
adamc@252
|
1394
|
adamc@252
|
1395 | L.EFfi ("Basis", "sql_no_limit") =>
|
adamc@252
|
1396 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@262
|
1397 | L.EFfiApp ("Basis", "sql_limit", [e]) =>
|
adamc@262
|
1398 let
|
adamc@262
|
1399 val (e, fm) = monoExp (env, st, fm) e
|
adamc@262
|
1400 in
|
adamc@262
|
1401 (strcat loc [
|
adamc@262
|
1402 (L'.EPrim (Prim.String " LIMIT "), loc),
|
adamc@262
|
1403 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@262
|
1404 ],
|
adamc@262
|
1405 fm)
|
adamc@262
|
1406 end
|
adamc@262
|
1407
|
adamc@252
|
1408 | L.EFfi ("Basis", "sql_no_offset") =>
|
adamc@252
|
1409 ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@263
|
1410 | L.EFfiApp ("Basis", "sql_offset", [e]) =>
|
adamc@263
|
1411 let
|
adamc@263
|
1412 val (e, fm) = monoExp (env, st, fm) e
|
adamc@263
|
1413 in
|
adamc@263
|
1414 (strcat loc [
|
adamc@263
|
1415 (L'.EPrim (Prim.String " OFFSET "), loc),
|
adamc@263
|
1416 (L'.EFfiApp ("Basis", "sqlifyInt", [e]), loc)
|
adamc@263
|
1417 ],
|
adamc@263
|
1418 fm)
|
adamc@263
|
1419 end
|
adamc@253
|
1420
|
adamc@559
|
1421 | L.ECApp ((L.EFfi ("Basis", "sql_eq"), _), _) =>
|
adamc@253
|
1422 ((L'.EPrim (Prim.String "="), loc), fm)
|
adamc@559
|
1423 | L.ECApp ((L.EFfi ("Basis", "sql_ne"), _), _) =>
|
adamc@253
|
1424 ((L'.EPrim (Prim.String "<>"), loc), fm)
|
adamc@559
|
1425 | L.ECApp ((L.EFfi ("Basis", "sql_lt"), _), _) =>
|
adamc@253
|
1426 ((L'.EPrim (Prim.String "<"), loc), fm)
|
adamc@559
|
1427 | L.ECApp ((L.EFfi ("Basis", "sql_le"), _), _) =>
|
adamc@253
|
1428 ((L'.EPrim (Prim.String "<="), loc), fm)
|
adamc@559
|
1429 | L.ECApp ((L.EFfi ("Basis", "sql_gt"), _), _) =>
|
adamc@253
|
1430 ((L'.EPrim (Prim.String ">"), loc), fm)
|
adamc@559
|
1431 | L.ECApp ((L.EFfi ("Basis", "sql_ge"), _), _) =>
|
adamc@253
|
1432 ((L'.EPrim (Prim.String ">="), loc), fm)
|
adamc@253
|
1433
|
adamc@559
|
1434 | L.ECApp ((L.EFfi ("Basis", "sql_plus"), _), _) =>
|
adamc@559
|
1435 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1436 (L'.EPrim (Prim.String "+"), loc)), loc), fm)
|
adamc@559
|
1437 | L.ECApp ((L.EFfi ("Basis", "sql_minus"), _), _) =>
|
adamc@559
|
1438 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1439 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@559
|
1440 | L.ECApp ((L.EFfi ("Basis", "sql_times"), _), _) =>
|
adamc@559
|
1441 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1442 (L'.EPrim (Prim.String "*"), loc)), loc), fm)
|
adamc@559
|
1443 | L.ECApp ((L.EFfi ("Basis", "sql_div"), _), _) =>
|
adamc@559
|
1444 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1445 (L'.EPrim (Prim.String "/"), loc)), loc), fm)
|
adamc@559
|
1446 | L.EFfi ("Basis", "sql_mod") =>
|
adamc@559
|
1447 ((L'.EPrim (Prim.String "%"), loc), fm)
|
adamc@559
|
1448
|
adamc@253
|
1449 | L.ECApp (
|
adamc@253
|
1450 (L.ECApp (
|
adamc@253
|
1451 (L.ECApp (
|
adamc@253
|
1452 (L.ECApp (
|
adamc@254
|
1453 (L.ECApp (
|
adamc@264
|
1454 (L.EFfi ("Basis", "sql_unary"), _),
|
adamc@264
|
1455 _), _),
|
adamc@264
|
1456 _), _),
|
adamc@264
|
1457 _), _),
|
adamc@264
|
1458 _), _),
|
adamc@264
|
1459 _) =>
|
adamc@264
|
1460 let
|
adamc@264
|
1461 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@264
|
1462 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@264
|
1463 in
|
adamc@264
|
1464 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@264
|
1465 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@264
|
1466 strcat loc [sc "(",
|
adamc@264
|
1467 (L'.ERel 1, loc),
|
adamc@264
|
1468 sc " ",
|
adamc@264
|
1469 (L'.ERel 0, loc),
|
adamc@264
|
1470 sc ")"]), loc)), loc),
|
adamc@264
|
1471 fm)
|
adamc@264
|
1472 end
|
adamc@264
|
1473 | L.EFfi ("Basis", "sql_not") => ((L'.EPrim (Prim.String "NOT"), loc), fm)
|
adamc@559
|
1474 | L.ECApp ((L.EFfi ("Basis", "sql_neg"), _), _) =>
|
adamc@559
|
1475 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@559
|
1476 (L'.EPrim (Prim.String "-"), loc)), loc), fm)
|
adamc@264
|
1477
|
adamc@264
|
1478 | L.ECApp (
|
adamc@264
|
1479 (L.ECApp (
|
adamc@264
|
1480 (L.ECApp (
|
adamc@264
|
1481 (L.ECApp (
|
adamc@264
|
1482 (L.ECApp (
|
adamc@254
|
1483 (L.ECApp (
|
adamc@254
|
1484 (L.EFfi ("Basis", "sql_binary"), _),
|
adamc@254
|
1485 _), _),
|
adamc@254
|
1486 _), _),
|
adamc@254
|
1487 _), _),
|
adamc@254
|
1488 _), _),
|
adamc@254
|
1489 _), _),
|
adamc@254
|
1490 _) =>
|
adamc@254
|
1491 let
|
adamc@254
|
1492 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@254
|
1493 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@254
|
1494 in
|
adamc@254
|
1495 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@254
|
1496 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@254
|
1497 (L'.EAbs ("e2", s, s,
|
adamc@254
|
1498 strcat loc [sc "(",
|
adamc@254
|
1499 (L'.ERel 1, loc),
|
adamc@254
|
1500 sc " ",
|
adamc@254
|
1501 (L'.ERel 2, loc),
|
adamc@254
|
1502 sc " ",
|
adamc@254
|
1503 (L'.ERel 0, loc),
|
adamc@254
|
1504 sc ")"]), loc)), loc)), loc),
|
adamc@254
|
1505 fm)
|
adamc@254
|
1506 end
|
adamc@254
|
1507 | L.EFfi ("Basis", "sql_and") => ((L'.EPrim (Prim.String "AND"), loc), fm)
|
adamc@254
|
1508 | L.EFfi ("Basis", "sql_or") => ((L'.EPrim (Prim.String "OR"), loc), fm)
|
adamc@254
|
1509
|
adamc@254
|
1510 | L.ECApp (
|
adamc@254
|
1511 (L.ECApp (
|
adamc@254
|
1512 (L.ECApp (
|
adamc@254
|
1513 (L.ECApp (
|
adamc@253
|
1514 (L.ECApp (
|
adamc@253
|
1515 (L.ECApp (
|
adamc@253
|
1516 (L.ECApp (
|
adamc@253
|
1517 (L.EFfi ("Basis", "sql_field"), _),
|
adamc@253
|
1518 _), _),
|
adamc@253
|
1519 _), _),
|
adamc@253
|
1520 _), _),
|
adamc@253
|
1521 _), _),
|
adamc@253
|
1522 _), _),
|
adamc@253
|
1523 (L.CName tab, _)), _),
|
adamc@311
|
1524 (L.CName field, _)) => ((L'.EPrim (Prim.String (tab ^ ".uw_" ^ field)), loc), fm)
|
adamc@260
|
1525
|
adamc@260
|
1526 | L.ECApp (
|
adamc@260
|
1527 (L.ECApp (
|
adamc@260
|
1528 (L.ECApp (
|
adamc@260
|
1529 (L.ECApp (
|
adamc@261
|
1530 (L.ECApp (
|
adamc@261
|
1531 (L.EFfi ("Basis", "sql_exp"), _),
|
adamc@261
|
1532 _), _),
|
adamc@261
|
1533 _), _),
|
adamc@261
|
1534 _), _),
|
adamc@261
|
1535 _), _),
|
adamc@261
|
1536 (L.CName nm, _)) => ((L'.EPrim (Prim.String ("_" ^ nm)), loc), fm)
|
adamc@261
|
1537
|
adamc@261
|
1538 | L.ECApp (
|
adamc@261
|
1539 (L.ECApp (
|
adamc@261
|
1540 (L.ECApp (
|
adamc@261
|
1541 (L.ECApp (
|
adamc@260
|
1542 (L.EFfi ("Basis", "sql_relop"), _),
|
adamc@260
|
1543 _), _),
|
adamc@260
|
1544 _), _),
|
adamc@260
|
1545 _), _),
|
adamc@260
|
1546 _) =>
|
adamc@260
|
1547 let
|
adamc@260
|
1548 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@260
|
1549 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@260
|
1550 in
|
adamc@260
|
1551 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@260
|
1552 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@260
|
1553 (L'.EAbs ("e2", s, s,
|
adamc@260
|
1554 strcat loc [sc "((",
|
adamc@260
|
1555 (L'.ERel 1, loc),
|
adamc@260
|
1556 sc ") ",
|
adamc@260
|
1557 (L'.ERel 2, loc),
|
adamc@260
|
1558 sc " (",
|
adamc@260
|
1559 (L'.ERel 0, loc),
|
adamc@260
|
1560 sc "))"]), loc)), loc)), loc),
|
adamc@260
|
1561 fm)
|
adamc@260
|
1562 end
|
adamc@260
|
1563
|
adamc@260
|
1564 | L.EFfi ("Basis", "sql_union") => ((L'.EPrim (Prim.String "UNION"), loc), fm)
|
adamc@260
|
1565 | L.EFfi ("Basis", "sql_intersect") => ((L'.EPrim (Prim.String "INTERSECT"), loc), fm)
|
adamc@260
|
1566 | L.EFfi ("Basis", "sql_except") => ((L'.EPrim (Prim.String "EXCEPT"), loc), fm)
|
adamc@260
|
1567
|
adamc@265
|
1568 | L.ECApp (
|
adamc@265
|
1569 (L.ECApp (
|
adamc@265
|
1570 (L.ECApp (
|
adamc@265
|
1571 (L.EFfi ("Basis", "sql_count"), _),
|
adamc@265
|
1572 _), _),
|
adamc@265
|
1573 _), _),
|
adamc@544
|
1574 _) => ((L'.EPrim (Prim.String "COUNT(*)"), loc),
|
adamc@265
|
1575 fm)
|
adamc@266
|
1576
|
adamc@266
|
1577 | L.ECApp (
|
adamc@266
|
1578 (L.ECApp (
|
adamc@266
|
1579 (L.ECApp (
|
adamc@266
|
1580 (L.ECApp (
|
adamc@266
|
1581 (L.EFfi ("Basis", "sql_aggregate"), _),
|
adamc@266
|
1582 _), _),
|
adamc@266
|
1583 _), _),
|
adamc@266
|
1584 _), _),
|
adamc@266
|
1585 _) =>
|
adamc@266
|
1586 let
|
adamc@266
|
1587 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@266
|
1588 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@266
|
1589 in
|
adamc@266
|
1590 ((L'.EAbs ("c", s, (L'.TFun (s, (L'.TFun (s, s), loc)), loc),
|
adamc@266
|
1591 (L'.EAbs ("e1", s, (L'.TFun (s, s), loc),
|
adamc@266
|
1592 strcat loc [(L'.ERel 1, loc),
|
adamc@266
|
1593 sc "(",
|
adamc@266
|
1594 (L'.ERel 0, loc),
|
adamc@266
|
1595 sc ")"]), loc)), loc),
|
adamc@266
|
1596 fm)
|
adamc@266
|
1597 end
|
adamc@266
|
1598
|
adamc@266
|
1599 | L.EFfi ("Basis", "sql_summable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1600 | L.EFfi ("Basis", "sql_summable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1601 | L.ECApp ((L.EFfi ("Basis", "sql_avg"), _), _) =>
|
adamc@266
|
1602 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1603 (L'.EPrim (Prim.String "AVG"), loc)), loc),
|
adamc@266
|
1604 fm)
|
adamc@266
|
1605 | L.ECApp ((L.EFfi ("Basis", "sql_sum"), _), _) =>
|
adamc@266
|
1606 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1607 (L'.EPrim (Prim.String "SUM"), loc)), loc),
|
adamc@266
|
1608 fm)
|
adamc@266
|
1609
|
adamc@559
|
1610 | L.EFfi ("Basis", "sql_arith_int") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
1611 | L.EFfi ("Basis", "sql_arith_float") => ((L'.ERecord [], loc), fm)
|
adamc@559
|
1612
|
adamc@266
|
1613 | L.EFfi ("Basis", "sql_maxable_int") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1614 | L.EFfi ("Basis", "sql_maxable_float") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1615 | L.EFfi ("Basis", "sql_maxable_string") => ((L'.ERecord [], loc), fm)
|
adamc@266
|
1616 | L.ECApp ((L.EFfi ("Basis", "sql_max"), _), _) =>
|
adamc@266
|
1617 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1618 (L'.EPrim (Prim.String "MAX"), loc)), loc),
|
adamc@266
|
1619 fm)
|
adamc@266
|
1620 | L.ECApp ((L.EFfi ("Basis", "sql_min"), _), _) =>
|
adamc@266
|
1621 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TFfi ("Basis", "string"), loc),
|
adamc@266
|
1622 (L'.EPrim (Prim.String "MIN"), loc)), loc),
|
adamc@266
|
1623 fm)
|
adamc@266
|
1624
|
adamc@268
|
1625 | L.EFfi ("Basis", "sql_asc") => ((L'.EPrim (Prim.String ""), loc), fm)
|
adamc@268
|
1626 | L.EFfi ("Basis", "sql_desc") => ((L'.EPrim (Prim.String " DESC"), loc), fm)
|
adamc@268
|
1627
|
adamc@441
|
1628 | L.ECApp (
|
adamc@441
|
1629 (L.ECApp (
|
adamc@441
|
1630 (L.ECApp (
|
adamc@441
|
1631 (L.ECApp (
|
adamc@441
|
1632 (L.EFfi ("Basis", "sql_nfunc"), _),
|
adamc@441
|
1633 _), _),
|
adamc@441
|
1634 _), _),
|
adamc@441
|
1635 _), _),
|
adamc@441
|
1636 _) =>
|
adamc@441
|
1637 let
|
adamc@441
|
1638 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@441
|
1639 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@441
|
1640 in
|
adamc@441
|
1641 ((L'.EAbs ("s", s, s, (L'.ERel 0, loc)), loc),
|
adamc@441
|
1642 fm)
|
adamc@441
|
1643 end
|
adamc@441
|
1644 | L.EFfi ("Basis", "sql_current_timestamp") => ((L'.EPrim (Prim.String "CURRENT_TIMESTAMP"), loc), fm)
|
adamc@441
|
1645
|
adamc@470
|
1646 | (L.ECApp (
|
adamc@470
|
1647 (L.ECApp (
|
adamc@470
|
1648 (L.ECApp (
|
adamc@470
|
1649 (L.ECApp (
|
adamc@470
|
1650 (L.EFfi ("Basis", "sql_is_null"), _), _),
|
adamc@470
|
1651 _), _),
|
adamc@470
|
1652 _), _),
|
adamc@470
|
1653 _), _)) =>
|
adamc@470
|
1654 let
|
adamc@470
|
1655 val s = (L'.TFfi ("Basis", "string"), loc)
|
adamc@470
|
1656 fun sc s = (L'.EPrim (Prim.String s), loc)
|
adamc@470
|
1657 in
|
adamc@470
|
1658 ((L'.EAbs ("s", s, s,
|
adamc@470
|
1659 strcat loc [sc "(",
|
adamc@470
|
1660 (L'.ERel 0, loc),
|
adamc@470
|
1661 sc " IS NULL)"]), loc),
|
adamc@470
|
1662 fm)
|
adamc@470
|
1663 end
|
adamc@470
|
1664
|
adamc@338
|
1665 | L.EFfiApp ("Basis", "nextval", [e]) =>
|
adamc@338
|
1666 let
|
adamc@338
|
1667 val (e, fm) = monoExp (env, st, fm) e
|
adamc@338
|
1668 in
|
adamc@465
|
1669 ((L'.ENextval e, loc), fm)
|
adamc@338
|
1670 end
|
adamc@338
|
1671
|
adamc@139
|
1672 | L.EApp (
|
adamc@139
|
1673 (L.ECApp (
|
adamc@141
|
1674 (L.ECApp ((L.EFfi ("Basis", "cdata"), _), _), _),
|
adamc@139
|
1675 _), _),
|
adamc@179
|
1676 se) =>
|
adamc@179
|
1677 let
|
adamc@179
|
1678 val (se, fm) = monoExp (env, st, fm) se
|
adamc@179
|
1679 in
|
adamc@179
|
1680 ((L'.EFfiApp ("Basis", "htmlifyString", [se]), loc), fm)
|
adamc@179
|
1681 end
|
adamc@179
|
1682
|
adamc@95
|
1683 | L.EApp (
|
adamc@95
|
1684 (L.EApp (
|
adamc@95
|
1685 (L.ECApp (
|
adamc@95
|
1686 (L.ECApp (
|
adamc@95
|
1687 (L.ECApp (
|
adamc@139
|
1688 (L.ECApp (
|
adamc@140
|
1689 (L.EFfi ("Basis", "join"),
|
adamc@139
|
1690 _), _), _),
|
adamc@139
|
1691 _), _),
|
adamc@95
|
1692 _), _),
|
adamc@95
|
1693 _), _),
|
adamc@95
|
1694 xml1), _),
|
adamc@179
|
1695 xml2) =>
|
adamc@179
|
1696 let
|
adamc@179
|
1697 val (xml1, fm) = monoExp (env, st, fm) xml1
|
adamc@179
|
1698 val (xml2, fm) = monoExp (env, st, fm) xml2
|
adamc@179
|
1699 in
|
adamc@179
|
1700 ((L'.EStrcat (xml1, xml2), loc), fm)
|
adamc@179
|
1701 end
|
adamc@95
|
1702
|
adamc@95
|
1703 | L.EApp (
|
adamc@95
|
1704 (L.EApp (
|
adamc@104
|
1705 (L.EApp (
|
adamc@95
|
1706 (L.ECApp (
|
adamc@104
|
1707 (L.ECApp (
|
adamc@104
|
1708 (L.ECApp (
|
adamc@104
|
1709 (L.ECApp (
|
adamc@139
|
1710 (L.ECApp (
|
adamc@139
|
1711 (L.ECApp (
|
adamc@139
|
1712 (L.ECApp (
|
adamc@139
|
1713 (L.ECApp (
|
adamc@139
|
1714 (L.EFfi ("Basis", "tag"),
|
adamc@139
|
1715 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@104
|
1716 attrs), _),
|
adamc@95
|
1717 tag), _),
|
adamc@95
|
1718 xml) =>
|
adamc@95
|
1719 let
|
adamc@140
|
1720 fun getTag' (e, _) =
|
adamc@140
|
1721 case e of
|
adamc@143
|
1722 L.EFfi ("Basis", tag) => (tag, [])
|
adamc@143
|
1723 | L.ECApp (e, t) => let
|
adamc@143
|
1724 val (tag, ts) = getTag' e
|
adamc@143
|
1725 in
|
adamc@143
|
1726 (tag, ts @ [t])
|
adamc@143
|
1727 end
|
adamc@140
|
1728 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@140
|
1729 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
1730 ("", []))
|
adamc@140
|
1731
|
adamc@95
|
1732 fun getTag (e, _) =
|
adamc@95
|
1733 case e of
|
adamc@143
|
1734 L.EFfiApp ("Basis", tag, [(L.ERecord [], _)]) => (tag, [])
|
adamc@140
|
1735 | L.EApp (e, (L.ERecord [], _)) => getTag' e
|
adamc@95
|
1736 | _ => (E.errorAt loc "Non-constant XML tag";
|
adamc@95
|
1737 Print.eprefaces' [("Expression", CorePrint.p_exp env tag)];
|
adamc@143
|
1738 ("", []))
|
adamc@95
|
1739
|
adamc@143
|
1740 val (tag, targs) = getTag tag
|
adamc@95
|
1741
|
adamc@179
|
1742 val (attrs, fm) = monoExp (env, st, fm) attrs
|
adamc@104
|
1743
|
adamc@143
|
1744 fun tagStart tag =
|
adamc@104
|
1745 case #1 attrs of
|
adamc@104
|
1746 L'.ERecord xes =>
|
adamc@104
|
1747 let
|
adamc@104
|
1748 fun lowercaseFirst "" = ""
|
adamc@143
|
1749 | lowercaseFirst s = str (Char.toLower (String.sub (s, 0)))
|
adamc@143
|
1750 ^ String.extract (s, 1, NONE)
|
adamc@104
|
1751
|
adamc@104
|
1752 val s = (L'.EPrim (Prim.String (String.concat ["<", tag])), loc)
|
adamc@104
|
1753 in
|
adamc@410
|
1754 foldl (fn (("Action", _, _), acc) => acc
|
adamc@410
|
1755 | ((x, e, t), (s, fm)) =>
|
adamc@347
|
1756 case t of
|
adamc@347
|
1757 (L'.TFfi ("Basis", "bool"), _) =>
|
adamc@347
|
1758 let
|
adamc@347
|
1759 val s' = " " ^ lowercaseFirst x
|
adamc@347
|
1760 in
|
adamc@347
|
1761 ((L'.ECase (e,
|
adamc@347
|
1762 [((L'.PCon (L'.Enum,
|
adamc@347
|
1763 L'.PConFfi {mod = "Basis",
|
adamc@347
|
1764 datatyp = "bool",
|
adamc@347
|
1765 con = "True",
|
adamc@347
|
1766 arg = NONE},
|
adamc@347
|
1767 NONE), loc),
|
adamc@347
|
1768 (L'.EStrcat (s,
|
adamc@347
|
1769 (L'.EPrim (Prim.String s'), loc)), loc)),
|
adamc@347
|
1770 ((L'.PCon (L'.Enum,
|
adamc@347
|
1771 L'.PConFfi {mod = "Basis",
|
adamc@347
|
1772 datatyp = "bool",
|
adamc@347
|
1773 con = "False",
|
adamc@347
|
1774 arg = NONE},
|
adamc@347
|
1775 NONE), loc),
|
adamc@347
|
1776 s)],
|
adamc@347
|
1777 {disc = (L'.TFfi ("Basis", "bool"), loc),
|
adamc@347
|
1778 result = (L'.TFfi ("Basis", "string"), loc)}), loc),
|
adamc@347
|
1779 fm)
|
adamc@347
|
1780 end
|
adamc@566
|
1781 | (L'.TFun _, _) =>
|
adamc@566
|
1782 let
|
adamc@566
|
1783 val s' = " " ^ lowercaseFirst x ^ "='"
|
adamc@566
|
1784 in
|
adamc@566
|
1785 ((L'.EStrcat (s,
|
adamc@566
|
1786 (L'.EStrcat (
|
adamc@566
|
1787 (L'.EPrim (Prim.String s'), loc),
|
adamc@566
|
1788 (L'.EStrcat (
|
adamc@568
|
1789 (L'.EJavaScript (L'.Attribute, e), loc),
|
adamc@566
|
1790 (L'.EPrim (Prim.String "'"), loc)), loc)),
|
adamc@566
|
1791 loc)), loc),
|
adamc@566
|
1792 fm)
|
adamc@566
|
1793 end
|
adamc@347
|
1794 | _ =>
|
adamc@347
|
1795 let
|
adamc@347
|
1796 val fooify =
|
adamc@347
|
1797 case x of
|
adamc@347
|
1798 "Href" => urlifyExp
|
adamc@347
|
1799 | "Link" => urlifyExp
|
adamc@347
|
1800 | _ => attrifyExp
|
adamc@120
|
1801
|
adamc@347
|
1802 val xp = " " ^ lowercaseFirst x ^ "=\""
|
adamc@179
|
1803
|
adamc@347
|
1804 val (e, fm) = fooify env fm (e, t)
|
adamc@347
|
1805 in
|
adamc@347
|
1806 ((L'.EStrcat (s,
|
adamc@347
|
1807 (L'.EStrcat ((L'.EPrim (Prim.String xp), loc),
|
adamc@347
|
1808 (L'.EStrcat (e,
|
adamc@347
|
1809 (L'.EPrim (Prim.String "\""),
|
adamc@347
|
1810 loc)),
|
adamc@347
|
1811 loc)),
|
adamc@347
|
1812 loc)), loc),
|
adamc@347
|
1813 fm)
|
adamc@347
|
1814 end)
|
adamc@179
|
1815 (s, fm) xes
|
adamc@104
|
1816 end
|
adamc@143
|
1817 | _ => raise Fail "Non-record attributes!"
|
adamc@104
|
1818
|
adamc@143
|
1819 fun input typ =
|
adamc@143
|
1820 case targs of
|
adamc@155
|
1821 [_, (L.CName name, _)] =>
|
adamc@179
|
1822 let
|
adamc@179
|
1823 val (ts, fm) = tagStart "input"
|
adamc@179
|
1824 in
|
adamc@179
|
1825 ((L'.EStrcat (ts,
|
adamc@179
|
1826 (L'.EPrim (Prim.String (" type=\"" ^ typ ^ "\" name=\"" ^ name ^ "\"/>")),
|
adamc@179
|
1827 loc)), loc), fm)
|
adamc@179
|
1828 end
|
adamc@143
|
1829 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
1830 raise Fail "No name passed to input tag")
|
adamc@104
|
1831
|
adamc@565
|
1832 fun normal (tag, extra, extraInner) =
|
adamc@143
|
1833 let
|
adamc@179
|
1834 val (tagStart, fm) = tagStart tag
|
adamc@152
|
1835 val tagStart = case extra of
|
adamc@152
|
1836 NONE => tagStart
|
adamc@152
|
1837 | SOME extra => (L'.EStrcat (tagStart, extra), loc)
|
adamc@152
|
1838
|
adamc@143
|
1839 fun normal () =
|
adamc@179
|
1840 let
|
adamc@179
|
1841 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@565
|
1842 val xml = case extraInner of
|
adamc@565
|
1843 NONE => xml
|
adamc@565
|
1844 | SOME ei => (L'.EStrcat (ei, xml), loc)
|
adamc@179
|
1845 in
|
adamc@179
|
1846 ((L'.EStrcat ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String ">"), loc)), loc),
|
adamc@179
|
1847 (L'.EStrcat (xml,
|
adamc@179
|
1848 (L'.EPrim (Prim.String (String.concat ["</", tag, ">"])),
|
adamc@179
|
1849 loc)), loc)),
|
adamc@179
|
1850 loc),
|
adamc@179
|
1851 fm)
|
adamc@179
|
1852 end
|
adamc@143
|
1853 in
|
adamc@143
|
1854 case xml of
|
adamc@143
|
1855 (L.EApp ((L.ECApp (
|
adamc@143
|
1856 (L.ECApp ((L.EFfi ("Basis", "cdata"), _),
|
adamc@143
|
1857 _), _),
|
adamc@143
|
1858 _), _),
|
adamc@143
|
1859 (L.EPrim (Prim.String s), _)), _) =>
|
adamc@143
|
1860 if CharVector.all Char.isSpace s then
|
adamc@179
|
1861 ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String "/>"), loc)), loc), fm)
|
adamc@143
|
1862 else
|
adamc@143
|
1863 normal ()
|
adamc@143
|
1864 | _ => normal ()
|
adamc@143
|
1865 end
|
adamc@152
|
1866 in
|
adamc@152
|
1867 case tag of
|
adamc@565
|
1868 "body" => normal ("body", NONE,
|
adamc@569
|
1869 SOME (L'.EStrcat ((L'.EPrim (Prim.String "<script src=\"/app.js\"></script>"), loc),
|
adamc@569
|
1870 (L'.EFfiApp ("Basis", "get_script", [(L'.ERecord [], loc)]),
|
adamc@569
|
1871 loc)), loc))
|
adamc@568
|
1872
|
adamc@568
|
1873 | "dyn" =>
|
adamc@568
|
1874 (case #1 attrs of
|
adamc@571
|
1875 (*L'.ERecord [("Signal", (L'.EApp ((L'.EAbs (_, _, _, (L'.ESignalReturn (L'.ERel 0, _), _)), _),
|
adamc@568
|
1876 e), _), _)] => (e, fm) *)
|
adamc@568
|
1877
|
adamc@568
|
1878 L'.ERecord [("Signal", e, _)] =>
|
adamc@568
|
1879 ((L'.EStrcat
|
adamc@571
|
1880 ((L'.EPrim (Prim.String "<script type=\"text/javascript\">dyn("), loc),
|
adamc@571
|
1881 (L'.EStrcat ((L'.EJavaScript (L'.Script, e), loc),
|
adamc@571
|
1882 (L'.EPrim (Prim.String ")</script>"), loc)), loc)), loc),
|
adamc@568
|
1883 fm)
|
adamc@568
|
1884 | _ => raise Fail "Monoize: Bad dyn attributes")
|
adamc@565
|
1885
|
adamc@565
|
1886 | "submit" => normal ("input type=\"submit\"", NONE, NONE)
|
adamc@152
|
1887
|
adamc@152
|
1888 | "textbox" =>
|
adamc@152
|
1889 (case targs of
|
adamc@152
|
1890 [_, (L.CName name, _)] =>
|
adamc@179
|
1891 let
|
adamc@179
|
1892 val (ts, fm) = tagStart "input"
|
adamc@179
|
1893 in
|
adamc@179
|
1894 ((L'.EStrcat (ts,
|
adamc@179
|
1895 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\"/>")),
|
adamc@179
|
1896 loc)), loc), fm)
|
adamc@179
|
1897 end
|
adamc@152
|
1898 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
1899 raise Fail "No name passed to textarea tag"))
|
adamc@155
|
1900 | "password" => input "password"
|
adamc@361
|
1901 | "textarea" =>
|
adamc@152
|
1902 (case targs of
|
adamc@152
|
1903 [_, (L.CName name, _)] =>
|
adamc@179
|
1904 let
|
adamc@179
|
1905 val (ts, fm) = tagStart "textarea"
|
adamc@179
|
1906 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
1907 in
|
adamc@179
|
1908 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@179
|
1909 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")), loc)), loc),
|
adamc@179
|
1910 (L'.EStrcat (xml,
|
adamc@179
|
1911 (L'.EPrim (Prim.String "</textarea>"),
|
adamc@179
|
1912 loc)), loc)),
|
adamc@179
|
1913 loc), fm)
|
adamc@179
|
1914 end
|
adamc@152
|
1915 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
1916 raise Fail "No name passed to ltextarea tag"))
|
adamc@153
|
1917
|
adamc@190
|
1918 | "checkbox" => input "checkbox"
|
adamc@190
|
1919
|
adamc@153
|
1920 | "radio" =>
|
adamc@153
|
1921 (case targs of
|
adamc@153
|
1922 [_, (L.CName name, _)] =>
|
adamc@179
|
1923 monoExp (env, St.setRadioGroup (st, name), fm) xml
|
adamc@153
|
1924 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@153
|
1925 raise Fail "No name passed to radio tag"))
|
adamc@153
|
1926 | "radioOption" =>
|
adamc@153
|
1927 (case St.radioGroup st of
|
adamc@153
|
1928 NONE => raise Fail "No name for radioGroup"
|
adamc@153
|
1929 | SOME name =>
|
adamc@153
|
1930 normal ("input",
|
adamc@565
|
1931 SOME (L'.EPrim (Prim.String (" type=\"radio\" name=\"" ^ name ^ "\"")), loc),
|
adamc@565
|
1932 NONE))
|
adamc@152
|
1933
|
adamc@361
|
1934 | "select" =>
|
adamc@154
|
1935 (case targs of
|
adamc@154
|
1936 [_, (L.CName name, _)] =>
|
adamc@179
|
1937 let
|
adamc@179
|
1938 val (ts, fm) = tagStart "select"
|
adamc@179
|
1939 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@179
|
1940 in
|
adamc@179
|
1941 ((L'.EStrcat ((L'.EStrcat (ts,
|
adamc@179
|
1942 (L'.EPrim (Prim.String (" name=\"" ^ name ^ "\">")), loc)), loc),
|
adamc@179
|
1943 (L'.EStrcat (xml,
|
adamc@179
|
1944 (L'.EPrim (Prim.String "</select>"),
|
adamc@179
|
1945 loc)), loc)),
|
adamc@179
|
1946 loc),
|
adamc@179
|
1947 fm)
|
adamc@179
|
1948 end
|
adamc@154
|
1949 | _ => (Print.prefaces "Targs" (map (fn t => ("T", CorePrint.p_con env t)) targs);
|
adamc@154
|
1950 raise Fail "No name passed to lselect tag"))
|
adamc@154
|
1951
|
adamc@565
|
1952 | "option" => normal ("option", NONE, NONE)
|
adamc@154
|
1953
|
adamc@565
|
1954 | "tabl" => normal ("table", NONE, NONE)
|
adamc@565
|
1955 | _ => normal (tag, NONE, NONE)
|
adamc@95
|
1956 end
|
adamc@94
|
1957
|
adamc@141
|
1958 | L.EApp ((L.ECApp (
|
adamc@361
|
1959 (L.ECApp ((L.EFfi ("Basis", "form"), _), _), _),
|
adamc@141
|
1960 _), _),
|
adamc@141
|
1961 xml) =>
|
adamc@143
|
1962 let
|
adamc@143
|
1963 fun findSubmit (e, _) =
|
adamc@143
|
1964 case e of
|
adamc@143
|
1965 L.EApp (
|
adamc@143
|
1966 (L.EApp (
|
adamc@143
|
1967 (L.ECApp (
|
adamc@143
|
1968 (L.ECApp (
|
adamc@143
|
1969 (L.ECApp (
|
adamc@143
|
1970 (L.ECApp (
|
adamc@143
|
1971 (L.EFfi ("Basis", "join"),
|
adamc@143
|
1972 _), _), _),
|
adamc@143
|
1973 _), _),
|
adamc@143
|
1974 _), _),
|
adamc@143
|
1975 _), _),
|
adamc@143
|
1976 xml1), _),
|
adamc@143
|
1977 xml2) => (case findSubmit xml1 of
|
adamc@143
|
1978 Error => Error
|
adamc@143
|
1979 | NotFound => findSubmit xml2
|
adamc@143
|
1980 | Found e =>
|
adamc@143
|
1981 case findSubmit xml2 of
|
adamc@143
|
1982 NotFound => Found e
|
adamc@143
|
1983 | _ => Error)
|
adamc@143
|
1984 | L.EApp (
|
adamc@143
|
1985 (L.EApp (
|
adamc@143
|
1986 (L.EApp (
|
adamc@143
|
1987 (L.ECApp (
|
adamc@143
|
1988 (L.ECApp (
|
adamc@143
|
1989 (L.ECApp (
|
adamc@143
|
1990 (L.ECApp (
|
adamc@143
|
1991 (L.ECApp (
|
adamc@143
|
1992 (L.ECApp (
|
adamc@143
|
1993 (L.ECApp (
|
adamc@143
|
1994 (L.ECApp (
|
adamc@143
|
1995 (L.EFfi ("Basis", "tag"),
|
adamc@143
|
1996 _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _), _),
|
adamc@143
|
1997 attrs), _),
|
adamc@143
|
1998 _), _),
|
adamc@143
|
1999 xml) =>
|
adamc@143
|
2000 (case #1 attrs of
|
adamc@143
|
2001 L.ERecord xes =>
|
adamc@143
|
2002 (case ListUtil.search (fn ((L.CName "Action", _), e, t) => SOME (e, t)
|
adamc@143
|
2003 | _ => NONE) xes of
|
adamc@143
|
2004 NONE => findSubmit xml
|
adamc@143
|
2005 | SOME et =>
|
adamc@143
|
2006 case findSubmit xml of
|
adamc@143
|
2007 NotFound => Found et
|
adamc@143
|
2008 | _ => Error)
|
adamc@143
|
2009 | _ => findSubmit xml)
|
adamc@143
|
2010 | _ => NotFound
|
adamc@143
|
2011
|
adamc@143
|
2012 val (action, actionT) = case findSubmit xml of
|
adamc@143
|
2013 NotFound => raise Fail "No submit found"
|
adamc@143
|
2014 | Error => raise Fail "Not ready for multi-submit lforms yet"
|
adamc@143
|
2015 | Found et => et
|
adamc@143
|
2016
|
adamc@143
|
2017 val actionT = monoType env actionT
|
adamc@179
|
2018 val (action, fm) = monoExp (env, st, fm) action
|
adamc@179
|
2019 val (action, fm) = urlifyExp env fm (action, actionT)
|
adamc@179
|
2020 val (xml, fm) = monoExp (env, st, fm) xml
|
adamc@143
|
2021 in
|
adamc@179
|
2022 ((L'.EStrcat ((L'.EStrcat ((L'.EPrim (Prim.String "<form action=\""), loc),
|
adamc@179
|
2023 (L'.EStrcat (action,
|
adamc@179
|
2024 (L'.EPrim (Prim.String "\">"), loc)), loc)), loc),
|
adamc@179
|
2025 (L'.EStrcat (xml,
|
adamc@179
|
2026 (L'.EPrim (Prim.String "</form>"), loc)), loc)), loc),
|
adamc@179
|
2027 fm)
|
adamc@143
|
2028 end
|
adamc@141
|
2029
|
adamc@148
|
2030 | L.EApp ((L.ECApp (
|
adamc@148
|
2031 (L.ECApp (
|
adamc@148
|
2032 (L.ECApp (
|
adamc@148
|
2033 (L.ECApp (
|
adamc@148
|
2034 (L.EFfi ("Basis", "useMore"), _), _), _),
|
adamc@148
|
2035 _), _),
|
adamc@148
|
2036 _), _),
|
adamc@148
|
2037 _), _),
|
adamc@179
|
2038 xml) => monoExp (env, st, fm) xml
|
adamc@148
|
2039
|
adamc@283
|
2040 | L.ECApp ((L.EFfi ("Basis", "error"), _), t) =>
|
adamc@283
|
2041 let
|
adamc@283
|
2042 val t = monoType env t
|
adamc@283
|
2043 in
|
adamc@283
|
2044 ((L'.EAbs ("s", (L'.TFfi ("Basis", "string"), loc), t,
|
adamc@283
|
2045 (L'.EError ((L'.ERel 0, loc), t), loc)), loc),
|
adamc@283
|
2046 fm)
|
adamc@283
|
2047 end
|
adamc@283
|
2048
|
adamc@179
|
2049 | L.EApp (e1, e2) =>
|
adamc@179
|
2050 let
|
adamc@179
|
2051 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@179
|
2052 val (e2, fm) = monoExp (env, st, fm) e2
|
adamc@179
|
2053 in
|
adamc@179
|
2054 ((L'.EApp (e1, e2), loc), fm)
|
adamc@179
|
2055 end
|
adamc@26
|
2056 | L.EAbs (x, dom, ran, e) =>
|
adamc@179
|
2057 let
|
adamc@179
|
2058 val (e, fm) = monoExp (Env.pushERel env x dom, st, fm) e
|
adamc@179
|
2059 in
|
adamc@179
|
2060 ((L'.EAbs (x, monoType env dom, monoType env ran, e), loc), fm)
|
adamc@179
|
2061 end
|
adamc@25
|
2062 | L.ECApp _ => poly ()
|
adamc@25
|
2063 | L.ECAbs _ => poly ()
|
adamc@25
|
2064
|
adamc@252
|
2065 | L.EFfi mx => ((L'.EFfi mx, loc), fm)
|
adamc@252
|
2066 | L.EFfiApp (m, x, es) =>
|
adamc@252
|
2067 let
|
adamc@252
|
2068 val (es, fm) = ListUtil.foldlMap (fn (e, fm) => monoExp (env, st, fm) e) fm es
|
adamc@252
|
2069 in
|
adamc@252
|
2070 ((L'.EFfiApp (m, x, es), loc), fm)
|
adamc@252
|
2071 end
|
adamc@252
|
2072
|
adamc@179
|
2073 | L.ERecord xes =>
|
adamc@179
|
2074 let
|
adamc@179
|
2075 val (xes, fm) = ListUtil.foldlMap
|
adamc@179
|
2076 (fn ((x, e, t), fm) =>
|
adamc@179
|
2077 let
|
adamc@179
|
2078 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2079 in
|
adamc@179
|
2080 ((monoName env x,
|
adamc@179
|
2081 e,
|
adamc@179
|
2082 monoType env t), fm)
|
adamc@179
|
2083 end) fm xes
|
adamc@179
|
2084 in
|
adamc@179
|
2085 ((L'.ERecord xes, loc), fm)
|
adamc@179
|
2086 end
|
adamc@179
|
2087 | L.EField (e, x, _) =>
|
adamc@179
|
2088 let
|
adamc@179
|
2089 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2090 in
|
adamc@179
|
2091 ((L'.EField (e, monoName env x), loc), fm)
|
adamc@179
|
2092 end
|
adamc@445
|
2093 | L.EConcat _ => poly ()
|
adamc@149
|
2094 | L.ECut _ => poly ()
|
adamc@493
|
2095 | L.ECutMulti _ => poly ()
|
adamc@73
|
2096 | L.EFold _ => poly ()
|
adamc@177
|
2097
|
adamc@182
|
2098 | L.ECase (e, pes, {disc, result}) =>
|
adamc@179
|
2099 let
|
adamc@179
|
2100 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2101 val (pes, fm) = ListUtil.foldlMap
|
adamc@179
|
2102 (fn ((p, e), fm) =>
|
adamc@179
|
2103 let
|
adamc@179
|
2104 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2105 in
|
adamc@182
|
2106 ((monoPat env p, e), fm)
|
adamc@179
|
2107 end) fm pes
|
adamc@179
|
2108 in
|
adamc@182
|
2109 ((L'.ECase (e, pes, {disc = monoType env disc, result = monoType env result}), loc), fm)
|
adamc@179
|
2110 end
|
adamc@177
|
2111
|
adamc@179
|
2112 | L.EWrite e =>
|
adamc@179
|
2113 let
|
adamc@179
|
2114 val (e, fm) = monoExp (env, st, fm) e
|
adamc@179
|
2115 in
|
adamc@252
|
2116 ((L'.EAbs ("_", (L'.TRecord [], loc), (L'.TRecord [], loc),
|
adamc@252
|
2117 (L'.EWrite (liftExpInExp 0 e), loc)), loc), fm)
|
adamc@179
|
2118 end
|
adamc@110
|
2119
|
adamc@179
|
2120 | L.EClosure (n, es) =>
|
adamc@179
|
2121 let
|
adamc@179
|
2122 val (es, fm) = ListUtil.foldlMap (fn (e, fm) =>
|
adamc@179
|
2123 monoExp (env, st, fm) e)
|
adamc@179
|
2124 fm es
|
adamc@179
|
2125 in
|
adamc@179
|
2126 ((L'.EClosure (n, es), loc), fm)
|
adamc@179
|
2127 end
|
adamc@450
|
2128
|
adamc@450
|
2129 | L.ELet (x, t, e1, e2) =>
|
adamc@450
|
2130 let
|
adamc@450
|
2131 val t' = monoType env t
|
adamc@450
|
2132 val (e1, fm) = monoExp (env, st, fm) e1
|
adamc@450
|
2133 val (e2, fm) = monoExp (Env.pushERel env x t, st, fm) e2
|
adamc@450
|
2134 in
|
adamc@450
|
2135 ((L'.ELet (x, t', e1, e2), loc), fm)
|
adamc@450
|
2136 end
|
adamc@25
|
2137 end
|
adamc@25
|
2138
|
adamc@179
|
2139 fun monoDecl (env, fm) (all as (d, loc)) =
|
adamc@25
|
2140 let
|
adamc@25
|
2141 fun poly () =
|
adamc@25
|
2142 (E.errorAt loc "Unsupported declaration";
|
adamc@25
|
2143 Print.eprefaces' [("Declaration", CorePrint.p_decl env all)];
|
adamc@25
|
2144 NONE)
|
adamc@25
|
2145 in
|
adamc@25
|
2146 case d of
|
adamc@25
|
2147 L.DCon _ => NONE
|
adamc@193
|
2148 | L.DDatatype (x, n, [], xncs) =>
|
adamc@193
|
2149 let
|
adamc@196
|
2150 val env' = Env.declBinds env all
|
adamc@196
|
2151 val d = (L'.DDatatype (x, n, map (fn (x, n, to) => (x, n, Option.map (monoType env') to)) xncs), loc)
|
adamc@164
|
2152 in
|
adamc@273
|
2153 SOME (env', fm, [d])
|
adamc@193
|
2154 end
|
adamc@193
|
2155 | L.DDatatype _ => poly ()
|
adamc@179
|
2156 | L.DVal (x, n, t, e, s) =>
|
adamc@179
|
2157 let
|
adamc@179
|
2158 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
2159 in
|
adamc@179
|
2160 SOME (Env.pushENamed env x n t NONE s,
|
adamc@179
|
2161 fm,
|
adamc@273
|
2162 [(L'.DVal (x, n, monoType env t, e, s), loc)])
|
adamc@179
|
2163 end
|
adamc@128
|
2164 | L.DValRec vis =>
|
adamc@128
|
2165 let
|
adamc@128
|
2166 val env = foldl (fn ((x, n, t, e, s), env) => Env.pushENamed env x n t NONE s) env vis
|
adamc@179
|
2167
|
adamc@179
|
2168 val (vis, fm) = ListUtil.foldlMap
|
adamc@179
|
2169 (fn ((x, n, t, e, s), fm) =>
|
adamc@179
|
2170 let
|
adamc@179
|
2171 val (e, fm) = monoExp (env, St.empty, fm) e
|
adamc@179
|
2172 in
|
adamc@179
|
2173 ((x, n, monoType env t, e, s), fm)
|
adamc@179
|
2174 end)
|
adamc@179
|
2175 fm vis
|
adamc@128
|
2176 in
|
adamc@128
|
2177 SOME (env,
|
adamc@179
|
2178 fm,
|
adamc@273
|
2179 [(L'.DValRec vis, loc)])
|
adamc@128
|
2180 end
|
adamc@144
|
2181 | L.DExport (ek, n) =>
|
adamc@115
|
2182 let
|
adamc@120
|
2183 val (_, t, _, s) = Env.lookupENamed env n
|
adamc@120
|
2184
|
adamc@120
|
2185 fun unwind (t, _) =
|
adamc@120
|
2186 case t of
|
adamc@120
|
2187 L.TFun (dom, ran) => dom :: unwind ran
|
adamc@314
|
2188 | L.CApp ((L.CFfi ("Basis", "transaction"), _), t) =>
|
adamc@314
|
2189 (L.TRecord (L.CRecord ((L.KType, loc), []), loc), loc) :: unwind t
|
adamc@120
|
2190 | _ => []
|
adamc@120
|
2191
|
adamc@120
|
2192 val ts = map (monoType env) (unwind t)
|
adamc@115
|
2193 in
|
adamc@273
|
2194 SOME (env, fm, [(L'.DExport (ek, s, n, ts), loc)])
|
adamc@115
|
2195 end
|
adamc@273
|
2196 | L.DTable (x, n, (L.CRecord (_, xts), _), s) =>
|
adamc@251
|
2197 let
|
adamc@251
|
2198 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@251
|
2199 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@311
|
2200 val s = "uw_" ^ s
|
adamc@251
|
2201 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@273
|
2202
|
adamc@273
|
2203 val xts = map (fn (x, t) => (monoName env x, monoType env t)) xts
|
adamc@251
|
2204 in
|
adamc@251
|
2205 SOME (Env.pushENamed env x n t NONE s,
|
adamc@251
|
2206 fm,
|
adamc@273
|
2207 [(L'.DTable (s, xts), loc),
|
adamc@273
|
2208 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@251
|
2209 end
|
adamc@273
|
2210 | L.DTable _ => poly ()
|
adamc@338
|
2211 | L.DSequence (x, n, s) =>
|
adamc@338
|
2212 let
|
adamc@338
|
2213 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@338
|
2214 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@338
|
2215 val s = "uw_" ^ s
|
adamc@338
|
2216 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@338
|
2217 in
|
adamc@338
|
2218 SOME (Env.pushENamed env x n t NONE s,
|
adamc@338
|
2219 fm,
|
adamc@338
|
2220 [(L'.DSequence s, loc),
|
adamc@338
|
2221 (L'.DVal (x, n, t', e, s), loc)])
|
adamc@338
|
2222 end
|
adamc@273
|
2223 | L.DDatabase s => SOME (env, fm, [(L'.DDatabase s, loc)])
|
adamc@462
|
2224 | L.DCookie (x, n, t, s) =>
|
adamc@462
|
2225 let
|
adamc@462
|
2226 val t = (L.CFfi ("Basis", "string"), loc)
|
adamc@462
|
2227 val t' = (L'.TFfi ("Basis", "string"), loc)
|
adamc@462
|
2228 val e = (L'.EPrim (Prim.String s), loc)
|
adamc@462
|
2229 in
|
adamc@462
|
2230 SOME (Env.pushENamed env x n t NONE s,
|
adamc@462
|
2231 fm,
|
adamc@462
|
2232 [(L'.DVal (x, n, t', e, s), loc)])
|
adamc@462
|
2233 end
|
adamc@25
|
2234 end
|
adamc@25
|
2235
|
adamc@25
|
2236 fun monoize env ds =
|
adamc@25
|
2237 let
|
adamc@385
|
2238 val p = !urlPrefix
|
adamc@385
|
2239 val () =
|
adamc@385
|
2240 if p = "" then
|
adamc@385
|
2241 urlPrefix := "/"
|
adamc@385
|
2242 else if String.sub (p, size p - 1) <> #"/" then
|
adamc@385
|
2243 urlPrefix := p ^ "/"
|
adamc@385
|
2244 else
|
adamc@385
|
2245 ()
|
adamc@385
|
2246
|
adamc@179
|
2247 val (_, _, ds) = List.foldl (fn (d, (env, fm, ds)) =>
|
adamc@179
|
2248 case monoDecl (env, fm) d of
|
adamc@179
|
2249 NONE => (env, fm, ds)
|
adamc@273
|
2250 | SOME (env, fm, ds') =>
|
adamc@179
|
2251 (env,
|
adamc@179
|
2252 Fm.enter fm,
|
adamc@273
|
2253 ds' @ Fm.decls fm @ ds))
|
adamc@179
|
2254 (env, Fm.empty (CoreUtil.File.maxName ds + 1), []) ds
|
adamc@25
|
2255 in
|
adamc@25
|
2256 rev ds
|
adamc@25
|
2257 end
|
adamc@25
|
2258
|
adamc@25
|
2259 end
|