1 (* Copyright (C
) 2017 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
.
6 * MLton is released under a BSD
-style license
.
7 * See the file MLton
-LICENSE for details
.
10 structure Array
: ARRAY_EXTRA
=
12 structure A
= Sequence (Primitive
.Array
)
19 fun wrap2 f
= fn (i
, x
) => f (SeqIndex
.toIntUnsafe i
, x
)
21 type 'a array
= 'a array
22 type 'a vector
= 'a
Vector.vector
24 structure ArraySlice
=
27 val vector
= Primitive
.Array
.Slice
.vector
28 val copyVec
= Vector.VectorSlice
.copy
29 val unsafeCopyVec
= Vector.VectorSlice
.unsafeCopy
30 fun modifyi f sl
= Primitive
.Array
.Slice
.modifyi (wrap2 f
) sl
31 val modify
= Primitive
.Array
.Slice
.modify
35 val unsafeArray
= unsafeNew
36 val vector
= Primitive
.Array
.vector
37 val copyVec
= Vector.copy
38 val unsafeCopyVec
= Vector.unsafeCopy
39 fun modifyi f sl
= Primitive
.Array
.modifyi (wrap2 f
) sl
40 val modify
= Primitive
.Array
.modify
42 structure Raw
= Primitive
.Array
.Raw
45 type 'a rawarr
= 'a Raw
.rawarr
48 if Primitive
.Controls
.safe
49 then (SeqIndex
.toInt (Raw
.length a
))
50 handle Overflow
=> raise Fail
"Raw.length"
51 else SeqIndex
.toIntUnsafe (Raw
.length a
)
53 fun alloc n
= Raw
.alloc (SeqIndex
.fromIntForLength n
)
54 fun unsafeAlloc n
= Raw
.unsafeAlloc (SeqIndex
.fromIntUnsafe n
)
56 val uninitIsNop
= Raw
.uninitIsNop
57 fun unsafeUninit (a
, i
) =
58 Raw
.unsafeUninit (a
, SeqIndex
.fromIntUnsafe i
)
60 if Primitive
.Controls
.safe
64 handle Overflow
=> raise Subscript
68 else unsafeUninit (a
, i
)
70 val unsafeToArray
= Primitive
.Array
.Raw
.unsafeToArray
74 structure ArraySlice
: ARRAY_SLICE_EXTRA
= Array
.ArraySlice
76 structure ArrayGlobal
: ARRAY_GLOBAL
= Array