annotate src/monoize.sml @ 1129:4f3a1aa3b66d

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