nullary _prim's

Stephen Weeks MLton@research.nj.nec.com
Thu, 29 Jun 2000 13:20:07 -0700 (PDT)


> As best I can make out, it's
> doing a gcc call _before_ getting to the point of outputting the .c file.
> So, I'm guessing that's the compile-time method of resolving primitives,
> but I wasn't exactly clear on everything going on.

Correct.  After elaboration, the MLton traverses the CoreML program
(see core-ml/lookup-constant.{fun,sig}) and builds a little C program
to print out the values of all nullary primitives (which must be of
type bool, int, or word, for now.  It then calls gcc, runs the
program, parses the output, and builds a little hash table.  On lines
859-868 of type-inference/infer.fun, these constants are replaced by
the appropriate Xml constant.  

The upshot is that no pass after type inference needs to worry about
nullary primitives.

The code dependencies are a bit weird because LookupConstant needs to 
call gcc with the right include files, which are determined by Main.
So, LookupConstant takes an extra argument which is a function
(created by Main) that knows how to call gcc.