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 alien.structs
4 arrays words sequences math kernel namespaces fry libc cpu.architecture
8 UNION: value-type array struct-type ;
12 M: array c-type-class drop object ;
14 M: array heap-size unclip [ product ] [ heap-size ] bi* * ;
16 M: array c-type-align first c-type-align ;
18 M: array c-type-stack-align? drop f ;
20 M: array unbox-parameter drop "void*" unbox-parameter ;
22 M: array unbox-return drop "void*" unbox-return ;
24 M: array box-parameter drop "void*" box-parameter ;
26 M: array box-return drop "void*" box-return ;
28 M: array stack-size drop "void*" stack-size ;
30 M: array c-type-boxer-quot drop [ ] ;
32 M: array c-type-unboxer-quot drop [ >c-ptr ] ;
34 M: value-type c-type-rep drop int-rep ;
36 M: value-type c-type-getter
37 drop [ swap <displaced-alien> ] ;
39 M: value-type c-type-setter ( type -- quot )
40 [ c-type-getter ] [ c-type-unboxer-quot ] [ heap-size ] tri
41 '[ @ swap @ _ memcpy ] ;
43 PREDICATE: string-type < pair
44 first2 [ "char*" = ] [ word? ] bi* and ;
46 M: string-type c-type ;
48 M: string-type c-type-class
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-stack-align?
58 drop "void*" c-type-stack-align? ;
60 M: string-type unbox-parameter
61 drop "void*" unbox-parameter ;
63 M: string-type unbox-return
64 drop "void*" unbox-return ;
66 M: string-type box-parameter
67 drop "void*" box-parameter ;
69 M: string-type box-return
70 drop "void*" box-return ;
72 M: string-type stack-size
73 drop "void*" stack-size ;
75 M: string-type c-type-rep
78 M: string-type c-type-boxer
79 drop "void*" c-type-boxer ;
81 M: string-type c-type-unboxer
82 drop "void*" c-type-unboxer ;
84 M: string-type c-type-boxer-quot
85 second '[ _ alien>string ] ;
87 M: string-type c-type-unboxer-quot
88 second '[ _ string>alien ] ;
90 M: string-type c-type-getter
93 M: string-type c-type-setter
94 drop [ set-alien-cell ] ;
96 { "char*" utf8 } "char*" typedef
97 "char*" "uchar*" typedef