[MLton-commit] r4548

Matthew Fluet MLton@mlton.org
Mon, 15 May 2006 20:02:16 -0700


Regularized the internal int/word conversions.  This makes it easier
to use coercion functions without knowing the signedness of the
structure.  (This is difficult with the Basis Library functions; for
instance, Int<N>.fromInt has different semantics from
Word<N>.fromInt.)

Added config/c/sys-types.sml which adds signatures to the C system
types, exposing the minimally needed functions.  Most types need only
(unchecked) casts from and to SysWord.word.


----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/Makefile
U   mlton/branches/on-20050822-x86_64-branch/basis-library/arrays-and-vectors/sequence.fun
U   mlton/branches/on-20050822-x86_64-branch/basis-library/build/sources.mlb
A   mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/sys-types.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/config/default/fixed-int.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-int.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-word.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int.sml
D   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int0.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/integer.sig
A   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/iwconv0.sml
A   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num0.sml
A   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num1.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sig
U   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml
D   mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word0.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/ffi.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/itimer.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/process.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig
U   mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rusage.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/net/net-host-db.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/net/net.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/flags.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-char.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml
A   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-iwconv.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-seq.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-string.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-word.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb
U   mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/system/time.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/text/byte.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/text/char0.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/text/string-cvt.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/util/CUtil.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library/util/integral-comparisons.sml

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/Makefile
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/Makefile	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/Makefile	2006-05-16 03:02:10 UTC (rev 4548)
@@ -33,7 +33,7 @@
 .PHONY: type-check-def
 type-check-def:
 	"$(MLTON)" -disable-ann deadCode -stop tc -show-types true \
-		libs/all.mlb; \
+		libs/all.mlb; 
 
 .PHONY: type-check-all
 type-check-all:
@@ -63,4 +63,5 @@
 		-default-type "$$defreal" \
 		-default-type "$$defword" \
 		libs/all.mlb; \
+	rm -f target.map; \
 	done; done; done; done; done; done; done; done; done

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/arrays-and-vectors/sequence.fun
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/arrays-and-vectors/sequence.fun	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/arrays-and-vectors/sequence.fun	2006-05-16 03:02:10 UTC (rev 4548)
@@ -6,6 +6,61 @@
  * See the file MLton-LICENSE for details.
  *)
 
+structure SeqIndex =
+   struct
+      open SeqIndex
+
+      val maxLen' = maxInt'
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> int
+             val fInt8 = SeqIndex.sextdFromInt8
+             val fInt16 = SeqIndex.sextdFromInt16
+             val fInt32 = SeqIndex.sextdFromInt32
+             val fInt64 = SeqIndex.sextdFromInt64
+             val fIntInf = SeqIndex.sextdFromIntInf)
+      in
+         val fromIntUnsafe = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> int
+             val fInt8 = SeqIndex.schckFromInt8
+             val fInt16 = SeqIndex.schckFromInt16
+             val fInt32 = SeqIndex.schckFromInt32
+             val fInt64 = SeqIndex.schckFromInt64
+             val fIntInf = SeqIndex.schckFromIntInf)
+      in
+         val fromInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = int -> 'a
+             val fInt8 = SeqIndex.sextdToInt8
+             val fInt16 = SeqIndex.sextdToInt16
+             val fInt32 = SeqIndex.sextdToInt32
+             val fInt64 = SeqIndex.sextdToInt64
+             val fIntInf = SeqIndex.sextdToIntInf)
+      in
+         val toIntUnsafe = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = int -> 'a
+             val fInt8 = SeqIndex.schckToInt8
+             val fInt16 = SeqIndex.schckToInt16
+             val fInt32 = SeqIndex.schckToInt32
+             val fInt64 = SeqIndex.schckToInt64
+             val fIntInf = SeqIndex.schckToIntInf)
+      in
+         val toInt = S.f
+      end
+   end
+
 functor Sequence (S: sig
                         type 'a sequence 
                         type 'a elt
@@ -48,20 +103,20 @@
 
       local
          fun doit (toInt, fromInt, maxInt') =
-            (Array.maxLen', toInt Array.maxLen') 
+            (SeqIndex.maxLen', toInt SeqIndex.maxLen') 
             handle Overflow => (fromInt maxInt', maxInt')
          structure S =
             Int_ChooseInt
             (type 'a t = SeqIndex.int * 'a
-             val fInt8 = doit (SeqIndex.toInt8, SeqIndex.fromInt8,
+             val fInt8 = doit (SeqIndex.schckToInt8, SeqIndex.schckFromInt8,
                                Primitive.Int8.maxInt')
-             val fInt16 = doit (SeqIndex.toInt16, SeqIndex.fromInt16,
+             val fInt16 = doit (SeqIndex.schckToInt16, SeqIndex.schckFromInt16,
                                 Primitive.Int16.maxInt')
-             val fInt32 = doit (SeqIndex.toInt32, SeqIndex.fromInt32,
+             val fInt32 = doit (SeqIndex.schckToInt32, SeqIndex.schckFromInt32,
                                 Primitive.Int32.maxInt')
-             val fInt64 = doit (SeqIndex.toInt64, SeqIndex.fromInt64,
+             val fInt64 = doit (SeqIndex.schckToInt64, SeqIndex.schckFromInt64,
                                 Primitive.Int64.maxInt')
-             val fIntInf = (Array.maxLen', SeqIndex.toIntInf Array.maxLen'))
+             val fIntInf = (SeqIndex.maxLen', SeqIndex.schckToIntInf SeqIndex.maxLen'))
       in
          val (maxLen', maxLen) = S.f
       end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/build/sources.mlb
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/build/sources.mlb	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/build/sources.mlb	2006-05-16 03:02:10 UTC (rev 4548)
@@ -17,8 +17,8 @@
    ../util/dynamic-wind.sig
    ../util/dynamic-wind.sml
 
-   ../integer/int0.sml
-   ../integer/word0.sml
+   ../integer/iwconv0.sml
+   ../integer/num0.sml
    local 
       ../config/bind/int-prim.sml 
       ../config/bind/pointer-prim.sml
@@ -29,8 +29,6 @@
       ../config/header/$(HEADER_WORD)
       ../config/seqindex/$(SEQINDEX_INT)
       ../config/c/$(TARGET_ARCH)-$(TARGET_OS)/c-types.sml
-      ../config/c/position.sml
-      ../config/c/sys-word.sml
    end end
    ../integer/int-inf0.sml
    local
@@ -41,12 +39,14 @@
       in ann "forceUsed" in
          ../config/default/$(DEFAULT_INT)
          ../config/default/$(DEFAULT_WORD)
+         ../config/default/fixed-int.sml
          ../config/default/large-int.sml
          ../config/default/large-word.sml
+         ../config/c/position.sml
+         ../config/c/sys-word.sml
       end end
    in
-      ../integer/int1.sml
-      ../integer/word1.sml
+      ../integer/num1.sml
    end
 
    local 
@@ -61,6 +61,7 @@
       ../config/default/$(DEFAULT_INT)
       ../config/default/$(DEFAULT_REAL)
       ../config/default/$(DEFAULT_WORD)
+      ../config/default/fixed-int.sml
       ../config/default/large-int.sml
       ../config/default/large-real.sml
       ../config/default/large-word.sml
@@ -207,6 +208,7 @@
    ../util/cleaner.sig
    ../util/cleaner.sml
 
+   ../config/c/sys-types.sml
    ../system/pre-os.sml
 
    ../posix/error.sig

Added: mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/sys-types.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/sys-types.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/config/c/sys-types.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -0,0 +1,83 @@
+(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+signature C_SYSTYPE =
+   sig
+      type t
+      val castFromSysWord: SysWord.word -> t
+      val castToSysWord: t -> SysWord.t
+   end
+signature C_FLAGTYPE =
+   sig
+      include C_SYSTYPE
+      val andb: t * t -> t
+      val notb: t -> t
+      val orb: t * t -> t
+   end
+
+(* from <dirent.h> *)
+structure C_DirP : C_SYSTYPE = C_DirP
+
+(* from <poll.h> *)
+structure C_NFds : sig
+                      include C_SYSTYPE 
+                      val fromInt: Int.int -> t
+                   end = C_NFds
+
+(* from <resource.h> *)
+structure C_RLim : C_SYSTYPE = C_RLim
+
+(* from <sys/types.h> *)
+structure C_Clock : sig
+                       include C_SYSTYPE
+                       val castFromFixedInt: FixedInt.int -> t
+                       val toLargeInt: t -> LargeInt.int
+                    end = C_Clock
+structure C_Dev : C_SYSTYPE = C_Dev
+structure C_GId : C_SYSTYPE = C_GId
+structure C_Id : C_SYSTYPE = C_Id
+structure C_INo : C_SYSTYPE = C_INo
+structure C_Mode : C_FLAGTYPE = C_Mode
+structure C_NLink : sig
+                       include C_SYSTYPE
+                       val toInt: t -> int
+                    end = C_NLink
+structure C_Off = C_Off
+structure C_PId : sig 
+                     include C_SYSTYPE 
+                     val castFromFixedInt: FixedInt.int -> t
+                     val ~ : t -> t
+                  end = C_PId
+structure C_SSize : sig
+                       include C_SYSTYPE
+                       val castFromFixedInt: FixedInt.int -> t
+                       val toInt: t -> Int.int
+                    end = C_SSize
+structure C_SUSeconds : sig
+                           include C_SYSTYPE
+                           val fromLargeInt: LargeInt.int -> t
+                           val toLargeInt: t -> LargeInt.int
+                        end = C_SUSeconds
+structure C_Time : sig
+                      include C_SYSTYPE
+                      val fromInt: Int.int -> t
+                      val toInt: t -> Int.int
+                      val fromLargeInt: LargeInt.int -> t
+                      val toLargeInt: t -> LargeInt.int
+                   end = C_Time
+structure C_UId : C_SYSTYPE = C_UId
+
+(* from <sys/socket.h> *)
+structure C_Socklen = C_Socklen
+
+(* from <termios.h> *)
+structure C_CC : C_SYSTYPE = C_CC
+structure C_Speed : sig
+                       include C_SYSTYPE
+                       val compare: t * t -> order
+                    end = C_Speed
+structure C_TCFlag : C_FLAGTYPE = C_TCFlag

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/config/default/fixed-int.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/config/default/fixed-int.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/config/default/fixed-int.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -7,6 +7,6 @@
 
 structure FixedInt = Int64
 
-functor FixedInt_ChooseIntN (A: CHOOSE_INT_ARG) :
+functor FixedInt_ChooseIntN (A: CHOOSE_INTN_ARG) :
    sig val f : FixedInt.int A.t end =
    ChooseIntN_Int64 (A)

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-int.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-int.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-int.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -10,8 +10,8 @@
       eqtype int
       type big
          
-      val precision': Int32.int
       val fromBigUnsafe: big -> int
+      val sizeInBits: Int32.int
       val toBig: int -> big
    end
 
@@ -21,7 +21,7 @@
       structure Small =
          struct
             open Small
-            val precision': Int.int = Int32.toInt precision'
+            val precision': Int.int = Int32.toInt sizeInBits
          end
 
       val () = if Int.< (Small.precision', Big.precision') then ()

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-word.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-word.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/embed-word.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -11,8 +11,8 @@
       type big
          
       val fromBigUnsafe: big -> word
+      val sizeInBits: Int32.int
       val toBig: word -> big
-      val wordSize: Int32.int
    end
 
 functor EmbedWord (structure Big: WORD
@@ -21,7 +21,7 @@
       structure Small =
          struct
             open Small
-            val wordSize: Int.int = Int32.toInt wordSize
+            val wordSize: Int.int = Int32.toInt sizeInBits
          end
 
       val () = if Int.< (Small.wordSize, Big.wordSize) then ()

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -47,6 +47,11 @@
          val ~>> = make ~>>
       end
 
+      val fromInt = schckFromInt
+      val toInt = schckToInt
+      val fromLarge = schckFromLargeInt
+      val toLarge = schckToLargeInt
+
       local
          open StringCvt
 
@@ -305,7 +310,7 @@
                         else i * evenPow (Int.- (j, 1))
                      (* evenPow (j) returns (i ^ j), assuming j is even *)
                      and evenPow (j: Int.int): int =
-                        square (pow (Int.~>> (j, 0w1)))
+                        square (pow (Int.div (j, 2)))
                   in 
                      pow j
                   end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int-inf0.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -6,7 +6,7 @@
  * See the file MLton-LICENSE for details.
  *)
 
-signature INT_INF0 =
+signature PRIM_INT_INF =
    sig
       eqtype int
       type t = int
@@ -69,9 +69,11 @@
       val isNeg: int -> bool
                
       val andb: int * int -> int
+      val <<? : int * Primitive.Word32.word -> int
       val << : int * Primitive.Word32.word -> int
       val notb: int -> int
       val orb: int * int -> int
+      val ~>>? : int * Primitive.Word32.word -> int
       val ~>> : int * Primitive.Word32.word -> int
       val xorb: int * int -> int
 
@@ -83,88 +85,251 @@
                                 numLimbsMinusOne: SeqIndex.int} -> 'a}
                    -> int -> 'a)
 
-      (* Sign extend. *)
-      val fromInt8Unsafe: Primitive.Int8.int -> int
-      val fromInt16Unsafe: Primitive.Int16.int -> int
-      val fromInt32Unsafe: Primitive.Int32.int -> int
-      val fromInt64Unsafe: Primitive.Int64.int -> int
-      val fromIntInfUnsafe: Primitive.IntInf.int -> int
+      val zextdFromInt8: Primitive.Int8.int -> int
+      val zextdFromInt16: Primitive.Int16.int -> int
+      val zextdFromInt32: Primitive.Int32.int -> int
+      val zextdFromInt64: Primitive.Int64.int -> int
+      val zextdFromIntInf: Primitive.IntInf.int -> int
+      val zextdFromWord8: Primitive.Word8.word -> int
+      val zextdFromWord16: Primitive.Word16.word -> int
+      val zextdFromWord32: Primitive.Word32.word -> int
+      val zextdFromWord64: Primitive.Word64.word -> int
+      val zextdToInt8: int -> Primitive.Int8.int
+      val zextdToInt16: int -> Primitive.Int16.int
+      val zextdToInt32: int -> Primitive.Int32.int
+      val zextdToInt64: int -> Primitive.Int64.int
+      val zextdToIntInf: int -> Primitive.IntInf.int
+      val zextdToWord8: int -> Primitive.Word8.word
+      val zextdToWord16: int -> Primitive.Word16.word
+      val zextdToWord32: int -> Primitive.Word32.word
+      val zextdToWord64: int -> Primitive.Word64.word
 
-      (* Sign extend. *)
-      val fromInt8: Primitive.Int8.int -> int
-      val fromInt16: Primitive.Int16.int -> int
-      val fromInt32: Primitive.Int32.int -> int
-      val fromInt64: Primitive.Int64.int -> int
-      val fromIntInf: Primitive.IntInf.int -> int
+      val sextdFromInt8: Primitive.Int8.int -> int
+      val sextdFromInt16: Primitive.Int16.int -> int
+      val sextdFromInt32: Primitive.Int32.int -> int
+      val sextdFromInt64: Primitive.Int64.int -> int
+      val sextdFromIntInf: Primitive.IntInf.int -> int
+      val sextdFromWord8: Primitive.Word8.word -> int
+      val sextdFromWord16: Primitive.Word16.word -> int
+      val sextdFromWord32: Primitive.Word32.word -> int
+      val sextdFromWord64: Primitive.Word64.word -> int
+      val sextdToInt8: int -> Primitive.Int8.int
+      val sextdToInt16: int -> Primitive.Int16.int
+      val sextdToInt32: int -> Primitive.Int32.int
+      val sextdToInt64: int -> Primitive.Int64.int
+      val sextdToIntInf: int -> Primitive.IntInf.int
+      val sextdToWord8: int -> Primitive.Word8.word
+      val sextdToWord16: int -> Primitive.Word16.word
+      val sextdToWord32: int -> Primitive.Word32.word
+      val sextdToWord64: int -> Primitive.Word64.word
 
-      (* Zero extend. *)
-      val fromWord8Unsafe: Primitive.Word8.word -> int
-      val fromWord16Unsafe: Primitive.Word16.word -> int
-      val fromWord32Unsafe: Primitive.Word32.word -> int
-      val fromWord64Unsafe: Primitive.Word64.word -> int
+      val castFromInt8: Primitive.Int8.int -> int
+      val castFromInt16: Primitive.Int16.int -> int
+      val castFromInt32: Primitive.Int32.int -> int
+      val castFromInt64: Primitive.Int64.int -> int
+      val castFromIntInf: Primitive.IntInf.int -> int
+      val castFromWord8: Primitive.Word8.word -> int
+      val castFromWord16: Primitive.Word16.word -> int
+      val castFromWord32: Primitive.Word32.word -> int
+      val castFromWord64: Primitive.Word64.word -> int
+      val castToInt8: int -> Primitive.Int8.int
+      val castToInt16: int -> Primitive.Int16.int
+      val castToInt32: int -> Primitive.Int32.int
+      val castToInt64: int -> Primitive.Int64.int
+      val castToIntInf: int -> Primitive.IntInf.int
+      val castToWord8: int -> Primitive.Word8.word
+      val castToWord16: int -> Primitive.Word16.word
+      val castToWord32: int -> Primitive.Word32.word
+      val castToWord64: int -> Primitive.Word64.word
 
-      (* Zero extend. *)
-      val fromWord8: Primitive.Word8.word -> int
-      val fromWord16: Primitive.Word16.word -> int
-      val fromWord32: Primitive.Word32.word -> int
-      val fromWord64: Primitive.Word64.word -> int
+      val zchckFromInt8: Primitive.Int8.int -> int
+      val zchckFromInt16: Primitive.Int16.int -> int
+      val zchckFromInt32: Primitive.Int32.int -> int
+      val zchckFromInt64: Primitive.Int64.int -> int
+      val zchckFromIntInf: Primitive.IntInf.int -> int
+      val zchckFromWord8: Primitive.Word8.word -> int
+      val zchckFromWord16: Primitive.Word16.word -> int
+      val zchckFromWord32: Primitive.Word32.word -> int
+      val zchckFromWord64: Primitive.Word64.word -> int
+      val zchckToInt8: int -> Primitive.Int8.int
+      val zchckToInt16: int -> Primitive.Int16.int
+      val zchckToInt32: int -> Primitive.Int32.int
+      val zchckToInt64: int -> Primitive.Int64.int
+      val zchckToIntInf: int -> Primitive.IntInf.int
+      val zchckToWord8: int -> Primitive.Word8.word
+      val zchckToWord16: int -> Primitive.Word16.word
+      val zchckToWord32: int -> Primitive.Word32.word
+      val zchckToWord64: int -> Primitive.Word64.word
 
-      (* Sign extend. *)
-      val fromWord8XUnsafe: Primitive.Word8.word -> int
-      val fromWord16XUnsafe: Primitive.Word16.word -> int
-      val fromWord32XUnsafe: Primitive.Word32.word -> int
-      val fromWord64XUnsafe: Primitive.Word64.word -> int
+      val schckFromInt8: Primitive.Int8.int -> int
+      val schckFromInt16: Primitive.Int16.int -> int
+      val schckFromInt32: Primitive.Int32.int -> int
+      val schckFromInt64: Primitive.Int64.int -> int
+      val schckFromIntInf: Primitive.IntInf.int -> int
+      val schckFromWord8: Primitive.Word8.word -> int
+      val schckFromWord16: Primitive.Word16.word -> int
+      val schckFromWord32: Primitive.Word32.word -> int
+      val schckFromWord64: Primitive.Word64.word -> int
+      val schckToInt8: int -> Primitive.Int8.int
+      val schckToInt16: int -> Primitive.Int16.int
+      val schckToInt32: int -> Primitive.Int32.int
+      val schckToInt64: int -> Primitive.Int64.int
+      val schckToIntInf: int -> Primitive.IntInf.int
+      val schckToWord8: int -> Primitive.Word8.word
+      val schckToWord16: int -> Primitive.Word16.word
+      val schckToWord32: int -> Primitive.Word32.word
+      val schckToWord64: int -> Primitive.Word64.word
+   end
 
-      (* Sign extend. *)
-      val fromWord8X: Primitive.Word8.word -> int
-      val fromWord16X: Primitive.Word16.word -> int
-      val fromWord32X: Primitive.Word32.word -> int
-      val fromWord64X: Primitive.Word64.word -> int
+signature PRIM_INTWORD_CONV =
+   sig
+      include PRIM_INTWORD_CONV
 
-      (* Lowbits. *)
-      val toInt8Unsafe: int -> Primitive.Int8.int
-      val toInt16Unsafe: int -> Primitive.Int16.int
-      val toInt32Unsafe: int -> Primitive.Int32.int
-      val toInt64Unsafe: int -> Primitive.Int64.int
-      val toIntInfUnsafe: int -> Primitive.IntInf.int
+      val idFromIntInfToIntInf: Primitive.IntInf.int -> Primitive.IntInf.int
 
-      (* Overflow checking. *)
-      val toInt8: int -> Primitive.Int8.int
-      val toInt16: int -> Primitive.Int16.int
-      val toInt32: int -> Primitive.Int32.int
-      val toInt64: int -> Primitive.Int64.int
-      val toIntInf: int -> Primitive.IntInf.int
+      val zextdFromInt8ToIntInf: Primitive.Int8.int -> Primitive.IntInf.int
+      val zextdFromInt16ToIntInf: Primitive.Int16.int -> Primitive.IntInf.int
+      val zextdFromInt32ToIntInf: Primitive.Int32.int -> Primitive.IntInf.int
+      val zextdFromInt64ToIntInf: Primitive.Int64.int -> Primitive.IntInf.int
+      val zextdFromWord8ToIntInf: Primitive.Word8.word -> Primitive.IntInf.int
+      val zextdFromWord16ToIntInf: Primitive.Word16.word -> Primitive.IntInf.int
+      val zextdFromWord32ToIntInf: Primitive.Word32.word -> Primitive.IntInf.int
+      val zextdFromWord64ToIntInf: Primitive.Word64.word -> Primitive.IntInf.int
 
-      (* Lowbits. *)
-      val toWord8Unsafe: int -> Primitive.Word8.word
-      val toWord16Unsafe: int -> Primitive.Word16.word
-      val toWord32Unsafe: int -> Primitive.Word32.word
-      val toWord64Unsafe: int -> Primitive.Word64.word
+      val zextdFromIntInfToInt8: Primitive.IntInf.int -> Primitive.Int8.int
+      val zextdFromIntInfToInt16: Primitive.IntInf.int -> Primitive.Int16.int
+      val zextdFromIntInfToInt32: Primitive.IntInf.int -> Primitive.Int32.int
+      val zextdFromIntInfToInt64: Primitive.IntInf.int -> Primitive.Int64.int
+      val zextdFromIntInfToIntInf: Primitive.IntInf.int -> Primitive.IntInf.int
+      val zextdFromIntInfToWord8: Primitive.IntInf.int -> Primitive.Word8.word
+      val zextdFromIntInfToWord16: Primitive.IntInf.int -> Primitive.Word16.word
+      val zextdFromIntInfToWord32: Primitive.IntInf.int -> Primitive.Word32.word
+      val zextdFromIntInfToWord64: Primitive.IntInf.int -> Primitive.Word64.word
 
-      (* Lowbits. *)
-      val toWord8: int -> Primitive.Word8.word
-      val toWord16: int -> Primitive.Word16.word
-      val toWord32: int -> Primitive.Word32.word
-      val toWord64: int -> Primitive.Word64.word
 
-      (* Lowbits. *)
-      val toWord8XUnsafe: int -> Primitive.Word8.word
-      val toWord16XUnsafe: int -> Primitive.Word16.word
-      val toWord32XUnsafe: int -> Primitive.Word32.word
-      val toWord64XUnsafe: int -> Primitive.Word64.word
+      val sextdFromInt8ToIntInf: Primitive.Int8.int -> Primitive.IntInf.int
+      val sextdFromInt16ToIntInf: Primitive.Int16.int -> Primitive.IntInf.int
+      val sextdFromInt32ToIntInf: Primitive.Int32.int -> Primitive.IntInf.int
+      val sextdFromInt64ToIntInf: Primitive.Int64.int -> Primitive.IntInf.int
+      val sextdFromWord8ToIntInf: Primitive.Word8.word -> Primitive.IntInf.int
+      val sextdFromWord16ToIntInf: Primitive.Word16.word -> Primitive.IntInf.int
+      val sextdFromWord32ToIntInf: Primitive.Word32.word -> Primitive.IntInf.int
+      val sextdFromWord64ToIntInf: Primitive.Word64.word -> Primitive.IntInf.int
 
-      (* Lowbits. *)
-      val toWord8X: int -> Primitive.Word8.word
-      val toWord16X: int -> Primitive.Word16.word
-      val toWord32X: int -> Primitive.Word32.word
-      val toWord64X: int -> Primitive.Word64.word
+      val sextdFromIntInfToInt8: Primitive.IntInf.int -> Primitive.Int8.int
+      val sextdFromIntInfToInt16: Primitive.IntInf.int -> Primitive.Int16.int
+      val sextdFromIntInfToInt32: Primitive.IntInf.int -> Primitive.Int32.int
+      val sextdFromIntInfToInt64: Primitive.IntInf.int -> Primitive.Int64.int
+      val sextdFromIntInfToIntInf: Primitive.IntInf.int -> Primitive.IntInf.int
+      val sextdFromIntInfToWord8: Primitive.IntInf.int -> Primitive.Word8.word
+      val sextdFromIntInfToWord16: Primitive.IntInf.int -> Primitive.Word16.word
+      val sextdFromIntInfToWord32: Primitive.IntInf.int -> Primitive.Word32.word
+      val sextdFromIntInfToWord64: Primitive.IntInf.int -> Primitive.Word64.word
+
+
+      val castFromInt8ToIntInf: Primitive.Int8.int -> Primitive.IntInf.int
+      val castFromInt16ToIntInf: Primitive.Int16.int -> Primitive.IntInf.int
+      val castFromInt32ToIntInf: Primitive.Int32.int -> Primitive.IntInf.int
+      val castFromInt64ToIntInf: Primitive.Int64.int -> Primitive.IntInf.int
+      val castFromWord8ToIntInf: Primitive.Word8.word -> Primitive.IntInf.int
+      val castFromWord16ToIntInf: Primitive.Word16.word -> Primitive.IntInf.int
+      val castFromWord32ToIntInf: Primitive.Word32.word -> Primitive.IntInf.int
+      val castFromWord64ToIntInf: Primitive.Word64.word -> Primitive.IntInf.int
+
+      val castFromIntInfToInt8: Primitive.IntInf.int -> Primitive.Int8.int
+      val castFromIntInfToInt16: Primitive.IntInf.int -> Primitive.Int16.int
+      val castFromIntInfToInt32: Primitive.IntInf.int -> Primitive.Int32.int
+      val castFromIntInfToInt64: Primitive.IntInf.int -> Primitive.Int64.int
+      val castFromIntInfToIntInf: Primitive.IntInf.int -> Primitive.IntInf.int
+      val castFromIntInfToWord8: Primitive.IntInf.int -> Primitive.Word8.word
+      val castFromIntInfToWord16: Primitive.IntInf.int -> Primitive.Word16.word
+      val castFromIntInfToWord32: Primitive.IntInf.int -> Primitive.Word32.word
+      val castFromIntInfToWord64: Primitive.IntInf.int -> Primitive.Word64.word
+
+
+      val zchckFromInt8ToIntInf: Primitive.Int8.int -> Primitive.IntInf.int
+      val zchckFromInt16ToIntInf: Primitive.Int16.int -> Primitive.IntInf.int
+      val zchckFromInt32ToIntInf: Primitive.Int32.int -> Primitive.IntInf.int
+      val zchckFromInt64ToIntInf: Primitive.Int64.int -> Primitive.IntInf.int
+      val zchckFromWord8ToIntInf: Primitive.Word8.word -> Primitive.IntInf.int
+      val zchckFromWord16ToIntInf: Primitive.Word16.word -> Primitive.IntInf.int
+      val zchckFromWord32ToIntInf: Primitive.Word32.word -> Primitive.IntInf.int
+      val zchckFromWord64ToIntInf: Primitive.Word64.word -> Primitive.IntInf.int
+
+      val zchckFromIntInfToInt8: Primitive.IntInf.int -> Primitive.Int8.int
+      val zchckFromIntInfToInt16: Primitive.IntInf.int -> Primitive.Int16.int
+      val zchckFromIntInfToInt32: Primitive.IntInf.int -> Primitive.Int32.int
+      val zchckFromIntInfToInt64: Primitive.IntInf.int -> Primitive.Int64.int
+      val zchckFromIntInfToIntInf: Primitive.IntInf.int -> Primitive.IntInf.int
+      val zchckFromIntInfToWord8: Primitive.IntInf.int -> Primitive.Word8.word
+      val zchckFromIntInfToWord16: Primitive.IntInf.int -> Primitive.Word16.word
+      val zchckFromIntInfToWord32: Primitive.IntInf.int -> Primitive.Word32.word
+      val zchckFromIntInfToWord64: Primitive.IntInf.int -> Primitive.Word64.word
+
+
+      val schckFromInt8ToIntInf: Primitive.Int8.int -> Primitive.IntInf.int
+      val schckFromInt16ToIntInf: Primitive.Int16.int -> Primitive.IntInf.int
+      val schckFromInt32ToIntInf: Primitive.Int32.int -> Primitive.IntInf.int
+      val schckFromInt64ToIntInf: Primitive.Int64.int -> Primitive.IntInf.int
+      val schckFromWord8ToIntInf: Primitive.Word8.word -> Primitive.IntInf.int
+      val schckFromWord16ToIntInf: Primitive.Word16.word -> Primitive.IntInf.int
+      val schckFromWord32ToIntInf: Primitive.Word32.word -> Primitive.IntInf.int
+      val schckFromWord64ToIntInf: Primitive.Word64.word -> Primitive.IntInf.int
+
+      val schckFromIntInfToInt8: Primitive.IntInf.int -> Primitive.Int8.int
+      val schckFromIntInfToInt16: Primitive.IntInf.int -> Primitive.Int16.int
+      val schckFromIntInfToInt32: Primitive.IntInf.int -> Primitive.Int32.int
+      val schckFromIntInfToInt64: Primitive.IntInf.int -> Primitive.Int64.int
+      val schckFromIntInfToIntInf: Primitive.IntInf.int -> Primitive.IntInf.int
+      val schckFromIntInfToWord8: Primitive.IntInf.int -> Primitive.Word8.word
+      val schckFromIntInfToWord16: Primitive.IntInf.int -> Primitive.Word16.word
+      val schckFromIntInfToWord32: Primitive.IntInf.int -> Primitive.Word32.word
+      val schckFromIntInfToWord64: Primitive.IntInf.int -> Primitive.Word64.word
    end
+signature PRIM_INTEGER =
+   sig
+      include PRIM_INTEGER
 
+      val zextdFromIntInf: Primitive.IntInf.int -> int
+      val zextdToIntInf: int -> Primitive.IntInf.int
+
+      val sextdFromIntInf: Primitive.IntInf.int -> int
+      val sextdToIntInf: int -> Primitive.IntInf.int
+
+      val castFromIntInf: Primitive.IntInf.int -> int
+      val castToIntInf: int -> Primitive.IntInf.int
+
+      val zchckFromIntInf: Primitive.IntInf.int -> int
+      val zchckToIntInf: int -> Primitive.IntInf.int
+
+      val schckFromIntInf: Primitive.IntInf.int -> int
+      val schckToIntInf: int -> Primitive.IntInf.int
+   end
+signature PRIM_WORD =
+   sig
+      include PRIM_WORD
+
+      val zextdFromIntInf: Primitive.IntInf.int -> word
+      val zextdToIntInf: word -> Primitive.IntInf.int
+
+      val sextdFromIntInf: Primitive.IntInf.int -> word
+      val sextdToIntInf: word -> Primitive.IntInf.int
+
+      val castFromIntInf: Primitive.IntInf.int -> word
+      val castToIntInf: word -> Primitive.IntInf.int
+
+      val zchckFromIntInf: Primitive.IntInf.int -> word
+      val zchckToIntInf: word -> Primitive.IntInf.int
+
+      val schckFromIntInf: Primitive.IntInf.int -> word
+      val schckToIntInf: word -> Primitive.IntInf.int
+   end
+
 structure Primitive = struct
 
 open Primitive
 
-structure IntInf : INT_INF0 =
+structure IntInf =
    struct
       structure Prim = Primitive.IntInf
 
@@ -177,35 +342,24 @@
                           structure S =
                              ObjptrInt_ChooseIntN
                              (type 'a t = 'a -> ObjptrWord.word
-                              val fInt8 = ObjptrWord.fromInt8
-                              val fInt16 = ObjptrWord.fromInt16
-                              val fInt32 = ObjptrWord.fromInt32
-                              val fInt64 = ObjptrWord.fromInt64)
+                              val fInt8 = ObjptrWord.zextdFromInt8
+                              val fInt16 = ObjptrWord.zextdFromInt16
+                              val fInt32 = ObjptrWord.zextdFromInt32
+                              val fInt64 = ObjptrWord.zextdFromInt64)
                        in
-                          val fromObjptrInt = S.f
+                          val idFromObjptrInt = S.f
                        end
                        local
                           structure S =
                              ObjptrInt_ChooseIntN
                              (type 'a t = ObjptrWord.word -> 'a
-                              val fInt8 = ObjptrWord.toInt8
-                              val fInt16 = ObjptrWord.toInt16
-                              val fInt32 = ObjptrWord.toInt32
-                              val fInt64 = ObjptrWord.toInt64)
+                              val fInt8 = ObjptrWord.zextdToInt8
+                              val fInt16 = ObjptrWord.zextdToInt16
+                              val fInt32 = ObjptrWord.zextdToInt32
+                              val fInt64 = ObjptrWord.zextdToInt64)
                        in
-                          val toObjptrInt = S.f
+                          val idToObjptrInt = S.f
                        end
-                       local
-                          structure S =
-                             ObjptrInt_ChooseIntN
-                             (type 'a t = ObjptrWord.word -> 'a
-                              val fInt8 = ObjptrWord.toInt8X
-                              val fInt16 = ObjptrWord.toInt16X
-                              val fInt32 = ObjptrWord.toInt32X
-                              val fInt64 = ObjptrWord.toInt64X)
-                       in
-                          val toObjptrIntX = S.f
-                       end
                     end
       structure I = ObjptrInt
       structure MPLimb = C_MPLimb
@@ -215,13 +369,24 @@
                            structure S =
                               SeqIndex_ChooseIntN
                               (type 'a t = 'a -> C_Size.word
-                               val fInt8 = C_Size.fromInt8
-                               val fInt16 = C_Size.fromInt16
-                               val fInt32 = C_Size.fromInt32
-                               val fInt64 = C_Size.fromInt64)
+                               val fInt8 = C_Size.zextdFromInt8
+                               val fInt16 = C_Size.zextdFromInt16
+                               val fInt32 = C_Size.zextdFromInt32
+                               val fInt64 = C_Size.zextdFromInt64)
                         in
-                           val fromSeqIndex = S.f
+                           val zextdFromSeqIndex = S.f
                         end
+                        local
+                           structure S =
+                              SeqIndex_ChooseIntN
+                              (type 'a t = 'a -> C_Size.word
+                               val fInt8 = C_Size.sextdFromInt8
+                               val fInt16 = C_Size.sextdFromInt16
+                               val fInt32 = C_Size.sextdFromInt32
+                               val fInt64 = C_Size.sextdFromInt64)
+                        in
+                           val sextdFromSeqIndex = S.f
+                        end
                      end
 
       type bigInt = Prim.int
@@ -248,12 +413,12 @@
             then 1
             else bigNumLimbs i
 
-      fun dropTag (w: W.word): W.word = W.~>> (w, 0w1)
+      fun dropTag (w: W.word): W.word = W.~>>? (w, 0w1)
       fun dropTagCoerce (i: bigInt): W.word = dropTag (Prim.toWord i)
-      fun dropTagCoerceInt (i: bigInt): I.int = W.toObjptrIntX (dropTagCoerce i)
-      fun addTag (w: W.word): W.word = W.orb (W.<< (w, 0w1), 0w1)
+      fun dropTagCoerceInt (i: bigInt): I.int = W.idToObjptrInt (dropTagCoerce i)
+      fun addTag (w: W.word): W.word = W.orb (W.<<? (w, 0w1), 0w1)
       fun addTagCoerce (w: W.word): bigInt = Prim.fromWord (addTag w)
-      fun addTagCoerceInt (i: I.int): bigInt = addTagCoerce (W.fromObjptrInt i)
+      fun addTagCoerceInt (i: I.int): bigInt = addTagCoerce (W.idFromObjptrInt i)
       fun zeroTag (w: W.word): W.word = W.andb (w, W.notb 0w1)
       fun oneTag (w: W.word): W.word = W.orb (w, 0w1)
       fun oneTagCoerce (w: W.word): bigInt = Prim.fromWord (oneTag w)
@@ -264,42 +429,47 @@
             else Big (Prim.toVector i)
 
       local
-         fun 'a make {toMPLimb: 'a -> MPLimb.word,
-                      toObjptrWordX: 'a -> ObjptrWord.word,
-                      other : {wordSize: Int32.int,
+         fun 'a make {zextdToMPLimb: 'a -> MPLimb.word,
+                      zextdToObjptrWord: 'a -> ObjptrWord.word,
+                      sextdToObjptrWord: 'a -> ObjptrWord.word,
+                      other : {sizeInBits: Int32.int,
                                zero: 'a,
                                eq: 'a * 'a -> bool,
+                               isNeg: 'a -> bool,
                                neg: 'a -> 'a,
                                notb: 'a -> 'a,
-                               rshift: 'a * Word32.word -> 'a}} 
-                     (isneg, w) =
-            if Int32.> (ObjptrWord.wordSize, #wordSize other)
+                               rashift: 'a * Word32.word -> 'a,
+                               rshift: 'a * Word32.word -> 'a}}
+                     (sextd, w) =
+            if Int32.> (ObjptrWord.sizeInBits, #sizeInBits other)
                orelse let
-                         val shift = Word32.- (ObjptrWord.wordSizeWord, 0w2)
-                         val upperBits = (#rshift other) (w, shift)
-                         val upperZeroBits = #zero other
-                         val upperOneBits = (#rshift other) ((#notb other) (#zero other), shift)
+                         val shift = Word32.- (ObjptrWord.sizeInBitsWord, 0w2)
+                         val upperBits = (#rashift other) (w, shift)
+                         val zeroBits = #zero other
+                         val oneBits = (#notb other) zeroBits
                       in
-                         (#eq other) (upperBits, upperZeroBits)
+                         (#eq other) (upperBits, zeroBits)
                          orelse
-                         (isneg andalso (#eq other) (upperBits, upperOneBits))
+                         (sextd andalso (#eq other) (upperBits, oneBits))
                       end
-               then Prim.fromWord (addTag (toObjptrWordX w))
+               then if sextd
+                       then Prim.fromWord (addTag (sextdToObjptrWord w))
+                       else Prim.fromWord (addTag (zextdToObjptrWord w))
                else let
                        fun loop (w, i, acc) =
                           if (#eq other) (w, (#zero other))
                              then (i, acc)
                              else 
                                 let
-                                   val limb = toMPLimb w
+                                   val limb = zextdToMPLimb w
                                    val w = 
                                       (#rshift other) 
-                                      (w, MPLimb.wordSizeWord)
+                                      (w, MPLimb.sizeInBitsWord)
                                 in
                                    loop (w, S.+ (i, 1), (i, limb) :: acc)
                                 end
                        val (n, acc) = 
-                          if isneg 
+                          if sextd andalso (#isNeg other) w
                              then loop ((#neg other) w, 1, [(0,0w1)])
                              else loop (w, 1, [(0,0w0)])
                        val a = A.arrayUnsafe n
@@ -313,93 +483,128 @@
                        Prim.fromVector (V.fromArray a)
                     end
       in
-         val fromWordAux8 =
-            make {toMPLimb = MPLimb.fromWord8,
-                  toObjptrWordX = ObjptrWord.fromWord8X,
-                  other = {wordSize = Word8.wordSize,
+         fun extdFromWord8 (sextd, w) =
+            make {zextdToMPLimb = MPLimb.zextdFromWord8,
+                  zextdToObjptrWord = ObjptrWord.zextdFromWord8,
+                  sextdToObjptrWord = ObjptrWord.sextdFromWord8,
+                  other = {sizeInBits = Word8.sizeInBits,
                            zero = Word8.zero,
                            eq = ((op =) : Word8.word * Word8.word -> bool),
+                           isNeg = fn w => Int8.< (IntWordConv.idFromWord8ToInt8 w, 0),
                            neg = Word8.~,
                            notb = Word8.notb,
-                           rshift = Word8.>>}}
-         fun fromWord8 w = fromWordAux8 (false, w)
-         fun fromInt8 i = fromWordAux8 (Int8.< (i, 0), Word8.fromInt8 i)
-         fun fromWord8X w = fromInt8 (Word8.toInt8X w)
-         val fromInt8Unsafe = fromInt8
-         val fromWord8Unsafe = fromWord8
-         val fromWord8XUnsafe = fromWord8X
+                           rashift = Word8.~>>?,
+                           rshift = Word8.>>?}}
+                 (sextd, w)
+         fun zextdFromWord8 w = extdFromWord8 (false, w)
+         fun zextdFromInt8 i = zextdFromWord8 (IntWordConv.idFromInt8ToWord8 i)
+         fun sextdFromWord8 w = extdFromWord8 (true, w)
+         fun sextdFromInt8 i = sextdFromWord8 (IntWordConv.idFromInt8ToWord8 i)
+         val castFromInt8 = sextdFromInt8
+         val castFromWord8 = zextdFromWord8
+         val zchckFromInt8 = zextdFromInt8
+         val zchckFromWord8 = zextdFromWord8
+         val schckFromInt8 = sextdFromInt8
+         val schckFromWord8 = sextdFromWord8
 
-         val fromWordAux16 =
-            make {toMPLimb = MPLimb.fromWord16,
-                  toObjptrWordX = ObjptrWord.fromWord16X,
-                  other = {wordSize = Word16.wordSize,
+         fun extdFromWord16 (sextd, w) =
+            make {zextdToMPLimb = MPLimb.zextdFromWord16,
+                  zextdToObjptrWord = ObjptrWord.zextdFromWord16,
+                  sextdToObjptrWord = ObjptrWord.sextdFromWord16,
+                  other = {sizeInBits = Word16.sizeInBits,
                            zero = Word16.zero,
                            eq = ((op =) : Word16.word * Word16.word -> bool),
+                           isNeg = fn w => Int16.< (IntWordConv.idFromWord16ToInt16 w, 0),
                            neg = Word16.~,
                            notb = Word16.notb,
-                           rshift = Word16.>>}}
-         fun fromWord16 w = fromWordAux16 (false, w)
-         fun fromInt16 i = fromWordAux16 (Int16.< (i, 0), Word16.fromInt16 i)
-         fun fromWord16X w = fromInt16 (Word16.toInt16X w)
-         val fromInt16Unsafe = fromInt16
-         val fromWord16Unsafe = fromWord16
-         val fromWord16XUnsafe = fromWord16X
+                           rashift = Word16.~>>?,
+                           rshift = Word16.>>?}}
+                 (sextd, w)
+         fun zextdFromWord16 w = extdFromWord16 (false, w)
+         fun zextdFromInt16 i = zextdFromWord16 (IntWordConv.idFromInt16ToWord16 i)
+         fun sextdFromWord16 w = extdFromWord16 (true, w)
+         fun sextdFromInt16 i = sextdFromWord16 (IntWordConv.idFromInt16ToWord16 i)
+         val castFromInt16 = sextdFromInt16
+         val castFromWord16 = zextdFromWord16
+         val zchckFromInt16 = zextdFromInt16
+         val zchckFromWord16 = zextdFromWord16
+         val schckFromInt16 = sextdFromInt16
+         val schckFromWord16 = sextdFromWord16
 
-         val fromWordAux32 =
-            make {toMPLimb = MPLimb.fromWord32,
-                  toObjptrWordX = ObjptrWord.fromWord32X,
-                  other = {wordSize = Word32.wordSize,
+         fun extdFromWord32 (sextd, w) =
+            make {zextdToMPLimb = MPLimb.zextdFromWord32,
+                  zextdToObjptrWord = ObjptrWord.zextdFromWord32,
+                  sextdToObjptrWord = ObjptrWord.sextdFromWord32,
+                  other = {sizeInBits = Word32.sizeInBits,
                            zero = Word32.zero,
                            eq = ((op =) : Word32.word * Word32.word -> bool),
+                           isNeg = fn w => Int32.< (IntWordConv.idFromWord32ToInt32 w, 0),
                            neg = Word32.~,
                            notb = Word32.notb,
-                           rshift = Word32.>>}}
-         fun fromWord32 w = fromWordAux32 (false, w)
-         fun fromInt32 i = fromWordAux32 (Int32.< (i, 0), Word32.fromInt32 i)
-         fun fromWord32X w = fromInt32 (Word32.toInt32X w)
-         val fromInt32Unsafe = fromInt32
-         val fromWord32Unsafe = fromWord32
-         val fromWord32XUnsafe = fromWord32X
+                           rashift = Word32.~>>?,
+                           rshift = Word32.>>?}}
+                 (sextd, w)
+         fun zextdFromWord32 w = extdFromWord32 (false, w)
+         fun zextdFromInt32 i = zextdFromWord32 (IntWordConv.idFromInt32ToWord32 i)
+         fun sextdFromWord32 w = extdFromWord32 (true, w)
+         fun sextdFromInt32 i = sextdFromWord32 (IntWordConv.idFromInt32ToWord32 i)
+         val castFromInt32 = sextdFromInt32
+         val castFromWord32 = zextdFromWord32
+         val zchckFromInt32 = zextdFromInt32
+         val zchckFromWord32 = zextdFromWord32
+         val schckFromInt32 = sextdFromInt32
+         val schckFromWord32 = sextdFromWord32
 
-         val fromWordAux64 =
-            make {toMPLimb = MPLimb.fromWord64,
-                  toObjptrWordX = ObjptrWord.fromWord64X,
-                  other = {wordSize = Word64.wordSize,
+         fun extdFromWord64 (sextd, w) =
+            make {zextdToMPLimb = MPLimb.zextdFromWord64,
+                  zextdToObjptrWord = ObjptrWord.zextdFromWord64,
+                  sextdToObjptrWord = ObjptrWord.sextdFromWord64,
+                  other = {sizeInBits = Word64.sizeInBits,
                            zero = Word64.zero,
                            eq = ((op =) : Word64.word * Word64.word -> bool),
+                           isNeg = fn w => Int64.< (IntWordConv.idFromWord64ToInt64 w, 0),
                            neg = Word64.~,
                            notb = Word64.notb,
-                           rshift = Word64.>>}}
-         fun fromWord64 w = fromWordAux64 (false, w)
-         fun fromInt64 i = fromWordAux64 (Int64.< (i, 0), Word64.fromInt64 i)
-         fun fromWord64X w = fromInt64 (Word64.toInt64X w)
-         val fromInt64Unsafe = fromInt64
-         val fromWord64Unsafe = fromWord64
-         val fromWord64XUnsafe = fromWord64X
+                           rashift = Word64.~>>?,
+                           rshift = Word64.>>?}}
+                 (sextd, w)
+         fun zextdFromWord64 w = extdFromWord64 (false, w)
+         fun zextdFromInt64 i = zextdFromWord64 (IntWordConv.idFromInt64ToWord64 i)
+         fun sextdFromWord64 w = extdFromWord64 (true, w)
+         fun sextdFromInt64 i = sextdFromWord64 (IntWordConv.idFromInt64ToWord64 i)
+         val castFromInt64 = sextdFromInt64
+         val castFromWord64 = zextdFromWord64
+         val zchckFromInt64 = zextdFromInt64
+         val zchckFromWord64 = zextdFromWord64
+         val schckFromInt64 = sextdFromInt64
+         val schckFromWord64 = sextdFromWord64
 
-         fun fromIntInf i = i
-         fun fromIntInfUnsafe i = i
+         fun zextdFromIntInf ii = ii
+         fun sextdFromIntInf ii = ii
+         fun castFromIntInf ii = ii
+         fun zchckFromIntInf ii = ii
+         fun schckFromIntInf ii = ii
       end
 
       local
          structure S =
             ObjptrInt_ChooseIntN
             (type 'a t = 'a -> bigInt
-             val fInt8 = fromInt8
-             val fInt16 = fromInt16
-             val fInt32 = fromInt32
-             val fInt64 = fromInt64)
+             val fInt8 = sextdFromInt8
+             val fInt16 = sextdFromInt16
+             val fInt32 = sextdFromInt32
+             val fInt64 = sextdFromInt64)
       in
-         val fromObjptrInt = S.f
+         val sextdFromObjptrInt = S.f
       end
 
       local
          datatype 'a ans =
             Big of bool * bool * 'a
           | Small of ObjptrWord.word
-         fun 'a make {fromMPLimb: MPLimb.word -> 'a,
-                      other : {wordSize: Int32.int,
-                               wordSizeWord: Word32.word,
+         fun 'a make {zextdFromMPLimb: MPLimb.word -> 'a,
+                      other : {sizeInBits: Int32.int,
+                               sizeInBitsWord: Word32.word,
                                zero: 'a,
                                lshift: 'a * Word32.word -> 'a,
                                orb: 'a * 'a -> 'a}} i =
@@ -410,24 +615,24 @@
                        val n = V.length v
                        val isneg = V.subUnsafe (v, 0) <> 0w0
                     in
-                       if Int32.>= (MPLimb.wordSize, #wordSize other) 
+                       if Int32.>= (MPLimb.sizeInBits, #sizeInBits other) 
                           then let
                                   val limbsPer = 1
                                   val limb = V.subUnsafe (v, 1)
                                   val extra =
                                      S.> (n, S.+ (limbsPer, 1))
                                      orelse
-                                     (MPLimb.>> (limb, #wordSizeWord other)) <> 0w0
-                                  val ans = fromMPLimb limb
+                                     (MPLimb.>>? (limb, #sizeInBitsWord other)) <> 0w0
+                                  val ans = zextdFromMPLimb limb
                                in
                                   Big (isneg, extra, ans)
                                end
                           else let
                                   val limbsPer =
-                                     S.fromInt32 (Int32.quot (#wordSize other, 
-                                                              MPLimb.wordSize))
-                                  val extra =
-                                     S.> (n, S.+ (limbsPer, 1))
+                                     S.sextdFromInt32
+                                     (Int32.quot (#sizeInBits other,
+                                                  MPLimb.sizeInBits))
+                                  val extra = S.> (n, S.+ (limbsPer, 1))
                                   val ans =
                                      let
                                         fun loop (i, ans) =
@@ -437,8 +642,8 @@
                                                       val ans = 
                                                          (#orb other) 
                                                          ((#lshift other) 
-                                                          (ans, MPLimb.wordSizeWord),
-                                                          fromMPLimb limb)
+                                                          (ans, MPLimb.sizeInBitsWord),
+                                                          zextdFromMPLimb limb)
                                                    in
                                                       loop (S.- (i, 1), ans)
                                                    end
@@ -451,149 +656,223 @@
                                end
                     end
       in
-         val toWordAux8 =
-            make {fromMPLimb = MPLimb.toWord8,
-                  other = {wordSize = Word8.wordSize,
-                           wordSizeWord = Word8.wordSizeWord,
+         val chckToWord8Aux =
+            make {zextdFromMPLimb = MPLimb.zextdToWord8,
+                  other = {sizeInBits = Word8.sizeInBits,
+                           sizeInBitsWord = Word8.sizeInBitsWord,
                            zero = Word8.zero,
-                           lshift = Word8.<<,
+                           lshift = Word8.<<?,
                            orb = Word8.orb}}
-         fun toWord8X i =
-            case toWordAux8 i of
-               Small w => ObjptrWord.toWord8X w
+         fun sextdToWord8 i =
+            case chckToWord8Aux i of
+               Small w => ObjptrWord.sextdToWord8 w
              | Big (isneg, _, ans) => if isneg then Word8.~ ans else ans
-         fun toWord8 i = toWord8X i
-         fun toInt8 i =
-            case toWordAux8 i of
-               Small w => ObjptrWord.toInt8X w
-             | Big (isneg, extra, ans) =>
+         fun sextdToInt8 i = IntWordConv.idFromWord8ToInt8 (sextdToWord8 i)
+         val zextdToWord8 = sextdToWord8
+         fun zextdToInt8 i = IntWordConv.idFromWord8ToInt8 (zextdToWord8 i)
+         val castToWord8 = sextdToWord8
+         val castToInt8 = sextdToInt8
+         fun schckToWord8 i =
+            case chckToWord8Aux i of
+               Small w => ObjptrWord.schckToWord8 w
+             | Big (isneg, extra, ans) => 
                   if extra
                      then raise Overflow
                   else if isneg
                      then let
-                             val ans = Word8.toInt8X (Word8.~ ans)
-                          in
-                             if Int8.>= (ans, 0)
+                             val ans = Word8.~ ans
+                             val ans' = IntWordConv.idFromWord8ToInt8 ans
+                          in 
+                             if Int8.> (ans', 0)
                                 then raise Overflow
                                 else ans
                           end
-                  else Word8.toInt8 ans
-         val toWord8Unsafe = toWord8
-         val toWord8XUnsafe = toWord8X
-         fun toInt8Unsafe i = Word8.toInt8X (toWord8X i)
+                  else let
+                          val ans' = IntWordConv.idFromWord8ToInt8 ans
+                       in
+                          if Int8.< (ans', 0)
+                             then raise Overflow
+                             else ans
+                       end
+         fun schckToInt8 i = IntWordConv.idFromWord8ToInt8 (schckToWord8 i)
+         fun zchckToWord8 i =
+            case chckToWord8Aux i of
+               Small w => ObjptrWord.schckToWord8 w
+             | Big (isneg, extra, ans) => 
+                  if isneg orelse extra
+                     then raise Overflow
+                  else ans
+         fun zchckToInt8 i = IntWordConv.idFromWord8ToInt8 (zchckToWord8 i)
 
-         val toWordAux16 =
-            make {fromMPLimb = MPLimb.toWord16,
-                  other = {wordSize = Word16.wordSize,
-                           wordSizeWord = Word16.wordSizeWord,
+         val chckToWord16Aux =
+            make {zextdFromMPLimb = MPLimb.zextdToWord16,
+                  other = {sizeInBits = Word16.sizeInBits,
+                           sizeInBitsWord = Word16.sizeInBitsWord,
                            zero = Word16.zero,
-                           lshift = Word16.<<,
+                           lshift = Word16.<<?,
                            orb = Word16.orb}}
-         fun toWord16X i =
-            case toWordAux16 i of
-               Small w => ObjptrWord.toWord16X w
+         fun sextdToWord16 i =
+            case chckToWord16Aux i of
+               Small w => ObjptrWord.sextdToWord16 w
              | Big (isneg, _, ans) => if isneg then Word16.~ ans else ans
-         fun toWord16 i = toWord16X i
-         fun toInt16 i =
-            case toWordAux16 i of
-               Small w => ObjptrWord.toInt16X w
-             | Big (isneg, extra, ans) =>
+         fun sextdToInt16 i = IntWordConv.idFromWord16ToInt16 (sextdToWord16 i)
+         val zextdToWord16 = sextdToWord16
+         fun zextdToInt16 i = IntWordConv.idFromWord16ToInt16 (zextdToWord16 i)
+         val castToWord16 = sextdToWord16
+         val castToInt16 = sextdToInt16
+         fun schckToWord16 i =
+            case chckToWord16Aux i of
+               Small w => ObjptrWord.schckToWord16 w
+             | Big (isneg, extra, ans) => 
                   if extra
                      then raise Overflow
                   else if isneg
                      then let
-                             val ans = Word16.toInt16X (Word16.~ ans)
-                          in
-                             if Int16.>= (ans, 0)
+                             val ans = Word16.~ ans
+                             val ans' = IntWordConv.idFromWord16ToInt16 ans
+                          in 
+                             if Int16.> (ans', 0)
                                 then raise Overflow
                                 else ans
                           end
-                  else Word16.toInt16 ans
-         val toWord16Unsafe = toWord16
-         val toWord16XUnsafe = toWord16X
-         fun toInt16Unsafe i = Word16.toInt16X (toWord16X i)
-                           
-         val toWordAux32 =
-            make {fromMPLimb = MPLimb.toWord32,
-                  other = {wordSize = Word32.wordSize,
-                           wordSizeWord = Word32.wordSizeWord,
+                  else let
+                          val ans' = IntWordConv.idFromWord16ToInt16 ans
+                       in
+                          if Int16.< (ans', 0)
+                             then raise Overflow
+                             else ans
+                       end
+         fun schckToInt16 i = IntWordConv.idFromWord16ToInt16 (schckToWord16 i)
+         fun zchckToWord16 i =
+            case chckToWord16Aux i of
+               Small w => ObjptrWord.schckToWord16 w
+             | Big (isneg, extra, ans) => 
+                  if isneg orelse extra
+                     then raise Overflow
+                  else ans
+         fun zchckToInt16 i = IntWordConv.idFromWord16ToInt16 (zchckToWord16 i)
+
+         val chckToWord32Aux =
+            make {zextdFromMPLimb = MPLimb.zextdToWord32,
+                  other = {sizeInBits = Word32.sizeInBits,
+                           sizeInBitsWord = Word32.sizeInBitsWord,
                            zero = Word32.zero,
-                           lshift = Word32.<<,
+                           lshift = Word32.<<?,
                            orb = Word32.orb}}
-         fun toWord32X i =
-            case toWordAux32 i of
-               Small w => ObjptrWord.toWord32X w
+         fun sextdToWord32 i =
+            case chckToWord32Aux i of
+               Small w => ObjptrWord.sextdToWord32 w
              | Big (isneg, _, ans) => if isneg then Word32.~ ans else ans
-         fun toWord32 i = toWord32X i
-         fun toInt32 i =
-            case toWordAux32 i of
-               Small w => ObjptrWord.toInt32X w
-             | Big (isneg, extra, ans) =>
+         fun sextdToInt32 i = IntWordConv.idFromWord32ToInt32 (sextdToWord32 i)
+         val zextdToWord32 = sextdToWord32
+         fun zextdToInt32 i = IntWordConv.idFromWord32ToInt32 (zextdToWord32 i)
+         val castToWord32 = sextdToWord32
+         val castToInt32 = sextdToInt32
+         fun schckToWord32 i =
+            case chckToWord32Aux i of
+               Small w => ObjptrWord.schckToWord32 w
+             | Big (isneg, extra, ans) => 
                   if extra
                      then raise Overflow
                   else if isneg
                      then let
-                             val ans = Word32.toInt32X (Word32.~ ans)
-                          in
-                             if Int32.>= (ans, 0)
+                             val ans = Word32.~ ans
+                             val ans' = IntWordConv.idFromWord32ToInt32 ans
+                          in 
+                             if Int32.> (ans', 0)
                                 then raise Overflow
                                 else ans
                           end
-                  else Word32.toInt32 ans
-         val toWord32Unsafe = toWord32
-         val toWord32XUnsafe = toWord32X
-         fun toInt32Unsafe i = Word32.toInt32X (toWord32X i)
+                  else let
+                          val ans' = IntWordConv.idFromWord32ToInt32 ans
+                       in
+                          if Int32.< (ans', 0)
+                             then raise Overflow
+                             else ans
+                       end
+         fun schckToInt32 i = IntWordConv.idFromWord32ToInt32 (schckToWord32 i)
+         fun zchckToWord32 i =
+            case chckToWord32Aux i of
+               Small w => ObjptrWord.schckToWord32 w
+             | Big (isneg, extra, ans) => 
+                  if isneg orelse extra
+                     then raise Overflow
+                  else ans
+         fun zchckToInt32 i = IntWordConv.idFromWord32ToInt32 (zchckToWord32 i)
 
-         val toWordAux64 =
-            make {fromMPLimb = MPLimb.toWord64,
-                  other = {wordSize = Word64.wordSize,
-                           wordSizeWord = Word64.wordSizeWord,
+         val chckToWord64Aux =
+            make {zextdFromMPLimb = MPLimb.zextdToWord64,
+                  other = {sizeInBits = Word64.sizeInBits,
+                           sizeInBitsWord = Word64.sizeInBitsWord,
                            zero = Word64.zero,
-                           lshift = Word64.<<,
+                           lshift = Word64.<<?,
                            orb = Word64.orb}}
-         fun toWord64X i =
-            case toWordAux64 i of
-               Small w => ObjptrWord.toWord64X w
+         fun sextdToWord64 i =
+            case chckToWord64Aux i of
+               Small w => ObjptrWord.sextdToWord64 w
              | Big (isneg, _, ans) => if isneg then Word64.~ ans else ans
-         fun toWord64 i = toWord64X i
-         fun toInt64 i =
-            case toWordAux64 i of
-               Small w => ObjptrWord.toInt64X w
-             | Big (isneg, extra, ans) =>
+         fun sextdToInt64 i = IntWordConv.idFromWord64ToInt64 (sextdToWord64 i)
+         val zextdToWord64 = sextdToWord64
+         fun zextdToInt64 i = IntWordConv.idFromWord64ToInt64 (zextdToWord64 i)
+         val castToWord64 = sextdToWord64
+         val castToInt64 = sextdToInt64
+         fun schckToWord64 i =
+            case chckToWord64Aux i of
+               Small w => ObjptrWord.schckToWord64 w
+             | Big (isneg, extra, ans) => 
                   if extra
                      then raise Overflow
                   else if isneg
                      then let
-                             val ans = Word64.toInt64X (Word64.~ ans)
-                          in
-                             if Int64.>= (ans, 0)
+                             val ans = Word64.~ ans
+                             val ans' = IntWordConv.idFromWord64ToInt64 ans
+                          in 
+                             if Int64.> (ans', 0)
                                 then raise Overflow
                                 else ans
                           end
-                  else Word64.toInt64 ans
-         val toWord64Unsafe = toWord64
-         val toWord64XUnsafe = toWord64X
-         fun toInt64Unsafe i = Word64.toInt64X (toWord64X i)
+                  else let
+                          val ans' = IntWordConv.idFromWord64ToInt64 ans
+                       in
+                          if Int64.< (ans', 0)
+                             then raise Overflow
+                             else ans
+                       end
+         fun schckToInt64 i = IntWordConv.idFromWord64ToInt64 (schckToWord64 i)
+         fun zchckToWord64 i =
+            case chckToWord64Aux i of
+               Small w => ObjptrWord.schckToWord64 w
+             | Big (isneg, extra, ans) => 
+                  if isneg orelse extra
+                     then raise Overflow
+                  else ans
+         fun zchckToInt64 i = IntWordConv.idFromWord64ToInt64 (zchckToWord64 i)
 
-         fun toIntInf i = i
-         fun toIntInfUnsafe i = i
+         fun zextdToIntInf ii = ii
+         fun sextdToIntInf ii = ii
+         fun castToIntInf ii = ii
+         fun zchckToIntInf ii = ii
+         fun schckToIntInf ii = ii
       end
 
       local
-         val bytesPerMPLimb = Sz.fromInt32 (Int32.quot (MPLimb.wordSize, 8))
-         val bytesPerCounter = Sz.fromInt32 (Int32.quot (S.precision', 8))
-         val bytesPerLength = Sz.fromInt32 (Int32.quot (S.precision', 8))
-         val bytesPerHeader = Sz.fromInt32 (Int32.quot (HeaderWord.wordSize, 8))
+         val bytesPerMPLimb = Sz.zextdFromInt32 (Int32.quot (MPLimb.sizeInBits, 8))
+         val bytesPerCounter = Sz.zextdFromInt32 (Int32.quot (S.sizeInBits, 8))
+         val bytesPerLength = Sz.zextdFromInt32 (Int32.quot (S.sizeInBits, 8))
+         val bytesPerHeader = Sz.zextdFromInt32 (Int32.quot (HeaderWord.sizeInBits, 8))
       in
          val bytesPerArrayHeader =
-            Sz.+ (bytesPerCounter, Sz.+ (bytesPerLength, bytesPerHeader))
+            Sz.+ (bytesPerCounter, 
+            Sz.+ (bytesPerLength, 
+                  bytesPerHeader
+            ))
          (* Reserve heap space for a large IntInf.int with room for num + extra
           * `limbs'.  The reason for splitting this up is that extra is intended
           * to be a constant, and so can be combined at compile time.
           *)
          fun reserve (num: S.int, extra: S.int) =
-            Sz.+ (Sz.* (bytesPerMPLimb, Sz.fromSeqIndex num),
-            Sz.+ (Sz.* (bytesPerMPLimb, Sz.fromSeqIndex extra),
+            Sz.+ (Sz.* (bytesPerMPLimb, Sz.zextdFromSeqIndex num),
+            Sz.+ (Sz.* (bytesPerMPLimb, Sz.zextdFromSeqIndex extra),
             Sz.+ (bytesPerMPLimb, (* isneg Field *)
                   bytesPerArrayHeader (* Array Header *)
             )))
@@ -603,16 +882,16 @@
        * negation and absolute values are not fixnums. 
        * negBadIntInf is the negation (and absolute value) of that IntInf.int.
        *)
-      val badObjptrInt: I.int = I.~>> (I.minInt', 0w1)
-      val badObjptrWord: W.word = W.fromObjptrInt badObjptrInt
+      val badObjptrInt: I.int = I.~>>? (I.minInt', 0w1)
+      val badObjptrWord: W.word = W.idFromObjptrInt badObjptrInt
       val badObjptrWordTagged: W.word = addTag badObjptrWord
-      val badObjptrIntTagged: I.int = W.toObjptrIntX badObjptrWordTagged
-      val negBadIntInf: bigInt = fromObjptrInt (I.~ badObjptrInt)
+      val badObjptrIntTagged: I.int = W.idToObjptrInt badObjptrWordTagged
+      val negBadIntInf: bigInt = sextdFromObjptrInt (I.~ badObjptrInt)
 
       (* Given two ObjptrWord.word's, check if they have the same 'high'/'sign' bit.
        *)
       fun sameSignBit (lhs: W.word, rhs: W.word): bool =
-         I.>= (W.toObjptrIntX (W.xorb (lhs, rhs)), 0)
+         I.>= (W.idToObjptrInt (W.xorb (lhs, rhs)), 0)
 
       (* Given a bignum bigint, test if it is (strictly) negative.
        *)
@@ -627,11 +906,11 @@
                   if areSmall (lhs, rhs)
                      then let
                              val lhsw = dropTagCoerce lhs
-                             val lhsi = W.toObjptrIntX lhsw
+                             val lhsi = W.idToObjptrInt lhsw
                              val rhsw = dropTagCoerce rhs
-                             val rhsi = W.toObjptrIntX rhsw
+                             val rhsi = W.idToObjptrInt rhsw
                              val ansi = smallOp (lhsi, rhsi)
-                             val answ = W.fromObjptrInt ansi
+                             val answ = W.idFromObjptrInt ansi
                              val ans = addTag answ
                           in
                              if sameSignBit (ans, answ)
@@ -667,16 +946,16 @@
          if areSmall (num, den)
             then let
                     val numw = dropTagCoerce num
-                    val numi = W.toObjptrIntX numw
+                    val numi = W.idToObjptrInt numw
                     val denw = dropTagCoerce den
-                    val deni = W.toObjptrIntX denw
+                    val deni = W.idToObjptrInt denw
                  in
                     if numw = badObjptrWord 
                        andalso deni = ~1
                        then negBadIntInf
                        else let
                                val ansi = I.quot (numi, deni)
-                               val answ = W.fromObjptrInt ansi
+                               val answ = W.idFromObjptrInt ansi
                                val ans = addTag answ
                             in 
                                Prim.fromWord ans
@@ -698,11 +977,11 @@
          if areSmall (num, den)
             then let 
                     val numw = dropTagCoerce num
-                    val numi = W.toObjptrIntX numw
+                    val numi = W.idToObjptrInt numw
                     val denw = dropTagCoerce den
-                    val deni = W.toObjptrIntX denw
+                    val deni = W.idToObjptrInt denw
                     val ansi = I.rem (numi, deni)
-                    val answ = W.fromObjptrInt ansi
+                    val answ = W.idFromObjptrInt ansi
                     val ans = addTag answ
                  in 
                     Prim.fromWord ans
@@ -724,7 +1003,7 @@
          open I
 
          fun mod2 x = I.andb (x, 1)
-         fun div2 x = I.>> (x, 0w1)
+         fun div2 x = I.>>? (x, 0w1)
             
          fun smallGcd (a, b, acc) =
             case (a, b) of
@@ -768,16 +1047,16 @@
 
       fun bigCompare (lhs: bigInt, rhs: bigInt): order =
          if areSmall (lhs, rhs)
-            then I.compare (W.toObjptrIntX (Prim.toWord lhs),
-                            W.toObjptrIntX (Prim.toWord rhs))
+            then I.compare (W.idToObjptrInt (Prim.toWord lhs),
+                            W.idToObjptrInt (Prim.toWord rhs))
             else Int32.compare (Prim.compare (lhs, rhs), 0)
 
       local
          fun make (smallTest, int32Test)
                   (lhs: bigInt, rhs: bigInt): bool =
             if areSmall (lhs, rhs)
-               then smallTest (W.toObjptrIntX (Prim.toWord lhs),
-                               W.toObjptrIntX (Prim.toWord rhs))
+               then smallTest (W.idToObjptrInt (Prim.toWord lhs),
+                               W.idToObjptrInt (Prim.toWord rhs))
                else int32Test (Prim.compare (lhs, rhs), 0)
       in
          val bigLT = make (I.<, Int32.<)
@@ -793,7 +1072,7 @@
                  in 
                     if argw = badObjptrWordTagged
                        then negBadIntInf
-                       else if I.< (W.toObjptrIntX argw, 0)
+                       else if I.< (W.idToObjptrInt argw, 0)
                                then Prim.fromWord (W.- (0w2, argw))
                                else arg
                  end
@@ -893,8 +1172,8 @@
             else Prim.notb (arg, reserve (numLimbs arg, 0))
 
       local
-         val bitsPerLimb = MPLimb.wordSizeWord
-         fun shiftSize shift = S.fromWord32 (Word32.div (shift, bitsPerLimb))
+         val bitsPerLimb = MPLimb.sizeInBitsWord
+         fun shiftSize shift = S.sextdFromWord32 (Word32.div (shift, bitsPerLimb))
       in
          fun bigLshift (arg: bigInt, shift: Word32.word): bigInt =
             if shift = 0wx0
@@ -915,8 +1194,8 @@
          if isSmall arg
             then smallCvt (dropTagCoerceInt arg)
             else let
-                    val bpd = Word32.log2 (Word32.fromInt32 base)
-                    val bpl = MPLimb.wordSize
+                    val bpd = Int32.log2 base
+                    val bpl = MPLimb.sizeInBits
                     val dpl =
                        Int32.+ (Int32.quot (bpl, bpd),
                                 if Int32.mod (bpl, bpd) = 0
@@ -926,8 +1205,8 @@
                     (arg, base, 
                      Sz.+ (Sz.+ (bytesPerArrayHeader (* Array Header *),
                                  0w1 (* sign *)),
-                           Sz.* (Sz.fromInt32 dpl, 
-                                 Sz.fromSeqIndex (numLimbs arg))))
+                           Sz.* (Sz.zextdFromInt32 dpl, 
+                                 Sz.zextdFromSeqIndex (numLimbs arg))))
                  end
 
       fun mkBigLog2 {fromSmall: {smallLog2: Primitive.Int32.int} -> 'a,
@@ -1005,9 +1284,11 @@
       val isNeg = bigIsNeg
 
       val andb = bigAndb
+      val <<? = bigLshift
       val << = bigLshift
       val notb = bigNotb
       val orb = bigOrb
+      val ~>>? = bigRashift
       val ~>> = bigRashift
       val xorb = bigXorb
 
@@ -1015,99 +1296,266 @@
       val mkLog2 = mkBigLog2
 end
 
-structure Char8 =
+structure IntWordConv : PRIM_INTWORD_CONV =
    struct
-      open Char8
-      fun fromIntInfUnsafe i = fromInt8Unsafe (IntInf.toInt8Unsafe i)
-      fun toIntInfUnsafe c = IntInf.fromInt8Unsafe (toInt8Unsafe c)
+      open IntWordConv
+
+      val idFromIntInfToIntInf = fn i => i
+
+
+      val zextdFromInt8ToIntInf = IntInf.zextdFromInt8
+      val zextdFromInt16ToIntInf = IntInf.zextdFromInt16
+      val zextdFromInt32ToIntInf = IntInf.zextdFromInt32
+      val zextdFromInt64ToIntInf = IntInf.zextdFromInt64
+      val zextdFromWord8ToIntInf = IntInf.zextdFromWord8
+      val zextdFromWord16ToIntInf = IntInf.zextdFromWord16
+      val zextdFromWord32ToIntInf = IntInf.zextdFromWord32
+      val zextdFromWord64ToIntInf = IntInf.zextdFromWord64
+
+      val zextdFromIntInfToInt8 = IntInf.zextdToInt8
+      val zextdFromIntInfToInt16 = IntInf.zextdToInt16
+      val zextdFromIntInfToInt32 = IntInf.zextdToInt32
+      val zextdFromIntInfToInt64 = IntInf.zextdToInt64
+      val zextdFromIntInfToIntInf = IntInf.zextdToIntInf
+      val zextdFromIntInfToWord8 = IntInf.zextdToWord8
+      val zextdFromIntInfToWord16 = IntInf.zextdToWord16
+      val zextdFromIntInfToWord32 = IntInf.zextdToWord32
+      val zextdFromIntInfToWord64 = IntInf.zextdToWord64
+
+
+      val sextdFromInt8ToIntInf = IntInf.sextdFromInt8
+      val sextdFromInt16ToIntInf = IntInf.sextdFromInt16
+      val sextdFromInt32ToIntInf = IntInf.sextdFromInt32
+      val sextdFromInt64ToIntInf = IntInf.sextdFromInt64
+      val sextdFromWord8ToIntInf = IntInf.sextdFromWord8
+      val sextdFromWord16ToIntInf = IntInf.sextdFromWord16
+      val sextdFromWord32ToIntInf = IntInf.sextdFromWord32
+      val sextdFromWord64ToIntInf = IntInf.sextdFromWord64
+
+      val sextdFromIntInfToInt8 = IntInf.sextdToInt8
+      val sextdFromIntInfToInt16 = IntInf.sextdToInt16
+      val sextdFromIntInfToInt32 = IntInf.sextdToInt32
+      val sextdFromIntInfToInt64 = IntInf.sextdToInt64
+      val sextdFromIntInfToIntInf = IntInf.sextdToIntInf
+      val sextdFromIntInfToWord8 = IntInf.sextdToWord8
+      val sextdFromIntInfToWord16 = IntInf.sextdToWord16
+      val sextdFromIntInfToWord32 = IntInf.sextdToWord32
+      val sextdFromIntInfToWord64 = IntInf.sextdToWord64
+
+
+      val castFromInt8ToIntInf = IntInf.castFromInt8
+      val castFromInt16ToIntInf = IntInf.castFromInt16
+      val castFromInt32ToIntInf = IntInf.castFromInt32
+      val castFromInt64ToIntInf = IntInf.castFromInt64
+      val castFromWord8ToIntInf = IntInf.castFromWord8
+      val castFromWord16ToIntInf = IntInf.castFromWord16
+      val castFromWord32ToIntInf = IntInf.castFromWord32
+      val castFromWord64ToIntInf = IntInf.castFromWord64
+
+      val castFromIntInfToInt8 = IntInf.castToInt8
+      val castFromIntInfToInt16 = IntInf.castToInt16
+      val castFromIntInfToInt32 = IntInf.castToInt32
+      val castFromIntInfToInt64 = IntInf.castToInt64
+      val castFromIntInfToIntInf = IntInf.castToIntInf
+      val castFromIntInfToWord8 = IntInf.castToWord8
+      val castFromIntInfToWord16 = IntInf.castToWord16
+      val castFromIntInfToWord32 = IntInf.castToWord32
+      val castFromIntInfToWord64 = IntInf.castToWord64
+
+
+      val zchckFromInt8ToIntInf = IntInf.zchckFromInt8
+      val zchckFromInt16ToIntInf = IntInf.zchckFromInt16
+      val zchckFromInt32ToIntInf = IntInf.zchckFromInt32
+      val zchckFromInt64ToIntInf = IntInf.zchckFromInt64
+      val zchckFromWord8ToIntInf = IntInf.zchckFromWord8
+      val zchckFromWord16ToIntInf = IntInf.zchckFromWord16
+      val zchckFromWord32ToIntInf = IntInf.zchckFromWord32
+      val zchckFromWord64ToIntInf = IntInf.zchckFromWord64
+
+      val zchckFromIntInfToInt8 = IntInf.zchckToInt8
+      val zchckFromIntInfToInt16 = IntInf.zchckToInt16
+      val zchckFromIntInfToInt32 = IntInf.zchckToInt32
+      val zchckFromIntInfToInt64 = IntInf.zchckToInt64
+      val zchckFromIntInfToIntInf = IntInf.zchckToIntInf
+      val zchckFromIntInfToWord8 = IntInf.zchckToWord8
+      val zchckFromIntInfToWord16 = IntInf.zchckToWord16
+      val zchckFromIntInfToWord32 = IntInf.zchckToWord32
+      val zchckFromIntInfToWord64 = IntInf.zchckToWord64
+
+
+      val schckFromInt8ToIntInf = IntInf.schckFromInt8
+      val schckFromInt16ToIntInf = IntInf.schckFromInt16
+      val schckFromInt32ToIntInf = IntInf.schckFromInt32
+      val schckFromInt64ToIntInf = IntInf.schckFromInt64
+      val schckFromWord8ToIntInf = IntInf.schckFromWord8
+      val schckFromWord16ToIntInf = IntInf.schckFromWord16
+      val schckFromWord32ToIntInf = IntInf.schckFromWord32
+      val schckFromWord64ToIntInf = IntInf.schckFromWord64
+
+      val schckFromIntInfToInt8 = IntInf.schckToInt8
+      val schckFromIntInfToInt16 = IntInf.schckToInt16
+      val schckFromIntInfToInt32 = IntInf.schckToInt32
+      val schckFromIntInfToInt64 = IntInf.schckToInt64
+      val schckFromIntInfToIntInf = IntInf.schckToIntInf
+      val schckFromIntInfToWord8 = IntInf.schckToWord8
+      val schckFromIntInfToWord16 = IntInf.schckToWord16
+      val schckFromIntInfToWord32 = IntInf.schckToWord32
+      val schckFromIntInfToWord64 = IntInf.schckToWord64
    end
-structure Char16 =
+
+structure Int8 : PRIM_INTEGER =
    struct
-      open Char16
-      fun fromIntInfUnsafe i = fromInt16Unsafe (IntInf.toInt16Unsafe i)
-      fun toIntInfUnsafe c = IntInf.fromInt16Unsafe (toInt16Unsafe c)
-   end
-structure Char32 =
-   struct
-      open Char32
-      fun fromIntInfUnsafe i = fromInt32Unsafe (IntInf.toInt32Unsafe i)
-      fun toIntInfUnsafe c = IntInf.fromInt32Unsafe (toInt32Unsafe c)
-   end
-structure Int8 = 
-   struct
       open Int8
-      val fromIntInfUnsafe = IntInf.toInt8Unsafe
-      val fromIntInf = IntInf.toInt8
-      val toIntInfUnsafe = IntInf.fromInt8Unsafe
-      val toIntInf = IntInf.fromInt8
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToInt8
+      val zextdToIntInf = IntWordConv.zextdFromInt8ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToInt8
+      val sextdToIntInf = IntWordConv.sextdFromInt8ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToInt8
+      val castToIntInf = IntWordConv.castFromInt8ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToInt8
+      val zchckToIntInf = IntWordConv.zchckFromInt8ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToInt8
+      val schckToIntInf = IntWordConv.schckFromInt8ToIntInf
    end
-structure Int16 = 
+structure Int16 : PRIM_INTEGER =
    struct
       open Int16
-      val fromIntInfUnsafe = IntInf.toInt16Unsafe
-      val fromIntInf = IntInf.toInt16
-      val toIntInfUnsafe = IntInf.fromInt16Unsafe
-      val toIntInf = IntInf.fromInt16
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToInt16
+      val zextdToIntInf = IntWordConv.zextdFromInt16ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToInt16
+      val sextdToIntInf = IntWordConv.sextdFromInt16ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToInt16
+      val castToIntInf = IntWordConv.castFromInt16ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToInt16
+      val zchckToIntInf = IntWordConv.zchckFromInt16ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToInt16
+      val schckToIntInf = IntWordConv.schckFromInt16ToIntInf
    end
-structure Int32 = 
+structure Int32 : PRIM_INTEGER =
    struct
       open Int32
-      val fromIntInfUnsafe = IntInf.toInt32Unsafe
-      val fromIntInf = IntInf.toInt32
-      val toIntInfUnsafe = IntInf.fromInt32Unsafe
-      val toIntInf = IntInf.fromInt32
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToInt32
+      val zextdToIntInf = IntWordConv.zextdFromInt32ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToInt32
+      val sextdToIntInf = IntWordConv.sextdFromInt32ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToInt32
+      val castToIntInf = IntWordConv.castFromInt32ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToInt32
+      val zchckToIntInf = IntWordConv.zchckFromInt32ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToInt32
+      val schckToIntInf = IntWordConv.schckFromInt32ToIntInf
    end
-structure Int64 = 
+structure Int64 : PRIM_INTEGER =
    struct
       open Int64
-      val fromIntInfUnsafe = IntInf.toInt64Unsafe
-      val fromIntInf = IntInf.toInt64
-      val toIntInfUnsafe = IntInf.fromInt64Unsafe
-      val toIntInf = IntInf.fromInt64
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToInt64
+      val zextdToIntInf = IntWordConv.zextdFromInt64ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToInt64
+      val sextdToIntInf = IntWordConv.sextdFromInt64ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToInt64
+      val castToIntInf = IntWordConv.castFromInt64ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToInt64
+      val zchckToIntInf = IntWordConv.zchckFromInt64ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToInt64
+      val schckToIntInf = IntWordConv.schckFromInt64ToIntInf
    end
-structure Word8 =
+structure Word8 : PRIM_WORD =
    struct
       open Word8
-      val fromIntInfUnsafe = IntInf.toWord8Unsafe
-      val fromIntInf = IntInf.toWord8
-      val fromIntInfZ = IntInf.toWord8
-      val toIntInfUnsafe = IntInf.fromWord8Unsafe
-      val toIntInf = IntInf.fromWord8
-      val toIntInfXUnsafe = IntInf.fromWord8XUnsafe
-      val toIntInfX = IntInf.fromWord8X
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToWord8
+      val zextdToIntInf = IntWordConv.zextdFromWord8ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToWord8
+      val sextdToIntInf = IntWordConv.sextdFromWord8ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToWord8
+      val castToIntInf = IntWordConv.castFromWord8ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToWord8
+      val zchckToIntInf = IntWordConv.zchckFromWord8ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToWord8
+      val schckToIntInf = IntWordConv.schckFromWord8ToIntInf
    end
-structure Word16 =
+structure Word16 : PRIM_WORD =
    struct
       open Word16
-      val fromIntInfUnsafe = IntInf.toWord16Unsafe
-      val fromIntInf = IntInf.toWord16
-      val fromIntInfZ = IntInf.toWord16
-      val toIntInfUnsafe = IntInf.fromWord16Unsafe
-      val toIntInf = IntInf.fromWord16
-      val toIntInfXUnsafe = IntInf.fromWord16XUnsafe
-      val toIntInfX = IntInf.fromWord16X
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToWord16
+      val zextdToIntInf = IntWordConv.zextdFromWord16ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToWord16
+      val sextdToIntInf = IntWordConv.sextdFromWord16ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToWord16
+      val castToIntInf = IntWordConv.castFromWord16ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToWord16
+      val zchckToIntInf = IntWordConv.zchckFromWord16ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToWord16
+      val schckToIntInf = IntWordConv.schckFromWord16ToIntInf
    end
-structure Word32 =
+structure Word32 : PRIM_WORD =
    struct
       open Word32
-      val fromIntInfUnsafe = IntInf.toWord32Unsafe
-      val fromIntInf = IntInf.toWord32
-      val fromIntInfZ = IntInf.toWord32
-      val toIntInfUnsafe = IntInf.fromWord32Unsafe
-      val toIntInf = IntInf.fromWord32
-      val toIntInfXUnsafe = IntInf.fromWord32XUnsafe
-      val toIntInfX = IntInf.fromWord32X
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToWord32
+      val zextdToIntInf = IntWordConv.zextdFromWord32ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToWord32
+      val sextdToIntInf = IntWordConv.sextdFromWord32ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToWord32
+      val castToIntInf = IntWordConv.castFromWord32ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToWord32
+      val zchckToIntInf = IntWordConv.zchckFromWord32ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToWord32
+      val schckToIntInf = IntWordConv.schckFromWord32ToIntInf
    end
-structure Word64 =
+structure Word64 : PRIM_WORD =
    struct
       open Word64
-      val fromIntInfUnsafe = IntInf.toWord64Unsafe
-      val fromIntInf = IntInf.toWord64
-      val fromIntInfZ = IntInf.toWord64
-      val toIntInfUnsafe = IntInf.fromWord64Unsafe
-      val toIntInf = IntInf.fromWord64
-      val toIntInfXUnsafe = IntInf.fromWord64XUnsafe
-      val toIntInfX = IntInf.fromWord64X
+
+      val zextdFromIntInf = IntWordConv.zextdFromIntInfToWord64
+      val zextdToIntInf = IntWordConv.zextdFromWord64ToIntInf
+
+      val sextdFromIntInf = IntWordConv.sextdFromIntInfToWord64
+      val sextdToIntInf = IntWordConv.sextdFromWord64ToIntInf
+
+      val castFromIntInf = IntWordConv.castFromIntInfToWord64
+      val castToIntInf = IntWordConv.castFromWord64ToIntInf
+
+      val zchckFromIntInf = IntWordConv.zchckFromIntInfToWord64
+      val zchckToIntInf = IntWordConv.zchckFromWord64ToIntInf
+
+      val schckFromIntInf = IntWordConv.schckFromIntInfToWord64
+      val schckToIntInf = IntWordConv.schckFromWord64ToIntInf
    end
 
+structure IntInf : PRIM_INT_INF = IntInf
+
 end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -6,15 +6,15 @@
  * See the file MLton-LICENSE for details.
  *)
 
-functor Integer (I: PRE_INTEGER_EXTRA): INTEGER_EXTRA =
+functor Integer (I: PRIM_INTEGER): INTEGER_EXTRA =
 struct
 
 open I
 type t = int
 
-val precision': Int.int = Primitive.Int32.toInt precision'
+val precision': Int.int = Primitive.Int32.zextdToInt sizeInBits
 val precision: Int.int option = SOME precision'
-val precisionWord': Word.word = Primitive.Word32.toWord precisionWord'
+val sizeInBitsWord = Primitive.Word32.zextdToWord sizeInBitsWord
 
 val maxInt: int option = SOME maxInt'
 val minInt: int option = SOME minInt'
@@ -29,20 +29,28 @@
 fun sameSign (x, y) = sign x = sign y
 
 fun << (i, n) = 
-   if Word.>= (n, precisionWord')
+   if Word.>= (n, sizeInBitsWord)
       then zero
-      else I.<< (i, Primitive.Word32.fromWord n)
+      else I.<<? (i, Primitive.Word32.zextdFromWord n)
 fun >> (i, n) = 
-   if Word.>= (n, precisionWord')
+   if Word.>= (n, sizeInBitsWord)
       then zero
-      else I.>> (i, Primitive.Word32.fromWord n)
+      else I.>>? (i, Primitive.Word32.zextdFromWord n)
 fun ~>> (i, n) =
-   if Word.< (n, precisionWord')
-      then I.~>> (i, Primitive.Word32.fromWord n)
-      else I.~>> (i, Primitive.Word32.- (I.precisionWord', 0w1))
-fun rol (i, n) = I.rol (i, Primitive.Word32.fromWord n)
-fun ror (i, n) = I.ror (i, Primitive.Word32.fromWord n)
-  
+   if Word.< (n, sizeInBitsWord)
+      then I.~>>? (i, Primitive.Word32.zextdFromWord n)
+      else I.~>>? (i, Primitive.Word32.- (I.sizeInBitsWord, 0w1))
+fun rol (i, n) = I.rolUnsafe (i, Primitive.Word32.zextdFromWord n)
+fun ror (i, n) = I.rorUnsafe (i, Primitive.Word32.zextdFromWord n)
+
+val fromInt = I.schckFromInt
+val toInt = I.schckToInt
+
+val fromLargeInt = I.schckFromLargeInt
+val toLargeInt = I.schckToLargeInt
+val fromLarge = fromLargeInt
+val toLarge = toLargeInt
+
 (* fmt constructs a string to represent the integer by building it into a
  * statically allocated buffer.  For the most part, this is a textbook
  * algorithm: loop starting at the end of the buffer; we use rem to

Deleted: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int0.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/int0.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -1,302 +0,0 @@
-(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
- *    Jagannathan, and Stephen Weeks.
- * Copyright (C) 1997-2000 NEC Research Institute.
- *
- * MLton is released under a BSD-style license.
- * See the file MLton-LICENSE for details.
- *)
-
-signature INTEGER0 =
-   sig
-      include PRIM_INTEGER
-
-      val precisionWord': Primitive.Word32.word
-
-      val maxInt: int option
-      val minInt: int option
-
-      val zero: int
-      val one: int
-
-      val abs: int -> int
-      val div: int * int -> int
-      val mod: int * int -> int
-      val quot: int * int -> int
-      val rem: int * int -> int
-
-      val power: {base:int, exp: int} -> int
-      val << : int * Primitive.Word32.word -> int
-      val rol : int * Primitive.Word32.word -> int
-      val ror : int * Primitive.Word32.word -> int
-      val ~>> : int * Primitive.Word32.word -> int
-      val >> : int * Primitive.Word32.word -> int
-
-      (* Overflow checking, signed interp. *)
-      val fromInt8: Primitive.Int8.int -> int
-      val fromInt16: Primitive.Int16.int -> int
-      val fromInt32: Primitive.Int32.int -> int
-      val fromInt64: Primitive.Int64.int -> int
-
-      (* Overflow checking, unsigned interp. *)
-      val fromWord8: Primitive.Word8.word -> int
-      val fromWord16: Primitive.Word16.word -> int
-      val fromWord32: Primitive.Word32.word -> int
-      val fromWord64: Primitive.Word64.word -> int
-
-      (* Overflow checking, signed interp. *)
-      val fromWord8X: Primitive.Word8.word -> int
-      val fromWord16X: Primitive.Word16.word -> int
-      val fromWord32X: Primitive.Word32.word -> int
-      val fromWord64X: Primitive.Word64.word -> int
-
-      (* Overflow checking. *)
-      val toInt8: int -> Primitive.Int8.int
-      val toInt16: int -> Primitive.Int16.int
-      val toInt32: int -> Primitive.Int32.int
-      val toInt64: int -> Primitive.Int64.int
-
-      (* Lowbits or zero extend. *)
-      val toWord8: int -> Primitive.Word8.word
-      val toWord16: int -> Primitive.Word16.word
-      val toWord32: int -> Primitive.Word32.word
-      val toWord64: int -> Primitive.Word64.word
-
-      (* Lowbits or sign extend. *)
-      val toWord8X: int -> Primitive.Word8.word
-      val toWord16X: int -> Primitive.Word16.word
-      val toWord32X: int -> Primitive.Word32.word
-      val toWord64X: int -> Primitive.Word64.word
-   end
-
-functor MkInt0 (I: PRIM_INTEGER): INTEGER0 =
-   struct
-
-      open I
-
-      val detectOverflow = Primitive.Controls.detectOverflow
-
-      val precisionWord' = Primitive.Word32.fromInt32Unsafe precision'
-      val precisionMinusOneWord' = Primitive.Word32.- (precisionWord', 0w1)
-
-      val maxInt: int option = SOME maxInt'
-      val minInt: int option = SOME minInt'
-
-      val zero: int = fromInt32Unsafe 0
-      val one: int = fromInt32Unsafe 1
-
-      fun abs (x: int) = if x < zero then ~ x else x
-
-      fun quot (x, y) =
-         if Primitive.Controls.safe andalso y = zero
-            then raise Div
-            else if detectOverflow andalso x = minInt' andalso y = ~one
-                    then raise Overflow
-                    else quotUnsafe (x, y)
-                       
-      fun rem (x, y) =
-         if Primitive.Controls.safe andalso y = zero
-            then raise Div
-            else if x = minInt' andalso y = ~one
-                    then zero
-                    else remUnsafe (x, y)
-                       
-      fun x div y =
-         if x >= zero
-            then if y > zero
-                    then quotUnsafe (x, y)
-                    else if y < zero
-                            then if x = zero
-                                    then zero
-                                    else quotUnsafe (x - one, y) -? one
-                            else raise Div
-            else if y < zero
-                    then if detectOverflow andalso x = minInt' andalso y = ~one
-                            then raise Overflow
-                            else quotUnsafe (x, y)
-                    else if y > zero
-                            then quotUnsafe (x + one, y) -? one
-                            else raise Div
-                               
-      fun x mod y =
-         if x >= zero
-            then if y > zero
-                    then remUnsafe (x, y)
-                    else if y < zero
-                            then if x = zero
-                                    then zero
-                                    else remUnsafe (x - one, y) +? (y + one)
-                            else raise Div
-            else if y < zero
-                    then if x = minInt' andalso y = ~one
-                            then zero
-                            else remUnsafe (x, y)
-                    else if y > zero
-                            then remUnsafe (x + one, y) +? (y - one)
-                            else raise Div
-
-      fun << (i, n) =
-         if Primitive.Word32.>= (n, precisionWord')
-            then zero
-            else <<? (i, n)
-      fun >> (i, n) =
-         if Primitive.Word32.>= (n, precisionWord')
-            then zero
-            else >>? (i, n)
-      fun ~>> (i, n) =
-         if Primitive.Word32.< (n, precisionWord')
-            then ~>>? (i, n)
-            else ~>>? (i, precisionMinusOneWord')
-      fun rol (i, n) =
-         let
-            val n = Primitive.Word32.remUnsafe (n, precisionWord')
-         in
-            if n = 0w0
-               then i
-               else rolUnsafe (i, n)
-         end
-      fun ror (i, n) =
-         let
-            val n = Primitive.Word32.remUnsafe (n, precisionWord')
-         in
-            if n = 0w0
-               then i
-               else rorUnsafe (i, n)
-         end
-
-      fun power {base, exp} =
-         if Primitive.Controls.safe andalso exp < zero
-            then raise Primitive.Exn.Fail8 "Int.power"
-            else let
-                    fun loop (exp, accum) =
-                       if exp <= zero
-                          then accum
-                          else loop (exp - one, base * accum)
-                 in loop (exp, one)
-                 end
-
-      local
-         fun 'a make {fromIntUnsafe: 'a -> int, 
-                      toIntUnsafe: int -> 'a,
-                      other : {precision': Primitive.Int32.int,
-                               maxInt': 'a, 
-                               minInt': 'a, 
-                               lte : 'a * 'a -> bool}} =
-            if detectOverflow andalso
-               precision' <> #precision' other
-               then if Primitive.Int32.< (precision', #precision' other)
-                       then (fn (i : 'a) =>
-                             if ((#lte other) (toIntUnsafe minInt', i)
-                                 andalso (#lte other) (i, toIntUnsafe maxInt'))
-                                then fromIntUnsafe i
-                                else raise Overflow, 
-                             toIntUnsafe)
-                       else (fromIntUnsafe, 
-                             fn i =>
-                             if (fromIntUnsafe (#minInt' other) <= i
-                                 andalso i <= fromIntUnsafe (#maxInt' other))
-                                then toIntUnsafe i
-                                else raise Overflow)
-               else (fromIntUnsafe, toIntUnsafe)
-      in
-         val (fromInt8, toInt8) = 
-            make {fromIntUnsafe = fromInt8Unsafe,
-                  toIntUnsafe = toInt8Unsafe,
-                  other = {precision' = Primitive.Int8.precision',
-                           maxInt' = Primitive.Int8.maxInt',
-                           minInt' = Primitive.Int8.minInt',
-                           lte = Primitive.Int8.<=}}
-         val (fromInt16, toInt16) = 
-            make {fromIntUnsafe = fromInt16Unsafe,
-                  toIntUnsafe = toInt16Unsafe,
-                  other = {precision' = Primitive.Int16.precision',
-                           maxInt' = Primitive.Int16.maxInt',
-                           minInt' = Primitive.Int16.minInt',
-                           lte = Primitive.Int16.<=}}
-         val (fromInt32, toInt32) = 
-            make {fromIntUnsafe = fromInt32Unsafe,
-                  toIntUnsafe = toInt32Unsafe,
-                  other = {precision' = Primitive.Int32.precision',
-                           maxInt' = Primitive.Int32.maxInt',
-                           minInt' = Primitive.Int32.minInt',
-                           lte = Primitive.Int32.<=}}
-         val (fromInt64, toInt64) = 
-            make {fromIntUnsafe = fromInt64Unsafe,
-                  toIntUnsafe = toInt64Unsafe,
-                  other = {precision' = Primitive.Int64.precision',
-                           maxInt' = Primitive.Int64.maxInt',
-                           minInt' = Primitive.Int64.minInt',
-                           lte = Primitive.Int64.<=}}
-      end
-
-      local
-         fun 'a make {fromWordUnsafe: 'a -> int, fromWordXUnsafe: 'a -> int,
-                      toWordUnsafe: int -> 'a, toWordXUnsafe: int -> 'a,
-                      other : {wordSize: Primitive.Int32.int,
-                               gt: 'a * 'a -> bool,
-                               lt: 'a * 'a -> bool}} =
-            let
-               fun fromWord w =
-                  if detectOverflow
-                     andalso Primitive.Int32.>= (#wordSize other, precision')
-                     andalso (#gt other) (w, toWordUnsafe maxInt')
-                     then raise Overflow
-                     else fromWordUnsafe w
-               fun fromWordX w =
-                  if detectOverflow
-                     andalso Primitive.Int32.> (#wordSize other, precision')
-                     andalso (#lt other) (toWordUnsafe maxInt', w)
-                     andalso (#lt other) (w, toWordUnsafe maxInt')
-                     then raise Overflow
-                     else fromWordXUnsafe w
-            in
-               (fromWord, 
-                fromWordX, 
-                toWordUnsafe, 
-                toWordXUnsafe)
-            end
-      in
-         val (fromWord8, fromWord8X, toWord8, toWord8X) =
-            make {fromWordUnsafe = fromWord8Unsafe, 
-                  fromWordXUnsafe = fromWord8XUnsafe,
-                  toWordUnsafe = toWord8Unsafe,
-                  toWordXUnsafe =toWord8XUnsafe,
-                  other = {wordSize = Primitive.Word8.wordSize,
-                           lt = Primitive.Word8.<,
-                           gt = Primitive.Word8.>}}
-         val (fromWord16, fromWord16X, toWord16, toWord16X) =
-            make {fromWordUnsafe = fromWord16Unsafe, 
-                  fromWordXUnsafe = fromWord16XUnsafe,
-                  toWordUnsafe = toWord16Unsafe,
-                  toWordXUnsafe =toWord16XUnsafe,
-                  other = {wordSize = Primitive.Word16.wordSize,
-                           lt = Primitive.Word16.<,
-                           gt = Primitive.Word16.>}}
-         val (fromWord32, fromWord32X, toWord32, toWord32X) =
-            make {fromWordUnsafe = fromWord32Unsafe, 
-                  fromWordXUnsafe = fromWord32XUnsafe,
-                  toWordUnsafe = toWord32Unsafe,
-                  toWordXUnsafe =toWord32XUnsafe,
-                  other = {wordSize = Primitive.Word32.wordSize,
-                           lt = Primitive.Word32.<,
-                           gt = Primitive.Word32.>}}
-         val (fromWord64, fromWord64X, toWord64, toWord64X) =
-            make {fromWordUnsafe = fromWord64Unsafe, 
-                  fromWordXUnsafe = fromWord64XUnsafe,
-                  toWordUnsafe = toWord64Unsafe,
-                  toWordXUnsafe =toWord64XUnsafe,
-                  other = {wordSize = Primitive.Word64.wordSize,
-                           lt = Primitive.Word64.<,
-                           gt = Primitive.Word64.>}}
-      end
-   
-   end
-
-structure Primitive = struct
-open Primitive
-
-structure Int8 = MkInt0 (Primitive.Int8)
-structure Int16 = MkInt0 (Primitive.Int16)
-structure Int32 = MkInt0 (Primitive.Int32)
-structure Int64 = MkInt0 (Primitive.Int64)
-
-end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/integer.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/integer.sig	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/integer.sig	2006-05-16 03:02:10 UTC (rev 4548)
@@ -3,18 +3,19 @@
       eqtype int
    end
 
-signature PRE_INTEGER =
+signature INTEGER =
    sig
       include INTEGER_GLOBAL
 
+      val precision : Int.int option
+      val minInt : int option
+      val maxInt : int option
+
       val toLarge: int -> LargeInt.int
       val fromLarge: LargeInt.int -> int
       val toInt: int -> Int.int
       val fromInt: Int.int -> int
 
-      val minInt: int option
-      val maxInt: int option
-
       val + : int * int -> int
       val - : int * int -> int
       val * : int * int -> int
@@ -33,53 +34,7 @@
       val abs: int -> int
       val min: int * int -> int
       val max: int * int -> int         
-   end
 
-signature PRE_INTEGER_EXTRA =
-   sig
-      include PRE_INTEGER
-
-      val zero: int
-      val one: int
-
-      val precision' : Primitive.Int32.int
-      val precisionWord' : Primitive.Word32.word
-
-      val maxInt' : int
-      val minInt' : int
-
-      val *? : int * int -> int
-      val +? : int * int -> int
-      val -? : int * int -> int
-      val ~? : int -> int
-      val power: {base: int, exp: int} -> int
-
-      val andb: int * int -> int
-      val << : int * Primitive.Word32.word -> int
-      val notb: int -> int
-      val orb: int * int -> int
-      val rol: int * Primitive.Word32.word -> int
-      val ror: int * Primitive.Word32.word -> int
-      val ~>> : int * Primitive.Word32.word -> int
-      val >> : int * Primitive.Word32.word -> int
-      val xorb: int * int -> int
-
-      val ltu: int * int -> bool
-      val leu: int * int -> bool
-      val gtu: int * int -> bool
-      val geu: int * int -> bool
-
-      val toLargeInt: int -> LargeInt.int
-      val fromLargeInt: LargeInt.int -> int
-      val fromSysWord: SysWord.word -> int
-      val toSysWord: int -> SysWord.word
-   end
-
-signature INTEGER =
-   sig
-      include PRE_INTEGER
-
-      val precision: Int.int option
       val sign: int -> Int.int
       val sameSign: int * int -> bool
 
@@ -122,6 +77,8 @@
 
       val toLargeInt: int -> LargeInt.int
       val fromLargeInt: LargeInt.int -> int
-      val fromSysWord: SysWord.word -> int
-      val toSysWord: int -> SysWord.word
+      val castFromFixedInt: FixedInt.int -> int
+      val castToFixedInt: int -> FixedInt.int
+      val castFromSysWord: SysWord.word -> int
+      val castToSysWord: int -> SysWord.word
    end

Added: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/iwconv0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/iwconv0.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/iwconv0.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -0,0 +1,1474 @@
+(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ * Copyright (C) 1997-2000 NEC Research Institute.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+signature PRIM_INTWORD_CONV =
+   sig
+      include PRIM_INTWORD_CONV
+
+      (* C-like cast: extend according to signedness of from or low-bits *)
+      val castFromInt8ToInt8: Primitive.Int8.int -> Primitive.Int8.int
+      val castFromInt8ToInt16: Primitive.Int8.int -> Primitive.Int16.int
+      val castFromInt8ToInt32: Primitive.Int8.int -> Primitive.Int32.int
+      val castFromInt8ToInt64: Primitive.Int8.int -> Primitive.Int64.int
+      val castFromInt8ToWord8: Primitive.Int8.int -> Primitive.Word8.word
+      val castFromInt8ToWord16: Primitive.Int8.int -> Primitive.Word16.word
+      val castFromInt8ToWord32: Primitive.Int8.int -> Primitive.Word32.word
+      val castFromInt8ToWord64: Primitive.Int8.int -> Primitive.Word64.word
+
+      val castFromInt16ToInt8: Primitive.Int16.int -> Primitive.Int8.int
+      val castFromInt16ToInt16: Primitive.Int16.int -> Primitive.Int16.int
+      val castFromInt16ToInt32: Primitive.Int16.int -> Primitive.Int32.int
+      val castFromInt16ToInt64: Primitive.Int16.int -> Primitive.Int64.int
+      val castFromInt16ToWord8: Primitive.Int16.int -> Primitive.Word8.word
+      val castFromInt16ToWord16: Primitive.Int16.int -> Primitive.Word16.word
+      val castFromInt16ToWord32: Primitive.Int16.int -> Primitive.Word32.word
+      val castFromInt16ToWord64: Primitive.Int16.int -> Primitive.Word64.word
+
+      val castFromInt32ToInt8: Primitive.Int32.int -> Primitive.Int8.int
+      val castFromInt32ToInt16: Primitive.Int32.int -> Primitive.Int16.int
+      val castFromInt32ToInt32: Primitive.Int32.int -> Primitive.Int32.int
+      val castFromInt32ToInt64: Primitive.Int32.int -> Primitive.Int64.int
+      val castFromInt32ToWord8: Primitive.Int32.int -> Primitive.Word8.word
+      val castFromInt32ToWord16: Primitive.Int32.int -> Primitive.Word16.word
+      val castFromInt32ToWord32: Primitive.Int32.int -> Primitive.Word32.word
+      val castFromInt32ToWord64: Primitive.Int32.int -> Primitive.Word64.word
+
+      val castFromInt64ToInt8: Primitive.Int64.int -> Primitive.Int8.int
+      val castFromInt64ToInt16: Primitive.Int64.int -> Primitive.Int16.int
+      val castFromInt64ToInt32: Primitive.Int64.int -> Primitive.Int32.int
+      val castFromInt64ToInt64: Primitive.Int64.int -> Primitive.Int64.int
+      val castFromInt64ToWord8: Primitive.Int64.int -> Primitive.Word8.word
+      val castFromInt64ToWord16: Primitive.Int64.int -> Primitive.Word16.word
+      val castFromInt64ToWord32: Primitive.Int64.int -> Primitive.Word32.word
+      val castFromInt64ToWord64: Primitive.Int64.int -> Primitive.Word64.word
+
+      val castFromWord8ToInt8: Primitive.Word8.word -> Primitive.Int8.int
+      val castFromWord8ToInt16: Primitive.Word8.word -> Primitive.Int16.int
+      val castFromWord8ToInt32: Primitive.Word8.word -> Primitive.Int32.int
+      val castFromWord8ToInt64: Primitive.Word8.word -> Primitive.Int64.int
+      val castFromWord8ToWord8: Primitive.Word8.word -> Primitive.Word8.word
+      val castFromWord8ToWord16: Primitive.Word8.word -> Primitive.Word16.word
+      val castFromWord8ToWord32: Primitive.Word8.word -> Primitive.Word32.word
+      val castFromWord8ToWord64: Primitive.Word8.word -> Primitive.Word64.word
+
+      val castFromWord16ToInt8: Primitive.Word16.word -> Primitive.Int8.int
+      val castFromWord16ToInt16: Primitive.Word16.word -> Primitive.Int16.int
+      val castFromWord16ToInt32: Primitive.Word16.word -> Primitive.Int32.int
+      val castFromWord16ToInt64: Primitive.Word16.word -> Primitive.Int64.int
+      val castFromWord16ToWord8: Primitive.Word16.word -> Primitive.Word8.word
+      val castFromWord16ToWord16: Primitive.Word16.word -> Primitive.Word16.word
+      val castFromWord16ToWord32: Primitive.Word16.word -> Primitive.Word32.word
+      val castFromWord16ToWord64: Primitive.Word16.word -> Primitive.Word64.word
+
+      val castFromWord32ToInt8: Primitive.Word32.word -> Primitive.Int8.int
+      val castFromWord32ToInt16: Primitive.Word32.word -> Primitive.Int16.int
+      val castFromWord32ToInt32: Primitive.Word32.word -> Primitive.Int32.int
+      val castFromWord32ToInt64: Primitive.Word32.word -> Primitive.Int64.int
+      val castFromWord32ToWord8: Primitive.Word32.word -> Primitive.Word8.word
+      val castFromWord32ToWord16: Primitive.Word32.word -> Primitive.Word16.word
+      val castFromWord32ToWord32: Primitive.Word32.word -> Primitive.Word32.word
+      val castFromWord32ToWord64: Primitive.Word32.word -> Primitive.Word64.word
+
+      val castFromWord64ToInt8: Primitive.Word64.word -> Primitive.Int8.int
+      val castFromWord64ToInt16: Primitive.Word64.word -> Primitive.Int16.int
+      val castFromWord64ToInt32: Primitive.Word64.word -> Primitive.Int32.int
+      val castFromWord64ToInt64: Primitive.Word64.word -> Primitive.Int64.int
+      val castFromWord64ToWord8: Primitive.Word64.word -> Primitive.Word8.word
+      val castFromWord64ToWord16: Primitive.Word64.word -> Primitive.Word16.word
+      val castFromWord64ToWord32: Primitive.Word64.word -> Primitive.Word32.word
+      val castFromWord64ToWord64: Primitive.Word64.word -> Primitive.Word64.word
+
+      (* checked zero-extend or low-bits, 
+       * Overflow if composed zero-extend not identity
+       *)
+      val zchckFromInt8ToInt8: Primitive.Int8.int -> Primitive.Int8.int
+      val zchckFromInt8ToInt16: Primitive.Int8.int -> Primitive.Int16.int
+      val zchckFromInt8ToInt32: Primitive.Int8.int -> Primitive.Int32.int
+      val zchckFromInt8ToInt64: Primitive.Int8.int -> Primitive.Int64.int
+      val zchckFromInt8ToWord8: Primitive.Int8.int -> Primitive.Word8.word
+      val zchckFromInt8ToWord16: Primitive.Int8.int -> Primitive.Word16.word
+      val zchckFromInt8ToWord32: Primitive.Int8.int -> Primitive.Word32.word
+      val zchckFromInt8ToWord64: Primitive.Int8.int -> Primitive.Word64.word
+
+      val zchckFromInt16ToInt8: Primitive.Int16.int -> Primitive.Int8.int
+      val zchckFromInt16ToInt16: Primitive.Int16.int -> Primitive.Int16.int
+      val zchckFromInt16ToInt32: Primitive.Int16.int -> Primitive.Int32.int
+      val zchckFromInt16ToInt64: Primitive.Int16.int -> Primitive.Int64.int
+      val zchckFromInt16ToWord8: Primitive.Int16.int -> Primitive.Word8.word
+      val zchckFromInt16ToWord16: Primitive.Int16.int -> Primitive.Word16.word
+      val zchckFromInt16ToWord32: Primitive.Int16.int -> Primitive.Word32.word
+      val zchckFromInt16ToWord64: Primitive.Int16.int -> Primitive.Word64.word
+
+      val zchckFromInt32ToInt8: Primitive.Int32.int -> Primitive.Int8.int
+      val zchckFromInt32ToInt16: Primitive.Int32.int -> Primitive.Int16.int
+      val zchckFromInt32ToInt32: Primitive.Int32.int -> Primitive.Int32.int
+      val zchckFromInt32ToInt64: Primitive.Int32.int -> Primitive.Int64.int
+      val zchckFromInt32ToWord8: Primitive.Int32.int -> Primitive.Word8.word
+      val zchckFromInt32ToWord16: Primitive.Int32.int -> Primitive.Word16.word
+      val zchckFromInt32ToWord32: Primitive.Int32.int -> Primitive.Word32.word
+      val zchckFromInt32ToWord64: Primitive.Int32.int -> Primitive.Word64.word
+
+      val zchckFromInt64ToInt8: Primitive.Int64.int -> Primitive.Int8.int
+      val zchckFromInt64ToInt16: Primitive.Int64.int -> Primitive.Int16.int
+      val zchckFromInt64ToInt32: Primitive.Int64.int -> Primitive.Int32.int
+      val zchckFromInt64ToInt64: Primitive.Int64.int -> Primitive.Int64.int
+      val zchckFromInt64ToWord8: Primitive.Int64.int -> Primitive.Word8.word
+      val zchckFromInt64ToWord16: Primitive.Int64.int -> Primitive.Word16.word
+      val zchckFromInt64ToWord32: Primitive.Int64.int -> Primitive.Word32.word
+      val zchckFromInt64ToWord64: Primitive.Int64.int -> Primitive.Word64.word
+
+      val zchckFromWord8ToInt8: Primitive.Word8.word -> Primitive.Int8.int
+      val zchckFromWord8ToInt16: Primitive.Word8.word -> Primitive.Int16.int
+      val zchckFromWord8ToInt32: Primitive.Word8.word -> Primitive.Int32.int
+      val zchckFromWord8ToInt64: Primitive.Word8.word -> Primitive.Int64.int
+      val zchckFromWord8ToWord8: Primitive.Word8.word -> Primitive.Word8.word
+      val zchckFromWord8ToWord16: Primitive.Word8.word -> Primitive.Word16.word
+      val zchckFromWord8ToWord32: Primitive.Word8.word -> Primitive.Word32.word
+      val zchckFromWord8ToWord64: Primitive.Word8.word -> Primitive.Word64.word
+
+      val zchckFromWord16ToInt8: Primitive.Word16.word -> Primitive.Int8.int
+      val zchckFromWord16ToInt16: Primitive.Word16.word -> Primitive.Int16.int
+      val zchckFromWord16ToInt32: Primitive.Word16.word -> Primitive.Int32.int
+      val zchckFromWord16ToInt64: Primitive.Word16.word -> Primitive.Int64.int
+      val zchckFromWord16ToWord8: Primitive.Word16.word -> Primitive.Word8.word
+      val zchckFromWord16ToWord16: Primitive.Word16.word -> Primitive.Word16.word
+      val zchckFromWord16ToWord32: Primitive.Word16.word -> Primitive.Word32.word
+      val zchckFromWord16ToWord64: Primitive.Word16.word -> Primitive.Word64.word
+
+      val zchckFromWord32ToInt8: Primitive.Word32.word -> Primitive.Int8.int
+      val zchckFromWord32ToInt16: Primitive.Word32.word -> Primitive.Int16.int
+      val zchckFromWord32ToInt32: Primitive.Word32.word -> Primitive.Int32.int
+      val zchckFromWord32ToInt64: Primitive.Word32.word -> Primitive.Int64.int
+      val zchckFromWord32ToWord8: Primitive.Word32.word -> Primitive.Word8.word
+      val zchckFromWord32ToWord16: Primitive.Word32.word -> Primitive.Word16.word
+      val zchckFromWord32ToWord32: Primitive.Word32.word -> Primitive.Word32.word
+      val zchckFromWord32ToWord64: Primitive.Word32.word -> Primitive.Word64.word
+
+      val zchckFromWord64ToInt8: Primitive.Word64.word -> Primitive.Int8.int
+      val zchckFromWord64ToInt16: Primitive.Word64.word -> Primitive.Int16.int
+      val zchckFromWord64ToInt32: Primitive.Word64.word -> Primitive.Int32.int
+      val zchckFromWord64ToInt64: Primitive.Word64.word -> Primitive.Int64.int
+      val zchckFromWord64ToWord8: Primitive.Word64.word -> Primitive.Word8.word
+      val zchckFromWord64ToWord16: Primitive.Word64.word -> Primitive.Word16.word
+      val zchckFromWord64ToWord32: Primitive.Word64.word -> Primitive.Word32.word
+      val zchckFromWord64ToWord64: Primitive.Word64.word -> Primitive.Word64.word
+
+      (* checked sign-extend or low-bits, 
+       * Overflow if composed sign-extend not identity
+       *)
+      val schckFromInt8ToInt8: Primitive.Int8.int -> Primitive.Int8.int
+      val schckFromInt8ToInt16: Primitive.Int8.int -> Primitive.Int16.int
+      val schckFromInt8ToInt32: Primitive.Int8.int -> Primitive.Int32.int
+      val schckFromInt8ToInt64: Primitive.Int8.int -> Primitive.Int64.int
+      val schckFromInt8ToWord8: Primitive.Int8.int -> Primitive.Word8.word
+      val schckFromInt8ToWord16: Primitive.Int8.int -> Primitive.Word16.word
+      val schckFromInt8ToWord32: Primitive.Int8.int -> Primitive.Word32.word
+      val schckFromInt8ToWord64: Primitive.Int8.int -> Primitive.Word64.word
+
+      val schckFromInt16ToInt8: Primitive.Int16.int -> Primitive.Int8.int
+      val schckFromInt16ToInt16: Primitive.Int16.int -> Primitive.Int16.int
+      val schckFromInt16ToInt32: Primitive.Int16.int -> Primitive.Int32.int
+      val schckFromInt16ToInt64: Primitive.Int16.int -> Primitive.Int64.int
+      val schckFromInt16ToWord8: Primitive.Int16.int -> Primitive.Word8.word
+      val schckFromInt16ToWord16: Primitive.Int16.int -> Primitive.Word16.word
+      val schckFromInt16ToWord32: Primitive.Int16.int -> Primitive.Word32.word
+      val schckFromInt16ToWord64: Primitive.Int16.int -> Primitive.Word64.word
+
+      val schckFromInt32ToInt8: Primitive.Int32.int -> Primitive.Int8.int
+      val schckFromInt32ToInt16: Primitive.Int32.int -> Primitive.Int16.int
+      val schckFromInt32ToInt32: Primitive.Int32.int -> Primitive.Int32.int
+      val schckFromInt32ToInt64: Primitive.Int32.int -> Primitive.Int64.int
+      val schckFromInt32ToWord8: Primitive.Int32.int -> Primitive.Word8.word
+      val schckFromInt32ToWord16: Primitive.Int32.int -> Primitive.Word16.word
+      val schckFromInt32ToWord32: Primitive.Int32.int -> Primitive.Word32.word
+      val schckFromInt32ToWord64: Primitive.Int32.int -> Primitive.Word64.word
+
+      val schckFromInt64ToInt8: Primitive.Int64.int -> Primitive.Int8.int
+      val schckFromInt64ToInt16: Primitive.Int64.int -> Primitive.Int16.int
+      val schckFromInt64ToInt32: Primitive.Int64.int -> Primitive.Int32.int
+      val schckFromInt64ToInt64: Primitive.Int64.int -> Primitive.Int64.int
+      val schckFromInt64ToWord8: Primitive.Int64.int -> Primitive.Word8.word
+      val schckFromInt64ToWord16: Primitive.Int64.int -> Primitive.Word16.word
+      val schckFromInt64ToWord32: Primitive.Int64.int -> Primitive.Word32.word
+      val schckFromInt64ToWord64: Primitive.Int64.int -> Primitive.Word64.word
+
+      val schckFromWord8ToInt8: Primitive.Word8.word -> Primitive.Int8.int
+      val schckFromWord8ToInt16: Primitive.Word8.word -> Primitive.Int16.int
+      val schckFromWord8ToInt32: Primitive.Word8.word -> Primitive.Int32.int
+      val schckFromWord8ToInt64: Primitive.Word8.word -> Primitive.Int64.int
+      val schckFromWord8ToWord8: Primitive.Word8.word -> Primitive.Word8.word
+      val schckFromWord8ToWord16: Primitive.Word8.word -> Primitive.Word16.word
+      val schckFromWord8ToWord32: Primitive.Word8.word -> Primitive.Word32.word
+      val schckFromWord8ToWord64: Primitive.Word8.word -> Primitive.Word64.word
+
+      val schckFromWord16ToInt8: Primitive.Word16.word -> Primitive.Int8.int
+      val schckFromWord16ToInt16: Primitive.Word16.word -> Primitive.Int16.int
+      val schckFromWord16ToInt32: Primitive.Word16.word -> Primitive.Int32.int
+      val schckFromWord16ToInt64: Primitive.Word16.word -> Primitive.Int64.int
+      val schckFromWord16ToWord8: Primitive.Word16.word -> Primitive.Word8.word
+      val schckFromWord16ToWord16: Primitive.Word16.word -> Primitive.Word16.word
+      val schckFromWord16ToWord32: Primitive.Word16.word -> Primitive.Word32.word
+      val schckFromWord16ToWord64: Primitive.Word16.word -> Primitive.Word64.word
+
+      val schckFromWord32ToInt8: Primitive.Word32.word -> Primitive.Int8.int
+      val schckFromWord32ToInt16: Primitive.Word32.word -> Primitive.Int16.int
+      val schckFromWord32ToInt32: Primitive.Word32.word -> Primitive.Int32.int
+      val schckFromWord32ToInt64: Primitive.Word32.word -> Primitive.Int64.int
+      val schckFromWord32ToWord8: Primitive.Word32.word -> Primitive.Word8.word
+      val schckFromWord32ToWord16: Primitive.Word32.word -> Primitive.Word16.word
+      val schckFromWord32ToWord32: Primitive.Word32.word -> Primitive.Word32.word
+      val schckFromWord32ToWord64: Primitive.Word32.word -> Primitive.Word64.word
+
+      val schckFromWord64ToInt8: Primitive.Word64.word -> Primitive.Int8.int
+      val schckFromWord64ToInt16: Primitive.Word64.word -> Primitive.Int16.int
+      val schckFromWord64ToInt32: Primitive.Word64.word -> Primitive.Int32.int
+      val schckFromWord64ToInt64: Primitive.Word64.word -> Primitive.Int64.int
+      val schckFromWord64ToWord8: Primitive.Word64.word -> Primitive.Word8.word
+      val schckFromWord64ToWord16: Primitive.Word64.word -> Primitive.Word16.word
+      val schckFromWord64ToWord32: Primitive.Word64.word -> Primitive.Word32.word
+      val schckFromWord64ToWord64: Primitive.Word64.word -> Primitive.Word64.word
+   end
+signature PRIM_INTEGER =
+   sig
+      include PRIM_INTEGER
+
+      val zextdFromInt8: Primitive.Int8.int -> int
+      val zextdFromInt16: Primitive.Int16.int -> int
+      val zextdFromInt32: Primitive.Int32.int -> int
+      val zextdFromInt64: Primitive.Int64.int -> int
+      val zextdFromWord8: Primitive.Word8.word -> int
+      val zextdFromWord16: Primitive.Word16.word -> int
+      val zextdFromWord32: Primitive.Word32.word -> int
+      val zextdFromWord64: Primitive.Word64.word -> int
+      val zextdToInt8: int -> Primitive.Int8.int
+      val zextdToInt16: int -> Primitive.Int16.int
+      val zextdToInt32: int -> Primitive.Int32.int
+      val zextdToInt64: int -> Primitive.Int64.int
+      val zextdToWord8: int -> Primitive.Word8.word
+      val zextdToWord16: int -> Primitive.Word16.word
+      val zextdToWord32: int -> Primitive.Word32.word
+      val zextdToWord64: int -> Primitive.Word64.word
+
+      val sextdFromInt8: Primitive.Int8.int -> int
+      val sextdFromInt16: Primitive.Int16.int -> int
+      val sextdFromInt32: Primitive.Int32.int -> int
+      val sextdFromInt64: Primitive.Int64.int -> int
+      val sextdFromWord8: Primitive.Word8.word -> int
+      val sextdFromWord16: Primitive.Word16.word -> int
+      val sextdFromWord32: Primitive.Word32.word -> int
+      val sextdFromWord64: Primitive.Word64.word -> int
+      val sextdToInt8: int -> Primitive.Int8.int
+      val sextdToInt16: int -> Primitive.Int16.int
+      val sextdToInt32: int -> Primitive.Int32.int
+      val sextdToInt64: int -> Primitive.Int64.int
+      val sextdToWord8: int -> Primitive.Word8.word
+      val sextdToWord16: int -> Primitive.Word16.word
+      val sextdToWord32: int -> Primitive.Word32.word
+      val sextdToWord64: int -> Primitive.Word64.word
+
+      val castFromInt8: Primitive.Int8.int -> int
+      val castFromInt16: Primitive.Int16.int -> int
+      val castFromInt32: Primitive.Int32.int -> int
+      val castFromInt64: Primitive.Int64.int -> int
+      val castFromWord8: Primitive.Word8.word -> int
+      val castFromWord16: Primitive.Word16.word -> int
+      val castFromWord32: Primitive.Word32.word -> int
+      val castFromWord64: Primitive.Word64.word -> int
+      val castToInt8: int -> Primitive.Int8.int
+      val castToInt16: int -> Primitive.Int16.int
+      val castToInt32: int -> Primitive.Int32.int
+      val castToInt64: int -> Primitive.Int64.int
+      val castToWord8: int -> Primitive.Word8.word
+      val castToWord16: int -> Primitive.Word16.word
+      val castToWord32: int -> Primitive.Word32.word
+      val castToWord64: int -> Primitive.Word64.word
+
+      val zchckFromInt8: Primitive.Int8.int -> int
+      val zchckFromInt16: Primitive.Int16.int -> int
+      val zchckFromInt32: Primitive.Int32.int -> int
+      val zchckFromInt64: Primitive.Int64.int -> int
+      val zchckFromWord8: Primitive.Word8.word -> int
+      val zchckFromWord16: Primitive.Word16.word -> int
+      val zchckFromWord32: Primitive.Word32.word -> int
+      val zchckFromWord64: Primitive.Word64.word -> int
+      val zchckToInt8: int -> Primitive.Int8.int
+      val zchckToInt16: int -> Primitive.Int16.int
+      val zchckToInt32: int -> Primitive.Int32.int
+      val zchckToInt64: int -> Primitive.Int64.int
+      val zchckToWord8: int -> Primitive.Word8.word
+      val zchckToWord16: int -> Primitive.Word16.word
+      val zchckToWord32: int -> Primitive.Word32.word
+      val zchckToWord64: int -> Primitive.Word64.word
+
+      val schckFromInt8: Primitive.Int8.int -> int
+      val schckFromInt16: Primitive.Int16.int -> int
+      val schckFromInt32: Primitive.Int32.int -> int
+      val schckFromInt64: Primitive.Int64.int -> int
+      val schckFromWord8: Primitive.Word8.word -> int
+      val schckFromWord16: Primitive.Word16.word -> int
+      val schckFromWord32: Primitive.Word32.word -> int
+      val schckFromWord64: Primitive.Word64.word -> int
+      val schckToInt8: int -> Primitive.Int8.int
+      val schckToInt16: int -> Primitive.Int16.int
+      val schckToInt32: int -> Primitive.Int32.int
+      val schckToInt64: int -> Primitive.Int64.int
+      val schckToWord8: int -> Primitive.Word8.word
+      val schckToWord16: int -> Primitive.Word16.word
+      val schckToWord32: int -> Primitive.Word32.word
+      val schckToWord64: int -> Primitive.Word64.word
+   end
+signature PRIM_WORD =
+   sig
+      include PRIM_WORD
+
+      val zextdFromInt8: Primitive.Int8.int -> word
+      val zextdFromInt16: Primitive.Int16.int -> word
+      val zextdFromInt32: Primitive.Int32.int -> word
+      val zextdFromInt64: Primitive.Int64.int -> word
+      val zextdFromWord8: Primitive.Word8.word -> word
+      val zextdFromWord16: Primitive.Word16.word -> word
+      val zextdFromWord32: Primitive.Word32.word -> word
+      val zextdFromWord64: Primitive.Word64.word -> word
+      val zextdToInt8: word -> Primitive.Int8.int
+      val zextdToInt16: word -> Primitive.Int16.int
+      val zextdToInt32: word -> Primitive.Int32.int
+      val zextdToInt64: word -> Primitive.Int64.int
+      val zextdToWord8: word -> Primitive.Word8.word
+      val zextdToWord16: word -> Primitive.Word16.word
+      val zextdToWord32: word -> Primitive.Word32.word
+      val zextdToWord64: word -> Primitive.Word64.word
+
+      val sextdFromInt8: Primitive.Int8.int -> word
+      val sextdFromInt16: Primitive.Int16.int -> word
+      val sextdFromInt32: Primitive.Int32.int -> word
+      val sextdFromInt64: Primitive.Int64.int -> word
+      val sextdFromWord8: Primitive.Word8.word -> word
+      val sextdFromWord16: Primitive.Word16.word -> word
+      val sextdFromWord32: Primitive.Word32.word -> word
+      val sextdFromWord64: Primitive.Word64.word -> word
+      val sextdToInt8: word -> Primitive.Int8.int
+      val sextdToInt16: word -> Primitive.Int16.int
+      val sextdToInt32: word -> Primitive.Int32.int
+      val sextdToInt64: word -> Primitive.Int64.int
+      val sextdToWord8: word -> Primitive.Word8.word
+      val sextdToWord16: word -> Primitive.Word16.word
+      val sextdToWord32: word -> Primitive.Word32.word
+      val sextdToWord64: word -> Primitive.Word64.word
+
+      val castFromInt8: Primitive.Int8.int -> word
+      val castFromInt16: Primitive.Int16.int -> word
+      val castFromInt32: Primitive.Int32.int -> word
+      val castFromInt64: Primitive.Int64.int -> word
+      val castFromWord8: Primitive.Word8.word -> word
+      val castFromWord16: Primitive.Word16.word -> word
+      val castFromWord32: Primitive.Word32.word -> word
+      val castFromWord64: Primitive.Word64.word -> word
+      val castToInt8: word -> Primitive.Int8.int
+      val castToInt16: word -> Primitive.Int16.int
+      val castToInt32: word -> Primitive.Int32.int
+      val castToInt64: word -> Primitive.Int64.int
+      val castToWord8: word -> Primitive.Word8.word
+      val castToWord16: word -> Primitive.Word16.word
+      val castToWord32: word -> Primitive.Word32.word
+      val castToWord64: word -> Primitive.Word64.word
+
+      val zchckFromInt8: Primitive.Int8.int -> word
+      val zchckFromInt16: Primitive.Int16.int -> word
+      val zchckFromInt32: Primitive.Int32.int -> word
+      val zchckFromInt64: Primitive.Int64.int -> word
+      val zchckFromWord8: Primitive.Word8.word -> word
+      val zchckFromWord16: Primitive.Word16.word -> word
+      val zchckFromWord32: Primitive.Word32.word -> word
+      val zchckFromWord64: Primitive.Word64.word -> word
+      val zchckToInt8: word -> Primitive.Int8.int
+      val zchckToInt16: word -> Primitive.Int16.int
+      val zchckToInt32: word -> Primitive.Int32.int
+      val zchckToInt64: word -> Primitive.Int64.int
+      val zchckToWord8: word -> Primitive.Word8.word
+      val zchckToWord16: word -> Primitive.Word16.word
+      val zchckToWord32: word -> Primitive.Word32.word
+      val zchckToWord64: word -> Primitive.Word64.word
+
+      val schckFromInt8: Primitive.Int8.int -> word
+      val schckFromInt16: Primitive.Int16.int -> word
+      val schckFromInt32: Primitive.Int32.int -> word
+      val schckFromInt64: Primitive.Int64.int -> word
+      val schckFromWord8: Primitive.Word8.word -> word
+      val schckFromWord16: Primitive.Word16.word -> word
+      val schckFromWord32: Primitive.Word32.word -> word
+      val schckFromWord64: Primitive.Word64.word -> word
+      val schckToInt8: word -> Primitive.Int8.int
+      val schckToInt16: word -> Primitive.Int16.int
+      val schckToInt32: word -> Primitive.Int32.int
+      val schckToInt64: word -> Primitive.Int64.int
+      val schckToWord8: word -> Primitive.Word8.word
+      val schckToWord16: word -> Primitive.Word16.word
+      val schckToWord32: word -> Primitive.Word32.word
+      val schckToWord64: word -> Primitive.Word64.word
+   end
+
+structure Primitive = struct
+
+open Primitive
+
+structure IntWordConv : PRIM_INTWORD_CONV =
+   struct
+      open IntWordConv
+
+      (* C-like cast: extend according to signedness of from or low-bits *)
+      val castFromInt8ToInt8 = sextdFromInt8ToInt8
+      val castFromInt8ToInt16 = sextdFromInt8ToInt16
+      val castFromInt8ToInt32 = sextdFromInt8ToInt32
+      val castFromInt8ToInt64 = sextdFromInt8ToInt64
+      val castFromInt8ToWord8 = sextdFromInt8ToWord8
+      val castFromInt8ToWord16 = sextdFromInt8ToWord16
+      val castFromInt8ToWord32 = sextdFromInt8ToWord32
+      val castFromInt8ToWord64 = sextdFromInt8ToWord64
+      val castFromInt16ToInt8 = sextdFromInt16ToInt8
+      val castFromInt16ToInt16 = sextdFromInt16ToInt16
+      val castFromInt16ToInt32 = sextdFromInt16ToInt32
+      val castFromInt16ToInt64 = sextdFromInt16ToInt64
+      val castFromInt16ToWord8 = sextdFromInt16ToWord8
+      val castFromInt16ToWord16 = sextdFromInt16ToWord16
+      val castFromInt16ToWord32 = sextdFromInt16ToWord32
+      val castFromInt16ToWord64 = sextdFromInt16ToWord64
+      val castFromInt32ToInt8 = sextdFromInt32ToInt8
+      val castFromInt32ToInt16 = sextdFromInt32ToInt16
+      val castFromInt32ToInt32 = sextdFromInt32ToInt32
+      val castFromInt32ToInt64 = sextdFromInt32ToInt64
+      val castFromInt32ToWord8 = sextdFromInt32ToWord8
+      val castFromInt32ToWord16 = sextdFromInt32ToWord16
+      val castFromInt32ToWord32 = sextdFromInt32ToWord32
+      val castFromInt32ToWord64 = sextdFromInt32ToWord64
+      val castFromInt64ToInt8 = sextdFromInt64ToInt8
+      val castFromInt64ToInt16 = sextdFromInt64ToInt16
+      val castFromInt64ToInt32 = sextdFromInt64ToInt32
+      val castFromInt64ToInt64 = sextdFromInt64ToInt64
+      val castFromInt64ToWord8 = sextdFromInt64ToWord8
+      val castFromInt64ToWord16 = sextdFromInt64ToWord16
+      val castFromInt64ToWord32 = sextdFromInt64ToWord32
+      val castFromInt64ToWord64 = sextdFromInt64ToWord64
+
+      val castFromWord8ToInt8 = zextdFromWord8ToInt8
+      val castFromWord8ToInt16 = zextdFromWord8ToInt16
+      val castFromWord8ToInt32 = zextdFromWord8ToInt32
+      val castFromWord8ToInt64 = zextdFromWord8ToInt64
+      val castFromWord8ToWord8 = zextdFromWord8ToWord8
+      val castFromWord8ToWord16 = zextdFromWord8ToWord16
+      val castFromWord8ToWord32 = zextdFromWord8ToWord32
+      val castFromWord8ToWord64 = zextdFromWord8ToWord64
+      val castFromWord16ToInt8 = zextdFromWord16ToInt8
+      val castFromWord16ToInt16 = zextdFromWord16ToInt16
+      val castFromWord16ToInt32 = zextdFromWord16ToInt32
+      val castFromWord16ToInt64 = zextdFromWord16ToInt64
+      val castFromWord16ToWord8 = zextdFromWord16ToWord8
+      val castFromWord16ToWord16 = zextdFromWord16ToWord16
+      val castFromWord16ToWord32 = zextdFromWord16ToWord32
+      val castFromWord16ToWord64 = zextdFromWord16ToWord64
+      val castFromWord32ToInt8 = zextdFromWord32ToInt8
+      val castFromWord32ToInt16 = zextdFromWord32ToInt16
+      val castFromWord32ToInt32 = zextdFromWord32ToInt32
+      val castFromWord32ToInt64 = zextdFromWord32ToInt64
+      val castFromWord32ToWord8 = zextdFromWord32ToWord8
+      val castFromWord32ToWord16 = zextdFromWord32ToWord16
+      val castFromWord32ToWord32 = zextdFromWord32ToWord32
+      val castFromWord32ToWord64 = zextdFromWord32ToWord64
+      val castFromWord64ToInt8 = zextdFromWord64ToInt8
+      val castFromWord64ToInt16 = zextdFromWord64ToInt16
+      val castFromWord64ToInt32 = zextdFromWord64ToInt32
+      val castFromWord64ToInt64 = zextdFromWord64ToInt64
+      val castFromWord64ToWord8 = zextdFromWord64ToWord8
+      val castFromWord64ToWord16 = zextdFromWord64ToWord16
+      val castFromWord64ToWord32 = zextdFromWord64ToWord32
+      val castFromWord64ToWord64 = zextdFromWord64ToWord64
+         
+      (* checked zero-extend or low-bits, 
+       * Overflow if composed zero-extend not identity
+       *)
+      local
+         fun (''l, ''s) make {zextdFromLargeToSmall: ''l -> ''s,
+                              zextdFromSmallToLarge: ''s -> ''l} =
+            if Primitive.Controls.detectOverflow
+               then fn (x: ''l) => let 
+                                      val res = zextdFromLargeToSmall x
+                                   in
+                                      if x = (zextdFromSmallToLarge res)
+                                         then res
+                                         else raise Overflow
+                                   end
+               else zextdFromLargeToSmall
+      in
+         val zchckFromInt8ToInt8 = zextdFromInt8ToInt8
+         val zchckFromInt8ToInt16 = zextdFromInt8ToInt16
+         val zchckFromInt8ToInt32 = zextdFromInt8ToInt32
+         val zchckFromInt8ToInt64 = zextdFromInt8ToInt64
+         val zchckFromInt8ToWord8 = zextdFromInt8ToWord8
+         val zchckFromInt8ToWord16 = zextdFromInt8ToWord16
+         val zchckFromInt8ToWord32 = zextdFromInt8ToWord32
+         val zchckFromInt8ToWord64 = zextdFromInt8ToWord64
+         val zchckFromInt16ToInt8 = 
+            make {zextdFromLargeToSmall = zextdFromInt16ToInt8,
+                  zextdFromSmallToLarge = zextdFromInt8ToInt16}
+         val zchckFromInt16ToInt16 = zextdFromInt16ToInt16
+         val zchckFromInt16ToInt32 = zextdFromInt16ToInt32
+         val zchckFromInt16ToInt64 = zextdFromInt16ToInt64
+         val zchckFromInt16ToWord8 = 
+            make {zextdFromLargeToSmall = zextdFromInt16ToWord8,
+                  zextdFromSmallToLarge = zextdFromWord8ToInt16}
+         val zchckFromInt16ToWord16 = zextdFromInt16ToWord16
+         val zchckFromInt16ToWord32 = zextdFromInt16ToWord32
+         val zchckFromInt16ToWord64 = zextdFromInt16ToWord64
+         val zchckFromInt32ToInt8 = 
+            make {zextdFromLargeToSmall = zextdFromInt32ToInt8,
+                  zextdFromSmallToLarge = zextdFromInt8ToInt32}
+         val zchckFromInt32ToInt16 = 
+            make {zextdFromLargeToSmall = zextdFromInt32ToInt16,
+                  zextdFromSmallToLarge = zextdFromInt16ToInt32}
+         val zchckFromInt32ToInt32 = zextdFromInt32ToInt32
+         val zchckFromInt32ToInt64 = zextdFromInt32ToInt64
+         val zchckFromInt32ToWord8 = 
+            make {zextdFromLargeToSmall = zextdFromInt32ToWord8,
+                  zextdFromSmallToLarge = zextdFromWord8ToInt32}
+         val zchckFromInt32ToWord16 = 
+            make {zextdFromLargeToSmall = zextdFromInt32ToWord16,
+                  zextdFromSmallToLarge = zextdFromWord16ToInt32}
+         val zchckFromInt32ToWord32 = zextdFromInt32ToWord32
+         val zchckFromInt32ToWord64 = zextdFromInt32ToWord64
+         val zchckFromInt64ToInt8 = 
+            make {zextdFromLargeToSmall = zextdFromInt64ToInt8,
+                  zextdFromSmallToLarge = zextdFromInt8ToInt64}
+         val zchckFromInt64ToInt16 = 
+            make {zextdFromLargeToSmall = zextdFromInt64ToInt16,
+                  zextdFromSmallToLarge = zextdFromInt16ToInt64}
+         val zchckFromInt64ToInt32 = 
+            make {zextdFromLargeToSmall = zextdFromInt64ToInt32,
+                  zextdFromSmallToLarge = zextdFromInt32ToInt64}
+         val zchckFromInt64ToInt64 = zextdFromInt64ToInt64
+         val zchckFromInt64ToWord8 = 
+            make {zextdFromLargeToSmall = zextdFromInt64ToWord8,
+                  zextdFromSmallToLarge = zextdFromWord8ToInt64}
+         val zchckFromInt64ToWord16 = 
+            make {zextdFromLargeToSmall = zextdFromInt64ToWord16,
+                  zextdFromSmallToLarge = zextdFromWord16ToInt64}
+         val zchckFromInt64ToWord32 = 
+            make {zextdFromLargeToSmall = zextdFromInt64ToWord32,
+                  zextdFromSmallToLarge = zextdFromWord32ToInt64}
+         val zchckFromInt64ToWord64 = zextdFromInt64ToWord64
+
+         val zchckFromWord8ToInt8 = zextdFromWord8ToInt8
+         val zchckFromWord8ToInt16 = zextdFromWord8ToInt16
+         val zchckFromWord8ToInt32 = zextdFromWord8ToInt32
+         val zchckFromWord8ToInt64 = zextdFromWord8ToInt64
+         val zchckFromWord8ToWord8 = zextdFromWord8ToWord8
+         val zchckFromWord8ToWord16 = zextdFromWord8ToWord16
+         val zchckFromWord8ToWord32 = zextdFromWord8ToWord32
+         val zchckFromWord8ToWord64 = zextdFromWord8ToWord64
+         val zchckFromWord16ToInt8 = 
+            make {zextdFromLargeToSmall = zextdFromWord16ToInt8,
+                  zextdFromSmallToLarge = zextdFromInt8ToWord16}
+         val zchckFromWord16ToInt16 = zextdFromWord16ToInt16
+         val zchckFromWord16ToInt32 = zextdFromWord16ToInt32
+         val zchckFromWord16ToInt64 = zextdFromWord16ToInt64
+         val zchckFromWord16ToWord8 = 
+            make {zextdFromLargeToSmall = zextdFromWord16ToWord8,
+                  zextdFromSmallToLarge = zextdFromWord8ToWord16}
+         val zchckFromWord16ToWord16 = zextdFromWord16ToWord16
+         val zchckFromWord16ToWord32 = zextdFromWord16ToWord32
+         val zchckFromWord16ToWord64 = zextdFromWord16ToWord64
+         val zchckFromWord32ToInt8 = 
+            make {zextdFromLargeToSmall = zextdFromWord32ToInt8,
+                  zextdFromSmallToLarge = zextdFromInt8ToWord32}
+         val zchckFromWord32ToInt16 = 
+            make {zextdFromLargeToSmall = zextdFromWord32ToInt16,
+                  zextdFromSmallToLarge = zextdFromInt16ToWord32}
+         val zchckFromWord32ToInt32 = zextdFromWord32ToInt32
+         val zchckFromWord32ToInt64 = zextdFromWord32ToInt64
+         val zchckFromWord32ToWord8 = 
+            make {zextdFromLargeToSmall = zextdFromWord32ToWord8,
+                  zextdFromSmallToLarge = zextdFromWord8ToWord32}
+         val zchckFromWord32ToWord16 = 
+            make {zextdFromLargeToSmall = zextdFromWord32ToWord16,
+                  zextdFromSmallToLarge = zextdFromWord16ToWord32}
+         val zchckFromWord32ToWord32 = zextdFromWord32ToWord32
+         val zchckFromWord32ToWord64 = zextdFromWord32ToWord64
+         val zchckFromWord64ToInt8 = 
+            make {zextdFromLargeToSmall = zextdFromWord64ToInt8,
+                  zextdFromSmallToLarge = zextdFromInt8ToWord64}
+         val zchckFromWord64ToInt16 = 
+            make {zextdFromLargeToSmall = zextdFromWord64ToInt16,
+                  zextdFromSmallToLarge = zextdFromInt16ToWord64}
+         val zchckFromWord64ToInt32 = 
+            make {zextdFromLargeToSmall = zextdFromWord64ToInt32,
+                  zextdFromSmallToLarge = zextdFromInt32ToWord64}
+         val zchckFromWord64ToInt64 = zextdFromWord64ToInt64
+         val zchckFromWord64ToWord8 = 
+            make {zextdFromLargeToSmall = zextdFromWord64ToWord8,
+                  zextdFromSmallToLarge = zextdFromWord8ToWord64}
+         val zchckFromWord64ToWord16 = 
+            make {zextdFromLargeToSmall = zextdFromWord64ToWord16,
+                  zextdFromSmallToLarge = zextdFromWord16ToWord64}
+         val zchckFromWord64ToWord32 = 
+            make {zextdFromLargeToSmall = zextdFromWord64ToWord32,
+                  zextdFromSmallToLarge = zextdFromWord32ToWord64}
+         val zchckFromWord64ToWord64 = zextdFromWord64ToWord64
+      end
+
+      (* checked sign-extend or low-bits, 
+       * Overflow if composed sign-extend not identity
+       *)
+      local
+         fun (''l, ''s) make {sextdFromLargeToSmall: ''l -> ''s,
+                              sextdFromSmallToLarge: ''s -> ''l} =
+            if Primitive.Controls.detectOverflow
+               then fn (x: ''l) => let 
+                                      val res = sextdFromLargeToSmall x
+                                   in
+                                      if x = (sextdFromSmallToLarge res)
+                                         then res
+                                         else raise Overflow
+                                   end
+               else sextdFromLargeToSmall
+      in
+         val schckFromInt8ToInt8 = sextdFromInt8ToInt8
+         val schckFromInt8ToInt16 = sextdFromInt8ToInt16
+         val schckFromInt8ToInt32 = sextdFromInt8ToInt32
+         val schckFromInt8ToInt64 = sextdFromInt8ToInt64
+         val schckFromInt8ToWord8 = sextdFromInt8ToWord8
+         val schckFromInt8ToWord16 = sextdFromInt8ToWord16
+         val schckFromInt8ToWord32 = sextdFromInt8ToWord32
+         val schckFromInt8ToWord64 = sextdFromInt8ToWord64
+         val schckFromInt16ToInt8 = 
+            make {sextdFromLargeToSmall = sextdFromInt16ToInt8,
+                  sextdFromSmallToLarge = sextdFromInt8ToInt16}
+         val schckFromInt16ToInt16 = sextdFromInt16ToInt16
+         val schckFromInt16ToInt32 = sextdFromInt16ToInt32
+         val schckFromInt16ToInt64 = sextdFromInt16ToInt64
+         val schckFromInt16ToWord8 = 
+            make {sextdFromLargeToSmall = sextdFromInt16ToWord8,
+                  sextdFromSmallToLarge = sextdFromWord8ToInt16}
+         val schckFromInt16ToWord16 = sextdFromInt16ToWord16
+         val schckFromInt16ToWord32 = sextdFromInt16ToWord32
+         val schckFromInt16ToWord64 = sextdFromInt16ToWord64
+         val schckFromInt32ToInt8 = 
+            make {sextdFromLargeToSmall = sextdFromInt32ToInt8,
+                  sextdFromSmallToLarge = sextdFromInt8ToInt32}
+         val schckFromInt32ToInt16 = 
+            make {sextdFromLargeToSmall = sextdFromInt32ToInt16,
+                  sextdFromSmallToLarge = sextdFromInt16ToInt32}
+         val schckFromInt32ToInt32 = sextdFromInt32ToInt32
+         val schckFromInt32ToInt64 = sextdFromInt32ToInt64
+         val schckFromInt32ToWord8 = 
+            make {sextdFromLargeToSmall = sextdFromInt32ToWord8,
+                  sextdFromSmallToLarge = sextdFromWord8ToInt32}
+         val schckFromInt32ToWord16 = 
+            make {sextdFromLargeToSmall = sextdFromInt32ToWord16,
+                  sextdFromSmallToLarge = sextdFromWord16ToInt32}
+         val schckFromInt32ToWord32 = sextdFromInt32ToWord32
+         val schckFromInt32ToWord64 = sextdFromInt32ToWord64
+         val schckFromInt64ToInt8 = 
+            make {sextdFromLargeToSmall = sextdFromInt64ToInt8,
+                  sextdFromSmallToLarge = sextdFromInt8ToInt64}
+         val schckFromInt64ToInt16 = 
+            make {sextdFromLargeToSmall = sextdFromInt64ToInt16,
+                  sextdFromSmallToLarge = sextdFromInt16ToInt64}
+         val schckFromInt64ToInt32 = 
+            make {sextdFromLargeToSmall = sextdFromInt64ToInt32,
+                  sextdFromSmallToLarge = sextdFromInt32ToInt64}
+         val schckFromInt64ToInt64 = sextdFromInt64ToInt64
+         val schckFromInt64ToWord8 = 
+            make {sextdFromLargeToSmall = sextdFromInt64ToWord8,
+                  sextdFromSmallToLarge = sextdFromWord8ToInt64}
+         val schckFromInt64ToWord16 = 
+            make {sextdFromLargeToSmall = sextdFromInt64ToWord16,
+                  sextdFromSmallToLarge = sextdFromWord16ToInt64}
+         val schckFromInt64ToWord32 = 
+            make {sextdFromLargeToSmall = sextdFromInt64ToWord32,
+                  sextdFromSmallToLarge = sextdFromWord32ToInt64}
+         val schckFromInt64ToWord64 = sextdFromInt64ToWord64
+
+         val schckFromWord8ToInt8 = sextdFromWord8ToInt8
+         val schckFromWord8ToInt16 = sextdFromWord8ToInt16
+         val schckFromWord8ToInt32 = sextdFromWord8ToInt32
+         val schckFromWord8ToInt64 = sextdFromWord8ToInt64
+         val schckFromWord8ToWord8 = sextdFromWord8ToWord8
+         val schckFromWord8ToWord16 = sextdFromWord8ToWord16
+         val schckFromWord8ToWord32 = sextdFromWord8ToWord32
+         val schckFromWord8ToWord64 = sextdFromWord8ToWord64
+         val schckFromWord16ToInt8 = 
+            make {sextdFromLargeToSmall = sextdFromWord16ToInt8,
+                  sextdFromSmallToLarge = sextdFromInt8ToWord16}
+         val schckFromWord16ToInt16 = sextdFromWord16ToInt16
+         val schckFromWord16ToInt32 = sextdFromWord16ToInt32
+         val schckFromWord16ToInt64 = sextdFromWord16ToInt64
+         val schckFromWord16ToWord8 = 
+            make {sextdFromLargeToSmall = sextdFromWord16ToWord8,
+                  sextdFromSmallToLarge = sextdFromWord8ToWord16}
+         val schckFromWord16ToWord16 = sextdFromWord16ToWord16
+         val schckFromWord16ToWord32 = sextdFromWord16ToWord32
+         val schckFromWord16ToWord64 = sextdFromWord16ToWord64
+         val schckFromWord32ToInt8 = 
+            make {sextdFromLargeToSmall = sextdFromWord32ToInt8,
+                  sextdFromSmallToLarge = sextdFromInt8ToWord32}
+         val schckFromWord32ToInt16 = 
+            make {sextdFromLargeToSmall = sextdFromWord32ToInt16,
+                  sextdFromSmallToLarge = sextdFromInt16ToWord32}
+         val schckFromWord32ToInt32 = sextdFromWord32ToInt32
+         val schckFromWord32ToInt64 = sextdFromWord32ToInt64
+         val schckFromWord32ToWord8 = 
+            make {sextdFromLargeToSmall = sextdFromWord32ToWord8,
+                  sextdFromSmallToLarge = sextdFromWord8ToWord32}
+         val schckFromWord32ToWord16 = 
+            make {sextdFromLargeToSmall = sextdFromWord32ToWord16,
+                  sextdFromSmallToLarge = sextdFromWord16ToWord32}
+         val schckFromWord32ToWord32 = sextdFromWord32ToWord32
+         val schckFromWord32ToWord64 = sextdFromWord32ToWord64
+         val schckFromWord64ToInt8 = 
+            make {sextdFromLargeToSmall = sextdFromWord64ToInt8,
+                  sextdFromSmallToLarge = sextdFromInt8ToWord64}
+         val schckFromWord64ToInt16 = 
+            make {sextdFromLargeToSmall = sextdFromWord64ToInt16,
+                  sextdFromSmallToLarge = sextdFromInt16ToWord64}
+         val schckFromWord64ToInt32 = 
+            make {sextdFromLargeToSmall = sextdFromWord64ToInt32,
+                  sextdFromSmallToLarge = sextdFromInt32ToWord64}
+         val schckFromWord64ToInt64 = sextdFromWord64ToInt64
+         val schckFromWord64ToWord8 = 
+            make {sextdFromLargeToSmall = sextdFromWord64ToWord8,
+                  sextdFromSmallToLarge = sextdFromWord8ToWord64}
+         val schckFromWord64ToWord16 = 
+            make {sextdFromLargeToSmall = sextdFromWord64ToWord16,
+                  sextdFromSmallToLarge = sextdFromWord16ToWord64}
+         val schckFromWord64ToWord32 = 
+            make {sextdFromLargeToSmall = sextdFromWord64ToWord32,
+                  sextdFromSmallToLarge = sextdFromWord32ToWord64}
+         val schckFromWord64ToWord64 = sextdFromWord64ToWord64
+      end
+
+   end
+
+structure Int8 : PRIM_INTEGER =
+   struct
+      open Int8
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToInt8
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToInt8
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToInt8
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToInt8
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToInt8
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToInt8
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToInt8
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToInt8
+      val zextdToInt8 = IntWordConv.zextdFromInt8ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromInt8ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromInt8ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromInt8ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromInt8ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromInt8ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromInt8ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromInt8ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToInt8
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToInt8
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToInt8
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToInt8
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToInt8
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToInt8
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToInt8
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToInt8
+      val sextdToInt8 = IntWordConv.sextdFromInt8ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromInt8ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromInt8ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromInt8ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromInt8ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromInt8ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromInt8ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromInt8ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToInt8
+      val castFromInt16 = IntWordConv.castFromInt16ToInt8
+      val castFromInt32 = IntWordConv.castFromInt32ToInt8
+      val castFromInt64 = IntWordConv.castFromInt64ToInt8
+      val castFromWord8 = IntWordConv.castFromWord8ToInt8
+      val castFromWord16 = IntWordConv.castFromWord16ToInt8
+      val castFromWord32 = IntWordConv.castFromWord32ToInt8
+      val castFromWord64 = IntWordConv.castFromWord64ToInt8
+      val castToInt8 = IntWordConv.castFromInt8ToInt8
+      val castToInt16 = IntWordConv.castFromInt8ToInt16
+      val castToInt32 = IntWordConv.castFromInt8ToInt32
+      val castToInt64 = IntWordConv.castFromInt8ToInt64
+      val castToWord8 = IntWordConv.castFromInt8ToWord8
+      val castToWord16 = IntWordConv.castFromInt8ToWord16
+      val castToWord32 = IntWordConv.castFromInt8ToWord32
+      val castToWord64 = IntWordConv.castFromInt8ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToInt8
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToInt8
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToInt8
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToInt8
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToInt8
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToInt8
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToInt8
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToInt8
+      val zchckToInt8 = IntWordConv.zchckFromInt8ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromInt8ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromInt8ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromInt8ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromInt8ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromInt8ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromInt8ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromInt8ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToInt8
+      val schckFromInt16 = IntWordConv.schckFromInt16ToInt8
+      val schckFromInt32 = IntWordConv.schckFromInt32ToInt8
+      val schckFromInt64 = IntWordConv.schckFromInt64ToInt8
+      val schckFromWord8 = IntWordConv.schckFromWord8ToInt8
+      val schckFromWord16 = IntWordConv.schckFromWord16ToInt8
+      val schckFromWord32 = IntWordConv.schckFromWord32ToInt8
+      val schckFromWord64 = IntWordConv.schckFromWord64ToInt8
+      val schckToInt8 = IntWordConv.schckFromInt8ToInt8
+      val schckToInt16 = IntWordConv.schckFromInt8ToInt16
+      val schckToInt32 = IntWordConv.schckFromInt8ToInt32
+      val schckToInt64 = IntWordConv.schckFromInt8ToInt64
+      val schckToWord8 = IntWordConv.schckFromInt8ToWord8
+      val schckToWord16 = IntWordConv.schckFromInt8ToWord16
+      val schckToWord32 = IntWordConv.schckFromInt8ToWord32
+      val schckToWord64 = IntWordConv.schckFromInt8ToWord64
+   end
+
+structure Int16 : PRIM_INTEGER  =
+   struct
+      open Int16
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToInt16
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToInt16
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToInt16
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToInt16
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToInt16
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToInt16
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToInt16
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToInt16
+      val zextdToInt8 = IntWordConv.zextdFromInt16ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromInt16ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromInt16ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromInt16ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromInt16ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromInt16ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromInt16ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromInt16ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToInt16
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToInt16
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToInt16
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToInt16
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToInt16
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToInt16
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToInt16
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToInt16
+      val sextdToInt8 = IntWordConv.sextdFromInt16ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromInt16ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromInt16ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromInt16ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromInt16ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromInt16ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromInt16ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromInt16ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToInt16
+      val castFromInt16 = IntWordConv.castFromInt16ToInt16
+      val castFromInt32 = IntWordConv.castFromInt32ToInt16
+      val castFromInt64 = IntWordConv.castFromInt64ToInt16
+      val castFromWord8 = IntWordConv.castFromWord8ToInt16
+      val castFromWord16 = IntWordConv.castFromWord16ToInt16
+      val castFromWord32 = IntWordConv.castFromWord32ToInt16
+      val castFromWord64 = IntWordConv.castFromWord64ToInt16
+      val castToInt8 = IntWordConv.castFromInt16ToInt8
+      val castToInt16 = IntWordConv.castFromInt16ToInt16
+      val castToInt32 = IntWordConv.castFromInt16ToInt32
+      val castToInt64 = IntWordConv.castFromInt16ToInt64
+      val castToWord8 = IntWordConv.castFromInt16ToWord8
+      val castToWord16 = IntWordConv.castFromInt16ToWord16
+      val castToWord32 = IntWordConv.castFromInt16ToWord32
+      val castToWord64 = IntWordConv.castFromInt16ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToInt16
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToInt16
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToInt16
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToInt16
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToInt16
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToInt16
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToInt16
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToInt16
+      val zchckToInt8 = IntWordConv.zchckFromInt16ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromInt16ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromInt16ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromInt16ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromInt16ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromInt16ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromInt16ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromInt16ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToInt16
+      val schckFromInt16 = IntWordConv.schckFromInt16ToInt16
+      val schckFromInt32 = IntWordConv.schckFromInt32ToInt16
+      val schckFromInt64 = IntWordConv.schckFromInt64ToInt16
+      val schckFromWord8 = IntWordConv.schckFromWord8ToInt16
+      val schckFromWord16 = IntWordConv.schckFromWord16ToInt16
+      val schckFromWord32 = IntWordConv.schckFromWord32ToInt16
+      val schckFromWord64 = IntWordConv.schckFromWord64ToInt16
+      val schckToInt8 = IntWordConv.schckFromInt16ToInt8
+      val schckToInt16 = IntWordConv.schckFromInt16ToInt16
+      val schckToInt32 = IntWordConv.schckFromInt16ToInt32
+      val schckToInt64 = IntWordConv.schckFromInt16ToInt64
+      val schckToWord8 = IntWordConv.schckFromInt16ToWord8
+      val schckToWord16 = IntWordConv.schckFromInt16ToWord16
+      val schckToWord32 = IntWordConv.schckFromInt16ToWord32
+      val schckToWord64 = IntWordConv.schckFromInt16ToWord64
+   end
+
+structure Int32 : PRIM_INTEGER  =
+   struct
+      open Int32
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToInt32
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToInt32
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToInt32
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToInt32
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToInt32
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToInt32
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToInt32
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToInt32
+      val zextdToInt8 = IntWordConv.zextdFromInt32ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromInt32ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromInt32ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromInt32ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromInt32ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromInt32ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromInt32ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromInt32ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToInt32
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToInt32
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToInt32
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToInt32
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToInt32
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToInt32
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToInt32
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToInt32
+      val sextdToInt8 = IntWordConv.sextdFromInt32ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromInt32ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromInt32ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromInt32ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromInt32ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromInt32ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromInt32ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromInt32ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToInt32
+      val castFromInt16 = IntWordConv.castFromInt16ToInt32
+      val castFromInt32 = IntWordConv.castFromInt32ToInt32
+      val castFromInt64 = IntWordConv.castFromInt64ToInt32
+      val castFromWord8 = IntWordConv.castFromWord8ToInt32
+      val castFromWord16 = IntWordConv.castFromWord16ToInt32
+      val castFromWord32 = IntWordConv.castFromWord32ToInt32
+      val castFromWord64 = IntWordConv.castFromWord64ToInt32
+      val castToInt8 = IntWordConv.castFromInt32ToInt8
+      val castToInt16 = IntWordConv.castFromInt32ToInt16
+      val castToInt32 = IntWordConv.castFromInt32ToInt32
+      val castToInt64 = IntWordConv.castFromInt32ToInt64
+      val castToWord8 = IntWordConv.castFromInt32ToWord8
+      val castToWord16 = IntWordConv.castFromInt32ToWord16
+      val castToWord32 = IntWordConv.castFromInt32ToWord32
+      val castToWord64 = IntWordConv.castFromInt32ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToInt32
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToInt32
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToInt32
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToInt32
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToInt32
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToInt32
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToInt32
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToInt32
+      val zchckToInt8 = IntWordConv.zchckFromInt32ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromInt32ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromInt32ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromInt32ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromInt32ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromInt32ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromInt32ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromInt32ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToInt32
+      val schckFromInt16 = IntWordConv.schckFromInt16ToInt32
+      val schckFromInt32 = IntWordConv.schckFromInt32ToInt32
+      val schckFromInt64 = IntWordConv.schckFromInt64ToInt32
+      val schckFromWord8 = IntWordConv.schckFromWord8ToInt32
+      val schckFromWord16 = IntWordConv.schckFromWord16ToInt32
+      val schckFromWord32 = IntWordConv.schckFromWord32ToInt32
+      val schckFromWord64 = IntWordConv.schckFromWord64ToInt32
+      val schckToInt8 = IntWordConv.schckFromInt32ToInt8
+      val schckToInt16 = IntWordConv.schckFromInt32ToInt16
+      val schckToInt32 = IntWordConv.schckFromInt32ToInt32
+      val schckToInt64 = IntWordConv.schckFromInt32ToInt64
+      val schckToWord8 = IntWordConv.schckFromInt32ToWord8
+      val schckToWord16 = IntWordConv.schckFromInt32ToWord16
+      val schckToWord32 = IntWordConv.schckFromInt32ToWord32
+      val schckToWord64 = IntWordConv.schckFromInt32ToWord64
+   end
+
+structure Int64 : PRIM_INTEGER  =
+   struct
+      open Int64
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToInt64
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToInt64
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToInt64
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToInt64
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToInt64
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToInt64
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToInt64
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToInt64
+      val zextdToInt8 = IntWordConv.zextdFromInt64ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromInt64ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromInt64ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromInt64ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromInt64ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromInt64ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromInt64ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromInt64ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToInt64
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToInt64
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToInt64
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToInt64
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToInt64
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToInt64
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToInt64
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToInt64
+      val sextdToInt8 = IntWordConv.sextdFromInt64ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromInt64ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromInt64ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromInt64ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromInt64ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromInt64ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromInt64ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromInt64ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToInt64
+      val castFromInt16 = IntWordConv.castFromInt16ToInt64
+      val castFromInt32 = IntWordConv.castFromInt32ToInt64
+      val castFromInt64 = IntWordConv.castFromInt64ToInt64
+      val castFromWord8 = IntWordConv.castFromWord8ToInt64
+      val castFromWord16 = IntWordConv.castFromWord16ToInt64
+      val castFromWord32 = IntWordConv.castFromWord32ToInt64
+      val castFromWord64 = IntWordConv.castFromWord64ToInt64
+      val castToInt8 = IntWordConv.castFromInt64ToInt8
+      val castToInt16 = IntWordConv.castFromInt64ToInt16
+      val castToInt32 = IntWordConv.castFromInt64ToInt32
+      val castToInt64 = IntWordConv.castFromInt64ToInt64
+      val castToWord8 = IntWordConv.castFromInt64ToWord8
+      val castToWord16 = IntWordConv.castFromInt64ToWord16
+      val castToWord32 = IntWordConv.castFromInt64ToWord32
+      val castToWord64 = IntWordConv.castFromInt64ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToInt64
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToInt64
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToInt64
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToInt64
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToInt64
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToInt64
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToInt64
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToInt64
+      val zchckToInt8 = IntWordConv.zchckFromInt64ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromInt64ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromInt64ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromInt64ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromInt64ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromInt64ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromInt64ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromInt64ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToInt64
+      val schckFromInt16 = IntWordConv.schckFromInt16ToInt64
+      val schckFromInt32 = IntWordConv.schckFromInt32ToInt64
+      val schckFromInt64 = IntWordConv.schckFromInt64ToInt64
+      val schckFromWord8 = IntWordConv.schckFromWord8ToInt64
+      val schckFromWord16 = IntWordConv.schckFromWord16ToInt64
+      val schckFromWord32 = IntWordConv.schckFromWord32ToInt64
+      val schckFromWord64 = IntWordConv.schckFromWord64ToInt64
+      val schckToInt8 = IntWordConv.schckFromInt64ToInt8
+      val schckToInt16 = IntWordConv.schckFromInt64ToInt16
+      val schckToInt32 = IntWordConv.schckFromInt64ToInt32
+      val schckToInt64 = IntWordConv.schckFromInt64ToInt64
+      val schckToWord8 = IntWordConv.schckFromInt64ToWord8
+      val schckToWord16 = IntWordConv.schckFromInt64ToWord16
+      val schckToWord32 = IntWordConv.schckFromInt64ToWord32
+      val schckToWord64 = IntWordConv.schckFromInt64ToWord64
+   end
+
+structure Word8 : PRIM_WORD  =
+   struct
+      open Word8
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToWord8
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToWord8
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToWord8
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToWord8
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToWord8
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToWord8
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToWord8
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToWord8
+      val zextdToInt8 = IntWordConv.zextdFromWord8ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromWord8ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromWord8ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromWord8ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromWord8ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromWord8ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromWord8ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromWord8ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToWord8
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToWord8
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToWord8
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToWord8
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToWord8
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToWord8
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToWord8
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToWord8
+      val sextdToInt8 = IntWordConv.sextdFromWord8ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromWord8ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromWord8ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromWord8ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromWord8ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromWord8ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromWord8ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromWord8ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToWord8
+      val castFromInt16 = IntWordConv.castFromInt16ToWord8
+      val castFromInt32 = IntWordConv.castFromInt32ToWord8
+      val castFromInt64 = IntWordConv.castFromInt64ToWord8
+      val castFromWord8 = IntWordConv.castFromWord8ToWord8
+      val castFromWord16 = IntWordConv.castFromWord16ToWord8
+      val castFromWord32 = IntWordConv.castFromWord32ToWord8
+      val castFromWord64 = IntWordConv.castFromWord64ToWord8
+      val castToInt8 = IntWordConv.castFromWord8ToInt8
+      val castToInt16 = IntWordConv.castFromWord8ToInt16
+      val castToInt32 = IntWordConv.castFromWord8ToInt32
+      val castToInt64 = IntWordConv.castFromWord8ToInt64
+      val castToWord8 = IntWordConv.castFromWord8ToWord8
+      val castToWord16 = IntWordConv.castFromWord8ToWord16
+      val castToWord32 = IntWordConv.castFromWord8ToWord32
+      val castToWord64 = IntWordConv.castFromWord8ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToWord8
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToWord8
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToWord8
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToWord8
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToWord8
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToWord8
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToWord8
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToWord8
+      val zchckToInt8 = IntWordConv.zchckFromWord8ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromWord8ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromWord8ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromWord8ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromWord8ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromWord8ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromWord8ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromWord8ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToWord8
+      val schckFromInt16 = IntWordConv.schckFromInt16ToWord8
+      val schckFromInt32 = IntWordConv.schckFromInt32ToWord8
+      val schckFromInt64 = IntWordConv.schckFromInt64ToWord8
+      val schckFromWord8 = IntWordConv.schckFromWord8ToWord8
+      val schckFromWord16 = IntWordConv.schckFromWord16ToWord8
+      val schckFromWord32 = IntWordConv.schckFromWord32ToWord8
+      val schckFromWord64 = IntWordConv.schckFromWord64ToWord8
+      val schckToInt8 = IntWordConv.schckFromWord8ToInt8
+      val schckToInt16 = IntWordConv.schckFromWord8ToInt16
+      val schckToInt32 = IntWordConv.schckFromWord8ToInt32
+      val schckToInt64 = IntWordConv.schckFromWord8ToInt64
+      val schckToWord8 = IntWordConv.schckFromWord8ToWord8
+      val schckToWord16 = IntWordConv.schckFromWord8ToWord16
+      val schckToWord32 = IntWordConv.schckFromWord8ToWord32
+      val schckToWord64 = IntWordConv.schckFromWord8ToWord64
+   end
+
+structure Word16 : PRIM_WORD =
+   struct
+      open Word16
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToWord16
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToWord16
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToWord16
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToWord16
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToWord16
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToWord16
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToWord16
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToWord16
+      val zextdToInt8 = IntWordConv.zextdFromWord16ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromWord16ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromWord16ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromWord16ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromWord16ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromWord16ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromWord16ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromWord16ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToWord16
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToWord16
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToWord16
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToWord16
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToWord16
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToWord16
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToWord16
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToWord16
+      val sextdToInt8 = IntWordConv.sextdFromWord16ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromWord16ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromWord16ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromWord16ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromWord16ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromWord16ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromWord16ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromWord16ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToWord16
+      val castFromInt16 = IntWordConv.castFromInt16ToWord16
+      val castFromInt32 = IntWordConv.castFromInt32ToWord16
+      val castFromInt64 = IntWordConv.castFromInt64ToWord16
+      val castFromWord8 = IntWordConv.castFromWord8ToWord16
+      val castFromWord16 = IntWordConv.castFromWord16ToWord16
+      val castFromWord32 = IntWordConv.castFromWord32ToWord16
+      val castFromWord64 = IntWordConv.castFromWord64ToWord16
+      val castToInt8 = IntWordConv.castFromWord16ToInt8
+      val castToInt16 = IntWordConv.castFromWord16ToInt16
+      val castToInt32 = IntWordConv.castFromWord16ToInt32
+      val castToInt64 = IntWordConv.castFromWord16ToInt64
+      val castToWord8 = IntWordConv.castFromWord16ToWord8
+      val castToWord16 = IntWordConv.castFromWord16ToWord16
+      val castToWord32 = IntWordConv.castFromWord16ToWord32
+      val castToWord64 = IntWordConv.castFromWord16ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToWord16
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToWord16
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToWord16
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToWord16
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToWord16
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToWord16
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToWord16
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToWord16
+      val zchckToInt8 = IntWordConv.zchckFromWord16ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromWord16ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromWord16ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromWord16ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromWord16ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromWord16ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromWord16ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromWord16ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToWord16
+      val schckFromInt16 = IntWordConv.schckFromInt16ToWord16
+      val schckFromInt32 = IntWordConv.schckFromInt32ToWord16
+      val schckFromInt64 = IntWordConv.schckFromInt64ToWord16
+      val schckFromWord8 = IntWordConv.schckFromWord8ToWord16
+      val schckFromWord16 = IntWordConv.schckFromWord16ToWord16
+      val schckFromWord32 = IntWordConv.schckFromWord32ToWord16
+      val schckFromWord64 = IntWordConv.schckFromWord64ToWord16
+      val schckToInt8 = IntWordConv.schckFromWord16ToInt8
+      val schckToInt16 = IntWordConv.schckFromWord16ToInt16
+      val schckToInt32 = IntWordConv.schckFromWord16ToInt32
+      val schckToInt64 = IntWordConv.schckFromWord16ToInt64
+      val schckToWord8 = IntWordConv.schckFromWord16ToWord8
+      val schckToWord16 = IntWordConv.schckFromWord16ToWord16
+      val schckToWord32 = IntWordConv.schckFromWord16ToWord32
+      val schckToWord64 = IntWordConv.schckFromWord16ToWord64
+   end
+
+structure Word32 : PRIM_WORD =
+   struct
+      open Word32
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToWord32
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToWord32
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToWord32
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToWord32
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToWord32
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToWord32
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToWord32
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToWord32
+      val zextdToInt8 = IntWordConv.zextdFromWord32ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromWord32ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromWord32ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromWord32ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromWord32ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromWord32ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromWord32ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromWord32ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToWord32
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToWord32
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToWord32
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToWord32
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToWord32
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToWord32
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToWord32
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToWord32
+      val sextdToInt8 = IntWordConv.sextdFromWord32ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromWord32ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromWord32ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromWord32ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromWord32ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromWord32ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromWord32ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromWord32ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToWord32
+      val castFromInt16 = IntWordConv.castFromInt16ToWord32
+      val castFromInt32 = IntWordConv.castFromInt32ToWord32
+      val castFromInt64 = IntWordConv.castFromInt64ToWord32
+      val castFromWord8 = IntWordConv.castFromWord8ToWord32
+      val castFromWord16 = IntWordConv.castFromWord16ToWord32
+      val castFromWord32 = IntWordConv.castFromWord32ToWord32
+      val castFromWord64 = IntWordConv.castFromWord64ToWord32
+      val castToInt8 = IntWordConv.castFromWord32ToInt8
+      val castToInt16 = IntWordConv.castFromWord32ToInt16
+      val castToInt32 = IntWordConv.castFromWord32ToInt32
+      val castToInt64 = IntWordConv.castFromWord32ToInt64
+      val castToWord8 = IntWordConv.castFromWord32ToWord8
+      val castToWord16 = IntWordConv.castFromWord32ToWord16
+      val castToWord32 = IntWordConv.castFromWord32ToWord32
+      val castToWord64 = IntWordConv.castFromWord32ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToWord32
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToWord32
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToWord32
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToWord32
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToWord32
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToWord32
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToWord32
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToWord32
+      val zchckToInt8 = IntWordConv.zchckFromWord32ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromWord32ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromWord32ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromWord32ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromWord32ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromWord32ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromWord32ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromWord32ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToWord32
+      val schckFromInt16 = IntWordConv.schckFromInt16ToWord32
+      val schckFromInt32 = IntWordConv.schckFromInt32ToWord32
+      val schckFromInt64 = IntWordConv.schckFromInt64ToWord32
+      val schckFromWord8 = IntWordConv.schckFromWord8ToWord32
+      val schckFromWord16 = IntWordConv.schckFromWord16ToWord32
+      val schckFromWord32 = IntWordConv.schckFromWord32ToWord32
+      val schckFromWord64 = IntWordConv.schckFromWord64ToWord32
+      val schckToInt8 = IntWordConv.schckFromWord32ToInt8
+      val schckToInt16 = IntWordConv.schckFromWord32ToInt16
+      val schckToInt32 = IntWordConv.schckFromWord32ToInt32
+      val schckToInt64 = IntWordConv.schckFromWord32ToInt64
+      val schckToWord8 = IntWordConv.schckFromWord32ToWord8
+      val schckToWord16 = IntWordConv.schckFromWord32ToWord16
+      val schckToWord32 = IntWordConv.schckFromWord32ToWord32
+      val schckToWord64 = IntWordConv.schckFromWord32ToWord64
+   end
+
+structure Word64 : PRIM_WORD =
+   struct
+      open Word64
+
+      val zextdFromInt8 = IntWordConv.zextdFromInt8ToWord64
+      val zextdFromInt16 = IntWordConv.zextdFromInt16ToWord64
+      val zextdFromInt32 = IntWordConv.zextdFromInt32ToWord64
+      val zextdFromInt64 = IntWordConv.zextdFromInt64ToWord64
+      val zextdFromWord8 = IntWordConv.zextdFromWord8ToWord64
+      val zextdFromWord16 = IntWordConv.zextdFromWord16ToWord64
+      val zextdFromWord32 = IntWordConv.zextdFromWord32ToWord64
+      val zextdFromWord64 = IntWordConv.zextdFromWord64ToWord64
+      val zextdToInt8 = IntWordConv.zextdFromWord64ToInt8
+      val zextdToInt16 = IntWordConv.zextdFromWord64ToInt16
+      val zextdToInt32 = IntWordConv.zextdFromWord64ToInt32
+      val zextdToInt64 = IntWordConv.zextdFromWord64ToInt64
+      val zextdToWord8 = IntWordConv.zextdFromWord64ToWord8
+      val zextdToWord16 = IntWordConv.zextdFromWord64ToWord16
+      val zextdToWord32 = IntWordConv.zextdFromWord64ToWord32
+      val zextdToWord64 = IntWordConv.zextdFromWord64ToWord64
+
+      val sextdFromInt8 = IntWordConv.sextdFromInt8ToWord64
+      val sextdFromInt16 = IntWordConv.sextdFromInt16ToWord64
+      val sextdFromInt32 = IntWordConv.sextdFromInt32ToWord64
+      val sextdFromInt64 = IntWordConv.sextdFromInt64ToWord64
+      val sextdFromWord8 = IntWordConv.sextdFromWord8ToWord64
+      val sextdFromWord16 = IntWordConv.sextdFromWord16ToWord64
+      val sextdFromWord32 = IntWordConv.sextdFromWord32ToWord64
+      val sextdFromWord64 = IntWordConv.sextdFromWord64ToWord64
+      val sextdToInt8 = IntWordConv.sextdFromWord64ToInt8
+      val sextdToInt16 = IntWordConv.sextdFromWord64ToInt16
+      val sextdToInt32 = IntWordConv.sextdFromWord64ToInt32
+      val sextdToInt64 = IntWordConv.sextdFromWord64ToInt64
+      val sextdToWord8 = IntWordConv.sextdFromWord64ToWord8
+      val sextdToWord16 = IntWordConv.sextdFromWord64ToWord16
+      val sextdToWord32 = IntWordConv.sextdFromWord64ToWord32
+      val sextdToWord64 = IntWordConv.sextdFromWord64ToWord64
+
+      val castFromInt8 = IntWordConv.castFromInt8ToWord64
+      val castFromInt16 = IntWordConv.castFromInt16ToWord64
+      val castFromInt32 = IntWordConv.castFromInt32ToWord64
+      val castFromInt64 = IntWordConv.castFromInt64ToWord64
+      val castFromWord8 = IntWordConv.castFromWord8ToWord64
+      val castFromWord16 = IntWordConv.castFromWord16ToWord64
+      val castFromWord32 = IntWordConv.castFromWord32ToWord64
+      val castFromWord64 = IntWordConv.castFromWord64ToWord64
+      val castToInt8 = IntWordConv.castFromWord64ToInt8
+      val castToInt16 = IntWordConv.castFromWord64ToInt16
+      val castToInt32 = IntWordConv.castFromWord64ToInt32
+      val castToInt64 = IntWordConv.castFromWord64ToInt64
+      val castToWord8 = IntWordConv.castFromWord64ToWord8
+      val castToWord16 = IntWordConv.castFromWord64ToWord16
+      val castToWord32 = IntWordConv.castFromWord64ToWord32
+      val castToWord64 = IntWordConv.castFromWord64ToWord64
+
+      val zchckFromInt8 = IntWordConv.zchckFromInt8ToWord64
+      val zchckFromInt16 = IntWordConv.zchckFromInt16ToWord64
+      val zchckFromInt32 = IntWordConv.zchckFromInt32ToWord64
+      val zchckFromInt64 = IntWordConv.zchckFromInt64ToWord64
+      val zchckFromWord8 = IntWordConv.zchckFromWord8ToWord64
+      val zchckFromWord16 = IntWordConv.zchckFromWord16ToWord64
+      val zchckFromWord32 = IntWordConv.zchckFromWord32ToWord64
+      val zchckFromWord64 = IntWordConv.zchckFromWord64ToWord64
+      val zchckToInt8 = IntWordConv.zchckFromWord64ToInt8
+      val zchckToInt16 = IntWordConv.zchckFromWord64ToInt16
+      val zchckToInt32 = IntWordConv.zchckFromWord64ToInt32
+      val zchckToInt64 = IntWordConv.zchckFromWord64ToInt64
+      val zchckToWord8 = IntWordConv.zchckFromWord64ToWord8
+      val zchckToWord16 = IntWordConv.zchckFromWord64ToWord16
+      val zchckToWord32 = IntWordConv.zchckFromWord64ToWord32
+      val zchckToWord64 = IntWordConv.zchckFromWord64ToWord64
+
+      val schckFromInt8 = IntWordConv.schckFromInt8ToWord64
+      val schckFromInt16 = IntWordConv.schckFromInt16ToWord64
+      val schckFromInt32 = IntWordConv.schckFromInt32ToWord64
+      val schckFromInt64 = IntWordConv.schckFromInt64ToWord64
+      val schckFromWord8 = IntWordConv.schckFromWord8ToWord64
+      val schckFromWord16 = IntWordConv.schckFromWord16ToWord64
+      val schckFromWord32 = IntWordConv.schckFromWord32ToWord64
+      val schckFromWord64 = IntWordConv.schckFromWord64ToWord64
+      val schckToInt8 = IntWordConv.schckFromWord64ToInt8
+      val schckToInt16 = IntWordConv.schckFromWord64ToInt16
+      val schckToInt32 = IntWordConv.schckFromWord64ToInt32
+      val schckToInt64 = IntWordConv.schckFromWord64ToInt64
+      val schckToWord8 = IntWordConv.schckFromWord64ToWord8
+      val schckToWord16 = IntWordConv.schckFromWord64ToWord16
+      val schckToWord32 = IntWordConv.schckFromWord64ToWord32
+      val schckToWord64 = IntWordConv.schckFromWord64ToWord64
+   end
+
+end

Added: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num0.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num0.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -0,0 +1,281 @@
+(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ * Copyright (C) 1997-2000 NEC Research Institute.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+signature MKNUM0_ARG =
+   sig
+      structure Int: PRIM_INTEGER
+      structure Word: PRIM_WORD
+      val idFromIntToWord: Int.int -> Word.word
+      val idFromWordToInt: Word.word -> Int.int
+   end
+signature PRIM_INTEGER =
+   sig
+      include PRIM_INTEGER
+
+      val maxInt': int
+      val minInt': int
+      val maxInt: int option
+      val minInt: int option
+
+      val zero: int
+      val one: int
+
+      val abs: int -> int
+      val div: int * int -> int
+      val mod: int * int -> int
+      val quot: int * int -> int
+      val rem: int * int -> int
+
+      val ltu: int * int -> bool
+      val leu: int * int -> bool
+      val gtu: int * int -> bool
+      val geu: int * int -> bool
+
+      val andb : int * int -> int
+      val <<? : int * Primitive.Word32.word -> int
+      val notb : int -> int
+      val orb : int * int -> int
+      val rolUnsafe : int * Primitive.Word32.word -> int
+      val rorUnsafe : int * Primitive.Word32.word -> int
+      val ~>>? : int * Primitive.Word32.word -> int
+      val >>? : int * Primitive.Word32.word -> int
+      val xorb : int * int -> int
+
+      val power: {base:int, exp: int} -> int
+      val log2: int -> Primitive.Int32.int
+      val log2Word: int -> Primitive.Word32.word
+   end
+signature PRIM_WORD =
+   sig
+      include PRIM_WORD
+      
+      val zero: word
+      val one: word
+   
+      val div: word * word -> word
+      val mod: word * word -> word
+
+      val log2: word -> Primitive.Int32.int
+      val log2Word: word -> Primitive.Word32.word
+   end
+
+functor MkNum0 (S: MKNUM0_ARG): sig
+                                   structure Int: PRIM_INTEGER
+                                   structure Word: PRIM_WORD
+                                end =
+   struct
+      open S
+
+      val _ =
+         if Int.sizeInBits <> Word.sizeInBits
+            orelse Int.sizeInBitsWord <> Word.sizeInBitsWord
+            then raise Primitive.Exn.Fail8 "MkNum0: Int.sizeInBits <> Word.sizeInBits"
+            else ()
+
+      structure Word =
+         struct
+            open Word
+
+            val zero = zextdFromWord32 0w0
+            val one = zextdFromWord32 0w1
+
+            local
+               fun make f (w, w') =
+                  if Primitive.Controls.safe andalso w' = zero
+                     then raise Div
+                     else f (w, w')
+            in
+               val op div = make (op quotUnsafe)
+               val op mod = make (op remUnsafe)
+            end
+
+            fun log2Word w =
+               let
+                  fun loop (n, s, acc) =
+                     if n = one
+                        then acc
+                        else let
+                                val (n, acc) =
+                                   if n >= <<? (one, s)
+                                      then (>>? (n, s), Primitive.Word32.+ (acc, s))
+                                      else (n, acc)
+                             in
+                                loop (n, Primitive.Word32.>>? (s, 0w1), acc)
+                             end
+               in
+                  if Primitive.Controls.safe andalso w = zero
+                     then raise Domain
+                     else loop (w, Primitive.Word32.>>? (sizeInBitsWord, 0w1), 0w0)
+               end
+            fun log2 w = Primitive.IntWordConv.zextdFromWord32ToInt32 (log2Word w)
+         end
+
+      structure Int = 
+         struct
+            open Int
+
+            val zero = zextdFromInt32 0
+            val one = zextdFromInt32 1
+
+            local
+               fun makeBinop f =
+                  fn (x: int, y: int) =>
+                  idFromWordToInt
+                  (f (idFromIntToWord x, idFromIntToWord y))
+               fun makeUnop f =
+                  fn (x: int) =>
+                  idFromWordToInt
+                  (f (idFromIntToWord x))
+               fun makeShop f =
+                  fn (x: int, w: Primitive.Word32.word) =>
+                  idFromWordToInt
+                  (f (idFromIntToWord x, w))
+            in
+               val andb = makeBinop Word.andb
+               val <<? = makeShop Word.<<?
+               val notb = makeUnop Word.notb
+               val orb = makeBinop Word.orb
+               val rolUnsafe = makeShop Word.rolUnsafe
+               val rorUnsafe = makeShop Word.rorUnsafe
+               val ~>>? = makeShop Word.~>>?
+               val >>? = makeShop Word.>>?
+               val xorb = makeBinop Word.xorb
+            end
+            fun log2 i = Word.log2 (idFromIntToWord i)
+            fun log2Word i = Word.log2Word (idFromIntToWord i)
+
+            val minInt' = <<? (one, Primitive.Word32.- (sizeInBitsWord, 0w1))
+            val maxInt' = >>? (notb zero, 0w1)
+            val minInt = SOME minInt'
+            val maxInt = SOME maxInt'
+
+            fun abs (x: int) = if x < zero then ~ x else x
+
+            fun quot (x, y) =
+               if Primitive.Controls.safe 
+                  andalso y = zero
+                  then raise Div
+                  else if Primitive.Controls.detectOverflow 
+                          andalso x = minInt' andalso y = ~one
+                          then raise Overflow
+                          else quotUnsafe (x, y)
+                       
+            fun rem (x, y) =
+               if Primitive.Controls.safe 
+                  andalso y = zero
+                  then raise Div
+                  else if x = minInt' andalso y = ~one
+                          then zero
+                          else remUnsafe (x, y)
+                       
+            fun x div y =
+               if x >= zero
+                  then if y > zero
+                          then quotUnsafe (x, y)
+                          else if y < zero
+                                  then if x = zero
+                                          then zero
+                                          else quotUnsafe (x -? one, y) -? one
+                                  else raise Div
+                  else if y < zero
+                          then if Primitive.Controls.detectOverflow 
+                                  andalso x = minInt' andalso y = ~one
+                                  then raise Overflow
+                                  else quotUnsafe (x, y)
+                          else if y > zero
+                                  then quotUnsafe (x +? one, y) -? one
+                                  else raise Div
+                                     
+            fun x mod y =
+               if x >= zero
+                  then if y > zero
+                          then remUnsafe (x, y)
+                          else if y < zero
+                                  then if x = zero
+                                          then zero
+                                          else remUnsafe (x -? one, y) +? (y + one)
+                                  else raise Div
+                  else if y < zero
+                          then if x = minInt' andalso y = ~one
+                                  then zero
+                                  else remUnsafe (x, y)
+                          else if y > zero
+                                  then remUnsafe (x +? one, y) +? (y -? one)
+                                  else raise Div
+
+            local
+               structure S = 
+                  UnsignedIntegralComparisons
+                  (type int = int
+                   type word = Word.word
+                   val idFromIntToWord = idFromIntToWord
+                   val op < = Word.<)
+            in
+               open S
+            end
+
+            fun power {base, exp} =
+               if Primitive.Controls.safe 
+                  andalso exp < zero
+                  then raise Primitive.Exn.Fail8 "Int.power"
+                  else let
+                          fun loop (exp, accum) =
+                             if exp <= zero
+                                then accum
+                                else loop (exp - one, base * accum)
+                       in loop (exp, one)
+                       end
+         end
+
+   end
+
+structure Primitive = struct
+open Primitive
+
+local
+   structure S =
+      MkNum0 (structure Int = Int8
+              structure Word = Word8
+              val idFromIntToWord = IntWordConv.idFromInt8ToWord8
+              val idFromWordToInt = IntWordConv.idFromWord8ToInt8)
+in
+   structure Int8 : PRIM_INTEGER = S.Int
+   structure Word8 : PRIM_WORD = S.Word
+end
+local
+   structure S =
+      MkNum0 (structure Int = Int16
+              structure Word = Word16
+              val idFromIntToWord = IntWordConv.idFromInt16ToWord16
+              val idFromWordToInt = IntWordConv.idFromWord16ToInt16)
+in
+   structure Int16 : PRIM_INTEGER = S.Int
+   structure Word16 : PRIM_WORD = S.Word
+end
+local
+   structure S =
+      MkNum0 (structure Int = Int32
+              structure Word = Word32
+              val idFromIntToWord = IntWordConv.idFromInt32ToWord32
+              val idFromWordToInt = IntWordConv.idFromWord32ToInt32)
+in
+   structure Int32 : PRIM_INTEGER = S.Int
+   structure Word32 : PRIM_WORD = S.Word
+end
+local
+   structure S =
+      MkNum0 (structure Int = Int64
+              structure Word = Word64
+              val idFromIntToWord = IntWordConv.idFromInt64ToWord64
+              val idFromWordToInt = IntWordConv.idFromWord64ToInt64)
+in
+   structure Int64 : PRIM_INTEGER = S.Int
+   structure Word64 : PRIM_WORD = S.Word
+end
+
+end

Added: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num1.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num1.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/num1.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -0,0 +1,999 @@
+(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ * Copyright (C) 1997-2000 NEC Research Institute.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+signature MKNUM1_ARG =
+   sig
+      type num
+
+      val zextdFromInt8: Primitive.Int8.int -> num
+      val zextdFromInt16: Primitive.Int16.int -> num
+      val zextdFromInt32: Primitive.Int32.int -> num
+      val zextdFromInt64: Primitive.Int64.int -> num
+      val zextdFromIntInf: Primitive.IntInf.int -> num
+      val zextdFromWord8: Primitive.Word8.word -> num
+      val zextdFromWord16: Primitive.Word16.word -> num
+      val zextdFromWord32: Primitive.Word32.word -> num
+      val zextdFromWord64: Primitive.Word64.word -> num
+      val zextdToInt8: num -> Primitive.Int8.int
+      val zextdToInt16: num -> Primitive.Int16.int
+      val zextdToInt32: num -> Primitive.Int32.int
+      val zextdToInt64: num -> Primitive.Int64.int
+      val zextdToIntInf: num -> Primitive.IntInf.int
+      val zextdToWord8: num -> Primitive.Word8.word
+      val zextdToWord16: num -> Primitive.Word16.word
+      val zextdToWord32: num -> Primitive.Word32.word
+      val zextdToWord64: num -> Primitive.Word64.word
+
+      val sextdFromInt8: Primitive.Int8.int -> num
+      val sextdFromInt16: Primitive.Int16.int -> num
+      val sextdFromInt32: Primitive.Int32.int -> num
+      val sextdFromInt64: Primitive.Int64.int -> num
+      val sextdFromIntInf: Primitive.IntInf.int -> num
+      val sextdFromWord8: Primitive.Word8.word -> num
+      val sextdFromWord16: Primitive.Word16.word -> num
+      val sextdFromWord32: Primitive.Word32.word -> num
+      val sextdFromWord64: Primitive.Word64.word -> num
+      val sextdToInt8: num -> Primitive.Int8.int
+      val sextdToInt16: num -> Primitive.Int16.int
+      val sextdToInt32: num -> Primitive.Int32.int
+      val sextdToInt64: num -> Primitive.Int64.int
+      val sextdToIntInf: num -> Primitive.IntInf.int
+      val sextdToWord8: num -> Primitive.Word8.word
+      val sextdToWord16: num -> Primitive.Word16.word
+      val sextdToWord32: num -> Primitive.Word32.word
+      val sextdToWord64: num -> Primitive.Word64.word
+
+      val castFromInt8: Primitive.Int8.int -> num
+      val castFromInt16: Primitive.Int16.int -> num
+      val castFromInt32: Primitive.Int32.int -> num
+      val castFromInt64: Primitive.Int64.int -> num
+      val castFromIntInf: Primitive.IntInf.int -> num
+      val castFromWord8: Primitive.Word8.word -> num
+      val castFromWord16: Primitive.Word16.word -> num
+      val castFromWord32: Primitive.Word32.word -> num
+      val castFromWord64: Primitive.Word64.word -> num
+      val castToInt8: num -> Primitive.Int8.int
+      val castToInt16: num -> Primitive.Int16.int
+      val castToInt32: num -> Primitive.Int32.int
+      val castToInt64: num -> Primitive.Int64.int
+      val castToIntInf: num -> Primitive.IntInf.int
+      val castToWord8: num -> Primitive.Word8.word
+      val castToWord16: num -> Primitive.Word16.word
+      val castToWord32: num -> Primitive.Word32.word
+      val castToWord64: num -> Primitive.Word64.word
+
+      val zchckFromInt8: Primitive.Int8.int -> num
+      val zchckFromInt16: Primitive.Int16.int -> num
+      val zchckFromInt32: Primitive.Int32.int -> num
+      val zchckFromInt64: Primitive.Int64.int -> num
+      val zchckFromIntInf: Primitive.IntInf.int -> num
+      val zchckFromWord8: Primitive.Word8.word -> num
+      val zchckFromWord16: Primitive.Word16.word -> num
+      val zchckFromWord32: Primitive.Word32.word -> num
+      val zchckFromWord64: Primitive.Word64.word -> num
+      val zchckToInt8: num -> Primitive.Int8.int
+      val zchckToInt16: num -> Primitive.Int16.int
+      val zchckToInt32: num -> Primitive.Int32.int
+      val zchckToInt64: num -> Primitive.Int64.int
+      val zchckToIntInf: num -> Primitive.IntInf.int
+      val zchckToWord8: num -> Primitive.Word8.word
+      val zchckToWord16: num -> Primitive.Word16.word
+      val zchckToWord32: num -> Primitive.Word32.word
+      val zchckToWord64: num -> Primitive.Word64.word
+
+      val schckFromInt8: Primitive.Int8.int -> num
+      val schckFromInt16: Primitive.Int16.int -> num
+      val schckFromInt32: Primitive.Int32.int -> num
+      val schckFromInt64: Primitive.Int64.int -> num
+      val schckFromIntInf: Primitive.IntInf.int -> num
+      val schckFromWord8: Primitive.Word8.word -> num
+      val schckFromWord16: Primitive.Word16.word -> num
+      val schckFromWord32: Primitive.Word32.word -> num
+      val schckFromWord64: Primitive.Word64.word -> num
+      val schckToInt8: num -> Primitive.Int8.int
+      val schckToInt16: num -> Primitive.Int16.int
+      val schckToInt32: num -> Primitive.Int32.int
+      val schckToInt64: num -> Primitive.Int64.int
+      val schckToIntInf: num -> Primitive.IntInf.int
+      val schckToWord8: num -> Primitive.Word8.word
+      val schckToWord16: num -> Primitive.Word16.word
+      val schckToWord32: num -> Primitive.Word32.word
+      val schckToWord64: num -> Primitive.Word64.word
+   end
+signature MKNUM1_RES =
+   sig
+      type num
+
+      val zextdFromInt: Int.int -> num
+      val zextdToInt: num -> Int.int
+      val sextdFromInt: Int.int -> num
+      val sextdToInt: num -> Int.int
+      val castFromInt: Int.int -> num
+      val castToInt: num -> Int.int
+      val zchckFromInt: Int.int -> num
+      val zchckToInt: num -> Int.int
+      val schckFromInt: Int.int -> num
+      val schckToInt: num -> Int.int
+
+      val zextdFromFixedInt: FixedInt.int -> num
+      val zextdToFixedInt: num -> FixedInt.int
+      val sextdFromFixedInt: FixedInt.int -> num
+      val sextdToFixedInt: num -> FixedInt.int
+      val castFromFixedInt: FixedInt.int -> num
+      val castToFixedInt: num -> FixedInt.int
+      val zchckFromFixedInt: FixedInt.int -> num
+      val zchckToFixedInt: num -> FixedInt.int
+      val schckFromFixedInt: FixedInt.int -> num
+      val schckToFixedInt: num -> FixedInt.int
+
+      val zextdFromLargeInt: LargeInt.int -> num
+      val zextdToLargeInt: num -> LargeInt.int
+      val sextdFromLargeInt: LargeInt.int -> num
+      val sextdToLargeInt: num -> LargeInt.int
+      val castFromLargeInt: LargeInt.int -> num
+      val castToLargeInt: num -> LargeInt.int
+      val zchckFromLargeInt: LargeInt.int -> num
+      val zchckToLargeInt: num -> LargeInt.int
+      val schckFromLargeInt: LargeInt.int -> num
+      val schckToLargeInt: num -> LargeInt.int
+
+      val zextdFromWord: Word.word -> num
+      val zextdToWord: num -> Word.word
+      val sextdFromWord: Word.word -> num
+      val sextdToWord: num -> Word.word
+      val castFromWord: Word.word -> num
+      val castToWord: num -> Word.word
+      val zchckFromWord: Word.word -> num
+      val zchckToWord: num -> Word.word
+      val schckFromWord: Word.word -> num
+      val schckToWord: num -> Word.word
+
+      val zextdFromLargeWord: LargeWord.word -> num
+      val zextdToLargeWord: num -> LargeWord.word
+      val sextdFromLargeWord: LargeWord.word -> num
+      val sextdToLargeWord: num -> LargeWord.word
+      val castFromLargeWord: LargeWord.word -> num
+      val castToLargeWord: num -> LargeWord.word
+      val zchckFromLargeWord: LargeWord.word -> num
+      val zchckToLargeWord: num -> LargeWord.word
+      val schckFromLargeWord: LargeWord.word -> num
+      val schckToLargeWord: num -> LargeWord.word
+
+      val zextdFromSysWord: SysWord.word -> num
+      val zextdToSysWord: num -> SysWord.word
+      val sextdFromSysWord: SysWord.word -> num
+      val sextdToSysWord: num -> SysWord.word
+      val castFromSysWord: SysWord.word -> num
+      val castToSysWord: num -> SysWord.word
+      val zchckFromSysWord: SysWord.word -> num
+      val zchckToSysWord: num -> SysWord.word
+      val schckFromSysWord: SysWord.word -> num
+      val schckToSysWord: num -> SysWord.word
+   end
+signature PRIM_INTEGER =
+   sig
+      include PRIM_INTEGER
+      include MKNUM1_RES where type num = int
+   end
+signature PRIM_WORD =
+   sig
+      include PRIM_WORD
+      include MKNUM1_RES where type num = word
+   end
+
+functor MkNum1 (I: MKNUM1_ARG) : MKNUM1_RES =
+   struct
+      open I
+
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.zextdFromInt8
+             val fInt16 = I.zextdFromInt16
+             val fInt32 = I.zextdFromInt32
+             val fInt64 = I.zextdFromInt64
+             val fIntInf = I.zextdFromIntInf)
+      in
+         val zextdFromInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.zextdToInt8
+             val fInt16 = I.zextdToInt16
+             val fInt32 = I.zextdToInt32
+             val fInt64 = I.zextdToInt64
+             val fIntInf = I.zextdToIntInf)
+      in
+         val zextdToInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.sextdFromInt8
+             val fInt16 = I.sextdFromInt16
+             val fInt32 = I.sextdFromInt32
+             val fInt64 = I.sextdFromInt64
+             val fIntInf = I.sextdFromIntInf)
+      in
+         val sextdFromInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.sextdToInt8
+             val fInt16 = I.sextdToInt16
+             val fInt32 = I.sextdToInt32
+             val fInt64 = I.sextdToInt64
+             val fIntInf = I.sextdToIntInf)
+      in
+         val sextdToInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.castFromInt8
+             val fInt16 = I.castFromInt16
+             val fInt32 = I.castFromInt32
+             val fInt64 = I.castFromInt64
+             val fIntInf = I.castFromIntInf)
+      in
+         val castFromInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.castToInt8
+             val fInt16 = I.castToInt16
+             val fInt32 = I.castToInt32
+             val fInt64 = I.castToInt64
+             val fIntInf = I.castToIntInf)
+      in
+         val castToInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.zchckFromInt8
+             val fInt16 = I.zchckFromInt16
+             val fInt32 = I.zchckFromInt32
+             val fInt64 = I.zchckFromInt64
+             val fIntInf = I.zchckFromIntInf)
+      in
+         val zchckFromInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.zchckToInt8
+             val fInt16 = I.zchckToInt16
+             val fInt32 = I.zchckToInt32
+             val fInt64 = I.zchckToInt64
+             val fIntInf = I.zchckToIntInf)
+      in
+         val zchckToInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.schckFromInt8
+             val fInt16 = I.schckFromInt16
+             val fInt32 = I.schckFromInt32
+             val fInt64 = I.schckFromInt64
+             val fIntInf = I.schckFromIntInf)
+      in
+         val schckFromInt = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.schckToInt8
+             val fInt16 = I.schckToInt16
+             val fInt32 = I.schckToInt32
+             val fInt64 = I.schckToInt64
+             val fIntInf = I.schckToIntInf)
+      in
+         val schckToInt = S.f
+      end
+
+
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = 'a -> num
+             val fInt8 = I.zextdFromInt8
+             val fInt16 = I.zextdFromInt16
+             val fInt32 = I.zextdFromInt32
+             val fInt64 = I.zextdFromInt64)
+      in
+         val zextdFromFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = num -> 'a
+             val fInt8 = I.zextdToInt8
+             val fInt16 = I.zextdToInt16
+             val fInt32 = I.zextdToInt32
+             val fInt64 = I.zextdToInt64)
+      in
+         val zextdToFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = 'a -> num
+             val fInt8 = I.sextdFromInt8
+             val fInt16 = I.sextdFromInt16
+             val fInt32 = I.sextdFromInt32
+             val fInt64 = I.sextdFromInt64)
+      in
+         val sextdFromFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = num -> 'a
+             val fInt8 = I.sextdToInt8
+             val fInt16 = I.sextdToInt16
+             val fInt32 = I.sextdToInt32
+             val fInt64 = I.sextdToInt64)
+      in
+         val sextdToFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = 'a -> num
+             val fInt8 = I.castFromInt8
+             val fInt16 = I.castFromInt16
+             val fInt32 = I.castFromInt32
+             val fInt64 = I.castFromInt64)
+      in
+         val castFromFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = num -> 'a
+             val fInt8 = I.castToInt8
+             val fInt16 = I.castToInt16
+             val fInt32 = I.castToInt32
+             val fInt64 = I.castToInt64)
+      in
+         val castToFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = 'a -> num
+             val fInt8 = I.zchckFromInt8
+             val fInt16 = I.zchckFromInt16
+             val fInt32 = I.zchckFromInt32
+             val fInt64 = I.zchckFromInt64)
+      in
+         val zchckFromFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = num -> 'a
+             val fInt8 = I.zchckToInt8
+             val fInt16 = I.zchckToInt16
+             val fInt32 = I.zchckToInt32
+             val fInt64 = I.zchckToInt64)
+      in
+         val zchckToFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = 'a -> num
+             val fInt8 = I.schckFromInt8
+             val fInt16 = I.schckFromInt16
+             val fInt32 = I.schckFromInt32
+             val fInt64 = I.schckFromInt64)
+      in
+         val schckFromFixedInt = S.f
+      end
+      local
+         structure S =
+            FixedInt_ChooseIntN
+            (type 'a t = num -> 'a
+             val fInt8 = I.schckToInt8
+             val fInt16 = I.schckToInt16
+             val fInt32 = I.schckToInt32
+             val fInt64 = I.schckToInt64)
+      in
+         val schckToFixedInt = S.f
+      end
+
+
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.zextdFromInt8
+             val fInt16 = I.zextdFromInt16
+             val fInt32 = I.zextdFromInt32
+             val fInt64 = I.zextdFromInt64
+             val fIntInf = I.zextdFromIntInf)
+      in
+         val zextdFromLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.zextdToInt8
+             val fInt16 = I.zextdToInt16
+             val fInt32 = I.zextdToInt32
+             val fInt64 = I.zextdToInt64
+             val fIntInf = I.zextdToIntInf)
+      in
+         val zextdToLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.sextdFromInt8
+             val fInt16 = I.sextdFromInt16
+             val fInt32 = I.sextdFromInt32
+             val fInt64 = I.sextdFromInt64
+             val fIntInf = I.sextdFromIntInf)
+      in
+         val sextdFromLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.sextdToInt8
+             val fInt16 = I.sextdToInt16
+             val fInt32 = I.sextdToInt32
+             val fInt64 = I.sextdToInt64
+             val fIntInf = I.sextdToIntInf)
+      in
+         val sextdToLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.castFromInt8
+             val fInt16 = I.castFromInt16
+             val fInt32 = I.castFromInt32
+             val fInt64 = I.castFromInt64
+             val fIntInf = I.castFromIntInf)
+      in
+         val castFromLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.castToInt8
+             val fInt16 = I.castToInt16
+             val fInt32 = I.castToInt32
+             val fInt64 = I.castToInt64
+             val fIntInf = I.castToIntInf)
+      in
+         val castToLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.zchckFromInt8
+             val fInt16 = I.zchckFromInt16
+             val fInt32 = I.zchckFromInt32
+             val fInt64 = I.zchckFromInt64
+             val fIntInf = I.zchckFromIntInf)
+      in
+         val zchckFromLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.zchckToInt8
+             val fInt16 = I.zchckToInt16
+             val fInt32 = I.zchckToInt32
+             val fInt64 = I.zchckToInt64
+             val fIntInf = I.zchckToIntInf)
+      in
+         val zchckToLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = 'a -> num
+             val fInt8 = I.schckFromInt8
+             val fInt16 = I.schckFromInt16
+             val fInt32 = I.schckFromInt32
+             val fInt64 = I.schckFromInt64
+             val fIntInf = I.schckFromIntInf)
+      in
+         val schckFromLargeInt = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = num -> 'a
+             val fInt8 = I.schckToInt8
+             val fInt16 = I.schckToInt16
+             val fInt32 = I.schckToInt32
+             val fInt64 = I.schckToInt64
+             val fIntInf = I.schckToIntInf)
+      in
+         val schckToLargeInt = S.f
+      end
+
+
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.zextdFromWord8
+             val fWord16 = I.zextdFromWord16
+             val fWord32 = I.zextdFromWord32
+             val fWord64 = I.zextdFromWord64)
+      in
+         val zextdFromWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.zextdToWord8
+             val fWord16 = I.zextdToWord16
+             val fWord32 = I.zextdToWord32
+             val fWord64 = I.zextdToWord64)
+      in
+         val zextdToWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.sextdFromWord8
+             val fWord16 = I.sextdFromWord16
+             val fWord32 = I.sextdFromWord32
+             val fWord64 = I.sextdFromWord64)
+      in
+         val sextdFromWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.sextdToWord8
+             val fWord16 = I.sextdToWord16
+             val fWord32 = I.sextdToWord32
+             val fWord64 = I.sextdToWord64)
+      in
+         val sextdToWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.castFromWord8
+             val fWord16 = I.castFromWord16
+             val fWord32 = I.castFromWord32
+             val fWord64 = I.castFromWord64)
+      in
+         val castFromWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.castToWord8
+             val fWord16 = I.castToWord16
+             val fWord32 = I.castToWord32
+             val fWord64 = I.castToWord64)
+      in
+         val castToWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.zchckFromWord8
+             val fWord16 = I.zchckFromWord16
+             val fWord32 = I.zchckFromWord32
+             val fWord64 = I.zchckFromWord64)
+      in
+         val zchckFromWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.zchckToWord8
+             val fWord16 = I.zchckToWord16
+             val fWord32 = I.zchckToWord32
+             val fWord64 = I.zchckToWord64)
+      in
+         val zchckToWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.schckFromWord8
+             val fWord16 = I.schckFromWord16
+             val fWord32 = I.schckFromWord32
+             val fWord64 = I.schckFromWord64)
+      in
+         val schckFromWord = S.f
+      end
+      local
+         structure S =
+            Word_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.schckToWord8
+             val fWord16 = I.schckToWord16
+             val fWord32 = I.schckToWord32
+             val fWord64 = I.schckToWord64)
+      in
+         val schckToWord = S.f
+      end
+
+
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.zextdFromWord8
+             val fWord16 = I.zextdFromWord16
+             val fWord32 = I.zextdFromWord32
+             val fWord64 = I.zextdFromWord64)
+      in
+         val zextdFromLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.zextdToWord8
+             val fWord16 = I.zextdToWord16
+             val fWord32 = I.zextdToWord32
+             val fWord64 = I.zextdToWord64)
+      in
+         val zextdToLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.sextdFromWord8
+             val fWord16 = I.sextdFromWord16
+             val fWord32 = I.sextdFromWord32
+             val fWord64 = I.sextdFromWord64)
+      in
+         val sextdFromLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.sextdToWord8
+             val fWord16 = I.sextdToWord16
+             val fWord32 = I.sextdToWord32
+             val fWord64 = I.sextdToWord64)
+      in
+         val sextdToLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.castFromWord8
+             val fWord16 = I.castFromWord16
+             val fWord32 = I.castFromWord32
+             val fWord64 = I.castFromWord64)
+      in
+         val castFromLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.castToWord8
+             val fWord16 = I.castToWord16
+             val fWord32 = I.castToWord32
+             val fWord64 = I.castToWord64)
+      in
+         val castToLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.zchckFromWord8
+             val fWord16 = I.zchckFromWord16
+             val fWord32 = I.zchckFromWord32
+             val fWord64 = I.zchckFromWord64)
+      in
+         val zchckFromLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.zchckToWord8
+             val fWord16 = I.zchckToWord16
+             val fWord32 = I.zchckToWord32
+             val fWord64 = I.zchckToWord64)
+      in
+         val zchckToLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.schckFromWord8
+             val fWord16 = I.schckFromWord16
+             val fWord32 = I.schckFromWord32
+             val fWord64 = I.schckFromWord64)
+      in
+         val schckFromLargeWord = S.f
+      end
+      local
+         structure S =
+            LargeWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.schckToWord8
+             val fWord16 = I.schckToWord16
+             val fWord32 = I.schckToWord32
+             val fWord64 = I.schckToWord64)
+      in
+         val schckToLargeWord = S.f
+      end
+
+
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.zextdFromWord8
+             val fWord16 = I.zextdFromWord16
+             val fWord32 = I.zextdFromWord32
+             val fWord64 = I.zextdFromWord64)
+      in
+         val zextdFromSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.zextdToWord8
+             val fWord16 = I.zextdToWord16
+             val fWord32 = I.zextdToWord32
+             val fWord64 = I.zextdToWord64)
+      in
+         val zextdToSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.sextdFromWord8
+             val fWord16 = I.sextdFromWord16
+             val fWord32 = I.sextdFromWord32
+             val fWord64 = I.sextdFromWord64)
+      in
+         val sextdFromSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.sextdToWord8
+             val fWord16 = I.sextdToWord16
+             val fWord32 = I.sextdToWord32
+             val fWord64 = I.sextdToWord64)
+      in
+         val sextdToSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.castFromWord8
+             val fWord16 = I.castFromWord16
+             val fWord32 = I.castFromWord32
+             val fWord64 = I.castFromWord64)
+      in
+         val castFromSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.castToWord8
+             val fWord16 = I.castToWord16
+             val fWord32 = I.castToWord32
+             val fWord64 = I.castToWord64)
+      in
+         val castToSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.zchckFromWord8
+             val fWord16 = I.zchckFromWord16
+             val fWord32 = I.zchckFromWord32
+             val fWord64 = I.zchckFromWord64)
+      in
+         val zchckFromSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.zchckToWord8
+             val fWord16 = I.zchckToWord16
+             val fWord32 = I.zchckToWord32
+             val fWord64 = I.zchckToWord64)
+      in
+         val zchckToSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = 'a -> num
+             val fWord8 = I.schckFromWord8
+             val fWord16 = I.schckFromWord16
+             val fWord32 = I.schckFromWord32
+             val fWord64 = I.schckFromWord64)
+      in
+         val schckFromSysWord = S.f
+      end
+      local
+         structure S =
+            SysWord_ChooseWordN
+            (type 'a t = num -> 'a
+             val fWord8 = I.schckToWord8
+             val fWord16 = I.schckToWord16
+             val fWord32 = I.schckToWord32
+             val fWord64 = I.schckToWord64)
+      in
+         val schckToSysWord = S.f
+      end
+   end
+
+structure Primitive =
+struct
+open Primitive
+
+structure Int8 = 
+   struct
+      open Int8
+      local
+         structure S = MkNum1(struct 
+                                 open Int8 
+                                 type num = int 
+                              end)
+      in
+         open S
+      end
+   end
+structure Int16 = 
+   struct
+      open Int16
+      local
+         structure S = MkNum1(struct 
+                                 open Int16
+                                 type num = int 
+                              end)
+      in
+         open S
+      end
+   end
+structure Int32 = 
+   struct
+      open Int32
+      local
+         structure S = MkNum1(struct 
+                                 open Int32
+                                 type num = int 
+                              end)
+      in
+         open S
+      end
+   end
+structure Int64 = 
+   struct
+      open Int64
+      local
+         structure S = MkNum1(struct 
+                                 open Int64
+                                 type num = int 
+                              end)
+      in
+         open S
+      end
+   end
+structure IntInf = 
+   struct
+      open IntInf
+      local
+         structure S = MkNum1(struct 
+                                 open IntInf
+                                 type num = int 
+                              end)
+      in
+         open S
+      end
+   end
+
+structure Word8 = 
+   struct
+      open Word8
+      local
+         structure S = MkNum1(struct 
+                                 open Word8 
+                                 type num = word 
+                              end)
+      in
+         open S
+      end
+   end
+structure Word16 = 
+   struct
+      open Word16
+      local
+         structure S = MkNum1(struct 
+                                 open Word16
+                                 type num = word 
+                              end)
+      in
+         open S
+      end
+   end
+structure Word32 = 
+   struct
+      open Word32
+      local
+         structure S = MkNum1(struct 
+                                 open Word32
+                                 type num = word 
+                              end)
+      in
+         open S
+      end
+   end
+structure Word64 : PRIM_WORD = 
+   struct
+      open Word64
+      local
+         structure S = MkNum1(struct 
+                                 open Word64
+                                 type num = word 
+                              end)
+      in
+         open S
+      end
+   end
+
+end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sig	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sig	2006-05-16 03:02:10 UTC (rev 4548)
@@ -3,10 +3,12 @@
       eqtype word
    end
 
-signature PRE_WORD =
+signature WORD =
    sig
       include WORD_GLOBAL
 
+      val wordSize: Int.int
+
       val toLarge: word -> LargeWord.word
       val toLargeX: word -> LargeWord.word
       val toLargeWord: word -> LargeWord.word
@@ -20,16 +22,19 @@
       val toIntX: word -> int
       val fromInt: int -> word
          
-      val andb: word * word -> word
-      val orb: word * word -> word
-      val xorb: word * word -> word
-      val notb: word -> word
-         
       val + : word * word -> word
       val - : word * word -> word
       val * : word * word -> word
       val div: word * word -> word
       val mod: word * word -> word
+
+      val andb: word * word -> word
+      val << : word * Word.word -> word
+      val notb: word -> word
+      val orb: word * word -> word
+      val ~>> : word * Word.word -> word
+      val >> : word * Word.word -> word
+      val xorb: word * word -> word
          
       val compare: word * word -> order
       val < : word * word -> bool
@@ -40,42 +45,6 @@
       val ~ : word -> word
       val min: word * word -> word
       val max: word * word -> word
-   end
-signature PRE_WORD_EXTRA =
-   sig
-      include PRE_WORD
-
-      val zero: word
-
-      val wordSize: Primitive.Int32.int
-      val wordSizeWord: Primitive.Word32.word
-
-      val fromWord: Word.word -> word
-      val fromWordX: Word.word -> word
-      val fromSysWord: SysWord.word -> word
-      val fromSysWordX: SysWord.word -> word
-      val toWord: word -> Word.word
-      val toWordX: word -> Word.word
-      val toSysWord: word -> SysWord.word
-      val toSysWordX: word -> SysWord.word
-
-      val << : word * Primitive.Word32.word -> word
-      val >> : word * Primitive.Word32.word -> word
-      val ~>> : word * Primitive.Word32.word -> word
-      val rol: word * Primitive.Word32.word -> word
-      val ror: word * Primitive.Word32.word -> word
-      val log2 : word -> Primitive.Int32.int
-   end
-
-signature WORD =
-   sig
-      include PRE_WORD
-
-      val wordSize: Int.int
-
-      val << : word * Word.word -> word
-      val >> : word * Word.word -> word
-      val ~>> : word * Word.word -> word
          
       val fmt: StringCvt.radix -> word -> string
       val toString: word -> string
@@ -90,18 +59,16 @@
       include WORD
       type t = word
 
-      val wordSizeWord: Word.word
-
-      val fromWord: Word.word -> word
-      val fromWordX: Word.word -> word
-      val fromSysWord: SysWord.word -> word
-      val fromSysWordX: SysWord.word -> word
       val toWord: word -> Word.word
       val toWordX: word -> Word.word
-      val toSysWord: word -> SysWord.word
-      val toSysWordX: word -> SysWord.word
+      val fromWord: Word.word -> word
 
       val rol: word * Word.word -> word
       val ror: word * Word.word -> word
       val log2 : word -> Primitive.Int32.int
+
+      val castFromFixedInt: FixedInt.int -> word
+      val castToFixedInt: word -> FixedInt.int
+      val castFromSysWord: SysWord.word -> word
+      val castToSysWord: word -> SysWord.word
    end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -6,30 +6,64 @@
  * See the file MLton-LICENSE for details.
  *)
 
-functor Word (W: PRE_WORD_EXTRA): WORD_EXTRA =
+functor Word (W: PRIM_WORD) : WORD_EXTRA =
 struct
 
 open W
 type t = word
 
-val wordSize: Int.int = Primitive.Int32.toInt wordSize
-val wordSizeWord: Word.word = Primitive.Word32.toWord wordSizeWord
+val wordSize: Int.int = Primitive.Int32.zextdToInt sizeInBits
+val sizeInBitsWord = Primitive.Word32.zextdToWord sizeInBitsWord
 
-fun << (w, n) = 
-   if Word.>= (n, wordSizeWord)
+fun << (i, n) = 
+   if Word.>= (n, sizeInBitsWord)
       then zero
-      else W.<< (w, Primitive.Word32.fromWord n)
-fun >> (w, n) = 
-   if Word.>= (n, wordSizeWord)
+      else W.<<? (i, Primitive.Word32.zextdFromWord n)
+fun >> (i, n) = 
+   if Word.>= (n, sizeInBitsWord)
       then zero
-      else W.>> (w, Primitive.Word32.fromWord n)
-fun ~>> (w, n) =
-   if Word.< (n, wordSizeWord)
-      then W.~>> (w, Primitive.Word32.fromWord n)
-      else W.~>> (w, Primitive.Word32.- (W.wordSizeWord, 0w1))
-fun rol (w, n) = W.rol (w, Primitive.Word32.fromWord n)
-fun ror (w, n) = W.ror (w, Primitive.Word32.fromWord n)
+      else W.>>? (i, Primitive.Word32.zextdFromWord n)
+fun ~>> (i, n) =
+   if Word.< (n, sizeInBitsWord)
+      then W.~>>? (i, Primitive.Word32.zextdFromWord n)
+      else W.~>>? (i, Primitive.Word32.- (W.sizeInBitsWord, 0w1))
+fun rol (i, n) = W.rolUnsafe (i, Primitive.Word32.zextdFromWord n)
+fun ror (i, n) = W.rorUnsafe (i, Primitive.Word32.zextdFromWord n)
 
+val fromInt = W.sextdFromInt
+val toIntX = W.schckToInt
+fun toInt w =
+   let
+      val i = W.zchckToInt w
+   in
+      if Primitive.Controls.detectOverflow
+         andalso Int.< (i, 0)
+         then raise Overflow
+         else i
+   end
+val fromLargeInt = W.sextdFromLargeInt
+val toLargeIntX = W.schckToLargeInt
+fun toLargeInt w =
+   let
+      val i = W.zchckToLargeInt w
+   in
+      if Primitive.Controls.detectOverflow
+         andalso LargeInt.< (i, 0)
+         then raise Overflow
+         else i
+   end
+
+val fromLargeWord = W.zextdFromLargeWord
+val fromLarge = fromLargeWord
+val toLargeWordX = W.sextdToLargeWord
+val toLargeX = toLargeWordX
+val toLargeWord = W.zextdToLargeWord
+val toLarge = toLargeWord
+
+val fromWord = W.zextdFromWord
+val toWordX = W.sextdToWord
+val toWord = W.zextdToWord
+
 local
    (* Allocate a buffer large enough to hold any formatted word in any radix.
     * The most that will be required is for maxWord in binary.

Deleted: mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word0.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/integer/word0.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -1,226 +0,0 @@
-(* Copyright (C) 1999-2005 Henry Cejtin, Matthew Fluet, Suresh
- *    Jagannathan, and Stephen Weeks.
- * Copyright (C) 1997-2000 NEC Research Institute.
- *
- * MLton is released under a BSD-style license.
- * See the file MLton-LICENSE for details.
- *)
-
-signature WORD0 =
-   sig
-      include PRIM_WORD
-
-      val wordSizeWord: Primitive.Word32.word
-
-      val zero: word
-      val one: word
-
-      val div: word * word -> word
-      val mod: word * word -> word
-
-      val << : word * Primitive.Word32.word -> word
-      val >> : word * Primitive.Word32.word -> word
-      val rol : word * Primitive.Word32.word -> word
-      val ror : word * Primitive.Word32.word -> word
-      val ~>> : word * Primitive.Word32.word -> word
-      val log2 : word -> Primitive.Int32.int
-
-      (* Lowbits or sign extend. *)
-      val fromInt8: Primitive.Int8.int -> word
-      val fromInt16: Primitive.Int16.int -> word
-      val fromInt32: Primitive.Int32.int -> word
-      val fromInt64: Primitive.Int64.int -> word
-
-      (* Lowbits or zero extend. *)
-      val fromInt8Z: Primitive.Int8.int -> word
-      val fromInt16Z: Primitive.Int16.int -> word
-      val fromInt32Z: Primitive.Int32.int -> word
-      val fromInt64Z: Primitive.Int64.int -> word
-
-      (* Lowbits or zero extend. *)
-      val fromWord8: Primitive.Word8.word -> word
-      val fromWord16: Primitive.Word16.word -> word
-      val fromWord32: Primitive.Word32.word -> word
-      val fromWord64: Primitive.Word64.word -> word
-         
-      (* Lowbits or sign extend. *)
-      val fromWord8X: Primitive.Word8.word -> word
-      val fromWord16X: Primitive.Word16.word -> word
-      val fromWord32X: Primitive.Word32.word -> word
-      val fromWord64X: Primitive.Word64.word -> word
-
-      (* Overflow checking, unsigned interp. *)
-      val toInt8: word -> Primitive.Int8.int
-      val toInt16: word -> Primitive.Int16.int
-      val toInt32: word -> Primitive.Int32.int
-      val toInt64: word -> Primitive.Int64.int
-
-      (* Overflow checking, signed interp. *)
-      val toInt8X: word -> Primitive.Int8.int
-      val toInt16X: word -> Primitive.Int16.int
-      val toInt32X: word -> Primitive.Int32.int
-      val toInt64X: word -> Primitive.Int64.int   
-
-      (* Lowbits or zero extend. *)
-      val toWord8: word -> Primitive.Word8.word
-      val toWord16: word -> Primitive.Word16.word
-      val toWord32: word -> Primitive.Word32.word
-      val toWord64: word -> Primitive.Word64.word
-
-      (* Lowbits or sign extend. *)
-      val toWord8X: word -> Primitive.Word8.word
-      val toWord16X: word -> Primitive.Word16.word
-      val toWord32X: word -> Primitive.Word32.word
-      val toWord64X: word -> Primitive.Word64.word
-   end
-
-functor MkWord0 (W: PRIM_WORD): WORD0 =
-   struct
-
-      open W
-
-      val detectOverflow = Primitive.Controls.detectOverflow
-
-      val wordSizeWord = Primitive.Word32.fromInt32Unsafe wordSize
-      val wordSizeMinusOneWord = Primitive.Word32.- (wordSizeWord, 0w1)
-
-      val zero: word = fromWord32Unsafe 0w0
-      val one: word = fromWord32Unsafe 0w1
-
-      local
-         fun make f (w, w') =
-            if Primitive.Controls.safe andalso w' = zero
-               then raise Div
-               else f (w, w')
-      in
-         val op div = make (op quotUnsafe)
-         val op mod = make (op remUnsafe)
-      end
-
-      fun << (w, n) =
-         if Primitive.Word32.>= (n, wordSizeWord)
-            then zero
-            else <<? (w, n)
-      fun >> (w, n) =
-         if Primitive.Word32.>= (n, wordSizeWord)
-            then zero
-            else >>? (w, n)
-      fun ~>> (w, n) =
-         if Primitive.Word32.< (n, wordSizeWord)
-            then ~>>? (w, n)
-            else ~>>? (w, wordSizeMinusOneWord)
-      fun rol (w, n) =
-         let
-            val n = Primitive.Word32.remUnsafe (n, wordSizeWord)
-         in
-            if n = 0w0
-               then w
-               else rolUnsafe (w, n)
-         end
-      fun ror (w, n) =
-         let
-            val n = Primitive.Word32.remUnsafe (n, wordSizeWord)
-         in
-            if n = 0w0
-               then w
-               else rorUnsafe (w, n)
-         end
-      fun log2 w =
-         let
-            fun loop (n, s, acc) =
-               if n = one
-                  then acc
-                  else let
-                          val (n, acc) =
-                            if n >= << (one, s)
-                               then (>> (n, s), Primitive.Word32.+ (acc, s))
-                               else (n, acc)
-                       in
-                          loop (n, Primitive.Word32.>>? (s, 0w1), acc)
-                       end
-         in
-            Primitive.Word32.toInt32Unsafe
-            (loop (w, Primitive.Word32.>>? (wordSizeWord, 0w1), 0w0))
-         end
-
-      local
-         fun 'a make {fromIntUnsafe: 'a -> word, fromIntZUnsafe: 'a -> word,
-                      toIntUnsafe: word -> 'a, toIntXUnsafe: word -> 'a,
-                      other : {precision': Primitive.Int32.int,
-                               maxInt': 'a,
-                               minInt': 'a}} =
-            let
-               fun toInt w =
-                  if detectOverflow
-                     andalso Primitive.Int32.>= (wordSize, #precision' other)
-                     andalso w > fromIntUnsafe (#maxInt' other)
-                     then raise Overflow
-                     else toIntUnsafe w
-               fun toIntX w =
-                  if detectOverflow
-                     andalso Primitive.Int32.> (wordSize, #precision' other)
-                     andalso fromIntUnsafe (#maxInt' other) < w
-                     andalso w < fromIntUnsafe (#minInt' other)
-                     then raise Overflow
-                     else toIntXUnsafe w
-            in
-               (fromIntUnsafe,
-                fromIntZUnsafe,
-                toInt,
-                toIntX)
-            end
-      in
-         val (fromInt8, fromInt8Z, toInt8, toInt8X) = 
-            make {fromIntUnsafe = fromInt8Unsafe,
-                  fromIntZUnsafe = fromInt8ZUnsafe, 
-                  toIntUnsafe = toInt8Unsafe,
-                  toIntXUnsafe = toInt8XUnsafe,
-                  other = {precision' = Primitive.Int8.precision',
-                           maxInt' = Primitive.Int8.maxInt',
-                           minInt' = Primitive.Int8.minInt'}}
-         val (fromInt16, fromInt16Z, toInt16, toInt16X) = 
-            make {fromIntUnsafe = fromInt16Unsafe,
-                  fromIntZUnsafe = fromInt16ZUnsafe, 
-                  toIntUnsafe = toInt16Unsafe,
-                  toIntXUnsafe = toInt16XUnsafe,
-                  other = {precision' = Primitive.Int16.precision',
-                           maxInt' = Primitive.Int16.maxInt',
-                           minInt' = Primitive.Int16.minInt'}}
-         val (fromInt32, fromInt32Z, toInt32, toInt32X) = 
-            make {fromIntUnsafe = fromInt32Unsafe,
-                  fromIntZUnsafe = fromInt32ZUnsafe, 
-                  toIntUnsafe = toInt32Unsafe,
-                  toIntXUnsafe = toInt32XUnsafe,
-                  other = {precision' = Primitive.Int32.precision',
-                           maxInt' = Primitive.Int32.maxInt',
-                           minInt' = Primitive.Int32.minInt'}}
-         val (fromInt64, fromInt64Z, toInt64, toInt64X) = 
-            make {fromIntUnsafe = fromInt64Unsafe,
-                  fromIntZUnsafe = fromInt64ZUnsafe, 
-                  toIntUnsafe = toInt64Unsafe,
-                  toIntXUnsafe = toInt64XUnsafe,
-                  other = {precision' = Primitive.Int64.precision',
-                           maxInt' = Primitive.Int64.maxInt',
-                           minInt' = Primitive.Int64.minInt'}}
-      end
-
-      val (fromWord8, fromWord8X, toWord8, toWord8X) =
-         (fromWord8Unsafe, fromWord8XUnsafe, toWord8Unsafe, toWord8XUnsafe)   
-      val (fromWord16, fromWord16X, toWord16, toWord16X) =
-         (fromWord16Unsafe, fromWord16XUnsafe, toWord16Unsafe, toWord16XUnsafe)   
-      val (fromWord32, fromWord32X, toWord32, toWord32X) =
-         (fromWord32Unsafe, fromWord32XUnsafe, toWord32Unsafe, toWord32XUnsafe)   
-      val (fromWord64, fromWord64X, toWord64, toWord64X) =
-         (fromWord64Unsafe, fromWord64XUnsafe, toWord64Unsafe, toWord64XUnsafe)   
-
-   end
-
-structure Primitive = struct
-open Primitive
-
-structure Word8 = MkWord0 (Primitive.Word8)
-structure Word16 = MkWord0 (Primitive.Word16)
-structure Word32 = MkWord0 (Primitive.Word32)
-structure Word64 = MkWord0 (Primitive.Word64)
-
-end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/ffi.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/ffi.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/ffi.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -50,16 +50,16 @@
    
 val getBool = intToBool o getInt32
 
-val getChar8 = Primitive.Char8.fromInt8Unsafe o getInt8
-val getChar16 = Primitive.Char16.fromInt16Unsafe o getInt16
-val getChar32 = Primitive.Char32.fromInt32Unsafe o getInt32
+val getChar8 = Primitive.Char8.idFromInt8 o getInt8
+val getChar16 = Primitive.Char16.idFromInt16 o getInt16
+val getChar32 = Primitive.Char32.idFromInt32 o getInt32
                
 fun boolToInt (b: bool): Int32.t = if b then 1 else 0
 
 val setBool = setInt32 o boolToInt
 
-val setChar8 = setInt8 o Primitive.Char8.toInt8Unsafe
-val setChar16 = setInt16 o Primitive.Char16.toInt16Unsafe
-val setChar32 = setInt32 o Primitive.Char32.toInt32Unsafe
+val setChar8 = setInt8 o Primitive.Char8.idToInt8
+val setChar16 = setInt16 o Primitive.Char16.idToInt16
+val setChar32 = setInt32 o Primitive.Char32.idToInt32
 
 end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/itimer.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/itimer.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/itimer.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -29,7 +29,7 @@
                   val q = LargeInt.quot (Time.toMicroseconds t, 1000000)
                   val r = LargeInt.rem (Time.toMicroseconds t, 1000000)
                in
-                  (C_Time.fromLarge q, C_SUSeconds.fromLarge r)
+                  (C_Time.fromLargeInt q, C_SUSeconds.fromLargeInt r)
                end
             val (s1, u1) = split interval
             val (s2, u2) = split value

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/process.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/process.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/process.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -255,7 +255,7 @@
 
       fun create (cmd, args, env, stdin, stdout, stderr) =
          SysCall.simpleResult'
-         ({errVal = C_PId.fromInt ~1}, fn () =>
+         ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
           let
 (*
              val cmd =
@@ -325,7 +325,7 @@
                   val env = CUtil.C_StringArray.fromList env
                in
                   SysCall.simpleResult'
-                  ({errVal = C_PId.fromInt ~1}, fn () =>
+                  ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                    Prim.spawne (path, args, env))
                end
          else
@@ -346,7 +346,7 @@
                   val args = CUtil.C_StringArray.fromList args
                in
                   SysCall.simpleResult'
-                  ({errVal = C_PId.fromInt ~1}, fn () =>
+                  ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                    Prim.spawnp (file, args))
                end
          else    

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rlimit.sig	2006-05-16 03:02:10 UTC (rev 4548)
@@ -8,9 +8,13 @@
 
 signature MLTON_RLIMIT =
    sig
-      structure RLim : WORD
+      structure RLim : sig
+                          type t
+                          val castFromSysWord: SysWord.word -> t
+                          val castToSysWord: t -> SysWord.word
+                       end
                
-      val infinity: RLim.word
+      val infinity: RLim.t
 
       type t
                
@@ -28,6 +32,6 @@
       val residentSetSize: t     (* RSS     max resident set size *)
  *)
 
-      val get: t -> {hard: RLim.word, soft: RLim.word}
-      val set: t * {hard: RLim.word, soft: RLim.word} -> unit
+      val get: t -> {hard: RLim.t, soft: RLim.t}
+      val set: t * {hard: RLim.t, soft: RLim.t} -> unit
    end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rusage.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rusage.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/mlton/rusage.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -17,9 +17,9 @@
             fun toTime (sec, usec) =
                let
                   val time_sec =
-                     Time.fromSeconds (C_Time.toLarge (sec ()))
+                     Time.fromSeconds (C_Time.toLargeInt (sec ()))
                   val time_usec =
-                     Time.fromMicroseconds (C_SUSeconds.toLarge (usec ()))
+                     Time.fromMicroseconds (C_SUSeconds.toLargeInt (usec ()))
                in
                   Time.+ (time_sec, time_usec)
                end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/net/net-host-db.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/net/net-host-db.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/net/net-host-db.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -31,7 +31,7 @@
                if i >= inAddrLen
                   then ()
                   else let
-                          val w = Word8.fromSysWord (C_Int.toSysWord acc)
+                          val w = Word8.castFromSysWord (C_Int.castToSysWord acc)
                           val () =
                              Array.update
                              (wa, (inAddrLen - 1) - i, w)

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/net/net.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/net/net.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/net/net.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -22,13 +22,25 @@
 
       structure Int32 =
          struct
-            val hton = Primitive.Word32.toInt32Unsafe o Word32.hton o Primitive.Word32.fromInt32Unsafe
-            val ntoh = Primitive.Word32.toInt32Unsafe o Word32.ntoh o Primitive.Word32.fromInt32Unsafe
+            val hton = 
+               Primitive.IntWordConv.idFromWord32ToInt32 
+               o Word32.hton 
+               o Primitive.IntWordConv.idFromInt32ToWord32
+            val ntoh = 
+               Primitive.IntWordConv.idFromWord32ToInt32 
+               o Word32.ntoh 
+               o Primitive.IntWordConv.idFromInt32ToWord32
          end
       structure Int16 =
          struct
-            val hton = Primitive.Word16.toInt16Unsafe o Word16.hton o Primitive.Word16.fromInt16Unsafe
-            val ntoh = Primitive.Word16.toInt16Unsafe o Word16.ntoh o Primitive.Word16.fromInt16Unsafe
+            val hton = 
+               Primitive.IntWordConv.idFromWord16ToInt16 
+               o Word16.hton 
+               o Primitive.IntWordConv.idFromInt16ToWord16
+            val ntoh = 
+               Primitive.IntWordConv.idFromWord16ToInt16 
+               o Word16.ntoh 
+               o Primitive.IntWordConv.idFromInt16ToWord16
          end
 
       structure C_Int =

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/net/socket.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -14,8 +14,8 @@
 structure FileSys = Posix.FileSys
 
 type sock = C_Sock.t
-val sockToWord = C_Sock.toSysWord
-val wordToSock = C_Sock.fromSysWord
+val sockToWord = C_Sock.castToSysWord
+val wordToSock = C_Sock.castFromSysWord
 val sockToFD = fn x => x
 val fdToSock = fn x => x
 
@@ -101,7 +101,7 @@
                              (wa, if isBigEndian
                                      then i
                                      else (intLen - 1) - i)
-                          val w = C_Int.fromSysWord (Word8.toSysWord w)
+                          val w = C_Int.castFromSysWord (Word8.castToSysWord w)
                        in
                           loop (i + 1, C_Int.andb (w, C_Int.<< (acc, 0w4)))
                        end
@@ -115,7 +115,7 @@
                if i >= intLen
                   then ()
                   else let
-                          val w = Word8.fromSysWord (C_Int.toSysWord acc)
+                          val w = Word8.castFromSysWord (C_Int.castToSysWord acc)
                           val () =
                              Array.update
                              (wa, if isBigEndian
@@ -145,7 +145,7 @@
                              (wa, if isBigEndian
                                      then i
                                      else (sizeLen - 1) - i)
-                          val w = C_Size.fromSysWord (Word8.toSysWord w)
+                          val w = C_Size.castFromSysWord (Word8.castToSysWord w)
                        in
                           loop (i + 1, C_Size.andb (w, C_Size.<< (acc, 0w4)))
                        end
@@ -159,7 +159,7 @@
                if i >= sizeLen
                   then ()
                   else let
-                          val w = Word8.fromSysWord (C_Size.toSysWord acc)
+                          val w = Word8.castFromSysWord (C_Size.castToSysWord acc)
                           val () =
                              Array.update
                              (wa, if isBigEndian
@@ -185,7 +185,7 @@
                              (wa, if isBigEndian
                                      then i
                                      else (intLen - 1) - i)
-                          val w = C_Int.fromSysWord (Word8.toSysWord w)
+                          val w = C_Int.castFromSysWord (Word8.castToSysWord w)
                        in
                           loopBool (i + 1, C_Int.andb (w, C_Int.<< (acc, 0w4)))
                        end
@@ -198,7 +198,7 @@
                              (wa, intLen + (if isBigEndian
                                                then i
                                                else (intLen - 1) - i))
-                          val w = C_Int.fromSysWord (Word8.toSysWord w)
+                          val w = C_Int.castFromSysWord (Word8.castToSysWord w)
                        in
                           loopInt (i + 1, C_Int.andb (w, C_Int.<< (acc, 0w4)))
                        end
@@ -214,7 +214,7 @@
                if i >= intLen
                   then ()
                   else let
-                          val w = Word8.fromSysWord (C_Int.toSysWord acc)
+                          val w = Word8.castFromSysWord (C_Int.castToSysWord acc)
                           val () =
                              Array.update
                              (wa, if isBigEndian
@@ -227,7 +227,7 @@
                if i >= intLen
                   then ()
                   else let
-                          val w = Word8.fromSysWord (C_Int.toSysWord acc)
+                          val w = Word8.castFromSysWord (C_Int.castToSysWord acc)
                           val () =
                              Array.update
                              (wa, intLen + (if isBigEndian
@@ -509,7 +509,7 @@
                val (buf, i, sz) = base sl
             in
                (C_SSize.toInt o Syscall.simpleResultRestart')
-               ({errVal = C_SSize.fromInt ~1}, fn () => 
+               ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
                 primSend (s, buf, C_Int.fromInt i, C_Size.fromInt sz, 
                           mk_out_flags out_flags))
             end
@@ -519,7 +519,7 @@
                val (buf, i, sz) = base sl
             in
                nonBlock
-               (C_SSize.fromInt ~1,
+               (C_SSize.castFromFixedInt ~1,
                 fn () =>
                 primSend (s, buf, C_Int.fromInt i, C_Size.fromInt sz,
                           C_Int.orb (Prim.MSG_DONTWAIT, mk_out_flags out_flags)),
@@ -532,7 +532,7 @@
                val (buf, i, sz) = base sl
             in
                Syscall.simpleRestart'
-               ({errVal = C_SSize.fromInt ~1}, fn () => 
+               ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
                 primSendTo (s, buf, C_Int.fromInt i, C_Size.fromInt sz,
                             mk_out_flags out_flags, 
                             sa, C_Socklen.fromInt (Vector.length sa)))
@@ -544,7 +544,7 @@
                val (buf, i, sz) = base sl
             in
                nonBlock 
-               (C_SSize.fromInt ~1,
+               (C_SSize.castFromFixedInt ~1,
                 fn () =>
                 primSendTo (s, buf, C_Int.fromInt i, C_Size.fromInt sz,
                             C_Int.orb (Prim.MSG_DONTWAIT, mk_out_flags out_flags),
@@ -580,7 +580,7 @@
       val (buf, i, sz) = Word8ArraySlice.base sl
    in
       (C_SSize.toInt o Syscall.simpleResultRestart')
-      ({errVal = C_SSize.fromInt ~1}, fn () => 
+      ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
        Prim.recv (s, Word8Array.toPoly buf, C_Int.fromInt i, C_Size.fromInt sz, 
                   mk_in_flags in_flags))
    end
@@ -609,7 +609,7 @@
       val (sa, salen, finish) = new_sock_addr ()
       val n =
          (C_SSize.toInt o Syscall.simpleResultRestart')
-         ({errVal = C_SSize.fromInt ~1}, fn () => 
+         ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
           Prim.recvFrom (s, Word8Array.toPoly buf, C_Int.fromInt i, C_Size.fromInt sz,
                          mk_in_flags in_flags, 
                          sa, salen))
@@ -637,7 +637,7 @@
       val (buf, i, sz) = Word8ArraySlice.base sl
    in
       nonBlock
-      (C_SSize.fromInt ~1,
+      (C_SSize.castFromFixedInt ~1,
        fn () => Prim.recv (s, Word8Array.toPoly buf, C_Int.fromInt i, C_Size.fromInt sz,
                            mk_in_flagsNB in_flags),
        SOME o C_SSize.toInt, 
@@ -649,7 +649,7 @@
       val a = Word8Array.arrayUninit n
    in
       nonBlock
-      (C_SSize.fromInt ~1,
+      (C_SSize.castFromFixedInt ~1,
        fn () => Prim.recv (s, Word8Array.toPoly a, 0, C_Size.fromInt n,
                            mk_in_flagsNB in_flags),
        fn bytesRead => SOME (getVec (a, n, C_SSize.toInt bytesRead)),
@@ -666,7 +666,7 @@
       val (sa, salen, finish) = new_sock_addr ()
    in
       nonBlock
-      (C_SSize.fromInt ~1,
+      (C_SSize.castFromFixedInt ~1,
        fn () => Prim.recvFrom (s, Word8Array.toPoly buf, C_Int.fromInt i, C_Size.fromInt sz,
                                mk_in_flagsNB in_flags, sa, salen),
        fn n => SOME (C_SSize.toInt n, finish ()),
@@ -679,7 +679,7 @@
       val (sa, salen, finish) = new_sock_addr ()
    in
       nonBlock
-      (C_SSize.fromInt ~1,
+      (C_SSize.castFromFixedInt ~1,
        fn () => Prim.recvFrom (s, Word8Array.toPoly a, 0, C_Size.fromInt n,
                                mk_in_flagsNB in_flags, sa, salen),
        fn bytesRead => SOME (getVec (a, n, C_SSize.toInt bytesRead), finish ()),

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/file-sys.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -17,10 +17,10 @@
          struct
             open Time
 
-            val fromSeconds = fromSeconds o C_Time.toLarge
+            val fromSeconds = fromSeconds o C_Time.toLargeInt
 
             fun toSeconds t =
-               C_Time.fromLarge (Time.toSeconds t)
+               C_Time.fromLargeInt (Time.toSeconds t)
                handle Overflow => Error.raiseSys Error.inval
          end
 
@@ -33,8 +33,8 @@
       type uid = C_UId.t
       type gid = C_GId.t
 
-      val fdToWord = C_Fd.toSysWord
-      val wordToFD = C_Fd.fromSysWord
+      val fdToWord = C_Fd.castToSysWord
+      val wordToFD = C_Fd.castFromSysWord
       val fdToIOD = fn x => x
       val iodToFD = SOME o (fn x => x)
 
@@ -58,7 +58,7 @@
                val s = NullString.nullTerm s
             in
                SysCall.syscall'
-               ({errVal = C_DirP.fromWord 0w0}, fn () =>
+               ({errVal = C_DirP.castFromSysWord 0w0}, fn () =>
                 (Prim.openDir s, fn d =>
                  DS (ref (SOME d))))
             end
@@ -220,7 +220,7 @@
             val flags = O.Flags.flags [openModeToFlags openMode,
                                        flags,
                                        O.creat]
-            val flags = C_Int.fromSysWord (O.Flags.toWord flags)
+            val flags = C_Int.castFromSysWord (O.Flags.toWord flags)
             val fd =
                SysCall.simpleResult
                (fn () => Prim.open3 (pathname, flags, mode))
@@ -232,10 +232,10 @@
          let 
             val pathname = NullString.nullTerm pathname
             val flags = O.Flags.flags [openModeToFlags openMode, flags]
-            val flags = C_Int.fromSysWord (O.Flags.toWord flags)
+            val flags = C_Int.castFromSysWord (O.Flags.toWord flags)
             val fd = 
                SysCall.simpleResult
-               (fn () => Prim.open3 (pathname, flags, C_Mode.fromInt 0))
+               (fn () => Prim.open3 (pathname, flags, C_Mode.castFromSysWord 0wx0))
          in 
             fd
          end
@@ -276,19 +276,19 @@
                val path = NullString.nullTerm path
             in
                SysCall.syscall'
-               ({errVal = C_SSize.fromInt ~1}, fn () =>
+               ({errVal = C_SSize.castFromFixedInt ~1}, fn () =>
                 (Prim.readlink (path, buf, C_Size.fromInt size), fn len =>
                  ArraySlice.vector (ArraySlice.slice (buf, 0, SOME (C_SSize.toInt len)))))
             end
       end
 
       type dev = C_Dev.t
-      val wordToDev = C_Dev.fromSysWord
-      val devToWord = C_Dev.toSysWord
+      val wordToDev = C_Dev.castFromSysWord
+      val devToWord = C_Dev.castToSysWord
 
       type ino = C_INo.t
-      val wordToIno = C_INo.fromSysWord
-      val inoToWord = C_INo.toSysWord
+      val wordToIno = C_INo.castFromSysWord
+      val inoToWord = C_INo.castToSysWord
 
       structure ST =
          struct

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/flags.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/flags.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/flags.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -8,8 +8,8 @@
 
 functor BitFlags(structure S : sig
                     eqtype t
-                    val toSysWord: t -> SysWord.word
-                    val fromSysWord: SysWord.word -> t
+                    val castToSysWord: t -> SysWord.word
+                    val castFromSysWord: SysWord.word -> t
                     val andb: t * t -> t
                     val notb: t -> t
                     val orb: t * t -> t
@@ -17,11 +17,11 @@
    struct
       type flags = S.t
          
-      val all: flags = S.fromSysWord (SysWord.~ 0w1)
-      val empty: flags = S.fromSysWord 0w0
+      val all: flags = S.castFromSysWord (SysWord.~ 0w1)
+      val empty: flags = S.castFromSysWord 0w0
 
-      fun toWord f = S.toSysWord f
-      fun fromWord w = S.fromSysWord (SysWord.andb (w, toWord all))
+      fun toWord f = S.castToSysWord f
+      fun fromWord w = S.castFromSysWord (SysWord.andb (w, toWord all))
 
       val flags: flags list -> flags = List.foldl S.orb empty
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/io.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -223,7 +223,7 @@
                val (buf, i, sz) = ArraySlice.base (toArraySlice sl)
                val bytesRead =
                   SysCall.simpleResultRestart'
-                  ({errVal = C_SSize.fromInt ~1}, fn () => 
+                  ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
                    primReadArr (fd, buf, C_Int.fromInt i, C_Size.fromInt sz))
                val bytesRead = C_SSize.toInt bytesRead
             in
@@ -234,7 +234,7 @@
                val buf = Array.arrayUninit n
                val bytesRead = 
                   SysCall.simpleResultRestart'
-                  ({errVal = C_SSize.fromInt ~1}, fn () => 
+                  ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
                    primReadArr (fd, buf, C_Int.fromInt 0, C_Size.fromInt n))
                val bytesRead = C_SSize.toInt bytesRead
             in 
@@ -248,7 +248,7 @@
                val (buf, i, sz) = ArraySlice.base (toArraySlice sl)
                val bytesWrote =
                   SysCall.simpleResultRestart'
-                  ({errVal = C_SSize.fromInt ~1}, fn () => 
+                  ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
                    primWriteArr (fd, buf, C_Int.fromInt i, C_Size.fromInt sz))
                val bytesWrote = C_SSize.toInt bytesWrote
             in
@@ -259,7 +259,7 @@
                val (buf, i, sz) = VectorSlice.base (toVectorSlice sl)
                val bytesWrote =
                   SysCall.simpleResultRestart'
-                  ({errVal = C_SSize.fromInt ~1}, fn () => 
+                  ({errVal = C_SSize.castFromFixedInt ~1}, fn () => 
                    primWriteVec (fd, buf, C_Int.fromInt i, C_Size.fromInt sz))
                val bytesWrote = C_SSize.toInt bytesWrote
             in

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/proc-env.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -35,10 +35,10 @@
 
       fun setsid () = SysCall.simpleResult (Prim.setsid)
 
-      val uidToWord = C_UId.toSysWord
-      val wordToUid = C_UId.fromSysWord
-      val gidToWord = C_GId.toSysWord
-      val wordToGid = C_GId.fromSysWord
+      val uidToWord = C_UId.castToSysWord
+      val wordToUid = C_UId.castFromSysWord
+      val gidToWord = C_GId.castToSysWord
+      val wordToGid = C_GId.castFromSysWord
 
       fun getgroups () =
          SysCall.syscall
@@ -234,7 +234,7 @@
       in
          fun times () =
             SysCall.syscall'
-            ({errVal = C_Clock.fromInt ~1}, fn () =>
+            ({errVal = C_Clock.castFromFixedInt ~1}, fn () =>
              (Prim.times (), fn elapsed =>
               {elapsed = cvt elapsed,
                utime = cvt (Times.getUTime ()), 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/process.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -16,14 +16,14 @@
       type signal = PosixSignal.signal
       type pid = C_PId.t
 
-      val wordToPid = C_PId.fromSysWord
-      val pidToWord = C_PId.toSysWord
+      val wordToPid = C_PId.castFromSysWord
+      val pidToWord = C_PId.castToSysWord
 
       fun fork () =
          SysCall.syscall'
-         ({errVal = C_PId.fromInt ~1}, fn () =>
+         ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
           (Prim.fork (), fn p =>
-           if p = C_PId.fromInt 0 then NONE else SOME p))
+           if p = C_PId.castFromFixedInt 0 then NONE else SOME p))
 
       val fork =
          if Primitive.MLton.Platform.OS.forkIsEnabled
@@ -73,7 +73,7 @@
          if Prim.ifExited status
             then (case Prim.exitStatus status of
                      0 => W_EXITED
-                   | n => W_EXITSTATUS (Word8.fromSysWord (C_Int.toSysWord n)))
+                   | n => W_EXITSTATUS (Word8.castFromSysWord (C_Int.castToSysWord n)))
          else if Prim.ifSignaled status
             then W_SIGNALED (Prim.termSig status)
          else if Prim.ifStopped status
@@ -98,14 +98,14 @@
                   andalso case wa of W_CHILD _ => true | _ => false
                val pid =
                   case wa of
-                     W_ANY_CHILD => C_PId.fromInt ~1
+                     W_ANY_CHILD => C_PId.castFromFixedInt ~1
                    | W_CHILD pid => pid
-                   | W_SAME_GROUP => C_PId.fromInt 0
+                   | W_SAME_GROUP => C_PId.castFromFixedInt 0
                    | W_GROUP pid => C_PId.~ pid
                val flags = W.flags flags
             in
                SysCall.simpleResultRestart'
-               ({errVal = C_PId.fromInt ~1}, fn () =>
+               ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                 let
                    val pid = 
                       if useCwait 
@@ -128,7 +128,7 @@
             let
                val pid = wait (wa, status, W.nohang :: flags)
             in
-               if C_PId.fromInt 0 = pid
+               if C_PId.castFromFixedInt 0 = pid
                   then NONE
                else SOME (pid, getStatus ())
             end
@@ -140,7 +140,7 @@
          (* Posix.Process.exit does not call atExit cleaners, as per the basis
           * library spec.
           *)
-         (Prim.exit (C_Status.fromSysWord (Word8.toSysWord w))
+         (Prim.exit (C_Status.castFromSysWord (Word8.castToSysWord w))
           ; raise Fail "Posix.Process.exit")
 
       datatype killpid_arg  =
@@ -153,7 +153,7 @@
             val pid =
                case ka of
                   K_PROC pid => pid
-                | K_SAME_GROUP => C_PId.fromInt ~1
+                | K_SAME_GROUP => C_PId.castFromFixedInt ~1
                 | K_GROUP pid => C_PId.~ pid
          in
             SysCall.simple (fn () => Prim.kill (pid, s))
@@ -177,13 +177,13 @@
             val sec = LargeInt.quot (t, 1000000000)
             val nsec = LargeInt.rem (t, 1000000000)
             val (sec, nsec) =
-               (C_Time.fromLarge sec, C_Long.fromLarge nsec)
+               (C_Time.fromLargeInt sec, C_Long.fromLargeInt nsec)
                handle Overflow => Error.raiseSys Error.inval
             val secRem = ref sec
             val nsecRem = ref nsec
             fun remaining _ =
-               Time.+ (Time.fromSeconds (C_Time.toLarge (!secRem)),
-                       Time.fromNanoseconds (C_Long.toLarge (!nsecRem)))
+               Time.+ (Time.fromSeconds (C_Time.toLargeInt (!secRem)),
+                       Time.fromNanoseconds (C_Long.toLargeInt (!nsecRem)))
          in
             SysCall.syscallErr
             ({clear = false, restart = false, errVal = C_Int.fromInt ~1}, fn () =>

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/posix/tty.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -35,13 +35,13 @@
 
             type cc = C_CC.t array
 
-            val default = C_CC.fromSysWord 0w0
+            val default = C_CC.castFromSysWord 0w0
 
             fun new () = Array.array (nccs, default)
 
             fun updates (a, l) = 
                List.app (fn (i, cc) => 
-                         Array.update (a, i, (C_CC.fromSysWord o Word8.toSysWord o Byte.charToByte) cc)) 
+                         Array.update (a, i, (C_CC.castFromSysWord o Word8.castToSysWord o Byte.charToByte) cc)) 
                         l
 
             fun cc l = let val a = new ()
@@ -56,7 +56,7 @@
                   ; a'
                end
 
-            val sub = (Byte.byteToChar o Word8.fromSysWord o C_CC.toSysWord) o Array.sub
+            val sub = (Byte.byteToChar o Word8.castFromSysWord o C_CC.castToSysWord) o Array.sub
          end
       
       structure Flags = BitFlags(structure S = C_TCFlag)
@@ -160,8 +160,8 @@
       val b9600 = B9600
 
       val compareSpeed = C_Speed.compare
-      val speedToWord = C_Speed.toSysWord
-      val wordToSpeed = C_Speed.fromSysWord
+      val speedToWord = C_Speed.castToSysWord
+      val wordToSpeed = C_Speed.castFromSysWord
 
       type termios = {iflag: I.flags,
                       oflag: O.flags,
@@ -269,7 +269,7 @@
               
             fun getpgrp fd =
                SysCall.simpleResultRestart'
-               ({errVal = C_PId.fromInt ~1}, fn () =>
+               ({errVal = C_PId.castFromFixedInt ~1}, fn () =>
                 Prim.TC.getpgrp fd)
               
             fun setpgrp (fd, pid) = 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-char.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-char.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-char.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -18,25 +18,10 @@
          
       val < = _prim "WordU8_lt": char * char -> bool;
 
-      val fromInt8Unsafe = _prim "WordS8_toWord8": Int8.int -> char;
-      val fromInt16Unsafe = _prim "WordS16_toWord8": Int16.int -> char;
-      val fromInt32Unsafe = _prim "WordS32_toWord8": Int32.int -> char;
-      val fromInt64Unsafe = _prim "WordS64_toWord8": Int64.int -> char;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord8": Word8.word -> char;
-      val fromWord16Unsafe = _prim "WordU16_toWord8": Word16.word -> char;
-      val fromWord32Unsafe = _prim "WordU32_toWord8": Word32.word -> char;
-      val fromWord64Unsafe = _prim "WordU64_toWord8": Word64.word -> char;
-
-      val toInt8Unsafe = _prim "WordS8_toWord8": char -> Int8.int;
-      val toInt16Unsafe = _prim "WordS8_toWord16": char -> Int16.int;
-      val toInt32Unsafe = _prim "WordS8_toWord32": char -> Int32.int;
-      val toInt64Unsafe = _prim "WordS8_toWord64": char -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU8_toWord8": char -> Word8.word;
-      val toWord16Unsafe = _prim "WordU8_toWord16": char -> Word16.word;
-      val toWord32Unsafe = _prim "WordU8_toWord32": char -> Word32.word;
-      val toWord64Unsafe = _prim "WordU8_toWord64": char -> Word64.word;
+      val idToWord8 = _prim "WordU8_toWord8": char -> Word8.word;
+      val idFromWord8 = _prim "WordU8_toWord8": Word8.word -> char;
+      val idToInt8 = _prim "WordS8_toWord8": char -> Int8.int;
+      val idFromInt8 = _prim "WordS8_toWord8": Int8.int -> char;
    end
 structure Char8 = 
    struct
@@ -54,25 +39,10 @@
          
       val < = _prim "WordU16_lt": char * char -> bool;
 
-      val fromInt8Unsafe = _prim "WordS8_toWord16": Int8.int -> char;
-      val fromInt16Unsafe = _prim "WordS16_toWord16": Int16.int -> char;
-      val fromInt32Unsafe = _prim "WordS32_toWord16": Int32.int -> char;
-      val fromInt64Unsafe = _prim "WordS64_toWord16": Int64.int -> char;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord16": Word8.word -> char;
-      val fromWord16Unsafe = _prim "WordU16_toWord16": Word16.word -> char;
-      val fromWord32Unsafe = _prim "WordU32_toWord16": Word32.word -> char;
-      val fromWord64Unsafe = _prim "WordU64_toWord16": Word64.word -> char;
-
-      val toInt8Unsafe = _prim "WordS16_toWord8": char -> Int8.int;
-      val toInt16Unsafe = _prim "WordS16_toWord16": char -> Int16.int;
-      val toInt32Unsafe = _prim "WordS16_toWord32": char -> Int32.int;
-      val toInt64Unsafe = _prim "WordS16_toWord64": char -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU16_toWord8": char -> Word8.word;
-      val toWord16Unsafe = _prim "WordU16_toWord16": char -> Word16.word;
-      val toWord32Unsafe = _prim "WordU16_toWord32": char -> Word32.word;
-      val toWord64Unsafe = _prim "WordU16_toWord64": char -> Word64.word;
+      val idToWord16 = _prim "WordU16_toWord16": char -> Word16.word;
+      val idFromWord16 = _prim "WordU16_toWord16": Word16.word -> char;
+      val idToInt16 = _prim "WordS16_toWord16": char -> Int16.int;
+      val idFromInt16 = _prim "WordS16_toWord16": Int16.int -> char;
    end
 structure Char16 = 
    struct
@@ -90,25 +60,10 @@
          
       val < = _prim "WordU32_lt": char * char -> bool;
 
-      val fromInt8Unsafe = _prim "WordS8_toWord32": Int8.int -> char;
-      val fromInt16Unsafe = _prim "WordS16_toWord32": Int16.int -> char;
-      val fromInt32Unsafe = _prim "WordS32_toWord32": Int32.int -> char;
-      val fromInt64Unsafe = _prim "WordS64_toWord32": Int64.int -> char;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord32": Word8.word -> char;
-      val fromWord16Unsafe = _prim "WordU16_toWord32": Word16.word -> char;
-      val fromWord32Unsafe = _prim "WordU32_toWord32": Word32.word -> char;
-      val fromWord64Unsafe = _prim "WordU64_toWord32": Word64.word -> char;
-
-      val toInt8Unsafe = _prim "WordS32_toWord8": char -> Int8.int;
-      val toInt16Unsafe = _prim "WordS32_toWord16": char -> Int16.int;
-      val toInt32Unsafe = _prim "WordS32_toWord32": char -> Int32.int;
-      val toInt64Unsafe = _prim "WordS32_toWord64": char -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU32_toWord8": char -> Word8.word;
-      val toWord16Unsafe = _prim "WordU32_toWord16": char -> Word16.word;
-      val toWord32Unsafe = _prim "WordU32_toWord32": char -> Word32.word;
-      val toWord64Unsafe = _prim "WordU32_toWord64": char -> Word64.word;
+      val idToWord32 = _prim "WordU32_toWord32": char -> Word32.word;
+      val idFromWord32 = _prim "WordU32_toWord32": Word32.word -> char;
+      val idToInt32 = _prim "WordS32_toWord32": char -> Int32.int;
+      val idFromInt32 = _prim "WordS32_toWord32": Int32.int -> char;
    end
 structure Char32 = 
    struct

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-int.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -13,9 +13,8 @@
       eqtype int
       type t = int
 
-      val precision' : Primitive.Int32.int
-      val maxInt': int
-      val minInt': int
+      val sizeInBits: Primitive.Int32.int
+      val sizeInBitsWord: Primitive.Word32.word
        
       val +? : int * int -> int
       val + : int * int -> int
@@ -35,72 +34,6 @@
       val compare: int * int -> Primitive.Order.order
       val min: int * int -> int
       val max: int * int -> int
-      val ltu: int * int -> bool
-      val leu: int * int -> bool
-      val gtu: int * int -> bool
-      val geu: int * int -> bool
-
-      val andb: int * int -> int
-      val <<? : int * Primitive.Word32.word -> int
-      val notb: int -> int
-      val orb: int * int -> int
-      val rolUnsafe: int * Primitive.Word32.word -> int
-      val rorUnsafe: int * Primitive.Word32.word -> int
-      val ~>>? : int * Primitive.Word32.word -> int
-      val >>? : int * Primitive.Word32.word -> int
-      val xorb: int * int -> int
-
-      (* Lowbits or sign extend. *)
-      val fromInt8Unsafe: Primitive.Int8.int -> int
-      val fromInt16Unsafe: Primitive.Int16.int -> int
-      val fromInt32Unsafe: Primitive.Int32.int -> int
-      val fromInt64Unsafe: Primitive.Int64.int -> int
-
-(*
-      (* Lowbits or zero extend. *)
-      val fromInt8ZUnsafe: Primitive.Int8.int -> int
-      val fromInt16ZUnsafe: Primitive.Int16.int -> int
-      val fromInt32ZUnsafe: Primitive.Int32.int -> int
-      val fromInt64ZUnsafe: Primitive.Int64.int -> int
-*)
-
-      (* Lowbits or zero extend. *)
-      val fromWord8Unsafe: Primitive.Word8.word -> int
-      val fromWord16Unsafe: Primitive.Word16.word -> int
-      val fromWord32Unsafe: Primitive.Word32.word -> int
-      val fromWord64Unsafe: Primitive.Word64.word -> int
-
-      (* Lowbits or sign extend. *)
-      val fromWord8XUnsafe: Primitive.Word8.word -> int
-      val fromWord16XUnsafe: Primitive.Word16.word -> int
-      val fromWord32XUnsafe: Primitive.Word32.word -> int
-      val fromWord64XUnsafe: Primitive.Word64.word -> int
-
-      (* Lowbits or sign extend. *)
-      val toInt8Unsafe: int -> Primitive.Int8.int
-      val toInt16Unsafe: int -> Primitive.Int16.int
-      val toInt32Unsafe: int -> Primitive.Int32.int
-      val toInt64Unsafe: int -> Primitive.Int64.int
-
-(*
-      (* Lowbits or zero extend. *)
-      val toInt8ZUnsafe: int -> Primitive.Int8.int
-      val toInt16ZUnsafe: int -> Primitive.Int16.int
-      val toInt32ZUnsafe: int -> Primitive.Int32.int
-      val toInt64ZUnsafe: int -> Primitive.Int64.int
-*)
-
-      (* Lowbits or zero extend. *)
-      val toWord8Unsafe: int -> Primitive.Word8.word
-      val toWord16Unsafe: int -> Primitive.Word16.word
-      val toWord32Unsafe: int -> Primitive.Word32.word
-      val toWord64Unsafe: int -> Primitive.Word64.word
-
-      (* Lowbits or sign extend. *)
-      val toWord8XUnsafe: int -> Primitive.Word8.word
-      val toWord16XUnsafe: int -> Primitive.Word16.word
-      val toWord32XUnsafe: int -> Primitive.Word32.word
-      val toWord64XUnsafe: int -> Primitive.Word64.word
    end
 
 structure Primitive = struct
@@ -112,7 +45,7 @@
       open Int1
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord1": big -> int;
-      val precision' : Int32.int = 1
+      val sizeInBits: Int32.int = 1
       val toBig = _prim "WordU1_toWord8": int -> big;
    end
 structure Int2 =
@@ -120,7 +53,7 @@
       open Int2
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord2": big -> int;
-      val precision' : Int32.int = 2
+      val sizeInBits: Int32.int = 2
       val toBig = _prim "WordU2_toWord8": int -> big;
    end
 structure Int3 =
@@ -128,7 +61,7 @@
       open Int3
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord3": big -> int;
-      val precision' : Int32.int = 3
+      val sizeInBits: Int32.int = 3
       val toBig = _prim "WordU3_toWord8": int -> big;
    end
 structure Int4 =
@@ -136,7 +69,7 @@
       open Int4
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord4": big -> int;
-      val precision' : Int32.int = 4
+      val sizeInBits: Int32.int = 4
       val toBig = _prim "WordU4_toWord8": int -> big;
    end
 structure Int5 =
@@ -144,7 +77,7 @@
       open Int5
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord5": big -> int;
-      val precision' : Int32.int = 5
+      val sizeInBits: Int32.int = 5
       val toBig = _prim "WordU5_toWord8": int -> big;
    end
 structure Int6 =
@@ -152,7 +85,7 @@
       open Int6
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord6": big -> int;
-      val precision' : Int32.int = 6
+      val sizeInBits: Int32.int = 6
       val toBig = _prim "WordU6_toWord8": int -> big;
    end
 structure Int7 =
@@ -160,16 +93,16 @@
       open Int7
       type big = Int8.int
       val fromBigUnsafe = _prim "WordU8_toWord7": big -> int;
-      val precision' : Int32.int = 7
+      val sizeInBits: Int32.int = 7
       val toBig = _prim "WordU7_toWord8": int -> big;
    end
 structure Int8 =
    struct
       open Int8
                
-      val precision' : Int32.int = 8
-      val maxInt' : int = 0x7f
-      val minInt' : int = ~0x80
+      val sizeInBits: Int32.int = 8
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
          
       val +? = _prim "Word8_add": int * int -> int;
       val + =
@@ -195,60 +128,6 @@
       val remUnsafe = _prim "WordS8_rem": int * int -> int;
 
       val < = _prim "WordS8_lt": int * int -> bool;
-
-      val andb = _prim "Word8_andb": int * int -> int;
-      val <<? = _prim "Word8_lshift": int * Word32.word -> int;
-      val notb = _prim "Word8_notb": int -> int;
-      val orb = _prim "Word8_orb": int * int -> int;
-      val rolUnsafe = _prim "Word8_rol": int * Word32.word -> int;
-      val rorUnsafe = _prim "Word8_ror": int * Word32.word -> int;
-      val ~>>? = _prim "WordS8_rshift": int * Word32.word -> int;
-      val >>? = _prim "WordU8_rshift": int * Word32.word -> int;
-      val xorb = _prim "Word8_xorb": int * int -> int;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord8": Int8.int -> int;
-      val fromInt16Unsafe = _prim "WordS16_toWord8": Int16.int -> int;
-      val fromInt32Unsafe = _prim "WordS32_toWord8": Int32.int -> int;
-      val fromInt64Unsafe = _prim "WordS64_toWord8": Int64.int -> int;
-
-(*
-      val fromInt8ZUnsafe = _prim "WordU8_toWord8": Int8.int -> int;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord8": Int16.int -> int;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord8": Int32.int -> int;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord8": Int64.int -> int;
-*)
-
-      val fromWord8Unsafe = _prim "WordU8_toWord8": Word8.word -> int;
-      val fromWord16Unsafe = _prim "WordU16_toWord8": Word16.word -> int;
-      val fromWord32Unsafe = _prim "WordU32_toWord8": Word32.word -> int;
-      val fromWord64Unsafe = _prim "WordU64_toWord8": Word64.word -> int;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord8": Word8.word -> int;
-      val fromWord16XUnsafe = _prim "WordS16_toWord8": Word16.word -> int;
-      val fromWord32XUnsafe = _prim "WordS32_toWord8": Word32.word -> int;
-      val fromWord64XUnsafe = _prim "WordS64_toWord8": Word64.word -> int;
-
-      val toInt8Unsafe = _prim "WordS8_toWord8": int -> Int8.int;
-      val toInt16Unsafe = _prim "WordS8_toWord16": int -> Int16.int;
-      val toInt32Unsafe = _prim "WordS8_toWord32": int -> Int32.int;
-      val toInt64Unsafe = _prim "WordS8_toWord64": int -> Int64.int;
-
-(*
-      val toInt8ZUnsafe = _prim "WordU8_toWord8": int -> Int8.int;
-      val toInt16ZUnsafe = _prim "WordU8_toWord16": int -> Int16.int;
-      val toInt32ZUnsafe = _prim "WordU8_toWord32": int -> Int32.int;
-      val toInt64ZUnsafe = _prim "WordU8_toWord64": int -> Int64.int;
-*)
-
-      val toWord8Unsafe = _prim "WordU8_toWord8": int -> Word8.word;
-      val toWord16Unsafe = _prim "WordU8_toWord16": int -> Word16.word;
-      val toWord32Unsafe = _prim "WordU8_toWord32": int -> Word32.word;
-      val toWord64Unsafe = _prim "WordU8_toWord64": int -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS8_toWord8": int -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS8_toWord16": int -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS8_toWord32": int -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS8_toWord64": int -> Word64.word;
    end
 structure Int8 : PRIM_INTEGER =
    struct
@@ -258,21 +137,13 @@
       in
          open S
       end
-      local
-         structure S = UnsignedIntegralComparisons(type int = Int8.int
-                                                   type word = Word8.word
-                                                   val fromInt = Word8.fromInt8Unsafe
-                                                   val < = Word8.<)
-      in
-         open S
-      end
    end
 structure Int9 =
    struct
       open Int9
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord9": big -> int;
-      val precision' : Int32.int = 9
+      val sizeInBits: Int32.int = 9
       val toBig = _prim "WordU9_toWord16": int -> big;
    end
 structure Int10 =
@@ -280,7 +151,7 @@
       open Int10
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord10": big -> int;
-      val precision' : Int32.int = 10
+      val sizeInBits: Int32.int = 10
       val toBig = _prim "WordU10_toWord16": int -> big;
    end
 structure Int11 =
@@ -288,7 +159,7 @@
       open Int11
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord11": big -> int;
-      val precision' : Int32.int = 11
+      val sizeInBits: Int32.int = 11
       val toBig = _prim "WordU11_toWord16": int -> big;
    end
 structure Int12 =
@@ -296,7 +167,7 @@
       open Int12
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord12": big -> int;
-      val precision' : Int32.int = 12
+      val sizeInBits: Int32.int = 12
       val toBig = _prim "WordU12_toWord16": int -> big;
    end
 structure Int13 =
@@ -304,7 +175,7 @@
       open Int13
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord13": big -> int;
-      val precision' : Int32.int = 13
+      val sizeInBits: Int32.int = 13
       val toBig = _prim "WordU13_toWord16": int -> big;
    end
 structure Int14 =
@@ -312,7 +183,7 @@
       open Int14
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord14": big -> int;
-      val precision' : Int32.int = 14
+      val sizeInBits: Int32.int = 14
       val toBig = _prim "WordU14_toWord16": int -> big;
    end
 structure Int15 =
@@ -320,16 +191,16 @@
       open Int15
       type big = Int16.int
       val fromBigUnsafe = _prim "WordU16_toWord15": big -> int;
-      val precision' : Int32.int = 15
+      val sizeInBits: Int32.int = 15
       val toBig = _prim "WordU15_toWord16": int -> big;
    end
 structure Int16 =
    struct
       open Int16
                
-      val precision' : Int32.int = 16
-      val maxInt' : int = 0x7fff
-      val minInt' : int = ~0x8000
+      val sizeInBits: Int32.int = 16
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
          
       val +? = _prim "Word16_add": int * int -> int;
       val + =
@@ -355,60 +226,6 @@
       val remUnsafe = _prim "WordS16_rem": int * int -> int;
 
       val < = _prim "WordS16_lt": int * int -> bool;
-
-      val andb = _prim "Word16_andb": int * int -> int;
-      val <<? = _prim "Word16_lshift": int * Word32.word -> int;
-      val notb = _prim "Word16_notb": int -> int;
-      val orb = _prim "Word16_orb": int * int -> int;
-      val rolUnsafe = _prim "Word16_rol": int * Word32.word -> int;
-      val rorUnsafe = _prim "Word16_ror": int * Word32.word -> int;
-      val ~>>? = _prim "WordS16_rshift": int * Word32.word -> int;
-      val >>? = _prim "WordU16_rshift": int * Word32.word -> int;
-      val xorb = _prim "Word16_xorb": int * int -> int;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord16": Int8.int -> int;
-      val fromInt16Unsafe = _prim "WordS16_toWord16": Int16.int -> int;
-      val fromInt32Unsafe = _prim "WordS32_toWord16": Int32.int -> int;
-      val fromInt64Unsafe = _prim "WordS64_toWord16": Int64.int -> int;
-
-(*
-      val fromInt8ZUnsafe = _prim "WordU8_toWord16": Int8.int -> int;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord16": Int16.int -> int;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord16": Int32.int -> int;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord16": Int64.int -> int;
-*)
-
-      val fromWord8Unsafe = _prim "WordU8_toWord16": Word8.word -> int;
-      val fromWord16Unsafe = _prim "WordU16_toWord16": Word16.word -> int;
-      val fromWord32Unsafe = _prim "WordU32_toWord16": Word32.word -> int;
-      val fromWord64Unsafe = _prim "WordU64_toWord16": Word64.word -> int;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord16": Word8.word -> int;
-      val fromWord16XUnsafe = _prim "WordS16_toWord16": Word16.word -> int;
-      val fromWord32XUnsafe = _prim "WordS32_toWord16": Word32.word -> int;
-      val fromWord64XUnsafe = _prim "WordS64_toWord16": Word64.word -> int;
-
-      val toInt8Unsafe = _prim "WordS16_toWord8": int -> Int8.int;
-      val toInt16Unsafe = _prim "WordS16_toWord16": int -> Int16.int;
-      val toInt32Unsafe = _prim "WordS16_toWord32": int -> Int32.int;
-      val toInt64Unsafe = _prim "WordS16_toWord64": int -> Int64.int;
-
-(*
-      val toInt8ZUnsafe = _prim "WordU16_toWord8": int -> Int8.int;
-      val toInt16ZUnsafe = _prim "WordU16_toWord16": int -> Int16.int;
-      val toInt32ZUnsafe = _prim "WordU16_toWord32": int -> Int32.int;
-      val toInt64ZUnsafe = _prim "WordU16_toWord64": int -> Int64.int;
-*)
-
-      val toWord8Unsafe = _prim "WordU16_toWord8": int -> Word8.word;
-      val toWord16Unsafe = _prim "WordU16_toWord16": int -> Word16.word;
-      val toWord32Unsafe = _prim "WordU16_toWord32": int -> Word32.word;
-      val toWord64Unsafe = _prim "WordU16_toWord64": int -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS16_toWord8": int -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS16_toWord16": int -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS16_toWord32": int -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS16_toWord64": int -> Word64.word;
    end
 structure Int16 : PRIM_INTEGER =
    struct
@@ -418,21 +235,13 @@
       in
          open S
       end
-      local
-         structure S = UnsignedIntegralComparisons(type int = Int16.int
-                                                   type word = Word16.word
-                                                   val fromInt = Word16.fromInt16Unsafe
-                                                   val < = Word16.<)
-      in
-         open S
-      end
    end
 structure Int17 =
    struct
       open Int17
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord17": big -> int;
-      val precision' : Int32.int = 17
+      val sizeInBits: Int32.int = 17
       val toBig = _prim "WordU17_toWord32": int -> big;
    end
 structure Int18 =
@@ -440,7 +249,7 @@
       open Int18
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord18": big -> int;
-      val precision' : Int32.int = 18
+      val sizeInBits: Int32.int = 18
       val toBig = _prim "WordU18_toWord32": int -> big;
    end
 structure Int19 =
@@ -448,7 +257,7 @@
       open Int19
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord19": big -> int;
-      val precision' : Int32.int = 19
+      val sizeInBits: Int32.int = 19
       val toBig = _prim "WordU19_toWord32": int -> big;
    end
 structure Int20 =
@@ -456,7 +265,7 @@
       open Int20
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord20": big -> int;
-      val precision' : Int32.int = 20
+      val sizeInBits: Int32.int = 20
       val toBig = _prim "WordU20_toWord32": int -> big;
    end
 structure Int21 =
@@ -464,7 +273,7 @@
       open Int21
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord21": big -> int;
-      val precision' : Int32.int = 21
+      val sizeInBits: Int32.int = 21
       val toBig = _prim "WordU21_toWord32": int -> big;
    end
 structure Int22 =
@@ -472,7 +281,7 @@
       open Int22
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord22": big -> int;
-      val precision' : Int32.int = 22
+      val sizeInBits: Int32.int = 22
       val toBig = _prim "WordU22_toWord32": int -> big;
    end
 structure Int23 =
@@ -480,7 +289,7 @@
       open Int23
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord23": big -> int;
-      val precision' : Int32.int = 23
+      val sizeInBits: Int32.int = 23
       val toBig = _prim "WordU23_toWord32": int -> big;
    end
 structure Int24 =
@@ -488,7 +297,7 @@
       open Int24
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord24": big -> int;
-      val precision' : Int32.int = 24
+      val sizeInBits: Int32.int = 24
       val toBig = _prim "WordU24_toWord32": int -> big;
    end
 structure Int25 =
@@ -496,7 +305,7 @@
       open Int25
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord25": big -> int;
-      val precision' : Int32.int = 25
+      val sizeInBits: Int32.int = 25
       val toBig = _prim "WordU25_toWord32": int -> big;
    end
 structure Int26 =
@@ -504,7 +313,7 @@
       open Int26
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord26": big -> int;
-      val precision' : Int32.int = 26
+      val sizeInBits: Int32.int = 26
       val toBig = _prim "WordU26_toWord32": int -> big;
    end
 structure Int27 =
@@ -512,7 +321,7 @@
       open Int27
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord27": big -> int;
-      val precision' : Int32.int = 27
+      val sizeInBits: Int32.int = 27
       val toBig = _prim "WordU27_toWord32": int -> big;
    end
 structure Int28 =
@@ -520,7 +329,7 @@
       open Int28
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord28": big -> int;
-      val precision' : Int32.int = 28
+      val sizeInBits: Int32.int = 28
       val toBig = _prim "WordU28_toWord32": int -> big;
    end
 structure Int29 =
@@ -528,7 +337,7 @@
       open Int29
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord29": big -> int;
-      val precision' : Int32.int = 29
+      val sizeInBits: Int32.int = 29
       val toBig = _prim "WordU29_toWord32": int -> big;
    end
 structure Int30 =
@@ -536,7 +345,7 @@
       open Int30
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord30": big -> int;
-      val precision' : Int32.int = 30
+      val sizeInBits: Int32.int = 30
       val toBig = _prim "WordU30_toWord32": int -> big;
    end
 structure Int31 =
@@ -544,16 +353,16 @@
       open Int31
       type big = Int32.int
       val fromBigUnsafe = _prim "WordU32_toWord31": big -> int;
-      val precision' : Int32.int = 31
+      val sizeInBits: Int32.int = 31
       val toBig = _prim "WordU31_toWord32": int -> big;
    end
 structure Int32 =
    struct
       open Int32
                
-      val precision' : Int32.int = 32
-      val maxInt' : int = 0x7fffffff
-      val minInt' : int = ~0x80000000
+      val sizeInBits: Int32.int = 32
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
          
       val +? = _prim "Word32_add": int * int -> int;
       val + =
@@ -579,60 +388,6 @@
       val remUnsafe = _prim "WordS32_rem": int * int -> int;
 
       val < = _prim "WordS32_lt": int * int -> bool;
-
-      val andb = _prim "Word32_andb": int * int -> int;
-      val <<? = _prim "Word32_lshift": int * Word32.word -> int;
-      val notb = _prim "Word32_notb": int -> int;
-      val orb = _prim "Word32_orb": int * int -> int;
-      val rolUnsafe = _prim "Word32_rol": int * Word32.word -> int;
-      val rorUnsafe = _prim "Word32_ror": int * Word32.word -> int;
-      val ~>>? = _prim "WordS32_rshift": int * Word32.word -> int;
-      val >>? = _prim "WordU32_rshift": int * Word32.word -> int;
-      val xorb = _prim "Word32_xorb": int * int -> int;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord32": Int8.int -> int;
-      val fromInt16Unsafe = _prim "WordS16_toWord32": Int16.int -> int;
-      val fromInt32Unsafe = _prim "WordS32_toWord32": Int32.int -> int;
-      val fromInt64Unsafe = _prim "WordS64_toWord32": Int64.int -> int;
-
-(*
-      val fromInt8ZUnsafe = _prim "WordU8_toWord32": Int8.int -> int;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord32": Int16.int -> int;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord32": Int32.int -> int;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord32": Int64.int -> int;
-*)
-
-      val fromWord8Unsafe = _prim "WordU8_toWord32": Word8.word -> int;
-      val fromWord16Unsafe = _prim "WordU16_toWord32": Word16.word -> int;
-      val fromWord32Unsafe = _prim "WordU32_toWord32": Word32.word -> int;
-      val fromWord64Unsafe = _prim "WordU64_toWord32": Word64.word -> int;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord32": Word8.word -> int;
-      val fromWord16XUnsafe = _prim "WordS16_toWord32": Word16.word -> int;
-      val fromWord32XUnsafe = _prim "WordS32_toWord32": Word32.word -> int;
-      val fromWord64XUnsafe = _prim "WordS64_toWord32": Word64.word -> int;
-
-      val toInt8Unsafe = _prim "WordS32_toWord8": int -> Int8.int;
-      val toInt16Unsafe = _prim "WordS32_toWord16": int -> Int16.int;
-      val toInt32Unsafe = _prim "WordS32_toWord32": int -> Int32.int;
-      val toInt64Unsafe = _prim "WordS32_toWord64": int -> Int64.int;
-
-(*
-      val toInt8ZUnsafe = _prim "WordU32_toWord8": int -> Int8.int;
-      val toInt16ZUnsafe = _prim "WordU32_toWord16": int -> Int16.int;
-      val toInt32ZUnsafe = _prim "WordU32_toWord32": int -> Int32.int;
-      val toInt64ZUnsafe = _prim "WordU32_toWord64": int -> Int64.int;
-*)
-
-      val toWord8Unsafe = _prim "WordU32_toWord8": int -> Word8.word;
-      val toWord16Unsafe = _prim "WordU32_toWord16": int -> Word16.word;
-      val toWord32Unsafe = _prim "WordU32_toWord32": int -> Word32.word;
-      val toWord64Unsafe = _prim "WordU32_toWord64": int -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS32_toWord8": int -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS32_toWord16": int -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS32_toWord32": int -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS32_toWord64": int -> Word64.word;
    end
 structure Int32 : PRIM_INTEGER =
    struct
@@ -642,22 +397,14 @@
       in
          open S
       end
-      local
-         structure S = UnsignedIntegralComparisons(type int = Int32.int
-                                                   type word = Word32.word
-                                                   val fromInt = Word32.fromInt32Unsafe
-                                                   val < = Word32.<)
-      in
-         open S
-      end
    end
 structure Int64 =
    struct
       open Int64
                
-      val precision' : Int32.int = 64
-      val maxInt' : int = 0x7fffffffffffffff
-      val minInt' : int = ~0x8000000000000000
+      val sizeInBits: Int32.int = 64
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
          
       val +? = _prim "Word64_add": int * int -> int;
       val + =
@@ -683,60 +430,6 @@
       val remUnsafe = _prim "WordS64_rem": int * int -> int;
 
       val < = _prim "WordS64_lt": int * int -> bool;
-
-      val andb = _prim "Word64_andb": int * int -> int;
-      val <<? = _prim "Word64_lshift": int * Word32.word -> int;
-      val notb = _prim "Word64_notb": int -> int;
-      val orb = _prim "Word64_orb": int * int -> int;
-      val rolUnsafe = _prim "Word64_rol": int * Word32.word -> int;
-      val rorUnsafe = _prim "Word64_ror": int * Word32.word -> int;
-      val ~>>? = _prim "WordS64_rshift": int * Word32.word -> int;
-      val >>? = _prim "WordU64_rshift": int * Word32.word -> int;
-      val xorb = _prim "Word64_xorb": int * int -> int;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord64": Int8.int -> int;
-      val fromInt16Unsafe = _prim "WordS16_toWord64": Int16.int -> int;
-      val fromInt32Unsafe = _prim "WordS32_toWord64": Int32.int -> int;
-      val fromInt64Unsafe = _prim "WordS64_toWord64": Int64.int -> int;
-
-(*
-      val fromInt8ZUnsafe = _prim "WordU8_toWord64": Int8.int -> int;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord64": Int16.int -> int;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord64": Int32.int -> int;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord64": Int64.int -> int;
-*)
-
-      val fromWord8Unsafe = _prim "WordU8_toWord64": Word8.word -> int;
-      val fromWord16Unsafe = _prim "WordU16_toWord64": Word16.word -> int;
-      val fromWord32Unsafe = _prim "WordU32_toWord64": Word32.word -> int;
-      val fromWord64Unsafe = _prim "WordU64_toWord64": Word64.word -> int;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord64": Word8.word -> int;
-      val fromWord16XUnsafe = _prim "WordS16_toWord64": Word16.word -> int;
-      val fromWord32XUnsafe = _prim "WordS32_toWord64": Word32.word -> int;
-      val fromWord64XUnsafe = _prim "WordS64_toWord64": Word64.word -> int;
-
-      val toInt8Unsafe = _prim "WordS64_toWord8": int -> Int8.int;
-      val toInt16Unsafe = _prim "WordS64_toWord16": int -> Int16.int;
-      val toInt32Unsafe = _prim "WordS64_toWord32": int -> Int32.int;
-      val toInt64Unsafe = _prim "WordS64_toWord64": int -> Int64.int;
-
-(*
-      val toInt8ZUnsafe = _prim "WordU64_toWord8": int -> Int8.int;
-      val toInt16ZUnsafe = _prim "WordU64_toWord16": int -> Int16.int;
-      val toInt32ZUnsafe = _prim "WordU64_toWord32": int -> Int32.int;
-      val toInt64ZUnsafe = _prim "WordU64_toWord64": int -> Int64.int;
-*)
-
-      val toWord8Unsafe = _prim "WordU64_toWord8": int -> Word8.word;
-      val toWord16Unsafe = _prim "WordU64_toWord16": int -> Word16.word;
-      val toWord32Unsafe = _prim "WordU64_toWord32": int -> Word32.word;
-      val toWord64Unsafe = _prim "WordU64_toWord64": int -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS64_toWord8": int -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS64_toWord16": int -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS64_toWord32": int -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS64_toWord64": int -> Word64.word;
    end
 structure Int64 : PRIM_INTEGER =
    struct
@@ -746,14 +439,6 @@
       in
          open S
       end
-      local
-         structure S = UnsignedIntegralComparisons(type int = Int64.int
-                                                   type word = Word64.word
-                                                   val fromInt = Word64.fromInt64Unsafe
-                                                   val < = Word64.<)
-      in
-         open S
-      end
    end
 
 end

Added: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-iwconv.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-iwconv.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-iwconv.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -0,0 +1,493 @@
+(* Copyright (C) 1999-2006 Henry Cejtin, Matthew Fluet, Suresh
+ *    Jagannathan, and Stephen Weeks.
+ * Copyright (C) 1997-2000 NEC Research Institute.
+ *
+ * MLton is released under a BSD-style license.
+ * See the file MLton-LICENSE for details.
+ *)
+
+(* Primitive names are special -- see atoms/prim.fun. *)
+
+signature PRIM_INTWORD_CONV =
+   sig
+      (* identity *)
+      val idFromInt8ToInt8: Primitive.Int8.int -> Primitive.Int8.int
+      val idFromInt8ToWord8: Primitive.Int8.int -> Primitive.Word8.word
+      val idFromInt16ToInt16: Primitive.Int16.int -> Primitive.Int16.int
+      val idFromInt16ToWord16: Primitive.Int16.int -> Primitive.Word16.word
+      val idFromInt32ToInt32: Primitive.Int32.int -> Primitive.Int32.int
+      val idFromInt32ToWord32: Primitive.Int32.int -> Primitive.Word32.word
+      val idFromInt64ToInt64: Primitive.Int64.int -> Primitive.Int64.int
+      val idFromInt64ToWord64: Primitive.Int64.int -> Primitive.Word64.word
+      val idFromWord8ToInt8: Primitive.Word8.word -> Primitive.Int8.int
+      val idFromWord8ToWord8: Primitive.Word8.word -> Primitive.Word8.word
+      val idFromWord16ToInt16: Primitive.Word16.word -> Primitive.Int16.int
+      val idFromWord16ToWord16: Primitive.Word16.word -> Primitive.Word16.word
+      val idFromWord32ToInt32: Primitive.Word32.word -> Primitive.Int32.int
+      val idFromWord32ToWord32: Primitive.Word32.word -> Primitive.Word32.word
+      val idFromWord64ToInt64: Primitive.Word64.word -> Primitive.Int64.int
+      val idFromWord64ToWord64: Primitive.Word64.word -> Primitive.Word64.word
+
+      (* zero-extend or low-bits *)
+      val zextdFromInt8ToInt8: Primitive.Int8.int -> Primitive.Int8.int
+      val zextdFromInt8ToInt16: Primitive.Int8.int -> Primitive.Int16.int
+      val zextdFromInt8ToInt32: Primitive.Int8.int -> Primitive.Int32.int
+      val zextdFromInt8ToInt64: Primitive.Int8.int -> Primitive.Int64.int
+      val zextdFromInt8ToWord8: Primitive.Int8.int -> Primitive.Word8.word
+      val zextdFromInt8ToWord16: Primitive.Int8.int -> Primitive.Word16.word
+      val zextdFromInt8ToWord32: Primitive.Int8.int -> Primitive.Word32.word
+      val zextdFromInt8ToWord64: Primitive.Int8.int -> Primitive.Word64.word
+
+      val zextdFromInt16ToInt8: Primitive.Int16.int -> Primitive.Int8.int
+      val zextdFromInt16ToInt16: Primitive.Int16.int -> Primitive.Int16.int
+      val zextdFromInt16ToInt32: Primitive.Int16.int -> Primitive.Int32.int
+      val zextdFromInt16ToInt64: Primitive.Int16.int -> Primitive.Int64.int
+      val zextdFromInt16ToWord8: Primitive.Int16.int -> Primitive.Word8.word
+      val zextdFromInt16ToWord16: Primitive.Int16.int -> Primitive.Word16.word
+      val zextdFromInt16ToWord32: Primitive.Int16.int -> Primitive.Word32.word
+      val zextdFromInt16ToWord64: Primitive.Int16.int -> Primitive.Word64.word
+
+      val zextdFromInt32ToInt8: Primitive.Int32.int -> Primitive.Int8.int
+      val zextdFromInt32ToInt16: Primitive.Int32.int -> Primitive.Int16.int
+      val zextdFromInt32ToInt32: Primitive.Int32.int -> Primitive.Int32.int
+      val zextdFromInt32ToInt64: Primitive.Int32.int -> Primitive.Int64.int
+      val zextdFromInt32ToWord8: Primitive.Int32.int -> Primitive.Word8.word
+      val zextdFromInt32ToWord16: Primitive.Int32.int -> Primitive.Word16.word
+      val zextdFromInt32ToWord32: Primitive.Int32.int -> Primitive.Word32.word
+      val zextdFromInt32ToWord64: Primitive.Int32.int -> Primitive.Word64.word
+
+      val zextdFromInt64ToInt8: Primitive.Int64.int -> Primitive.Int8.int
+      val zextdFromInt64ToInt16: Primitive.Int64.int -> Primitive.Int16.int
+      val zextdFromInt64ToInt32: Primitive.Int64.int -> Primitive.Int32.int
+      val zextdFromInt64ToInt64: Primitive.Int64.int -> Primitive.Int64.int
+      val zextdFromInt64ToWord8: Primitive.Int64.int -> Primitive.Word8.word
+      val zextdFromInt64ToWord16: Primitive.Int64.int -> Primitive.Word16.word
+      val zextdFromInt64ToWord32: Primitive.Int64.int -> Primitive.Word32.word
+      val zextdFromInt64ToWord64: Primitive.Int64.int -> Primitive.Word64.word
+
+      val zextdFromWord8ToInt8: Primitive.Word8.word -> Primitive.Int8.int
+      val zextdFromWord8ToInt16: Primitive.Word8.word -> Primitive.Int16.int
+      val zextdFromWord8ToInt32: Primitive.Word8.word -> Primitive.Int32.int
+      val zextdFromWord8ToInt64: Primitive.Word8.word -> Primitive.Int64.int
+      val zextdFromWord8ToWord8: Primitive.Word8.word -> Primitive.Word8.word
+      val zextdFromWord8ToWord16: Primitive.Word8.word -> Primitive.Word16.word
+      val zextdFromWord8ToWord32: Primitive.Word8.word -> Primitive.Word32.word
+      val zextdFromWord8ToWord64: Primitive.Word8.word -> Primitive.Word64.word
+
+      val zextdFromWord16ToInt8: Primitive.Word16.word -> Primitive.Int8.int
+      val zextdFromWord16ToInt16: Primitive.Word16.word -> Primitive.Int16.int
+      val zextdFromWord16ToInt32: Primitive.Word16.word -> Primitive.Int32.int
+      val zextdFromWord16ToInt64: Primitive.Word16.word -> Primitive.Int64.int
+      val zextdFromWord16ToWord8: Primitive.Word16.word -> Primitive.Word8.word
+      val zextdFromWord16ToWord16: Primitive.Word16.word -> Primitive.Word16.word
+      val zextdFromWord16ToWord32: Primitive.Word16.word -> Primitive.Word32.word
+      val zextdFromWord16ToWord64: Primitive.Word16.word -> Primitive.Word64.word
+
+      val zextdFromWord32ToInt8: Primitive.Word32.word -> Primitive.Int8.int
+      val zextdFromWord32ToInt16: Primitive.Word32.word -> Primitive.Int16.int
+      val zextdFromWord32ToInt32: Primitive.Word32.word -> Primitive.Int32.int
+      val zextdFromWord32ToInt64: Primitive.Word32.word -> Primitive.Int64.int
+      val zextdFromWord32ToWord8: Primitive.Word32.word -> Primitive.Word8.word
+      val zextdFromWord32ToWord16: Primitive.Word32.word -> Primitive.Word16.word
+      val zextdFromWord32ToWord32: Primitive.Word32.word -> Primitive.Word32.word
+      val zextdFromWord32ToWord64: Primitive.Word32.word -> Primitive.Word64.word
+
+      val zextdFromWord64ToInt8: Primitive.Word64.word -> Primitive.Int8.int
+      val zextdFromWord64ToInt16: Primitive.Word64.word -> Primitive.Int16.int
+      val zextdFromWord64ToInt32: Primitive.Word64.word -> Primitive.Int32.int
+      val zextdFromWord64ToInt64: Primitive.Word64.word -> Primitive.Int64.int
+      val zextdFromWord64ToWord8: Primitive.Word64.word -> Primitive.Word8.word
+      val zextdFromWord64ToWord16: Primitive.Word64.word -> Primitive.Word16.word
+      val zextdFromWord64ToWord32: Primitive.Word64.word -> Primitive.Word32.word
+      val zextdFromWord64ToWord64: Primitive.Word64.word -> Primitive.Word64.word
+
+      (* sign-extend or low-bits *)
+      val sextdFromInt8ToInt8: Primitive.Int8.int -> Primitive.Int8.int
+      val sextdFromInt8ToInt16: Primitive.Int8.int -> Primitive.Int16.int
+      val sextdFromInt8ToInt32: Primitive.Int8.int -> Primitive.Int32.int
+      val sextdFromInt8ToInt64: Primitive.Int8.int -> Primitive.Int64.int
+      val sextdFromInt8ToWord8: Primitive.Int8.int -> Primitive.Word8.word
+      val sextdFromInt8ToWord16: Primitive.Int8.int -> Primitive.Word16.word
+      val sextdFromInt8ToWord32: Primitive.Int8.int -> Primitive.Word32.word
+      val sextdFromInt8ToWord64: Primitive.Int8.int -> Primitive.Word64.word
+
+      val sextdFromInt16ToInt8: Primitive.Int16.int -> Primitive.Int8.int
+      val sextdFromInt16ToInt16: Primitive.Int16.int -> Primitive.Int16.int
+      val sextdFromInt16ToInt32: Primitive.Int16.int -> Primitive.Int32.int
+      val sextdFromInt16ToInt64: Primitive.Int16.int -> Primitive.Int64.int
+      val sextdFromInt16ToWord8: Primitive.Int16.int -> Primitive.Word8.word
+      val sextdFromInt16ToWord16: Primitive.Int16.int -> Primitive.Word16.word
+      val sextdFromInt16ToWord32: Primitive.Int16.int -> Primitive.Word32.word
+      val sextdFromInt16ToWord64: Primitive.Int16.int -> Primitive.Word64.word
+
+      val sextdFromInt32ToInt8: Primitive.Int32.int -> Primitive.Int8.int
+      val sextdFromInt32ToInt16: Primitive.Int32.int -> Primitive.Int16.int
+      val sextdFromInt32ToInt32: Primitive.Int32.int -> Primitive.Int32.int
+      val sextdFromInt32ToInt64: Primitive.Int32.int -> Primitive.Int64.int
+      val sextdFromInt32ToWord8: Primitive.Int32.int -> Primitive.Word8.word
+      val sextdFromInt32ToWord16: Primitive.Int32.int -> Primitive.Word16.word
+      val sextdFromInt32ToWord32: Primitive.Int32.int -> Primitive.Word32.word
+      val sextdFromInt32ToWord64: Primitive.Int32.int -> Primitive.Word64.word
+
+      val sextdFromInt64ToInt8: Primitive.Int64.int -> Primitive.Int8.int
+      val sextdFromInt64ToInt16: Primitive.Int64.int -> Primitive.Int16.int
+      val sextdFromInt64ToInt32: Primitive.Int64.int -> Primitive.Int32.int
+      val sextdFromInt64ToInt64: Primitive.Int64.int -> Primitive.Int64.int
+      val sextdFromInt64ToWord8: Primitive.Int64.int -> Primitive.Word8.word
+      val sextdFromInt64ToWord16: Primitive.Int64.int -> Primitive.Word16.word
+      val sextdFromInt64ToWord32: Primitive.Int64.int -> Primitive.Word32.word
+      val sextdFromInt64ToWord64: Primitive.Int64.int -> Primitive.Word64.word
+
+      val sextdFromWord8ToInt8: Primitive.Word8.word -> Primitive.Int8.int
+      val sextdFromWord8ToInt16: Primitive.Word8.word -> Primitive.Int16.int
+      val sextdFromWord8ToInt32: Primitive.Word8.word -> Primitive.Int32.int
+      val sextdFromWord8ToInt64: Primitive.Word8.word -> Primitive.Int64.int
+      val sextdFromWord8ToWord8: Primitive.Word8.word -> Primitive.Word8.word
+      val sextdFromWord8ToWord16: Primitive.Word8.word -> Primitive.Word16.word
+      val sextdFromWord8ToWord32: Primitive.Word8.word -> Primitive.Word32.word
+      val sextdFromWord8ToWord64: Primitive.Word8.word -> Primitive.Word64.word
+
+      val sextdFromWord16ToInt8: Primitive.Word16.word -> Primitive.Int8.int
+      val sextdFromWord16ToInt16: Primitive.Word16.word -> Primitive.Int16.int
+      val sextdFromWord16ToInt32: Primitive.Word16.word -> Primitive.Int32.int
+      val sextdFromWord16ToInt64: Primitive.Word16.word -> Primitive.Int64.int
+      val sextdFromWord16ToWord8: Primitive.Word16.word -> Primitive.Word8.word
+      val sextdFromWord16ToWord16: Primitive.Word16.word -> Primitive.Word16.word
+      val sextdFromWord16ToWord32: Primitive.Word16.word -> Primitive.Word32.word
+      val sextdFromWord16ToWord64: Primitive.Word16.word -> Primitive.Word64.word
+
+      val sextdFromWord32ToInt8: Primitive.Word32.word -> Primitive.Int8.int
+      val sextdFromWord32ToInt16: Primitive.Word32.word -> Primitive.Int16.int
+      val sextdFromWord32ToInt32: Primitive.Word32.word -> Primitive.Int32.int
+      val sextdFromWord32ToInt64: Primitive.Word32.word -> Primitive.Int64.int
+      val sextdFromWord32ToWord8: Primitive.Word32.word -> Primitive.Word8.word
+      val sextdFromWord32ToWord16: Primitive.Word32.word -> Primitive.Word16.word
+      val sextdFromWord32ToWord32: Primitive.Word32.word -> Primitive.Word32.word
+      val sextdFromWord32ToWord64: Primitive.Word32.word -> Primitive.Word64.word
+
+      val sextdFromWord64ToInt8: Primitive.Word64.word -> Primitive.Int8.int
+      val sextdFromWord64ToInt16: Primitive.Word64.word -> Primitive.Int16.int
+      val sextdFromWord64ToInt32: Primitive.Word64.word -> Primitive.Int32.int
+      val sextdFromWord64ToInt64: Primitive.Word64.word -> Primitive.Int64.int
+      val sextdFromWord64ToWord8: Primitive.Word64.word -> Primitive.Word8.word
+      val sextdFromWord64ToWord16: Primitive.Word64.word -> Primitive.Word16.word
+      val sextdFromWord64ToWord32: Primitive.Word64.word -> Primitive.Word32.word
+      val sextdFromWord64ToWord64: Primitive.Word64.word -> Primitive.Word64.word
+   end
+
+structure Primitive = struct
+
+open Primitive
+
+structure IntWordConv : PRIM_INTWORD_CONV =
+   struct
+      (* identity *)
+      val idFromInt8ToInt8 =
+         _prim "WordU8_toWord8": Int8.int -> Int8.int;
+      val idFromInt8ToWord8 =
+         _prim "WordU8_toWord8": Int8.int -> Word8.word;
+      val idFromInt16ToInt16 =
+         _prim "WordU16_toWord16": Int16.int -> Int16.int;
+      val idFromInt16ToWord16 =
+         _prim "WordU16_toWord16": Int16.int -> Word16.word;
+      val idFromInt32ToInt32 =
+         _prim "WordU32_toWord32": Int32.int -> Int32.int;
+      val idFromInt32ToWord32 =
+         _prim "WordU32_toWord32": Int32.int -> Word32.word;
+      val idFromInt64ToInt64 =
+         _prim "WordU64_toWord64": Int64.int -> Int64.int;
+      val idFromInt64ToWord64 =
+         _prim "WordU64_toWord64": Int64.int -> Word64.word;
+      val idFromWord8ToInt8 =
+         _prim "WordU8_toWord8": Word8.word -> Int8.int;
+      val idFromWord8ToWord8 =
+         _prim "WordU8_toWord8": Word8.word -> Word8.word;
+      val idFromWord16ToInt16 =
+         _prim "WordU16_toWord16": Word16.word -> Int16.int;
+      val idFromWord16ToWord16 =
+         _prim "WordU16_toWord16": Word16.word -> Word16.word;
+      val idFromWord32ToInt32 =
+         _prim "WordU32_toWord32": Word32.word -> Int32.int;
+      val idFromWord32ToWord32 =
+         _prim "WordU32_toWord32": Word32.word -> Word32.word;
+      val idFromWord64ToInt64 =
+         _prim "WordU64_toWord64": Word64.word -> Int64.int;
+      val idFromWord64ToWord64 =
+         _prim "WordU64_toWord64": Word64.word -> Word64.word;
+
+      (* zero-extend or low-bits *)
+      val zextdFromInt8ToInt8 =
+         _prim "WordU8_toWord8": Int8.int -> Int8.int;
+      val zextdFromInt8ToInt16 =
+         _prim "WordU8_toWord16": Int8.int -> Int16.int;
+      val zextdFromInt8ToInt32 =
+         _prim "WordU8_toWord32": Int8.int -> Int32.int;
+      val zextdFromInt8ToInt64 =
+         _prim "WordU8_toWord64": Int8.int -> Int64.int;
+      val zextdFromInt8ToWord8 =
+         _prim "WordU8_toWord8": Int8.int -> Word8.word;
+      val zextdFromInt8ToWord16 =
+         _prim "WordU8_toWord16": Int8.int -> Word16.word;
+      val zextdFromInt8ToWord32 =
+         _prim "WordU8_toWord32": Int8.int -> Word32.word;
+      val zextdFromInt8ToWord64 =
+         _prim "WordU8_toWord64": Int8.int -> Word64.word;
+
+      val zextdFromInt16ToInt8 =
+         _prim "WordU16_toWord8": Int16.int -> Int8.int;
+      val zextdFromInt16ToInt16 =
+         _prim "WordU16_toWord16": Int16.int -> Int16.int;
+      val zextdFromInt16ToInt32 =
+         _prim "WordU16_toWord32": Int16.int -> Int32.int;
+      val zextdFromInt16ToInt64 =
+         _prim "WordU16_toWord64": Int16.int -> Int64.int;
+      val zextdFromInt16ToWord8 =
+         _prim "WordU16_toWord8": Int16.int -> Word8.word;
+      val zextdFromInt16ToWord16 =
+         _prim "WordU16_toWord16": Int16.int -> Word16.word;
+      val zextdFromInt16ToWord32 =
+         _prim "WordU16_toWord32": Int16.int -> Word32.word;
+      val zextdFromInt16ToWord64 =
+         _prim "WordU16_toWord64": Int16.int -> Word64.word;
+
+      val zextdFromInt32ToInt8 =
+         _prim "WordU32_toWord8": Int32.int -> Int8.int;
+      val zextdFromInt32ToInt16 =
+         _prim "WordU32_toWord16": Int32.int -> Int16.int;
+      val zextdFromInt32ToInt32 =
+         _prim "WordU32_toWord32": Int32.int -> Int32.int;
+      val zextdFromInt32ToInt64 =
+         _prim "WordU32_toWord64": Int32.int -> Int64.int;
+      val zextdFromInt32ToWord8 =
+         _prim "WordU32_toWord8": Int32.int -> Word8.word;
+      val zextdFromInt32ToWord16 =
+         _prim "WordU32_toWord16": Int32.int -> Word16.word;
+      val zextdFromInt32ToWord32 =
+         _prim "WordU32_toWord32": Int32.int -> Word32.word;
+      val zextdFromInt32ToWord64 =
+         _prim "WordU32_toWord64": Int32.int -> Word64.word;
+
+      val zextdFromInt64ToInt8 =
+         _prim "WordU64_toWord8": Int64.int -> Int8.int;
+      val zextdFromInt64ToInt16 =
+         _prim "WordU64_toWord16": Int64.int -> Int16.int;
+      val zextdFromInt64ToInt32 =
+         _prim "WordU64_toWord32": Int64.int -> Int32.int;
+      val zextdFromInt64ToInt64 =
+         _prim "WordU64_toWord64": Int64.int -> Int64.int;
+      val zextdFromInt64ToWord8 =
+         _prim "WordU64_toWord8": Int64.int -> Word8.word;
+      val zextdFromInt64ToWord16 =
+         _prim "WordU64_toWord16": Int64.int -> Word16.word;
+      val zextdFromInt64ToWord32 =
+         _prim "WordU64_toWord32": Int64.int -> Word32.word;
+      val zextdFromInt64ToWord64 =
+         _prim "WordU64_toWord64": Int64.int -> Word64.word;
+
+      val zextdFromWord8ToInt8 =
+         _prim "WordU8_toWord8": Word8.word -> Int8.int;
+      val zextdFromWord8ToInt16 =
+         _prim "WordU8_toWord16": Word8.word -> Int16.int;
+      val zextdFromWord8ToInt32 =
+         _prim "WordU8_toWord32": Word8.word -> Int32.int;
+      val zextdFromWord8ToInt64 =
+         _prim "WordU8_toWord64": Word8.word -> Int64.int;
+      val zextdFromWord8ToWord8 =
+         _prim "WordU8_toWord8": Word8.word -> Word8.word;
+      val zextdFromWord8ToWord16 =
+         _prim "WordU8_toWord16": Word8.word -> Word16.word;
+      val zextdFromWord8ToWord32 =
+         _prim "WordU8_toWord32": Word8.word -> Word32.word;
+      val zextdFromWord8ToWord64 =
+         _prim "WordU8_toWord64": Word8.word -> Word64.word;
+
+      val zextdFromWord16ToInt8 =
+         _prim "WordU16_toWord8": Word16.word -> Int8.int;
+      val zextdFromWord16ToInt16 =
+         _prim "WordU16_toWord16": Word16.word -> Int16.int;
+      val zextdFromWord16ToInt32 =
+         _prim "WordU16_toWord32": Word16.word -> Int32.int;
+      val zextdFromWord16ToInt64 =
+         _prim "WordU16_toWord64": Word16.word -> Int64.int;
+      val zextdFromWord16ToWord8 =
+         _prim "WordU16_toWord8": Word16.word -> Word8.word;
+      val zextdFromWord16ToWord16 =
+         _prim "WordU16_toWord16": Word16.word -> Word16.word;
+      val zextdFromWord16ToWord32 =
+         _prim "WordU16_toWord32": Word16.word -> Word32.word;
+      val zextdFromWord16ToWord64 =
+         _prim "WordU16_toWord64": Word16.word -> Word64.word;
+
+      val zextdFromWord32ToInt8 =
+         _prim "WordU32_toWord8": Word32.word -> Int8.int;
+      val zextdFromWord32ToInt16 =
+         _prim "WordU32_toWord16": Word32.word -> Int16.int;
+      val zextdFromWord32ToInt32 =
+         _prim "WordU32_toWord32": Word32.word -> Int32.int;
+      val zextdFromWord32ToInt64 =
+         _prim "WordU32_toWord64": Word32.word -> Int64.int;
+      val zextdFromWord32ToWord8 =
+         _prim "WordU32_toWord8": Word32.word -> Word8.word;
+      val zextdFromWord32ToWord16 =
+         _prim "WordU32_toWord16": Word32.word -> Word16.word;
+      val zextdFromWord32ToWord32 =
+         _prim "WordU32_toWord32": Word32.word -> Word32.word;
+      val zextdFromWord32ToWord64 =
+         _prim "WordU32_toWord64": Word32.word -> Word64.word;
+
+      val zextdFromWord64ToInt8 =
+         _prim "WordU64_toWord8": Word64.word -> Int8.int;
+      val zextdFromWord64ToInt16 =
+         _prim "WordU64_toWord16": Word64.word -> Int16.int;
+      val zextdFromWord64ToInt32 =
+         _prim "WordU64_toWord32": Word64.word -> Int32.int;
+      val zextdFromWord64ToInt64 =
+         _prim "WordU64_toWord64": Word64.word -> Int64.int;
+      val zextdFromWord64ToWord8 =
+         _prim "WordU64_toWord8": Word64.word -> Word8.word;
+      val zextdFromWord64ToWord16 =
+         _prim "WordU64_toWord16": Word64.word -> Word16.word;
+      val zextdFromWord64ToWord32 =
+         _prim "WordU64_toWord32": Word64.word -> Word32.word;
+      val zextdFromWord64ToWord64 =
+         _prim "WordU64_toWord64": Word64.word -> Word64.word;
+
+      (* sign-extend or low-bits *)
+      val sextdFromInt8ToInt8 =
+         _prim "WordS8_toWord8": Int8.int -> Int8.int;
+      val sextdFromInt8ToInt16 =
+         _prim "WordS8_toWord16": Int8.int -> Int16.int;
+      val sextdFromInt8ToInt32 =
+         _prim "WordS8_toWord32": Int8.int -> Int32.int;
+      val sextdFromInt8ToInt64 =
+         _prim "WordS8_toWord64": Int8.int -> Int64.int;
+      val sextdFromInt8ToWord8 =
+         _prim "WordS8_toWord8": Int8.int -> Word8.word;
+      val sextdFromInt8ToWord16 =
+         _prim "WordS8_toWord16": Int8.int -> Word16.word;
+      val sextdFromInt8ToWord32 =
+         _prim "WordS8_toWord32": Int8.int -> Word32.word;
+      val sextdFromInt8ToWord64 =
+         _prim "WordS8_toWord64": Int8.int -> Word64.word;
+
+      val sextdFromInt16ToInt8 =
+         _prim "WordS16_toWord8": Int16.int -> Int8.int;
+      val sextdFromInt16ToInt16 =
+         _prim "WordS16_toWord16": Int16.int -> Int16.int;
+      val sextdFromInt16ToInt32 =
+         _prim "WordS16_toWord32": Int16.int -> Int32.int;
+      val sextdFromInt16ToInt64 =
+         _prim "WordS16_toWord64": Int16.int -> Int64.int;
+      val sextdFromInt16ToWord8 =
+         _prim "WordS16_toWord8": Int16.int -> Word8.word;
+      val sextdFromInt16ToWord16 =
+         _prim "WordS16_toWord16": Int16.int -> Word16.word;
+      val sextdFromInt16ToWord32 =
+         _prim "WordS16_toWord32": Int16.int -> Word32.word;
+      val sextdFromInt16ToWord64 =
+         _prim "WordS16_toWord64": Int16.int -> Word64.word;
+
+      val sextdFromInt32ToInt8 =
+         _prim "WordS32_toWord8": Int32.int -> Int8.int;
+      val sextdFromInt32ToInt16 =
+         _prim "WordS32_toWord16": Int32.int -> Int16.int;
+      val sextdFromInt32ToInt32 =
+         _prim "WordS32_toWord32": Int32.int -> Int32.int;
+      val sextdFromInt32ToInt64 =
+         _prim "WordS32_toWord64": Int32.int -> Int64.int;
+      val sextdFromInt32ToWord8 =
+         _prim "WordS32_toWord8": Int32.int -> Word8.word;
+      val sextdFromInt32ToWord16 =
+         _prim "WordS32_toWord16": Int32.int -> Word16.word;
+      val sextdFromInt32ToWord32 =
+         _prim "WordS32_toWord32": Int32.int -> Word32.word;
+      val sextdFromInt32ToWord64 =
+         _prim "WordS32_toWord64": Int32.int -> Word64.word;
+
+      val sextdFromInt64ToInt8 =
+         _prim "WordS64_toWord8": Int64.int -> Int8.int;
+      val sextdFromInt64ToInt16 =
+         _prim "WordS64_toWord16": Int64.int -> Int16.int;
+      val sextdFromInt64ToInt32 =
+         _prim "WordS64_toWord32": Int64.int -> Int32.int;
+      val sextdFromInt64ToInt64 =
+         _prim "WordS64_toWord64": Int64.int -> Int64.int;
+      val sextdFromInt64ToWord8 =
+         _prim "WordS64_toWord8": Int64.int -> Word8.word;
+      val sextdFromInt64ToWord16 =
+         _prim "WordS64_toWord16": Int64.int -> Word16.word;
+      val sextdFromInt64ToWord32 =
+         _prim "WordS64_toWord32": Int64.int -> Word32.word;
+      val sextdFromInt64ToWord64 =
+         _prim "WordS64_toWord64": Int64.int -> Word64.word;
+
+      val sextdFromWord8ToInt8 =
+         _prim "WordS8_toWord8": Word8.word -> Int8.int;
+      val sextdFromWord8ToInt16 =
+         _prim "WordS8_toWord16": Word8.word -> Int16.int;
+      val sextdFromWord8ToInt32 =
+         _prim "WordS8_toWord32": Word8.word -> Int32.int;
+      val sextdFromWord8ToInt64 =
+         _prim "WordS8_toWord64": Word8.word -> Int64.int;
+      val sextdFromWord8ToWord8 =
+         _prim "WordS8_toWord8": Word8.word -> Word8.word;
+      val sextdFromWord8ToWord16 =
+         _prim "WordS8_toWord16": Word8.word -> Word16.word;
+      val sextdFromWord8ToWord32 =
+         _prim "WordS8_toWord32": Word8.word -> Word32.word;
+      val sextdFromWord8ToWord64 =
+         _prim "WordS8_toWord64": Word8.word -> Word64.word;
+
+      val sextdFromWord16ToInt8 =
+         _prim "WordS16_toWord8": Word16.word -> Int8.int;
+      val sextdFromWord16ToInt16 =
+         _prim "WordS16_toWord16": Word16.word -> Int16.int;
+      val sextdFromWord16ToInt32 =
+         _prim "WordS16_toWord32": Word16.word -> Int32.int;
+      val sextdFromWord16ToInt64 =
+         _prim "WordS16_toWord64": Word16.word -> Int64.int;
+      val sextdFromWord16ToWord8 =
+         _prim "WordS16_toWord8": Word16.word -> Word8.word;
+      val sextdFromWord16ToWord16 =
+         _prim "WordS16_toWord16": Word16.word -> Word16.word;
+      val sextdFromWord16ToWord32 =
+         _prim "WordS16_toWord32": Word16.word -> Word32.word;
+      val sextdFromWord16ToWord64 =
+         _prim "WordS16_toWord64": Word16.word -> Word64.word;
+
+      val sextdFromWord32ToInt8 =
+         _prim "WordS32_toWord8": Word32.word -> Int8.int;
+      val sextdFromWord32ToInt16 =
+         _prim "WordS32_toWord16": Word32.word -> Int16.int;
+      val sextdFromWord32ToInt32 =
+         _prim "WordS32_toWord32": Word32.word -> Int32.int;
+      val sextdFromWord32ToInt64 =
+         _prim "WordS32_toWord64": Word32.word -> Int64.int;
+      val sextdFromWord32ToWord8 =
+         _prim "WordS32_toWord8": Word32.word -> Word8.word;
+      val sextdFromWord32ToWord16 =
+         _prim "WordS32_toWord16": Word32.word -> Word16.word;
+      val sextdFromWord32ToWord32 =
+         _prim "WordS32_toWord32": Word32.word -> Word32.word;
+      val sextdFromWord32ToWord64 =
+         _prim "WordS32_toWord64": Word32.word -> Word64.word;
+
+      val sextdFromWord64ToInt8 =
+         _prim "WordS64_toWord8": Word64.word -> Int8.int;
+      val sextdFromWord64ToInt16 =
+         _prim "WordS64_toWord16": Word64.word -> Int16.int;
+      val sextdFromWord64ToInt32 =
+         _prim "WordS64_toWord32": Word64.word -> Int32.int;
+      val sextdFromWord64ToInt64 =
+         _prim "WordS64_toWord64": Word64.word -> Int64.int;
+      val sextdFromWord64ToWord8 =
+         _prim "WordS64_toWord8": Word64.word -> Word8.word;
+      val sextdFromWord64ToWord16 =
+         _prim "WordS64_toWord16": Word64.word -> Word16.word;
+      val sextdFromWord64ToWord32 =
+         _prim "WordS64_toWord32": Word64.word -> Word32.word;
+      val sextdFromWord64ToWord64 =
+         _prim "WordS64_toWord64": Word64.word -> Word64.word;
+   end
+
+end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-seq.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-seq.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-seq.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -19,7 +19,7 @@
       val array0Const = _prim "Array_array0Const": unit -> 'a array;
       val length = _prim "Array_length": 'a array -> SeqIndex.int;
       (* There is no maximum length on arrays, so maxLen' = SeqIndex.maxInt'. *)
-      val maxLen': SeqIndex.int = SeqIndex.maxInt'
+      (* val maxLen': SeqIndex.int = SeqIndex.maxInt' *)
       val subUnsafe = _prim "Array_sub": 'a array * SeqIndex.int -> 'a;
       val updateUnsafe = _prim "Array_update": 'a array * SeqIndex.int * 'a -> unit;
    end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-string.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-string.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-string.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -16,9 +16,9 @@
    struct
       open String8
 
-      val fromWord8Vector = 
+      val idFromWord8Vector = 
          _prim "Word8Vector_toString": Word8.word vector -> string;
-      val toWord8Vector = 
+      val idToWord8Vector = 
          _prim "String_toWord8Vector": string -> Word8.word vector;
    end
                       

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-word.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-word.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/prim-word.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -13,7 +13,8 @@
       eqtype word
       type t = word
 
-      val wordSize: Primitive.Int32.int
+      val sizeInBits: Primitive.Int32.int
+      val sizeInBitsWord: Primitive.Word32.word
 
       val + : word * word -> word
       val andb : word * word -> word
@@ -38,54 +39,6 @@
       val compare: word * word -> Primitive.Order.order
       val min: word * word -> word
       val max: word * word -> word
-
-      (* Lowbits or sign extend. *)
-      val fromInt8Unsafe: Primitive.Int8.int -> word
-      val fromInt16Unsafe: Primitive.Int16.int -> word
-      val fromInt32Unsafe: Primitive.Int32.int -> word
-      val fromInt64Unsafe: Primitive.Int64.int -> word
-
-      (* Lowbits or zero extend. *)
-      val fromInt8ZUnsafe: Primitive.Int8.int -> word
-      val fromInt16ZUnsafe: Primitive.Int16.int -> word
-      val fromInt32ZUnsafe: Primitive.Int32.int -> word
-      val fromInt64ZUnsafe: Primitive.Int64.int -> word
-
-      (* Lowbits or zero extend. *)
-      val fromWord8Unsafe: Primitive.Word8.word -> word
-      val fromWord16Unsafe: Primitive.Word16.word -> word
-      val fromWord32Unsafe: Primitive.Word32.word -> word
-      val fromWord64Unsafe: Primitive.Word64.word -> word
-
-      (* Lowbits or sign extend. *)
-      val fromWord8XUnsafe: Primitive.Word8.word -> word
-      val fromWord16XUnsafe: Primitive.Word16.word -> word
-      val fromWord32XUnsafe: Primitive.Word32.word -> word
-      val fromWord64XUnsafe: Primitive.Word64.word -> word
-
-      (* Lowbits or zero extend. *)
-      val toInt8Unsafe: word -> Primitive.Int8.int
-      val toInt16Unsafe: word -> Primitive.Int16.int
-      val toInt32Unsafe: word -> Primitive.Int32.int
-      val toInt64Unsafe: word -> Primitive.Int64.int
-
-      (* Lowbits or sign extend. *)
-      val toInt8XUnsafe: word -> Primitive.Int8.int
-      val toInt16XUnsafe: word -> Primitive.Int16.int
-      val toInt32XUnsafe: word -> Primitive.Int32.int
-      val toInt64XUnsafe: word -> Primitive.Int64.int
-
-      (* Lowbits or zero extend. *)
-      val toWord8Unsafe: word -> Primitive.Word8.word
-      val toWord16Unsafe: word -> Primitive.Word16.word
-      val toWord32Unsafe: word -> Primitive.Word32.word
-      val toWord64Unsafe: word -> Primitive.Word64.word
-
-      (* Lowbits or sign extend. *)
-      val toWord8XUnsafe: word -> Primitive.Word8.word
-      val toWord16XUnsafe: word -> Primitive.Word16.word
-      val toWord32XUnsafe: word -> Primitive.Word32.word
-      val toWord64XUnsafe: word -> Primitive.Word64.word
    end
 
 structure Primitive = struct
@@ -98,7 +51,7 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord1": big -> word;
       val toBig = _prim "WordU1_toWord8": word -> big;
-      val wordSize: Int32.int = 1
+      val sizeInBits: Int32.int = 1
    end
 structure Word2 =
    struct
@@ -106,7 +59,7 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord2": big -> word;
       val toBig = _prim "WordU2_toWord8": word -> big;
-      val wordSize: Int32.int = 2
+      val sizeInBits: Int32.int = 2
    end
 structure Word3 =
    struct
@@ -114,7 +67,7 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord3": big -> word;
       val toBig = _prim "WordU3_toWord8": word -> big;
-      val wordSize: Int32.int = 3
+      val sizeInBits: Int32.int = 3
    end
 structure Word4 =
    struct
@@ -122,7 +75,7 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord4": big -> word;
       val toBig = _prim "WordU4_toWord8": word -> big;
-      val wordSize: Int32.int = 4
+      val sizeInBits: Int32.int = 4
    end
 structure Word5 =
    struct
@@ -130,7 +83,7 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord5": big -> word;
       val toBig = _prim "WordU5_toWord8": word -> big;
-      val wordSize: Int32.int = 5
+      val sizeInBits: Int32.int = 5
    end
 structure Word6 =
    struct
@@ -138,7 +91,7 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord6": big -> word;
       val toBig = _prim "WordU6_toWord8": word -> big;
-      val wordSize: Int32.int = 6
+      val sizeInBits: Int32.int = 6
    end
 structure Word7 =
    struct
@@ -146,13 +99,15 @@
       type big = Word8.word
       val fromBigUnsafe = _prim "WordU8_toWord7": big -> word;
       val toBig = _prim "WordU7_toWord8": word -> big;
-      val wordSize: Int32.int = 7
+      val sizeInBits: Int32.int = 7
    end
 structure Word8 =
    struct
       open Word8
          
-      val wordSize: Int32.int = 8
+      val sizeInBits: Int32.int = 8
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
 
       val + = _prim "Word8_add": word * word -> word;
       val andb = _prim "Word8_andb": word * word -> word;
@@ -171,46 +126,6 @@
       val xorb = _prim "Word8_xorb": word * word -> word;
 
       val < = _prim "WordU8_lt": word * word -> bool;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord8": Int8.int -> word;
-      val fromInt16Unsafe = _prim "WordS16_toWord8": Int16.int -> word;
-      val fromInt32Unsafe = _prim "WordS32_toWord8": Int32.int -> word;
-      val fromInt64Unsafe = _prim "WordS64_toWord8": Int64.int -> word;
-
-      val fromInt8ZUnsafe = _prim "WordU8_toWord8": Int8.int -> word;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord8": Int16.int -> word;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord8": Int32.int -> word;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord8": Int64.int -> word;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord8": Word8.word -> word;
-      val fromWord16Unsafe = _prim "WordU16_toWord8": Word16.word -> word;
-      val fromWord32Unsafe = _prim "WordU32_toWord8": Word32.word -> word;
-      val fromWord64Unsafe = _prim "WordU64_toWord8": Word64.word -> word;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord8": Word8.word -> word;
-      val fromWord16XUnsafe = _prim "WordS16_toWord8": Word16.word -> word;
-      val fromWord32XUnsafe = _prim "WordS32_toWord8": Word32.word -> word;
-      val fromWord64XUnsafe = _prim "WordS64_toWord8": Word64.word -> word;
-
-      val toInt8Unsafe = _prim "WordU8_toWord8": word -> Int8.int;
-      val toInt16Unsafe = _prim "WordU8_toWord16": word -> Int16.int;
-      val toInt32Unsafe = _prim "WordU8_toWord32": word -> Int32.int;
-      val toInt64Unsafe = _prim "WordU8_toWord64": word -> Int64.int;
-
-      val toInt8XUnsafe = _prim "WordS8_toWord8": word -> Int8.int;
-      val toInt16XUnsafe = _prim "WordS8_toWord16": word -> Int16.int;
-      val toInt32XUnsafe = _prim "WordS8_toWord32": word -> Int32.int;
-      val toInt64XUnsafe = _prim "WordS8_toWord64": word -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU8_toWord8": word -> Word8.word;
-      val toWord16Unsafe = _prim "WordU8_toWord16": word -> Word16.word;
-      val toWord32Unsafe = _prim "WordU8_toWord32": word -> Word32.word;
-      val toWord64Unsafe = _prim "WordU8_toWord64": word -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS8_toWord8": word -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS8_toWord16": word -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS8_toWord32": word -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS8_toWord64": word -> Word64.word;
    end
 structure Word8 : PRIM_WORD =
    struct
@@ -227,7 +142,7 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord9": big -> word;
       val toBig = _prim "WordU9_toWord16": word -> big;
-      val wordSize: Int32.int = 9
+      val sizeInBits: Int32.int = 9
    end
 structure Word10 =
    struct
@@ -235,7 +150,7 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord10": big -> word;
       val toBig = _prim "WordU10_toWord16": word -> big;
-      val wordSize: Int32.int = 10
+      val sizeInBits: Int32.int = 10
    end
 structure Word11 =
    struct
@@ -243,7 +158,7 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord11": big -> word;
       val toBig = _prim "WordU11_toWord16": word -> big;
-      val wordSize: Int32.int = 11
+      val sizeInBits: Int32.int = 11
    end
 structure Word12 =
    struct
@@ -251,7 +166,7 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord12": big -> word;
       val toBig = _prim "WordU12_toWord16": word -> big;
-      val wordSize: Int32.int = 12
+      val sizeInBits: Int32.int = 12
    end
 structure Word13 =
    struct
@@ -259,7 +174,7 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord13": big -> word;
       val toBig = _prim "WordU13_toWord16": word -> big;
-      val wordSize: Int32.int = 13
+      val sizeInBits: Int32.int = 13
    end
 structure Word14 =
    struct
@@ -267,7 +182,7 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord14": big -> word;
       val toBig = _prim "WordU14_toWord16": word -> big;
-      val wordSize: Int32.int = 14
+      val sizeInBits: Int32.int = 14
    end
 structure Word15 =
    struct
@@ -275,13 +190,15 @@
       type big = Word16.word
       val fromBigUnsafe = _prim "WordU16_toWord15": big -> word;
       val toBig = _prim "WordU15_toWord16": word -> big;
-      val wordSize: Int32.int = 15
+      val sizeInBits: Int32.int = 15
    end
 structure Word16 =
    struct
       open Word16
          
-      val wordSize: Int32.int = 16
+      val sizeInBits: Int32.int = 16
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
 
       val + = _prim "Word16_add": word * word -> word;
       val andb = _prim "Word16_andb": word * word -> word;
@@ -300,46 +217,6 @@
       val xorb = _prim "Word16_xorb": word * word -> word;
 
       val < = _prim "WordU16_lt": word * word -> bool;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord16": Int8.int -> word;
-      val fromInt16Unsafe = _prim "WordS16_toWord16": Int16.int -> word;
-      val fromInt32Unsafe = _prim "WordS32_toWord16": Int32.int -> word;
-      val fromInt64Unsafe = _prim "WordS64_toWord16": Int64.int -> word;
-
-      val fromInt8ZUnsafe = _prim "WordU8_toWord16": Int8.int -> word;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord16": Int16.int -> word;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord16": Int32.int -> word;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord16": Int64.int -> word;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord16": Word8.word -> word;
-      val fromWord16Unsafe = _prim "WordU16_toWord16": Word16.word -> word;
-      val fromWord32Unsafe = _prim "WordU32_toWord16": Word32.word -> word;
-      val fromWord64Unsafe = _prim "WordU64_toWord16": Word64.word -> word;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord16": Word8.word -> word;
-      val fromWord16XUnsafe = _prim "WordS16_toWord16": Word16.word -> word;
-      val fromWord32XUnsafe = _prim "WordS32_toWord16": Word32.word -> word;
-      val fromWord64XUnsafe = _prim "WordS64_toWord16": Word64.word -> word;
-
-      val toInt8Unsafe = _prim "WordU16_toWord8": word -> Int8.int;
-      val toInt16Unsafe = _prim "WordU16_toWord16": word -> Int16.int;
-      val toInt32Unsafe = _prim "WordU16_toWord32": word -> Int32.int;
-      val toInt64Unsafe = _prim "WordU16_toWord64": word -> Int64.int;
-
-      val toInt8XUnsafe = _prim "WordS16_toWord8": word -> Int8.int;
-      val toInt16XUnsafe = _prim "WordS16_toWord16": word -> Int16.int;
-      val toInt32XUnsafe = _prim "WordS16_toWord32": word -> Int32.int;
-      val toInt64XUnsafe = _prim "WordS16_toWord64": word -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU16_toWord8": word -> Word8.word;
-      val toWord16Unsafe = _prim "WordU16_toWord16": word -> Word16.word;
-      val toWord32Unsafe = _prim "WordU16_toWord32": word -> Word32.word;
-      val toWord64Unsafe = _prim "WordU16_toWord64": word -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS16_toWord8": word -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS16_toWord16": word -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS16_toWord32": word -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS16_toWord64": word -> Word64.word;
    end
 structure Word16 : PRIM_WORD =
    struct
@@ -356,7 +233,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord17": big -> word;
       val toBig = _prim "WordU17_toWord32": word -> big;
-      val wordSize: Int32.int = 17
+      val sizeInBits: Int32.int = 17
    end
 structure Word18 =
    struct
@@ -364,7 +241,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord18": big -> word;
       val toBig = _prim "WordU18_toWord32": word -> big;
-      val wordSize: Int32.int = 18
+      val sizeInBits: Int32.int = 18
    end
 structure Word19 =
    struct
@@ -372,7 +249,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord19": big -> word;
       val toBig = _prim "WordU19_toWord32": word -> big;
-      val wordSize: Int32.int = 19
+      val sizeInBits: Int32.int = 19
    end
 structure Word20 =
    struct
@@ -380,7 +257,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord20": big -> word;
       val toBig = _prim "WordU20_toWord32": word -> big;
-      val wordSize: Int32.int = 20
+      val sizeInBits: Int32.int = 20
    end
 structure Word21 =
    struct
@@ -388,7 +265,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord21": big -> word;
       val toBig = _prim "WordU21_toWord32": word -> big;
-      val wordSize: Int32.int = 21
+      val sizeInBits: Int32.int = 21
    end
 structure Word22 =
    struct
@@ -396,7 +273,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord22": big -> word;
       val toBig = _prim "WordU22_toWord32": word -> big;
-      val wordSize: Int32.int = 22
+      val sizeInBits: Int32.int = 22
    end
 structure Word23 =
    struct
@@ -404,7 +281,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord23": big -> word;
       val toBig = _prim "WordU23_toWord32": word -> big;
-      val wordSize: Int32.int = 23
+      val sizeInBits: Int32.int = 23
    end
 structure Word24 =
    struct
@@ -412,7 +289,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord24": big -> word;
       val toBig = _prim "WordU24_toWord32": word -> big;
-      val wordSize: Int32.int = 24
+      val sizeInBits: Int32.int = 24
    end
 structure Word25 =
    struct
@@ -420,7 +297,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord25": big -> word;
       val toBig = _prim "WordU25_toWord32": word -> big;
-      val wordSize: Int32.int = 25
+      val sizeInBits: Int32.int = 25
    end
 structure Word26 =
    struct
@@ -428,7 +305,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord26": big -> word;
       val toBig = _prim "WordU26_toWord32": word -> big;
-      val wordSize: Int32.int = 26
+      val sizeInBits: Int32.int = 26
    end
 structure Word27 =
    struct
@@ -436,7 +313,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord27": big -> word;
       val toBig = _prim "WordU27_toWord32": word -> big;
-      val wordSize: Int32.int = 27
+      val sizeInBits: Int32.int = 27
    end
 structure Word28 =
    struct
@@ -444,7 +321,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord28": big -> word;
       val toBig = _prim "WordU28_toWord32": word -> big;
-      val wordSize: Int32.int = 28
+      val sizeInBits: Int32.int = 28
    end
 structure Word29 =
    struct
@@ -452,7 +329,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord29": big -> word;
       val toBig = _prim "WordU29_toWord32": word -> big;
-      val wordSize: Int32.int = 29
+      val sizeInBits: Int32.int = 29
    end
 structure Word30 =
    struct
@@ -460,7 +337,7 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord30": big -> word;
       val toBig = _prim "WordU30_toWord32": word -> big;
-      val wordSize: Int32.int = 30
+      val sizeInBits: Int32.int = 30
    end
 structure Word31 =
    struct
@@ -468,13 +345,15 @@
       type big = Word32.word
       val fromBigUnsafe = _prim "WordU32_toWord31": big -> word;
       val toBig = _prim "WordU31_toWord32": word -> big;
-      val wordSize: Int32.int = 31
+      val sizeInBits: Int32.int = 31
    end
 structure Word32 =
    struct
       open Word32
          
-      val wordSize: Int32.int = 32
+      val sizeInBits: Int32.int = 32
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
 
       val + = _prim "Word32_add": word * word -> word;
       val andb = _prim "Word32_andb": word * word -> word;
@@ -493,46 +372,6 @@
       val xorb = _prim "Word32_xorb": word * word -> word;
 
       val < = _prim "WordU32_lt": word * word -> bool;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord32": Int8.int -> word;
-      val fromInt16Unsafe = _prim "WordS16_toWord32": Int16.int -> word;
-      val fromInt32Unsafe = _prim "WordS32_toWord32": Int32.int -> word;
-      val fromInt64Unsafe = _prim "WordS64_toWord32": Int64.int -> word;
-
-      val fromInt8ZUnsafe = _prim "WordU8_toWord32": Int8.int -> word;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord32": Int16.int -> word;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord32": Int32.int -> word;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord32": Int64.int -> word;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord32": Word8.word -> word;
-      val fromWord16Unsafe = _prim "WordU16_toWord32": Word16.word -> word;
-      val fromWord32Unsafe = _prim "WordU32_toWord32": Word32.word -> word;
-      val fromWord64Unsafe = _prim "WordU64_toWord32": Word64.word -> word;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord32": Word8.word -> word;
-      val fromWord16XUnsafe = _prim "WordS16_toWord32": Word16.word -> word;
-      val fromWord32XUnsafe = _prim "WordS32_toWord32": Word32.word -> word;
-      val fromWord64XUnsafe = _prim "WordS64_toWord32": Word64.word -> word;
-
-      val toInt8Unsafe = _prim "WordU32_toWord8": word -> Int8.int;
-      val toInt16Unsafe = _prim "WordU32_toWord16": word -> Int16.int;
-      val toInt32Unsafe = _prim "WordU32_toWord32": word -> Int32.int;
-      val toInt64Unsafe = _prim "WordU32_toWord64": word -> Int64.int;
-
-      val toInt8XUnsafe = _prim "WordS32_toWord8": word -> Int8.int;
-      val toInt16XUnsafe = _prim "WordS32_toWord16": word -> Int16.int;
-      val toInt32XUnsafe = _prim "WordS32_toWord32": word -> Int32.int;
-      val toInt64XUnsafe = _prim "WordS32_toWord64": word -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU32_toWord8": word -> Word8.word;
-      val toWord16Unsafe = _prim "WordU32_toWord16": word -> Word16.word;
-      val toWord32Unsafe = _prim "WordU32_toWord32": word -> Word32.word;
-      val toWord64Unsafe = _prim "WordU32_toWord64": word -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS32_toWord8": word -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS32_toWord16": word -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS32_toWord32": word -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS32_toWord64": word -> Word64.word;
    end
 structure Word32 : PRIM_WORD =
    struct
@@ -547,7 +386,9 @@
    struct
       open Word64
          
-      val wordSize: Int32.int = 64
+      val sizeInBits: Int32.int = 64
+      val sizeInBitsWord: Word32.word = 
+         IntWordConv.zextdFromInt32ToWord32 sizeInBits
 
       val + = _prim "Word64_add": word * word -> word;
       val andb = _prim "Word64_andb": word * word -> word;
@@ -566,46 +407,6 @@
       val xorb = _prim "Word64_xorb": word * word -> word;
 
       val < = _prim "WordU64_lt": word * word -> bool;
-
-      val fromInt8Unsafe = _prim "WordS8_toWord64": Int8.int -> word;
-      val fromInt16Unsafe = _prim "WordS16_toWord64": Int16.int -> word;
-      val fromInt32Unsafe = _prim "WordS32_toWord64": Int32.int -> word;
-      val fromInt64Unsafe = _prim "WordS64_toWord64": Int64.int -> word;
-
-      val fromInt8ZUnsafe = _prim "WordU8_toWord64": Int8.int -> word;
-      val fromInt16ZUnsafe = _prim "WordU16_toWord64": Int16.int -> word;
-      val fromInt32ZUnsafe = _prim "WordU32_toWord64": Int32.int -> word;
-      val fromInt64ZUnsafe = _prim "WordU64_toWord64": Int64.int -> word;
-
-      val fromWord8Unsafe = _prim "WordU8_toWord64": Word8.word -> word;
-      val fromWord16Unsafe = _prim "WordU16_toWord64": Word16.word -> word;
-      val fromWord32Unsafe = _prim "WordU32_toWord64": Word32.word -> word;
-      val fromWord64Unsafe = _prim "WordU64_toWord64": Word64.word -> word;
-
-      val fromWord8XUnsafe = _prim "WordS8_toWord64": Word8.word -> word;
-      val fromWord16XUnsafe = _prim "WordS16_toWord64": Word16.word -> word;
-      val fromWord32XUnsafe = _prim "WordS32_toWord64": Word32.word -> word;
-      val fromWord64XUnsafe = _prim "WordS64_toWord64": Word64.word -> word;
-
-      val toInt8Unsafe = _prim "WordU64_toWord8": word -> Int8.int;
-      val toInt16Unsafe = _prim "WordU64_toWord16": word -> Int16.int;
-      val toInt32Unsafe = _prim "WordU64_toWord32": word -> Int32.int;
-      val toInt64Unsafe = _prim "WordU64_toWord64": word -> Int64.int;
-
-      val toInt8XUnsafe = _prim "WordS64_toWord8": word -> Int8.int;
-      val toInt16XUnsafe = _prim "WordS64_toWord16": word -> Int16.int;
-      val toInt32XUnsafe = _prim "WordS64_toWord32": word -> Int32.int;
-      val toInt64XUnsafe = _prim "WordS64_toWord64": word -> Int64.int;
-
-      val toWord8Unsafe = _prim "WordU64_toWord8": word -> Word8.word;
-      val toWord16Unsafe = _prim "WordU64_toWord16": word -> Word16.word;
-      val toWord32Unsafe = _prim "WordU64_toWord32": word -> Word32.word;
-      val toWord64Unsafe = _prim "WordU64_toWord64": word -> Word64.word;
-
-      val toWord8XUnsafe = _prim "WordS64_toWord8": word -> Word8.word;
-      val toWord16XUnsafe = _prim "WordS64_toWord16": word -> Word16.word;
-      val toWord32XUnsafe = _prim "WordS64_toWord32": word -> Word32.word;
-      val toWord64XUnsafe = _prim "WordS64_toWord64": word -> Word64.word;
    end
 structure Word64 : PRIM_WORD =
    struct

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/primitive/primitive.mlb	2006-05-16 03:02:10 UTC (rev 4548)
@@ -33,6 +33,7 @@
       ../config/choose.sml
    end end
 
+   prim-iwconv.sml
    prim-word.sml
    prim-int.sml
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/real/real.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -46,9 +46,9 @@
          val minNormalPos = minNormalPos
          val minPos = minPos
 
-         val realSize = Primitive.Int32.toInt realSize
-         val precision = Primitive.Int32.toInt precision
-         val radix = Primitive.Int32.toInt radix
+         val realSize = Int32.toInt realSize
+         val precision = Int32.toInt precision
+         val radix = Int32.toInt radix
 
          val signBit = fn r => signBit r <> 0
       end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/system/io.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -28,7 +28,7 @@
     val iodToFd = fn x => x
     val fdToIod = fn x => x
 
-    val iodescToWord = C_Fd.toSysWord
+    val iodescToWord = C_Fd.castToSysWord
        
   (* return a hash value for the I/O descriptor. *)
     val hash = SysWord.toWord o iodescToWord

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/system/process.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -32,7 +32,7 @@
                in
                   case es of
                      W_EXITED => success
-                   | W_EXITSTATUS w => C_Status.fromSysWord (Word8.toSysWord w)
+                   | W_EXITSTATUS w => C_Status.castFromSysWord (Word8.castToSysWord w)
                    | W_SIGNALED _ => failure
                    | W_STOPPED _ => failure
                end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/system/time.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/system/time.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/system/time.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -72,8 +72,8 @@
       (if ~1 = Prim.getTimeOfDay ()
           then raise Fail "Time.now"
        else ()
-       ; timeAdd(fromSeconds (C_Time.toLarge (Prim.sec ())),
-                 fromMicroseconds (C_SUSeconds.toLarge (Prim.usec ()))))
+       ; timeAdd(fromSeconds (C_Time.toLargeInt (Prim.sec ())),
+                 fromMicroseconds (C_SUSeconds.toLargeInt (Prim.usec ()))))
    val prev = ref (getNow ())
 in
    fun now (): time =

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/text/byte.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/text/byte.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/text/byte.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -8,18 +8,18 @@
 
 structure Byte: BYTE =
    struct
-      val byteToChar = Primitive.Char8.fromWord8Unsafe
+      val byteToChar = Primitive.Char8.idFromWord8
 
-      val bytesToString = Primitive.String8.fromWord8Vector o Word8Vector.toPoly
+      val bytesToString = Primitive.String8.idFromWord8Vector o Word8Vector.toPoly
 
-      val charToByte = Primitive.Char8.toWord8Unsafe
+      val charToByte = Primitive.Char8.idToWord8
 
       fun packString (a: Word8Array.array, i: int, s: substring): unit =
          Natural.foreach
          (Substring.size s, fn j =>
           Word8Array.update (a, i + j, charToByte (Substring.sub (s, j))))
 
-      val stringToBytes = Word8Vector.fromPoly o Primitive.String8.toWord8Vector
+      val stringToBytes = Word8Vector.fromPoly o Primitive.String8.idToWord8Vector
 
       local
          fun make (length, sub) s =

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/text/char0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/text/char0.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/text/char0.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -14,19 +14,8 @@
       type char = Primitive.Char8.char
       type string = Primitive.String8.string
 
-      local
-         structure S =
-            Int_ChooseInt
-            (type 'a t = 'a -> char
-             val fInt8 = Prim.fromInt8Unsafe
-             val fInt16 = Prim.fromInt16Unsafe
-             val fInt32 = Prim.fromInt32Unsafe
-             val fInt64 = Prim.fromInt64Unsafe
-             val fIntInf = Prim.fromIntInfUnsafe)
-      in
-         val chrUnsafe = S.f
-      end
-      val ord = Primitive.Word8.toInt o Prim.toWord8Unsafe
+      val chrUnsafe = Prim.idFromWord8 o Int.sextdToWord8
+      val ord = Int.zextdFromWord8 o Prim.idToWord8
 
       val minChar: char = #"\000"
       val numChars: int = 256
@@ -34,12 +23,14 @@
       val maxChar:char = #"\255"
 
       fun succ c =
-         if Primitive.Controls.safe andalso c = maxChar
+         if Primitive.Controls.safe 
+            andalso c = maxChar
             then raise Chr
          else chrUnsafe (Int.+ (ord c, 1))
 
       fun pred c =
-         if Primitive.Controls.safe andalso c = minChar
+         if Primitive.Controls.safe 
+            andalso c = minChar
             then raise Chr
          else chrUnsafe (Int.- (ord c, 1))
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/text/string-cvt.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/text/string-cvt.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/text/string-cvt.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -10,7 +10,7 @@
    struct
       open Reader
 
-      val wordFromInt = Word.fromInt
+      val wordFromInt = Word.sextdFromInt
 
       datatype radix = BIN | OCT | DEC | HEX
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/util/CUtil.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/util/CUtil.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/util/CUtil.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -48,14 +48,14 @@
             type t = C_String.t
 
             fun sub (cs, i) =
-               Primitive.Char8.fromWord8Unsafe 
+               Primitive.Char8.idFromWord8
                (Pointer.getWord8 
                 (Pointer.fromWord cs, C_Ptrdiff.fromInt i))
 
             fun update (cs, i, c) =
                Pointer.setWord8 
                (Pointer.fromWord cs, C_Ptrdiff.fromInt i, 
-                Primitive.Char8.toWord8Unsafe c)
+                Primitive.Char8.idToWord8 c)
 
             fun toCharArrayOfLength (cs, n) = toArrayOfLength (cs, sub, n)
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/util/integral-comparisons.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/util/integral-comparisons.sml	2006-05-16 02:49:56 UTC (rev 4547)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/util/integral-comparisons.sml	2006-05-16 03:02:10 UTC (rev 4548)
@@ -22,11 +22,11 @@
    end
 functor UnsignedIntegralComparisons (type int
                                      type word
-                                     val fromInt : int -> word
+                                     val idFromIntToWord : int -> word
                                      val < : word * word -> bool) =
    struct
       local
-         fun ltu (i: int, i': int) = < (fromInt i, fromInt i')
+         fun ltu (i: int, i': int) = < (idFromIntToWord i, idFromIntToWord i')
          structure S = IntegralComparisons (type t = int 
                                             val < = ltu)
       in