[MLton-commit] r4388

Stephen Weeks MLton@mlton.org
Thu, 30 Mar 2006 12:37:39 -0800


Eliminated deprecated checkSlice{,Max}.

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

U   mlton/trunk/basis-library/arrays-and-vectors/array.sig
U   mlton/trunk/basis-library/arrays-and-vectors/array2.sml
U   mlton/trunk/basis-library/arrays-and-vectors/sequence.fun
U   mlton/trunk/basis-library/arrays-and-vectors/sequence.sig
U   mlton/trunk/basis-library/arrays-and-vectors/vector.sig
U   mlton/trunk/basis-library/real/pack-real.sml

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

Modified: mlton/trunk/basis-library/arrays-and-vectors/array.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/array.sig	2006-03-30 20:09:58 UTC (rev 4387)
+++ mlton/trunk/basis-library/arrays-and-vectors/array.sig	2006-03-30 20:37:36 UTC (rev 4388)
@@ -40,8 +40,6 @@
 
       structure ArraySlice: ARRAY_SLICE_EXTRA 
 
-      val checkSlice: 'a array * int * int option -> int (* Deprecated *)
-      val checkSliceMax: int * int option * int -> int (* Deprecated *)
       val concat: 'a array list -> 'a array
       val duplicate: 'a array -> 'a array
       val rawArray: int -> 'a array

Modified: mlton/trunk/basis-library/arrays-and-vectors/array2.sml
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/array2.sml	2006-03-30 20:09:58 UTC (rev 4387)
+++ mlton/trunk/basis-library/arrays-and-vectors/array2.sml	2006-03-30 20:37:36 UTC (rev 4388)
@@ -28,10 +28,28 @@
                         nrows: int option,
                         ncols: int option}
 
+      fun checkSliceMax (start: int, num: int option, max: int): int =
+         case num of
+            NONE =>
+               if Primitive.safe andalso (start < 0 orelse start > max) then
+                  raise Subscript
+               else
+                  max
+          | SOME num =>
+               if Primitive.safe
+                  andalso (start < 0
+                           orelse num < 0
+                           orelse start > max -? num) then
+                  raise Subscript
+               else
+                  start +? num
+
       fun checkRegion {base, row, col, nrows, ncols} =
-         let val (rows, cols) = dimensions base
-         in {stopRow = Array.checkSliceMax (row, nrows, rows),
-             stopCol = Array.checkSliceMax (col, ncols, cols)}
+         let
+            val (rows, cols) = dimensions base
+         in
+            {stopRow = checkSliceMax (row, nrows, rows),
+             stopCol = checkSliceMax (col, ncols, cols)}
          end
       
       fun wholeRegion (a: 'a array): 'a region =

Modified: mlton/trunk/basis-library/arrays-and-vectors/sequence.fun
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/sequence.fun	2006-03-30 20:09:58 UTC (rev 4387)
+++ mlton/trunk/basis-library/arrays-and-vectors/sequence.fun	2006-03-30 20:37:36 UTC (rev 4388)
@@ -456,18 +456,4 @@
         fun duplicate seq = make Slice.sequence seq
         fun toList seq = make Slice.toList seq
       end
-    
-      (* Deprecated *)
-      fun checkSliceMax (start: int, num: int option, max: int): int =
-         case num of
-            NONE => if Primitive.safe andalso (start < 0 orelse start > max)
-                       then raise Subscript
-                    else max
-          | SOME num =>
-               if Primitive.safe
-                  andalso (start < 0 orelse num < 0 orelse start > max -? num)
-                  then raise Subscript
-               else start +? num
-      (* Deprecated *)
-      fun checkSlice (s, i, opt) = checkSliceMax (i, opt, length s)
    end

Modified: mlton/trunk/basis-library/arrays-and-vectors/sequence.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/sequence.sig	2006-03-30 20:09:58 UTC (rev 4387)
+++ mlton/trunk/basis-library/arrays-and-vectors/sequence.sig	2006-03-30 20:37:36 UTC (rev 4388)
@@ -63,9 +63,4 @@
       val new: int * 'a elt -> 'a sequence
       val toList: 'a sequence -> 'a elt list
       val unfoldi: int * 'a * (int * 'a -> 'b elt * 'a) -> 'b sequence * 'a
