[MLton] IntInf_to_WordVector semantics

Stephen Weeks MLton@mlton.org
Fri, 9 Jun 2006 17:22:39 -0700


> But we are unsure about IntInf_to_WordVector. 

IntInf_toVector is a cast (i.e. nothing happens at runtime) from the
sum type that is IntInf.int to the word vector type.  The basis
library ensures via run-time tests that this will only be called with
a value that actually is a word vector.

> Looking at the signature of WordXVector it looks like the only way
> to create one is to use the fromString function.

Yeah, that's because we never construct any of the GnuMP vectors in
the compiler.  We keep around the big integer throughout the compiler
and spit out a decimal or hex string at the end, leaving the
conversion to a GnuMP vector to the runtime.

> We are wondering how exactly any given number should be translated
> to a string to produce the correct word vector. Assuming that is the
> right thing to do at all. It would seem logical that we would just
> produce the number as a string, but the, IntInf -> string -> word
> vector, sequence seems odd.

IntInf_toVector doesn't have anything to do with converting integers
to decimal strings.  It is only a type cast.  It shouldn't have any
impact on flow analysis (unless one was doing analysis of integers
simultaneously).  As to your interpreter, you could use
MLton.IntInf.rep

  http://mlton.org/MLtonIntInf

which lets you go from an IntInf.int to a word vector, but there isn't
anything to go the other way, which is what you would need to
implement WordVector_toIntInf.

If you must handle this in your interpreter, you could hook into the
MLton primitive

   _prim "WordVector_toIntInf": Word32.word vector -> IntInf.int;

But if you do this you are well on your way down the slippery slope of
building a full concrete interpreter for SXML, which is a challenging
exercise of questionable utility.  In the end, to get meaningful
results, you will need to translate your IL back into one of MLton's
ILs and let the rest of the compiler run.  So, you may as well write
that translation now and use that for testing correctness of your CPS
pass.  As to correspondence between a concrete interpreter and a flow
analysis, there's really not much overlap in my experience.