factor/core/byte-arrays/byte-arrays.factor

29 lines
915 B
Factor
Raw Normal View History

2008-01-05 17:27:15 -05:00
! Copyright (C) 2007, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-07-16 17:48:09 -04:00
USING: accessors kernel kernel.private alien.accessors sequences
2008-01-31 21:11:46 -05:00
sequences.private math ;
2007-09-20 18:09:08 -04:00
IN: byte-arrays
M: byte-array clone (clone) ;
2008-07-16 17:48:09 -04:00
M: byte-array length length>> ;
2007-09-20 18:09:08 -04:00
M: byte-array nth-unsafe swap >fixnum alien-unsigned-1 ;
M: byte-array set-nth-unsafe swap >fixnum set-alien-unsigned-1 ;
: >byte-array ( seq -- byte-array ) B{ } clone-like ; inline
M: byte-array new-sequence drop (byte-array) ;
2007-09-20 18:09:08 -04:00
M: byte-array equal?
over byte-array? [ sequence= ] [ 2drop f ] if ;
2008-01-28 19:15:21 -05:00
M: byte-array resize
resize-byte-array ;
2007-09-20 18:09:08 -04:00
INSTANCE: byte-array sequence
2008-09-01 19:26:10 -04:00
2008-09-05 17:04:23 -04:00
: 1byte-array ( x -- byte-array ) 1 <byte-array> [ set-first ] keep ; inline
2008-09-01 19:26:10 -04:00
2008-09-05 17:04:23 -04:00
: 2byte-array ( x y -- byte-array ) B{ } 2sequence ; inline
2008-09-01 19:26:10 -04:00
2008-09-05 17:04:23 -04:00
: 3byte-array ( x y z -- byte-array ) B{ } 3sequence ; inline
2008-09-01 19:26:10 -04:00
2008-09-05 17:04:23 -04:00
: 4byte-array ( w x y z -- byte-array ) B{ } 4sequence ; inline