-
-      (* Deprecated *)
-      val checkSlice: 'a sequence * int * int option -> int
-      (* Deprecated *)
-      val checkSliceMax: int * int option * int -> int
    end

Modified: mlton/trunk/basis-library/arrays-and-vectors/vector.sig
===================================================================
--- mlton/trunk/basis-library/arrays-and-vectors/vector.sig	2006-03-30 20:09:58 UTC (rev 4387)
+++ mlton/trunk/basis-library/arrays-and-vectors/vector.sig	2006-03-30 20:37:36 UTC (rev 4388)
@@ -34,28 +34,24 @@
       include VECTOR
       structure VectorSlice: VECTOR_SLICE_EXTRA 
 
-      val unsafeSub: 'a vector * int -> 'a
-
-      (* Used to implement Substring/String functions *)
-      val concatWith: 'a vector -> 'a vector list -> 'a vector
-      val isPrefix: ('a * 'a -> bool) -> 'a vector -> 'a vector -> bool
-      val isSubvector: ('a * 'a -> bool) -> 'a vector -> 'a vector -> bool
-      val isSuffix: ('a * 'a -> bool) -> 'a vector -> 'a vector -> bool
-      val translate: ('a -> 'a vector) -> 'a vector -> 'a vector
-      val tokens: ('a -> bool) -> 'a vector -> 'a vector list
-      val fields: ('a -> bool) -> 'a vector -> 'a vector list
-
       val append: 'a vector * 'a vector -> 'a vector
+      (* concatWith is used to implement Substring/String functions *)
+      val concatWith: 'a vector -> 'a vector list -> 'a vector
       val create:
-         int * ({sub: int -> 'a, update: int * 'a -> unit}
-                -> (int -> 'a) * (unit -> unit))
+         int
+         * ({sub: int -> 'a, update: int * 'a -> unit}
+            -> (int -> 'a) * (unit -> unit))
          -> 'a vector
       val duplicate: 'a vector -> 'a vector
+      val fields: ('a -> bool) -> 'a vector -> 'a vector list
       val fromArray: 'a array -> 'a vector
+      val isPrefix: ('a * 'a -> bool) -> 'a vector -> 'a vector -> bool
+      val isSubvector: ('a * 'a -> bool) -> 'a vector -> 'a vector -> bool
+      val isSuffix: ('a * 'a -> bool) -> 'a vector -> 'a vector -> bool
       val toList: 'a vector -> 'a list
+      val tokens: ('a -> bool) -> 'a vector -> 'a vector list
+      val translate: ('a -> 'a vector) -> 'a vector -> 'a vector
       val unfoldi: int * 'b * (int * 'b -> 'a * 'b) -> 'a vector * 'b
+      val unsafeSub: 'a vector * int -> 'a
       val vector: int * 'a -> 'a vector
-
-      (* Deprecated *)
-      val checkSlice: 'a vector * int * int option -> int
    end

Modified: mlton/trunk/basis-library/real/pack-real.sml
===================================================================
--- mlton/trunk/basis-library/real/pack-real.sml	2006-03-30 20:09:58 UTC (rev 4387)
+++ mlton/trunk/basis-library/real/pack-real.sml	2006-03-30 20:37:36 UTC (rev 4388)
@@ -24,10 +24,16 @@
       then (subVec, update)
    else (subVecRev, updateRev)
 
+fun check (size, i) =
+   if Int.< (i, 0) orelse Int.> (i, size -? bytesPerElem) then
+      raise Subscript
+   else
+      ()
+
 fun update (a, i, r) =
    let
+      val () = check (Word8Array.length a, i)
       val a = Word8Array.toPoly a
-      val _ = Array.checkSlice (a, i, SOME bytesPerElem)
    in
       up (a, i, r)
    end
@@ -42,8 +48,8 @@
 
 fun subVec (v, i) =
    let
+      val () = check (Word8Vector.length v, i)
       val v = Word8Vector.toPoly v
-      val _ = Vector.checkSlice (v, i, SOME bytesPerElem)
    in
       sub (v, i)
    end