[MLton-commit] r4357

Matthew Fluet MLton@mlton.org
Mon, 13 Feb 2006 19:58:21 -0800


More refactoring
----------------------------------------------------------------------

D   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/seq-index1.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb
U   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int-inf0.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int1.sml
D   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sig
D   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/primitive/prim-char.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/char0.sml
U   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/string-cvt.sml
A   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/util/reader.sig
A   mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/util/reader.sml

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

Deleted: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/seq-index1.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/seq-index1.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/arrays-and-vectors/seq-index1.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -1,46 +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.
- *)
-
-structure SeqIndex =
-   struct
-      open SeqIndex
-         
-      local
-         open Primitive
-         structure S =
-            SeqIndex_ChooseIntN
-            (type 'a t = IntInf.int -> 'a
-             val fInt8 = fn i => Word8.toInt8X (IntInf.toWord8X i)
-             val fInt16 = fn i => Word16.toInt16X (IntInf.toWord16X i)
-             val fInt32 = fn i => Word32.toInt32X (IntInf.toWord32X i)
-             val fInt64 = fn i => Word64.toInt64X (IntInf.toWord64X i))
-         structure S =
-            Int_ChooseInt
-            (type 'a t = 'a -> int
-             val fInt8 = fromInt8Unsafe
-             val fInt16 = fromInt16Unsafe
-             val fInt32 = fromInt32Unsafe
-             val fInt64 = fromInt64Unsafe
-             val fIntInf = S.f)
-      in
-         val fromIntUnsafe = S.f
-      end
-   
-      local
-         structure S =
-            Int_ChooseInt
-            (type 'a t = int -> 'a
-             val fInt8 = toInt8Unsafe
-             val fInt16 = toInt16Unsafe
-             val fInt32 = toInt32Unsafe
-             val fInt64 = toInt64Unsafe
-             val fIntInf = toIntInf)
-      in
-         val toIntUnsafe = S.f
-      end
-   end

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/build/sources.mlb	2006-02-14 03:58:19 UTC (rev 4357)
@@ -62,7 +62,6 @@
    ../list/list-pair.sml
    ../arrays-and-vectors/slice.sig
    ../arrays-and-vectors/sequence.sig
-   ../arrays-and-vectors/seq-index1.sml
    ../arrays-and-vectors/sequence.fun
    ../arrays-and-vectors/vector-slice.sig
    ../arrays-and-vectors/vector.sig
@@ -81,16 +80,16 @@
    ../arrays-and-vectors/mono-array2.sig
    ../arrays-and-vectors/mono-array2.fun
    ../arrays-and-vectors/mono.sml
