| 1 |
(* Copyright (C) 2017,2020 Matthew Fluet. |
| 2 |
* Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh |
| 3 |
* Jagannathan, and Stephen Weeks. |
| 4 |
* Copyright (C) 1997-2000 NEC Research Institute. |
| 5 |
* |
| 6 |
* MLton is released under a HPND-style license. |
| 7 |
* See the file MLton-LICENSE for details. |
| 8 |
*) |
| 9 |
|
| 10 |
structure Array: ARRAY_EXTRA = |
| 11 |
struct |
| 12 |
structure A = Sequence (Primitive.Array) |
| 13 |
open A |
| 14 |
|
| 15 |
val op < = Int.< |
| 16 |
val op <= = Int.<= |
| 17 |
|
| 18 |
fun wrap2 f = fn (i, x) => f (SeqIndex.toIntUnsafe i, x) |
| 19 |
|
| 20 |
type 'a array = 'a array |
| 21 |
type 'a vector = 'a Vector.vector |
| 22 |
|
| 23 |
structure ArraySlice = |
| 24 |
struct |
| 25 |
open Slice |
| 26 |
val vector = Primitive.Array.Slice.vector |
| 27 |
val copyVec = Vector.VectorSlice.copy |
| 28 |
val unsafeCopyVec = Vector.VectorSlice.unsafeCopy |
| 29 |
fun modifyi f sl = Primitive.Array.Slice.modifyi (wrap2 f) sl |
| 30 |
val modify = Primitive.Array.Slice.modify |
| 31 |
end |
| 32 |
|
| 33 |
val array = new |
| 34 |
val unsafeArray = unsafeNew |
| 35 |
val vector = Primitive.Array.vector |
| 36 |
val copyVec = Vector.copy |
| 37 |
val unsafeCopyVec = Vector.unsafeCopy |
| 38 |
fun modifyi f sl = Primitive.Array.modifyi (wrap2 f) sl |
| 39 |
val modify = Primitive.Array.modify |
| 40 |
|
| 41 |
structure Raw = Primitive.Array.Raw |
| 42 |
structure Raw = |
| 43 |
struct |
| 44 |
type 'a rawarr = 'a Raw.rawarr |
| 45 |
|
| 46 |
fun length a = |
| 47 |
if Primitive.Controls.safe |
| 48 |
then (SeqIndex.toInt (Raw.length a)) |
| 49 |
handle Overflow => raise Fail "Raw.length" |
| 50 |
else SeqIndex.toIntUnsafe (Raw.length a) |
| 51 |
|
| 52 |
fun alloc n = Raw.alloc (SeqIndex.fromIntForLength n) |
| 53 |
fun unsafeAlloc n = Raw.unsafeAlloc (SeqIndex.fromIntUnsafe n) |
| 54 |
|
| 55 |
val uninitIsNop = Raw.uninitIsNop |
| 56 |
fun unsafeUninit (a, i) = |
| 57 |
Raw.unsafeUninit (a, SeqIndex.fromIntUnsafe i) |
| 58 |
fun uninit (a, i) = |
| 59 |
if Primitive.Controls.safe |
| 60 |
then let |
| 61 |
val i = |
| 62 |
(SeqIndex.fromInt i) |
| 63 |
handle Overflow => raise Subscript |
| 64 |
in |
| 65 |
Raw.uninit (a, i) |
| 66 |
end |
| 67 |
else unsafeUninit (a, i) |
| 68 |
|
| 69 |
val unsafeToArray = Primitive.Array.Raw.unsafeToArray |
| 70 |
end |
| 71 |
end |
| 72 |
|
| 73 |
structure ArraySlice: ARRAY_SLICE_EXTRA = Array.ArraySlice |
| 74 |
|
| 75 |
structure ArrayGlobal: ARRAY_GLOBAL = Array |
| 76 |
open ArrayGlobal |