]> gitweb.factorcode.org Git - factor.git/commitdiff
specialized-arrays, specialized-vectors: fix potential problem if two vocabularies...
authorSlava Pestov <slava@shill.local>
Mon, 19 Oct 2009 09:41:53 +0000 (04:41 -0500)
committerSlava Pestov <slava@shill.local>
Mon, 19 Oct 2009 09:41:53 +0000 (04:41 -0500)
basis/images/bitmap/bitmap.factor
basis/io/mmap/mmap-tests.factor
basis/specialized-arrays/specialized-arrays-docs.factor
basis/specialized-arrays/specialized-arrays-tests.factor
basis/specialized-arrays/specialized-arrays.factor
basis/specialized-vectors/specialized-vectors-docs.factor
basis/specialized-vectors/specialized-vectors-tests.factor
basis/specialized-vectors/specialized-vectors.factor
extra/random/cmwc/cmwc-tests.factor
extra/random/cmwc/cmwc.factor
extra/random/lagged-fibonacci/lagged-fibonacci-tests.factor

index f14dd3290c81f6c3b5ac7538aafe598bb59f9058..fa12aaa3204729f86c1273ed7ee4715a647b3a84 100755 (executable)
@@ -6,8 +6,8 @@ images.loader images.normalization io io.binary
 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
index 94f8c778835142831ca130adaf85c3b4b8b2159e..967009243e24cd1d66f629f870f2f84cfe28cc9a 100644 (file)
@@ -1,7 +1,8 @@
 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
index 50e94b65e9a3a675731f6d3fc5eb03b179c57229..68ce02e71e7f345b91fc5265bb3d7e42ba812ba2 100755 (executable)
@@ -86,7 +86,7 @@ ARTICLE: "specialized-array-examples" "Specialized array examples"
 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:
index 1ee877608537ae50118019add491c4767d70d116..3226557494c2ce01b0567cc9efceae58a4ec20b4 100755 (executable)
@@ -4,7 +4,7 @@ specialized-arrays.private sequences alien.c-types accessors
 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
@@ -120,9 +120,10 @@ SPECIALIZED-ARRAY: fixed-string
 [ "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
 
 [
@@ -146,6 +147,8 @@ SPECIALIZED-ARRAY: __does_not_exist__
 
 [ 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
index c5de95b5b51b1ab09fdbcc49f550ec1fc8db2954..67c58987a1ecf6f6324510b22fb6b185aa670985 100755 (executable)
@@ -6,7 +6,7 @@ libc math math.vectors math.vectors.private
 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
@@ -125,11 +125,13 @@ M: word (underlying-type) "c-type" word-prop ;
         [ 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>
 
@@ -143,18 +145,18 @@ M: c-type-name require-c-array define-array-vocab drop ;
 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:
index 6b53885e1361547c4d107056ac3fba86bd913b35..e54f26ac57de6fd3d342fade449ecb7dd74f972c 100644 (file)
@@ -6,6 +6,13 @@ HELP: SPECIALIZED-VECTOR:
 { $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
@@ -21,6 +28,12 @@ ARTICLE: "specialized-vector-c" "Passing specialized vectors to C functions"
 
 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"
index c7a045a7e1ed98f80a1756f6a8159317ee26e97a..1519ad415eb0afc0b6b15b9a938f1aee7ed79502 100644 (file)
@@ -2,8 +2,7 @@ IN: specialized-vectors.tests
 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
 
index 7cda026cb307ecaa00fd03d8f50f815f20f450f4..75197d9ec0dc012d8177be238d2733b65358af67 100644 (file)
@@ -1,9 +1,10 @@
 ! 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
 
@@ -41,8 +42,13 @@ INSTANCE: V S
 
 ;FUNCTOR
 
-: specialized-vector-vocab ( type -- vocab )
-    "specialized-vectors.instances." prepend ;
+: specialized-vector-vocab ( c-type -- vocab )
+    [
+        "specialized-vectors.instances." %
+        [ vocabulary>> % "." % ]
+        [ name>> % ]
+        bi
+    ] "" make ;
 
 PRIVATE>
 
@@ -51,7 +57,14 @@ 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 ;
index 8dc9f8764f6838db85321f28698eca42ab6ea319..d5e1fe685842016e73e9943c3d11559506191a9a 100644 (file)
@@ -1,7 +1,8 @@
 ! 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
 
 [ ] [
index 941840f23ad9e7a1e0f74cd5dcf2cc6c1e238937..3fda392d805ab4ee2ab5a23eec0f24d2984d4edd 100644 (file)
@@ -2,7 +2,8 @@
 ! 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
index e830c466c2b9090b0783ac020d165711864317f0..df90d4d40fe2b3566a69dadd6850f2b150530827 100644 (file)
@@ -1,7 +1,8 @@
 ! 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 ] [