factor/basis/alien/arrays/arrays.factor

111 lines
2.5 KiB
Factor
Raw Normal View History

! Copyright (C) 2008, 2009 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
USING: alien alien.strings alien.c-types alien.data alien.accessors
arrays words sequences math kernel namespaces fry cpu.architecture
io.encodings.binary io.encodings.utf8 accessors ;
2007-09-20 18:09:08 -04:00
IN: alien.arrays
INSTANCE: array value-type
2007-09-20 18:09:08 -04:00
M: array c-type ;
2008-11-29 05:59:29 -05:00
M: array c-type-class drop object ;
M: array c-type-boxed-class drop object ;
: array-length ( seq -- n )
[ dup word? [ def>> call( -- object ) ] when ] [ * ] map-reduce ;
M: array heap-size unclip [ array-length ] [ heap-size ] bi* * ;
2007-09-20 18:09:08 -04:00
M: array c-type-align first c-type-align ;
2007-09-20 18:09:08 -04:00
2009-11-10 20:34:14 -05:00
M: array c-type-align-first first c-type-align-first ;
2007-09-20 18:09:08 -04:00
M: array c-type-stack-align? drop f ;
2009-09-15 16:18:54 -04:00
M: array unbox-parameter drop void* unbox-parameter ;
2007-09-20 18:09:08 -04:00
2009-09-15 16:18:54 -04:00
M: array unbox-return drop void* unbox-return ;
2007-09-20 18:09:08 -04:00
2009-09-15 16:18:54 -04:00
M: array box-parameter drop void* box-parameter ;
2007-09-20 18:09:08 -04:00
2009-09-15 16:18:54 -04:00
M: array box-return drop void* box-return ;
2007-09-20 18:09:08 -04:00
2009-09-15 16:18:54 -04:00
M: array stack-size drop void* stack-size ;
2007-09-20 18:09:08 -04:00
2009-08-25 22:36:25 -04:00
M: array c-type-boxer-quot
unclip
[ array-length ]
[ [ require-c-array ] keep ] bi*
2009-08-30 20:05:29 -04:00
[ <c-direct-array> ] 2curry ;
2007-09-20 18:09:08 -04:00
M: array c-type-unboxer-quot drop [ >c-ptr ] ;
2008-04-20 06:15:46 -04:00
PREDICATE: string-type < pair
2009-09-15 16:18:54 -04:00
first2 [ char* = ] [ word? ] bi* and ;
M: string-type c-type ;
M: string-type c-type-class drop object ;
M: string-type c-type-boxed-class drop object ;
M: string-type heap-size
2009-09-15 16:18:54 -04:00
drop void* heap-size ;
M: string-type c-type-align
2009-09-15 16:18:54 -04:00
drop void* c-type-align ;
2009-11-10 20:34:14 -05:00
M: string-type c-type-align-first
drop void* c-type-align-first ;
M: string-type c-type-stack-align?
2009-09-15 16:18:54 -04:00
drop void* c-type-stack-align? ;
M: string-type unbox-parameter
2009-09-15 16:18:54 -04:00
drop void* unbox-parameter ;
M: string-type unbox-return
2009-09-15 16:18:54 -04:00
drop void* unbox-return ;
M: string-type box-parameter
2009-09-15 16:18:54 -04:00
drop void* box-parameter ;
M: string-type box-return
2009-09-15 16:18:54 -04:00
drop void* box-return ;
M: string-type stack-size
2009-09-15 16:18:54 -04:00
drop void* stack-size ;
M: string-type c-type-rep
drop int-rep ;
M: string-type c-type-boxer
2009-09-15 16:18:54 -04:00
drop void* c-type-boxer ;
M: string-type c-type-unboxer
2009-09-15 16:18:54 -04:00
drop void* c-type-unboxer ;
M: string-type c-type-boxer-quot
second dup binary =
[ drop void* c-type-boxer-quot ]
[ '[ _ alien>string ] ] if ;
M: string-type c-type-unboxer-quot
second dup binary =
[ drop void* c-type-unboxer-quot ]
[ '[ _ string>alien ] ] if ;
M: string-type c-type-getter
drop [ alien-cell ] ;
M: string-type c-type-setter
drop [ set-alien-cell ] ;
{ char* utf8 } char <pointer> typedef
{ char* utf8 } uchar <pointer> typedef
{ char* binary } byte <pointer> typedef
{ char* binary } ubyte <pointer> typedef