io.encodings.binary io.encodings.string io.files
io.streams.limited kernel locals macros math math.bitwise
math.functions namespaces sequences specialized-arrays
-specialized-arrays.instances.uint
-specialized-arrays.instances.ushort strings summary ;
+strings summary ;
+SPECIALIZED-ARRAYS: uint ushort ;
IN: images.bitmap
SINGLETON: bmp-image
USING: alien.c-types alien.data compiler.tree.debugger
continuations io.directories io.encodings.ascii io.files
io.files.temp io.mmap kernel math sequences sequences.private
-specialized-arrays specialized-arrays.instances.uint tools.test ;
+specialized-arrays tools.test ;
+SPECIALIZED-ARRAY: uint
IN: io.mmap.tests
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
ARTICLE: "specialized-arrays" "Specialized arrays"
"The " { $vocab-link "specialized-arrays" } " vocabulary implements fixed-length sequence types for storing machine values in a space-efficient manner without boxing."
$nl
-"A specialized array type needs to be generated for each element type. This is done with a parsing word:"
+"A specialized array type needs to be generated for each element type. This is done with parsing words:"
{ $subsections
POSTPONE: SPECIALIZED-ARRAY:
POSTPONE: SPECIALIZED-ARRAYS:
kernel arrays combinators compiler compiler.units classes.struct
combinators.smart compiler.tree.debugger math libc destructors
sequences.private multiline eval words vocabs namespaces
-assocs prettyprint alien.data math.vectors ;
+assocs prettyprint alien.data math.vectors definitions ;
FROM: alien.c-types => float ;
SPECIALIZED-ARRAY: int
[ "int-array@ f 100" ] [ f 100 <direct-int-array> unparse ] unit-test
! If the C type doesn't exist, don't generate a vocab
+SYMBOL: __does_not_exist__
+
[ ] [
- [ "__does_not_exist__" specialized-array-vocab forget-vocab ] with-compilation-unit
- "__does_not_exist__" c-types get delete-at
+ [ __does_not_exist__ specialized-array-vocab forget-vocab ] with-compilation-unit
] unit-test
[
[ f ] [
"__does_not_exist__-array{"
- "__does_not_exist__" specialized-array-vocab lookup
+ __does_not_exist__ specialized-array-vocab lookup
deferred?
] unit-test
+
+[ \ __does_not_exist__ forget ] with-compilation-unit
math.vectors.specialization namespaces
parser prettyprint.custom sequences sequences.private strings
summary vocabs vocabs.loader vocabs.parser vocabs.generated
-words fry combinators present ;
+words fry combinators make ;
IN: specialized-arrays
MIXIN: specialized-array
[ drop ]
} cond ;
-: underlying-type-name ( c-type -- name )
- underlying-type present ;
-
: specialized-array-vocab ( c-type -- vocab )
- present "specialized-arrays.instances." prepend ;
+ [
+ "specialized-arrays.instances." %
+ [ vocabulary>> % "." % ]
+ [ name>> % ]
+ bi
+ ] "" make ;
PRIVATE>
ERROR: specialized-array-vocab-not-loaded c-type ;
M: c-type-name c-array-constructor
- underlying-type-name
- dup [ "<" "-array>" surround ] [ specialized-array-vocab ] bi lookup
+ underlying-type
+ dup [ name>> "<" "-array>" surround ] [ specialized-array-vocab ] bi lookup
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
M: c-type-name c-(array)-constructor
- underlying-type-name
- dup [ "(" "-array)" surround ] [ specialized-array-vocab ] bi lookup
+ underlying-type
+ dup [ name>> "(" "-array)" surround ] [ specialized-array-vocab ] bi lookup
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
M: c-type-name c-direct-array-constructor
- underlying-type-name
- dup [ "<direct-" "-array>" surround ] [ specialized-array-vocab ] bi lookup
+ underlying-type
+ dup [ name>> "<direct-" "-array>" surround ] [ specialized-array-vocab ] bi lookup
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
SYNTAX: SPECIALIZED-ARRAYS:
{ $values { "type" "a C type" } }
{ $description "Brings a specialized vector for holding values of " { $snippet "type" } " into the vocabulary search path. The generated words are documented in " { $link "specialized-vector-words" } "." } ;
+HELP: SPECIALIZED-VECTORS:
+{ $syntax "SPECIALIZED-VECTORS: type type type ... ;" }
+{ $values { "type" "a C type" } }
+{ $description "Brings a set of specialized vectors for holding values of each " { $snippet "type" } " into the vocabulary search path. The generated words are documented in " { $link "specialized-vector-words" } "." } ;
+
+{ POSTPONE: SPECIALIZED-VECTOR: POSTPONE: SPECIALIZED-VECTORS: } related-words
+
ARTICLE: "specialized-vector-words" "Specialized vector words"
"The " { $link POSTPONE: SPECIALIZED-VECTOR: } " parsing word generates the specialized vector type if it hasn't been generated already, and adds the following words to the vocabulary search path, where " { $snippet "T" } " is the C type in question:"
{ $table
ARTICLE: "specialized-vectors" "Specialized vectors"
"The " { $vocab-link "specialized-vectors" } " vocabulary implements resizable sequence types for storing machine values in a space-efficient manner without boxing."
+$nl
+"A specialized vector type needs to be generated for each element type. This is done with parsing words:"
+{ $subsections
+ POSTPONE: SPECIALIZED-VECTOR:
+ POSTPONE: SPECIALIZED-VECTORS:
+}
{ $subsections
"specialized-vector-words"
"specialized-vector-c"
USING: specialized-arrays specialized-vectors
tools.test kernel sequences alien.c-types ;
SPECIALIZED-ARRAY: float
-SPECIALIZED-VECTOR: float
-SPECIALIZED-VECTOR: double
+SPECIALIZED-VECTORS: float double ;
[ 3 ] [ double-vector{ 1 2 } 3 over push length ] unit-test
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types assocs compiler.units functors
-growable kernel lexer namespaces parser prettyprint.custom
-sequences specialized-arrays specialized-arrays.private strings
-vocabs vocabs.parser vocabs.generated fry ;
+USING: accessors alien.c-types alien.parser assocs
+compiler.units functors growable kernel lexer namespaces parser
+prettyprint.custom sequences specialized-arrays
+specialized-arrays.private strings vocabs vocabs.parser
+vocabs.generated fry make ;
QUALIFIED: vectors.functor
IN: specialized-vectors
;FUNCTOR
-: specialized-vector-vocab ( type -- vocab )
- "specialized-vectors.instances." prepend ;
+: specialized-vector-vocab ( c-type -- vocab )
+ [
+ "specialized-vectors.instances." %
+ [ vocabulary>> % "." % ]
+ [ name>> % ]
+ bi
+ ] "" make ;
PRIVATE>
[ 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 ;
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types arrays kernel random random.cmwc sequences
-specialized-arrays specialized-arrays.instances.uint tools.test ;
+specialized-arrays tools.test ;
+SPECIALIZED-ARRAY: uint
IN: random.cmwc.tests
[ ] [
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays fry kernel locals math
math.bitwise random sequences sequences.private
-specialized-arrays specialized-arrays.instances.uint ;
+specialized-arrays ;
+SPECIALIZED-ARRAY: uint
IN: random.cmwc
! Multiply-with-carry RNG
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: fry kernel math.functions random random.lagged-fibonacci
-sequences specialized-arrays.instances.double tools.test ;
+sequences tools.test specialized-arrays alien.c-types ;
+SPECIALIZED-ARRAY: double
IN: random.lagged-fibonacci.tests
[ t ] [