]> gitweb.factorcode.org Git - factor.git/commitdiff
specialized-arrays: rename byte-array>T-array to T-array-cast, and make it work with...
authorSlava Pestov <slava@factorcode.org>
Wed, 19 May 2010 03:09:34 +0000 (23:09 -0400)
committerSlava Pestov <slava@factorcode.org>
Wed, 19 May 2010 03:09:34 +0000 (23:09 -0400)
13 files changed:
basis/checksums/md5/md5.factor
basis/images/bitmap/bitmap.factor
basis/images/normalization/normalization.factor
basis/io/ports/ports-tests.factor
basis/math/vectors/simd/intrinsics/intrinsics.factor
basis/random/sfmt/sfmt.factor
basis/specialized-arrays/specialized-arrays-docs.factor
basis/specialized-arrays/specialized-arrays-tests.factor
basis/specialized-arrays/specialized-arrays.factor
basis/ui/backend/windows/windows.factor
extra/alien/data/map/map-tests.factor
extra/grid-meshes/grid-meshes-tests.factor
extra/noise/noise.factor

index 63fdb4dee07737dbdd85b1af11cd6fe5855c64fe..f83d0354f658ebc2f8b67134d4846870da5ab259 100644 (file)
@@ -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) ]
index aa500e53fbf53b70308b7dc957b0f098aca00ebc..424efb993afb464681d807540b103789b3c00512 100644 (file)
@@ -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 [ ] }
index a73de4f7b8066822b99aadbffb62943cd73ac52b..aa85057ee9f70e4d214be5a242637791ca7a6df4 100644 (file)
@@ -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 ;
index c7af6909e16dd7fbe187129a73315ba0fae37aa0..d2fb5764ff6ac67ea42f3fe31fad7cdb504d3818 100644 (file)
@@ -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
 
index c7d650e1e6fe9c7171dc4b5c40f8d58439116847..121293f45e661ac370f38951628a21070de49ad5 100644 (file)
@@ -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 )
index 7a80cda062eb6b56434ef27ad9417aeb7c77d5c0..ccccaac7eaf53eef675dcbd18327da8cf2f9ba6e 100644 (file)
@@ -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>
index 68ce02e71e7f345b91fc5265bb3d7e42ba812ba2..fd1a4a72f25e2947e86346e3a245ba5e9cc3ae2f 100644 (file)
@@ -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 "}" } } }
 }
index ad1b4ad2b713ece63d6bc44a03b351ca1d22a3d9..3a34b3891bebbb6fbe53a9ea051b88db7454e10d 100644 (file)
@@ -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
index 35448a501c5694365b0aec9f5ffd35eb3108fee8..34854597e167cc473876b2a1e2ab2f1337c23f94 100644 (file)
@@ -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
 
index 8dae849a1fa0bed133cf271d04eb9f087a131fa3..00fdb907fdb9ce387db3548b67fb201a99fecf79 100755 (executable)
@@ -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 )
index 305ae6bdf236f4b7b2d07d23bd1e58218968abad..67e7b5f22e72265e3ed8985ccc7c6d4b9bdb16a7 100644 (file)
@@ -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
index ef71a669ed204b3f7cb6bcd79fba3626aa7e745f..0b6275dba0800f2735ece98452e99d0f4f89c006 100644 (file)
@@ -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
index 9204fa55f124473314b2f452a7ff8e0e5fb9cd0a..9417a868a0c0e089d04b9e345bad8a99c8783252 100644 (file)
@@ -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 ;