A Hugs bytecode interpreter

Malcolm Wallace Malcolm.Wallace@cs.york.ac.uk
Mon, 2 Apr 2001 16:25:07 +0100

> Do you know roughly how small nhc98 can get? 
> Even if a 16-bit system is impossible, having a small 32-bit Haskell
> could be of interest in other connections.

The executable for a "hello world" type program currently comes out
at about 115kb code size when compiled with nhc98.  We have done
some tests on manually stripping the excess dead weight from that (by
removing class overloading, simplifying the error-handling, cutting
out big Integers, etc. etc.), and ended up with a 45kb executable.
Most of that is the bytecode interpreter itself, so it can't be reduced
much further - although we did once toy with the idea of automatically
removing code from the interpreter for individual bytecodes that were
discovered not to be used in a particular program...  :-)

For runtime memory usage, nhc98 uses a default 20kb stack, and a
default 400kb heap, but both of these are configurable.  (There are
some other small static tables, of typically 1-2kb each.)  The absolute
minimum heap size possible is 2512 bytes - and I have some non-trivial
programs that run happily in that tiny heap (including one that runs
for over 60 seconds and writes a complex 44Mb output file!).

> And is it absolutely impossible to make a 16-bit nch98?  After all, the
> compiler could remain 32-bit - it's just the bytecode interpreter that
> would have to be 16-bit.  A rudimentary system might suffice as long as
> there is a good FFI.

It should be quite possible, yes.  At a guess, the main change
needed is to adjust some hard-coded constants to determine the size
of ints, addresses, and alignment boundaries.  Provided you have a C
cross-compiler for the 16-bit machine, that should be all you need.
(As a bonus on a 16-bit system, the bytecode files nhc98 generates
will become somewhat smaller due to the size reduction of in-lined
address labels.)

> And a somewhat unrelated question: is nhc98 going to have native code
> generation in the foreseeable future?

Not in the immediate future, unless some eager Haskell developer or
student decides they would like to take it on as a project.  I know
there are several people who would be keen to see a native backend
for nhc98 (including myself), but no-one has yet found sufficient
time to devote to it.