-! Copyright (C) 2008, 2009 Slava Pestov.
+! Copyright (C) 2008, 2010 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types assocs compiler.units functors
-growable io kernel lexer namespaces parser prettyprint.custom
-sequences specialized-arrays specialized-arrays.private strings
-vocabs vocabs.parser ;
+USING: accessors alien alien.c-types alien.parser assocs
+compiler.units functors growable kernel lexer math namespaces
+parser prettyprint.custom sequences specialized-arrays
+specialized-arrays.private strings vocabs vocabs.parser
+vocabs.generated fry make ;
QUALIFIED: vectors.functor
IN: specialized-vectors
V DEFINES-CLASS ${T}-vector
A IS ${T}-array
-S IS ${T}-sequence
<A> IS <${A}>
>V DEFERS >${V}
V A <A> vectors.functor:define-vector
-M: V contract 2drop ;
+M: V contract 2drop ; inline
-M: V byte-length underlying>> byte-length ;
+M: V element-size drop \ T heap-size ; inline
M: V pprint-delims drop \ V{ \ } ;
SYNTAX: V{ \ } [ >V ] parse-literal ;
INSTANCE: V growable
-INSTANCE: V S
;FUNCTOR
-: specialized-vector-vocab ( type -- vocab )
- "specialized-vectors.instances." prepend ;
-
-: defining-vector-message ( type -- )
- "quiet" get [ drop ] [
- "Generating specialized " " vectors..." surround print
- ] if ;
+: specialized-vector-vocab ( c-type -- vocab )
+ [
+ "specialized-vectors.instances." %
+ [ vocabulary>> % "." % ]
+ [ name>> % ]
+ bi
+ ] "" make ;
PRIVATE>
-: define-vector-vocab ( type -- vocab )
+: define-vector-vocab ( type -- vocab )
underlying-type
- dup specialized-vector-vocab vocab
- [ ] [
- [ defining-vector-message ]
- [
- [
- dup specialized-vector-vocab
- [ define-vector ] with-current-vocab
- ] with-compilation-unit
- ]
- [ specialized-vector-vocab ]
- tri
- ] ?if ;
+ [ specialized-vector-vocab ] [ '[ _ define-vector ] ] bi
+ generate-vocab ;
+
+SYNTAX: SPECIALIZED-VECTORS:
+ ";" parse-tokens [
+ parse-c-type
+ [ define-array-vocab use-vocab ]
+ [ define-vector-vocab use-vocab ] bi
+ ] each ;
SYNTAX: SPECIALIZED-VECTOR:
- scan
+ scan-c-type
[ define-array-vocab use-vocab ]
[ define-vector-vocab use-vocab ] bi ;