summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-11 15:16:04 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-11 15:16:04 -0500
commitf327681cc734f2b478051f0174ca9d980ff2e5ae (patch)
tree83876d7a5e776b30240a4894ea70dfa58ddf120b /src
parent019d9a9c56bab7876983b78613e621d884ec20ae (diff)
minHeap option in .urp files
Diffstat (limited to 'src')
-rw-r--r--src/c/urweb.c4
-rw-r--r--src/cjr_print.sml10
-rw-r--r--src/compiler.sig3
-rw-r--r--src/compiler.sml26
-rw-r--r--src/demo.sml3
-rw-r--r--src/settings.sig3
-rw-r--r--src/settings.sml4
7 files changed, 43 insertions, 10 deletions
diff --git a/src/c/urweb.c b/src/c/urweb.c
index 392108fe..b4a15bce 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -348,7 +348,7 @@ void uw_app_init(uw_app *app) {
app->client_init();
}
-int uw_time = 0, uw_time_max = 0;
+int uw_time = 0, uw_time_max = 0, uw_min_heap = 0;
// Single-request state
@@ -461,7 +461,7 @@ uw_context uw_init() {
buf_init(uw_headers_max, &ctx->outHeaders, 0);
buf_init(uw_page_max, &ctx->page, 0);
ctx->returning_indirectly = 0;
- buf_init(uw_heap_max, &ctx->heap, 0);
+ buf_init(uw_heap_max, &ctx->heap, uw_min_heap);
buf_init(uw_script_max, &ctx->script, 1);
ctx->script.start[0] = 0;
diff --git a/src/cjr_print.sml b/src/cjr_print.sml
index 46de6a52..df11737e 100644
--- a/src/cjr_print.sml
+++ b/src/cjr_print.sml
@@ -2834,6 +2834,16 @@ fun p_file env (ds, ps) =
box [string "static void uw_setup_limits() {",
newline,
+ case Settings.getMinHeap () of
+ 0 => box []
+ | n => box [string "uw_min_heap",
+ space,
+ string "=",
+ space,
+ string (Int.toString n),
+ string ";",
+ newline,
+ newline],
box [p_list_sep (box []) (fn (class, num) =>
let
val num = case class of
diff --git a/src/compiler.sig b/src/compiler.sig
index d0f6ac72..971ddf53 100644
--- a/src/compiler.sig
+++ b/src/compiler.sig
@@ -55,7 +55,8 @@ signature COMPILER = sig
dbms : string option,
sigFile : string option,
safeGets : string list,
- onError : (string * string list * string) option
+ onError : (string * string list * string) option,
+ minHeap : int
}
val compile : string -> bool
val compiler : string -> unit
diff --git a/src/compiler.sml b/src/compiler.sml
index 63db1b87..655f8ced 100644
--- a/src/compiler.sml
+++ b/src/compiler.sml
@@ -59,7 +59,8 @@ type job = {
dbms : string option,
sigFile : string option,
safeGets : string list,
- onError : (string * string list * string) option
+ onError : (string * string list * string) option,
+ minHeap : int
}
type ('src, 'dst) phase = {
@@ -308,14 +309,19 @@ fun institutionalizeJob (job : job) =
Option.app Settings.setProtocol (#protocol job);
Option.app Settings.setDbms (#dbms job);
Settings.setSafeGets (#safeGets job);
- Settings.setOnError (#onError job))
+ Settings.setOnError (#onError job);
+ Settings.setMinHeap (#minHeap job))
fun inputCommentableLine inf =
Option.map (fn s =>
let
val s = #1 (Substring.splitl (fn ch => ch <> #"#") (Substring.full s))
+ val s = #1 (Substring.splitr (not o Char.isSpace) s)
in
- Substring.string (#1 (Substring.splitr (not o Char.isSpace) s))
+ Substring.string (if Substring.size s > 0 andalso Char.isSpace (Substring.sub (s, Substring.size s - 1)) then
+ Substring.trimr 1 s
+ else
+ s)
end) (TextIO.inputLine inf)
fun parseUrp' accLibs fname =
@@ -349,7 +355,8 @@ fun parseUrp' accLibs fname =
dbms = NONE,
sigFile = NONE,
safeGets = [],
- onError = NONE}
+ onError = NONE,
+ minHeap = 0}
in
institutionalizeJob job;
{Job = job, Libs = []}
@@ -464,6 +471,7 @@ fun parseUrp' accLibs fname =
val sigFile = ref (Settings.getSigFile ())
val safeGets = ref []
val onError = ref NONE
+ val minHeap = ref 0
fun finish sources =
let
@@ -494,7 +502,8 @@ fun parseUrp' accLibs fname =
dbms = !dbms,
sigFile = !sigFile,
safeGets = rev (!safeGets),
- onError = !onError
+ onError = !onError,
+ minHeap = !minHeap
}
fun mergeO f (old, new) =
@@ -539,7 +548,8 @@ fun parseUrp' accLibs fname =
dbms = mergeO #2 (#dbms old, #dbms new),
sigFile = mergeO #2 (#sigFile old, #sigFile new),
safeGets = #safeGets old @ #safeGets new,
- onError = mergeO #2 (#onError old, #onError new)
+ onError = mergeO #2 (#onError old, #onError new),
+ minHeap = Int.max (#minHeap old, #minHeap new)
}
in
if accLibs then
@@ -717,6 +727,10 @@ fun parseUrp' accLibs fname =
else
Settings.addLimit (class, n))
| _ => ErrorMsg.error "invalid 'limit' arguments")
+ | "minHeap" =>
+ (case Int.fromString arg of
+ NONE => ErrorMsg.error ("invalid min heap '" ^ arg ^ "'")
+ | SOME n => minHeap := n)
| _ => ErrorMsg.error ("Unrecognized command '" ^ cmd ^ "'");
read ()
diff --git a/src/demo.sml b/src/demo.sml
index 19632d0e..4ebdbcbc 100644
--- a/src/demo.sml
+++ b/src/demo.sml
@@ -118,7 +118,8 @@ fun make' {prefix, dirname, guided} =
dbms = mergeWith #2 (#dbms combined, #dbms urp),
sigFile = mergeWith #2 (#sigFile combined, #sigFile urp),
safeGets = [],
- onError = NONE
+ onError = NONE,
+ minHeap = 0
}
val parse = Compiler.run (Compiler.transform Compiler.parseUrp "Demo parseUrp")
diff --git a/src/settings.sig b/src/settings.sig
index b72d007b..efbbdb32 100644
--- a/src/settings.sig
+++ b/src/settings.sig
@@ -211,4 +211,7 @@ signature SETTINGS = sig
val addLimit : string * int -> unit
val limits : unit -> (string * int) list
+
+ val setMinHeap : int -> unit
+ val getMinHeap : unit -> int
end
diff --git a/src/settings.sml b/src/settings.sml
index 7a943217..898b503f 100644
--- a/src/settings.sml
+++ b/src/settings.sml
@@ -509,4 +509,8 @@ fun addLimit (v as (name, _)) =
raise Fail ("Unknown limit category '" ^ name ^ "'")
fun limits () = !limitsList
+val minHeap = ref 0
+fun setMinHeap n = if n >= 0 then minHeap := n else raise Fail "Trying to set negative minHeap"
+fun getMinHeap () = !minHeap
+
end