annotate src/monoize.sml @ 1107:52571ca9b777

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