specialized-arrays, specialized-vectors: fix potential problem if two vocabularies define different C types with the same name
parent
191e3cf2fb
commit
102af9badb
|
@ -6,8 +6,8 @@ images.loader images.normalization io io.binary
|
||||||
io.encodings.binary io.encodings.string io.files
|
io.encodings.binary io.encodings.string io.files
|
||||||
io.streams.limited kernel locals macros math math.bitwise
|
io.streams.limited kernel locals macros math math.bitwise
|
||||||
math.functions namespaces sequences specialized-arrays
|
math.functions namespaces sequences specialized-arrays
|
||||||
specialized-arrays.instances.uint
|
strings summary ;
|
||||||
specialized-arrays.instances.ushort strings summary ;
|
SPECIALIZED-ARRAYS: uint ushort ;
|
||||||
IN: images.bitmap
|
IN: images.bitmap
|
||||||
|
|
||||||
SINGLETON: bmp-image
|
SINGLETON: bmp-image
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
USING: alien.c-types alien.data compiler.tree.debugger
|
USING: alien.c-types alien.data compiler.tree.debugger
|
||||||
continuations io.directories io.encodings.ascii io.files
|
continuations io.directories io.encodings.ascii io.files
|
||||||
io.files.temp io.mmap kernel math sequences sequences.private
|
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
|
IN: io.mmap.tests
|
||||||
|
|
||||||
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
|
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
|
||||||
|
|
|
@ -86,7 +86,7 @@ ARTICLE: "specialized-array-examples" "Specialized array examples"
|
||||||
ARTICLE: "specialized-arrays" "Specialized arrays"
|
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."
|
"The " { $vocab-link "specialized-arrays" } " vocabulary implements fixed-length sequence types for storing machine values in a space-efficient manner without boxing."
|
||||||
$nl
|
$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
|
{ $subsections
|
||||||
POSTPONE: SPECIALIZED-ARRAY:
|
POSTPONE: SPECIALIZED-ARRAY:
|
||||||
POSTPONE: SPECIALIZED-ARRAYS:
|
POSTPONE: SPECIALIZED-ARRAYS:
|
||||||
|
|
|
@ -4,7 +4,7 @@ specialized-arrays.private sequences alien.c-types accessors
|
||||||
kernel arrays combinators compiler compiler.units classes.struct
|
kernel arrays combinators compiler compiler.units classes.struct
|
||||||
combinators.smart compiler.tree.debugger math libc destructors
|
combinators.smart compiler.tree.debugger math libc destructors
|
||||||
sequences.private multiline eval words vocabs namespaces
|
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 ;
|
FROM: alien.c-types => float ;
|
||||||
|
|
||||||
SPECIALIZED-ARRAY: int
|
SPECIALIZED-ARRAY: int
|
||||||
|
@ -120,9 +120,10 @@ SPECIALIZED-ARRAY: fixed-string
|
||||||
[ "int-array@ f 100" ] [ f 100 <direct-int-array> unparse ] unit-test
|
[ "int-array@ f 100" ] [ f 100 <direct-int-array> unparse ] unit-test
|
||||||
|
|
||||||
! If the C type doesn't exist, don't generate a vocab
|
! 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__ specialized-array-vocab forget-vocab ] with-compilation-unit
|
||||||
"__does_not_exist__" c-types get delete-at
|
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[
|
[
|
||||||
|
@ -146,6 +147,8 @@ SPECIALIZED-ARRAY: __does_not_exist__
|
||||||
|
|
||||||
[ f ] [
|
[ f ] [
|
||||||
"__does_not_exist__-array{"
|
"__does_not_exist__-array{"
|
||||||
"__does_not_exist__" specialized-array-vocab lookup
|
__does_not_exist__ specialized-array-vocab lookup
|
||||||
deferred?
|
deferred?
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
[ \ __does_not_exist__ forget ] with-compilation-unit
|
||||||
|
|
|
@ -6,7 +6,7 @@ libc math math.vectors math.vectors.private
|
||||||
math.vectors.specialization namespaces
|
math.vectors.specialization namespaces
|
||||||
parser prettyprint.custom sequences sequences.private strings
|
parser prettyprint.custom sequences sequences.private strings
|
||||||
summary vocabs vocabs.loader vocabs.parser vocabs.generated
|
summary vocabs vocabs.loader vocabs.parser vocabs.generated
|
||||||
words fry combinators present ;
|
words fry combinators make ;
|
||||||
IN: specialized-arrays
|
IN: specialized-arrays
|
||||||
|
|
||||||
MIXIN: specialized-array
|
MIXIN: specialized-array
|
||||||
|
@ -125,11 +125,13 @@ M: word (underlying-type) "c-type" word-prop ;
|
||||||
[ drop ]
|
[ drop ]
|
||||||
} cond ;
|
} cond ;
|
||||||
|
|
||||||
: underlying-type-name ( c-type -- name )
|
|
||||||
underlying-type present ;
|
|
||||||
|
|
||||||
: specialized-array-vocab ( c-type -- vocab )
|
: specialized-array-vocab ( c-type -- vocab )
|
||||||
present "specialized-arrays.instances." prepend ;
|
[
|
||||||
|
"specialized-arrays.instances." %
|
||||||
|
[ vocabulary>> % "." % ]
|
||||||
|
[ name>> % ]
|
||||||
|
bi
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -143,18 +145,18 @@ M: c-type-name require-c-array define-array-vocab drop ;
|
||||||
ERROR: specialized-array-vocab-not-loaded c-type ;
|
ERROR: specialized-array-vocab-not-loaded c-type ;
|
||||||
|
|
||||||
M: c-type-name c-array-constructor
|
M: c-type-name c-array-constructor
|
||||||
underlying-type-name
|
underlying-type
|
||||||
dup [ "<" "-array>" surround ] [ specialized-array-vocab ] bi lookup
|
dup [ name>> "<" "-array>" surround ] [ specialized-array-vocab ] bi lookup
|
||||||
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
|
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
|
||||||
|
|
||||||
M: c-type-name c-(array)-constructor
|
M: c-type-name c-(array)-constructor
|
||||||
underlying-type-name
|
underlying-type
|
||||||
dup [ "(" "-array)" surround ] [ specialized-array-vocab ] bi lookup
|
dup [ name>> "(" "-array)" surround ] [ specialized-array-vocab ] bi lookup
|
||||||
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
|
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
|
||||||
|
|
||||||
M: c-type-name c-direct-array-constructor
|
M: c-type-name c-direct-array-constructor
|
||||||
underlying-type-name
|
underlying-type
|
||||||
dup [ "<direct-" "-array>" surround ] [ specialized-array-vocab ] bi lookup
|
dup [ name>> "<direct-" "-array>" surround ] [ specialized-array-vocab ] bi lookup
|
||||||
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
|
[ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable
|
||||||
|
|
||||||
SYNTAX: SPECIALIZED-ARRAYS:
|
SYNTAX: SPECIALIZED-ARRAYS:
|
||||||
|
|
|
@ -6,6 +6,13 @@ HELP: SPECIALIZED-VECTOR:
|
||||||
{ $values { "type" "a C type" } }
|
{ $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" } "." } ;
|
{ $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"
|
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:"
|
"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
|
{ $table
|
||||||
|
@ -21,6 +28,12 @@ ARTICLE: "specialized-vector-c" "Passing specialized vectors to C functions"
|
||||||
|
|
||||||
ARTICLE: "specialized-vectors" "Specialized vectors"
|
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."
|
"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
|
{ $subsections
|
||||||
"specialized-vector-words"
|
"specialized-vector-words"
|
||||||
"specialized-vector-c"
|
"specialized-vector-c"
|
||||||
|
|
|
@ -2,8 +2,7 @@ IN: specialized-vectors.tests
|
||||||
USING: specialized-arrays specialized-vectors
|
USING: specialized-arrays specialized-vectors
|
||||||
tools.test kernel sequences alien.c-types ;
|
tools.test kernel sequences alien.c-types ;
|
||||||
SPECIALIZED-ARRAY: float
|
SPECIALIZED-ARRAY: float
|
||||||
SPECIALIZED-VECTOR: float
|
SPECIALIZED-VECTORS: float double ;
|
||||||
SPECIALIZED-VECTOR: double
|
|
||||||
|
|
||||||
[ 3 ] [ double-vector{ 1 2 } 3 over push length ] unit-test
|
[ 3 ] [ double-vector{ 1 2 } 3 over push length ] unit-test
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
! Copyright (C) 2008, 2009 Slava Pestov.
|
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types assocs compiler.units functors
|
USING: accessors alien.c-types alien.parser assocs
|
||||||
growable kernel lexer namespaces parser prettyprint.custom
|
compiler.units functors growable kernel lexer namespaces parser
|
||||||
sequences specialized-arrays specialized-arrays.private strings
|
prettyprint.custom sequences specialized-arrays
|
||||||
vocabs vocabs.parser vocabs.generated fry ;
|
specialized-arrays.private strings vocabs vocabs.parser
|
||||||
|
vocabs.generated fry make ;
|
||||||
QUALIFIED: vectors.functor
|
QUALIFIED: vectors.functor
|
||||||
IN: specialized-vectors
|
IN: specialized-vectors
|
||||||
|
|
||||||
|
@ -41,8 +42,13 @@ INSTANCE: V S
|
||||||
|
|
||||||
;FUNCTOR
|
;FUNCTOR
|
||||||
|
|
||||||
: specialized-vector-vocab ( type -- vocab )
|
: specialized-vector-vocab ( c-type -- vocab )
|
||||||
"specialized-vectors.instances." prepend ;
|
[
|
||||||
|
"specialized-vectors.instances." %
|
||||||
|
[ vocabulary>> % "." % ]
|
||||||
|
[ name>> % ]
|
||||||
|
bi
|
||||||
|
] "" make ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
@ -51,7 +57,14 @@ PRIVATE>
|
||||||
[ specialized-vector-vocab ] [ '[ _ define-vector ] ] bi
|
[ specialized-vector-vocab ] [ '[ _ define-vector ] ] bi
|
||||||
generate-vocab ;
|
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:
|
SYNTAX: SPECIALIZED-VECTOR:
|
||||||
scan
|
scan-c-type
|
||||||
[ define-array-vocab use-vocab ]
|
[ define-array-vocab use-vocab ]
|
||||||
[ define-vector-vocab use-vocab ] bi ;
|
[ define-vector-vocab use-vocab ] bi ;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien.c-types arrays kernel random random.cmwc sequences
|
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
|
IN: random.cmwc.tests
|
||||||
|
|
||||||
[ ] [
|
[ ] [
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors alien.c-types arrays fry kernel locals math
|
USING: accessors alien.c-types arrays fry kernel locals math
|
||||||
math.bitwise random sequences sequences.private
|
math.bitwise random sequences sequences.private
|
||||||
specialized-arrays specialized-arrays.instances.uint ;
|
specialized-arrays ;
|
||||||
|
SPECIALIZED-ARRAY: uint
|
||||||
IN: random.cmwc
|
IN: random.cmwc
|
||||||
|
|
||||||
! Multiply-with-carry RNG
|
! Multiply-with-carry RNG
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
! Copyright (C) 2009 Doug Coleman.
|
! Copyright (C) 2009 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: fry kernel math.functions random random.lagged-fibonacci
|
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
|
IN: random.lagged-fibonacci.tests
|
||||||
|
|
||||||
[ t ] [
|
[ t ] [
|
||||||
|
|
Loading…
Reference in New Issue