annotate src/compiler.sml @ 1071:26197c957ad6

Better record summary error messages; more tweaking SQL usability
author Adam Chlipala <adamc@hcoop.net>
date Sun, 13 Dec 2009 11:28:47 -0500
parents 3bc726a822fb
children d069b193ed6b
rev   line source
adamc@764 1 (* Copyright (c) 2008-2009, Adam Chlipala
adamc@1 2 * All rights reserved.
adamc@1 3 *
adamc@1 4 * Redistribution and use in source and binary forms, with or without
adamc@1 5 * modification, are permitted provided that the following conditions are met:
adamc@1 6 *
adamc@1 7 * - Redistributions of source code must retain the above copyright notice,
adamc@1 8 * this list of conditions and the following disclaimer.
adamc@1 9 * - Redistributions in binary form must reproduce the above copyright notice,
adamc@1 10 * this list of conditions and the following disclaimer in the documentation
adamc@1 11 * and/or other materials provided with the distribution.
adamc@1 12 * - The names of contributors may not be used to endorse or promote products
adamc@1 13 * derived from this software without specific prior written permission.
adamc@1 14 *
adamc@1 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
adamc@1 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
adamc@1 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
adamc@1 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
adamc@1 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
adamc@1 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
adamc@1 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
adamc@1 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
adamc@1 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
adamc@1 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
adamc@1 25 * POSSIBILITY OF SUCH DAMAGE.
adamc@1 26 *)
adamc@1 27
adamc@1 28 structure Compiler :> COMPILER = struct
adamc@1 29
adamc@244 30 structure UrwebLrVals = UrwebLrValsFn(structure Token = LrParser.Token)
adamc@244 31 structure Lex = UrwebLexFn(structure Tokens = UrwebLrVals.Tokens)
adamc@244 32 structure UrwebP = Join(structure ParserData = UrwebLrVals.ParserData
adamc@1 33 structure Lex = Lex
adamc@1 34 structure LrParser = LrParser)
adamc@1 35
adamc@270 36 type job = {
adamc@385 37 prefix : string,
adamc@270 38 database : string option,
adamc@274 39 sources : string list,
adamc@274 40 exe : string,
adamc@274 41 sql : string option,
adamc@502 42 debug : bool,
adamc@673 43 profile : bool,
adamc@764 44 timeout : int,
adamc@764 45 ffi : string list,
adamc@764 46 link : string list,
adamc@765 47 headers : string list,
adamc@766 48 scripts : string list,
adamc@765 49 clientToServer : Settings.ffi list,
adamc@765 50 effectful : Settings.ffi list,
adamc@765 51 clientOnly : Settings.ffi list,
adamc@765 52 serverOnly : Settings.ffi list,
adamc@768 53 jsFuncs : (Settings.ffi * string) list,
adamc@769 54 rewrites : Settings.rewrite list,
adamc@769 55 filterUrl : Settings.rule list,
adamc@866 56 filterMime : Settings.rule list,
adamc@866 57 protocol : string option,
adamc@866 58 dbms : string option
adamc@270 59 }
adamc@201 60
adamc@201 61 type ('src, 'dst) phase = {
adamc@201 62 func : 'src -> 'dst,
adamc@201 63 print : 'dst -> Print.PD.pp_desc
adamc@201 64 }
adamc@201 65
adamc@201 66 type pmap = (string * Time.time) list
adamc@201 67
adamc@201 68 type ('src, 'dst) transform = {
adamc@201 69 func : 'src -> 'dst option,
adamc@201 70 print : 'dst -> Print.PD.pp_desc,
adamc@201 71 time : 'src * pmap -> 'dst option * pmap
adamc@201 72 }
adamc@201 73
adamc@201 74 fun transform (ph : ('src, 'dst) phase) name = {
adamc@201 75 func = fn input => let
adamc@201 76 val v = #func ph input
adamc@201 77 in
adamc@201 78 if ErrorMsg.anyErrors () then
adamc@201 79 NONE
adamc@201 80 else
adamc@201 81 SOME v
adamc@201 82 end,
adamc@201 83 print = #print ph,
adamc@201 84 time = fn (input, pmap) => let
adamc@201 85 val befor = Time.now ()
adamc@201 86 val v = #func ph input
adamc@201 87 val elapsed = Time.- (Time.now (), befor)
adamc@201 88 in
adamc@201 89 (if ErrorMsg.anyErrors () then
adamc@201 90 NONE
adamc@201 91 else
adamc@201 92 SOME v,
adamc@201 93 (name, elapsed) :: pmap)
adamc@201 94 end
adamc@201 95 }
adamc@201 96
adamc@270 97 fun op o (tr2 : ('b, 'c) transform, tr1 : ('a, 'b) transform) = {
adamc@201 98 func = fn input => case #func tr1 input of
adamc@201 99 NONE => NONE
adamc@201 100 | SOME v => #func tr2 v,
adamc@201 101 print = #print tr2,
adamc@201 102 time = fn (input, pmap) => let
adamc@201 103 val (ro, pmap) = #time tr1 (input, pmap)
adamc@201 104 in
adamc@201 105 case ro of
adamc@201 106 NONE => (NONE, pmap)
adamc@201 107 | SOME v => #time tr2 (v, pmap)
adamc@201 108 end
adamc@201 109 }
adamc@201 110
adamc@346 111 fun check (tr : ('src, 'dst) transform) x = (ErrorMsg.resetErrors ();
adamc@346 112 ignore (#func tr x))
adamc@346 113
adamc@280 114 fun run (tr : ('src, 'dst) transform) x = (ErrorMsg.resetErrors ();
adamc@280 115 #func tr x)
adamc@201 116
adamc@201 117 fun runPrint (tr : ('src, 'dst) transform) input =
adamc@280 118 (ErrorMsg.resetErrors ();
adamc@280 119 case #func tr input of
adamc@280 120 NONE => print "Failure\n"
adamc@280 121 | SOME v =>
adamc@280 122 (print "Success\n";
adamc@280 123 Print.print (#print tr v);
adamc@280 124 print "\n"))
adamc@201 125
adamc@201 126 fun time (tr : ('src, 'dst) transform) input =
adamc@55 127 let
adamc@201 128 val (_, pmap) = #time tr (input, [])
adamc@201 129 in
adamc@201 130 app (fn (name, time) =>
adamc@201 131 print (name ^ ": " ^ LargeReal.toString (Time.toReal time) ^ "\n")) (rev pmap);
adamc@201 132 print ("TOTAL: " ^ LargeReal.toString (Time.toReal (foldl Time.+ Time.zeroTime (map #2 pmap))) ^ "\n");
adamc@201 133 print "\n"
adamc@201 134 end
adamc@55 135
adamc@201 136 fun timePrint (tr : ('src, 'dst) transform) input =
adamc@201 137 let
adamc@201 138 val (ro, pmap) = #time tr (input, [])
adamc@55 139 in
adamc@201 140 app (fn (name, time) =>
adamc@201 141 print (name ^ ": " ^ LargeReal.toString (Time.toReal time) ^ "\n")) (rev pmap);
adamc@201 142 print ("TOTAL: " ^ LargeReal.toString (Time.toReal (foldl Time.+ Time.zeroTime (map #2 pmap))) ^ "\n");
adamc@201 143 print "\n";
adamc@201 144 case ro of
adamc@201 145 NONE => print "Failure\n"
adamc@201 146 | SOME v =>
adamc@201 147 (print "Success\n";
adamc@201 148 Print.print (#print tr v);
adamc@201 149 print "\n")
adamc@55 150 end
adamc@55 151
adamc@244 152 val parseUrs =
adamc@201 153 {func = fn filename => let
adamc@201 154 val fname = OS.FileSys.tmpName ()
adamc@201 155 val outf = TextIO.openOut fname
adamc@201 156 val () = TextIO.output (outf, "sig\n")
adamc@201 157 val inf = TextIO.openIn filename
adamc@201 158 fun loop () =
adamc@201 159 case TextIO.inputLine inf of
adamc@201 160 NONE => ()
adamc@201 161 | SOME line => (TextIO.output (outf, line);
adamc@201 162 loop ())
adamc@201 163 val () = loop ()
adamc@201 164 val () = TextIO.closeIn inf
adamc@201 165 val () = TextIO.closeOut outf
adamc@201 166
adamc@201 167 val () = (ErrorMsg.resetErrors ();
adamc@201 168 ErrorMsg.resetPositioning filename;
adamc@201 169 Lex.UserDeclarations.initialize ())
adamc@201 170 val file = TextIO.openIn fname
adamc@201 171 fun get _ = TextIO.input file
adamc@201 172 fun parseerror (s, p1, p2) = ErrorMsg.errorAt' (p1, p2) s
adamc@201 173 val lexer = LrParser.Stream.streamify (Lex.makeLexer get)
adamc@244 174 val (absyn, _) = UrwebP.parse (30, lexer, parseerror, ())
adamc@201 175 in
adamc@201 176 TextIO.closeIn file;
adamc@201 177 case absyn of
adamc@201 178 [(Source.DSgn ("?", (Source.SgnConst sgis, _)), _)] => sgis
adamc@201 179 | _ => (ErrorMsg.errorAt {file = filename,
adamc@201 180 first = {line = 0,
adamc@201 181 char = 0},
adamc@201 182 last = {line = 0,
adamc@201 183 char = 0}} "Not a signature";
adamc@201 184 [])
adamc@201 185 end
adamc@201 186 handle LrParser.ParseError => [],
adamc@201 187 print = Print.p_list_sep Print.PD.newline SourcePrint.p_sgn_item}
adamc@55 188
adamc@1 189 (* The main parsing routine *)
adamc@244 190 val parseUr = {
adamc@201 191 func = fn filename =>
adamc@201 192 let
adamc@201 193 val () = (ErrorMsg.resetErrors ();
adamc@201 194 ErrorMsg.resetPositioning filename;
adamc@201 195 Lex.UserDeclarations.initialize ())
adamc@201 196 val file = TextIO.openIn filename
adamc@201 197 fun get _ = TextIO.input file
adamc@201 198 fun parseerror (s, p1, p2) = ErrorMsg.errorAt' (p1, p2) s
adamc@201 199 val lexer = LrParser.Stream.streamify (Lex.makeLexer get)
adamc@244 200 val (absyn, _) = UrwebP.parse (30, lexer, parseerror, ())
adamc@201 201 in
adamc@201 202 TextIO.closeIn file;
adamc@201 203 case absyn of
adamc@201 204 [(Source.DSgn ("?", _), _)] =>
adamc@201 205 (ErrorMsg.errorAt {file = filename,
adamc@201 206 first = {line = 0,
adamc@201 207 char = 0},
adamc@201 208 last = {line = 0,
adamc@201 209 char = 0}} "File starts with 'sig'";
adamc@201 210 [])
adamc@201 211 | _ => absyn
adamc@201 212 end
adamc@201 213 handle LrParser.ParseError => [],
adamc@201 214 print = SourcePrint.p_file}
adamc@56 215
adamc@768 216 fun p_job ({prefix, database, exe, sql, sources, debug, profile,
adamc@768 217 timeout, ffi, link, headers, scripts,
adamc@768 218 clientToServer, effectful, clientOnly, serverOnly, jsFuncs, ...} : job) =
adamc@270 219 let
adamc@270 220 open Print.PD
adamc@270 221 open Print
adamc@765 222
adamc@765 223 fun p_ffi name = p_list_sep (box []) (fn (m, s) =>
adamc@765 224 box [string name, space, string m, string ".", string s, newline])
adamc@270 225 in
adamc@274 226 box [if debug then
adamc@274 227 box [string "DEBUG", newline]
adamc@274 228 else
adamc@274 229 box [],
adamc@502 230 if profile then
adamc@502 231 box [string "PROFILE", newline]
adamc@502 232 else
adamc@502 233 box [],
adamc@274 234 case database of
adamc@270 235 NONE => string "No database."
adamc@270 236 | SOME db => string ("Database: " ^ db),
adamc@270 237 newline,
adamc@274 238 string "Exe: ",
adamc@274 239 string exe,
adamc@274 240 newline,
adamc@274 241 case sql of
adamc@274 242 NONE => string "No SQL file."
adamc@274 243 | SOME sql => string ("SQL fle: " ^ sql),
adamc@673 244 newline,
adamc@673 245 string "Timeout: ",
adamc@673 246 string (Int.toString timeout),
adamc@673 247 newline,
adamc@764 248 p_list_sep (box []) (fn s => box [string "Ffi", space, string s, newline]) ffi,
adamc@764 249 p_list_sep (box []) (fn s => box [string "Header", space, string s, newline]) headers,
adamc@766 250 p_list_sep (box []) (fn s => box [string "Script", space, string s, newline]) scripts,
adamc@764 251 p_list_sep (box []) (fn s => box [string "Link", space, string s, newline]) link,
adamc@765 252 p_ffi "ClientToServer" clientToServer,
adamc@765 253 p_ffi "Effectful" effectful,
adamc@765 254 p_ffi "ClientOnly" clientOnly,
adamc@765 255 p_ffi "ServerOnly" serverOnly,
adamc@765 256 p_list_sep (box []) (fn ((m, s), s') =>
adamc@765 257 box [string "JsFunc", space, string m, string ".", string s,
adamc@765 258 space, string "=", space, string s', newline]) jsFuncs,
adamc@270 259 string "Sources:",
adamc@270 260 p_list string sources,
adamc@270 261 newline]
adamc@270 262 end
adamc@270 263
adamc@270 264 fun trim s =
adamc@270 265 let
adamc@270 266 val (_, s) = Substring.splitl Char.isSpace s
adamc@270 267 val (s, _) = Substring.splitr Char.isSpace s
adamc@270 268 in
adamc@270 269 s
adamc@270 270 end
adamc@270 271
adamc@794 272 structure M = BinaryMapFn(struct
adamc@794 273 type ord_key = string
adamc@794 274 val compare = String.compare
adamc@794 275 end)
adamc@794 276
adamc@794 277 fun parseUrp' fname =
adamc@767 278 let
adamc@794 279 val pathmap = ref (M.insert (M.empty, "", Config.libUr))
adamc@767 280
adamc@794 281 fun pu filename =
adamc@794 282 let
adamc@794 283 val dir = OS.Path.dir filename
adamc@794 284 val inf = TextIO.openIn (OS.Path.joinBaseExt {base = filename, ext = SOME "urp"})
adamc@767 285
adamc@794 286 fun pathify fname =
adamc@794 287 if size fname > 0 andalso String.sub (fname, 0) = #"$" then
adamc@794 288 let
adamc@794 289 val fname' = Substring.extract (fname, 1, NONE)
adamc@794 290 val (befor, after) = Substring.splitl (fn ch => ch <> #"/") fname'
adamc@794 291 in
adamc@794 292 if Substring.isEmpty after then
adamc@794 293 fname
adamc@794 294 else
adamc@794 295 case M.find (!pathmap, Substring.string befor) of
adamc@794 296 NONE => fname
adamc@794 297 | SOME rep => rep ^ Substring.string after
adamc@794 298 end
adamc@794 299 else
adamc@794 300 fname
adamc@767 301
adamc@794 302 fun relify fname =
adamc@794 303 let
adamc@794 304 val fname = pathify fname
adamc@794 305 in
adamc@794 306 OS.Path.concat (dir, fname)
adamc@794 307 handle OS.Path.Path => fname
adamc@794 308 end
adamc@767 309
adamc@794 310 val absDir = OS.Path.mkAbsolute {path = dir, relativeTo = OS.FileSys.getDir ()}
adamc@767 311
adamc@794 312 fun relifyA fname =
adamc@794 313 OS.Path.mkAbsolute {path = pathify fname, relativeTo = absDir}
adamc@767 314
adamc@794 315 fun readSources acc =
adamc@794 316 case TextIO.inputLine inf of
adamc@794 317 NONE => rev acc
adamc@794 318 | SOME line =>
adamc@794 319 let
adamc@794 320 val acc = if CharVector.all Char.isSpace line then
adamc@794 321 acc
adamc@794 322 else
adamc@794 323 let
adamc@794 324 val fname = String.implode (List.filter (fn x => not (Char.isSpace x))
adamc@794 325 (String.explode line))
adamc@794 326 val fname = relify fname
adamc@794 327 in
adamc@794 328 fname :: acc
adamc@794 329 end
adamc@794 330 in
adamc@794 331 readSources acc
adamc@794 332 end
adamc@767 333
adamc@794 334 val prefix = ref NONE
adamc@891 335 val database = ref (Settings.getDbstring ())
adamc@891 336 val exe = ref (Settings.getExe ())
adamc@891 337 val sql = ref (Settings.getSql ())
adamc@857 338 val debug = ref (Settings.getDebug ())
adamc@794 339 val profile = ref false
adamc@794 340 val timeout = ref NONE
adamc@794 341 val ffi = ref []
adamc@794 342 val link = ref []
adamc@794 343 val headers = ref []
adamc@794 344 val scripts = ref []
adamc@794 345 val clientToServer = ref []
adamc@794 346 val effectful = ref []
adamc@794 347 val clientOnly = ref []
adamc@794 348 val serverOnly = ref []
adamc@794 349 val jsFuncs = ref []
adamc@794 350 val rewrites = ref []
adamc@794 351 val url = ref []
adamc@794 352 val mime = ref []
adamc@794 353 val libs = ref []
adamc@866 354 val protocol = ref NONE
adamc@866 355 val dbms = ref NONE
adamc@767 356
adamc@794 357 fun finish sources =
adamc@794 358 let
adamc@794 359 val job = {
adamc@794 360 prefix = Option.getOpt (!prefix, "/"),
adamc@794 361 database = !database,
adamc@794 362 exe = Option.getOpt (!exe, OS.Path.joinBaseExt {base = OS.Path.base filename,
adamc@794 363 ext = SOME "exe"}),
adamc@794 364 sql = !sql,
adamc@794 365 debug = !debug,
adamc@794 366 profile = !profile,
adamc@794 367 timeout = Option.getOpt (!timeout, 60),
adamc@794 368 ffi = rev (!ffi),
adamc@794 369 link = rev (!link),
adamc@794 370 headers = rev (!headers),
adamc@794 371 scripts = rev (!scripts),
adamc@794 372 clientToServer = rev (!clientToServer),
adamc@794 373 effectful = rev (!effectful),
adamc@794 374 clientOnly = rev (!clientOnly),
adamc@794 375 serverOnly = rev (!serverOnly),
adamc@794 376 jsFuncs = rev (!jsFuncs),
adamc@794 377 rewrites = rev (!rewrites),
adamc@794 378 filterUrl = rev (!url),
adamc@794 379 filterMime = rev (!mime),
adamc@866 380 sources = sources,
adamc@866 381 protocol = !protocol,
adamc@866 382 dbms = !dbms
adamc@794 383 }
adamc@767 384
adamc@794 385 fun mergeO f (old, new) =
adamc@794 386 case (old, new) of
adamc@794 387 (NONE, _) => new
adamc@794 388 | (_, NONE) => old
adamc@794 389 | (SOME v1, SOME v2) => SOME (f (v1, v2))
adamc@794 390
adamc@794 391 fun same desc = mergeO (fn (x : string, y) =>
adamc@794 392 (if x = y then
adamc@794 393 ()
adamc@794 394 else
adamc@794 395 ErrorMsg.error ("Multiple "
adamc@794 396 ^ desc ^ " values that don't agree");
adamc@794 397 x))
adamc@794 398
adamc@794 399 fun merge (old : job, new : job) = {
adamc@794 400 prefix = #prefix old,
adamc@891 401 database = mergeO (fn (old, _) => old) (#database old, #database new),
adamc@794 402 exe = #exe old,
adamc@794 403 sql = #sql old,
adamc@794 404 debug = #debug old orelse #debug new,
adamc@794 405 profile = #profile old orelse #profile new,
adamc@794 406 timeout = #timeout old,
adamc@794 407 ffi = #ffi old @ #ffi new,
adamc@794 408 link = #link old @ #link new,
adamc@794 409 headers = #headers old @ #headers new,
adamc@794 410 scripts = #scripts old @ #scripts new,
adamc@794 411 clientToServer = #clientToServer old @ #clientToServer new,
adamc@794 412 effectful = #effectful old @ #effectful new,
adamc@794 413 clientOnly = #clientOnly old @ #clientOnly new,
adamc@794 414 serverOnly = #serverOnly old @ #serverOnly new,
adamc@794 415 jsFuncs = #jsFuncs old @ #jsFuncs new,
adamc@794 416 rewrites = #rewrites old @ #rewrites new,
adamc@794 417 filterUrl = #filterUrl old @ #filterUrl new,
adamc@794 418 filterMime = #filterMime old @ #filterMime new,
adamc@866 419 sources = #sources new @ #sources old,
adamc@866 420 protocol = mergeO #2 (#protocol old, #protocol new),
adamc@866 421 dbms = mergeO #2 (#dbms old, #dbms new)
adamc@794 422 }
adamc@794 423 in
adamc@1057 424 foldr (fn (job', job) => merge (job, job')) job (!libs)
adamc@794 425 end
adamc@794 426
adamc@794 427 fun parsePkind s =
adamc@794 428 case s of
adamc@794 429 "all" => Settings.Any
adamc@794 430 | "url" => Settings.Url
adamc@794 431 | "table" => Settings.Table
adamc@794 432 | "sequence" => Settings.Sequence
adamc@794 433 | "view" => Settings.View
adamc@794 434 | "relation" => Settings.Relation
adamc@794 435 | "cookie" => Settings.Cookie
adamc@794 436 | "style" => Settings.Style
adamc@794 437 | _ => (ErrorMsg.error "Bad path kind spec";
adamc@794 438 Settings.Any)
adamc@794 439
adamc@794 440 fun parseFrom s =
adamc@794 441 if size s > 1 andalso String.sub (s, size s - 2) = #"/" andalso String.sub (s, size s - 1) = #"*" then
adamc@794 442 (Settings.Prefix, String.substring (s, 0, size s - 1))
adamc@794 443 else
adamc@794 444 (Settings.Exact, s)
adamc@794 445
adamc@794 446 fun parseFkind s =
adamc@794 447 case s of
adamc@794 448 "url" => url
adamc@794 449 | "mime" => mime
adamc@794 450 | _ => (ErrorMsg.error "Bad filter kind";
adamc@794 451 url)
adamc@794 452
adamc@794 453 fun parsePattern s =
adamc@794 454 if size s > 0 andalso String.sub (s, size s - 1) = #"*" then
adamc@794 455 (Settings.Prefix, String.substring (s, 0, size s - 1))
adamc@794 456 else
adamc@794 457 (Settings.Exact, s)
adamc@794 458
adamc@794 459 fun read () =
adamc@794 460 case TextIO.inputLine inf of
adamc@794 461 NONE => finish []
adamc@794 462 | SOME "\n" => finish (readSources [])
adamc@794 463 | SOME line =>
adamc@794 464 let
adamc@794 465 val (cmd, arg) = Substring.splitl (fn x => not (Char.isSpace x)) (Substring.full line)
adamc@794 466 val cmd = Substring.string (trim cmd)
adamc@794 467 val arg = Substring.string (trim arg)
adamc@794 468
adamc@794 469 fun ffiS () =
adamc@794 470 case String.fields (fn ch => ch = #".") arg of
adamc@794 471 [m, x] => (m, x)
adamc@794 472 | _ => (ErrorMsg.error (cmd ^ " argument not of the form Module.func");
adamc@794 473 ("", ""))
adamc@794 474
adamc@794 475 fun ffiM () =
adamc@794 476 case String.fields (fn ch => ch = #"=") arg of
adamc@794 477 [f, s] =>
adamc@794 478 (case String.fields (fn ch => ch = #".") f of
adamc@794 479 [m, x] => ((m, x), s)
adamc@794 480 | _ => (ErrorMsg.error (cmd ^ " argument not of the form Module.func=func'");
adamc@794 481 (("", ""), "")))
adamc@794 482 | _ => (ErrorMsg.error (cmd ^ " argument not of the form Module.func=func'");
adamc@794 483 (("", ""), ""))
adamc@794 484 in
adamc@794 485 case cmd of
adamc@794 486 "prefix" =>
adamc@794 487 (case !prefix of
adamc@794 488 NONE => ()
adamc@794 489 | SOME _ => ErrorMsg.error "Duplicate 'prefix' directive";
adamc@794 490 prefix := SOME arg)
adamc@794 491 | "database" =>
adamc@794 492 (case !database of
adamc@891 493 NONE => database := SOME arg
adamc@891 494 | SOME _ => ())
adamc@794 495 | "exe" =>
adamc@794 496 (case !exe of
adamc@891 497 NONE => exe := SOME (relify arg)
adamc@891 498 | SOME _ => ())
adamc@794 499 | "sql" =>
adamc@794 500 (case !sql of
adamc@891 501 NONE => sql := SOME (relify arg)
adamc@891 502 | SOME _ => ())
adamc@794 503 | "debug" => debug := true
adamc@794 504 | "profile" => profile := true
adamc@794 505 | "timeout" =>
adamc@794 506 (case !timeout of
adamc@794 507 NONE => ()
adamc@794 508 | SOME _ => ErrorMsg.error "Duplicate 'timeout' directive";
adamc@794 509 timeout := SOME (valOf (Int.fromString arg)))
adamc@794 510 | "ffi" => ffi := relify arg :: !ffi
adamc@1061 511 | "link" => let
adamc@1061 512 val arg = if size arg >= 2 andalso String.substring (arg, 0, 2) = "-l" then
adamc@1061 513 arg
adamc@1061 514 else
adamc@1061 515 relifyA arg
adamc@1061 516 in
adamc@1061 517 link := arg :: !link
adamc@1061 518 end
adamc@794 519 | "include" => headers := relifyA arg :: !headers
adamc@794 520 | "script" => scripts := arg :: !scripts
adamc@794 521 | "clientToServer" => clientToServer := ffiS () :: !clientToServer
adamc@794 522 | "effectful" => effectful := ffiS () :: !effectful
adamc@794 523 | "clientOnly" => clientOnly := ffiS () :: !clientOnly
adamc@794 524 | "serverOnly" => serverOnly := ffiS () :: !serverOnly
adamc@794 525 | "jsFunc" => jsFuncs := ffiM () :: !jsFuncs
adamc@794 526 | "rewrite" =>
adamc@794 527 let
adamc@794 528 fun doit (pkind, from, to) =
adamc@794 529 let
adamc@794 530 val pkind = parsePkind pkind
adamc@794 531 val (kind, from) = parseFrom from
adamc@794 532 in
adamc@794 533 rewrites := {pkind = pkind, kind = kind, from = from, to = to} :: !rewrites
adamc@794 534 end
adamc@794 535 in
adamc@794 536 case String.tokens Char.isSpace arg of
adamc@794 537 [pkind, from, to] => doit (pkind, from, to)
adamc@794 538 | [pkind, from] => doit (pkind, from, "")
adamc@794 539 | _ => ErrorMsg.error "Bad 'rewrite' syntax"
adamc@794 540 end
adamc@794 541 | "allow" =>
adamc@794 542 (case String.tokens Char.isSpace arg of
adamc@794 543 [fkind, pattern] =>
adamc@794 544 let
adamc@794 545 val fkind = parseFkind fkind
adamc@794 546 val (kind, pattern) = parsePattern pattern
adamc@794 547 in
adamc@794 548 fkind := {action = Settings.Allow, kind = kind, pattern = pattern} :: !fkind
adamc@794 549 end
adamc@794 550 | _ => ErrorMsg.error "Bad 'allow' syntax")
adamc@794 551 | "deny" =>
adamc@794 552 (case String.tokens Char.isSpace arg of
adamc@794 553 [fkind, pattern] =>
adamc@794 554 let
adamc@794 555 val fkind = parseFkind fkind
adamc@794 556 val (kind, pattern) = parsePattern pattern
adamc@794 557 in
adamc@794 558 fkind := {action = Settings.Deny, kind = kind, pattern = pattern} :: !fkind
adamc@794 559 end
adamc@794 560 | _ => ErrorMsg.error "Bad 'deny' syntax")
adamc@1057 561 | "library" => libs := pu (relify arg) :: !libs
adamc@794 562 | "path" =>
adamc@794 563 (case String.fields (fn ch => ch = #"=") arg of
adamc@794 564 [n, v] => pathmap := M.insert (!pathmap, n, v)
adamc@794 565 | _ => ErrorMsg.error "path argument not of the form name=value'")
adamc@794 566 | _ => ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'");
adamc@794 567 read ()
adamc@794 568 end
adamc@794 569
adamc@794 570 val job = read ()
adamc@767 571 in
adamc@794 572 TextIO.closeIn inf;
adamc@794 573 Settings.setUrlPrefix (#prefix job);
adamc@794 574 Settings.setTimeout (#timeout job);
adamc@794 575 Settings.setHeaders (#headers job);
adamc@794 576 Settings.setScripts (#scripts job);
adamc@794 577 Settings.setClientToServer (#clientToServer job);
adamc@794 578 Settings.setEffectful (#effectful job);
adamc@794 579 Settings.setClientOnly (#clientOnly job);
adamc@794 580 Settings.setServerOnly (#serverOnly job);
adamc@794 581 Settings.setJsFuncs (#jsFuncs job);
adamc@794 582 Settings.setRewriteRules (#rewrites job);
adamc@794 583 Settings.setUrlRules (#filterUrl job);
adamc@794 584 Settings.setMimeRules (#filterMime job);
adamc@866 585 Option.app Settings.setProtocol (#protocol job);
adamc@866 586 Option.app Settings.setDbms (#dbms job);
adamc@794 587 job
adamc@767 588 end
adamc@767 589 in
adamc@794 590 pu fname
adamc@767 591 end
adamc@767 592
adamc@270 593 val parseUrp = {
adamc@767 594 func = parseUrp',
adamc@270 595 print = p_job
adamc@270 596 }
adamc@270 597
adamc@270 598 val toParseJob = transform parseUrp "parseJob"
adamc@270 599
adamc@56 600 fun capitalize "" = ""
adamc@56 601 | capitalize s = str (Char.toUpper (String.sub (s, 0))) ^ String.extract (s, 1, NONE)
adamc@56 602
adamc@201 603 val parse = {
adamc@764 604 func = fn {database, sources = fnames, ffi, ...} : job =>
adamc@201 605 let
adamc@834 606 val anyErrors = ref false
adamc@834 607 fun checkErrors () = anyErrors := (!anyErrors orelse ErrorMsg.anyErrors ())
adamc@201 608 fun nameOf fname = capitalize (OS.Path.file fname)
adamc@109 609
adamc@764 610 fun parseFfi fname =
adamc@764 611 let
adamc@764 612 val mname = nameOf fname
adamc@764 613 val urs = OS.Path.joinBaseExt {base = fname, ext = SOME "urs"}
adamc@764 614
adamc@764 615 val loc = {file = urs,
adamc@764 616 first = ErrorMsg.dummyPos,
adamc@764 617 last = ErrorMsg.dummyPos}
adamc@764 618
adamc@764 619 val sgn = (Source.SgnConst (#func parseUrs urs), loc)
adamc@764 620 in
adamc@834 621 checkErrors ();
adamc@764 622 (Source.DFfiStr (mname, sgn), loc)
adamc@764 623 end
adamc@764 624
adamc@201 625 fun parseOne fname =
adamc@201 626 let
adamc@201 627 val mname = nameOf fname
adamc@244 628 val ur = OS.Path.joinBaseExt {base = fname, ext = SOME "ur"}
adamc@244 629 val urs = OS.Path.joinBaseExt {base = fname, ext = SOME "urs"}
adamc@56 630
adamc@201 631 val sgnO =
adamc@244 632 if Posix.FileSys.access (urs, []) then
adamc@244 633 SOME (Source.SgnConst (#func parseUrs urs),
adamc@244 634 {file = urs,
adamc@201 635 first = ErrorMsg.dummyPos,
adamc@201 636 last = ErrorMsg.dummyPos})
adamc@834 637 before checkErrors ()
adamc@201 638 else
adamc@201 639 NONE
adamc@56 640
adamc@244 641 val loc = {file = ur,
adamc@201 642 first = ErrorMsg.dummyPos,
adamc@201 643 last = ErrorMsg.dummyPos}
adamc@56 644
adamc@244 645 val ds = #func parseUr ur
adamc@201 646 in
adamc@834 647 checkErrors ();
adamc@201 648 (Source.DStr (mname, sgnO, (Source.StrConst ds, loc)), loc)
adamc@201 649 end
adamc@56 650
adamc@764 651 val dsFfi = map parseFfi ffi
adamc@201 652 val ds = map parseOne fnames
adamc@201 653 in
adamc@834 654 if !anyErrors then
adamc@834 655 ErrorMsg.error "Parse failure"
adamc@834 656 else
adamc@834 657 ();
adamc@834 658
adamc@201 659 let
adamc@201 660 val final = nameOf (List.last fnames)
adamc@271 661
adamc@764 662 val ds = dsFfi @ ds
adamc@764 663 @ [(Source.DExport (Source.StrVar final, ErrorMsg.dummySpan), ErrorMsg.dummySpan)]
adamc@201 664 in
adamc@271 665 case database of
adamc@271 666 NONE => ds
adamc@271 667 | SOME s => (Source.DDatabase s, ErrorMsg.dummySpan) :: ds
adamc@201 668 end handle Empty => ds
adamc@201 669 end,
adamc@201 670 print = SourcePrint.p_file
adamc@201 671 }
adamc@56 672
adamc@270 673 val toParse = transform parse "parse" o toParseJob
adamc@38 674
adamc@378 675 fun libFile s = OS.Path.joinDirFile {dir = Config.libUr,
adamc@378 676 file = s}
adamc@378 677 fun clibFile s = OS.Path.joinDirFile {dir = Config.libC,
adamc@378 678 file = s}
adamc@378 679
adamc@201 680 val elaborate = {
adamc@201 681 func = fn file => let
adamc@378 682 val basis = #func parseUrs (libFile "basis.urs")
adamc@378 683 val topSgn = #func parseUrs (libFile "top.urs")
adamc@378 684 val topStr = #func parseUr (libFile "top.ur")
adamc@201 685 in
adamc@325 686 Elaborate.elabFile basis topStr topSgn ElabEnv.empty file
adamc@201 687 end,
adamc@201 688 print = ElabPrint.p_file ElabEnv.empty
adamc@201 689 }
adamc@5 690
adamc@270 691 val toElaborate = transform elaborate "elaborate" o toParse
adamc@201 692
adamc@448 693 val unnest = {
adamc@448 694 func = Unnest.unnest,
adamc@448 695 print = ElabPrint.p_file ElabEnv.empty
adamc@448 696 }
adamc@448 697
adamc@448 698 val toUnnest = transform unnest "unnest" o toElaborate
adamc@448 699
adamc@313 700 val termination = {
adamc@313 701 func = (fn file => (Termination.check file; file)),
adamc@313 702 print = ElabPrint.p_file ElabEnv.empty
adamc@313 703 }
adamc@313 704
adamc@448 705 val toTermination = transform termination "termination" o toUnnest
adamc@313 706
adamc@201 707 val explify = {
adamc@201 708 func = Explify.explify,
adamc@201 709 print = ExplPrint.p_file ExplEnv.empty
adamc@201 710 }
adamc@201 711
adamc@625 712 val toExplify = transform explify "explify" o toUnnest
adamc@201 713
adamc@201 714 val corify = {
adamc@201 715 func = Corify.corify,
adamc@201 716 print = CorePrint.p_file CoreEnv.empty
adamc@201 717 }
adamc@201 718
adamc@270 719 val toCorify = transform corify "corify" o toExplify
adamc@201 720
adamc@482 721 (*val reduce_local = {
adamc@482 722 func = ReduceLocal.reduce,
adamc@482 723 print = CorePrint.p_file CoreEnv.empty
adamc@482 724 }
adamc@482 725
adamc@482 726 val toReduce_local = transform reduce_local "reduce_local" o toCorify*)
adamc@482 727
adamc@443 728 val especialize = {
adamc@443 729 func = ESpecialize.specialize,
adamc@443 730 print = CorePrint.p_file CoreEnv.empty
adamc@443 731 }
adamc@443 732
adamc@454 733 val core_untangle = {
adamc@454 734 func = CoreUntangle.untangle,
adamc@454 735 print = CorePrint.p_file CoreEnv.empty
adamc@454 736 }
adamc@454 737
adamc@794 738 val toCore_untangle = transform core_untangle "core_untangle" o toCorify
adamc@454 739
adamc@202 740 val shake = {
adamc@202 741 func = Shake.shake,
adamc@202 742 print = CorePrint.p_file CoreEnv.empty
adamc@202 743 }
adamc@39 744
adamc@454 745 val toShake1 = transform shake "shake1" o toCore_untangle
adamc@110 746
adamc@607 747 val rpcify = {
adamc@607 748 func = Rpcify.frob,
adamc@607 749 print = CorePrint.p_file CoreEnv.empty
adamc@607 750 }
adamc@607 751
adamc@607 752 val toRpcify = transform rpcify "rpcify" o toShake1
adamc@607 753
adamc@642 754 val toCore_untangle2 = transform core_untangle "core_untangle2" o toRpcify
adamc@642 755 val toShake2 = transform shake "shake2" o toCore_untangle2
adamc@1062 756 val toEspecialize1 = transform especialize "especialize1" o toShake2
adamc@1062 757 val toCore_untangle3 = transform core_untangle "core_untangle3" o toEspecialize1
adamc@1062 758 val toShake3 = transform shake "shake3" o toCore_untangle3
adamc@642 759
adamc@202 760 val tag = {
adamc@202 761 func = Tag.tag,
adamc@202 762 print = CorePrint.p_file CoreEnv.empty
adamc@202 763 }
adamc@193 764
adamc@1062 765 val toTag = transform tag "tag" o toShake3
adamc@20 766
adamc@202 767 val reduce = {
adamc@202 768 func = Reduce.reduce,
adamc@202 769 print = CorePrint.p_file CoreEnv.empty
adamc@202 770 }
adamc@25 771
adamc@692 772 val toReduce = transform reduce "reduce" o toTag
adamc@23 773
adamc@315 774 val unpoly = {
adamc@315 775 func = Unpoly.unpoly,
adamc@315 776 print = CorePrint.p_file CoreEnv.empty
adamc@315 777 }
adamc@315 778
adamc@315 779 val toUnpoly = transform unpoly "unpoly" o toReduce
adamc@315 780
adamc@202 781 val specialize = {
adamc@202 782 func = Specialize.specialize,
adamc@202 783 print = CorePrint.p_file CoreEnv.empty
adamc@202 784 }
adamc@132 785
adamc@315 786 val toSpecialize = transform specialize "specialize" o toUnpoly
adamc@131 787
adamc@1062 788 val toShake4 = transform shake "shake4" o toSpecialize
adamc@133 789
adamc@1062 790 val toEspecialize2 = transform especialize "especialize2" o toShake4
adamc@794 791
adamc@1062 792 val toReduce2 = transform reduce "reduce2" o toEspecialize2
adamc@898 793
adamc@1062 794 val toShake5 = transform shake "shake5" o toReduce2
adamc@794 795
adamc@692 796 val marshalcheck = {
adamc@692 797 func = (fn file => (MarshalCheck.check file; file)),
adamc@692 798 print = CorePrint.p_file CoreEnv.empty
adamc@692 799 }
adamc@692 800
adamc@1062 801 val toMarshalcheck = transform marshalcheck "marshalcheck" o toShake5
adamc@692 802
adamc@732 803 val effectize = {
adamc@732 804 func = Effective.effectize,
adamc@732 805 print = CorePrint.p_file CoreEnv.empty
adamc@732 806 }
adamc@732 807
adamc@732 808 val toEffectize = transform effectize "effectize" o toMarshalcheck
adamc@732 809
adamc@202 810 val monoize = {
adamc@202 811 func = Monoize.monoize CoreEnv.empty,
adamc@202 812 print = MonoPrint.p_file MonoEnv.empty
adamc@202 813 }
adamc@134 814
adamc@732 815 val toMonoize = transform monoize "monoize" o toEffectize
adamc@96 816
adamc@202 817 val mono_opt = {
adamc@910 818 func = MonoOpt.optimize,
adamc@202 819 print = MonoPrint.p_file MonoEnv.empty
adamc@202 820 }
adamc@29 821
adamc@270 822 val toMono_opt1 = transform mono_opt "mono_opt1" o toMonoize
adamc@5 823
adamc@202 824 val untangle = {
adamc@202 825 func = Untangle.untangle,
adamc@202 826 print = MonoPrint.p_file MonoEnv.empty
adamc@202 827 }
adamc@1 828
adamc@270 829 val toUntangle = transform untangle "untangle" o toMono_opt1
adamc@38 830
adamc@202 831 val mono_reduce = {
adamc@202 832 func = MonoReduce.reduce,
adamc@202 833 print = MonoPrint.p_file MonoEnv.empty
adamc@202 834 }
adamc@16 835
adamc@270 836 val toMono_reduce = transform mono_reduce "mono_reduce" o toUntangle
adamc@39 837
adamc@202 838 val mono_shake = {
adamc@202 839 func = MonoShake.shake,
adamc@202 840 print = MonoPrint.p_file MonoEnv.empty
adamc@202 841 }
adamc@110 842
adamc@270 843 val toMono_shake = transform mono_shake "mono_shake1" o toMono_reduce
adamc@193 844
adamc@572 845 val toMono_opt2 = transform mono_opt "mono_opt2" o toMono_shake
adamc@572 846
adamc@567 847 val jscomp = {
adamc@567 848 func = JsComp.process,
adamc@567 849 print = MonoPrint.p_file MonoEnv.empty
adamc@567 850 }
adamc@567 851
adamc@572 852 val toJscomp = transform jscomp "jscomp" o toMono_opt2
adamc@567 853
adamc@910 854 val toMono_opt3 = transform mono_opt "mono_opt3" o toJscomp
adamc@20 855
adamc@506 856 val fuse = {
adamc@506 857 func = Fuse.fuse,
adamc@506 858 print = MonoPrint.p_file MonoEnv.empty
adamc@506 859 }
adamc@506 860
adamc@572 861 val toFuse = transform fuse "fuse" o toMono_opt3
adamc@506 862
adamc@506 863 val toUntangle2 = transform untangle "untangle2" o toFuse
adamc@506 864
adamc@601 865 val toMono_reduce2 = transform mono_reduce "mono_reduce2" o toUntangle2
adamc@601 866 val toMono_shake2 = transform mono_shake "mono_shake2" o toMono_reduce2
adamc@916 867 val toMono_opt4 = transform mono_opt "mono_opt4" o toMono_shake2
adamc@1017 868 val toMono_reduce3 = transform mono_reduce "mono_reduce3" o toMono_opt4
adamc@1017 869 val toFuse2 = transform fuse "shake2" o toMono_reduce3
adamc@916 870 val toUntangle3 = transform untangle "untangle3" o toFuse2
adamc@916 871 val toMono_shake3 = transform mono_shake "mono_shake3" o toUntangle3
adamc@506 872
adamc@377 873 val pathcheck = {
adamc@377 874 func = (fn file => (PathCheck.check file; file)),
adamc@377 875 print = MonoPrint.p_file MonoEnv.empty
adamc@377 876 }
adamc@377 877
adamc@916 878 val toPathcheck = transform pathcheck "pathcheck" o toMono_shake3
adamc@377 879
adamc@202 880 val cjrize = {
adamc@202 881 func = Cjrize.cjrize,
adamc@202 882 print = CjrPrint.p_file CjrEnv.empty
adamc@202 883 }
adamc@23 884
adamc@377 885 val toCjrize = transform cjrize "cjrize" o toPathcheck
adamc@29 886
adamc@643 887 val scriptcheck = {
adamc@643 888 func = ScriptCheck.classify,
adamc@643 889 print = CjrPrint.p_file CjrEnv.empty
adamc@643 890 }
adamc@643 891
adamc@643 892 val toScriptcheck = transform scriptcheck "scriptcheck" o toCjrize
adamc@643 893
adamc@282 894 val prepare = {
adamc@282 895 func = Prepare.prepare,
adamc@282 896 print = CjrPrint.p_file CjrEnv.empty
adamc@282 897 }
adamc@282 898
adamc@643 899 val toPrepare = transform prepare "prepare" o toScriptcheck
adamc@282 900
adamc@879 901 val checknest = {
adamc@879 902 func = fn f => if #supportsNestedPrepared (Settings.currentDbms ()) then f else Checknest.annotate f,
adamc@879 903 print = CjrPrint.p_file CjrEnv.empty
adamc@879 904 }
adamc@879 905
adamc@879 906 val toChecknest = transform checknest "checknest" o toPrepare
adamc@879 907
adamc@274 908 val sqlify = {
adamc@274 909 func = Cjrize.cjrize,
adamc@274 910 print = CjrPrint.p_sql CjrEnv.empty
adamc@274 911 }
adamc@274 912
adamc@274 913 val toSqlify = transform sqlify "sqlify" o toMono_opt2
adamc@274 914
adamc@764 915 fun compileC {cname, oname, ename, libs, profile, debug, link = link'} =
adamc@183 916 let
adamc@855 917 val proto = Settings.currentProtocol ()
adamc@378 918 val urweb_o = clibFile "urweb.o"
adamc@914 919 val memmem_o = clibFile "memmem.o"
adamc@378 920
adamc@949 921 val compile = "gcc " ^ Config.gccArgs ^ " -Wstrict-prototypes -Werror -O3 -fno-inline -I " ^ Config.includ
adamc@832 922 ^ " -c " ^ cname ^ " -o " ^ oname
adamc@914 923 val link = "gcc -Werror -O3 -lm -lmhash -pthread " ^ Config.gccArgs ^ " " ^ libs ^ " " ^ urweb_o ^ " " ^ oname
adamc@914 924 ^ " " ^ memmem_o ^ " " ^ #link proto ^ " -o " ^ ename
adamc@502 925
adamc@502 926 val (compile, link) =
adamc@502 927 if profile then
adamc@502 928 (compile ^ " -pg", link ^ " -pg")
adamc@502 929 else
adamc@502 930 (compile, link)
adamc@742 931
adamc@742 932 val (compile, link) =
adamc@742 933 if debug then
adamc@742 934 (compile ^ " -g", link ^ " -g")
adamc@742 935 else
adamc@742 936 (compile, link)
adamc@764 937
adamc@764 938 val link = foldl (fn (s, link) => link ^ " " ^ s) link link'
adamc@183 939 in
adamc@1045 940 OS.Process.isSuccess (OS.Process.system compile)
adamc@1045 941 andalso OS.Process.isSuccess (OS.Process.system link)
adamc@183 942 end
adamc@183 943
adamc@202 944 fun compile job =
adamc@879 945 case run toChecknest job of
adamc@1045 946 NONE => false
adamc@29 947 | SOME file =>
adamc@202 948 let
adamc@274 949 val job = valOf (run (transform parseUrp "parseUrp") job)
adamc@102 950
adamc@274 951 val (cname, oname, cleanup) =
adamc@274 952 if #debug job then
adamc@457 953 ("/tmp/webapp.c", "/tmp/webapp.o", fn () => ())
adamc@274 954 else
adamc@274 955 let
adamc@274 956 val dir = OS.FileSys.tmpName ()
adamc@403 957 val () = if OS.FileSys.access (dir, []) then
adamc@403 958 OS.FileSys.remove dir
adamc@403 959 else
adamc@403 960 ()
adamc@457 961 val cname = OS.Path.joinDirFile {dir = dir, file = "webapp.c"}
adamc@457 962 val oname = OS.Path.joinDirFile {dir = dir, file = "webapp.o"}
adamc@274 963 in
adamc@274 964 OS.FileSys.mkDir dir;
adamc@274 965 (cname, oname,
adamc@274 966 fn () => (OS.FileSys.remove cname;
adamc@274 967 OS.FileSys.remove oname;
adamc@473 968 OS.FileSys.rmDir dir)
adamc@473 969 handle OS.SysErr _ => OS.FileSys.rmDir dir)
adamc@274 970 end
adamc@274 971 val ename = #exe job
adamc@202 972 in
adamc@274 973 let
adamc@274 974 val outf = TextIO.openOut cname
adamc@274 975 val s = TextIOPP.openOut {dst = outf, wid = 80}
adamc@432 976
adamc@432 977 val hasDb = List.exists (fn (Cjr.DDatabase _, _) => true | _ => false) (#1 file)
adamc@432 978 val libs =
adamc@432 979 if hasDb then
adamc@866 980 #link (Settings.currentDbms ())
adamc@432 981 else
adamc@432 982 ""
adamc@274 983 in
adamc@274 984 Print.fprint s (CjrPrint.p_file CjrEnv.empty file);
adamc@415 985 TextIO.output1 (outf, #"\n");
adamc@274 986 TextIO.closeOut outf;
adamc@102 987
adamc@274 988 case #sql job of
adamc@274 989 NONE => ()
adamc@274 990 | SOME sql =>
adamc@274 991 let
adamc@274 992 val outf = TextIO.openOut sql
adamc@274 993 val s = TextIOPP.openOut {dst = outf, wid = 80}
adamc@274 994 in
adamc@274 995 Print.fprint s (CjrPrint.p_sql CjrEnv.empty file);
adamc@274 996 TextIO.closeOut outf
adamc@274 997 end;
adamc@274 998
adamc@742 999 compileC {cname = cname, oname = oname, ename = ename, libs = libs,
adamc@1045 1000 profile = #profile job, debug = #debug job, link = #link job}
adamc@274 1001
adamc@1045 1002 before cleanup ()
adamc@274 1003 end
adamc@274 1004 handle ex => (((cleanup ()) handle _ => ()); raise ex)
adamc@202 1005 end
adamc@29 1006
adamc@1045 1007 fun compiler job =
adamc@1045 1008 if compile job then
adamc@1045 1009 ()
adamc@1045 1010 else
adamc@1045 1011 OS.Process.exit OS.Process.failure
adamc@1045 1012
adamc@1 1013 end