changeset 1540:659a2f71f5e5

Compiler frees as much memory as possible before passing control to C compiler
author Adam Chlipala <adam@chlipala.net>
date Mon, 15 Aug 2011 11:26:10 -0400
parents dde3bd82cb3d
children 94ef0b07066a
files src/compiler.mlb src/compiler.sig src/compiler.sml src/main.mlton.sml
diffstat 4 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/compiler.mlb	Mon Aug 15 10:22:09 2011 -0400
+++ b/src/compiler.mlb	Mon Aug 15 11:26:10 2011 -0400
@@ -1,4 +1,5 @@
 $(SML_LIB)/basis/basis.mlb
+$(SML_LIB)/basis/mlton.mlb
 
 urweb.mlb
 
--- a/src/compiler.sig	Mon Aug 15 10:22:09 2011 -0400
+++ b/src/compiler.sig	Mon Aug 15 11:26:10 2011 -0400
@@ -65,6 +65,11 @@
     val compileC : {cname : string, oname : string, ename : string, libs : string,
                     profile : bool, debug : bool, link : string list} -> bool
 
+    val beforeC : (unit -> unit) ref
+    (* This function is called before beginning C compilation.
+     * The current use is for MLton to compact its heap here, to avoid hogging
+     * space after all the interesting ML code is done. *)
+
     type ('src, 'dst) phase
     type ('src, 'dst) transform
 
--- a/src/compiler.sml	Mon Aug 15 10:22:09 2011 -0400
+++ b/src/compiler.sml	Mon Aug 15 11:26:10 2011 -0400
@@ -1311,6 +1311,8 @@
 
 val escapeFilename = String.translate (fn #" " => "\\ " | #"\"" => "\\\"" | #"'" => "\\'" | ch => str ch)
 
+val beforeC = ref (fn () => ())
+
 fun compileC {cname, oname, ename, libs, profile, debug, link = link'} =
     let
         val proto = Settings.currentProtocol ()
@@ -1348,6 +1350,7 @@
                  ();
              OS.Process.isSuccess (OS.Process.system s))
     in
+        !beforeC ();
         system compile andalso system link
     end
 
--- a/src/main.mlton.sml	Mon Aug 15 10:22:09 2011 -0400
+++ b/src/main.mlton.sml	Mon Aug 15 11:26:10 2011 -0400
@@ -32,6 +32,8 @@
 val tutorial = ref false
 val css = ref false
 
+val () = Compiler.beforeC := MLton.GC.pack
+
 fun printVersion () = (print (Config.versionString ^ "\n");
 		       OS.Process.exit OS.Process.success)
 fun printNumericVersion () = (print (Config.versionNumber ^ "\n");