From 7f2e2b17771a3d2eaea44b5e116c4a433d061b62 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 9 Sep 2009 22:33:34 -0500 Subject: [PATCH] Specialized array overhaul - Replace hand-written specialized-arrays.* subvocabularies with new system; instead of USE:ing specialized-arrays.T, do SPECIALIZED-ARRAY: T - Ditto for specialized-vectors; use SPECIALIZED-VECTOR: - io.mmap.functor: removed entirely, use instead - struct-arrays and struct-vectors have been removed because specialized arrays and vectors subsume them entirely --- basis/alien/c-types/c-types-docs.factor | 10 +- basis/alien/c-types/c-types.factor | 96 ++------- basis/alien/complex/functor/functor.factor | 1 - basis/alien/structs/structs.factor | 2 +- basis/bootstrap/compiler/timing/tags.txt | 1 + basis/checksums/md5/md5.factor | 3 +- basis/classes/struct/struct-tests.factor | 12 +- basis/classes/struct/struct.factor | 9 +- basis/cocoa/messages/messages.factor | 4 +- basis/compiler/tests/alien.factor | 6 +- .../tree/propagation/propagation-tests.factor | 3 +- .../dictionaries/dictionaries.factor | 4 +- .../core-foundation/fsevents/fsevents.factor | 9 +- basis/db/postgresql/lib/lib.factor | 4 +- basis/game-input/dinput/dinput.factor | 13 +- basis/images/bitmap/bitmap.factor | 6 +- basis/images/bitmap/loading/loading.factor | 3 +- basis/images/tiff/tiff.factor | 3 +- .../unix/multiplexers/epoll/epoll.factor | 9 +- .../unix/multiplexers/kqueue/kqueue.factor | 9 +- .../io/files/info/unix/freebsd/freebsd.factor | 6 +- basis/io/files/info/unix/macosx/macosx.factor | 12 +- basis/io/files/info/unix/netbsd/netbsd.factor | 7 +- .../io/files/info/unix/openbsd/openbsd.factor | 7 +- basis/io/files/info/unix/unix.factor | 8 +- basis/io/files/info/windows/windows.factor | 3 +- basis/io/files/windows/nt/nt.factor | 3 +- basis/io/launcher/windows/windows.factor | 14 +- basis/io/mmap/alien/alien.factor | 4 - basis/io/mmap/bool/bool.factor | 4 - basis/io/mmap/char/char.factor | 4 - basis/io/mmap/double/double.factor | 4 - basis/io/mmap/float/float.factor | 4 - basis/io/mmap/functor/functor.factor | 32 --- basis/io/mmap/int/int.factor | 4 - basis/io/mmap/long/long.factor | 4 - basis/io/mmap/longlong/longlong.factor | 4 - basis/io/mmap/mmap-tests.factor | 8 +- basis/io/mmap/mmap.factor | 7 +- basis/io/mmap/short/short.factor | 4 - basis/io/mmap/uchar/uchar.factor | 4 - basis/io/mmap/uint/uint.factor | 4 - basis/io/mmap/ulong/ulong.factor | 4 - basis/io/mmap/ulonglong/ulonglong.factor | 4 - basis/io/mmap/ushort/ushort.factor | 4 - basis/io/pipes/unix/unix.factor | 5 +- basis/math/blas/matrices/matrices.factor | 9 +- basis/math/blas/vectors/vectors.factor | 7 +- .../vectors/simd/alien/alien-tests.factor | 5 +- .../specialization-tests.factor | 7 +- .../specialization/specialization.factor | 22 ++- basis/opengl/opengl.factor | 4 +- basis/opengl/shaders/shaders.factor | 3 +- basis/opengl/textures/textures.factor | 11 +- .../mersenne-twister/mersenne-twister.factor | 3 +- basis/sequences/complex/complex-docs.factor | 9 +- basis/sequences/complex/complex-tests.factor | 3 +- basis/serialize/serialize-tests.factor | 3 +- basis/specialized-arrays/alien/alien.factor | 4 - basis/specialized-arrays/bool/bool.factor | 4 - basis/specialized-arrays/char/char.factor | 4 - .../complex-double-tests.factor | 13 -- .../complex-double/complex-double.factor | 4 - .../complex-float/complex-float.factor | 4 - basis/specialized-arrays/double/double.factor | 25 --- basis/specialized-arrays/float/float.factor | 4 - .../specialized-arrays/functor/functor.factor | 94 --------- basis/specialized-arrays/functor/summary.txt | 1 - basis/specialized-arrays/int/int.factor | 4 - basis/specialized-arrays/long/long.factor | 4 - .../longlong/longlong.factor | 4 - .../ptrdiff_t/ptrdiff_t.factor | 4 - basis/specialized-arrays/short/short.factor | 4 - .../specialized-arrays-docs.factor | 71 ++++--- .../specialized-arrays-tests.factor | 79 +++++++- .../specialized-arrays.factor | 145 +++++++++++++- basis/specialized-arrays/uchar/uchar.factor | 4 - basis/specialized-arrays/uint/uint.factor | 4 - basis/specialized-arrays/ulong/ulong.factor | 4 - .../ulonglong/ulonglong.factor | 4 - basis/specialized-arrays/ushort/ushort.factor | 4 - basis/specialized-vectors/alien/alien.factor | 4 - basis/specialized-vectors/bool/bool.factor | 4 - basis/specialized-vectors/char/char.factor | 4 - .../specialized-vectors/double/double.factor | 4 - basis/specialized-vectors/float/float.factor | 4 - .../functor/functor.factor | 38 ---- basis/specialized-vectors/functor/summary.txt | 1 - basis/specialized-vectors/int/int.factor | 4 - basis/specialized-vectors/long/long.factor | 4 - .../longlong/longlong.factor | 4 - basis/specialized-vectors/short/short.factor | 4 - .../specialized-vectors-docs.factor | 43 ++-- .../specialized-vectors-tests.factor | 7 +- .../specialized-vectors.factor | 71 ++++++- basis/specialized-vectors/uchar/uchar.factor | 4 - basis/specialized-vectors/uint/uint.factor | 4 - basis/specialized-vectors/ulong/ulong.factor | 4 - .../ulonglong/ulonglong.factor | 4 - .../specialized-vectors/ushort/ushort.factor | 4 - basis/struct-arrays/authors.txt | 1 - .../prettyprint/prettyprint.factor | 20 -- basis/struct-arrays/struct-arrays-docs.factor | 51 ----- .../struct-arrays/struct-arrays-tests.factor | 70 ------- basis/struct-arrays/struct-arrays.factor | 100 ---------- basis/struct-arrays/summary.txt | 1 - basis/struct-arrays/tags.txt | 1 - .../struct-vectors/struct-vectors-docs.factor | 16 -- .../struct-vectors-tests.factor | 16 -- basis/struct-vectors/struct-vectors.factor | 25 --- basis/tools/deploy/shaker/shaker.factor | 8 - .../deploy/shaker/strip-struct-arrays.factor | 13 -- basis/ui/backend/windows/windows.factor | 27 +-- basis/ui/pens/gradient/gradient.factor | 3 +- basis/ui/pens/polygon/polygon.factor | 5 +- basis/ui/pixel-formats/pixel-formats.factor | 3 +- basis/unix/utilities/utilities.factor | 6 +- basis/windows/com/wrapper/wrapper.factor | 3 +- .../windows/dinput/constants/constants.factor | 5 +- basis/windows/ole32/ole32-tests.factor | 3 +- basis/windows/ole32/ole32.factor | 9 +- basis/windows/shell32/shell32.factor | 3 +- basis/x11/clipboard/clipboard.factor | 3 +- basis/x11/glx/glx.factor | 5 +- basis/x11/xim/xim.factor | 5 +- core/assocs/assocs-tests.factor | 3 +- core/generic/single/single-tests.factor | 11 +- core/vocabs/parser/parser.factor | 5 + extra/alien/marshall/marshall.factor | 26 ++- extra/alien/marshall/private/private.factor | 3 +- extra/benchmark/dawes/dawes.factor | 9 +- extra/benchmark/dispatch2/dispatch2.factor | 3 +- extra/benchmark/dispatch3/dispatch3.factor | 3 +- extra/benchmark/fasta/fasta.factor | 5 +- extra/benchmark/nbody-simd/nbody-simd.factor | 14 +- extra/benchmark/nbody/nbody.factor | 7 +- extra/benchmark/raytracer-simd/authors.txt | 1 + .../raytracer-simd/raytracer-simd.factor | 187 ++++++++++++++++++ extra/benchmark/raytracer/raytracer.factor | 3 +- extra/benchmark/simd-1/authors.txt | 1 + extra/benchmark/simd-1/simd-1.factor | 30 +++ .../spectral-norm/spectral-norm.factor | 3 +- .../struct-arrays/struct-arrays.factor | 6 +- .../fixed-pipeline/fixed-pipeline.factor | 4 +- extra/bunny/model/model.factor | 5 +- extra/gpu/demos/bunny/bunny.factor | 20 +- extra/gpu/demos/bunny/deploy.factor | 14 ++ extra/gpu/framebuffers/framebuffers.factor | 5 +- extra/gpu/render/render-docs.factor | 8 +- extra/gpu/render/render.factor | 7 +- extra/gpu/shaders/shaders.factor | 17 +- extra/gpu/state/state.factor | 4 +- extra/gpu/textures/textures.factor | 3 +- extra/gpu/util/util.factor | 3 +- extra/gpu/util/wasd/wasd.factor | 3 +- extra/grid-meshes/grid-meshes.factor | 3 +- extra/half-floats/half-floats-tests.factor | 4 +- extra/half-floats/half-floats.factor | 5 +- extra/id3/id3.factor | 27 ++- .../images/normalization/normalization.factor | 7 +- extra/jamshred/gl/gl.factor | 3 +- extra/jamshred/player/player.factor | 6 +- extra/jamshred/tunnel/tunnel-tests.factor | 4 +- extra/jamshred/tunnel/tunnel.factor | 3 +- extra/llvm/invoker/invoker.factor | 4 +- extra/llvm/types/types.factor | 9 +- extra/nurbs/nurbs.factor | 3 +- extra/openal/openal.factor | 8 +- extra/synth/buffers/buffers.factor | 5 +- extra/system-info/linux/linux.factor | 3 +- extra/system-info/windows/windows.factor | 3 +- extra/terrain/terrain.factor | 3 +- 172 files changed, 978 insertions(+), 1106 deletions(-) create mode 100644 basis/bootstrap/compiler/timing/tags.txt delete mode 100755 basis/io/mmap/alien/alien.factor delete mode 100755 basis/io/mmap/bool/bool.factor delete mode 100755 basis/io/mmap/char/char.factor delete mode 100755 basis/io/mmap/double/double.factor delete mode 100755 basis/io/mmap/float/float.factor delete mode 100644 basis/io/mmap/functor/functor.factor delete mode 100755 basis/io/mmap/int/int.factor delete mode 100755 basis/io/mmap/long/long.factor delete mode 100755 basis/io/mmap/longlong/longlong.factor delete mode 100755 basis/io/mmap/short/short.factor delete mode 100755 basis/io/mmap/uchar/uchar.factor delete mode 100755 basis/io/mmap/uint/uint.factor delete mode 100755 basis/io/mmap/ulong/ulong.factor delete mode 100755 basis/io/mmap/ulonglong/ulonglong.factor delete mode 100755 basis/io/mmap/ushort/ushort.factor delete mode 100644 basis/specialized-arrays/alien/alien.factor delete mode 100644 basis/specialized-arrays/bool/bool.factor delete mode 100644 basis/specialized-arrays/char/char.factor delete mode 100644 basis/specialized-arrays/complex-double/complex-double-tests.factor delete mode 100644 basis/specialized-arrays/complex-double/complex-double.factor delete mode 100644 basis/specialized-arrays/complex-float/complex-float.factor delete mode 100644 basis/specialized-arrays/double/double.factor delete mode 100644 basis/specialized-arrays/float/float.factor delete mode 100755 basis/specialized-arrays/functor/functor.factor delete mode 100644 basis/specialized-arrays/functor/summary.txt delete mode 100644 basis/specialized-arrays/int/int.factor delete mode 100644 basis/specialized-arrays/long/long.factor delete mode 100644 basis/specialized-arrays/longlong/longlong.factor delete mode 100644 basis/specialized-arrays/ptrdiff_t/ptrdiff_t.factor delete mode 100644 basis/specialized-arrays/short/short.factor delete mode 100644 basis/specialized-arrays/uchar/uchar.factor delete mode 100644 basis/specialized-arrays/uint/uint.factor delete mode 100644 basis/specialized-arrays/ulong/ulong.factor delete mode 100644 basis/specialized-arrays/ulonglong/ulonglong.factor delete mode 100644 basis/specialized-arrays/ushort/ushort.factor delete mode 100644 basis/specialized-vectors/alien/alien.factor delete mode 100644 basis/specialized-vectors/bool/bool.factor delete mode 100644 basis/specialized-vectors/char/char.factor delete mode 100644 basis/specialized-vectors/double/double.factor delete mode 100644 basis/specialized-vectors/float/float.factor delete mode 100644 basis/specialized-vectors/functor/functor.factor delete mode 100644 basis/specialized-vectors/functor/summary.txt delete mode 100644 basis/specialized-vectors/int/int.factor delete mode 100644 basis/specialized-vectors/long/long.factor delete mode 100644 basis/specialized-vectors/longlong/longlong.factor delete mode 100644 basis/specialized-vectors/short/short.factor delete mode 100644 basis/specialized-vectors/uchar/uchar.factor delete mode 100644 basis/specialized-vectors/uint/uint.factor delete mode 100644 basis/specialized-vectors/ulong/ulong.factor delete mode 100644 basis/specialized-vectors/ulonglong/ulonglong.factor delete mode 100644 basis/specialized-vectors/ushort/ushort.factor delete mode 100644 basis/struct-arrays/authors.txt delete mode 100644 basis/struct-arrays/prettyprint/prettyprint.factor delete mode 100644 basis/struct-arrays/struct-arrays-docs.factor delete mode 100755 basis/struct-arrays/struct-arrays-tests.factor delete mode 100755 basis/struct-arrays/struct-arrays.factor delete mode 100644 basis/struct-arrays/summary.txt delete mode 100644 basis/struct-arrays/tags.txt delete mode 100644 basis/struct-vectors/struct-vectors-docs.factor delete mode 100644 basis/struct-vectors/struct-vectors-tests.factor delete mode 100644 basis/struct-vectors/struct-vectors.factor delete mode 100644 basis/tools/deploy/shaker/strip-struct-arrays.factor create mode 100644 extra/benchmark/raytracer-simd/authors.txt create mode 100644 extra/benchmark/raytracer-simd/raytracer-simd.factor create mode 100644 extra/benchmark/simd-1/authors.txt create mode 100644 extra/benchmark/simd-1/simd-1.factor create mode 100644 extra/gpu/demos/bunny/deploy.factor diff --git a/basis/alien/c-types/c-types-docs.factor b/basis/alien/c-types/c-types-docs.factor index 3a7c3a7405..d9e1f7124a 100755 --- a/basis/alien/c-types/c-types-docs.factor +++ b/basis/alien/c-types/c-types-docs.factor @@ -51,7 +51,7 @@ HELP: c-setter HELP: { $values { "len" "a non-negative integer" } { "c-type" "a C type" } { "array" byte-array } } { $description "Creates a byte array large enough to hold " { $snippet "n" } " values of a C type." } -{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, a " { $link specialized-array-vocab-not-loaded } " error will be thrown. The vocabulary can be loaded with a " { $link POSTPONE: USING: } " form as usual, or with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary set for details on the underlying sequence type constructed." } +{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } { $errors "Throws an error if the type does not exist, the necessary specialized array vocabulary is not loaded, or the requested size is negative." } ; HELP: @@ -73,7 +73,7 @@ HELP: byte-array>memory HELP: malloc-array { $values { "n" "a non-negative integer" } { "type" "a C type" } { "alien" alien } } { $description "Allocates an unmanaged memory block large enough to hold " { $snippet "n" } " values of a C type, then wraps the memory in a sequence object using " { $link } "." } -{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, a " { $link specialized-array-vocab-not-loaded } " error will be thrown. The vocabulary can be loaded with a " { $link POSTPONE: USING: } " form as usual, or with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary set for details on the underlying sequence type constructed." } +{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } { $warning "Don't forget to deallocate the memory with a call to " { $link free } "." } { $errors "Throws an error if the type does not exist, if the requested size is negative, if a direct specialized array class appropriate to the type is not loaded, or if memory allocation fails." } ; @@ -132,13 +132,13 @@ HELP: malloc-string HELP: require-c-array { $values { "c-type" "a C type" } } -{ $description { $link require } "s any unloaded vocabularies needed to construct a specialized array of " { $snippet "c-type" } " using the " { $link } " or " { $link } " vocabularies." } -{ $notes "This word must be called inside a compilation unit. See the " { $vocab-link "specialized-arrays" } " vocabulary set for details on the underlying sequence types loaded." } ; +{ $description "Generates a specialized array of " { $snippet "c-type" } " using the " { $link } " or " { $link } " vocabularies." } +{ $notes "This word must be called inside a compilation unit. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence types loaded." } ; HELP: { $values { "alien" c-ptr } { "len" integer } { "c-type" "a C type" } { "array" "a specialized direct array" } } { $description "Constructs a new specialized array of length " { $snippet "len" } " and element type " { $snippet "c-type" } " over the range of memory referenced by " { $snippet "alien" } "." } -{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, a " { $link specialized-array-vocab-not-loaded } " error will be thrown. The vocabulary can be loaded with a " { $link POSTPONE: USING: } " form as usual, or with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary set for details on the underlying sequence type constructed." } ; +{ $notes "The appropriate specialized array vocabulary must be loaded; otherwise, an error will be thrown. The vocabulary can be loaded with the " { $link require-c-array } " word. See the " { $vocab-link "specialized-arrays" } " vocabulary for details on the underlying sequence type constructed." } ; ARTICLE: "c-strings" "C strings" "C string types are arrays with shape " { $snippet "{ \"char*\" encoding }" } ", where " { $snippet "encoding" } " is an encoding descriptor. The type " { $snippet "\"char*\"" } " is an alias for " { $snippet "{ \"char*\" utf8 }" } ". See " { $link "encodings-descriptors" } " for information about encoding descriptors." diff --git a/basis/alien/c-types/c-types.factor b/basis/alien/c-types/c-types.factor index aa2ac2f93d..b177ab35d4 100755 --- a/basis/alien/c-types/c-types.factor +++ b/basis/alien/c-types/c-types.factor @@ -21,11 +21,7 @@ TUPLE: abstract-c-type { getter callable } { setter callable } size -align -array-class -array-constructor -(array)-constructor -direct-array-constructor ; +align ; TUPLE: c-type < abstract-c-type boxer @@ -75,9 +71,6 @@ M: string c-type ( name -- type ) ] ?if ] if ; -: ?require-word ( word/pair -- ) - dup word? [ drop ] [ first require ] ?if ; - ! These words being foldable means that words need to be ! recompiled if a C type is redefined. Even so, folding the ! size facilitates some optimizations. @@ -89,55 +82,28 @@ M: abstract-c-type heap-size size>> ; GENERIC: require-c-array ( c-type -- ) -M: object require-c-array - drop ; - -M: c-type require-c-array - array-class>> ?require-word ; - -M: string require-c-array - c-type require-c-array ; - -M: array require-c-array - first c-type require-c-array ; - -ERROR: specialized-array-vocab-not-loaded vocab word ; +M: array require-c-array first require-c-array ; -: c-array-constructor ( c-type -- word ) - array-constructor>> dup array? - [ first2 specialized-array-vocab-not-loaded ] when ; foldable +GENERIC: c-array-constructor ( c-type -- word ) -: c-(array)-constructor ( c-type -- word ) - (array)-constructor>> dup array? - [ first2 specialized-array-vocab-not-loaded ] when ; foldable +GENERIC: c-(array)-constructor ( c-type -- word ) -: c-direct-array-constructor ( c-type -- word ) - direct-array-constructor>> dup array? - [ first2 specialized-array-vocab-not-loaded ] when ; foldable +GENERIC: c-direct-array-constructor ( c-type -- word ) GENERIC: ( len c-type -- array ) -M: object - c-array-constructor execute( len -- array ) ; inline + M: string - c-type ; inline -M: array - first c-type ; inline + c-array-constructor execute( len -- array ) ; inline GENERIC: (c-array) ( len c-type -- array ) -M: object (c-array) - c-(array)-constructor execute( len -- array ) ; inline + M: string (c-array) - c-type (c-array) ; inline -M: array (c-array) - first c-type (c-array) ; inline + c-(array)-constructor execute( len -- array ) ; inline GENERIC: ( alien len c-type -- array ) -M: object - c-direct-array-constructor execute( alien len -- array ) ; inline + M: string - c-type ; inline -M: array - first c-type ; inline + c-direct-array-constructor execute( alien len -- array ) ; inline : malloc-array ( n type -- alien ) [ heap-size calloc ] [ ] 2bi ; inline @@ -347,32 +313,6 @@ M: long-long-type box-return ( type -- ) : if-void ( type true false -- ) pick "void" = [ drop nip call ] [ nip call ] if ; inline -: ?lookup ( vocab word -- word/pair ) - over vocab [ swap lookup ] [ 2array ] if ; - -: set-array-class* ( c-type vocab-stem type-stem -- c-type ) - { - [ - [ "specialized-arrays." prepend ] - [ "-array" append ] bi* ?lookup >>array-class - ] - [ - [ "specialized-arrays." prepend ] - [ "<" "-array>" surround ] bi* ?lookup >>array-constructor - ] - [ - [ "specialized-arrays." prepend ] - [ "(" "-array)" surround ] bi* ?lookup >>(array)-constructor - ] - [ - [ "specialized-arrays." prepend ] - [ "" surround ] bi* ?lookup >>direct-array-constructor - ] - } 2cleave ; - -: set-array-class ( c-type stem -- c-type ) - dup set-array-class* ; - CONSTANT: primitive-types { "char" "uchar" @@ -395,7 +335,6 @@ CONSTANT: primitive-types [ >c-ptr ] >>unboxer-quot "box_alien" >>boxer "alien_offset" >>unboxer - "alien" "void*" set-array-class* "void*" define-primitive-type @@ -407,7 +346,6 @@ CONSTANT: primitive-types 8 >>align "box_signed_8" >>boxer "to_signed_8" >>unboxer - "longlong" set-array-class "longlong" define-primitive-type @@ -419,7 +357,6 @@ CONSTANT: primitive-types 8 >>align "box_unsigned_8" >>boxer "to_unsigned_8" >>unboxer - "ulonglong" set-array-class "ulonglong" define-primitive-type @@ -431,7 +368,6 @@ CONSTANT: primitive-types bootstrap-cell >>align "box_signed_cell" >>boxer "to_fixnum" >>unboxer - "long" set-array-class "long" define-primitive-type @@ -443,7 +379,6 @@ CONSTANT: primitive-types bootstrap-cell >>align "box_unsigned_cell" >>boxer "to_cell" >>unboxer - "ulong" set-array-class "ulong" define-primitive-type @@ -455,7 +390,6 @@ CONSTANT: primitive-types 4 >>align "box_signed_4" >>boxer "to_fixnum" >>unboxer - "int" set-array-class "int" define-primitive-type @@ -467,7 +401,6 @@ CONSTANT: primitive-types 4 >>align "box_unsigned_4" >>boxer "to_cell" >>unboxer - "uint" set-array-class "uint" define-primitive-type @@ -479,7 +412,6 @@ CONSTANT: primitive-types 2 >>align "box_signed_2" >>boxer "to_fixnum" >>unboxer - "short" set-array-class "short" define-primitive-type @@ -491,7 +423,6 @@ CONSTANT: primitive-types 2 >>align "box_unsigned_2" >>boxer "to_cell" >>unboxer - "ushort" set-array-class "ushort" define-primitive-type @@ -503,7 +434,6 @@ CONSTANT: primitive-types 1 >>align "box_signed_1" >>boxer "to_fixnum" >>unboxer - "char" set-array-class "char" define-primitive-type @@ -515,7 +445,6 @@ CONSTANT: primitive-types 1 >>align "box_unsigned_1" >>boxer "to_cell" >>unboxer - "uchar" set-array-class "uchar" define-primitive-type @@ -525,7 +454,6 @@ CONSTANT: primitive-types 1 >>align "box_boolean" >>boxer "to_boolean" >>unboxer - "bool" set-array-class "bool" define-primitive-type @@ -539,7 +467,6 @@ CONSTANT: primitive-types "to_float" >>unboxer float-rep >>rep [ >float ] >>unboxer-quot - "float" set-array-class "float" define-primitive-type @@ -553,7 +480,6 @@ CONSTANT: primitive-types "to_double" >>unboxer double-rep >>rep [ >float ] >>unboxer-quot - "double" set-array-class "double" define-primitive-type "long" "ptrdiff_t" typedef diff --git a/basis/alien/complex/functor/functor.factor b/basis/alien/complex/functor/functor.factor index b05059e9cb..b1f9c2be85 100644 --- a/basis/alien/complex/functor/functor.factor +++ b/basis/alien/complex/functor/functor.factor @@ -26,7 +26,6 @@ T-class c-type 1quotation >>unboxer-quot *T 1quotation >>boxer-quot number >>boxed-class -T set-array-class drop ;FUNCTOR diff --git a/basis/alien/structs/structs.factor b/basis/alien/structs/structs.factor index 05558040e8..a80adf5137 100755 --- a/basis/alien/structs/structs.factor +++ b/basis/alien/structs/structs.factor @@ -66,4 +66,4 @@ M: struct-type stack-size [ name>> = ] with find nip offset>> ; USE: vocabs.loader -"struct-arrays" require +"specialized-arrays" require diff --git a/basis/bootstrap/compiler/timing/tags.txt b/basis/bootstrap/compiler/timing/tags.txt new file mode 100644 index 0000000000..6bf68304bb --- /dev/null +++ b/basis/bootstrap/compiler/timing/tags.txt @@ -0,0 +1 @@ +unportable diff --git a/basis/checksums/md5/md5.factor b/basis/checksums/md5/md5.factor index d59976fb7e..a2b6d4fd79 100644 --- a/basis/checksums/md5/md5.factor +++ b/basis/checksums/md5/md5.factor @@ -5,7 +5,8 @@ math.functions math.parser namespaces splitting grouping strings sequences byte-arrays locals sequences.private macros fry io.encodings.binary math.bitwise checksums accessors checksums.common checksums.stream combinators combinators.smart -specialized-arrays.uint literals hints ; +specialized-arrays literals hints ; +SPECIALIZED-ARRAY: uint IN: checksums.md5 SINGLETON: md5 diff --git a/basis/classes/struct/struct-tests.factor b/basis/classes/struct/struct-tests.factor index d76013e138..22d194d2a4 100755 --- a/basis/classes/struct/struct-tests.factor +++ b/basis/classes/struct/struct-tests.factor @@ -5,9 +5,11 @@ classes.struct classes.tuple.private combinators compiler.tree.debugger compiler.units destructors io.encodings.utf8 io.pathnames io.streams.string kernel libc literals math mirrors multiline namespaces prettyprint -prettyprint.config see sequences specialized-arrays.char -specialized-arrays.int specialized-arrays.ushort -struct-arrays system tools.test ; +prettyprint.config see sequences specialized-arrays +system tools.test ; +SPECIALIZED-ARRAY: char +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: ushort IN: classes.struct.tests << @@ -301,9 +303,11 @@ STRUCT: struct-test-array-slots STRUCT: struct-test-optimization { x { "int" 3 } } { y int } ; +SPECIALIZED-ARRAY: struct-test-optimization + [ t ] [ [ struct-test-optimization memory>struct y>> ] { memory>struct y>> } inlined? ] unit-test [ t ] [ - [ 3 struct-test-optimization third y>> ] + [ 3 third y>> ] { memory>struct y>> } inlined? ] unit-test diff --git a/basis/classes/struct/struct.factor b/basis/classes/struct/struct.factor index dc7fa965db..24d7e592bd 100755 --- a/basis/classes/struct/struct.factor +++ b/basis/classes/struct/struct.factor @@ -4,13 +4,14 @@ alien.structs.fields arrays byte-arrays classes classes.parser classes.tuple classes.tuple.parser classes.tuple.private combinators combinators.short-circuit combinators.smart definitions functors.backend fry generalizations generic.parser -kernel kernel.private lexer libc locals macros make math math.order -parser quotations sequences slots slots.private struct-arrays vectors -words compiler.tree.propagation.transforms specialized-arrays.uchar ; +kernel kernel.private lexer libc locals macros make math +math.order parser quotations sequences slots slots.private +specialized-arrays vectors words +compiler.tree.propagation.transforms ; FROM: slots => reader-word writer-word ; IN: classes.struct -! struct class +SPECIALIZED-ARRAY: uchar ERROR: struct-must-have-slots ; diff --git a/basis/cocoa/messages/messages.factor b/basis/cocoa/messages/messages.factor index 7342451c38..c0d8939a7a 100755 --- a/basis/cocoa/messages/messages.factor +++ b/basis/cocoa/messages/messages.factor @@ -5,9 +5,11 @@ classes.struct continuations combinators compiler compiler.alien stack-checker kernel math namespaces make quotations sequences strings words cocoa.runtime io macros memoize io.encodings.utf8 effects libc libc.private lexer init core-foundation fry -generalizations specialized-arrays.alien ; +generalizations specialized-arrays ; IN: cocoa.messages +SPECIALIZED-ARRAY: void* + : make-sender ( method function -- quot ) [ over first , f , , second , \ alien-invoke , ] [ ] make ; diff --git a/basis/compiler/tests/alien.factor b/basis/compiler/tests/alien.factor index 1428ba1b66..484b1f4f2f 100755 --- a/basis/compiler/tests/alien.factor +++ b/basis/compiler/tests/alien.factor @@ -3,8 +3,10 @@ alien.syntax arrays classes.struct combinators compiler continuations effects io io.backend io.pathnames io.streams.string kernel math memory namespaces namespaces.private parser quotations sequences -specialized-arrays.float stack-checker stack-checker.errors -system threads tools.test words specialized-arrays.char ; +specialized-arrays stack-checker stack-checker.errors +system threads tools.test words ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: char IN: compiler.tests.alien << diff --git a/basis/compiler/tree/propagation/propagation-tests.factor b/basis/compiler/tree/propagation/propagation-tests.factor index 06e68d3e35..4c6e8f55d7 100644 --- a/basis/compiler/tree/propagation/propagation-tests.factor +++ b/basis/compiler/tree/propagation/propagation-tests.factor @@ -8,8 +8,9 @@ math.functions math.private strings layouts compiler.tree.propagation.info compiler.tree.def-use compiler.tree.debugger compiler.tree.checker slots.private words hashtables classes assocs locals -specialized-arrays.double system sorting math.libm +specialized-arrays system sorting math.libm math.intervals quotations effects alien ; +SPECIALIZED-ARRAY: double IN: compiler.tree.propagation.tests [ V{ } ] [ [ ] final-classes ] unit-test diff --git a/basis/core-foundation/dictionaries/dictionaries.factor b/basis/core-foundation/dictionaries/dictionaries.factor index f758e0e63a..cc0175e0ea 100644 --- a/basis/core-foundation/dictionaries/dictionaries.factor +++ b/basis/core-foundation/dictionaries/dictionaries.factor @@ -1,9 +1,11 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien.syntax core-foundation kernel assocs -specialized-arrays.alien math sequences accessors ; +specialized-arrays math sequences accessors ; IN: core-foundation.dictionaries +SPECIALIZED-ARRAY: void* + TYPEDEF: void* CFDictionaryRef TYPEDEF: void* CFMutableDictionaryRef TYPEDEF: void* CFDictionaryKeyCallBacks* diff --git a/basis/core-foundation/fsevents/fsevents.factor b/basis/core-foundation/fsevents/fsevents.factor index 7eba7d14c9..9a22046a3a 100755 --- a/basis/core-foundation/fsevents/fsevents.factor +++ b/basis/core-foundation/fsevents/fsevents.factor @@ -3,12 +3,15 @@ USING: alien alien.c-types alien.strings alien.syntax kernel math sequences namespaces make assocs init accessors continuations combinators io.encodings.utf8 destructors locals -arrays specialized-arrays.alien classes.struct -specialized-arrays.int specialized-arrays.longlong -core-foundation core-foundation.run-loop core-foundation.strings +arrays specialized-arrays classes.struct core-foundation +core-foundation.run-loop core-foundation.strings core-foundation.time ; IN: core-foundation.fsevents +SPECIALIZED-ARRAY: void* +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: longlong + CONSTANT: kFSEventStreamCreateFlagUseCFTypes 2 CONSTANT: kFSEventStreamCreateFlagWatchRoot 4 diff --git a/basis/db/postgresql/lib/lib.factor b/basis/db/postgresql/lib/lib.factor index 0d50d1ab2c..2278afe4ed 100644 --- a/basis/db/postgresql/lib/lib.factor +++ b/basis/db/postgresql/lib/lib.factor @@ -6,7 +6,9 @@ db.types tools.walker ascii splitting math.parser combinators libc calendar.format byte-arrays destructors prettyprint accessors strings serialize io.encodings.binary io.encodings.utf8 alien.strings io.streams.byte-array summary present urls -specialized-arrays.uint specialized-arrays.alien db.private ; +specialized-arrays db.private ; +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: void* IN: db.postgresql.lib : postgresql-result-error-message ( res -- str/f ) diff --git a/basis/game-input/dinput/dinput.factor b/basis/game-input/dinput/dinput.factor index 6c72dc05cc..ea3100f95f 100755 --- a/basis/game-input/dinput/dinput.factor +++ b/basis/game-input/dinput/dinput.factor @@ -3,11 +3,13 @@ assocs byte-arrays combinators continuations game-input game-input.dinput.keys-array io.encodings.utf16 io.encodings.utf16n kernel locals math math.bitwise math.rectangles namespaces parser sequences shuffle -struct-arrays ui.backend.windows vectors windows.com +specialized-arrays ui.backend.windows vectors windows.com windows.dinput windows.dinput.constants windows.errors windows.kernel32 windows.messages windows.ole32 windows.user32 classes.struct ; +SPECIALIZED-ARRAY: DIDEVICEOBJECTDATA IN: game-input.dinput + CONSTANT: MOUSE-BUFFER-SIZE 16 SINGLETON: dinput-game-input-backend @@ -70,12 +72,9 @@ SYMBOLS: +dinput+ +keyboard-device+ +keyboard-state+ : find-mouse ( -- ) GUID_SysMouse device-for-guid - [ configure-mouse ] - [ +mouse-device+ set-global ] bi - 0 0 0 0 8 f mouse-state boa - +mouse-state+ set-global - MOUSE-BUFFER-SIZE DIDEVICEOBJECTDATA - +mouse-buffer+ set-global ; + [ configure-mouse ] [ +mouse-device+ set-global ] bi + 0 0 0 0 8 f mouse-state boa +mouse-state+ set-global + MOUSE-BUFFER-SIZE +mouse-buffer+ set-global ; : device-info ( device -- DIDEVICEIMAGEINFOW ) DIDEVICEINSTANCEW diff --git a/basis/images/bitmap/bitmap.factor b/basis/images/bitmap/bitmap.factor index cb73e4e274..8580a766b3 100755 --- a/basis/images/bitmap/bitmap.factor +++ b/basis/images/bitmap/bitmap.factor @@ -5,8 +5,10 @@ combinators compression.run-length endian fry grouping images images.bitmap.loading images.loader 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.uint -specialized-arrays.ushort strings summary ; +math.functions namespaces sequences specialized-arrays +strings summary ; +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: ushort IN: images.bitmap : write2 ( n -- ) 2 >le write ; diff --git a/basis/images/bitmap/loading/loading.factor b/basis/images/bitmap/loading/loading.factor index 82805fb688..823cfcd03a 100644 --- a/basis/images/bitmap/loading/loading.factor +++ b/basis/images/bitmap/loading/loading.factor @@ -4,8 +4,9 @@ USING: accessors arrays byte-arrays combinators compression.run-length fry grouping images images.loader io io.binary io.encodings.8-bit io.encodings.binary io.encodings.string io.streams.limited kernel math math.bitwise -sequences specialized-arrays.ushort summary ; +sequences specialized-arrays summary ; QUALIFIED-WITH: bitstreams b +SPECIALIZED-ARRAY: ushort IN: images.bitmap.loading SINGLETON: bitmap-image diff --git a/basis/images/tiff/tiff.factor b/basis/images/tiff/tiff.factor index 0d16bf75d4..c589349dff 100755 --- a/basis/images/tiff/tiff.factor +++ b/basis/images/tiff/tiff.factor @@ -5,8 +5,9 @@ compression.lzw endian fry grouping images io io.binary io.encodings.ascii io.encodings.binary io.encodings.string io.encodings.utf8 io.files kernel math math.bitwise math.order math.parser pack prettyprint sequences -strings math.vectors specialized-arrays.float locals +strings math.vectors specialized-arrays locals images.loader ; +SPECIALIZED-ARRAY: float IN: images.tiff SINGLETON: tiff-image diff --git a/basis/io/backend/unix/multiplexers/epoll/epoll.factor b/basis/io/backend/unix/multiplexers/epoll/epoll.factor index 11fa5620f2..b9c224c629 100644 --- a/basis/io/backend/unix/multiplexers/epoll/epoll.factor +++ b/basis/io/backend/unix/multiplexers/epoll/epoll.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors classes.struct kernel destructors bit-arrays -sequences assocs struct-arrays math namespaces locals fry unix -unix.linux.epoll unix.time io.ports io.backend.unix -io.backend.unix.multiplexers ; +sequences assocs specialized-arrays math namespaces +locals fry unix unix.linux.epoll unix.time io.ports +io.backend.unix io.backend.unix.multiplexers ; +SPECIALIZED-ARRAY: epoll-event IN: io.backend.unix.multiplexers.epoll TUPLE: epoll-mx < mx events ; @@ -16,7 +17,7 @@ TUPLE: epoll-mx < mx events ; : ( -- mx ) epoll-mx new-mx max-events epoll_create dup io-error >>fd - max-events epoll-event >>events ; + max-events >>events ; M: epoll-mx dispose* fd>> close-file ; diff --git a/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor b/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor index ab3308916d..c777e57f1d 100644 --- a/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor +++ b/basis/io/backend/unix/multiplexers/kqueue/kqueue.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types combinators destructors -io.backend.unix kernel math.bitwise sequences struct-arrays unix -unix.kqueue unix.time assocs io.backend.unix.multiplexers -classes.struct ; +io.backend.unix kernel math.bitwise sequences +specialized-arrays unix unix.kqueue unix.time assocs +io.backend.unix.multiplexers classes.struct ; +SPECIALIZED-ARRAY: kevent IN: io.backend.unix.multiplexers.kqueue TUPLE: kqueue-mx < mx events ; @@ -15,7 +16,7 @@ CONSTANT: max-events 256 : ( -- mx ) kqueue-mx new-mx kqueue dup io-error >>fd - max-events \ kevent >>events ; + max-events >>events ; M: kqueue-mx dispose* fd>> close-file ; diff --git a/basis/io/files/info/unix/freebsd/freebsd.factor b/basis/io/files/info/unix/freebsd/freebsd.factor index cdf158bd2f..f1d6b4db66 100644 --- a/basis/io/files/info/unix/freebsd/freebsd.factor +++ b/basis/io/files/info/unix/freebsd/freebsd.factor @@ -4,7 +4,9 @@ USING: accessors alien.c-types alien.syntax combinators io.backend io.files io.files.info io.files.unix kernel math system unix unix.statfs.freebsd unix.statvfs.freebsd unix.getfsstat.freebsd sequences grouping alien.strings io.encodings.utf8 unix.types -arrays io.files.info.unix classes.struct struct-arrays ; +arrays io.files.info.unix classes.struct +specialized-arrays ; +SPECIALIZED-ARRAY: statfs IN: io.files.info.unix.freebsd TUPLE: freebsd-file-system-info < unix-file-system-info @@ -50,6 +52,6 @@ M: freebsd statvfs>file-system-info ( file-system-info statvfs -- file-system-in M: freebsd file-systems ( -- array ) f 0 0 getfsstat dup io-error - \ statfs + [ dup byte-length 0 getfsstat io-error ] [ [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ] bi ; diff --git a/basis/io/files/info/unix/macosx/macosx.factor b/basis/io/files/info/unix/macosx/macosx.factor index 9ce235ecd7..ac5f8c23b1 100755 --- a/basis/io/files/info/unix/macosx/macosx.factor +++ b/basis/io/files/info/unix/macosx/macosx.factor @@ -1,10 +1,12 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.strings combinators -grouping io.encodings.utf8 io.files kernel math sequences -system unix io.files.unix specialized-arrays.uint arrays -unix.statfs.macosx unix.statvfs.macosx unix.getfsstat.macosx -io.files.info.unix io.files.info classes.struct struct-arrays ; +grouping io.encodings.utf8 io.files kernel math sequences system +unix io.files.unix arrays unix.statfs.macosx unix.statvfs.macosx +unix.getfsstat.macosx io.files.info.unix io.files.info +classes.struct specialized-arrays ; +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: statfs64 IN: io.files.info.unix.macosx TUPLE: macosx-file-system-info < unix-file-system-info @@ -12,7 +14,7 @@ io-size owner type-id filesystem-subtype ; M: macosx file-systems ( -- array ) f dup 0 getmntinfo64 dup io-error - [ *void* ] dip \ statfs64 + [ *void* ] dip [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ; M: macosx new-file-system-info macosx-file-system-info new ; diff --git a/basis/io/files/info/unix/netbsd/netbsd.factor b/basis/io/files/info/unix/netbsd/netbsd.factor index 10d9a7eb8b..9e37ec8aa9 100755 --- a/basis/io/files/info/unix/netbsd/netbsd.factor +++ b/basis/io/files/info/unix/netbsd/netbsd.factor @@ -4,8 +4,9 @@ USING: alien.syntax kernel unix.stat math unix combinators system io.backend accessors alien.c-types io.encodings.utf8 alien.strings unix.types io.files.unix io.files io.files.info unix.statvfs.netbsd unix.getfsstat.netbsd arrays -grouping sequences io.encodings.utf8 classes.struct struct-arrays -io.files.info.unix ; +grouping sequences io.encodings.utf8 classes.struct +specialized-arrays io.files.info.unix ; +SPECIALIZED-ARRAY: statvfs IN: io.files.info.unix.netbsd TUPLE: netbsd-file-system-info < unix-file-system-info @@ -47,6 +48,6 @@ M: netbsd statvfs>file-system-info ( file-system-info statvfs -- file-system-inf M: netbsd file-systems ( -- array ) f 0 0 getvfsstat dup io-error - \ statvfs + [ dup byte-length 0 getvfsstat io-error ] [ [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ] bi ; diff --git a/basis/io/files/info/unix/openbsd/openbsd.factor b/basis/io/files/info/unix/openbsd/openbsd.factor index 68c9d2ca12..fe94f70fd8 100755 --- a/basis/io/files/info/unix/openbsd/openbsd.factor +++ b/basis/io/files/info/unix/openbsd/openbsd.factor @@ -4,8 +4,9 @@ USING: accessors alien.c-types alien.strings alien.syntax combinators io.backend io.files io.files.info io.files.unix kernel math sequences system unix unix.getfsstat.openbsd grouping unix.statfs.openbsd unix.statvfs.openbsd unix.types -arrays io.files.info.unix classes.struct struct-arrays -io.encodings.utf8 ; +arrays io.files.info.unix classes.struct +specialized-arrays io.encodings.utf8 ; +SPECIALIZED-ARRAY: statvfs IN: io.files.unix.openbsd TUPLE: openbsd-file-system-info < unix-file-system-info @@ -48,6 +49,6 @@ M: openbsd statvfs>file-system-info ( file-system-info statvfs -- file-system-in M: openbsd file-systems ( -- seq ) f 0 0 getfsstat dup io-error - \ statfs + [ dup byte-length 0 getfsstat io-error ] [ [ f_mntonname>> utf8 alien>string file-system-info ] { } map-as ] bi ; diff --git a/basis/io/files/info/unix/unix.factor b/basis/io/files/info/unix/unix.factor index 20b3513c6c..0b52237a6d 100644 --- a/basis/io/files/info/unix/unix.factor +++ b/basis/io/files/info/unix/unix.factor @@ -3,8 +3,10 @@ USING: accessors kernel system math math.bitwise strings arrays sequences combinators combinators.short-circuit alien.c-types vocabs.loader calendar calendar.unix io.files.info -io.files.types io.backend io.directories unix unix.stat unix.time unix.users -unix.groups classes.struct struct-arrays ; +io.files.types io.backend io.directories unix unix.stat +unix.time unix.users unix.groups classes.struct +specialized-arrays ; +SPECIALIZED-ARRAY: timeval IN: io.files.info.unix TUPLE: unix-file-system-info < file-system-info @@ -184,7 +186,7 @@ M: unix copy-file-and-info ( from to -- ) : timestamps>byte-array ( timestamps -- byte-array ) [ [ timestamp>timeval ] [ \ timeval ] if* ] map - \ timeval >struct-array ; + >timeval-array ; PRIVATE> diff --git a/basis/io/files/info/windows/windows.factor b/basis/io/files/info/windows/windows.factor index 385a1eb196..bb3a412669 100755 --- a/basis/io/files/info/windows/windows.factor +++ b/basis/io/files/info/windows/windows.factor @@ -6,7 +6,8 @@ windows.time windows accessors alien.c-types combinators generalizations system alien.strings io.encodings.utf16n sequences splitting windows.errors fry continuations destructors calendar ascii combinators.short-circuit locals classes.struct -specialized-arrays.ushort ; +specialized-arrays ; +SPECIALIZED-ARRAY: ushort IN: io.files.info.windows :: round-up-to ( n multiple -- n' ) diff --git a/basis/io/files/windows/nt/nt.factor b/basis/io/files/windows/nt/nt.factor index 17cfa0977e..97754cf237 100755 --- a/basis/io/files/windows/nt/nt.factor +++ b/basis/io/files/windows/nt/nt.factor @@ -5,7 +5,8 @@ windows.kernel32 kernel libc math threads system environment alien.c-types alien.arrays alien.strings sequences combinators combinators.short-circuit ascii splitting alien strings assocs namespaces make accessors tr windows.time windows.shell32 -windows.errors specialized-arrays.ushort classes.struct ; +windows.errors specialized-arrays classes.struct ; +SPECIALIZED-ARRAY: ushort IN: io.files.windows.nt M: winnt cwd diff --git a/basis/io/launcher/windows/windows.factor b/basis/io/launcher/windows/windows.factor index 45aeec0a80..475be5d70c 100755 --- a/basis/io/launcher/windows/windows.factor +++ b/basis/io/launcher/windows/windows.factor @@ -1,13 +1,13 @@ ! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types arrays continuations io -io.backend.windows io.pipes.windows.nt io.pathnames libc io.ports -windows.types math windows.kernel32 -namespaces make io.launcher kernel sequences windows.errors -splitting system threads init strings combinators -io.backend accessors concurrency.flags io.files assocs -io.files.private windows destructors specialized-arrays.ushort -specialized-arrays.alien classes classes.struct ; +io.backend.windows io.pipes.windows.nt io.pathnames libc +io.ports windows.types math windows.kernel32 namespaces make +io.launcher kernel sequences windows.errors splitting system +threads init strings combinators io.backend accessors +concurrency.flags io.files assocs io.files.private windows +destructors specialized-arrays.alien classes classes.struct ; +SPECIALIZED-ARRAY: ushort IN: io.launcher.windows TUPLE: CreateProcess-args diff --git a/basis/io/mmap/alien/alien.factor b/basis/io/mmap/alien/alien.factor deleted file mode 100755 index bf721489fa..0000000000 --- a/basis/io/mmap/alien/alien.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.alien ; -IN: io.mmap.alien - -<< "void*" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/bool/bool.factor b/basis/io/mmap/bool/bool.factor deleted file mode 100755 index 5352bbf9af..0000000000 --- a/basis/io/mmap/bool/bool.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.bool ; -IN: io.mmap.bool - -<< "bool" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/char/char.factor b/basis/io/mmap/char/char.factor deleted file mode 100755 index fc5f14faaf..0000000000 --- a/basis/io/mmap/char/char.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.char ; -IN: io.mmap.char - -<< "char" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/double/double.factor b/basis/io/mmap/double/double.factor deleted file mode 100755 index 708286bc3d..0000000000 --- a/basis/io/mmap/double/double.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.double ; -IN: io.mmap.double - -<< "double" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/float/float.factor b/basis/io/mmap/float/float.factor deleted file mode 100755 index 71685a4548..0000000000 --- a/basis/io/mmap/float/float.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.float ; -IN: io.mmap.float - -<< "float" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/functor/functor.factor b/basis/io/mmap/functor/functor.factor deleted file mode 100644 index a80ce3bc82..0000000000 --- a/basis/io/mmap/functor/functor.factor +++ /dev/null @@ -1,32 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: io.mmap functors accessors alien.c-types math kernel -words fry ; -IN: io.mmap.functor - -SLOT: address -SLOT: length - -: mapped-file>direct ( mapped-file type -- alien length ) - [ [ address>> ] [ length>> ] bi ] dip - heap-size [ 1 - + ] keep /i ; - -FUNCTOR: define-mapped-array ( T -- ) - - DEFINES - IS -with-mapped-A-file DEFINES with-mapped-${T}-file -with-mapped-A-file-reader DEFINES with-mapped-${T}-file-reader - -WHERE - -: ( mapped-file -- direct-array ) - T mapped-file>direct ; inline - -: with-mapped-A-file ( path quot -- ) - '[ @ ] with-mapped-file ; inline - -: with-mapped-A-file-reader ( path quot -- ) - '[ @ ] with-mapped-file-reader ; inline - -;FUNCTOR diff --git a/basis/io/mmap/int/int.factor b/basis/io/mmap/int/int.factor deleted file mode 100755 index 1f6bd2ac36..0000000000 --- a/basis/io/mmap/int/int.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.int ; -IN: io.mmap.int - -<< "int" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/long/long.factor b/basis/io/mmap/long/long.factor deleted file mode 100755 index 70a9c46756..0000000000 --- a/basis/io/mmap/long/long.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.long ; -IN: io.mmap.long - -<< "long" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/longlong/longlong.factor b/basis/io/mmap/longlong/longlong.factor deleted file mode 100755 index 426f87274f..0000000000 --- a/basis/io/mmap/longlong/longlong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.longlong ; -IN: io.mmap.longlong - -<< "longlong" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/mmap-tests.factor b/basis/io/mmap/mmap-tests.factor index 0e1cd1a036..4847b0701c 100644 --- a/basis/io/mmap/mmap-tests.factor +++ b/basis/io/mmap/mmap-tests.factor @@ -1,13 +1,13 @@ -USING: io io.mmap io.mmap.char io.files io.files.temp +USING: io io.mmap io.files io.files.temp io.directories kernel tools.test continuations sequences io.encodings.ascii accessors math ; IN: io.mmap.tests [ "mmap-test-file.txt" temp-file delete-file ] ignore-errors [ ] [ "12345" "mmap-test-file.txt" temp-file ascii set-file-contents ] unit-test -[ ] [ "mmap-test-file.txt" temp-file [ CHAR: 2 0 pick set-nth drop ] with-mapped-char-file ] unit-test -[ 5 ] [ "mmap-test-file.txt" temp-file [ length ] with-mapped-char-file ] unit-test -[ 5 ] [ "mmap-test-file.txt" temp-file [ length ] with-mapped-char-file-reader ] unit-test +[ ] [ "mmap-test-file.txt" temp-file [ "char" CHAR: 2 0 pick set-nth drop ] with-mapped-file ] unit-test +[ 5 ] [ "mmap-test-file.txt" temp-file [ "char" length ] with-mapped-file ] unit-test +[ 5 ] [ "mmap-test-file.txt" temp-file [ "char" length ] with-mapped-file-reader ] unit-test [ "22345" ] [ "mmap-test-file.txt" temp-file ascii file-contents ] unit-test [ "mmap-test-file.txt" temp-file delete-file ] ignore-errors diff --git a/basis/io/mmap/mmap.factor b/basis/io/mmap/mmap.factor index aa3ac624a0..704a585dd4 100644 --- a/basis/io/mmap/mmap.factor +++ b/basis/io/mmap/mmap.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2007, 2008 Doug Coleman, Slava Pestov. +! Copyright (C) 2007, 2009 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: continuations destructors io.files io.files.info io.backend kernel quotations system alien alien.accessors @@ -30,6 +30,11 @@ PRIVATE> : ( path -- mmap ) [ (mapped-file-r/w) ] prepare-mapped-file ; +: ( mmap c-type -- direct-array ) + [ [ address>> ] [ length>> ] bi ] dip + [ heap-size /i ] keep + ; inline + HOOK: close-mapped-file io-backend ( mmap -- ) M: mapped-file dispose* ( mmap -- ) close-mapped-file ; diff --git a/basis/io/mmap/short/short.factor b/basis/io/mmap/short/short.factor deleted file mode 100755 index c19d70d34a..0000000000 --- a/basis/io/mmap/short/short.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.short ; -IN: io.mmap.short - -<< "short" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/uchar/uchar.factor b/basis/io/mmap/uchar/uchar.factor deleted file mode 100755 index 03b6cd4647..0000000000 --- a/basis/io/mmap/uchar/uchar.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.uchar ; -IN: io.mmap.uchar - -<< "uchar" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/uint/uint.factor b/basis/io/mmap/uint/uint.factor deleted file mode 100755 index a3793495c0..0000000000 --- a/basis/io/mmap/uint/uint.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.uint ; -IN: io.mmap.uint - -<< "uint" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/ulong/ulong.factor b/basis/io/mmap/ulong/ulong.factor deleted file mode 100755 index dfdae5d661..0000000000 --- a/basis/io/mmap/ulong/ulong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.ulong ; -IN: io.mmap.ulong - -<< "ulong" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/ulonglong/ulonglong.factor b/basis/io/mmap/ulonglong/ulonglong.factor deleted file mode 100755 index 1d6bd0e3b8..0000000000 --- a/basis/io/mmap/ulonglong/ulonglong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.ulonglong ; -IN: io.mmap.ulonglong - -<< "ulonglong" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/mmap/ushort/ushort.factor b/basis/io/mmap/ushort/ushort.factor deleted file mode 100755 index fc63313bd8..0000000000 --- a/basis/io/mmap/ushort/ushort.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: io.mmap.functor specialized-arrays.ushort ; -IN: io.mmap.ushort - -<< "ushort" define-mapped-array >> \ No newline at end of file diff --git a/basis/io/pipes/unix/unix.factor b/basis/io/pipes/unix/unix.factor index f94733ca56..7319ad1db8 100644 --- a/basis/io/pipes/unix/unix.factor +++ b/basis/io/pipes/unix/unix.factor @@ -1,9 +1,10 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: system kernel unix math sequences -io.backend.unix io.ports specialized-arrays.int accessors ; -IN: io.pipes.unix +io.backend.unix io.ports specialized-arrays accessors ; QUALIFIED: io.pipes +SPECIALIZED-ARRAY: int +IN: io.pipes.unix M: unix io.pipes:(pipe) ( -- pair ) 2 diff --git a/basis/math/blas/matrices/matrices.factor b/basis/math/blas/matrices/matrices.factor index c315021ed4..a051fb250d 100755 --- a/basis/math/blas/matrices/matrices.factor +++ b/basis/math/blas/matrices/matrices.factor @@ -3,9 +3,12 @@ combinators.short-circuit fry kernel locals macros math math.blas.ffi math.blas.vectors math.blas.vectors.private math.complex math.functions math.order functors words sequences sequences.merged sequences.private shuffle -specialized-arrays.float specialized-arrays.double -specialized-arrays.complex-float specialized-arrays.complex-double -parser prettyprint.backend prettyprint.custom ascii ; +parser prettyprint.backend prettyprint.custom ascii +specialized-arrays ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: double +SPECIALIZED-ARRAY: complex-float +SPECIALIZED-ARRAY: complex-double IN: math.blas.matrices TUPLE: blas-matrix-base underlying ld rows cols transpose ; diff --git a/basis/math/blas/vectors/vectors.factor b/basis/math/blas/vectors/vectors.factor index 2b573ab6ed..c08fdb6120 100755 --- a/basis/math/blas/vectors/vectors.factor +++ b/basis/math/blas/vectors/vectors.factor @@ -2,8 +2,11 @@ USING: accessors alien alien.c-types arrays ascii byte-arrays combinators combinators.short-circuit fry kernel math math.blas.ffi math.complex math.functions math.order sequences sequences.private functors words locals parser prettyprint.backend prettyprint.custom -specialized-arrays.float specialized-arrays.double -specialized-arrays.complex-float specialized-arrays.complex-double ; +specialized-arrays ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: double +SPECIALIZED-ARRAY: complex-float +SPECIALIZED-ARRAY: complex-double IN: math.blas.vectors TUPLE: blas-vector-base underlying length inc ; diff --git a/basis/math/vectors/simd/alien/alien-tests.factor b/basis/math/vectors/simd/alien/alien-tests.factor index 52b8db9bd1..87540dd9a5 100644 --- a/basis/math/vectors/simd/alien/alien-tests.factor +++ b/basis/math/vectors/simd/alien/alien-tests.factor @@ -1,8 +1,9 @@ -IN: math.vectors.simd.alien.tests USING: cpu.architecture math.vectors.simd math.vectors.simd.intrinsics accessors math.vectors.simd.alien kernel classes.struct tools.test compiler sequences byte-arrays -alien math kernel.private specialized-arrays.float combinators ; +alien math kernel.private specialized-arrays combinators ; +SPECIALIZED-ARRAY: float +IN: math.vectors.simd.alien.tests ! Vector alien intrinsics [ float-4{ 1 2 3 4 } ] [ diff --git a/basis/math/vectors/specialization/specialization-tests.factor b/basis/math/vectors/specialization/specialization-tests.factor index 5b6f1eac71..f9f241bb6f 100644 --- a/basis/math/vectors/specialization/specialization-tests.factor +++ b/basis/math/vectors/specialization/specialization-tests.factor @@ -1,8 +1,9 @@ IN: math.vectors.specialization.tests USING: compiler.tree.debugger math.vectors tools.test kernel -kernel.private math specialized-arrays.double -specialized-arrays.complex-float -specialized-arrays.float ; +kernel.private math specialized-arrays ; +SPECIALIZED-ARRAY: double +SPECIALIZED-ARRAY: complex-float +SPECIALIZED-ARRAY: float [ V{ t } ] [ [ { double-array double-array } declare distance 0.0 < not ] final-literals diff --git a/basis/math/vectors/specialization/specialization.factor b/basis/math/vectors/specialization/specialization.factor index acf8dada38..21ec9f64f3 100644 --- a/basis/math/vectors/specialization/specialization.factor +++ b/basis/math/vectors/specialization/specialization.factor @@ -1,9 +1,9 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: words kernel make sequences effects kernel.private accessors -combinators math math.intervals math.vectors namespaces assocs fry -splitting classes.algebra generalizations locals -compiler.tree.propagation.info ; +USING: alien.c-types words kernel make sequences effects +kernel.private accessors combinators math math.intervals +math.vectors namespaces assocs fry splitting classes.algebra +generalizations locals compiler.tree.propagation.info ; IN: math.vectors.specialization SYMBOLS: -> +vector+ +scalar+ +nonnegative+ ; @@ -99,12 +99,14 @@ M: vector-word subwords specializations values [ word? ] filter ; array-type elt-type word word-schema inputs signature-for-schema ; :: specialize-vector-words ( array-type elt-type simd -- ) - vector-words keys [ - [ array-type elt-type simd specialize-vector-word ] - [ array-type elt-type input-signature ] - [ ] - tri add-specialization - ] each ; + elt-type number class<= [ + vector-words keys [ + [ array-type elt-type simd specialize-vector-word ] + [ array-type elt-type input-signature ] + [ ] + tri add-specialization + ] each + ] when ; : find-specialization ( classes word -- word/f ) specializations diff --git a/basis/opengl/opengl.factor b/basis/opengl/opengl.factor index 0a037287fe..75f327664d 100755 --- a/basis/opengl/opengl.factor +++ b/basis/opengl/opengl.factor @@ -7,7 +7,9 @@ continuations kernel libc math macros namespaces math.vectors math.parser opengl.gl combinators combinators.smart arrays sequences splitting words byte-arrays assocs vocabs colors colors.constants accessors generalizations locals fry -specialized-arrays.float specialized-arrays.uint ; +specialized-arrays ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: uint IN: opengl : gl-color ( color -- ) >rgba-components glColor4d ; inline diff --git a/basis/opengl/shaders/shaders.factor b/basis/opengl/shaders/shaders.factor index 9d5f4810e1..26ffd0cf88 100755 --- a/basis/opengl/shaders/shaders.factor +++ b/basis/opengl/shaders/shaders.factor @@ -2,8 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel opengl.gl alien.c-types continuations namespaces assocs alien alien.strings libc opengl math sequences combinators -macros arrays io.encodings.ascii fry specialized-arrays.uint +macros arrays io.encodings.ascii fry specialized-arrays destructors accessors ; +SPECIALIZED-ARRAY: uint IN: opengl.shaders : with-gl-shader-source-ptr ( string quot -- ) diff --git a/basis/opengl/textures/textures.factor b/basis/opengl/textures/textures.factor index 528aaaa12f..28d920d8d6 100755 --- a/basis/opengl/textures/textures.factor +++ b/basis/opengl/textures/textures.factor @@ -1,10 +1,11 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs cache colors.constants destructors kernel -opengl opengl.gl opengl.capabilities combinators images -images.tesselation grouping specialized-arrays.float sequences math -math.vectors math.matrices generalizations fry arrays namespaces -system locals literals ; +USING: accessors assocs cache colors.constants destructors +kernel opengl opengl.gl opengl.capabilities combinators images +images.tesselation grouping sequences math math.vectors +math.matrices generalizations fry arrays namespaces system +locals literals specialized-arrays ; +SPECIALIZED-ARRAY: float IN: opengl.textures SYMBOL: non-power-of-2-textures? diff --git a/basis/random/mersenne-twister/mersenne-twister.factor b/basis/random/mersenne-twister/mersenne-twister.factor index 966c5b2e60..3a44066caf 100644 --- a/basis/random/mersenne-twister/mersenne-twister.factor +++ b/basis/random/mersenne-twister/mersenne-twister.factor @@ -4,7 +4,8 @@ ! http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/CODES/mt19937ar.c USING: kernel math namespaces sequences sequences.private system init accessors math.ranges random math.bitwise combinators -specialized-arrays.uint fry ; +specialized-arrays fry ; +SPECIALIZED-ARRAY: uint IN: random.mersenne-twister >array . "> "{ C{ 1.0 -1.0 } C{ -2.0 2.0 } C{ 3.0 0.0 } }" } } ; @@ -23,8 +23,9 @@ HELP: { $description "Wraps " { $snippet "sequence" } " in a " { $link complex-sequence } "." } { $examples { $example <" USING: prettyprint -specialized-arrays.double sequences.complex +specialized-arrays sequences.complex sequences arrays ; +SPECIALIZED-ARRAY: double double-array{ 1.0 -1.0 -2.0 2.0 3.0 0.0 } second . "> "C{ -2.0 2.0 }" } } ; diff --git a/basis/sequences/complex/complex-tests.factor b/basis/sequences/complex/complex-tests.factor index 5861bc8b02..04a80c6bee 100644 --- a/basis/sequences/complex/complex-tests.factor +++ b/basis/sequences/complex/complex-tests.factor @@ -1,5 +1,6 @@ -USING: specialized-arrays.float sequences.complex +USING: specialized-arrays sequences.complex kernel sequences tools.test arrays accessors ; +SPECIALIZED-ARRAY: float IN: sequences.complex.tests : test-array ( -- x ) diff --git a/basis/serialize/serialize-tests.factor b/basis/serialize/serialize-tests.factor index b6a4b1a86f..99c8adefb6 100644 --- a/basis/serialize/serialize-tests.factor +++ b/basis/serialize/serialize-tests.factor @@ -2,9 +2,10 @@ ! See http://factorcode.org/license.txt for BSD license. ! USING: tools.test kernel serialize io io.streams.byte-array -alien arrays byte-arrays bit-arrays specialized-arrays.double +alien arrays byte-arrays bit-arrays specialized-arrays sequences math prettyprint parser classes math.constants io.encodings.binary random assocs serialize.private ; +SPECIALIZED-ARRAY: double IN: serialize.tests : test-serialize-cell ( a -- ? ) diff --git a/basis/specialized-arrays/alien/alien.factor b/basis/specialized-arrays/alien/alien.factor deleted file mode 100644 index 465d1665f9..0000000000 --- a/basis/specialized-arrays/alien/alien.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.alien - -<< "void*" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/bool/bool.factor b/basis/specialized-arrays/bool/bool.factor deleted file mode 100644 index 759ee91abc..0000000000 --- a/basis/specialized-arrays/bool/bool.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.bool - -<< "bool" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/char/char.factor b/basis/specialized-arrays/char/char.factor deleted file mode 100644 index cdf78eeef8..0000000000 --- a/basis/specialized-arrays/char/char.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.char - -<< "char" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/complex-double/complex-double-tests.factor b/basis/specialized-arrays/complex-double/complex-double-tests.factor deleted file mode 100644 index 9f2bcc99b7..0000000000 --- a/basis/specialized-arrays/complex-double/complex-double-tests.factor +++ /dev/null @@ -1,13 +0,0 @@ -USING: kernel sequences specialized-arrays.complex-double tools.test ; -IN: specialized-arrays.complex-double.tests - -[ C{ 3.0 2.0 } ] -[ complex-double-array{ 1.0 C{ 3.0 2.0 } 5.0 } second ] unit-test - -[ C{ 1.0 0.0 } ] -[ complex-double-array{ 1.0 C{ 3.0 2.0 } 5.0 } first ] unit-test - -[ complex-double-array{ 1.0 C{ 6.0 -7.0 } 5.0 } ] [ - complex-double-array{ 1.0 C{ 3.0 2.0 } 5.0 } - dup [ C{ 6.0 -7.0 } 1 ] dip set-nth -] unit-test diff --git a/basis/specialized-arrays/complex-double/complex-double.factor b/basis/specialized-arrays/complex-double/complex-double.factor deleted file mode 100644 index 00b07fb9b3..0000000000 --- a/basis/specialized-arrays/complex-double/complex-double.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.complex-double - -<< "complex-double" define-array >> diff --git a/basis/specialized-arrays/complex-float/complex-float.factor b/basis/specialized-arrays/complex-float/complex-float.factor deleted file mode 100644 index 5348343bae..0000000000 --- a/basis/specialized-arrays/complex-float/complex-float.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.complex-float - -<< "complex-float" define-array >> diff --git a/basis/specialized-arrays/double/double.factor b/basis/specialized-arrays/double/double.factor deleted file mode 100644 index 95324bd2d5..0000000000 --- a/basis/specialized-arrays/double/double.factor +++ /dev/null @@ -1,25 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.double - -<< "double" define-array >> - -! Specializer hints. These should really be generalized, and placed -! somewhere else -USING: hints math.vectors arrays kernel math accessors sequences ; - -HINTS: { 2 } { 3 } ; - -HINTS: (double-array) { 2 } { 3 } ; - -! Type functions -USING: words classes.algebra compiler.tree.propagation.info -math.intervals ; - -\ norm-sq [ - class>> double-array class<= [ float 0. 1/0. [a,b] ] [ object-info ] if -] "outputs" set-word-prop - -\ distance [ - [ class>> double-array class<= ] both? - [ float 0. 1/0. [a,b] ] [ object-info ] if -] "outputs" set-word-prop diff --git a/basis/specialized-arrays/float/float.factor b/basis/specialized-arrays/float/float.factor deleted file mode 100644 index 5d9da66739..0000000000 --- a/basis/specialized-arrays/float/float.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.float - -<< "float" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/functor/functor.factor b/basis/specialized-arrays/functor/functor.factor deleted file mode 100755 index b4d052467d..0000000000 --- a/basis/specialized-arrays/functor/functor.factor +++ /dev/null @@ -1,94 +0,0 @@ -! Copyright (C) 2008, 2009 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: functors sequences sequences.private prettyprint.custom -kernel words classes math math.vectors.specialization parser -alien.c-types byte-arrays accessors summary alien specialized-arrays ; -IN: specialized-arrays.functor - -ERROR: bad-byte-array-length byte-array type ; - -M: bad-byte-array-length summary - drop "Byte array length doesn't divide type width" ; - -: (underlying) ( n c-type -- array ) - heap-size * (byte-array) ; inline - -: ( n type -- array ) - heap-size * ; inline - -FUNCTOR: define-array ( T -- ) - -A DEFINES-CLASS ${T}-array -S DEFINES-CLASS ${T}-sequence - DEFINES <${A}> -(A) DEFINES (${A}) - DEFINES ->A DEFINES >${A} -byte-array>A DEFINES byte-array>${A} - -A{ DEFINES ${A}{ -A@ DEFINES ${A}@ - -NTH [ T dup c-type-getter-boxer array-accessor ] -SET-NTH [ T dup c-setter array-accessor ] - -WHERE - -MIXIN: S - -TUPLE: A -{ underlying c-ptr read-only } -{ length array-capacity read-only } ; - -: ( alien len -- specialized-array ) A boa ; inline - -: ( n -- specialized-array ) [ T ] keep ; inline - -: (A) ( n -- specialized-array ) [ T (underlying) ] keep ; inline - -: byte-array>A ( byte-array -- specialized-array ) - dup length T heap-size /mod 0 = [ drop T bad-byte-array-length ] unless - ; inline - -M: A clone [ underlying>> clone ] [ length>> ] bi ; inline - -M: A length length>> ; inline - -M: A nth-unsafe underlying>> NTH call ; inline - -M: A set-nth-unsafe underlying>> SET-NTH call ; inline - -: >A ( seq -- specialized-array ) A new clone-like ; - -M: A like drop dup A instance? [ >A ] unless ; inline - -M: A new-sequence drop (A) ; inline - -M: A equal? over A instance? [ sequence= ] [ 2drop f ] if ; - -M: A resize - [ - [ T heap-size * ] [ underlying>> ] bi* - resize-byte-array - ] [ drop ] 2bi - ; inline - -M: A byte-length underlying>> length ; inline -M: A pprint-delims drop \ A{ \ } ; -M: A >pprint-sequence ; - -SYNTAX: A{ \ } [ >A ] parse-literal ; -SYNTAX: A@ scan-object scan-object parsed ; - -INSTANCE: A specialized-array - -A T c-type-boxed-class f specialize-vector-words - -T c-type - \ A >>array-class - \ >>array-constructor - \ (A) >>(array)-constructor - \ >>direct-array-constructor - drop - -;FUNCTOR diff --git a/basis/specialized-arrays/functor/summary.txt b/basis/specialized-arrays/functor/summary.txt deleted file mode 100644 index 77cb2d4d89..0000000000 --- a/basis/specialized-arrays/functor/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Code generation for specialized arrays diff --git a/basis/specialized-arrays/int/int.factor b/basis/specialized-arrays/int/int.factor deleted file mode 100644 index 37f4b59c80..0000000000 --- a/basis/specialized-arrays/int/int.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.int - -<< "int" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/long/long.factor b/basis/specialized-arrays/long/long.factor deleted file mode 100644 index 2cba6424eb..0000000000 --- a/basis/specialized-arrays/long/long.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.long - -<< "long" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/longlong/longlong.factor b/basis/specialized-arrays/longlong/longlong.factor deleted file mode 100644 index 195dd78f7b..0000000000 --- a/basis/specialized-arrays/longlong/longlong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.longlong - -<< "longlong" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/ptrdiff_t/ptrdiff_t.factor b/basis/specialized-arrays/ptrdiff_t/ptrdiff_t.factor deleted file mode 100644 index 4fd7d825cc..0000000000 --- a/basis/specialized-arrays/ptrdiff_t/ptrdiff_t.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.alien - -<< "ptrdiff_t" define-array >> diff --git a/basis/specialized-arrays/short/short.factor b/basis/specialized-arrays/short/short.factor deleted file mode 100644 index 3891462159..0000000000 --- a/basis/specialized-arrays/short/short.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.short - -<< "short" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/specialized-arrays-docs.factor b/basis/specialized-arrays/specialized-arrays-docs.factor index e0645456ec..bb5c7d38d6 100755 --- a/basis/specialized-arrays/specialized-arrays-docs.factor +++ b/basis/specialized-arrays/specialized-arrays-docs.factor @@ -1,43 +1,52 @@ -USING: help.markup help.syntax byte-arrays ; +USING: help.markup help.syntax byte-arrays alien ; IN: 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." -$nl -"For each primitive C type " { $snippet "T" } ", a set of words are defined in the vocabulary named " { $snippet "specialized-arrays.T" } ":" +HELP: SPECIALIZED-ARRAY: +{ $syntax "SPECIALIZED-ARRAY: type" } +{ $values { "type" "a C type" } } +{ $description "Brings a specialized array for holding values of " { $snippet "type" } " into the vocabulary search path. The generated words are documented in " { $link "specialized-array-words" } "." } ; + +ARTICLE: "specialized-array-words" "Specialized array words" +"The " { $link POSTPONE: SPECIALIZED-ARRAY: } " parsing word generates the specialized array 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 { { $snippet "T-array" } { "The class of arrays with elements of type " { $snippet "T" } } } { { $snippet "" } { "Constructor for arrays with elements of type " { $snippet "T" } "; stack effect " { $snippet "( len -- array )" } } } - { { $snippet "" } { "Constructor for arrays with elements of type " { $snippet "T" } "; stack effect " { $snippet "( alien len -- array )" } } } + { { $snippet "(T-array)" } { "Constructor for arrays with elements of type " { $snippet "T" } ", where the initial contents are uninitialized; stack effect " { $snippet "( len -- array )" } } } + { { $snippet "malloc-T-array" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by newly-allocated unmanaged memory; stack effect " { $snippet "( alien len -- array )" } } } + { { $snippet "" } { "Constructor for arrays with elements of type " { $snippet "T" } " backed by raw memory; stack effect " { $snippet "( alien len -- array )" } } } { { $snippet "byte-array>T-array" } { "Converts a byte array into a specialized array by interpreting the bytes in as machine-specific values. Code which uses this word is unportable" } } { { $snippet ">T-array" } { "Converts a sequence into a specialized array of type " { $snippet "T" } "; stack effect " { $snippet "( seq -- array )" } } } { { $snippet "T-array{" } { "Literal syntax, consists of a series of values terminated by " { $snippet "}" } } } } -"Each specialized array has a " { $slot "underlying" } " slot holding a " { $link byte-array } " with the raw data. This data can be passed to C functions." -$nl -"The primitive C types for which specialized arrays exist:" -{ $list - { $snippet "char" } - { $snippet "uchar" } - { $snippet "short" } - { $snippet "ushort" } - { $snippet "int" } - { $snippet "uint" } - { $snippet "long" } - { $snippet "ulong" } - { $snippet "longlong" } - { $snippet "ulonglong" } - { $snippet "float" } - { $snippet "double" } - { $snippet "complex-float" } - { $snippet "complex-double" } - { $snippet "void*" } - { $snippet "bool" } -} -"Note that " { $vocab-link "specialized-arrays.bool" } " behaves like a C " { $snippet "bool[]" } " array, and each element takes up 8 bits of space. For a more space-efficient boolean array, see " { $link "bit-arrays" } "." -$nl -"Specialized arrays are generated with a functor in the " { $vocab-link "specialized-arrays.functor" } " vocabulary." +"Behind the scenes, these words are placed in a vocabulary named " { $snippet "specialized-arrays.instances.T" } ", however this vocabulary should not be placed in a " { $link POSTPONE: USING: } " form directly. Instead, always use " { $link POSTPONE: SPECIALIZED-ARRAY: } ". This ensures that the vocabulary can get generated the first time it is needed." ; + +ARTICLE: "specialized-array-c" "Passing specialized arrays to C functions" +"Each specialized array has a " { $slot "underlying" } " slot holding a " { $link byte-array } " with the raw data. Passing a specialized array as a parameter to a C function call will automatically extract the underlying data. To get at the underlying data directly, call the " { $link >c-ptr } " word on a specialized array." ; + +ARTICLE: "specialized-array-math" "Vector arithmetic with specialized arrays" +"Each specialized array with a numeric type generates specialized versions of the " { $link "math-vectors" } " words. The compiler substitutes calls for these words if it can statically determine input types. The " { $snippet "optimized." } " word in the " { $vocab-link "compiler.tree.debugger" } " vocabulary can be used to determine if this optimization is being performed for a particular piece of code." ; + +ARTICLE: "specialized-array-examples" "Specialized array examples" +"Let's import specialized float arrays:" +{ $code "USING: specialized-arrays math.constants math.functions ;" "SPECIALIZED-ARRAY: float" } +"Creating a float array with 3 elements:" +{ $code "1.0 [ sin ] [ cos ] [ tan ] tri float-array{ } 3sequence ." } +"Create a float array and sum the elements:" +{ $code + "1000 iota [ 1000 /f pi * sin ] float-array{ } map-as" + "0.0 [ + ] reduce ." +} ; + +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 -"The " { $vocab-link "specialized-vectors" } " vocabulary provides resizable versions of the above." ; +"A specialized array type needs to be generated for each element type. This is done with a parsing word:" +{ $subsection POSTPONE: SPECIALIZED-ARRAY: } +"This parsing word adds new words to the search path:" +{ $subsection "specialized-array-words" } +{ $subsection "specialized-array-c" } +{ $subsection "specialized-array-math" } +{ $subsection "specialized-array-examples" } +"The " { $vocab-link "specialized-vectors" } " vocabulary provides a resizable version of this abstraction." ; ABOUT: "specialized-arrays" diff --git a/basis/specialized-arrays/specialized-arrays-tests.factor b/basis/specialized-arrays/specialized-arrays-tests.factor index 19f98ff31f..3290eccd2f 100755 --- a/basis/specialized-arrays/specialized-arrays-tests.factor +++ b/basis/specialized-arrays/specialized-arrays-tests.factor @@ -1,9 +1,16 @@ IN: specialized-arrays.tests -USING: tools.test alien.syntax specialized-arrays sequences -specialized-arrays.int specialized-arrays.bool -specialized-arrays.ushort alien.c-types accessors kernel -specialized-arrays.char specialized-arrays.uint -specialized-arrays.float arrays combinators compiler ; +USING: tools.test alien.syntax specialized-arrays +specialized-arrays sequences alien.c-types accessors +kernel arrays combinators compiler classes.struct +combinators.smart compiler.tree.debugger math libc destructors +sequences.private ; + +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: bool +SPECIALIZED-ARRAY: ushort +SPECIALIZED-ARRAY: char +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: float [ t ] [ { 1 2 3 } >int-array int-array? ] unit-test @@ -37,3 +44,65 @@ specialized-arrays.float arrays combinators compiler ; 3 ALIEN: 123 100 new-sequence dup [ drop 0 ] change-each ] unit-test + +STRUCT: test-struct + { x int } + { y int } ; + +SPECIALIZED-ARRAY: test-struct + +[ 1 ] [ + 1 test-struct-array{ } new-sequence length +] unit-test + +[ V{ test-struct } ] [ + [ [ test-struct-array ] test-struct-array{ } output>sequence first ] final-classes +] unit-test + +: make-point ( x y -- struct ) + test-struct ; + +[ 5/4 ] [ + 2 + 1 2 make-point over set-first + 3 4 make-point over set-second + 0 [ [ x>> ] [ y>> ] bi / + ] reduce +] unit-test + +[ 5/4 ] [ + [ + 2 malloc-test-struct-array + dup &free drop + 1 2 make-point over set-first + 3 4 make-point over set-second + 0 [ [ x>> ] [ y>> ] bi / + ] reduce + ] with-destructors +] unit-test + +[ ] [ ALIEN: 123 10 drop ] unit-test + +[ ] [ + [ + 10 malloc-test-struct-array + &free drop + ] with-destructors +] unit-test + +[ 15 ] [ 15 10 resize length ] unit-test + +[ S{ test-struct f 12 20 } ] [ + test-struct-array{ + S{ test-struct f 4 20 } + S{ test-struct f 12 20 } + S{ test-struct f 20 20 } + } second +] unit-test + +! Regression +STRUCT: fixed-string { text char[100] } ; + +SPECIALIZED-ARRAY: fixed-string + +[ { ALIEN: 123 ALIEN: 223 ALIEN: 323 ALIEN: 423 } ] [ + ALIEN: 123 4 [ (underlying)>> ] { } map-as +] unit-test diff --git a/basis/specialized-arrays/specialized-arrays.factor b/basis/specialized-arrays/specialized-arrays.factor index f3b75af958..3a1ce48e68 100755 --- a/basis/specialized-arrays/specialized-arrays.factor +++ b/basis/specialized-arrays/specialized-arrays.factor @@ -1,13 +1,156 @@ ! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel sequences vocabs vocabs.loader ; +USING: accessors alien alien.c-types assocs byte-arrays classes +compiler.units functors io kernel lexer libc math +math.vectors.specialization namespaces parser +prettyprint.custom sequences sequences.private strings summary +vocabs vocabs.loader vocabs.parser words ; IN: specialized-arrays MIXIN: specialized-array + INSTANCE: specialized-array sequence GENERIC: direct-array-syntax ( obj -- word ) +ERROR: bad-byte-array-length byte-array type ; + +M: bad-byte-array-length summary + drop "Byte array length doesn't divide type width" ; + +: (underlying) ( n c-type -- array ) + heap-size * (byte-array) ; inline + +: ( n type -- array ) + heap-size * ; inline + + DEFINES <${A}> +(A) DEFINES (${A}) + DEFINES +malloc-A DEFINES malloc-${A} +>A DEFINES >${A} +byte-array>A DEFINES byte-array>${A} + +A{ DEFINES ${A}{ +A@ DEFINES ${A}@ + +NTH [ T dup c-type-getter-boxer array-accessor ] +SET-NTH [ T dup c-setter array-accessor ] + +WHERE + +MIXIN: S + +TUPLE: A +{ underlying c-ptr read-only } +{ length array-capacity read-only } ; + +: ( alien len -- specialized-array ) A boa ; inline + +: ( n -- specialized-array ) [ T ] keep ; inline + +: (A) ( n -- specialized-array ) [ T (underlying) ] keep ; inline + +: malloc-A ( len -- specialized-array ) [ T heap-size calloc ] keep ; inline + +: byte-array>A ( byte-array -- specialized-array ) + dup length T heap-size /mod 0 = [ drop T bad-byte-array-length ] unless + ; inline + +M: A clone [ underlying>> clone ] [ length>> ] bi ; inline + +M: A length length>> ; inline + +M: A nth-unsafe underlying>> NTH call ; inline + +M: A set-nth-unsafe underlying>> SET-NTH call ; inline + +: >A ( seq -- specialized-array ) A new clone-like ; + +M: A like drop dup A instance? [ >A ] unless ; inline + +M: A new-sequence drop (A) ; inline + +M: A equal? over A instance? [ sequence= ] [ 2drop f ] if ; + +M: A resize + [ + [ T heap-size * ] [ underlying>> ] bi* + resize-byte-array + ] [ drop ] 2bi + ; inline + +M: A byte-length underlying>> length ; inline +M: A pprint-delims drop \ A{ \ } ; +M: A >pprint-sequence ; + +SYNTAX: A{ \ } [ >A ] parse-literal ; +SYNTAX: A@ scan-object scan-object parsed ; + +INSTANCE: A specialized-array + +A T c-type-boxed-class f specialize-vector-words + +;FUNCTOR + +: underlying-type ( c-type -- c-type' ) + dup c-types get at string? [ + c-types get at underlying-type + ] when ; + +: specialized-array-vocab ( c-type -- vocab ) + "specialized-arrays.instances." prepend ; + +: defining-array-message ( type -- ) + "quiet" get [ drop ] [ + "Generating specialized " " arrays..." surround print + ] if ; + +PRIVATE> + +: define-array-vocab ( type -- vocab ) + underlying-type + dup specialized-array-vocab vocab + [ ] [ + [ defining-array-message ] + [ + [ + dup specialized-array-vocab + [ define-array ] with-current-vocab + ] with-compilation-unit + ] + [ specialized-array-vocab ] + tri + ] ?if ; + +M: string require-c-array define-array-vocab drop ; + +ERROR: specialized-array-vocab-not-loaded c-type ; + +M: string c-array-constructor + underlying-type + dup [ "<" "-array>" surround ] [ specialized-array-vocab ] bi lookup + [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable + +M: string c-(array)-constructor + underlying-type + dup [ "(" "-array)" surround ] [ specialized-array-vocab ] bi lookup + [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable + +M: string c-direct-array-constructor + underlying-type + dup [ "" surround ] [ specialized-array-vocab ] bi lookup + [ ] [ specialized-array-vocab-not-loaded ] ?if ; foldable + +SYNTAX: SPECIALIZED-ARRAY: + scan define-array-vocab use-vocab ; + "prettyprint" vocab [ "specialized-arrays.prettyprint" require ] when diff --git a/basis/specialized-arrays/uchar/uchar.factor b/basis/specialized-arrays/uchar/uchar.factor deleted file mode 100644 index c6ed4f3ab6..0000000000 --- a/basis/specialized-arrays/uchar/uchar.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.uchar - -<< "uchar" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/uint/uint.factor b/basis/specialized-arrays/uint/uint.factor deleted file mode 100644 index 1534a3d158..0000000000 --- a/basis/specialized-arrays/uint/uint.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.uint - -<< "uint" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/ulong/ulong.factor b/basis/specialized-arrays/ulong/ulong.factor deleted file mode 100644 index 27dc1295b3..0000000000 --- a/basis/specialized-arrays/ulong/ulong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.ulong - -<< "ulong" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/ulonglong/ulonglong.factor b/basis/specialized-arrays/ulonglong/ulonglong.factor deleted file mode 100644 index cbb2b3cf9d..0000000000 --- a/basis/specialized-arrays/ulonglong/ulonglong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.ulonglong - -<< "ulonglong" define-array >> \ No newline at end of file diff --git a/basis/specialized-arrays/ushort/ushort.factor b/basis/specialized-arrays/ushort/ushort.factor deleted file mode 100644 index e0989aa9d4..0000000000 --- a/basis/specialized-arrays/ushort/ushort.factor +++ /dev/null @@ -1,4 +0,0 @@ -USE: specialized-arrays.functor -IN: specialized-arrays.ushort - -<< "ushort" define-array >> \ No newline at end of file diff --git a/basis/specialized-vectors/alien/alien.factor b/basis/specialized-vectors/alien/alien.factor deleted file mode 100644 index 2b9855f6c9..0000000000 --- a/basis/specialized-vectors/alien/alien.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.alien ; -IN: specialized-vectors.alien - -<< "void*" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/bool/bool.factor b/basis/specialized-vectors/bool/bool.factor deleted file mode 100644 index 75d452a1d8..0000000000 --- a/basis/specialized-vectors/bool/bool.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.bool ; -IN: specialized-vectors.bool - -<< "bool" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/char/char.factor b/basis/specialized-vectors/char/char.factor deleted file mode 100644 index c34167cb6c..0000000000 --- a/basis/specialized-vectors/char/char.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.char ; -IN: specialized-vectors.char - -<< "char" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/double/double.factor b/basis/specialized-vectors/double/double.factor deleted file mode 100644 index 5e77162517..0000000000 --- a/basis/specialized-vectors/double/double.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.double ; -IN: specialized-vectors.double - -<< "double" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/float/float.factor b/basis/specialized-vectors/float/float.factor deleted file mode 100644 index 010b4486cf..0000000000 --- a/basis/specialized-vectors/float/float.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.float ; -IN: specialized-vectors.float - -<< "float" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/functor/functor.factor b/basis/specialized-vectors/functor/functor.factor deleted file mode 100644 index 27bba3f9a6..0000000000 --- a/basis/specialized-vectors/functor/functor.factor +++ /dev/null @@ -1,38 +0,0 @@ -! Copyright (C) 2008, 2009 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types functors sequences sequences.private growable -prettyprint.custom kernel words classes math parser ; -QUALIFIED: vectors.functor -IN: specialized-vectors.functor - -FUNCTOR: define-vector ( T -- ) - -V DEFINES-CLASS ${T}-vector - -A IS ${T}-array -S IS ${T}-sequence - IS <${A}> - ->V DEFERS >${V} -V{ DEFINES ${V}{ - -WHERE - -V A vectors.functor:define-vector - -M: V contract 2drop ; - -M: V byte-length underlying>> byte-length ; - -M: V pprint-delims drop \ V{ \ } ; - -M: V >pprint-sequence ; - -M: V pprint* pprint-object ; - -SYNTAX: V{ \ } [ >V ] parse-literal ; - -INSTANCE: V growable -INSTANCE: V S - -;FUNCTOR diff --git a/basis/specialized-vectors/functor/summary.txt b/basis/specialized-vectors/functor/summary.txt deleted file mode 100644 index dc26fa6d44..0000000000 --- a/basis/specialized-vectors/functor/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Code generation for specialized vectors diff --git a/basis/specialized-vectors/int/int.factor b/basis/specialized-vectors/int/int.factor deleted file mode 100644 index d77e6fd214..0000000000 --- a/basis/specialized-vectors/int/int.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.int ; -IN: specialized-vectors.int - -<< "int" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/long/long.factor b/basis/specialized-vectors/long/long.factor deleted file mode 100644 index a026054f0b..0000000000 --- a/basis/specialized-vectors/long/long.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.long ; -IN: specialized-vectors.long - -<< "long" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/longlong/longlong.factor b/basis/specialized-vectors/longlong/longlong.factor deleted file mode 100644 index e272ea0bdf..0000000000 --- a/basis/specialized-vectors/longlong/longlong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.longlong ; -IN: specialized-vectors.longlong - -<< "longlong" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/short/short.factor b/basis/specialized-vectors/short/short.factor deleted file mode 100644 index 26ffad4245..0000000000 --- a/basis/specialized-vectors/short/short.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.short ; -IN: specialized-vectors.short - -<< "short" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/specialized-vectors-docs.factor b/basis/specialized-vectors/specialized-vectors-docs.factor index 5c0a15cb75..9c575fe73a 100644 --- a/basis/specialized-vectors/specialized-vectors-docs.factor +++ b/basis/specialized-vectors/specialized-vectors-docs.factor @@ -1,35 +1,28 @@ -USING: help.markup help.syntax byte-vectors ; +USING: help.markup help.syntax byte-vectors alien byte-arrays ; IN: 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." -$nl -"For each primitive C type " { $snippet "T" } ", a set of words are defined:" +HELP: SPECIALIZED-VECTOR: +{ $syntax "SPECIALIZED-VECTOR: 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" } "." } ; + +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 { { $snippet "T-vector" } { "The class of vectors with elements of type " { $snippet "T" } } } { { $snippet "" } { "Constructor for vectors with elements of type " { $snippet "T" } "; stack effect " { $snippet "( len -- vector )" } } } { { $snippet ">T-vector" } { "Converts a sequence into a specialized vector of type " { $snippet "T" } "; stack effect " { $snippet "( seq -- vector )" } } } { { $snippet "T-vector{" } { "Literal syntax, consists of a series of values terminated by " { $snippet "}" } } } } -"The primitive C types for which specialized vectors exist:" -{ $list - { $snippet "char" } - { $snippet "uchar" } - { $snippet "short" } - { $snippet "ushort" } - { $snippet "int" } - { $snippet "uint" } - { $snippet "long" } - { $snippet "ulong" } - { $snippet "longlong" } - { $snippet "ulonglong" } - { $snippet "float" } - { $snippet "double" } - { $snippet "void*" } - { $snippet "bool" } -} -"Specialized vectors are generated with a functor in the " { $vocab-link "specialized-vectors.functor" } " vocabulary." -$nl -"The " { $vocab-link "specialized-arrays" } " vocabulary provides fixed-length versions of the above." ; +"Behind the scenes, these words are placed in a vocabulary named " { $snippet "specialized-vectors.instances.T" } ", however this vocabulary should not be placed in a " { $link POSTPONE: USING: } " form directly. Instead, always use " { $link POSTPONE: SPECIALIZED-VECTOR: } ". This ensures that the vocabulary can get generated the first time it is needed." ; + +ARTICLE: "specialized-vector-c" "Passing specialized arrays to C functions" +"Each specialized array has a " { $slot "underlying" } " slot holding a specialized array, which in turn has an " { $slot "underlying" } " slot holding a " { $link byte-array } " with the raw data. Passing a specialized vector as a parameter to a C function call will automatically extract the underlying data. To get at the underlying data directly, call the " { $link >c-ptr } " word on a specialized vector." ; + +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." +{ $subsection "specialized-vector-words" } +{ $subsection "specialized-vector-c" } +"The " { $vocab-link "specialized-arrays" } " vocabulary provides a fixed-length version of this abstraction." ; ABOUT: "specialized-vectors" diff --git a/basis/specialized-vectors/specialized-vectors-tests.factor b/basis/specialized-vectors/specialized-vectors-tests.factor index 82def17e44..edff828b13 100644 --- a/basis/specialized-vectors/specialized-vectors-tests.factor +++ b/basis/specialized-vectors/specialized-vectors-tests.factor @@ -1,8 +1,9 @@ IN: specialized-vectors.tests -USING: specialized-arrays.float -specialized-vectors.float -specialized-vectors.double +USING: specialized-arrays specialized-vectors tools.test kernel sequences ; +SPECIALIZED-ARRAY: float +SPECIALIZED-VECTOR: float +SPECIALIZED-VECTOR: double [ 3 ] [ double-vector{ 1 2 } 3 over push length ] unit-test diff --git a/basis/specialized-vectors/specialized-vectors.factor b/basis/specialized-vectors/specialized-vectors.factor index 5df602c78d..19f32a7fdb 100644 --- a/basis/specialized-vectors/specialized-vectors.factor +++ b/basis/specialized-vectors/specialized-vectors.factor @@ -1,3 +1,72 @@ -! Copyright (C) 2008 Slava Pestov. +! 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 io kernel lexer namespaces parser prettyprint.custom +sequences specialized-arrays specialized-arrays.private strings +vocabs vocabs.parser ; +QUALIFIED: vectors.functor IN: specialized-vectors + + IS <${A}> + +>V DEFERS >${V} +V{ DEFINES ${V}{ + +WHERE + +V A vectors.functor:define-vector + +M: V contract 2drop ; + +M: V byte-length underlying>> byte-length ; + +M: V pprint-delims drop \ V{ \ } ; + +M: V >pprint-sequence ; + +M: V pprint* pprint-object ; + +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 ; + +PRIVATE> + +: 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 ; + +SYNTAX: SPECIALIZED-VECTOR: + scan + [ define-array-vocab use-vocab ] + [ define-vector-vocab use-vocab ] bi ; diff --git a/basis/specialized-vectors/uchar/uchar.factor b/basis/specialized-vectors/uchar/uchar.factor deleted file mode 100644 index 76cbd154b0..0000000000 --- a/basis/specialized-vectors/uchar/uchar.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.uchar ; -IN: specialized-vectors.uchar - -<< "uchar" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/uint/uint.factor b/basis/specialized-vectors/uint/uint.factor deleted file mode 100644 index 95800878eb..0000000000 --- a/basis/specialized-vectors/uint/uint.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.uint ; -IN: specialized-vectors.uint - -<< "uint" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/ulong/ulong.factor b/basis/specialized-vectors/ulong/ulong.factor deleted file mode 100644 index 486a9dd513..0000000000 --- a/basis/specialized-vectors/ulong/ulong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.ulong ; -IN: specialized-vectors.ulong - -<< "ulong" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/ulonglong/ulonglong.factor b/basis/specialized-vectors/ulonglong/ulonglong.factor deleted file mode 100644 index c06ccec1c3..0000000000 --- a/basis/specialized-vectors/ulonglong/ulonglong.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.ulonglong ; -IN: specialized-vectors.ulonglong - -<< "ulonglong" define-vector >> \ No newline at end of file diff --git a/basis/specialized-vectors/ushort/ushort.factor b/basis/specialized-vectors/ushort/ushort.factor deleted file mode 100644 index 6968607919..0000000000 --- a/basis/specialized-vectors/ushort/ushort.factor +++ /dev/null @@ -1,4 +0,0 @@ -USING: specialized-vectors.functor specialized-arrays.ushort ; -IN: specialized-vectors.ushort - -<< "ushort" define-vector >> \ No newline at end of file diff --git a/basis/struct-arrays/authors.txt b/basis/struct-arrays/authors.txt deleted file mode 100644 index 1901f27a24..0000000000 --- a/basis/struct-arrays/authors.txt +++ /dev/null @@ -1 +0,0 @@ -Slava Pestov diff --git a/basis/struct-arrays/prettyprint/prettyprint.factor b/basis/struct-arrays/prettyprint/prettyprint.factor deleted file mode 100644 index 77fb6847a0..0000000000 --- a/basis/struct-arrays/prettyprint/prettyprint.factor +++ /dev/null @@ -1,20 +0,0 @@ -! (c)Joe Groff bsd license -USING: accessors arrays kernel prettyprint.backend -prettyprint.custom prettyprint.sections sequences struct-arrays ; -IN: struct-arrays.prettyprint - -M: struct-array pprint-delims - drop \ struct-array{ \ } ; - -M: struct-array >pprint-sequence - [ >array ] [ class>> ] bi prefix ; - -: pprint-struct-array-pointer ( struct-array -- ) - \ struct-array@ - [ [ class>> pprint-word ] [ underlying>> pprint* ] [ length>> pprint* ] tri ] - pprint-prefix ; - -M: struct-array pprint* - [ pprint-object ] - [ pprint-struct-array-pointer ] pprint-c-object ; - diff --git a/basis/struct-arrays/struct-arrays-docs.factor b/basis/struct-arrays/struct-arrays-docs.factor deleted file mode 100644 index 8483901f46..0000000000 --- a/basis/struct-arrays/struct-arrays-docs.factor +++ /dev/null @@ -1,51 +0,0 @@ -IN: struct-arrays -USING: classes.struct help.markup help.syntax alien strings math multiline ; - -HELP: struct-array -{ $class-description "The class of C struct and union arrays." -$nl -"The " { $slot "underlying" } " slot holds a " { $link c-ptr } " with the raw data. This pointer can be passed to C functions." } ; - -HELP: -{ $values { "length" integer } { "struct-class" struct-class } { "struct-array" struct-array } } -{ $description "Creates a new array for holding values of the specified struct type." } ; - -HELP: -{ $values { "alien" c-ptr } { "length" integer } { "struct-class" struct-class } { "struct-array" struct-array } } -{ $description "Creates a new array for holding values of the specified C type, backed by the memory at " { $snippet "alien" } "." } ; - -HELP: struct-array-on -{ $values { "struct" struct } { "length" integer } { "struct-array" struct-array } } -{ $description "Create a new array for holding values of " { $snippet "struct" } "'s C type, backed by the memory starting at " { $snippet "struct" } "'s address." } -{ $examples -"This word is useful with the FFI. When a C function has a pointer to a struct as its return type (or a C callback has a struct pointer as an argument type), Factor automatically wraps the pointer in a " { $link struct } " object. If the pointer actually references an array of objects, this word will convert the struct object to a struct array object:" -{ $code <" USING: alien.syntax classes.struct struct-arrays ; -IN: scratchpad - -STRUCT: zim { zang int } { zung int } ; - -FUNCTION: zim* zingle ( ) ; ! Returns a pointer to 20 zims - -zingle 20 struct-array-on "> } -} ; - -HELP: struct-array{ -{ $syntax "struct-array{ class value value value ... }" } -{ $description "Literal syntax for a " { $link struct-array } " containing structs of the given " { $link struct } " class." } ; - -HELP: struct-array@ -{ $syntax "struct-array@ class alien length" } -{ $description "Literal syntax for a " { $link struct-array } " at a particular memory address. The prettyprinter uses this syntax when the memory backing a struct array object is invalid. This syntax should not generally be used in source code." } ; - -{ POSTPONE: struct-array{ POSTPONE: struct-array@ } related-words - -ARTICLE: "struct-arrays" "C struct and union arrays" -"The " { $vocab-link "struct-arrays" } " vocabulary implements arrays specialized for holding C struct and union values." -{ $subsection struct-array } -{ $subsection } -{ $subsection } -{ $subsection struct-array-on } -"Struct arrays have literal syntax:" -{ $subsection POSTPONE: struct-array{ } ; - -ABOUT: "struct-arrays" diff --git a/basis/struct-arrays/struct-arrays-tests.factor b/basis/struct-arrays/struct-arrays-tests.factor deleted file mode 100755 index 24caafa9fa..0000000000 --- a/basis/struct-arrays/struct-arrays-tests.factor +++ /dev/null @@ -1,70 +0,0 @@ -IN: struct-arrays.tests -USING: classes.struct struct-arrays tools.test kernel math sequences -alien.syntax alien.c-types destructors libc accessors sequences.private -compiler.tree.debugger combinators.smart ; - -STRUCT: test-struct-array - { x int } - { y int } ; - -[ 1 ] [ - 1 struct-array{ test-struct-array } new-sequence length -] unit-test - -[ V{ test-struct-array } ] [ - [ [ test-struct-array ] struct-array{ test-struct-array } output>sequence first ] final-classes -] unit-test - -: make-point ( x y -- struct ) - test-struct-array ; - -[ 5/4 ] [ - 2 test-struct-array - 1 2 make-point over set-first - 3 4 make-point over set-second - 0 [ [ x>> ] [ y>> ] bi / + ] reduce -] unit-test - -[ 5/4 ] [ - [ - 2 test-struct-array malloc-struct-array - dup &free drop - 1 2 make-point over set-first - 3 4 make-point over set-second - 0 [ [ x>> ] [ y>> ] bi / + ] reduce - ] with-destructors -] unit-test - -[ ] [ ALIEN: 123 10 test-struct-array drop ] unit-test - -[ ] [ - [ - 10 test-struct-array malloc-struct-array - &free drop - ] with-destructors -] unit-test - -[ 15 ] [ 15 10 test-struct-array resize length ] unit-test - -[ S{ test-struct-array f 12 20 } ] [ - struct-array{ test-struct-array - S{ test-struct-array f 4 20 } - S{ test-struct-array f 12 20 } - S{ test-struct-array f 20 20 } - } second -] unit-test - -! Regression -STRUCT: fixed-string { text char[100] } ; - -[ { ALIEN: 123 ALIEN: 223 ALIEN: 323 ALIEN: 423 } ] [ - ALIEN: 123 4 fixed-string [ (underlying)>> ] { } map-as -] unit-test - -[ 10 "int" ] must-fail - -STRUCT: wig { x int } ; -: ( -- wig ) 0 wig ; inline -: waterfall ( -- a b ) 1 wig swap first x>> ; inline - -[ t ] [ [ waterfall ] { x>> } inlined? ] unit-test \ No newline at end of file diff --git a/basis/struct-arrays/struct-arrays.factor b/basis/struct-arrays/struct-arrays.factor deleted file mode 100755 index c578082602..0000000000 --- a/basis/struct-arrays/struct-arrays.factor +++ /dev/null @@ -1,100 +0,0 @@ -! Copyright (C) 2008 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien alien.c-types alien.structs byte-arrays -classes classes.struct kernel libc math parser sequences -sequences.private words fry memoize compiler.units ; -IN: struct-arrays - -TUPLE: struct-array -{ underlying c-ptr read-only } -{ length array-capacity read-only } -{ element-size array-capacity read-only } -{ class read-only } -{ ctor read-only } ; - -> * >fixnum ] [ underlying>> ] bi ; inline - -: (struct-element-constructor) ( struct-class -- word ) - [ - "struct-array-ctor" f - [ swap '[ _ memory>struct ] (( alien -- object )) define-inline ] keep - ] with-compilation-unit ; - -! Foldable memo word. This is an optimization; by precompiling a -! constructor for array elements, we avoid memory>struct's slow path. -MEMO: struct-element-constructor ( struct-class -- word ) - (struct-element-constructor) ; foldable - -PRIVATE> - -M: struct-array length length>> ; inline - -M: struct-array byte-length [ length>> ] [ element-size>> ] bi * ; inline - -M: struct-array nth-unsafe - [ (nth-ptr) ] [ ctor>> ] bi execute( alien -- object ) ; inline - -M: struct-array set-nth-unsafe - [ (nth-ptr) swap ] [ element-size>> ] bi memcpy ; inline - -ERROR: not-a-struct-class struct-class ; - -: ( alien length struct-class -- struct-array ) - dup struct-class? [ not-a-struct-class ] unless - [ heap-size ] [ ] [ struct-element-constructor ] - tri struct-array boa ; inline - -M: struct-array new-sequence - [ element-size>> * (byte-array) ] [ class>> ] 2bi - ; inline - -M: struct-array resize ( n seq -- newseq ) - [ [ element-size>> * ] [ underlying>> ] bi resize ] [ class>> ] 2bi - ; inline - -: ( length struct-class -- struct-array ) - [ heap-size * ] 2keep ; inline - -ERROR: bad-byte-array-length byte-array ; - -: byte-array>struct-array ( byte-array c-type -- struct-array ) - [ - heap-size - [ dup length ] dip /mod 0 = - [ drop bad-byte-array-length ] unless - ] keep ; inline - -: struct-array-on ( struct length -- struct-array ) - [ [ >c-ptr ] [ class ] bi ] dip swap ; inline - -: malloc-struct-array ( length c-type -- struct-array ) - [ heap-size calloc ] 2keep ; inline - -INSTANCE: struct-array sequence - -M: struct-type ( len c-type -- array ) - dup c-array-constructor - [ execute( len -- array ) ] - [ ] ?if ; inline - -M: struct-type ( alien len c-type -- array ) - dup c-direct-array-constructor - [ execute( alien len -- array ) ] - [ ] ?if ; inline - -: >struct-array ( sequence class -- struct-array ) - [ dup length ] dip - [ 0 swap copy ] keep ; inline - -SYNTAX: struct-array{ - \ } scan-word [ >struct-array ] curry parse-literal ; - -SYNTAX: struct-array@ - scan-word [ scan-object scan-object ] dip parsed ; - -USING: vocabs vocabs.loader ; - -"prettyprint" vocab [ "struct-arrays.prettyprint" require ] when diff --git a/basis/struct-arrays/summary.txt b/basis/struct-arrays/summary.txt deleted file mode 100644 index 0458b5a806..0000000000 --- a/basis/struct-arrays/summary.txt +++ /dev/null @@ -1 +0,0 @@ -Arrays of C structs and unions diff --git a/basis/struct-arrays/tags.txt b/basis/struct-arrays/tags.txt deleted file mode 100644 index 42d711b32b..0000000000 --- a/basis/struct-arrays/tags.txt +++ /dev/null @@ -1 +0,0 @@ -collections diff --git a/basis/struct-vectors/struct-vectors-docs.factor b/basis/struct-vectors/struct-vectors-docs.factor deleted file mode 100644 index fe1b8991cf..0000000000 --- a/basis/struct-vectors/struct-vectors-docs.factor +++ /dev/null @@ -1,16 +0,0 @@ -IN: struct-vectors -USING: help.markup help.syntax classes.struct alien strings math ; - -HELP: struct-vector -{ $class-description "The class of growable C struct and union arrays." } ; - -HELP: -{ $values { "capacity" integer } { "struct-class" struct-class } { "struct-vector" struct-vector } } -{ $description "Creates a new vector with the given initial capacity." } ; - -ARTICLE: "struct-vectors" "C struct and union vectors" -"The " { $vocab-link "struct-vectors" } " vocabulary implements vectors specialized for holding C struct and union values. These are growable versions of " { $vocab-link "struct-arrays" } "." -{ $subsection struct-vector } -{ $subsection } ; - -ABOUT: "struct-vectors" diff --git a/basis/struct-vectors/struct-vectors-tests.factor b/basis/struct-vectors/struct-vectors-tests.factor deleted file mode 100644 index dec2e96040..0000000000 --- a/basis/struct-vectors/struct-vectors-tests.factor +++ /dev/null @@ -1,16 +0,0 @@ -IN: struct-vectors.tests -USING: struct-vectors tools.test alien.c-types classes.struct accessors -namespaces kernel sequences ; - -STRUCT: point { x float } { y float } ; - -: make-point ( x y -- point ) point ; - -[ ] [ 1 point "v" set ] unit-test - -[ 1.5 6.0 ] [ - 1.0 2.0 make-point "v" get push - 3.0 4.5 make-point "v" get push - 1.5 6.0 make-point "v" get push - "v" get pop [ x>> ] [ y>> ] bi -] unit-test \ No newline at end of file diff --git a/basis/struct-vectors/struct-vectors.factor b/basis/struct-vectors/struct-vectors.factor deleted file mode 100644 index d4aa03c7ed..0000000000 --- a/basis/struct-vectors/struct-vectors.factor +++ /dev/null @@ -1,25 +0,0 @@ -! Copyright (C) 2009 Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types byte-arrays growable kernel math sequences -sequences.private struct-arrays ; -IN: struct-vectors - -TUPLE: struct-vector -{ underlying struct-array } -{ length array-capacity } -{ c-type read-only } ; - -: ( capacity struct-class -- struct-vector ) - [ 0 ] keep struct-vector boa ; inline - -M: struct-vector byte-length underlying>> byte-length ; - -M: struct-vector new-sequence - [ c-type>> ] [ [ >fixnum ] [ c-type>> ] bi* ] 2bi - struct-vector boa ; - -M: struct-vector contract 2drop ; - -M: struct-array new-resizable c-type>> ; - -INSTANCE: struct-vector growable diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index e46d702e1f..42d1ee2a9f 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -72,13 +72,6 @@ IN: tools.deploy.shaker "vocab:tools/deploy/shaker/strip-destructors.factor" run-file ; -: strip-struct-arrays ( -- ) - "struct-arrays" vocab [ - "Stripping dynamic struct array code" show - "vocab:tools/deploy/shaker/strip-struct-arrays.factor" - run-file - ] when ; - : strip-call ( -- ) "Stripping stack effect checking from call( and execute(" show "vocab:tools/deploy/shaker/strip-call.factor" run-file ; @@ -498,7 +491,6 @@ SYMBOL: deploy-vocab : strip ( -- ) init-stripper strip-libc - strip-struct-arrays strip-destructors strip-call strip-cocoa diff --git a/basis/tools/deploy/shaker/strip-struct-arrays.factor b/basis/tools/deploy/shaker/strip-struct-arrays.factor deleted file mode 100644 index 022b5f1de9..0000000000 --- a/basis/tools/deploy/shaker/strip-struct-arrays.factor +++ /dev/null @@ -1,13 +0,0 @@ -USING: kernel stack-checker.transforms ; -IN: struct-arrays.private - -: struct-element-constructor ( c-type -- word ) - "Struct array usages must be compiled" throw ; - -<< - -\ struct-element-constructor [ - (struct-element-constructor) [ ] curry -] 1 define-transform - ->> \ No newline at end of file diff --git a/basis/ui/backend/windows/windows.factor b/basis/ui/backend/windows/windows.factor index fd06b2cb76..2be6e70df8 100755 --- a/basis/ui/backend/windows/windows.factor +++ b/basis/ui/backend/windows/windows.factor @@ -1,17 +1,20 @@ ! Copyright (C) 2005, 2006 Doug Coleman. ! Portions copyright (C) 2007, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: alien alien.c-types alien.strings arrays assocs ui ui.private -ui.gadgets ui.gadgets.private ui.backend ui.clipboards -ui.gadgets.worlds ui.gestures ui.event-loop io kernel math -math.vectors namespaces make sequences strings vectors words -windows.kernel32 windows.gdi32 windows.user32 windows.opengl32 -windows.messages windows.types windows.offscreen windows.nt -threads libc combinators fry combinators.short-circuit continuations -command-line shuffle opengl ui.render math.bitwise locals -accessors math.rectangles math.order calendar ascii sets -io.encodings.utf16n windows.errors literals ui.pixel-formats -ui.pixel-formats.private memoize classes struct-arrays classes.struct ; +USING: alien alien.c-types alien.strings arrays assocs ui +ui.private ui.gadgets ui.gadgets.private ui.backend +ui.clipboards ui.gadgets.worlds ui.gestures ui.event-loop io +kernel math math.vectors namespaces make sequences strings +vectors words windows.kernel32 windows.gdi32 windows.user32 +windows.opengl32 windows.messages windows.types +windows.offscreen windows.nt threads libc combinators fry +combinators.short-circuit continuations command-line shuffle +opengl ui.render math.bitwise locals accessors math.rectangles +math.order calendar ascii sets io.encodings.utf16n +windows.errors literals ui.pixel-formats +ui.pixel-formats.private memoize classes +specialized-arrays classes.struct ; +SPECIALIZED-ARRAY: POINT IN: ui.backend.windows SINGLETON: windows-ui-backend @@ -758,7 +761,7 @@ M: windows-ui-backend beep ( -- ) : client-area>RECT ( hwnd -- RECT ) RECT [ GetClientRect win32-error=0/f ] - [ >c-ptr "POINT" byte-array>struct-array [ ClientToScreen drop ] with each ] + [ >c-ptr byte-array>POINT-array [ ClientToScreen drop ] with each ] [ nip ] 2tri ; : hwnd>RECT ( hwnd -- RECT ) diff --git a/basis/ui/pens/gradient/gradient.factor b/basis/ui/pens/gradient/gradient.factor index 042e2d3446..53b4357d44 100644 --- a/basis/ui/pens/gradient/gradient.factor +++ b/basis/ui/pens/gradient/gradient.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors math math.vectors locals sequences -specialized-arrays.float colors arrays combinators +specialized-arrays colors arrays combinators opengl opengl.gl ui.pens ui.pens.caching ; +SPECIALIZED-ARRAY: float IN: ui.pens.gradient ! Gradient pen diff --git a/basis/ui/pens/polygon/polygon.factor b/basis/ui/pens/polygon/polygon.factor index d244cc71d2..a39a5cb7cd 100644 --- a/basis/ui/pens/polygon/polygon.factor +++ b/basis/ui/pens/polygon/polygon.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors colors help.markup help.syntax kernel opengl -opengl.gl sequences specialized-arrays.float math.vectors -ui.gadgets ui.pens ; +opengl.gl sequences math.vectors ui.gadgets ui.pens +specialized-arrays ; +SPECIALIZED-ARRAY: float IN: ui.pens.polygon ! Polygon pen diff --git a/basis/ui/pixel-formats/pixel-formats.factor b/basis/ui/pixel-formats/pixel-formats.factor index f463ae2b68..5dcd9bde9a 100644 --- a/basis/ui/pixel-formats/pixel-formats.factor +++ b/basis/ui/pixel-formats/pixel-formats.factor @@ -1,6 +1,7 @@ USING: accessors assocs classes destructors functors kernel -lexer math parser sequences specialized-arrays.int ui.backend +lexer math parser sequences specialized-arrays ui.backend words ; +SPECIALIZED-ARRAY: int IN: ui.pixel-formats SYMBOLS: diff --git a/basis/unix/utilities/utilities.factor b/basis/unix/utilities/utilities.factor index e1d26eab66..8d141ccb24 100644 --- a/basis/unix/utilities/utilities.factor +++ b/basis/unix/utilities/utilities.factor @@ -1,10 +1,12 @@ ! Copyright (C) 2008 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings -combinators.short-circuit fry kernel layouts sequences -specialized-arrays.alien accessors ; +combinators.short-circuit fry kernel layouts sequences accessors +specialized-arrays ; IN: unix.utilities +SPECIALIZED-ARRAY: void* + : more? ( alien -- ? ) { [ ] [ *void* ] } 1&& ; diff --git a/basis/windows/com/wrapper/wrapper.factor b/basis/windows/com/wrapper/wrapper.factor index 2cf6b31cf5..e69fc5b820 100755 --- a/basis/windows/com/wrapper/wrapper.factor +++ b/basis/windows/com/wrapper/wrapper.factor @@ -3,7 +3,8 @@ init windows.com.syntax.private windows.com continuations kernel namespaces windows.ole32 libc vocabs assocs accessors arrays sequences quotations combinators math words compiler.units destructors fry math.parser generalizations sets -specialized-arrays.alien windows.kernel32 classes.struct ; +specialized-arrays windows.kernel32 classes.struct ; +SPECIALIZED-ARRAY: void* IN: windows.com.wrapper TUPLE: com-wrapper < disposable callbacks vtbls ; diff --git a/basis/windows/dinput/constants/constants.factor b/basis/windows/dinput/constants/constants.factor index ec70a3cdd6..e0bfafc5c4 100755 --- a/basis/windows/dinput/constants/constants.factor +++ b/basis/windows/dinput/constants/constants.factor @@ -2,7 +2,8 @@ USING: windows.dinput windows.kernel32 windows.ole32 windows.com windows.com.syntax alien alien.c-types alien.syntax kernel system namespaces combinators sequences fry math accessors macros words quotations libc continuations generalizations splitting locals assocs init -struct-arrays memoize classes.struct ; +specialized-arrays memoize classes.struct ; +SPECIALIZED-ARRAY: DIOBJECTDATAFORMAT IN: windows.dinput.constants ! Some global variables aren't provided by the DirectInput DLL (they're in the @@ -49,7 +50,7 @@ MEMO: heap-size* ( c-type -- n ) heap-size ; DIOBJECTDATAFORMAT ; :: malloc-DIOBJECTDATAFORMAT-array ( struct array -- alien ) - [let | alien [ array length DIOBJECTDATAFORMAT malloc-struct-array ] | + [let | alien [ array length malloc-DIOBJECTDATAFORMAT-array ] | array [| args i | struct args i alien set-nth diff --git a/basis/windows/ole32/ole32-tests.factor b/basis/windows/ole32/ole32-tests.factor index c8358f5aa6..e7c92b5996 100644 --- a/basis/windows/ole32/ole32-tests.factor +++ b/basis/windows/ole32/ole32-tests.factor @@ -1,6 +1,7 @@ USING: kernel tools.test windows.ole32 alien.c-types -classes.struct specialized-arrays.uchar windows.kernel32 +classes.struct specialized-arrays windows.kernel32 windows.com.syntax ; +SPECIALIZED-ARRAY: uchar IN: windows.ole32.tests [ t ] [ diff --git a/basis/windows/ole32/ole32.factor b/basis/windows/ole32/ole32.factor index c7ccf38e43..9e117c8522 100755 --- a/basis/windows/ole32/ole32.factor +++ b/basis/windows/ole32/ole32.factor @@ -1,8 +1,9 @@ USING: alien alien.syntax alien.c-types alien.strings math -kernel sequences windows.errors windows.types io -accessors math.order namespaces make math.parser windows.kernel32 -combinators locals specialized-arrays.uchar -literals splitting grouping classes.struct combinators.smart ; +kernel sequences windows.errors windows.types io accessors +math.order namespaces make math.parser windows.kernel32 +combinators locals specialized-arrays literals splitting +grouping classes.struct combinators.smart ; +SPECIALIZED-ARRAY: uchar IN: windows.ole32 LIBRARY: ole32 diff --git a/basis/windows/shell32/shell32.factor b/basis/windows/shell32/shell32.factor index 47fed998c4..6b4e0d797e 100644 --- a/basis/windows/shell32/shell32.factor +++ b/basis/windows/shell32/shell32.factor @@ -4,7 +4,8 @@ USING: alien alien.c-types alien.strings alien.syntax classes.struct combinators io.encodings.utf16n io.files io.pathnames kernel windows.errors windows.com windows.com.syntax windows.user32 windows.ole32 windows -specialized-arrays.ushort ; +specialized-arrays ; +SPECIALIZED-ARRAY: ushort IN: windows.shell32 CONSTANT: CSIDL_DESKTOP HEX: 00 diff --git a/basis/x11/clipboard/clipboard.factor b/basis/x11/clipboard/clipboard.factor index 5cf6453443..c08ff1d176 100644 --- a/basis/x11/clipboard/clipboard.factor +++ b/basis/x11/clipboard/clipboard.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.strings classes.struct io.encodings.utf8 kernel namespaces sequences -specialized-arrays.int x11 x11.constants x11.xlib ; +specialized-arrays x11 x11.constants x11.xlib ; +SPECIALIZED-ARRAY: int IN: x11.clipboard ! This code was based on by McCLIM's Backends/CLX/port.lisp diff --git a/basis/x11/glx/glx.factor b/basis/x11/glx/glx.factor index 67ac0e8cc1..5bc58e5f0a 100644 --- a/basis/x11/glx/glx.factor +++ b/basis/x11/glx/glx.factor @@ -3,8 +3,9 @@ ! ! based on glx.h from xfree86, and some of glxtokens.h USING: alien alien.c-types alien.syntax x11 x11.xlib x11.syntax -namespaces make kernel sequences parser words specialized-arrays.int -accessors ; +namespaces make kernel sequences parser words +specialized-arrays accessors ; +SPECIALIZED-ARRAY: int IN: x11.glx LIBRARY: glx diff --git a/basis/x11/xim/xim.factor b/basis/x11/xim/xim.factor index 54f20a28dd..06add388b1 100644 --- a/basis/x11/xim/xim.factor +++ b/basis/x11/xim/xim.factor @@ -2,8 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.strings arrays byte-arrays hashtables io io.encodings.string kernel math namespaces -sequences strings continuations x11 x11.xlib specialized-arrays.uint -accessors io.encodings.utf16n ; +sequences strings continuations x11 x11.xlib +specialized-arrays accessors io.encodings.utf16n ; +SPECIALIZED-ARRAY: uint IN: x11.xim SYMBOL: xim diff --git a/core/assocs/assocs-tests.factor b/core/assocs/assocs-tests.factor index 9e36f9f00c..78c17a1cc0 100644 --- a/core/assocs/assocs-tests.factor +++ b/core/assocs/assocs-tests.factor @@ -1,6 +1,7 @@ USING: kernel math namespaces make tools.test vectors sequences sequences.private hashtables io prettyprint assocs -continuations specialized-arrays.double ; +continuations specialized-arrays ; +SPECIALIZED-ARRAY: double IN: assocs.tests [ t ] [ H{ } dup assoc-subset? ] unit-test diff --git a/core/generic/single/single-tests.factor b/core/generic/single/single-tests.factor index f59268b770..554e287a3b 100644 --- a/core/generic/single/single-tests.factor +++ b/core/generic/single/single-tests.factor @@ -1,9 +1,10 @@ -USING: tools.test math math.functions math.constants generic.standard -generic.single strings sequences arrays kernel accessors words -specialized-arrays.double byte-arrays bit-arrays parser namespaces -make quotations stack-checker vectors growable hashtables sbufs -prettyprint byte-vectors bit-vectors specialized-vectors.double +USING: tools.test math math.functions math.constants +generic.standard generic.single strings sequences arrays kernel +accessors words byte-arrays bit-arrays parser namespaces make +quotations stack-checker vectors growable hashtables sbufs +prettyprint byte-vectors bit-vectors specialized-vectors definitions generic sets graphs assocs grouping see eval ; +SPECIALIZED-VECTOR: double IN: generic.single.tests GENERIC: lo-tag-test ( obj -- obj' ) diff --git a/core/vocabs/parser/parser.factor b/core/vocabs/parser/parser.factor index 7ac0bd2e58..2fc9d05d79 100755 --- a/core/vocabs/parser/parser.factor +++ b/core/vocabs/parser/parser.factor @@ -86,6 +86,11 @@ PRIVATE> [ manifest get (>>current-vocab) ] [ words>> (add-qualified) ] bi ; +: with-current-vocab ( name quot -- ) + manifest get clone manifest [ + [ set-current-vocab ] dip call + ] with-variable ; inline + TUPLE: no-current-vocab ; : no-current-vocab ( -- vocab ) diff --git a/extra/alien/marshall/marshall.factor b/extra/alien/marshall/marshall.factor index d861178fad..2cae122641 100644 --- a/extra/alien/marshall/marshall.factor +++ b/extra/alien/marshall/marshall.factor @@ -4,15 +4,22 @@ USING: accessors alien alien.c-types alien.inline.types alien.marshall.private alien.strings byte-arrays classes combinators combinators.short-circuit destructors fry io.encodings.utf8 kernel libc sequences -specialized-arrays.alien specialized-arrays.bool -specialized-arrays.char specialized-arrays.double -specialized-arrays.float specialized-arrays.int -specialized-arrays.long specialized-arrays.longlong -specialized-arrays.short specialized-arrays.uchar -specialized-arrays.uint specialized-arrays.ulong -specialized-arrays.ulonglong specialized-arrays.ushort strings -unix.utilities vocabs.parser words libc.private struct-arrays -locals generalizations math ; +specialized-arrays strings unix.utilities vocabs.parser +words libc.private locals generalizations math ; +SPECIALIZED-ARRAY: bool +SPECIALIZED-ARRAY: char +SPECIALIZED-ARRAY: double +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: long +SPECIALIZED-ARRAY: longlong +SPECIALIZED-ARRAY: short +SPECIALIZED-ARRAY: uchar +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: ulong +SPECIALIZED-ARRAY: ulonglong +SPECIALIZED-ARRAY: ushort +SPECIALIZED-ARRAY: void* IN: alien.marshall << primitive-types [ [ "void*" = ] [ "bool" = ] bi or not ] @@ -39,7 +46,6 @@ M: class-wrapper c++-type class name>> parse-c++-type ; { [ dup not ] [ ] } { [ dup byte-array? ] [ malloc-byte-array ] } { [ dup alien-wrapper? ] [ underlying>> ] } - { [ dup struct-array? ] [ underlying>> ] } } cond ; : marshall-primitive ( n -- n ) diff --git a/extra/alien/marshall/private/private.factor b/extra/alien/marshall/private/private.factor index 70b03e2bab..c85b722d11 100644 --- a/extra/alien/marshall/private/private.factor +++ b/extra/alien/marshall/private/private.factor @@ -2,8 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.inline arrays combinators fry functors kernel lexer libc macros math -sequences specialized-arrays.alien libc.private +sequences specialized-arrays libc.private combinators.short-circuit ; +SPECIALIZED-ARRAY: void* IN: alien.marshall.private : bool>arg ( ? -- 1/0/obj ) diff --git a/extra/benchmark/dawes/dawes.factor b/extra/benchmark/dawes/dawes.factor index 5cd40bc098..ebfa37cdbc 100644 --- a/extra/benchmark/dawes/dawes.factor +++ b/extra/benchmark/dawes/dawes.factor @@ -1,16 +1,15 @@ -USING: sequences hints kernel math specialized-arrays.int fry ; +USING: sequences kernel math specialized-arrays fry ; +SPECIALIZED-ARRAY: int IN: benchmark.dawes ! Phil Dawes's performance problem : count-ones ( int-array -- n ) [ 1 = ] count ; inline -HINTS: count-ones int-array ; - : make-int-array ( -- int-array ) - 120000 [ 255 bitand ] int-array{ } map-as ; + 120000 [ 255 bitand ] int-array{ } map-as ; inline : dawes-benchmark ( -- ) - make-int-array 200 swap '[ _ count-ones ] replicate drop ; + 200 make-int-array '[ _ count-ones ] replicate drop ; MAIN: dawes-benchmark diff --git a/extra/benchmark/dispatch2/dispatch2.factor b/extra/benchmark/dispatch2/dispatch2.factor index c9d4f9ffa2..5dcefdda5a 100644 --- a/extra/benchmark/dispatch2/dispatch2.factor +++ b/extra/benchmark/dispatch2/dispatch2.factor @@ -1,5 +1,6 @@ USING: make math sequences splitting grouping -kernel columns specialized-arrays.double bit-arrays ; +kernel columns specialized-arrays bit-arrays ; +SPECIALIZED-ARRAY: double IN: benchmark.dispatch2 : sequences ( -- seq ) diff --git a/extra/benchmark/dispatch3/dispatch3.factor b/extra/benchmark/dispatch3/dispatch3.factor index 94925f0d79..58301b57af 100644 --- a/extra/benchmark/dispatch3/dispatch3.factor +++ b/extra/benchmark/dispatch3/dispatch3.factor @@ -1,6 +1,7 @@ USING: sequences math mirrors splitting grouping kernel make assocs alien.syntax columns -specialized-arrays.double bit-arrays ; +specialized-arrays bit-arrays ; +SPECIALIZED-ARRAY: double IN: benchmark.dispatch3 GENERIC: g ( obj -- str ) diff --git a/extra/benchmark/fasta/fasta.factor b/extra/benchmark/fasta/fasta.factor index c1d554a5a3..5b1a50c9e6 100755 --- a/extra/benchmark/fasta/fasta.factor +++ b/extra/benchmark/fasta/fasta.factor @@ -1,7 +1,8 @@ ! Based on http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=java&id=2 USING: math kernel io io.files locals multiline assocs sequences -sequences.private benchmark.reverse-complement hints io.encodings.ascii -byte-arrays specialized-arrays.double ; +sequences.private benchmark.reverse-complement hints +io.encodings.ascii byte-arrays specialized-arrays ; +SPECIALIZED-ARRAY: double IN: benchmark.fasta CONSTANT: IM 139968 diff --git a/extra/benchmark/nbody-simd/nbody-simd.factor b/extra/benchmark/nbody-simd/nbody-simd.factor index e83f3ddc01..e8bef58923 100644 --- a/extra/benchmark/nbody-simd/nbody-simd.factor +++ b/extra/benchmark/nbody-simd/nbody-simd.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors fry kernel locals math math.constants math.functions math.vectors math.vectors.simd prettyprint -combinators.smart sequences hints struct-arrays classes.struct ; +combinators.smart sequences hints classes.struct +specialized-arrays ; IN: benchmark.nbody-simd : solar-mass ( -- x ) 4 pi sq * ; inline @@ -13,6 +14,8 @@ STRUCT: body { velocity double-4 } { mass double } ; +SPECIALIZED-ARRAY: body + : ( location velocity mass -- body ) [ days-per-year v*n ] [ solar-mass * ] bi* body ; inline @@ -46,16 +49,14 @@ STRUCT: body : offset-momentum ( body offset -- body ) vneg solar-mass v/n >>velocity ; inline -TUPLE: nbody-system { bodies struct-array read-only } ; - : init-bodies ( bodies -- ) [ first ] [ [ [ velocity>> ] [ mass>> ] bi v*n ] [ v+ ] map-reduce ] bi offset-momentum drop ; inline : ( -- system ) [ ] - struct-array{ body } output>sequence nbody-system boa - dup bodies>> init-bodies ; inline + body-array{ } output>sequence + dup init-bodies ; inline :: each-pair ( bodies pair-quot: ( other-body body -- ) each-quot: ( body -- ) -- ) bodies [| body i | @@ -77,7 +78,6 @@ TUPLE: nbody-system { bodies struct-array read-only } ; [ [ other-body ] 2dip '[ body mass>> _ * _ n*v v+ ] change-velocity drop ] 2bi ; inline : advance ( system dt -- ) - [ bodies>> ] dip [ '[ _ update-velocity ] [ drop ] each-pair ] [ '[ _ update-position ] each ] 2bi ; inline @@ -89,7 +89,7 @@ TUPLE: nbody-system { bodies struct-array read-only } ; [ [ mass>> ] bi@ * ] [ [ location>> ] bi@ distance ] 2bi / ; inline : energy ( system -- x ) - [ 0.0 ] dip bodies>> [ newton's-law - ] [ inertia + ] each-pair ; inline + [ 0.0 ] dip [ newton's-law - ] [ inertia + ] each-pair ; inline : nbody ( n -- ) >fixnum diff --git a/extra/benchmark/nbody/nbody.factor b/extra/benchmark/nbody/nbody.factor index 983da88821..fc1cbaa12c 100644 --- a/extra/benchmark/nbody/nbody.factor +++ b/extra/benchmark/nbody/nbody.factor @@ -1,8 +1,9 @@ ! Copyright (C) 2008, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors specialized-arrays.double fry kernel locals math -math.constants math.functions math.vectors prettyprint combinators.smart -sequences hints arrays ; +USING: accessors specialized-arrays fry kernel locals math +math.constants math.functions math.vectors prettyprint +combinators.smart sequences hints arrays ; +SPECIALIZED-ARRAY: double IN: benchmark.nbody : solar-mass ( -- x ) 4 pi sq * ; inline diff --git a/extra/benchmark/raytracer-simd/authors.txt b/extra/benchmark/raytracer-simd/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/benchmark/raytracer-simd/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/benchmark/raytracer-simd/raytracer-simd.factor b/extra/benchmark/raytracer-simd/raytracer-simd.factor new file mode 100644 index 0000000000..3712972862 --- /dev/null +++ b/extra/benchmark/raytracer-simd/raytracer-simd.factor @@ -0,0 +1,187 @@ +! Factor port of the raytracer benchmark from +! http://www.ffconsultancy.com/free/ray_tracer/languages.html + +USING: arrays accessors io io.files io.files.temp +io.encodings.binary kernel math math.constants math.functions +math.vectors math.vectors.simd math.parser make sequences +sequences.private words hints classes.struct ; +IN: benchmark.raytracer-simd + +! parameters + +! Normalized { -1 -3 2 }. +CONSTANT: light + double-4{ + -0.2672612419124244 + -0.8017837257372732 + 0.5345224838248488 + 0.0 + } + +CONSTANT: oversampling 4 + +CONSTANT: levels 3 + +CONSTANT: size 200 + +: delta ( -- n ) epsilon sqrt ; inline + +TUPLE: ray { orig double-4 read-only } { dir double-4 read-only } ; + +C: ray + +TUPLE: hit { normal double-4 read-only } { lambda float read-only } ; + +C: hit + +GENERIC: intersect-scene ( hit ray scene -- hit ) + +TUPLE: sphere { center double-4 read-only } { radius float read-only } ; + +C: sphere + +: sphere-v ( sphere ray -- v ) + [ center>> ] [ orig>> ] bi* v- ; inline + +: sphere-b ( v ray -- b ) + dir>> v. ; inline + +: sphere-d ( sphere b v -- d ) + [ radius>> sq ] [ sq ] [ norm-sq ] tri* - + ; inline + +: -+ ( x y -- x-y x+y ) + [ - ] [ + ] 2bi ; inline + +: sphere-t ( b d -- t ) + -+ dup 0.0 < + [ 2drop 1/0. ] [ [ [ 0.0 > ] keep ] dip ? ] if ; inline + +: sphere-b&v ( sphere ray -- b v ) + [ sphere-v ] [ nip ] 2bi + [ sphere-b ] [ drop ] 2bi ; inline + +: ray-sphere ( sphere ray -- t ) + [ drop ] [ sphere-b&v ] 2bi + [ drop ] [ sphere-d ] 3bi + dup 0.0 < [ 3drop 1/0. ] [ sqrt sphere-t nip ] if ; inline + +: if-ray-sphere ( hit ray sphere quot -- hit ) + #! quot: hit ray sphere l -- hit + [ + [ ] [ swap ray-sphere nip ] [ 2drop lambda>> ] 3tri + [ drop ] [ < ] 2bi + ] dip [ 3drop ] if ; inline + +: sphere-n ( ray sphere l -- n ) + [ [ orig>> ] [ dir>> ] bi ] [ center>> ] [ ] tri* + swap [ v*n ] dip v- v+ ; inline + +M: sphere intersect-scene ( hit ray sphere -- hit ) + [ [ sphere-n normalize ] keep nip ] if-ray-sphere ; + +HINTS: M\ sphere intersect-scene { hit ray sphere } ; + +TUPLE: group < sphere { objs array read-only } ; + +: ( objs bound -- group ) + [ center>> ] [ radius>> ] bi rot group boa ; inline + +: make-group ( bound quot -- ) + swap [ { } make ] dip ; inline + +M: group intersect-scene ( hit ray group -- hit ) + [ drop objs>> [ intersect-scene ] with each ] if-ray-sphere ; + +HINTS: M\ group intersect-scene { hit ray group } ; + +CONSTANT: initial-hit T{ hit f double-4{ 0.0 0.0 0.0 0.0 } 1/0. } + +: initial-intersect ( ray scene -- hit ) + [ initial-hit ] 2dip intersect-scene ; inline + +: ray-o ( ray hit -- o ) + [ [ orig>> ] [ normal>> delta v*n ] bi* ] + [ [ dir>> ] [ lambda>> ] bi* v*n ] + 2bi v+ v+ ; inline + +: sray-intersect ( ray scene hit -- ray ) + swap [ ray-o light vneg ] dip initial-intersect ; inline + +: ray-g ( hit -- g ) normal>> light v. ; inline + +: cast-ray ( ray scene -- g ) + 2dup initial-intersect dup lambda>> 1/0. = [ + 3drop 0.0 + ] [ + [ sray-intersect lambda>> 1/0. = ] keep swap + [ ray-g neg ] [ drop 0.0 ] if + ] if ; inline + +: create-center ( c r d -- c2 ) + [ 3.0 12.0 sqrt / * ] dip n*v v+ ; inline + +DEFER: create ( level c r -- scene ) + +: create-step ( level c r d -- scene ) + over [ create-center ] dip 2.0 / [ 1 - ] 2dip create ; + +: create-offsets ( quot -- ) + { + double-4{ -1.0 1.0 -1.0 0.0 } + double-4{ 1.0 1.0 -1.0 0.0 } + double-4{ -1.0 1.0 1.0 0.0 } + double-4{ 1.0 1.0 1.0 0.0 } + } swap each ; inline + +: create-bound ( c r -- sphere ) 3.0 * ; + +: create-group ( level c r -- scene ) + 2dup create-bound [ + 2dup , + [ [ 3dup ] dip create-step , ] create-offsets 3drop + ] make-group ; + +: create ( level c r -- scene ) + pick 1 = [ nip ] [ create-group ] if ; + +: ss-point ( dx dy -- point ) + [ oversampling /f ] bi@ 0.0 0.0 double-4-boa ; + +: ss-grid ( -- ss-grid ) + oversampling [ oversampling [ ss-point ] with map ] map ; + +: ray-grid ( point ss-grid -- ray-grid ) + [ + [ v+ normalize double-4{ 0.0 0.0 -4.0 0.0 } swap ] with map + ] with map ; + +: ray-pixel ( scene point -- n ) + ss-grid ray-grid [ 0.0 ] 2dip + [ [ swap cast-ray + ] with each ] with each ; + +: pixel-grid ( -- grid ) + size reverse [ + size [ + [ size 0.5 * - ] bi@ swap size + 0.0 double-4-boa + ] with map + ] map ; + +: pgm-header ( w h -- ) + "P5\n" % swap # " " % # "\n255\n" % ; + +: pgm-pixel ( n -- ) 255 * 0.5 + >fixnum , ; + +: ray-trace ( scene -- pixels ) + pixel-grid [ [ ray-pixel ] with map ] with map ; + +: run ( -- string ) + levels double-4{ 0.0 -1.0 0.0 0.0 } 1.0 create ray-trace [ + size size pgm-header + [ [ oversampling sq / pgm-pixel ] each ] each + ] B{ } make ; + +: raytracer-main ( -- ) + run "raytracer.pnm" temp-file binary set-file-contents ; + +MAIN: raytracer-main diff --git a/extra/benchmark/raytracer/raytracer.factor b/extra/benchmark/raytracer/raytracer.factor index 4b60576bd1..96f345510f 100755 --- a/extra/benchmark/raytracer/raytracer.factor +++ b/extra/benchmark/raytracer/raytracer.factor @@ -1,10 +1,11 @@ ! Factor port of the raytracer benchmark from ! http://www.ffconsultancy.com/free/ray_tracer/languages.html -USING: arrays accessors specialized-arrays.double io io.files +USING: arrays accessors specialized-arrays io io.files io.files.temp io.encodings.binary kernel math math.constants math.functions math.vectors math.parser make sequences sequences.private words hints ; +SPECIALIZED-ARRAY: double IN: benchmark.raytracer ! parameters diff --git a/extra/benchmark/simd-1/authors.txt b/extra/benchmark/simd-1/authors.txt new file mode 100644 index 0000000000..d4f5d6b3ae --- /dev/null +++ b/extra/benchmark/simd-1/authors.txt @@ -0,0 +1 @@ +Slava Pestov \ No newline at end of file diff --git a/extra/benchmark/simd-1/simd-1.factor b/extra/benchmark/simd-1/simd-1.factor new file mode 100644 index 0000000000..d5576b8cf5 --- /dev/null +++ b/extra/benchmark/simd-1/simd-1.factor @@ -0,0 +1,30 @@ +! Copyright (C) 2009 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel io math math.functions math.parser math.vectors +math.vectors.simd sequences specialized-arrays ; +SPECIALIZED-ARRAY: float-4 +IN: benchmark.simd-1 + +: ( n -- float-4 ) + >float [ sin ] [ cos 3 * ] [ sin sq 2 / ] tri + 0.0 float-4-boa ; inline + +: make-points ( len -- points ) + iota [ ] float-4-array{ } map-as ; inline + +: normalize-points ( points -- ) + [ normalize ] change-each ; inline + +: max-points ( points -- point ) + [ ] [ vmax ] map-reduce ; inline + +: print-point ( point -- ) + [ number>string ] { } map-as ", " join print ; inline + +: simd-benchmark ( len -- ) + >fixnum make-points [ normalize-points ] [ max-points ] bi print-point ; + +: main ( -- ) + 5000000 simd-benchmark ; + +MAIN: main diff --git a/extra/benchmark/spectral-norm/spectral-norm.factor b/extra/benchmark/spectral-norm/spectral-norm.factor index b86e11e239..4f93367b8a 100644 --- a/extra/benchmark/spectral-norm/spectral-norm.factor +++ b/extra/benchmark/spectral-norm/spectral-norm.factor @@ -1,8 +1,9 @@ ! Factor port of ! http://shootout.alioth.debian.org/gp4/benchmark.php?test=spectralnorm&lang=all -USING: specialized-arrays.double kernel math math.functions +USING: specialized-arrays kernel math math.functions math.vectors sequences sequences.private prettyprint words hints locals ; +SPECIALIZED-ARRAY: double IN: benchmark.spectral-norm :: inner-loop ( u n quot -- seq ) diff --git a/extra/benchmark/struct-arrays/struct-arrays.factor b/extra/benchmark/struct-arrays/struct-arrays.factor index faed2f4dca..799ef2d467 100644 --- a/extra/benchmark/struct-arrays/struct-arrays.factor +++ b/extra/benchmark/struct-arrays/struct-arrays.factor @@ -2,11 +2,13 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors classes.struct combinators.smart fry kernel math math.functions math.order math.parser sequences -struct-arrays io ; +specialized-arrays io ; IN: benchmark.struct-arrays STRUCT: point { x float } { y float } { z float } ; +SPECIALIZED-ARRAY: point + : xyz ( point -- x y z ) [ x>> ] [ y>> ] [ z>> ] tri ; inline @@ -19,7 +21,7 @@ STRUCT: point { x float } { y float } { z float } ; 1 + ; inline : make-points ( len -- points ) - point dup 0 [ init-point ] reduce drop ; inline + dup 0 [ init-point ] reduce drop ; inline : point-norm ( point -- norm ) [ xyz [ absq ] tri@ ] sum-outputs sqrt ; inline diff --git a/extra/bunny/fixed-pipeline/fixed-pipeline.factor b/extra/bunny/fixed-pipeline/fixed-pipeline.factor index 0791773ba7..07528c35e8 100755 --- a/extra/bunny/fixed-pipeline/fixed-pipeline.factor +++ b/extra/bunny/fixed-pipeline/fixed-pipeline.factor @@ -1,6 +1,6 @@ USING: alien.c-types continuations destructors kernel -opengl opengl.gl bunny.model specialized-arrays.float -accessors ; +opengl opengl.gl bunny.model specialized-arrays accessors ; +SPECIALIZED-ARRAY: float IN: bunny.fixed-pipeline TUPLE: bunny-fixed-pipeline ; diff --git a/extra/bunny/model/model.factor b/extra/bunny/model/model.factor index 3871936902..dd6730b57f 100755 --- a/extra/bunny/model/model.factor +++ b/extra/bunny/model/model.factor @@ -2,8 +2,9 @@ USING: accessors alien.c-types arrays combinators destructors http.client io io.encodings.ascii io.files io.files.temp kernel math math.matrices math.parser math.vectors opengl opengl.capabilities opengl.gl opengl.demo-support sequences -splitting vectors words specialized-arrays.float -specialized-arrays.uint ; +splitting vectors words specialized-arrays ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: uint IN: bunny.model : numbers ( str -- seq ) diff --git a/extra/gpu/demos/bunny/bunny.factor b/extra/gpu/demos/bunny/bunny.factor index 44ce63692e..10e49984a1 100755 --- a/extra/gpu/demos/bunny/bunny.factor +++ b/extra/gpu/demos/bunny/bunny.factor @@ -1,12 +1,14 @@ ! (c)2009 Joe Groff bsd license USING: accessors alien.c-types arrays classes.struct combinators -combinators.short-circuit game-worlds gpu gpu.buffers gpu.util.wasd -gpu.framebuffers gpu.render gpu.shaders gpu.state gpu.textures gpu.util -grouping http.client images images.loader io io.encodings.ascii io.files -io.files.temp kernel math math.matrices math.parser math.vectors -method-chains sequences specialized-arrays.float specialized-vectors.uint -splitting struct-vectors threads ui ui.gadgets ui.gadgets.worlds -ui.pixel-formats ; +combinators.short-circuit game-worlds gpu gpu.buffers +gpu.util.wasd gpu.framebuffers gpu.render gpu.shaders gpu.state +gpu.textures gpu.util grouping http.client images images.loader +io io.encodings.ascii io.files io.files.temp kernel math +math.matrices math.parser math.vectors method-chains sequences +splitting threads ui ui.gadgets ui.gadgets.worlds +ui.pixel-formats specialized-arrays specialized-vectors ; +SPECIALIZED-ARRAY: float +SPECIALIZED-VECTOR: uint IN: gpu.demos.bunny GLSL-SHADER-FILE: bunny-vertex-shader vertex-shader "bunny.v.glsl" @@ -51,6 +53,8 @@ VERTEX-FORMAT: bunny-vertex { f float-components 1 f } ; VERTEX-STRUCT: bunny-vertex-struct bunny-vertex +SPECIALIZED-VECTOR: bunny-vertex-struct + UNIFORM-TUPLE: bunny-uniforms < mvp-uniforms { "light-position" vec3-uniform f } { "color" vec4-uniform f } @@ -86,7 +90,7 @@ UNIFORM-TUPLE: loading-uniforms ] when* ; : parse-bunny-model ( -- vertexes indexes ) - 100000 bunny-vertex-struct + 100000 100000 (parse-bunny-model) ; diff --git a/extra/gpu/demos/bunny/deploy.factor b/extra/gpu/demos/bunny/deploy.factor new file mode 100644 index 0000000000..fe80da122e --- /dev/null +++ b/extra/gpu/demos/bunny/deploy.factor @@ -0,0 +1,14 @@ +USING: tools.deploy.config ; +H{ + { deploy-name "gpu.demos.bunny" } + { deploy-word-defs? f } + { deploy-io 3 } + { "stop-after-last-window?" t } + { deploy-math? t } + { deploy-word-props? f } + { deploy-threads? t } + { deploy-c-types? f } + { deploy-reflection 2 } + { deploy-unicode? f } + { deploy-ui? t } +} diff --git a/extra/gpu/framebuffers/framebuffers.factor b/extra/gpu/framebuffers/framebuffers.factor index 12bc3430c3..efd71782d0 100755 --- a/extra/gpu/framebuffers/framebuffers.factor +++ b/extra/gpu/framebuffers/framebuffers.factor @@ -3,8 +3,9 @@ USING: accessors alien.c-types arrays byte-arrays combinators destructors gpu gpu.buffers gpu.private gpu.textures gpu.textures.private images kernel locals math math.rectangles opengl opengl.framebuffers opengl.gl opengl.textures sequences -specialized-arrays.int specialized-arrays.uint -ui.gadgets.worlds variants ; +specialized-arrays ui.gadgets.worlds variants ; +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: uint IN: gpu.framebuffers SINGLETON: system-framebuffer diff --git a/extra/gpu/render/render-docs.factor b/extra/gpu/render/render-docs.factor index 171c9bb031..f323c1ee3b 100755 --- a/extra/gpu/render/render-docs.factor +++ b/extra/gpu/render/render-docs.factor @@ -2,8 +2,12 @@ USING: alien alien.syntax byte-arrays classes gpu.buffers gpu.framebuffers gpu.shaders gpu.textures help.markup help.syntax images kernel math multiline sequences -specialized-arrays.alien specialized-arrays.uint -specialized-arrays.ulong strings ; +specialized-arrays strings ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: ulong +SPECIALIZED-ARRAY: void* IN: gpu.render HELP: diff --git a/extra/gpu/render/render.factor b/extra/gpu/render/render.factor index 2f920645ed..c0dca56551 100644 --- a/extra/gpu/render/render.factor +++ b/extra/gpu/render/render.factor @@ -7,9 +7,12 @@ gpu.framebuffers.private gpu.shaders gpu.shaders.private gpu.state gpu.textures gpu.textures.private half-floats images kernel lexer locals math math.order math.parser namespaces opengl opengl.gl parser quotations sequences slots sorting -specialized-arrays.alien specialized-arrays.float specialized-arrays.int -specialized-arrays.uint strings ui.gadgets.worlds variants +specialized-arrays strings ui.gadgets.worlds variants vocabs.parser words ; +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: void* IN: gpu.render UNION: ?integer integer POSTPONE: f ; diff --git a/extra/gpu/shaders/shaders.factor b/extra/gpu/shaders/shaders.factor index a247158684..91bc760673 100755 --- a/extra/gpu/shaders/shaders.factor +++ b/extra/gpu/shaders/shaders.factor @@ -1,15 +1,16 @@ ! (c)2009 Joe Groff bsd license -USING: accessors alien alien.c-types alien.strings -arrays assocs byte-arrays classes.mixin classes.parser -classes.singleton classes.struct combinators -combinators.short-circuit definitions destructors -generic.parser gpu gpu.buffers hashtables images +USING: accessors alien alien.c-types alien.strings arrays assocs +byte-arrays classes.mixin classes.parser classes.singleton +classes.struct combinators combinators.short-circuit definitions +destructors generic.parser gpu gpu.buffers hashtables images io.encodings.ascii io.files io.pathnames kernel lexer literals locals math math.parser memoize multiline namespaces opengl opengl.gl opengl.shaders parser quotations sequences -specialized-arrays.alien specialized-arrays.int splitting -strings tr ui.gadgets.worlds variants vectors vocabs vocabs.loader -vocabs.parser words words.constant ; +specialized-arrays splitting strings tr ui.gadgets.worlds +variants vectors vocabs vocabs.loader vocabs.parser words +words.constant ; +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: void* IN: gpu.shaders VARIANT: shader-kind diff --git a/extra/gpu/state/state.factor b/extra/gpu/state/state.factor index 6027be74b5..02d6046722 100755 --- a/extra/gpu/state/state.factor +++ b/extra/gpu/state/state.factor @@ -1,7 +1,9 @@ ! (c)2009 Joe Groff bsd license USING: accessors alien.c-types arrays byte-arrays combinators gpu kernel literals math math.rectangles opengl opengl.gl sequences -variants specialized-arrays.int specialized-arrays.float ; +variants specialized-arrays ; +SPECIALIZED-ARRAY: int +SPECIALIZED-ARRAY: float IN: gpu.state UNION: ?rect rect POSTPONE: f ; diff --git a/extra/gpu/textures/textures.factor b/extra/gpu/textures/textures.factor index a2e6ffd440..8015ff9a9b 100644 --- a/extra/gpu/textures/textures.factor +++ b/extra/gpu/textures/textures.factor @@ -2,7 +2,8 @@ USING: accessors alien.c-types arrays byte-arrays combinators destructors fry gpu gpu.buffers images kernel locals math opengl opengl.gl opengl.textures sequences -specialized-arrays.float ui.gadgets.worlds variants ; +specialized-arrays ui.gadgets.worlds variants ; +SPECIALIZED-ARRAY: float IN: gpu.textures TUPLE: texture < gpu-object diff --git a/extra/gpu/util/util.factor b/extra/gpu/util/util.factor index 512cea4a17..862c94d4b3 100644 --- a/extra/gpu/util/util.factor +++ b/extra/gpu/util/util.factor @@ -1,6 +1,7 @@ ! (c)2009 Joe Groff bsd license USING: gpu.buffers gpu.render gpu.shaders gpu.textures images kernel -specialized-arrays.float ; +specialized-arrays ; +SPECIALIZED-ARRAY: float IN: gpu.util CONSTANT: environment-cube-map-mv-matrices diff --git a/extra/gpu/util/wasd/wasd.factor b/extra/gpu/util/wasd/wasd.factor index b0a3d8179a..9145434d90 100644 --- a/extra/gpu/util/wasd/wasd.factor +++ b/extra/gpu/util/wasd/wasd.factor @@ -4,7 +4,8 @@ game-input.scancodes game-loop game-worlds gpu.render gpu.state kernel literals locals math math.constants math.functions math.matrices math.order math.vectors opengl.gl sequences -specialized-arrays.float ui ui.gadgets.worlds ; +ui ui.gadgets.worlds specialized-arrays ; +SPECIALIZED-ARRAY: float IN: gpu.util.wasd UNIFORM-TUPLE: mvp-uniforms diff --git a/extra/grid-meshes/grid-meshes.factor b/extra/grid-meshes/grid-meshes.factor index 19c4568b7c..94638de346 100644 --- a/extra/grid-meshes/grid-meshes.factor +++ b/extra/grid-meshes/grid-meshes.factor @@ -1,6 +1,7 @@ ! (c)2009 Joe Groff bsd license USING: accessors arrays destructors kernel math opengl -opengl.gl sequences sequences.product specialized-arrays.float ; +opengl.gl sequences sequences.product specialized-arrays ; +SPECIALIZED-ARRAY: float IN: grid-meshes TUPLE: grid-mesh dim buffer row-length ; diff --git a/extra/half-floats/half-floats-tests.factor b/extra/half-floats/half-floats-tests.factor index 3eff29635c..cf3d7d3690 100644 --- a/extra/half-floats/half-floats-tests.factor +++ b/extra/half-floats/half-floats-tests.factor @@ -1,4 +1,6 @@ -USING: alien.c-types alien.syntax half-floats kernel math tools.test ; +USING: alien.c-types alien.syntax half-floats kernel math tools.test +specialized-arrays ; +SPECIALIZED-ARRAY: half IN: half-floats.tests [ HEX: 0000 ] [ 0.0 half>bits ] unit-test diff --git a/extra/half-floats/half-floats.factor b/extra/half-floats/half-floats.factor index d54c7af55f..2c089e4330 100755 --- a/extra/half-floats/half-floats.factor +++ b/extra/half-floats/half-floats.factor @@ -1,6 +1,5 @@ ! (c)2009 Joe Groff bsd license -USING: accessors alien.c-types alien.syntax kernel math math.order -specialized-arrays.functor ; +USING: accessors alien.c-types alien.syntax kernel math math.order ; IN: half-floats : half>bits ( float -- bits ) @@ -36,6 +35,4 @@ C-STRUCT: half { "ushort" "(bits)" } ; [ *ushort bits>half ] >>boxer-quot drop -"half" define-array - >> diff --git a/extra/id3/id3.factor b/extra/id3/id3.factor index 38aa291a3a..22474a7526 100644 --- a/extra/id3/id3.factor +++ b/extra/id3/id3.factor @@ -1,12 +1,12 @@ ! Copyright (C) 2009 Tim Wawrzynczak, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: sequences io io.encodings.binary io.files io.pathnames -strings kernel math io.mmap io.mmap.uchar accessors -combinators math.ranges unicode.categories byte-arrays -io.encodings.string io.encodings.utf16 assocs math.parser -combinators.short-circuit fry namespaces combinators.smart -splitting io.encodings.ascii arrays io.files.info unicode.case -io.directories.search literals math.functions continuations ; +strings kernel math io.mmap accessors combinators math.ranges +unicode.categories byte-arrays io.encodings.string +io.encodings.utf16 assocs math.parser combinators.short-circuit +fry namespaces combinators.smart splitting io.encodings.ascii +arrays io.files.info unicode.case io.directories.search literals +math.functions continuations ; IN: id3 : mp3>id3 ( path -- id3/f ) [ - [ ] dip - { - [ dup id3v1? [ read-v1-tags merge-id3v1 ] [ drop ] if ] - [ dup id3v1+? [ read-v1+-tags merge-id3v1 ] [ drop ] if ] - [ dup id3v2? [ read-v2-tags ] [ drop ] if ] - } cleave - ] with-mapped-uchar-file-reader ; + [ ] dip "uchar" + [ dup id3v1? [ read-v1-tags merge-id3v1 ] [ drop ] if ] + [ dup id3v1+? [ read-v1+-tags merge-id3v1 ] [ drop ] if ] + [ dup id3v2? [ read-v2-tags ] [ drop ] if ] + tri + ] with-mapped-file-reader ; : find-id3-frame ( id3 name -- obj/f ) swap frames>> at* [ data>> ] when ; diff --git a/extra/images/normalization/normalization.factor b/extra/images/normalization/normalization.factor index 90341fed92..8706ac5834 100755 --- a/extra/images/normalization/normalization.factor +++ b/extra/images/normalization/normalization.factor @@ -1,8 +1,11 @@ ! Copyright (C) 2009 Doug Coleman ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors grouping sequences combinators math -byte-arrays fry specialized-arrays.uint specialized-arrays.ushort -specialized-arrays.float images half-floats ; +byte-arrays fry images half-floats specialized-arrays ; +SPECIALIZED-ARRAY: uint +SPECIALIZED-ARRAY: ushort +SPECIALIZED-ARRAY: float +SPECIALIZED-ARRAY: half IN: images.normalization distance ; +SPECIALIZED-ARRAY: float IN: jamshred.tunnel CONSTANT: n-segments 5000 diff --git a/extra/llvm/invoker/invoker.factor b/extra/llvm/invoker/invoker.factor index bb1b06bcf3..87f39944d9 100644 --- a/extra/llvm/invoker/invoker.factor +++ b/extra/llvm/invoker/invoker.factor @@ -2,9 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien arrays assocs compiler.units effects io.backend io.pathnames kernel llvm.core llvm.jit llvm.reader -llvm.types make namespaces sequences specialized-arrays.alien +llvm.types make namespaces sequences specialized-arrays vocabs words ; - +SPECIALIZED-ARRAY: void* IN: llvm.invoker ! get function name, ret type, param types and names diff --git a/extra/llvm/types/types.factor b/extra/llvm/types/types.factor index a88c45c6cf..426e464b1b 100644 --- a/extra/llvm/types/types.factor +++ b/extra/llvm/types/types.factor @@ -1,10 +1,9 @@ ! Copyright (C) 2009 Matthew Willis. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors arrays combinators kernel llvm.core -locals math.parser math multiline -namespaces parser peg.ebnf sequences -sequences.deep specialized-arrays.alien strings vocabs words ; - +USING: accessors arrays combinators kernel llvm.core locals +math.parser math multiline namespaces parser peg.ebnf sequences +sequences.deep specialized-arrays strings vocabs words ; +SPECIALIZED-ARRAY: void* IN: llvm.types ! Type resolution strategy: diff --git a/extra/nurbs/nurbs.factor b/extra/nurbs/nurbs.factor index ff77d3e915..b8f2f1cb5f 100644 --- a/extra/nurbs/nurbs.factor +++ b/extra/nurbs/nurbs.factor @@ -1,7 +1,8 @@ ! (c)2009 Joe Groff bsd license USING: accessors arrays grouping kernel locals math math.order math.ranges math.vectors math.vectors.homogeneous sequences -specialized-arrays.float ; +specialized-arrays ; +SPECIALIZED-ARRAY: float IN: nurbs TUPLE: nurbs-curve diff --git a/extra/openal/openal.factor b/extra/openal/openal.factor index 6e9721b0fe..81a6621eff 100644 --- a/extra/openal/openal.factor +++ b/extra/openal/openal.factor @@ -1,8 +1,10 @@ ! Copyright (C) 2007 Chris Double. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel accessors arrays alien system combinators alien.syntax namespaces - alien.c-types sequences vocabs.loader shuffle - openal.backend specialized-arrays.uint alien.libraries generalizations ; +USING: kernel accessors arrays alien system combinators +alien.syntax namespaces alien.c-types sequences vocabs.loader +shuffle openal.backend alien.libraries generalizations +specialized-arrays ; +SPECIALIZED-ARRAY: uint IN: openal << "alut" { diff --git a/extra/synth/buffers/buffers.factor b/extra/synth/buffers/buffers.factor index 4c0ef64607..71b05ac642 100644 --- a/extra/synth/buffers/buffers.factor +++ b/extra/synth/buffers/buffers.factor @@ -1,6 +1,9 @@ ! Copyright (C) 2008 Alex Chapman ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien.c-types combinators kernel locals math math.ranges openal sequences sequences.merged specialized-arrays.uchar specialized-arrays.short ; +USING: accessors alien.c-types combinators kernel locals math +math.ranges openal sequences sequences.merged specialized-arrays ; +SPECIALIZED-ARRAY: uchar +SPECIALIZED-ARRAY: short IN: synth.buffers TUPLE: buffer sample-freq 8bit? id ; diff --git a/extra/system-info/linux/linux.factor b/extra/system-info/linux/linux.factor index 8a943927c7..5f83eb268b 100644 --- a/extra/system-info/linux/linux.factor +++ b/extra/system-info/linux/linux.factor @@ -2,7 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: unix alien alien.c-types kernel math sequences strings io.backend.unix splitting io.encodings.utf8 io.encodings.string -specialized-arrays.char ; +specialized-arrays ; +SPECIALIZED-ARRAY: char IN: system-info.linux : (uname) ( buf -- int ) diff --git a/extra/system-info/windows/windows.factor b/extra/system-info/windows/windows.factor index 6576ca6d53..07cbcc41b3 100755 --- a/extra/system-info/windows/windows.factor +++ b/extra/system-info/windows/windows.factor @@ -3,7 +3,8 @@ USING: alien alien.c-types classes.struct accessors kernel math namespaces windows windows.kernel32 windows.advapi32 words combinators vocabs.loader system-info.backend system -alien.strings windows.errors specialized-arrays.ushort ; +alien.strings windows.errors specialized-arrays ; +SPECIALIZED-ARRAY: ushort IN: system-info.windows : system-info ( -- SYSTEM_INFO ) diff --git a/extra/terrain/terrain.factor b/extra/terrain/terrain.factor index 4304ba3432..95322e423a 100644 --- a/extra/terrain/terrain.factor +++ b/extra/terrain/terrain.factor @@ -4,11 +4,12 @@ game-input.scancodes grouping kernel literals locals math math.constants math.functions math.matrices math.order math.vectors opengl opengl.capabilities opengl.gl opengl.shaders opengl.textures opengl.textures.private -sequences sequences.product specialized-arrays.float +sequences sequences.product specialized-arrays terrain.generation terrain.shaders ui ui.gadgets ui.gadgets.worlds ui.pixel-formats game-worlds method-chains math.affine-transforms noise ui.gestures combinators.short-circuit destructors grid-meshes ; +SPECIALIZED-ARRAY: float IN: terrain CONSTANT: FOV $[ 2.0 sqrt 1 + ] -- 2.34.1