]> gitweb.factorcode.org Git - factor.git/blob - basis/alien/arrays/arrays.factor
use a "pointer" wrapper tuple to indicate pointer types instead of the current slipsh...
[factor.git] / basis / alien / arrays / arrays.factor
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.utf8 accessors ;
6 IN: alien.arrays
7
8 INSTANCE: array value-type
9
10 M: array c-type ;
11
12 M: array c-type-class drop object ;
13
14 M: array c-type-boxed-class drop object ;
15
16 : array-length ( seq -- n )
17     [ dup word? [ def>> call( -- object ) ] when ] [ * ] map-reduce ;
18
19 M: array heap-size unclip [ array-length ] [ heap-size ] bi* * ;
20
21 M: array c-type-align first c-type-align ;
22
23 M: array c-type-align-first first c-type-align-first ;
24
25 M: array c-type-stack-align? drop f ;
26
27 M: array unbox-parameter drop void* unbox-parameter ;
28
29 M: array unbox-return drop void* unbox-return ;
30
31 M: array box-parameter drop void* box-parameter ;
32
33 M: array box-return drop void* box-return ;
34
35 M: array stack-size drop void* stack-size ;
36
37 M: array c-type-boxer-quot
38     unclip
39     [ array-length ]
40     [ [ require-c-array ] keep ] bi*
41     [ <c-direct-array> ] 2curry ;
42
43 M: array c-type-unboxer-quot drop [ >c-ptr ] ;
44
45 PREDICATE: string-type < pair
46     first2 [ char* = ] [ word? ] bi* and ;
47
48 M: string-type c-type ;
49
50 M: string-type c-type-class drop object ;
51
52 M: string-type c-type-boxed-class drop object ;
53
54 M: string-type heap-size
55     drop void* heap-size ;
56
57 M: string-type c-type-align
58     drop void* c-type-align ;
59
60 M: string-type c-type-align-first
61     drop void* c-type-align-first ;
62
63 M: string-type c-type-stack-align?
64     drop void* c-type-stack-align? ;
65
66 M: string-type unbox-parameter
67     drop void* unbox-parameter ;
68
69 M: string-type unbox-return
70     drop void* unbox-return ;
71
72 M: string-type box-parameter
73     drop void* box-parameter ;
74
75 M: string-type box-return
76     drop void* box-return ;
77
78 M: string-type stack-size
79     drop void* stack-size ;
80
81 M: string-type c-type-rep
82     drop int-rep ;
83
84 M: string-type c-type-boxer
85     drop void* c-type-boxer ;
86
87 M: string-type c-type-unboxer
88     drop void* c-type-unboxer ;
89
90 M: string-type c-type-boxer-quot
91     second '[ _ alien>string ] ;
92
93 M: string-type c-type-unboxer-quot
94     second '[ _ string>alien ] ;
95
96 M: string-type c-type-getter
97     drop [ alien-cell ] ;
98
99 M: string-type c-type-setter
100     drop [ set-alien-cell ] ;
101
102 TYPEDEF: { char* utf8 } char*
103