1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.strings alien.c-types alien.data alien.accessors
4 arrays words sequences math kernel namespaces fry cpu.architecture
5 io.encodings.binary io.encodings.utf8 accessors ;
8 INSTANCE: array value-type
12 M: array c-type-class drop object ;
14 M: array c-type-boxed-class drop object ;
16 : array-length ( seq -- n )
17 [ dup word? [ def>> call( -- object ) ] when ] [ * ] map-reduce ;
19 M: array heap-size unclip [ array-length ] [ heap-size ] bi* * ;
21 M: array c-type-align first c-type-align ;
23 M: array c-type-align-first first c-type-align-first ;
25 M: array c-type-stack-align? drop f ;
27 M: array unbox-parameter drop void* unbox-parameter ;
29 M: array unbox-return drop void* unbox-return ;
31 M: array box-parameter drop void* box-parameter ;
33 M: array box-return drop void* box-return ;
35 M: array stack-size drop void* stack-size ;
37 M: array c-type-boxer-quot
38 unclip [ array-length ] dip [ <c-direct-array> ] 2curry ;
40 M: array c-type-unboxer-quot drop [ >c-ptr ] ;
42 PREDICATE: string-type < pair
43 first2 [ char* = ] [ word? ] bi* and ;
45 M: string-type c-type ;
47 M: string-type c-type-class drop object ;
49 M: string-type c-type-boxed-class drop object ;
51 M: string-type heap-size
52 drop void* heap-size ;
54 M: string-type c-type-align
55 drop void* c-type-align ;
57 M: string-type c-type-align-first
58 drop void* c-type-align-first ;
60 M: string-type c-type-stack-align?
61 drop void* c-type-stack-align? ;
63 M: string-type unbox-parameter
64 drop void* unbox-parameter ;
66 M: string-type unbox-return
67 drop void* unbox-return ;
69 M: string-type box-parameter
70 drop void* box-parameter ;
72 M: string-type box-return
73 drop void* box-return ;
75 M: string-type stack-size
76 drop void* stack-size ;
78 M: string-type c-type-rep
81 M: string-type c-type-boxer
82 drop void* c-type-boxer ;
84 M: string-type c-type-unboxer
85 drop void* c-type-unboxer ;
87 M: string-type c-type-boxer-quot
89 [ drop void* c-type-boxer-quot ]
90 [ '[ _ alien>string ] ] if ;
92 M: string-type c-type-unboxer-quot
94 [ drop void* c-type-unboxer-quot ]
95 [ '[ _ string>alien ] ] if ;
97 M: string-type c-type-getter
100 M: string-type c-type-setter
101 drop [ set-alien-cell ] ;
103 { char* utf8 } char <pointer> typedef
104 { char* utf8 } char* typedef
105 { char* utf8 } uchar <pointer> typedef
106 { char* binary } byte <pointer> typedef
107 { char* binary } ubyte <pointer> typedef