1 ! Copyright (C) 2008, 2010 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.parser assocs
4 compiler.units functors growable kernel lexer math namespaces
5 parser prettyprint.custom sequences specialized-arrays
6 specialized-arrays.private strings vocabs vocabs.parser
7 vocabs.generated fry make ;
8 FROM: sequences.private => nth-unsafe ;
9 QUALIFIED: vectors.functor
10 IN: specialized-vectors
14 FUNCTOR: define-vector ( T -- )
16 V DEFINES-CLASS ${T}-vector
26 V A <A> vectors.functor:define-vector
28 M: V contract 2drop ; inline
30 M: V element-size drop \ T heap-size ; inline
32 M: V pprint-delims drop \ V{ \ } ;
34 M: V >pprint-sequence ;
36 M: V pprint* pprint-object ;
38 M: V >c-ptr underlying>> underlying>> ; inline
39 M: V byte-length [ length ] [ element-size ] bi * ; inline
41 SYNTAX: V{ \ } [ >V ] parse-literal ;
47 : specialized-vector-vocab ( c-type -- vocab )
49 "specialized-vectors.instances." %
50 [ vocabulary>> % "." % ]
57 : push-new ( vector -- new )
58 [ length ] keep ensure nth-unsafe ; inline
60 : define-vector-vocab ( type -- vocab )
62 [ specialized-vector-vocab ] [ '[ _ define-vector ] ] bi
65 SYNTAX: SPECIALIZED-VECTORS:
68 [ define-array-vocab use-vocab ]
69 [ define-vector-vocab use-vocab ] bi
72 SYNTAX: SPECIALIZED-VECTOR:
74 [ define-array-vocab use-vocab ]
75 [ define-vector-vocab use-vocab ] bi ;