comparison src/compiler.sml @ 1332:4dd5d23bace2

minHeap option in .urp files
author Adam Chlipala <adam@chlipala.net>
date Sat, 11 Dec 2010 15:16:04 -0500
parents a6427d1eda6f
children 79557535b843
comparison
equal deleted inserted replaced
1331:a6427d1eda6f 1332:4dd5d23bace2
57 filterMime : Settings.rule list, 57 filterMime : Settings.rule list,
58 protocol : string option, 58 protocol : string option,
59 dbms : string option, 59 dbms : string option,
60 sigFile : string option, 60 sigFile : string option,
61 safeGets : string list, 61 safeGets : string list,
62 onError : (string * string list * string) option 62 onError : (string * string list * string) option,
63 minHeap : int
63 } 64 }
64 65
65 type ('src, 'dst) phase = { 66 type ('src, 'dst) phase = {
66 func : 'src -> 'dst, 67 func : 'src -> 'dst,
67 print : 'dst -> Print.PD.pp_desc 68 print : 'dst -> Print.PD.pp_desc
306 Settings.setUrlRules (#filterUrl job); 307 Settings.setUrlRules (#filterUrl job);
307 Settings.setMimeRules (#filterMime job); 308 Settings.setMimeRules (#filterMime job);
308 Option.app Settings.setProtocol (#protocol job); 309 Option.app Settings.setProtocol (#protocol job);
309 Option.app Settings.setDbms (#dbms job); 310 Option.app Settings.setDbms (#dbms job);
310 Settings.setSafeGets (#safeGets job); 311 Settings.setSafeGets (#safeGets job);
311 Settings.setOnError (#onError job)) 312 Settings.setOnError (#onError job);
313 Settings.setMinHeap (#minHeap job))
312 314
313 fun inputCommentableLine inf = 315 fun inputCommentableLine inf =
314 Option.map (fn s => 316 Option.map (fn s =>
315 let 317 let
316 val s = #1 (Substring.splitl (fn ch => ch <> #"#") (Substring.full s)) 318 val s = #1 (Substring.splitl (fn ch => ch <> #"#") (Substring.full s))
319 val s = #1 (Substring.splitr (not o Char.isSpace) s)
317 in 320 in
318 Substring.string (#1 (Substring.splitr (not o Char.isSpace) s)) 321 Substring.string (if Substring.size s > 0 andalso Char.isSpace (Substring.sub (s, Substring.size s - 1)) then
322 Substring.trimr 1 s
323 else
324 s)
319 end) (TextIO.inputLine inf) 325 end) (TextIO.inputLine inf)
320 326
321 fun parseUrp' accLibs fname = 327 fun parseUrp' accLibs fname =
322 if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", [])) 328 if not (Posix.FileSys.access (fname ^ ".urp", []) orelse Posix.FileSys.access (fname ^ "/lib.urp", []))
323 andalso Posix.FileSys.access (fname ^ ".ur", []) then 329 andalso Posix.FileSys.access (fname ^ ".ur", []) then
347 filterMime = [], 353 filterMime = [],
348 protocol = NONE, 354 protocol = NONE,
349 dbms = NONE, 355 dbms = NONE,
350 sigFile = NONE, 356 sigFile = NONE,
351 safeGets = [], 357 safeGets = [],
352 onError = NONE} 358 onError = NONE,
359 minHeap = 0}
353 in 360 in
354 institutionalizeJob job; 361 institutionalizeJob job;
355 {Job = job, Libs = []} 362 {Job = job, Libs = []}
356 end 363 end
357 else 364 else
462 val protocol = ref NONE 469 val protocol = ref NONE
463 val dbms = ref NONE 470 val dbms = ref NONE
464 val sigFile = ref (Settings.getSigFile ()) 471 val sigFile = ref (Settings.getSigFile ())
465 val safeGets = ref [] 472 val safeGets = ref []
466 val onError = ref NONE 473 val onError = ref NONE
474 val minHeap = ref 0
467 475
468 fun finish sources = 476 fun finish sources =
469 let 477 let
470 val job = { 478 val job = {
471 prefix = Option.getOpt (!prefix, "/"), 479 prefix = Option.getOpt (!prefix, "/"),
492 sources = sources, 500 sources = sources,
493 protocol = !protocol, 501 protocol = !protocol,
494 dbms = !dbms, 502 dbms = !dbms,
495 sigFile = !sigFile, 503 sigFile = !sigFile,
496 safeGets = rev (!safeGets), 504 safeGets = rev (!safeGets),
497 onError = !onError 505 onError = !onError,
506 minHeap = !minHeap
498 } 507 }
499 508
500 fun mergeO f (old, new) = 509 fun mergeO f (old, new) =
501 case (old, new) of 510 case (old, new) of
502 (NONE, _) => new 511 (NONE, _) => new
537 (#sources old), 546 (#sources old),
538 protocol = mergeO #2 (#protocol old, #protocol new), 547 protocol = mergeO #2 (#protocol old, #protocol new),
539 dbms = mergeO #2 (#dbms old, #dbms new), 548 dbms = mergeO #2 (#dbms old, #dbms new),
540 sigFile = mergeO #2 (#sigFile old, #sigFile new), 549 sigFile = mergeO #2 (#sigFile old, #sigFile new),
541 safeGets = #safeGets old @ #safeGets new, 550 safeGets = #safeGets old @ #safeGets new,
542 onError = mergeO #2 (#onError old, #onError new) 551 onError = mergeO #2 (#onError old, #onError new),
552 minHeap = Int.max (#minHeap old, #minHeap new)
543 } 553 }
544 in 554 in
545 if accLibs then 555 if accLibs then
546 foldr (fn (job', job) => merge (job, job')) job (!libs) 556 foldr (fn (job', job) => merge (job, job')) job (!libs)
547 else 557 else
715 if n < 0 then 725 if n < 0 then
716 ErrorMsg.error ("invalid limit number '" ^ num ^ "'") 726 ErrorMsg.error ("invalid limit number '" ^ num ^ "'")
717 else 727 else
718 Settings.addLimit (class, n)) 728 Settings.addLimit (class, n))
719 | _ => ErrorMsg.error "invalid 'limit' arguments") 729 | _ => ErrorMsg.error "invalid 'limit' arguments")
730 | "minHeap" =>
731 (case Int.fromString arg of
732 NONE => ErrorMsg.error ("invalid min heap '" ^ arg ^ "'")
733 | SOME n => minHeap := n)
720 734
721 | _ => ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'"); 735 | _ => ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'");
722 read () 736 read ()
723 end 737 end
724 738