specialized-arrays: rename byte-array>T-array to T-array-cast, and make it work with anything that responds to >c-ptr / byte-length
parent
4dd58ce40e
commit
a8098e3182
|
@ -182,10 +182,10 @@ HINTS: (process-md5-block-I) { uint-array md5-state } ;
|
|||
] each
|
||||
] unless ;
|
||||
|
||||
: byte-array>uint-array-le ( byte-array -- uint-array )
|
||||
byte-array>le byte-array>uint-array ;
|
||||
: uint-array-cast-le ( byte-array -- uint-array )
|
||||
byte-array>le uint-array-cast ;
|
||||
|
||||
HINTS: byte-array>uint-array-le byte-array ;
|
||||
HINTS: uint-array-cast-le byte-array ;
|
||||
|
||||
: uint-array>byte-array-le ( uint-array -- byte-array )
|
||||
underlying>> byte-array>le ;
|
||||
|
@ -194,7 +194,7 @@ HINTS: uint-array>byte-array-le uint-array ;
|
|||
|
||||
M: md5-state checksum-block ( block state -- )
|
||||
[
|
||||
[ byte-array>uint-array-le ] [ state>> ] bi* {
|
||||
[ uint-array-cast-le ] [ state>> ] bi* {
|
||||
[ (process-md5-block-F) ]
|
||||
[ (process-md5-block-G) ]
|
||||
[ (process-md5-block-H) ]
|
||||
|
|
|
@ -281,7 +281,7 @@ ERROR: bmp-not-supported n ;
|
|||
{ 24 [ color-index>> ] }
|
||||
{ 16 [
|
||||
[
|
||||
! byte-array>ushort-array
|
||||
! ushort-array-cast
|
||||
2 group [ le> ] map
|
||||
! 5 6 5
|
||||
! { HEX: f800 HEX: 7e0 HEX: 1f } uncompress-bitfield
|
||||
|
@ -312,7 +312,7 @@ M: unsupported-bitfield-widths summary
|
|||
dup header>> bit-count>> {
|
||||
{ 16 [
|
||||
dup bitfields>> '[
|
||||
byte-array>ushort-array _ uncompress-bitfield
|
||||
ushort-array-cast _ uncompress-bitfield
|
||||
] change-color-index
|
||||
] }
|
||||
{ 32 [ ] }
|
||||
|
|
|
@ -47,13 +47,13 @@ GENERIC: normalize-component-type* ( image component-type -- image )
|
|||
[ 255.0 * >integer ] B{ } map-as ;
|
||||
|
||||
M: float-components normalize-component-type*
|
||||
drop byte-array>float-array normalize-floats ;
|
||||
drop float-array-cast normalize-floats ;
|
||||
|
||||
M: half-components normalize-component-type*
|
||||
drop byte-array>half-array normalize-floats ;
|
||||
drop half-array-cast normalize-floats ;
|
||||
|
||||
: ushorts>ubytes ( bitmap -- bitmap' )
|
||||
byte-array>ushort-array [ -8 shift ] B{ } map-as ; inline
|
||||
ushort-array-cast [ -8 shift ] B{ } map-as ; inline
|
||||
|
||||
M: ushort-components normalize-component-type*
|
||||
drop ushorts>ubytes ;
|
||||
|
|
|
@ -18,7 +18,7 @@ IN: io.ports.tests
|
|||
|
||||
[ t ] [
|
||||
"test.txt" temp-file binary [
|
||||
100,000 4 * read byte-array>int-array 100,000 iota sequence=
|
||||
100,000 4 * read int-array-cast 100,000 iota sequence=
|
||||
] with-file-reader
|
||||
] unit-test
|
||||
|
||||
|
|
|
@ -45,16 +45,16 @@ IN: math.vectors.simd.intrinsics
|
|||
|
||||
: [byte>rep-array] ( rep -- class )
|
||||
{
|
||||
{ char-16-rep [ [ byte-array>char-array ] ] }
|
||||
{ uchar-16-rep [ [ byte-array>uchar-array ] ] }
|
||||
{ short-8-rep [ [ byte-array>short-array ] ] }
|
||||
{ ushort-8-rep [ [ byte-array>ushort-array ] ] }
|
||||
{ int-4-rep [ [ byte-array>int-array ] ] }
|
||||
{ uint-4-rep [ [ byte-array>uint-array ] ] }
|
||||
{ longlong-2-rep [ [ byte-array>longlong-array ] ] }
|
||||
{ ulonglong-2-rep [ [ byte-array>ulonglong-array ] ] }
|
||||
{ float-4-rep [ [ byte-array>float-array ] ] }
|
||||
{ double-2-rep [ [ byte-array>double-array ] ] }
|
||||
{ char-16-rep [ [ char-array-cast ] ] }
|
||||
{ uchar-16-rep [ [ uchar-array-cast ] ] }
|
||||
{ short-8-rep [ [ short-array-cast ] ] }
|
||||
{ ushort-8-rep [ [ ushort-array-cast ] ] }
|
||||
{ int-4-rep [ [ int-array-cast ] ] }
|
||||
{ uint-4-rep [ [ uint-array-cast ] ] }
|
||||
{ longlong-2-rep [ [ longlong-array-cast ] ] }
|
||||
{ ulonglong-2-rep [ [ ulonglong-array-cast ] ] }
|
||||
{ float-4-rep [ [ float-array-cast ] ] }
|
||||
{ double-2-rep [ [ double-array-cast ] ] }
|
||||
} case ; foldable
|
||||
|
||||
: [>rep-array] ( rep -- class )
|
||||
|
|
|
@ -118,7 +118,7 @@ M:: sfmt generate ( sfmt -- )
|
|||
state-multiplier * 32 bits
|
||||
] dip + 32 bits
|
||||
] uint-array{ } accumulate-as nip
|
||||
dup underlying>> byte-array>uint-4-array ;
|
||||
dup uint-4-array-cast ;
|
||||
|
||||
: <sfmt-state> ( seed n m mask parity -- sfmt )
|
||||
sfmt-state <struct>
|
||||
|
|
|
@ -21,7 +21,7 @@ ARTICLE: "specialized-array-words" "Specialized array words"
|
|||
{ { $snippet "(T-array)" } { "Constructor for arrays with elements of type " { $snippet "T" } ", where the initial contents are uninitialized; stack effect " { $snippet "( len -- array )" } } }
|
||||
{ { $snippet "malloc-T-array" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by newly-allocated unmanaged memory; stack effect " { $snippet "( alien len -- array )" } } }
|
||||
{ { $snippet "<direct-T-array>" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by raw memory; stack effect " { $snippet "( alien len -- array )" } } }
|
||||
{ { $snippet "byte-array>T-array" } { "Converts a byte array into a specialized array by interpreting the bytes in as machine-specific values. Code which uses this word is unportable" } }
|
||||
{ { $snippet "T-array-cast" } { "Converts a byte array into a specialized array by interpreting the bytes in as machine-specific values. Code which uses this word is unportable" } }
|
||||
{ { $snippet ">T-array" } { "Converts a sequence into a specialized array of type " { $snippet "T" } "; stack effect " { $snippet "( seq -- array )" } } }
|
||||
{ { $snippet "T-array{" } { "Literal syntax, consists of a series of values terminated by " { $snippet "}" } } }
|
||||
}
|
||||
|
|
|
@ -27,10 +27,10 @@ SPECIALIZED-ARRAYS: bool ushort char uint float ulonglong ;
|
|||
] unit-test
|
||||
|
||||
[ ushort-array{ 1234 } ] [
|
||||
little-endian? B{ 210 4 } B{ 4 210 } ? byte-array>ushort-array
|
||||
little-endian? B{ 210 4 } B{ 4 210 } ? ushort-array-cast
|
||||
] unit-test
|
||||
|
||||
[ B{ 210 4 1 } byte-array>ushort-array ] must-fail
|
||||
[ B{ 210 4 1 } ushort-array-cast ] must-fail
|
||||
|
||||
[ { 3 1 3 3 7 } ] [
|
||||
int-array{ 3 1 3 3 7 } malloc-byte-array 5 <direct-int-array> >array
|
||||
|
|
|
@ -34,19 +34,19 @@ M: not-a-byte-array summary
|
|||
|
||||
FUNCTOR: define-array ( T -- )
|
||||
|
||||
A DEFINES-CLASS ${T}-array
|
||||
<A> DEFINES <${A}>
|
||||
(A) DEFINES (${A})
|
||||
<direct-A> DEFINES <direct-${A}>
|
||||
malloc-A DEFINES malloc-${A}
|
||||
>A DEFINES >${A}
|
||||
byte-array>A DEFINES byte-array>${A}
|
||||
|
||||
A{ DEFINES ${A}{
|
||||
A@ DEFINES ${A}@
|
||||
|
||||
NTH [ T dup c-getter array-accessor ]
|
||||
SET-NTH [ T dup c-setter array-accessor ]
|
||||
A DEFINES-CLASS ${T}-array
|
||||
<A> DEFINES <${A}>
|
||||
(A) DEFINES (${A})
|
||||
<direct-A> DEFINES <direct-${A}>
|
||||
malloc-A DEFINES malloc-${A}
|
||||
>A DEFINES >${A}
|
||||
A-cast DEFINES ${A}-cast
|
||||
|
||||
A{ DEFINES ${A}{
|
||||
A@ DEFINES ${A}@
|
||||
|
||||
NTH [ T dup c-getter array-accessor ]
|
||||
SET-NTH [ T dup c-setter array-accessor ]
|
||||
|
||||
WHERE
|
||||
|
||||
|
@ -65,12 +65,9 @@ TUPLE: A
|
|||
: malloc-A ( len -- specialized-array )
|
||||
[ \ T heap-size calloc ] keep <direct-A> ; inline
|
||||
|
||||
: byte-array>A ( byte-array -- specialized-array )
|
||||
>c-ptr dup byte-array? [
|
||||
dup length \ T heap-size /mod 0 =
|
||||
[ <direct-A> ]
|
||||
[ drop \ T bad-byte-array-length ] if
|
||||
] [ not-a-byte-array ] if ; inline
|
||||
: A-cast ( byte-array -- specialized-array )
|
||||
binary-object \ T heap-size /mod 0 =
|
||||
[ <direct-A> ] [ drop \ T bad-byte-array-length ] bi ; inline
|
||||
|
||||
M: A clone [ underlying>> clone ] [ length>> ] bi <direct-A> ; inline
|
||||
|
||||
|
|
|
@ -797,7 +797,7 @@ M: windows-ui-backend system-alert
|
|||
: client-area>RECT ( hwnd -- RECT )
|
||||
RECT <struct>
|
||||
[ GetClientRect win32-error=0/f ]
|
||||
[ >c-ptr byte-array>POINT-array [ ClientToScreen drop ] with each ]
|
||||
[ >c-ptr POINT-array-cast [ ClientToScreen drop ] with each ]
|
||||
[ nip ] 2tri ;
|
||||
|
||||
: hwnd>RECT ( hwnd -- RECT )
|
||||
|
|
|
@ -9,7 +9,7 @@ IN: alien.data.map.tests
|
|||
[ float-array{ 1.0 1.0 3.0 3.0 5.0 5.0 } ]
|
||||
[
|
||||
int-array{ 1 3 5 } [ dup ] data-map( int -- float[2] )
|
||||
byte-array>float-array
|
||||
float-array-cast
|
||||
] unit-test
|
||||
|
||||
[
|
||||
|
@ -20,7 +20,7 @@ IN: alien.data.map.tests
|
|||
}
|
||||
] [
|
||||
3 iota [ float-4-with ] data-map( object -- float-4 )
|
||||
byte-array>float-4-array
|
||||
float-4-array-cast
|
||||
] unit-test
|
||||
|
||||
[
|
||||
|
@ -31,7 +31,7 @@ IN: alien.data.map.tests
|
|||
}
|
||||
] [
|
||||
12 iota [ float-4-boa ] data-map( object[4] -- float-4 )
|
||||
byte-array>float-4-array
|
||||
float-4-array-cast
|
||||
] unit-test
|
||||
|
||||
[ float-array{ 1.0 1.0 3.0 3.0 5.0 5.0 0.0 0.0 } ]
|
||||
|
@ -151,5 +151,5 @@ CONSTANT: plane-count 4
|
|||
[ ] data-map( object -- float ) ;
|
||||
|
||||
[ float-array{ 0.0 0.5 1.0 } ]
|
||||
[ 2 data-map-compiler-bug-test byte-array>float-array ]
|
||||
[ 2 data-map-compiler-bug-test float-array-cast ]
|
||||
unit-test
|
||||
|
|
|
@ -18,4 +18,4 @@ SPECIALIZED-ARRAY: float
|
|||
1.0 0.0 0.5 1.0
|
||||
1.0 0.0 1.0 1.0
|
||||
}
|
||||
] [ { 2 2 } vertex-array byte-array>float-array ] unit-test
|
||||
] [ { 2 2 } vertex-array float-array-cast ] unit-test
|
||||
|
|
|
@ -124,7 +124,7 @@ MEMO: perlin-noise-map-coords ( dim -- coords )
|
|||
|
||||
TYPED:: perlin-noise-map ( table: byte-array transform: matrix4 coords: float-4-array -- map: float-array )
|
||||
coords [| coord | table transform coord m4.v perlin-noise ] data-map( float-4 -- c:float )
|
||||
byte-array>float-array ;
|
||||
float-array-cast ;
|
||||
|
||||
: perlin-noise-image ( table transform dim -- image )
|
||||
[ perlin-noise-map-coords perlin-noise-map ] [ 5/7. 0.5 float-map>image ] bi ;
|
||||
|
|
Loading…
Reference in New Issue