Good news so far... :)
Stephen Weeks
MLton@research.nj.nec.com
Wed, 3 Nov 1999 19:23:30 -0800 (PST)
> Yes, thanks! It works now... but it doesn't like the _prim
> function. It thinks that _ is the wildcard symbol...
> Are there any good workarounds for this?
Code containing _prim should only be compiled using MLton, not SML/NJ.
What I do for program development is use stubs so that I can typecheck
using SML/NJ. Once the program typechecks, I then compile using
MLton. So, I have a file that defines a bogus MLton structure which I
reference in my sources.cm that looks like the following:
--------------------------------------------------------------------------------
(* This file is just a dummy provided in place of the structure that MLton
* supplies so that we can compile under SML/NJ.
*)
structure MLton: MLTON =
struct
fun serialize _ = raise Fail "serialize"
fun deserialize _ = raise Fail "deserialize"
structure GC =
struct
fun collect _ = ()
fun messages _ = ()
fun summary _ = ()
end
fun cleanAtExit _ = raise Fail "cleanAtExit"
fun random _ = 0w13: Word32.word
val safe = true
datatype status = Original | Clone
fun saveWorld _ = raise Fail "saveWorld"
fun size _ = ~1
local open SMLofNJ.Cont
in
type 'a cont = 'a cont
val callcc = callcc
val throw = throw
end
end
--------------------------------------------------------------------------------
Then, I have a Makefile that uses cmcat to concatenate all of the
files together to create the file that MLton compiles. I keep all of
my stubs in a particular known directory and use egrep to strip out
the stubs from the concatenation. A generic Makefile that I use looks
something like:
--------------------------------------------------------------------------------
NAME = foo
mlton = mlton
FLAGS =
all: $(NAME)
$(NAME): $(NAME).sml
$(mlton) -o $(NAME) $(FLAGS) $(NAME).sml
$(NAME).sml: $(NAME).files $(shell cat $(NAME).files)
@echo 'Concatenating SML files to make $(NAME) source file'
( \
echo 'structure Word31 = Word structure Int31 = Int'; \
cat $(NAME).files | xargs cat; \
echo 'val _ = Main.main()' \
) >$(NAME).sml
$(NAME).files: sources.cm
@echo 'Using CM to build file list'
cmcat -filename sources.cm \
| sed 's;.*/$(NAME)/\(.*\);\1;' \
| egrep -v 'library/nj-basis/' \
>$(NAME).files
--------------------------------------------------------------------------------
> Well, I'm mostly concerned about "rare"/occational breaks in
> the game, which I guess would be distracting for the user.
> What about forcing the GC to run every iteration of the main
> loop? Say, if there was an extra non-standard ML function
> like: force_GC : unit -> unit
This already exists in MLton -- MLton.GC.collect.
> But of course this would only be a good thing, if
> the garbage collector is fast when only a few things
> have changed in memory... maybe a
> force_quick_GC : unit -> unit
> would be better :)
> A GC function optimized for small memory changes...?
MLton.GC.collect does a full GC, which takes time proportional to the
amount of live data, so if you call it whenever there isn't much live
data, then it might be enough. But I doubt this is good enough for
your situation.