]> gitweb.factorcode.org Git - factor.git/blob - basis/specialized-vectors/specialized-vectors.factor
Merge branch 'new_gc' of git://factorcode.org/git/factor into new_gc
[factor.git] / basis / specialized-vectors / specialized-vectors.factor
1 ! Copyright (C) 2008, 2009 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.parser assocs
4 compiler.units functors growable kernel lexer namespaces parser
5 prettyprint.custom sequences specialized-arrays
6 specialized-arrays.private strings vocabs vocabs.parser
7 vocabs.generated fry make ;
8 QUALIFIED: vectors.functor
9 IN: specialized-vectors
10
11 <PRIVATE
12
13 FUNCTOR: define-vector ( T -- )
14
15 V   DEFINES-CLASS ${T}-vector
16
17 A   IS      ${T}-array
18 S   IS      ${T}-sequence
19 <A> IS      <${A}>
20
21 >V  DEFERS >${V}
22 V{  DEFINES ${V}{
23
24 WHERE
25
26 V A <A> vectors.functor:define-vector
27
28 M: V contract 2drop ;
29
30 M: V byte-length underlying>> byte-length ;
31
32 M: V pprint-delims drop \ V{ \ } ;
33
34 M: V >pprint-sequence ;
35
36 M: V pprint* pprint-object ;
37
38 SYNTAX: V{ \ } [ >V ] parse-literal ;
39
40 INSTANCE: V growable
41 INSTANCE: V S
42
43 ;FUNCTOR
44
45 : specialized-vector-vocab ( c-type -- vocab )
46     [
47         "specialized-vectors.instances." %
48         [ vocabulary>> % "." % ]
49         [ name>> % ]
50         bi
51     ] "" make ;
52
53 PRIVATE>
54
55 : define-vector-vocab ( type -- vocab )
56     underlying-type
57     [ specialized-vector-vocab ] [ '[ _ define-vector ] ] bi
58     generate-vocab ;
59
60 SYNTAX: SPECIALIZED-VECTORS:
61     ";" parse-tokens [
62         parse-c-type
63         [ define-array-vocab use-vocab ]
64         [ define-vector-vocab use-vocab ] bi
65     ] each ;
66
67 SYNTAX: SPECIALIZED-VECTOR:
68     scan-c-type
69     [ define-array-vocab use-vocab ]
70     [ define-vector-vocab use-vocab ] bi ;