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.accessors
4 arrays words sequences math kernel namespaces fry libc cpu.architecture
5 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-stack-align? drop f ;
25 M: array unbox-parameter drop "void*" unbox-parameter ;
27 M: array unbox-return drop "void*" unbox-return ;
29 M: array box-parameter drop "void*" box-parameter ;
31 M: array box-return drop "void*" box-return ;
33 M: array stack-size drop "void*" stack-size ;
35 M: array c-type-boxer-quot
38 [ [ require-c-array ] keep ] bi*
39 [ <c-direct-array> ] 2curry ;
41 M: array c-type-unboxer-quot drop [ >c-ptr ] ;
43 PREDICATE: string-type < pair
44 first2 [ "char*" = ] [ word? ] bi* and ;
46 M: string-type c-type ;
48 M: string-type c-type-class drop object ;
50 M: string-type c-type-boxed-class drop object ;
52 M: string-type heap-size
53 drop "void*" heap-size ;
55 M: string-type c-type-align
56 drop "void*" c-type-align ;
58 M: string-type c-type-stack-align?
59 drop "void*" c-type-stack-align? ;
61 M: string-type unbox-parameter
62 drop "void*" unbox-parameter ;
64 M: string-type unbox-return
65 drop "void*" unbox-return ;
67 M: string-type box-parameter
68 drop "void*" box-parameter ;
70 M: string-type box-return
71 drop "void*" box-return ;
73 M: string-type stack-size
74 drop "void*" stack-size ;
76 M: string-type c-type-rep
79 M: string-type c-type-boxer
80 drop "void*" c-type-boxer ;
82 M: string-type c-type-unboxer
83 drop "void*" c-type-unboxer ;
85 M: string-type c-type-boxer-quot
86 second '[ _ alien>string ] ;
88 M: string-type c-type-unboxer-quot
89 second '[ _ string>alien ] ;
91 M: string-type c-type-getter
94 M: string-type c-type-setter
95 drop [ set-alien-cell ] ;
97 { "char*" utf8 } "char*" typedef
98 "char*" "uchar*" typedef