[MLton] Re: PackWord to/from nonsense
Matthew Fluet
fluet at tti-c.org
Thu Jul 9 17:37:16 PDT 2009
On Wed, 8 Jul 2009, Wesley W. Terpstra wrote:
> It would be ideal if I could get this conversion code to work also on
> Int.{to,from}Large, but there are two problems: 1) packing an IntInf
> involves shifting and tagging 2) FixedInt doesn't fit into IntInf without
> using GMP's representation.
Another option is to make the (unsafe) IntInf conversions into primitives:
IntInf_truncToWord of WordSize.t
| Word_extdToIntInf of WordSize.t * {signed: bool}
Like the (unsafe) Word conversions, the IntInf_truncToWord does not check
for Overflow; that check would be left (in some fashion) to the Basis
Library implementation.
Your conversion code should work with
fun rules x3 (conversion as ((W2: WordSize.t option,
W3: WordSize.t option,
{signed=s2}),
x2)) =
let
val { equals, <, <=, ... } =
Relation.compare (fn (NONE, NONE) => EQUAL
| (NONE, SOME _) => GREATER
| (SOME _, NONE) => LESS
| (SOME w1, SOME w3) =>
WordSize.compare (w1, w3))
That is, represent a width as a WordSize.t option, with NONE for the
infinite width (IntInf).
The downside of this implementation is that the shifting and tagging
(small int inf) or vector creation (big int inf) for extending to an int
inf and untagging and shifting or vector extraction for truncating an int
inf that currently resides in basis-library/integer/int-inf0.sml would
need to be implemented in the compiler (perhaps expanding the
IntInf_truncToWord and IntInf_extdToWord in the combine conversions pass,
since they wouldn't be needed after). It isn't terribly complicated code,
but it is a little more verbose to write in SSA, rather than in SML.
More information about the MLton
mailing list