+   ../text/string0.sml
+   ../text/char0.sml
+   ../util/reader.sig
+   ../util/reader.sml
+   ../text/string-cvt.sig
+   ../text/string-cvt.sml
+   ../general/bool.sig
+   ../general/bool.sml
+   ../integer/integer.sig
 (*
-      ../../text/string0.sml
-      ../../text/char0.sml
-      ../../misc/reader.sig
-      ../../misc/reader.sml
-      ../../text/string-cvt.sig
-      ../../text/string-cvt.sml
-      ../../general/bool.sig
-      ../../general/bool.sml
-      ../../integer/integer.sig
       ../../integer/int.sml
       ../../text/char.sig
       ../../text/char.sml

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int-inf0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int-inf0.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int-inf0.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -58,6 +58,13 @@
       val toString8: int -> Primitive.String8.string
 
       (* 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
+
+      (* Sign extend. *)
       val fromInt8: Primitive.Int8.int -> int
       val fromInt16: Primitive.Int16.int -> int
       val fromInt32: Primitive.Int32.int -> int
@@ -65,17 +72,36 @@
       val fromIntInf: Primitive.IntInf.int -> int
 
       (* 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
+
+      (* 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
 
       (* 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
+
+      (* 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
 
+      (* 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
+
       (* Overflow checking. *)
       val toInt8: int -> Primitive.Int8.int
       val toInt16: int -> Primitive.Int16.int
@@ -84,12 +110,24 @@
       val toIntInf: int -> 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
+
+      (* 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
+
+      (* Lowbits. *)
       val toWord8X: int -> Primitive.Word8.word
       val toWord16X: int -> Primitive.Word16.word
       val toWord32X: int -> Primitive.Word32.word
@@ -262,7 +300,11 @@
                then fromWordAux8 (false, Word8.fromInt8 i)
                else fromWordAux8 (true, Word8.~ (Word8.fromInt8 i))
          fun fromWord8X w = fromInt8 (Word8.toInt8X w)
+         val fromInt8Unsafe = fromInt8
+         val fromWord8Unsafe = fromWord8
+         val fromWord8XUnsafe = fromWord8X
 
+
          val fromWordAux16 =
             make {toMPLimb = MPLimb.fromWord16,
                   toObjptrWord = ObjptrWord.fromWord16,
@@ -276,6 +318,9 @@
                then fromWordAux16 (false, Word16.fromInt16 i)
                else fromWordAux16 (true, Word16.~ (Word16.fromInt16 i))
          fun fromWord16X w = fromInt16 (Word16.toInt16X w)
+         val fromInt16Unsafe = fromInt16
+         val fromWord16Unsafe = fromWord16
+         val fromWord16XUnsafe = fromWord16X
 
          val fromWordAux32 =
             make {toMPLimb = MPLimb.fromWord32,
@@ -290,6 +335,9 @@
                then fromWordAux32 (false, Word32.fromInt32 i)
                else fromWordAux32 (true, Word32.~ (Word32.fromInt32 i))
          fun fromWord32X w = fromInt32 (Word32.toInt32X w)
+         val fromInt32Unsafe = fromInt32
+         val fromWord32Unsafe = fromWord32
+         val fromWord32XUnsafe = fromWord32X
 
          val fromWordAux64 =
             make {toMPLimb = MPLimb.fromWord64,
@@ -304,8 +352,12 @@
                then fromWordAux64 (false, Word64.fromInt64 i)
                else fromWordAux64 (true, Word64.~ (Word64.fromInt64 i))
          fun fromWord64X w = fromInt64 (Word64.toInt64X w)
+         val fromInt64Unsafe = fromInt64
+         val fromWord64Unsafe = fromWord64
+         val fromWord64XUnsafe = fromWord64X
 
          fun fromIntInf i = i
+         fun fromIntInfUnsafe i = i
       end
 
       local
@@ -405,6 +457,9 @@
                                 else ans
                           end
                   else Word8.toInt8 ans
+         val toWord8Unsafe = toWord8
+         val toWord8XUnsafe = toWord8X
+         fun toInt8Unsafe i = Word8.toInt8X (toWord8X i)
 
          val toWordAux16 =
             make {fromMPLimb = MPLimb.toWord16,
@@ -433,6 +488,9 @@
                                 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,
@@ -461,6 +519,9 @@
                                 else ans
                           end
                   else Word32.toInt32 ans
+         val toWord32Unsafe = toWord32
+         val toWord32XUnsafe = toWord32X
+         fun toInt32Unsafe i = Word32.toInt32X (toWord32X i)
 
          val toWordAux64 =
             make {fromMPLimb = MPLimb.toWord64,
@@ -489,8 +550,12 @@
                                 else ans
                           end
                   else Word64.toInt64 ans
+         val toWord64Unsafe = toWord64
+         val toWord64XUnsafe = toWord64X
+         fun toInt64Unsafe i = Word64.toInt64X (toWord64X i)
 
          fun toIntInf i = i
+         fun toIntInfUnsafe i = i
       end
 
       local
@@ -861,56 +926,94 @@
       val toString8 = bigToString8
 end
 
+structure Char8 =
+   struct
+      open Char8
+      fun fromIntInfUnsafe i = fromInt8Unsafe (IntInf.toInt8Unsafe i)
+      fun toIntInfUnsafe c = IntInf.fromInt8Unsafe (toInt8Unsafe c)
+   end
+structure Char16 =
+   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
    end
 structure Int16 = 
    struct
       open Int16
+      val fromIntInfUnsafe = IntInf.toInt16Unsafe
       val fromIntInf = IntInf.toInt16
+      val toIntInfUnsafe = IntInf.fromInt16Unsafe
       val toIntInf = IntInf.fromInt16
    end
 structure Int32 = 
    struct
       open Int32
+      val fromIntInfUnsafe = IntInf.toInt32Unsafe
       val fromIntInf = IntInf.toInt32
+      val toIntInfUnsafe = IntInf.fromInt32Unsafe
       val toIntInf = IntInf.fromInt32
    end
 structure Int64 = 
    struct
       open Int64
+      val fromIntInfUnsafe = IntInf.toInt64Unsafe
       val fromIntInf = IntInf.toInt64
+      val toIntInfUnsafe = IntInf.fromInt64Unsafe
       val toIntInf = IntInf.fromInt64
    end
 structure Word8 =
    struct
       open Word8
+      val fromIntInfUnsafe = IntInf.toWord8Unsafe
       val fromIntInf = IntInf.toWord8
+      val toIntInfUnsafe = IntInf.fromWord8Unsafe
       val toIntInf = IntInf.fromWord8
+      val toIntInfXUnsafe = IntInf.fromWord8XUnsafe
       val toIntInfX = IntInf.fromWord8X
    end
 structure Word16 =
    struct
       open Word16
+      val fromIntInfUnsafe = IntInf.toWord16Unsafe
       val fromIntInf = IntInf.toWord16
+      val toIntInfUnsafe = IntInf.fromWord16Unsafe
       val toIntInf = IntInf.fromWord16
+      val toIntInfXUnsafe = IntInf.fromWord16XUnsafe
       val toIntInfX = IntInf.fromWord16X
    end
 structure Word32 =
    struct
       open Word32
+      val fromIntInfUnsafe = IntInf.toWord32Unsafe
       val fromIntInf = IntInf.toWord32
+      val toIntInfUnsafe = IntInf.fromWord32Unsafe
       val toIntInf = IntInf.fromWord32
+      val toIntInfXUnsafe = IntInf.fromWord32XUnsafe
       val toIntInfX = IntInf.fromWord32X
    end
 structure Word64 =
    struct
       open Word64
+      val fromIntInfUnsafe = IntInf.toWord64Unsafe
       val fromIntInf = IntInf.toWord64
+      val toIntInfUnsafe = IntInf.fromWord64Unsafe
       val toIntInf = IntInf.fromWord64
+      val toIntInfXUnsafe = IntInf.fromWord64XUnsafe
       val toIntInfX = IntInf.fromWord64X
    end
 

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int1.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int1.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/integer/int1.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -9,12 +9,24 @@
 signature INT_FROM_TO_ARG =
    sig
       type 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
+      val fromIntInfUnsafe: Primitive.IntInf.int -> 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
       val fromIntInf: Primitive.IntInf.int -> 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
+      val toIntInfUnsafe: int -> Primitive.IntInf.int
       (* Overflow checking. *)
       val toInt8: int -> Primitive.Int8.int
       val toInt16: int -> Primitive.Int16.int
@@ -26,8 +38,12 @@
 signature INT_FROM_TO_RES =
    sig
       type int
+      val fromIntUnsafe: Int.int -> int
+      val fromLargeUnsafe: LargeInt.int -> int
       val fromInt: Int.int -> int
       val fromLarge: LargeInt.int -> int
+      val toIntUnsafe: int -> Int.int
+      val toLargeUnsafe: int -> LargeInt.int
       val toInt: int -> Int.int
       val toLarge: int -> LargeInt.int
    end
@@ -40,6 +56,30 @@
          structure S =
             Int_ChooseInt
             (type 'a t = 'a -> int
+             val fInt8 = I.fromInt8Unsafe
+             val fInt16 = I.fromInt16Unsafe
+             val fInt32 = I.fromInt32Unsafe
+             val fInt64 = I.fromInt64Unsafe
+             val fIntInf = I.fromIntInfUnsafe)
+      in
+         val fromIntUnsafe = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = 'a -> int
+             val fInt8 = I.fromInt8Unsafe
+             val fInt16 = I.fromInt16Unsafe
+             val fInt32 = I.fromInt32Unsafe
+             val fInt64 = I.fromInt64Unsafe
+             val fIntInf = I.fromIntInfUnsafe)
+      in
+         val fromLargeUnsafe = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> int
              val fInt8 = I.fromInt8
              val fInt16 = I.fromInt16
              val fInt32 = I.fromInt32
@@ -64,6 +104,30 @@
          structure S =
             Int_ChooseInt
             (type 'a t = int -> 'a
+             val fInt8 = I.toInt8Unsafe
+             val fInt16 = I.toInt16Unsafe
+             val fInt32 = I.toInt32Unsafe
+             val fInt64 = I.toInt64Unsafe
+             val fIntInf = I.toIntInfUnsafe)
+      in
+         val toIntUnsafe = S.f
+      end
+      local
+         structure S =
+            LargeInt_ChooseInt
+            (type 'a t = int -> 'a
+             val fInt8 = I.toInt8Unsafe
+             val fInt16 = I.toInt16Unsafe
+             val fInt32 = I.toInt32Unsafe
+             val fInt64 = I.toInt64Unsafe
+             val fIntInf = I.toIntInfUnsafe)
+      in
+         val toLargeUnsafe = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = int -> 'a
              val fInt8 = I.toInt8
              val fInt16 = I.toInt16
              val fInt32 = I.toInt32

Deleted: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sig
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sig	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sig	2006-02-14 03:58:19 UTC (rev 4357)
@@ -1,30 +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 READER =
-   sig
-      type ('a, 'b) reader = 'b -> ('a * 'b) option
-
-      (* read as many items as possible (never returns NONE) *)
-      val list: ('a, 'b) reader -> ('a list, 'b) reader
-
-      (* never return NONE *)
-      (* val tokens: ('a -> bool) -> ('a, 'b) reader -> ('a list list, 'b) reader *)
-      (* val fields: ('a -> bool) -> ('a, 'b) reader -> ('a list list, 'b) reader *)
-         
-      val map: ('a -> 'c) -> ('a, 'b) reader -> ('c, 'b) reader
-      val mapOpt: ('a -> 'c option) -> ('a, 'b) reader -> ('c, 'b) reader
-         
-      val ignore: ('a -> bool) -> ('a, 'b) reader -> ('a, 'b) reader
-
-      (* read excatly N items *)
-      val readerN: ('a, 'b) reader * int -> ('a list, 'b) reader
-      val reader2: ('a, 'b) reader -> ('a * 'a, 'b) reader
-      val reader3: ('a, 'b) reader -> ('a * 'a * 'a, 'b) reader
-      val reader4: ('a, 'b) reader -> ('a * 'a * 'a * 'a, 'b) reader
-   end

Deleted: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -1,103 +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.
- *)
-
-structure Reader: READER =
-struct
-
-open Primitive.Int
-   
-type ('a, 'b) reader = 'b -> ('a * 'b) option
-
-(* local
- *    fun make finish p reader state =
- *       let
- *       fun loop (state, token, tokens) =
- *          case reader state of
- *             NONE => SOME (rev (finish (token, tokens)), state)
- *           | SOME (x, state) =>
- *                let
- *                   val (token, tokens) =
- *                      if p x then ([], finish (token, tokens))
- *                      else (x :: token, tokens)
- *                in loop (state, token, tokens)
- *                end
- *       in loop (state, [], [])
- *       end
- * in
- *     fun tokens p = make (fn (token, tokens) =>
- *                     case token of
- *                        [] => tokens
- *                      | _ => (rev token) :: tokens) p
- *    fun fields p = make (fn (field, fields) => (rev field) :: fields) p
- * end
- *)
-   
-fun list (reader: ('a, 'b) reader): ('a list, 'b) reader =
-   fn state =>
-   let
-      fun loop (state, accum) =
-         case reader state of
-            NONE => SOME (rev accum, state)
-          | SOME (a, state) => loop (state, a :: accum)
-   in loop (state, [])
-   end
-               
-fun readerN (reader: ('a, 'b) reader, n: int): ('a list, 'b) reader =
-   fn (state :'b) =>
-   let
-      fun loop (n, state, accum) =
-         if n <= 0
-            then SOME (rev accum, state)
-         else case reader state of
-            NONE => NONE
-          | SOME (x, state) => loop (n - 1, state, x :: accum)
-   in loop (n, state, [])
-   end
-
-fun ignore f reader =
-   let
-      fun loop state =
-         case reader state of
-            NONE => NONE
-          | SOME (x, state) =>
-               if f x
-                  then loop state
-               else SOME (x, state)
-   in loop
-   end
-val _ = ignore
-   
-fun map (f: 'a -> 'c) (reader: ('a, 'b) reader): ('c, 'b) reader =
-   fn (b: 'b) =>
-   case reader b of
-      NONE => NONE
-    | SOME (a, b) => SOME (f a, b)
-
-fun mapOpt (f: 'a -> 'c option) (reader: ('a, 'b) reader): ('c, 'b) reader =
-   fn (b: 'b) =>
-   case reader b of
-      NONE => NONE
-    | SOME (a, b) =>
-         case f a of
-            NONE => NONE
-          | SOME c => SOME (c, b)
-
-fun reader2 reader =
-   map (fn [y, z] => (y, z) | _ => raise Fail "Reader.reader2")
-   (readerN (reader, 2))
-val _ = reader2
-   
-fun reader3 reader =
-   map (fn [x, y, z] => (x, y, z) | _ => raise Fail "Reader.reader3")
-   (readerN (reader, 3))
-   
-fun reader4 reader =
-   map (fn [w, x, y, z] => (w, x, y, z) | _ => raise Fail "Reader.reader4")
-   (readerN (reader, 4))
-   
-end   

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/primitive/prim-char.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/primitive/prim-char.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/primitive/prim-char.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -18,25 +18,25 @@
          
       val < = _prim "WordU8_lt": char * char -> bool;
 
-      val fromInt8 = _prim "WordS8_toWord8": Int8.int -> char;
-      val fromInt16 = _prim "WordS16_toWord8": Int16.int -> char;
-      val fromInt32 = _prim "WordS32_toWord8": Int32.int -> char;
-      val fromInt64 = _prim "WordS64_toWord8": Int64.int -> char;
+      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 fromWord8 = _prim "WordU8_toWord8": Word8.word -> char;
-      val fromWord16 = _prim "WordU16_toWord8": Word16.word -> char;
-      val fromWord32 = _prim "WordU32_toWord8": Word32.word -> char;
-      val fromWord64 = _prim "WordU64_toWord8": Word64.word -> 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 toInt8 = _prim "WordS8_toWord8": char -> Int8.int;
-      val toInt16 = _prim "WordS8_toWord16": char -> Int16.int;
-      val toInt32 = _prim "WordS8_toWord32": char -> Int32.int;
-      val toInt64 = _prim "WordS8_toWord64": char -> Int64.int;
+      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 toWord8 = _prim "WordU8_toWord8": char -> Word8.word;
-      val toWord16 = _prim "WordU8_toWord16": char -> Word16.word;
-      val toWord32 = _prim "WordU8_toWord32": char -> Word32.word;
-      val toWord64 = _prim "WordU8_toWord64": char -> Word64.word;
+      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;
    end
 structure Char8 = 
    struct
@@ -54,25 +54,25 @@
          
       val < = _prim "WordU16_lt": char * char -> bool;
 
-      val fromInt8 = _prim "WordS8_toWord16": Int8.int -> char;
-      val fromInt16 = _prim "WordS16_toWord16": Int16.int -> char;
-      val fromInt32 = _prim "WordS32_toWord16": Int32.int -> char;
-      val fromInt64 = _prim "WordS64_toWord16": Int64.int -> char;
+      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 fromWord8 = _prim "WordU8_toWord16": Word8.word -> char;
-      val fromWord16 = _prim "WordU16_toWord16": Word16.word -> char;
-      val fromWord32 = _prim "WordU32_toWord16": Word32.word -> char;
-      val fromWord64 = _prim "WordU64_toWord16": Word64.word -> 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 toInt8 = _prim "WordS16_toWord8": char -> Int8.int;
-      val toInt16 = _prim "WordS16_toWord16": char -> Int16.int;
-      val toInt32 = _prim "WordS16_toWord32": char -> Int32.int;
-      val toInt64 = _prim "WordS16_toWord64": char -> Int64.int;
+      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 toWord8 = _prim "WordU16_toWord8": char -> Word8.word;
-      val toWord16 = _prim "WordU16_toWord16": char -> Word16.word;
-      val toWord32 = _prim "WordU16_toWord32": char -> Word32.word;
-      val toWord64 = _prim "WordU16_toWord64": char -> Word64.word;
+      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;
    end
 structure Char16 = 
    struct
@@ -90,25 +90,25 @@
          
       val < = _prim "WordU32_lt": char * char -> bool;
 
-      val fromInt8 = _prim "WordS8_toWord32": Int8.int -> char;
-      val fromInt16 = _prim "WordS16_toWord32": Int16.int -> char;
-      val fromInt32 = _prim "WordS32_toWord32": Int32.int -> char;
-      val fromInt64 = _prim "WordS64_toWord32": Int64.int -> char;
+      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 fromWord8 = _prim "WordU8_toWord32": Word8.word -> char;
-      val fromWord16 = _prim "WordU16_toWord32": Word16.word -> char;
-      val fromWord32 = _prim "WordU32_toWord32": Word32.word -> char;
-      val fromWord64 = _prim "WordU64_toWord32": Word64.word -> 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 toInt8 = _prim "WordS32_toWord8": char -> Int8.int;
-      val toInt16 = _prim "WordS32_toWord16": char -> Int16.int;
-      val toInt32 = _prim "WordS32_toWord32": char -> Int32.int;
-      val toInt64 = _prim "WordS32_toWord64": char -> Int64.int;
+      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 toWord8 = _prim "WordU32_toWord8": char -> Word8.word;
-      val toWord16 = _prim "WordU32_toWord16": char -> Word16.word;
-      val toWord32 = _prim "WordU32_toWord32": char -> Word32.word;
-      val toWord64 = _prim "WordU32_toWord64": char -> Word64.word;
+      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;
    end
 structure Char32 = 
    struct

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/char0.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/char0.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/char0.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -8,38 +8,63 @@
 
 structure Char0 =
    struct
-      open Primitive.Int Primitive.Char
+      open Char
          
       type char = char
       type string = string
 
-      val minChar = #"\000"
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = 'a -> char
+             val fInt8 = Char.fromInt8Unsafe
+             val fInt16 = Char.fromInt16Unsafe
+             val fInt32 = Char.fromInt32Unsafe
+             val fInt64 = Char.fromInt64Unsafe
+             val fIntInf = Char.fromIntInfUnsafe)
+      in
+         val chrUnsafe = S.f
+      end
+      local
+         structure S =
+            Int_ChooseInt
+            (type 'a t = char -> 'a
+             val fInt8 = Char.toInt8Unsafe
+             val fInt16 = Char.toInt16Unsafe
+             val fInt32 = Char.toInt32Unsafe
+             val fInt64 = Char.toInt64Unsafe
+             val fIntInf = Char.toIntInfUnsafe)
+      in
+         val ord = S.f
+      end
+
+      val minChar:char = #"\000"
       val numChars: int = 256
       val maxOrd: int = 255
-      val maxChar = #"\255"
+      val maxChar:char = #"\255"
 
       fun succ c =
-         if Primitive.safe andalso c = maxChar
+         if Primitive.Controls.safe andalso c = maxChar
             then raise Chr
-         else Primitive.Char.chr (ord c + 1)
+         else chrUnsafe (Int.+ (ord c, 1))
 
       fun pred c =
-         if Primitive.safe andalso c = minChar
+         if Primitive.Controls.safe andalso c = minChar
             then raise Chr
-         else Primitive.Char.chr (ord c - 1)
+         else chrUnsafe (Int.- (ord c, 1))
 
       fun chrOpt c =
-         if Primitive.safe andalso Primitive.Int.gtu (c, maxOrd)
+         if Primitive.Controls.safe 
+            andalso (Int.< (c, 0) orelse Int.> (c, maxOrd))
+            (* andalso Int.gtu (c, maxOrd) *)
             then NONE
-         else SOME (Primitive.Char.chr c)
+         else SOME (chrUnsafe c)
 
       fun chr c =
          case chrOpt c of
             NONE => raise Chr
           | SOME c => c
 
-      val {compare, ...} = Util.makeCompare (op <)
-
       structure String = String0
 
       fun oneOf s =
@@ -47,9 +72,9 @@
             val a = Array.array (numChars, false)
             val n = String.size s
             fun loop i =
-               if Primitive.Int.>= (i, n) then ()
+               if Int.>= (i, n) then ()
                else (Array.update (a, ord (String.sub (s, i)), true)
-                     ; loop (i + 1))
+                     ; loop (Int.+ (i, 1)))
          in loop 0
             ; fn c => Array.sub (a, ord c)
          end
@@ -65,20 +90,20 @@
          
       local
          val not = fn f => memoize (not o f)
-         infix or andd
-         fun f or g = memoize (fn c => f c orelse g c)
-         fun f andd g = memoize (fn c => f c andalso g c)
+         infix || &&
+         fun f || g = memoize (fn c => f c orelse g c)
+         fun f && g = memoize (fn c => f c andalso g c)
       in
          val isLower = oneOf "abcdefghijklmnopqrstuvwxyz"
          val isUpper = oneOf "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
          val isDigit = oneOf "0123456789"
-         val isAlpha = isUpper or isLower
-         val isHexDigit = isDigit or (oneOf "abcdefABCDEF")
-         val isAlphaNum = isAlpha or isDigit
+         val isAlpha = isUpper || isLower
+         val isHexDigit = isDigit || (oneOf "abcdefABCDEF")
+         val isAlphaNum = isAlpha || isDigit
          val isPrint = fn c => #" " <= c andalso c <= #"~"
          val isSpace = oneOf " \t\r\n\v\f"
-         val isGraph = (not isSpace) andd isPrint
-         val isPunct = isGraph andd (not isAlphaNum)
+         val isGraph = (not isSpace) && isPrint
+         val isPunct = isGraph && (not isAlphaNum)
          val isCntrl = not isPrint
          val isAscii = fn c => c < #"\128"
       end
@@ -86,12 +111,11 @@
       local
          fun make (lower, upper, diff) =
             memoize (fn c => if lower <= c andalso c <= upper
-                               then chr (ord c +? diff)
+                               then chr (Int.+? (ord c, diff))
                             else c)
-         val diff = ord #"A" - ord #"a"
+         val diff = Int.- (ord #"A", ord #"a")
       in
-         val toLower = make (#"A", #"Z", ~diff)
+         val toLower = make (#"A", #"Z", Int.~ diff)
          val toUpper = make (#"a", #"z", diff)
       end
    end
-

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/string-cvt.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/string-cvt.sml	2006-02-13 18:15:50 UTC (rev 4356)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/text/string-cvt.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -10,7 +10,7 @@
    struct
       open Reader
 
-      val wordFromInt = Primitive.Word32.fromInt
+      val wordFromInt = Word.fromInt
 
       datatype radix = BIN | OCT | DEC | HEX
 
@@ -29,7 +29,7 @@
          
       type ('a, 'b) reader = 'b -> ('a * 'b) option
 
-      open Primitive.Int
+      open Int
 
       structure Char = Char0
       structure String = String0
@@ -177,8 +177,8 @@
 
       fun wdigits radix reader state =
          let 
-            val op + = Primitive.Word32.+
-            val op * = Primitive.Word32.*
+            val op + = Word.+
+            val op * = Word.*
             val r = radixToWord radix
             fun loop (accum, state) =
                case reader state of

Copied: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/util/reader.sig (from rev 4350, mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sig)

Copied: mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/util/reader.sml (from rev 4347, mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sml)
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/misc/reader.sml	2006-02-05 14:22:33 UTC (rev 4347)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library.refactor/util/reader.sml	2006-02-14 03:58:19 UTC (rev 4357)
@@ -0,0 +1,103 @@
+(* 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.
+ *)
+
+structure Reader: READER =
+struct
+
+open Int
+   
+type ('a, 'b) reader = 'b -> ('a * 'b) option
+
+(* local
+ *    fun make finish p reader state =
+ *       let
+ *       fun loop (state, token, tokens) =
+ *          case reader state of
+ *             NONE => SOME (rev (finish (token, tokens)), state)
+ *           | SOME (x, state) =>
+ *                let
+ *                   val (token, tokens) =
+ *                      if p x then ([], finish (token, tokens))
+ *                      else (x :: token, tokens)
+ *                in loop (state, token, tokens)
+ *                end
+ *       in loop (state, [], [])
+ *       end
+ * in
+ *     fun tokens p = make (fn (token, tokens) =>
+ *                     case token of
+ *                        [] => tokens
+ *                      | _ => (rev token) :: tokens) p
+ *    fun fields p = make (fn (field, fields) => (rev field) :: fields) p
+ * end
+ *)
+   
+fun list (reader: ('a, 'b) reader): ('a list, 'b) reader =
+   fn state =>
+   let
+      fun loop (state, accum) =
+         case reader state of
+            NONE => SOME (rev accum, state)
+          | SOME (a, state) => loop (state, a :: accum)
+   in loop (state, [])
+   end
+               
+fun readerN (reader: ('a, 'b) reader, n: int): ('a list, 'b) reader =
+   fn (state :'b) =>
+   let
+      fun loop (n, state, accum) =
+         if n <= 0
+            then SOME (rev accum, state)
+         else case reader state of
+            NONE => NONE
+          | SOME (x, state) => loop (n - 1, state, x :: accum)
+   in loop (n, state, [])
+   end
+
+fun ignore f reader =
+   let
+      fun loop state =
+         case reader state of
+            NONE => NONE
+          | SOME (x, state) =>
+               if f x
+                  then loop state
+               else SOME (x, state)
+   in loop
+   end
+val _ = ignore
+   
+fun map (f: 'a -> 'c) (reader: ('a, 'b) reader): ('c, 'b) reader =
+   fn (b: 'b) =>
+   case reader b of
+      NONE => NONE
+    | SOME (a, b) => SOME (f a, b)
+
+fun mapOpt (f: 'a -> 'c option) (reader: ('a, 'b) reader): ('c, 'b) reader =
+   fn (b: 'b) =>
+   case reader b of
+      NONE => NONE
+    | SOME (a, b) =>
+         case f a of
+            NONE => NONE
+          | SOME c => SOME (c, b)
+
+fun reader2 reader =
+   map (fn [y, z] => (y, z) | _ => raise Fail "Reader.reader2")
+   (readerN (reader, 2))
+val _ = reader2
+   
+fun reader3 reader =
+   map (fn [x, y, z] => (x, y, z) | _ => raise Fail "Reader.reader3")
+   (readerN (reader, 3))
+   
+fun reader4 reader =
+   map (fn [w, x, y, z] => (w, x, y, z) | _ => raise Fail "Reader.reader4")
+   (readerN (reader, 4))
+   
+end