]> gitweb.factorcode.org Git - factor.git/commitdiff
specialized-arrays: direct-slice for byte-arrays
authorJoe Groff <arcata@gmail.com>
Thu, 13 Oct 2011 22:11:32 +0000 (15:11 -0700)
committerJoe Groff <arcata@gmail.com>
Tue, 18 Oct 2011 04:23:06 +0000 (21:23 -0700)
Implement nth-c-ptr and direct-like for byte-arrays so that direct-slice over a byte-array makes a uchar-array{ } over a part of the byte-array

basis/specialized-arrays/specialized-arrays-tests.factor
basis/specialized-arrays/specialized-arrays.factor

index 17fcc5da7d97e02bcad89872a2e159e0e092e414..01fac4cc47663afed1df63f0b17d13e58b41a7d1 100644 (file)
@@ -199,6 +199,7 @@ SPECIALIZED-ARRAY: struct-resize-test
 [ int-array{ 4 5 6 7 8 } ] [ int-array{ 1 2 3 4 5 6 7 8 } 3 direct-tail ] unit-test
 [ int-array{ 6 7 8 } ] [ int-array{ 1 2 3 4 5 6 7 8 } 3 direct-tail* ] unit-test
 
+[ uchar-array{ 0 1 255 } ] [ 3 6 B{ 1 1 1 0 1 255 2 2 2 } direct-slice ] unit-test
 
 [ int-array{ 1 2 3 4 55555 6 7 8 } ] [
     int-array{ 1 2 3 4 5 6 7 8 }
index 791d17b29af49657c8ed22ceab0f287731fb61c3..314989fd0ae33f28f196710e23be45a0861331f2 100644 (file)
@@ -36,6 +36,9 @@ M: pointer underlying-type
 GENERIC: nth-c-ptr ( n seq -- displaced-alien )
 GENERIC: direct-like ( alien len exemplar -- seq )
 
+M: byte-array nth-c-ptr <displaced-alien> ; inline
+M: byte-array direct-like drop uchar <c-direct-array> ; inline
+
 FUNCTOR: define-array ( T -- )
 
 A          DEFINES-CLASS ${T}-array
@@ -179,3 +182,5 @@ SYNTAX: SPECIALIZED-ARRAY:
 { "specialized-arrays" "prettyprint" } "specialized-arrays.prettyprint" require-when
 
 { "specialized-arrays" "mirrors" } "specialized-arrays.mirrors" require-when
+
+uchar define-array-vocab drop