2009-05-02 14:45:38 -04:00
|
|
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
2007-09-20 18:09:08 -04:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2009-09-17 23:07:21 -04:00
|
|
|
USING: alien alien.strings alien.c-types alien.data alien.accessors
|
|
|
|
arrays words sequences math kernel namespaces fry cpu.architecture
|
2010-02-21 22:23:47 -05:00
|
|
|
io.encodings.binary io.encodings.utf8 accessors ;
|
2007-09-20 18:09:08 -04:00
|
|
|
IN: alien.arrays
|
|
|
|
|
2009-09-15 18:38:49 -04:00
|
|
|
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 ;
|
|
|
|
|
2009-08-10 17:17:33 -04:00
|
|
|
M: array c-type-boxed-class drop object ;
|
|
|
|
|
2009-08-27 22:49:25 -04:00
|
|
|
: 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
|
|
|
|
2008-08-31 08:45:33 -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
|
2010-02-22 15:21:29 -05:00
|
|
|
unclip [ array-length ] dip [ <c-direct-array> ] 2curry ;
|
2007-09-20 18:09:08 -04:00
|
|
|
|
2009-02-06 05:36:17 -05:00
|
|
|
M: array c-type-unboxer-quot drop [ >c-ptr ] ;
|
2008-04-20 06:15:46 -04:00
|
|
|
|
2009-05-02 14:45:38 -04:00
|
|
|
PREDICATE: string-type < pair
|
2009-09-15 16:18:54 -04:00
|
|
|
first2 [ char* = ] [ word? ] bi* and ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type ;
|
|
|
|
|
2009-08-10 17:17:33 -04:00
|
|
|
M: string-type c-type-class drop object ;
|
|
|
|
|
|
|
|
M: string-type c-type-boxed-class drop object ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type heap-size
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* heap-size ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type-align
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* c-type-align ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
2009-11-10 20:34:14 -05:00
|
|
|
M: string-type c-type-align-first
|
|
|
|
drop void* c-type-align-first ;
|
|
|
|
|
2009-05-02 14:45:38 -04:00
|
|
|
M: string-type c-type-stack-align?
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* c-type-stack-align? ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type unbox-parameter
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* unbox-parameter ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type unbox-return
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* unbox-return ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type box-parameter
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* box-parameter ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type box-return
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* box-return ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type stack-size
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* stack-size ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
2009-08-07 18:44:50 -04:00
|
|
|
M: string-type c-type-rep
|
|
|
|
drop int-rep ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type-boxer
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* c-type-boxer ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type-unboxer
|
2009-09-15 16:18:54 -04:00
|
|
|
drop void* c-type-unboxer ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type-boxer-quot
|
2010-02-21 22:23:47 -05:00
|
|
|
second dup binary =
|
|
|
|
[ drop void* c-type-boxer-quot ]
|
|
|
|
[ '[ _ alien>string ] ] if ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type-unboxer-quot
|
2010-02-21 22:23:47 -05:00
|
|
|
second dup binary =
|
|
|
|
[ drop void* c-type-unboxer-quot ]
|
|
|
|
[ '[ _ string>alien ] ] if ;
|
2009-05-02 14:45:38 -04:00
|
|
|
|
|
|
|
M: string-type c-type-getter
|
|
|
|
drop [ alien-cell ] ;
|
|
|
|
|
|
|
|
M: string-type c-type-setter
|
|
|
|
drop [ set-alien-cell ] ;
|
|
|
|
|
2010-02-21 22:23:47 -05:00
|
|
|
{ char* utf8 } char <pointer> typedef
|
2010-02-22 02:11:59 -05:00
|
|
|
{ char* utf8 } char* typedef
|
2010-02-21 22:23:47 -05:00
|
|
|
{ char* utf8 } uchar <pointer> typedef
|
|
|
|
{ char* binary } byte <pointer> typedef
|
|
|
|
{ char* binary } ubyte <pointer> typedef
|
2009-05-02 14:45:38 -04:00
|
|
|
|