]> gitweb.factorcode.org Git - factor.git/blob - core/byte-arrays/byte-arrays.factor
ee7f5d660e1ed1b6caaba570e5e6495e30cbc24f
[factor.git] / core / byte-arrays / byte-arrays.factor
1 ! Copyright (C) 2007, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.accessors kernel math sequences
4 sequences.private ;
5 IN: byte-arrays
6
7 BUILTIN: byte-array
8 { length array-capacity read-only initial: 0 } ;
9
10 MIXIN: byte-sequence
11
12 PRIMITIVE: (byte-array) ( n -- byte-array )
13 PRIMITIVE: <byte-array> ( n -- byte-array )
14 PRIMITIVE: resize-byte-array ( n byte-array -- new-byte-array )
15
16 M: byte-array clone (clone) ; inline
17 M: byte-array clone-like
18     over byte-array? [ drop clone ] [ call-next-method ] if ; inline
19 M: byte-array length length>> ; inline
20 M: byte-array nth-unsafe swap integer>fixnum alien-unsigned-1 ; inline
21 M: byte-array set-nth-unsafe swap integer>fixnum set-alien-unsigned-1 ; inline
22 : >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
23 M: byte-array new-sequence drop (byte-array) ; inline
24
25 M: byte-array equal?
26     over byte-array? [ sequence= ] [ 2drop f ] if ;
27
28 M: byte-array resize
29     resize-byte-array ; inline
30
31 INSTANCE: byte-array sequence
32 INSTANCE: byte-array byte-sequence
33
34 : 1byte-array ( x -- byte-array ) B{ } 1sequence ; inline
35
36 : 2byte-array ( x y -- byte-array ) B{ } 2sequence ; inline
37
38 : 3byte-array ( x y z -- byte-array ) B{ } 3sequence ; inline
39
40 : 4byte-array ( w x y z -- byte-array ) B{ } 4sequence ; inline