factor/basis/io/streams/memory/memory.factor

22 lines
618 B
Factor
Raw Normal View History

2008-04-20 06:15:46 -04:00
! Copyright (C) 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors alien alien.c-types alien.accessors math io ;
2008-04-20 06:15:46 -04:00
IN: io.streams.memory
TUPLE: memory-stream alien index ;
: <memory-stream> ( alien -- stream )
0 memory-stream boa ;
2009-03-15 18:11:18 -04:00
M: memory-stream stream-element-type drop +byte+ ;
2008-04-20 06:15:46 -04:00
M: memory-stream stream-read1
[ [ alien>> ] [ index>> ] bi alien-unsigned-1 ]
[ [ 1+ ] change-index drop ] bi ;
M: memory-stream stream-read
[
[ index>> ] [ alien>> ] bi <displaced-alien>
swap memory>byte-array
] [ [ + ] change-index drop ] 2bi ;