]> gitweb.factorcode.org Git - factor.git/commitdiff
Specialized arrays work in progress
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 15 Nov 2008 02:18:16 +0000 (20:18 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 15 Nov 2008 02:18:16 +0000 (20:18 -0600)
113 files changed:
basis/alien/arrays/arrays-docs.factor
basis/alien/c-types/c-types-tests.factor
basis/alien/c-types/c-types.factor
basis/alien/structs/structs.factor
basis/cocoa/views/views.factor
basis/compiler/tests/alien.factor
basis/compiler/tests/codegen.factor
basis/compiler/tests/spilling.factor
basis/compiler/tree/propagation/propagation-tests.factor
basis/db/postgresql/lib/lib.factor
basis/float-arrays/authors.txt [deleted file]
basis/float-arrays/float-arrays-docs.factor [deleted file]
basis/float-arrays/float-arrays-tests.factor [deleted file]
basis/float-arrays/float-arrays.factor [deleted file]
basis/float-arrays/summary.txt [deleted file]
basis/float-arrays/tags.txt [deleted file]
basis/float-vectors/float-vectors-docs.factor [deleted file]
basis/float-vectors/float-vectors-tests.factor [deleted file]
basis/float-vectors/float-vectors.factor [deleted file]
basis/float-vectors/summary.txt [deleted file]
basis/float-vectors/tags.txt [deleted file]
basis/functors/authors.txt [new file with mode: 0644]
basis/functors/functors-tests.factor [new file with mode: 0644]
basis/functors/functors.factor [new file with mode: 0644]
basis/functors/summary.txt [new file with mode: 0644]
basis/functors/tags.txt [new file with mode: 0644]
basis/io/mmap/functor/functor.factor [new file with mode: 0644]
basis/io/mmap/mmap.factor
basis/io/unix/pipes/pipes.factor
basis/io/windows/launcher/launcher.factor
basis/io/windows/nt/monitors/monitors.factor
basis/locals/locals-tests.factor
basis/locals/locals.factor
basis/opengl/opengl.factor
basis/serialize/serialize-tests.factor
basis/specialized-arrays/alien/alien.factor [new file with mode: 0644]
basis/specialized-arrays/authors.txt [new file with mode: 0644]
basis/specialized-arrays/bool/bool.factor [new file with mode: 0644]
basis/specialized-arrays/char/char.factor [new file with mode: 0644]
basis/specialized-arrays/direct/alien/alien.factor [new file with mode: 0644]
basis/specialized-arrays/direct/bool/bool.factor [new file with mode: 0644]
basis/specialized-arrays/direct/char/char.factor [new file with mode: 0644]
basis/specialized-arrays/direct/direct.factor [new file with mode: 0644]
basis/specialized-arrays/direct/double/double.factor [new file with mode: 0644]
basis/specialized-arrays/direct/float/float.factor [new file with mode: 0644]
basis/specialized-arrays/direct/functor/functor.factor [new file with mode: 0644]
basis/specialized-arrays/direct/int/int.factor [new file with mode: 0644]
basis/specialized-arrays/direct/long/long.factor [new file with mode: 0644]
basis/specialized-arrays/direct/longlong/longlong.factor [new file with mode: 0644]
basis/specialized-arrays/direct/short/short.factor [new file with mode: 0644]
basis/specialized-arrays/direct/uchar/uchar.factor [new file with mode: 0644]
basis/specialized-arrays/direct/uint/uint.factor [new file with mode: 0644]
basis/specialized-arrays/direct/ulong/ulong.factor [new file with mode: 0644]
basis/specialized-arrays/direct/ulonglong/ulonglong.factor [new file with mode: 0644]
basis/specialized-arrays/direct/ushort/ushort.factor [new file with mode: 0644]
basis/specialized-arrays/double/double.factor [new file with mode: 0644]
basis/specialized-arrays/float/float.factor [new file with mode: 0644]
basis/specialized-arrays/functor/functor.factor [new file with mode: 0644]
basis/specialized-arrays/int/int.factor [new file with mode: 0644]
basis/specialized-arrays/long/long.factor [new file with mode: 0644]
basis/specialized-arrays/longlong/longlong.factor [new file with mode: 0644]
basis/specialized-arrays/short/short.factor [new file with mode: 0644]
basis/specialized-arrays/specialized-arrays-docs.factor [new file with mode: 0644]
basis/specialized-arrays/specialized-arrays-tests.factor [new file with mode: 0644]
basis/specialized-arrays/specialized-arrays.factor [new file with mode: 0644]
basis/specialized-arrays/summary.txt [new file with mode: 0644]
basis/specialized-arrays/tags.txt [new file with mode: 0644]
basis/specialized-arrays/uchar/uchar.factor [new file with mode: 0644]
basis/specialized-arrays/uint/uint.factor [new file with mode: 0644]
basis/specialized-arrays/ulong/ulong.factor [new file with mode: 0644]
basis/specialized-arrays/ulonglong/ulonglong.factor [new file with mode: 0644]
basis/specialized-arrays/ushort/ushort.factor [new file with mode: 0644]
basis/specialized-vectors/alien/alien.factor [new file with mode: 0644]
basis/specialized-vectors/authors.txt [new file with mode: 0644]
basis/specialized-vectors/bool/bool.factor [new file with mode: 0644]
basis/specialized-vectors/char/char.factor [new file with mode: 0644]
basis/specialized-vectors/double/double.factor [new file with mode: 0644]
basis/specialized-vectors/float/float.factor [new file with mode: 0644]
basis/specialized-vectors/functor/functor.factor [new file with mode: 0644]
basis/specialized-vectors/int/int.factor [new file with mode: 0644]
basis/specialized-vectors/long/long.factor [new file with mode: 0644]
basis/specialized-vectors/longlong/longlong.factor [new file with mode: 0644]
basis/specialized-vectors/short/short.factor [new file with mode: 0644]
basis/specialized-vectors/specialized-vectors-docs.factor [new file with mode: 0644]
basis/specialized-vectors/specialized-vectors.factor [new file with mode: 0644]
basis/specialized-vectors/summary.txt [new file with mode: 0644]
basis/specialized-vectors/tags.txt [new file with mode: 0644]
basis/specialized-vectors/uchar/uchar.factor [new file with mode: 0644]
basis/specialized-vectors/uint/uint.factor [new file with mode: 0644]
basis/specialized-vectors/ulong/ulong.factor [new file with mode: 0644]
basis/specialized-vectors/ulonglong/ulonglong.factor [new file with mode: 0644]
basis/specialized-vectors/ushort/ushort.factor [new file with mode: 0644]
basis/ui/gadgets/buttons/buttons.factor
basis/ui/render/render.factor
basis/unix/utilities/utilities.factor
basis/windows/com/wrapper/wrapper.factor
basis/x11/clipboard/clipboard.factor
basis/x11/glx/glx.factor
basis/x11/xim/xim.factor
core/syntax/syntax.factor
core/words/words.factor
extra/benchmark/dawes/dawes.factor
extra/bunny/fixed-pipeline/fixed-pipeline.factor
extra/bunny/model/model.factor
extra/cairo/samples/samples.factor
extra/cfdg/cfdg.factor
extra/hello-world/deploy.factor
extra/jamshred/gl/gl.factor
extra/math/blas/matrices/matrices.factor
extra/math/blas/vectors/vectors.factor
extra/openal/openal.factor
extra/opengl/shaders/shaders.factor
extra/synth/buffers/buffers.factor

index 09a09cdc6f97d7136053b2ea2f6dfddbe824d462..c5efe1e030e7e711278f984c21fe7c5aa782ec0f 100644 (file)
@@ -1,69 +1,7 @@
 IN: alien.arrays\r
 USING: help.syntax help.markup byte-arrays alien.c-types ;\r
 \r
-ARTICLE: "c-arrays-factor" "Converting C arrays to and from Factor arrays"\r
-"Each primitive C type has a pair of words, " { $snippet ">" { $emphasis "type" } "-array" } " and " { $snippet { $emphasis "type" } "-array>" } ", for converting an array of Factor objects to and from a " { $link byte-array } " of C values. This set of words consists of:"\r
-{ $subsection >c-bool-array      }\r
-{ $subsection >c-char-array      }\r
-{ $subsection >c-double-array    }\r
-{ $subsection >c-float-array     }\r
-{ $subsection >c-int-array       }\r
-{ $subsection >c-long-array      }\r
-{ $subsection >c-longlong-array  }\r
-{ $subsection >c-short-array     }\r
-{ $subsection >c-uchar-array     }\r
-{ $subsection >c-uint-array      }\r
-{ $subsection >c-ulong-array     }\r
-{ $subsection >c-ulonglong-array }\r
-{ $subsection >c-ushort-array    }\r
-{ $subsection >c-void*-array     }\r
-{ $subsection c-bool-array>      }\r
-{ $subsection c-char-array>      }\r
-{ $subsection c-double-array>    }\r
-{ $subsection c-float-array>     }\r
-{ $subsection c-int-array>       }\r
-{ $subsection c-long-array>      }\r
-{ $subsection c-longlong-array>  }\r
-{ $subsection c-short-array>     }\r
-{ $subsection c-uchar-array>     }\r
-{ $subsection c-uint-array>      }\r
-{ $subsection c-ulong-array>     }\r
-{ $subsection c-ulonglong-array> }\r
-{ $subsection c-ushort-array>    }\r
-{ $subsection c-void*-array>     } ;\r
-\r
-ARTICLE: "c-arrays-get/set" "Reading and writing elements in C arrays"\r
-"Each C type has a pair of words, " { $snippet { $emphasis "type" } "-nth" } " and " { $snippet "set-" { $emphasis "type" } "-nth" } ", for reading and writing values of this type stored in an array. This set of words includes but is not limited to:"\r
-{ $subsection char-nth }\r
-{ $subsection set-char-nth }\r
-{ $subsection uchar-nth }\r
-{ $subsection set-uchar-nth }\r
-{ $subsection short-nth }\r
-{ $subsection set-short-nth }\r
-{ $subsection ushort-nth }\r
-{ $subsection set-ushort-nth }\r
-{ $subsection int-nth }\r
-{ $subsection set-int-nth }\r
-{ $subsection uint-nth }\r
-{ $subsection set-uint-nth }\r
-{ $subsection long-nth }\r
-{ $subsection set-long-nth }\r
-{ $subsection ulong-nth }\r
-{ $subsection set-ulong-nth }\r
-{ $subsection longlong-nth }\r
-{ $subsection set-longlong-nth }\r
-{ $subsection ulonglong-nth }\r
-{ $subsection set-ulonglong-nth }\r
-{ $subsection float-nth }\r
-{ $subsection set-float-nth }\r
-{ $subsection double-nth }\r
-{ $subsection set-double-nth }\r
-{ $subsection void*-nth }\r
-{ $subsection set-void*-nth } ;\r
-\r
 ARTICLE: "c-arrays" "C arrays"\r
 "C arrays are allocated in the same manner as other C data; see " { $link "c-byte-arrays" } " and " { $link "malloc" } "."\r
 $nl\r
-"C type specifiers for array types are documented in " { $link "c-types-specs" } "."\r
-{ $subsection "c-arrays-factor" }\r
-{ $subsection "c-arrays-get/set" } ;\r
+"C type specifiers for array types are documented in " { $link "c-types-specs" } "." ;\r
index edda9e7fdb4fa13a7a16c1336f6ce9bbf36edd09..13ea115089811c4b18c79a31764cc292389cdd96 100644 (file)
@@ -54,5 +54,3 @@ TYPEDEF: uchar* MyLPBYTE
 [
     0 B{ 1 2 3 4 } <displaced-alien> <void*>
 ] must-fail
-
-[ t ] [ { t f t } >c-bool-array { 1 0 1 } >c-int-array = ] unit-test
index a93c87611d4e0ee76dc8a7686b8c7743fdd984d2..a81296f24d91a92d6c7015f4a47a2e68a78c955f 100644 (file)
@@ -19,7 +19,7 @@ reg-class size align stack-align? ;
 
 : new-c-type ( class -- type )
     new
-        int-regs >>reg-class ;
+        int-regs >>reg-class ; inline
 
 : <c-type> ( -- type )
     \ c-type new-c-type ;
@@ -172,12 +172,12 @@ M: byte-array byte-length length ;
 
 : c-getter ( name -- quot )
     c-type-getter [
-        [ "Cannot read struct fields with type" throw ]
+        [ "Cannot read struct fields with this type" throw ]
     ] unless* ;
 
 : c-setter ( name -- quot )
     c-type-setter [
-        [ "Cannot write struct fields with type" throw ]
+        [ "Cannot write struct fields with this type" throw ]
     ] unless* ;
 
 : <c-array> ( n type -- array )
@@ -201,28 +201,13 @@ M: byte-array byte-length length ;
 : byte-array>memory ( byte-array base -- )
     swap dup length memcpy ;
 
-: (define-nth) ( word type quot -- )
+: array-accessor ( type quot -- def )
     [
         \ swap , [ heap-size , [ * >fixnum ] % ] [ % ] bi*
-    ] [ ] make define-inline ;
-
-: nth-word ( name vocab -- word )
-    >r "-nth" append r> create ;
-
-: define-nth ( name vocab -- )
-    dupd nth-word swap dup c-getter (define-nth) ;
-
-: set-nth-word ( name vocab -- word )
-    >r "set-" swap "-nth" 3append r> create ;
-
-: define-set-nth ( name vocab -- )
-    dupd set-nth-word swap dup c-setter (define-nth) ;
+    ] [ ] make ;
 
 : typedef ( old new -- ) c-types get set-at ;
 
-: define-c-type ( type name vocab -- )
-    >r tuck typedef r> [ define-nth ] 2keep define-set-nth ;
-
 TUPLE: long-long-type < c-type ;
 
 : <long-long-type> ( -- type )
@@ -240,62 +225,34 @@ M: long-long-type box-parameter ( n type -- )
 M: long-long-type box-return ( type -- )
     f swap box-parameter ;
 
-: define-deref ( name vocab -- )
-    >r dup CHAR: * prefix r> create
-    swap c-getter 0 prefix define-inline ;
+: define-deref ( name -- )
+    [ CHAR: * prefix "alien.c-types" create ]
+    [ c-getter 0 prefix ] bi
+    define-inline ;
 
-: define-out ( name vocab -- )
-    over [ <c-object> tuck 0 ] over c-setter append swap
-    >r >r constructor-word r> r> prefix define-inline ;
+: define-out ( name -- )
+    [ "alien.c-types" constructor-word ]
+    [ [ [ <c-object> ] curry ] [ c-setter ] bi append ] bi
+    define-inline ;
 
 : c-bool> ( int -- ? )
     zero? not ;
 
-: >c-array ( seq type word -- byte-array )
-    [ [ dup length ] dip <c-array> ] dip
-    [ [ execute ] 2curry each-index ] 2keep drop ; inline
-
-: >c-array-quot ( type vocab -- quot )
-    dupd set-nth-word [ >c-array ] 2curry ;
-
-: to-array-word ( name vocab -- word )
-    >r ">c-" swap "-array" 3append r> create ;
-
-: define-to-array ( type vocab -- )
-    [ to-array-word ] 2keep >c-array-quot
-    (( array -- byte-array )) define-declared ;
-
-: c-array>quot ( type vocab -- quot )
-    [
-        \ swap ,
-        nth-word 1quotation ,
-        [ curry map ] %
-    ] [ ] make ;
-
-: from-array-word ( name vocab -- word )
-    >r "c-" swap "-array>" 3append r> create ;
-
-: define-from-array ( type vocab -- )
-    [ from-array-word ] 2keep c-array>quot
-    (( c-ptr n -- array )) define-declared ;
-
 : define-primitive-type ( type name -- )
-    "alien.c-types"
-    {
-        [ define-c-type ]
-        [ define-deref ]
-        [ define-to-array ]
-        [ define-from-array ]
-        [ define-out ]
-    } 2cleave ;
+    [ typedef ]
+    [ define-deref ]
+    [ define-out ]
+    tri ;
 
 : expand-constants ( c-type -- c-type' )
     dup array? [
-        unclip >r [
-            dup word? [
-                def>> { } swap with-datastack first
-            ] when
-        ] map r> prefix
+        unclip [
+            [
+                dup word? [
+                    def>> { } swap with-datastack first
+                ] when
+            ] map
+        ] dip prefix
     ] when ;
 
 : malloc-file-contents ( path -- alien len )
@@ -304,6 +261,17 @@ M: long-long-type box-return ( type -- )
 : if-void ( type true false -- )
     pick "void" = [ drop nip call ] [ nip call ] if ; inline
 
+: primitive-types
+    {
+        "char" "uchar"
+        "short" "ushort"
+        "int" "uint"
+        "long" "ulong"
+        "longlong" "ulonglong"
+        "float" "double"
+        "void*" "bool"
+    } ;
+
 [
     <c-type>
         [ alien-cell ] >>getter
index ce30a2ee25b51aa3829a3541574f3fd75aa6901e..181ff98e627f1b003e5800852a36eb20e8d36407 100644 (file)
@@ -34,10 +34,10 @@ M: struct-type stack-size
 
 : c-struct? ( type -- ? ) (c-type) struct-type? ;
 
-: (define-struct) ( name vocab size align fields -- )
+: (define-struct) ( name size align fields -- )
     >r [ align ] keep r>
     struct-type boa
-    -rot define-c-type ;
+    swap typedef ;
 
 : define-struct-early ( name vocab fields -- fields )
     -rot [ rot first2 <field-spec> ] 2curry map ;
index d03688b2be701cc2c865e8fed622a7955de20854..3e7bd26965860577a0e618b9df10a1d55769e4a9 100644 (file)
@@ -1,8 +1,8 @@
-! Copyright (C) 2006, 2007 Slava Pestov
+! Copyright (C) 2006, 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types arrays kernel math namespaces make cocoa
-cocoa.messages cocoa.classes cocoa.types sequences
-continuations ;
+USING: specialized-arrays.int arrays kernel math namespaces make
+cocoa cocoa.messages cocoa.classes cocoa.types sequences
+continuations accessors ;
 IN: cocoa.views
 
 : NSOpenGLPFAAllRenderers 1 ;
@@ -69,7 +69,7 @@ PRIVATE>
             NSOpenGLPFASamples , 8 ,
         ] when
         0 ,
-    ] { } make >c-int-array
+    ] int-array{ } make underlying>>
     -> initWithAttributes:
     -> autorelease ;
 
index d7e82402d5da64b6f61a4e8482db6ade3adc6c70..114d3cdda2160fe4f16f7477bb6d6d6f7a7042a7 100644 (file)
@@ -3,7 +3,8 @@ USING: alien alien.c-types alien.syntax compiler kernel
 namespaces namespaces tools.test sequences stack-checker
 stack-checker.errors words arrays parser quotations
 continuations effects namespaces.private io io.streams.string
-memory system threads tools.test math accessors combinators ;
+memory system threads tools.test math accessors combinators
+specialized-arrays.float ;
 
 FUNCTION: void ffi_test_0 ;
 [ ] [ ffi_test_0 ] unit-test
@@ -188,7 +189,11 @@ FUNCTION: int ffi_test_12 int a int b rect c int d int e int f ;
 
 FUNCTION: float ffi_test_23 ( float[3] x, float[3] y ) ;
 
-[ 32.0 ] [ { 1.0 2.0 3.0 } >c-float-array { 4.0 5.0 6.0 } >c-float-array ffi_test_23 ] unit-test
+[ 32.0 ] [
+    { 1.0 2.0 3.0 } >float-array underlying>>
+    { 4.0 5.0 6.0 } >float-array underlying>>
+    ffi_test_23
+] unit-test
 
 ! Test odd-size structs
 C-STRUCT: test-struct-1 { { "char" 1 } "x" } ;
index a56ee55c82df5838188e1077bea8247fac944fb0..2375e3da35f1b3727f8406fdeb97888250298113 100644 (file)
@@ -3,7 +3,7 @@ kernel.private math hashtables.private math.private namespaces
 sequences sequences.private tools.test namespaces.private
 slots.private sequences.private byte-arrays alien
 alien.accessors layouts words definitions compiler.units io
-combinators vectors float-arrays ;
+combinators vectors ;
 IN: compiler.tests
 
 ! Originally, this file did black box testing of templating
index 156fdfff028a4d9d3e4b0569125185db67eaecc4..ee8c2f056a97fecd2611224e24243b6595c63fce 100644 (file)
@@ -1,5 +1,5 @@
 USING: math.private kernel combinators accessors arrays
-generalizations float-arrays tools.test ;
+generalizations tools.test ;
 IN: compiler.tests
 
 : float-spill-bug ( a -- b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b b )
index 760ff167aa8072e9cbb6be08bc3999a056e5d5a6..865852e99f69a9e325ef00e98731083a2673faf9 100644 (file)
@@ -8,7 +8,7 @@ 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
-float-arrays system sorting ;
+specialized-arrays.double system sorting ;
 IN: compiler.tree.propagation.tests
 
 \ propagate must-infer
@@ -588,7 +588,7 @@ MIXIN: empty-mixin
     [ { fixnum integer } declare bitand ] final-classes
 ] unit-test
 
-[ V{ float-array } ] [ [| | F{ } ] final-classes ] unit-test
+[ V{ double-array } ] [ [| | double-array{ } ] final-classes ] unit-test
 
 [ V{ t } ] [ [ netbsd unix? ] final-literals ] unit-test
 
index 63284b28a30d985b908a4125cb37dd5e3c6498e4..0a12f4374ab1cdc0a4b45ece00a3b51e719fe7c6 100644 (file)
@@ -5,7 +5,8 @@ quotations sequences db.postgresql.ffi alien alien.c-types
 db.types tools.walker ascii splitting math.parser combinators
 libc shuffle calendar.format byte-arrays destructors prettyprint
 accessors strings serialize io.encodings.binary io.encodings.utf8
-alien.strings io.streams.byte-array summary present urls ;
+alien.strings io.streams.byte-array summary present urls
+specialized-arrays.uint specialized-arrays.alien ;
 IN: db.postgresql.lib
 
 : postgresql-result-error-message ( res -- str/f )
@@ -64,7 +65,7 @@ M: postgresql-result-null summary ( obj -- str )
     } case ;
 
 : param-types ( statement -- seq )
-    in-params>> [ type>> type>oid ] map >c-uint-array ;
+    in-params>> [ type>> type>oid ] uint-array{ } map-as underlying>> ;
 
 : malloc-byte-array/length ( byte-array -- alien length )
     [ malloc-byte-array &free ] [ length ] bi ;
@@ -90,11 +91,11 @@ M: postgresql-result-null summary ( obj -- str )
     ] 2map flip [
         f f
     ] [
-        first2 [ >c-void*-array ] [ >c-uint-array ] bi*
+        first2 [ >void*-array underlying>> ] [ >uint-array underlying>> ] bi*
     ] if-empty ;
 
 : param-formats ( statement -- seq )
-    in-params>> [ type>> type>param-format ] map >c-uint-array ;
+    in-params>> [ type>> type>param-format ] uint-array{ } map-as underlying>> ;
 
 : do-postgresql-bound-statement ( statement -- res )
     [
diff --git a/basis/float-arrays/authors.txt b/basis/float-arrays/authors.txt
deleted file mode 100755 (executable)
index 1901f27..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Slava Pestov
diff --git a/basis/float-arrays/float-arrays-docs.factor b/basis/float-arrays/float-arrays-docs.factor
deleted file mode 100644 (file)
index 6c775db..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-USING: arrays bit-arrays vectors strings sbufs
-kernel help.markup help.syntax math ;
-IN: float-arrays
-
-ARTICLE: "float-arrays" "Float arrays"
-"Float arrays are fixed-size mutable sequences (" { $link "sequence-protocol" } ") whose elements are instances of " { $link float } ". Elements are unboxed, hence the memory usage is lower than an equivalent " { $link array } " of floats."
-$nl
-"Float array words are in the " { $vocab-link "float-arrays" } " vocabulary."
-$nl
-"Float arrays play a special role in the C library interface; they can be used to pass binary data back and forth between Factor and C. See " { $link "c-byte-arrays" } "."
-$nl
-"Float arrays form a class of objects."
-{ $subsection float-array }
-{ $subsection float-array? }
-"There are several ways to construct float arrays."
-{ $subsection >float-array }
-{ $subsection <float-array> }
-"Creating a float array from several elements on the stack:"
-{ $subsection 1float-array }
-{ $subsection 2float-array }
-{ $subsection 3float-array }
-{ $subsection 4float-array }
-"Float array literal syntax:"
-{ $subsection POSTPONE: F{ } ;
-
-ABOUT: "float-arrays"
-
-HELP: F{
-{ $syntax "F{ elements... }" }
-{ $values { "elements" "a list of real numbers" } }
-{ $description "Marks the beginning of a literal float array. Literal float arrays are terminated by " { $link POSTPONE: } } "." } 
-{ $examples { $code "F{ 1.0 2.0 3.0 }" } } ;
-
-HELP: float-array
-{ $description "The class of float arrays." } ;
-
-HELP: <float-array> ( n -- float-array )
-{ $values { "n" "a non-negative integer" } { "float-array" "a new float array" } }
-{ $description "Creates a new float array holding " { $snippet "n" } " floats with all elements initially set to " { $snippet "0.0" } "." } ;
-
-HELP: >float-array
-{ $values { "seq" "a sequence" } { "float-array" float-array } }
-{ $description "Outputs a freshly-allocated float array whose elements have the same floating-point values as a given sequence." }
-{ $errors "Throws an error if the sequence contains elements other than real numbers." } ;
-
-HELP: 1float-array
-{ $values { "x" object } { "array" float-array } }
-{ $description "Create a new float array with one element." } ;
-
-{ 1array 2array 3array 4array } related-words
-
-HELP: 2float-array
-{ $values { "x" object } { "y" object } { "array" float-array } }
-{ $description "Create a new float array with two elements, with " { $snippet "x" } " appearing first." } ;
-
-HELP: 3float-array
-{ $values { "x" object } { "y" object } { "z" object } { "array" float-array } }
-{ $description "Create a new float array with three elements, with " { $snippet "x" } " appearing first." } ;
-
-HELP: 4float-array
-{ $values { "w" object } { "x" object } { "y" object } { "z" object } { "array" float-array } }
-{ $description "Create a new float array with four elements, with " { $snippet "w" } " appearing first." } ;
diff --git a/basis/float-arrays/float-arrays-tests.factor b/basis/float-arrays/float-arrays-tests.factor
deleted file mode 100644 (file)
index 64070b9..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-IN: float-arrays.tests
-USING: float-arrays tools.test sequences.private ;
-
-[ F{ 0.0 0.0 0.0 } ] [ 3 <float-array> ] unit-test
-
-[ F{ 1 2 3 0 0 0 } ] [ 6 F{ 1 2 3 } resize ] unit-test
-
-[ F{ 1 2 } ] [ 2 F{ 1 2 3 4 5 6 7 8 9 } resize ] unit-test
-
-[ -10 F{ } resize ] must-fail
-
-[ F{ 1.3 } ] [ 1.3 1float-array ] unit-test
diff --git a/basis/float-arrays/float-arrays.factor b/basis/float-arrays/float-arrays.factor
deleted file mode 100644 (file)
index ab3eef6..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-! Copyright (C) 2007, 2008 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: kernel kernel.private alien.accessors sequences
-sequences.private math math.private byte-arrays accessors
-alien.c-types parser prettyprint.backend ;
-IN: float-arrays
-
-TUPLE: float-array
-{ length array-capacity read-only }
-{ underlying byte-array read-only } ;
-
-: <float-array> ( n -- float-array )
-    dup "double" <c-array> float-array boa ; inline
-
-M: float-array clone
-    [ length>> ] [ underlying>> clone ] bi float-array boa ;
-
-M: float-array length length>> ;
-
-M: float-array nth-unsafe
-    underlying>> double-nth ;
-
-M: float-array set-nth-unsafe
-    [ >float ] 2dip underlying>> set-double-nth ;
-
-: >float-array ( seq -- float-array )
-    T{ float-array } clone-like ; inline
-
-M: float-array like
-    drop dup float-array? [ >float-array ] unless ;
-
-M: float-array new-sequence
-    drop <float-array> ;
-
-M: float-array equal?
-    over float-array? [ sequence= ] [ 2drop f ] if ;
-
-M: float-array resize
-    [ drop ] [
-        [ "double" heap-size * ] [ underlying>> ] bi*
-        resize-byte-array
-    ] 2bi
-    float-array boa ;
-
-M: float-array byte-length length "double" heap-size * ;
-
-INSTANCE: float-array sequence
-
-: 1float-array ( x -- array )
-    1 <float-array> [ set-first ] keep ; inline
-
-: 2float-array ( x y -- array )
-    T{ float-array } 2sequence ; inline
-
-: 3float-array ( x y z -- array )
-    T{ float-array } 3sequence ; inline
-
-: 4float-array ( w x y z -- array )
-    T{ float-array } 4sequence ; inline
-
-: F{ \ } [ >float-array ] parse-literal ; parsing
-
-M: float-array pprint-delims drop \ F{ \ } ;
-M: float-array >pprint-sequence ;
-M: float-array pprint* pprint-object ;
-
-! Rice
-USING: hints math.vectors arrays ;
-
-HINTS: vneg { float-array } { array } ;
-HINTS: v*n { float-array float } { array object } ;
-HINTS: n*v { float float-array } { array object } ;
-HINTS: v/n { float-array float } { array object } ;
-HINTS: n/v { float float-array } { object array } ;
-HINTS: v+ { float-array float-array } { array array } ;
-HINTS: v- { float-array float-array } { array array } ;
-HINTS: v* { float-array float-array } { array array } ;
-HINTS: v/ { float-array float-array } { array array } ;
-HINTS: vmax { float-array float-array } { array array } ;
-HINTS: vmin { float-array float-array } { array array } ;
-HINTS: v. { float-array float-array } { array array } ;
-HINTS: norm-sq { float-array } { array } ;
-HINTS: norm { float-array } { array } ;
-HINTS: normalize { float-array } { array } ;
-
-! More rice. Experimental, currently causes a slowdown in raytracer
-! for some odd reason.
-
-USING: words classes.algebra compiler.tree.propagation.info ;
-
-{ v+ v- v* v/ vmax vmin } [
-    [
-        [ class>> float-array class<= ] both?
-        float-array object ? <class-info>
-    ] "outputs" set-word-prop
-] each
-
-{ n*v n/v } [
-    [
-        nip class>> float-array class<= float-array object ? <class-info>
-    ] "outputs" set-word-prop
-] each
-
-{ v*n v/n } [
-    [
-        drop class>> float-array class<= float-array object ? <class-info>
-    ] "outputs" set-word-prop
-] each
-
-{ vneg normalize } [
-    [
-        class>> float-array class<= float-array object ? <class-info>
-    ] "outputs" set-word-prop
-] each
-
-\ norm-sq [
-    class>> float-array class<= float object ? <class-info>
-] "outputs" set-word-prop
-
-\ v. [
-    [ class>> float-array class<= ] both?
-    float object ? <class-info>
-] "outputs" set-word-prop
diff --git a/basis/float-arrays/summary.txt b/basis/float-arrays/summary.txt
deleted file mode 100644 (file)
index 0eac3b0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Efficient fixed-length floating point number arrays
diff --git a/basis/float-arrays/tags.txt b/basis/float-arrays/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections
diff --git a/basis/float-vectors/float-vectors-docs.factor b/basis/float-vectors/float-vectors-docs.factor
deleted file mode 100644 (file)
index 714c851..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-USING: arrays float-arrays help.markup help.syntax kernel\r
-combinators ;\r
-IN: float-vectors\r
-\r
-ARTICLE: "float-vectors" "Float vectors"\r
-"A float vector is a resizable mutable sequence of unsigned floats. Float vector words are found in the " { $vocab-link "float-vectors" } " vocabulary."\r
-$nl\r
-"Float vectors form a class:"\r
-{ $subsection float-vector }\r
-{ $subsection float-vector? }\r
-"Creating float vectors:"\r
-{ $subsection >float-vector }\r
-{ $subsection <float-vector> }\r
-"Literal syntax:"\r
-{ $subsection POSTPONE: FV{ }\r
-"If you don't care about initial capacity, a more elegant way to create a new float vector is to write:"\r
-{ $code "FV{ } clone" } ;\r
-\r
-ABOUT: "float-vectors"\r
-\r
-HELP: float-vector\r
-{ $description "The class of resizable float vectors. See " { $link "float-vectors" } " for information." } ;\r
-\r
-HELP: <float-vector>\r
-{ $values { "n" "a positive integer specifying initial capacity" } { "float-vector" float-vector } }\r
-{ $description "Creates a new float vector that can hold " { $snippet "n" } " floats before resizing." } ;\r
-\r
-HELP: >float-vector\r
-{ $values { "seq" "a sequence" } { "float-vector" float-vector } }\r
-{ $description "Outputs a freshly-allocated float vector with the same elements as a given sequence." }\r
-{ $errors "Throws an error if the sequence contains elements other than real numbers." } ;\r
-\r
-HELP: FV{\r
-{ $syntax "FV{ elements... }" }\r
-{ $values { "elements" "a list of real numbers" } }\r
-{ $description "Marks the beginning of a literal float vector. Literal float vectors are terminated by " { $link POSTPONE: } } "." } \r
-{ $examples { $code "FV{ 1.0 2.0 3.0 }" } } ;\r
diff --git a/basis/float-vectors/float-vectors-tests.factor b/basis/float-vectors/float-vectors-tests.factor
deleted file mode 100644 (file)
index 1483b26..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-USING: tools.test float-vectors vectors sequences kernel math ;\r
-IN: float-vectors.tests\r
-\r
-[ 0 ] [ 123 <float-vector> length ] unit-test\r
-\r
-: do-it\r
-    12345 [ >float over push ] each ;\r
-\r
-[ t ] [\r
-    3 <float-vector> do-it\r
-    3 <vector> do-it sequence=\r
-] unit-test\r
-\r
-[ t ] [ FV{ } float-vector? ] unit-test\r
diff --git a/basis/float-vectors/float-vectors.factor b/basis/float-vectors/float-vectors.factor
deleted file mode 100644 (file)
index 8e93582..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-! Copyright (C) 2008 Slava Pestov.\r
-! See http://factorcode.org/license.txt for BSD license.\r
-USING: arrays kernel kernel.private math sequences\r
-sequences.private growable float-arrays prettyprint.backend\r
-parser accessors ;\r
-IN: float-vectors\r
-\r
-TUPLE: float-vector\r
-{ underlying float-array initial: F{ } }\r
-{ length array-capacity } ;\r
-\r
-: <float-vector> ( n -- float-vector )\r
-    <float-array> 0 float-vector boa ; inline\r
-\r
-: >float-vector ( seq -- float-vector )\r
-    T{ float-vector f F{ } 0 } clone-like ;\r
-\r
-M: float-vector like\r
-    drop dup float-vector? [\r
-        dup float-array?\r
-        [ dup length float-vector boa ] [ >float-vector ] if\r
-    ] unless ;\r
-\r
-M: float-vector new-sequence\r
-    drop [ <float-array> ] [ >fixnum ] bi float-vector boa ;\r
-\r
-M: float-vector equal?\r
-    over float-vector? [ sequence= ] [ 2drop f ] if ;\r
-\r
-M: float-array new-resizable drop <float-vector> ;\r
-\r
-INSTANCE: float-vector growable\r
-\r
-: FV{ \ } [ >float-vector ] parse-literal ; parsing\r
-\r
-M: float-vector >pprint-sequence ;\r
-M: float-vector pprint-delims drop \ FV{ \ } ;\r
-M: float-vector pprint* pprint-object ;\r
diff --git a/basis/float-vectors/summary.txt b/basis/float-vectors/summary.txt
deleted file mode 100644 (file)
index c476f41..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Growable float arrays
diff --git a/basis/float-vectors/tags.txt b/basis/float-vectors/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections
diff --git a/basis/functors/authors.txt b/basis/functors/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/basis/functors/functors-tests.factor b/basis/functors/functors-tests.factor
new file mode 100644 (file)
index 0000000..39923af
--- /dev/null
@@ -0,0 +1,47 @@
+IN: functors.tests
+USING: functors tools.test math words kernel ;
+
+<<
+
+FUNCTOR: define-box ( T -- )
+
+B DEFINES ${T}-box
+<B> DEFINES <${B}>
+
+WHERE
+
+TUPLE: B { value T } ;
+
+C: <B> B
+
+;FUNCTOR
+
+\ float define-box
+
+>>
+
+{ 1 0 } [ define-box ] must-infer-as
+
+[ T{ float-box f 5.0 } ] [ 5.0 <float-box> ] unit-test
+
+: twice ( word -- )
+    [ execute ] [ execute ] bi ; inline
+<<
+
+FUNCTOR: wrapper-test ( W -- )
+
+WW DEFINES ${W}${W}
+
+WHERE
+
+: WW W twice ; inline
+
+;FUNCTOR
+
+\ sq wrapper-test
+
+>>
+
+\ sqsq must-infer
+
+[ 16 ] [ 2 sqsq ] unit-test
diff --git a/basis/functors/functors.factor b/basis/functors/functors.factor
new file mode 100644 (file)
index 0000000..16f6f07
--- /dev/null
@@ -0,0 +1,98 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: parser kernel locals.private quotations classes.tuple
+classes.tuple.parser make lexer combinators generic words
+interpolate namespaces sequences io.streams.string fry
+classes.mixin ;
+IN: functors
+
+: scan-param ( -- obj )
+    scan-object dup special? [ literalize ] unless ;
+
+: define* ( word def -- ) over set-word define ;
+
+: `TUPLE:
+    scan-param parsed
+    scan {
+        { ";" [ tuple parsed f parsed ] }
+        { "<" [ scan-param [ parse-tuple-slots ] { } make parsed ] }
+        [
+            [ tuple parsed ] dip
+            [ parse-slot-name [ parse-tuple-slots ] when ] { }
+            make parsed
+        ]
+    } case
+    \ define-tuple-class parsed ; parsing
+
+: `M:
+    scan-param parsed
+    scan-param parsed
+    \ create-method parsed
+    parse-definition parsed
+    \ define* parsed ; parsing
+
+: `C:
+    scan-param parsed
+    scan-param parsed
+    [ [ boa ] curry define* ] over push-all ; parsing
+
+: `:
+    scan-param parsed
+    parse-definition parsed
+    \ define* parsed ; parsing
+
+: `INSTANCE:
+    scan-param parsed
+    scan-param parsed
+    \ add-mixin-instance parsed ; parsing
+
+: `inline \ inline parsed ; parsing
+
+: `parsing \ parsing parsed ; parsing
+
+: (INTERPOLATE) ( accum quot -- accum )
+    [ scan interpolate-locals ] dip
+    '[ _ with-string-writer @ ] parsed ;
+
+: IS [ search ] (INTERPOLATE) ; parsing
+
+: DEFINES [ in get create ] (INTERPOLATE) ; parsing
+
+DEFER: ;FUNCTOR delimiter
+
+: functor-words ( -- assoc )
+    H{
+        { "TUPLE:" POSTPONE: `TUPLE: }
+        { "M:" POSTPONE: `M: }
+        { "C:" POSTPONE: `C: }
+        { ":" POSTPONE: `: }
+        { "INSTANCE:" POSTPONE: `INSTANCE: }
+        { "inline" POSTPONE: `inline }
+        { "parsing" POSTPONE: `parsing }
+    } ;
+
+: push-functor-words ( -- )
+    functor-words use get push ;
+
+: pop-functor-words ( -- )
+    functor-words use get delq ;
+
+: parse-functor-body ( -- form )
+    t in-lambda? [
+        V{ } clone
+        push-functor-words
+        "WHERE" parse-bindings* \ ;FUNCTOR (parse-lambda)
+        <let*> parsed-lambda
+        pop-functor-words
+        >quotation
+    ] with-variable ;
+
+: (FUNCTOR:) ( -- word def )
+    CREATE
+    parse-locals
+    parse-functor-body swap pop-locals <lambda>
+    lambda-rewrite first ;
+
+: FUNCTOR: (FUNCTOR:) define ; parsing
+
+: APPLY: scan-word scan-word execute swap '[ _ execute ] each ; parsing
diff --git a/basis/functors/summary.txt b/basis/functors/summary.txt
new file mode 100644 (file)
index 0000000..d95b366
--- /dev/null
@@ -0,0 +1 @@
+First-class syntax
diff --git a/basis/functors/tags.txt b/basis/functors/tags.txt
new file mode 100644 (file)
index 0000000..f427429
--- /dev/null
@@ -0,0 +1 @@
+extensions
diff --git a/basis/io/mmap/functor/functor.factor b/basis/io/mmap/functor/functor.factor
new file mode 100644 (file)
index 0000000..b60a1c0
--- /dev/null
@@ -0,0 +1,22 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: functors accessors alien.c-types math kernel words ;
+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: mapped-array-functor ( T -- )
+
+C   DEFINES <mapped-${T}-array>
+<A> IS      <direct-${T}-array>
+
+WHERE
+
+: C mapped-file>direct <A> execute ; inline
+
+;FUNCTOR
index 01e7054ef1f3c670723aab54406a7079959c078d..aea6d80636d80822ef3aab7c4b10511092a6e2a4 100644 (file)
@@ -2,7 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: continuations destructors io.backend kernel quotations
 sequences system alien alien.accessors accessors
-sequences.private system vocabs.loader combinators ;
+sequences.private system vocabs.loader combinators
+specialized-arrays.direct functors alien.c-types
+io.mmap.functor ;
 IN: io.mmap
 
 TUPLE: mapped-file address handle length disposed ;
@@ -30,6 +32,8 @@ M: mapped-file dispose* ( mmap -- ) close-mapped-file ;
 : with-mapped-file ( path length quot -- )
     >r <mapped-file> r> with-disposal ; inline
 
+APPLY: mapped-array-functor primitive-types
+
 {
     { [ os unix? ] [ "io.unix.mmap" require ] }
     { [ os winnt? ] [ "io.windows.mmap" require ] }
index 53c336c5555ac2135bbc8c2383e44be36ecba956..5a1f2849d488dc7d66d3b2064fedba0cb82da466 100644 (file)
@@ -1,11 +1,11 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: system alien.c-types kernel unix math sequences
-qualified io.unix.backend io.ports ;
+USING: system kernel unix math sequences qualified
+io.unix.backend io.ports specialized-arrays.int ;
 IN: io.unix.pipes
 QUALIFIED: io.pipes
 
 M: unix io.pipes:(pipe) ( -- pair )
-    2 "int" <c-array>
-    dup pipe io-error
-    2 c-int-array> first2 [ <fd> init-fd ] bi@ io.pipes:pipe boa ;
+    2 <int-array>
+    dup underlying>> pipe io-error
+    first2 [ <fd> init-fd ] bi@ io.pipes:pipe boa ;
index d1ad309dd5b9cf14df8408d82494566c83380871..fc8e4a7bc08fadad9eab535c4cc60c2de44ccefc 100644 (file)
@@ -6,7 +6,8 @@ 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 ;
+io.files.private windows destructors specialized-arrays.ushort
+specialized-arrays.alien ;
 IN: io.windows.launcher
 
 TUPLE: CreateProcess-args
@@ -103,7 +104,7 @@ TUPLE: CreateProcess-args
             over get-environment
             [ swap % "=" % % "\0" % ] assoc-each
             "\0" %
-        ] "" make >c-ushort-array
+        ] ushort-array{ } make underlying>>
         >>lpEnvironment
     ] when ;
 
@@ -157,8 +158,8 @@ M: windows kill-process* ( handle -- )
 
 M: windows wait-for-processes ( -- ? )
     processes get keys dup
-    [ handle>> PROCESS_INFORMATION-hProcess ] map
-    dup length swap >c-void*-array 0 0
+    [ handle>> PROCESS_INFORMATION-hProcess ] void*-array{ } map-as
+    [ length ] [ underlying>> ] bi 0 0
     WaitForMultipleObjects
     dup HEX: ffffffff = [ win32-error ] when
     dup WAIT_TIMEOUT = [ 2drop t ] [ swap nth process-exited f ] if ;
index 2680b400893fcea5315ee1030ee958cb948e719c..3db726e06a44bb5fa7346b7461968a5795579aa8 100644 (file)
@@ -50,7 +50,7 @@ TUPLE: win32-monitor < monitor port ;
     } case 1array ;
 
 : memory>u16-string ( alien len -- string )
-    [ memory>byte-array ] keep 2/ c-ushort-array> >string ;
+    memory>byte-array utf16n decode ;
 
 : parse-notify-record ( buffer -- path changed )
     [
index 003ef459e30f9c7834a1b4d5cc5c07dd4ba32ad3..4bb4b9e0523948b3f154a6ffac1c677a7c914050 100644 (file)
@@ -346,7 +346,6 @@ M:: sequence method-with-locals ( a -- y ) a reverse ;
 
 { 3 1 } [| from to seq | T{ slice f from to seq } ] must-infer-as
 
-
 :: literal-identity-test ( -- a b )
     { } V{ } ;
 
index e74ecf3dc9fa55da59eb939a2c144ae79138f4bb..e06f714b5618babf57b33f753684ee38656cb8a0 100644 (file)
@@ -274,29 +274,26 @@ SYMBOL: in-lambda?
     "|" parse-tokens make-locals dup push-locals
     \ ] (parse-lambda) <lambda> ;
 
-: parse-binding ( -- pair/f )
-    scan dup "|" = [
+: parse-binding ( end -- pair/f )
+    scan tuck = [
         drop f
     ] [
-        scan {
-            { "[" [ \ ] parse-until >quotation ] }
-            { "[|" [ parse-lambda ] }
-        } case 2array
+        scan-object 2array
     ] if ;
 
-: (parse-bindings) ( -- )
-    parse-binding [
+: (parse-bindings) ( end -- )
+    dup parse-binding dup [
         first2 >r make-local r> 2array ,
         (parse-bindings)
-    ] when* ;
+    ] [ 2drop ] if ;
 
-: parse-bindings ( -- bindings vars )
+: parse-bindings ( end -- bindings vars )
     [
         [ (parse-bindings) ] H{ } make-assoc
         dup push-locals
     ] { } make swap ;
 
-: parse-bindings* ( -- words assoc )
+: parse-bindings* ( end -- words assoc )
     [
         [
             namespace push-locals
@@ -305,13 +302,13 @@ SYMBOL: in-lambda?
         ] { } make-assoc
     ] { } make swap ;
 
-: (parse-wbindings) ( -- )
-    parse-binding [
+: (parse-wbindings) ( end -- )
+    dup parse-binding dup [
         first2 >r make-local-word r> 2array ,
         (parse-wbindings)
-    ] when* ;
+    ] [ 2drop ] if ;
 
-: parse-wbindings ( -- bindings vars )
+: parse-wbindings ( end -- bindings vars )
     [
         [ (parse-wbindings) ] H{ } make-assoc
         dup push-locals
@@ -334,12 +331,12 @@ M: wlet local-rewrite*
     let-rewrite ;
 
 : parse-locals ( -- vars assoc )
-    ")" parse-effect
+    scan "(" assert= ")" parse-effect
     word [ over "declared-effect" set-word-prop ] when*
     in>> [ dup pair? [ first ] when ] map make-locals dup push-locals ;
 
 : parse-locals-definition ( word -- word quot )
-    scan "(" assert= parse-locals \ ; (parse-lambda) <lambda>
+    parse-locals \ ; (parse-lambda) <lambda>
     2dup "lambda" set-word-prop
     lambda-rewrite first ;
 
@@ -357,15 +354,15 @@ PRIVATE>
 : [| parse-lambda parsed-lambda ; parsing
 
 : [let
-    scan "|" assert= parse-bindings
+    scan "|" assert= "|" parse-bindings
     \ ] (parse-lambda) <let> parsed-lambda ; parsing
 
 : [let*
-    scan "|" assert= parse-bindings*
+    scan "|" assert= "|" parse-bindings*
     \ ] (parse-lambda) <let*> parsed-lambda ; parsing
 
 : [wlet
-    scan "|" assert= parse-wbindings
+    scan "|" assert= "|" parse-wbindings
     \ ] (parse-lambda) <wlet> parsed-lambda ; parsing
 
 : :: (::) define ; parsing
index 64326f340eaf9e9e5b1c327299533fae5b416625..300e4f0a716aa552022410f93ae80becf7341eff 100644 (file)
@@ -6,7 +6,8 @@ USING: alien alien.c-types continuations kernel libc math macros
 namespaces math.vectors math.constants math.functions
 math.parser opengl.gl opengl.glu combinators arrays sequences
 splitting words byte-arrays assocs colors accessors
-generalizations locals memoize ;
+generalizations locals specialized-arrays.float
+specialized-arrays.uint ;
 IN: opengl
 
 : color>raw ( object -- r g b a )
@@ -52,7 +53,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     glMatrixMode glPopMatrix ; inline
 
 : gl-material ( face pname params -- )
-    >c-float-array glMaterialfv ;
+    >float-array underlying>> glMaterialfv ;
 
 : gl-vertex-pointer ( seq -- )
     [ 2 GL_FLOAT 0 ] dip glVertexPointer ; inline
@@ -64,7 +65,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     [ 2 GL_FLOAT 0 ] dip glTexCoordPointer ; inline
 
 : line-vertices ( a b -- )
-    append >c-float-array gl-vertex-pointer ;
+    append >float-array underlying>> gl-vertex-pointer ;
 
 : gl-line ( a b -- )
     line-vertices GL_LINES 0 2 glDrawArrays ;
@@ -75,7 +76,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
         [ first 1- 1 ]
         [ [ first 1- ] [ second ] bi ]
         [ second 0 swap ]
-    } cleave 8 narray >c-float-array ;
+    } cleave 8 float-array{ } nsequence underlying>> ;
 
 : rect-vertices ( dim -- )
     (rect-vertices) gl-vertex-pointer ;
@@ -92,7 +93,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
         [ first 0 ]
         [ first2 ]
         [ second 0 swap ]
-    } cleave 8 narray >c-float-array ;
+    } cleave 8 float-array{ } nsequence underlying>> ;
 
 : fill-rect-vertices ( dim -- )
     (fill-rect-vertices) gl-vertex-pointer ;
@@ -119,7 +120,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     circle-steps unit-circle adjust-points scale-points ;
 
 : circle-vertices ( loc dim steps -- vertices )
-    circle-points concat >c-float-array ;
+    circle-points concat >float-array underlying>> ;
 
 : (gen-gl-object) ( quot -- id )
     >r 1 0 <uint> r> keep *uint ; inline
@@ -160,7 +161,7 @@ MACRO: all-enabled-client-state ( seq quot -- )
     glActiveTexture swap glBindTexture gl-error ;
 
 : (set-draw-buffers) ( buffers -- )
-    dup length swap >c-uint-array glDrawBuffers ;
+    [ length ] [ >uint-array underlying>> ] bi glDrawBuffers ;
 
 MACRO: set-draw-buffers ( buffers -- )
     words>values [ (set-draw-buffers) ] curry ;
@@ -203,11 +204,8 @@ TUPLE: sprite loc dim dim2 dlist texture ;
 
 : gl-translate ( point -- ) first2 0.0 glTranslated ;
 
-MEMO: (rect-texture-coords) ( -- seq )
-    { 0 0 1 0 1 1 0 1 } >c-float-array ;
-
 : rect-texture-coords ( -- )
-    (rect-texture-coords) gl-texture-coord-pointer ;
+    float-array{ 0 0 1 0 1 1 0 1 } gl-texture-coord-pointer ;
 
 : draw-sprite ( sprite -- )
     GL_TEXTURE_COORD_ARRAY [
index 3a75ad65b60687a7e7e85c20fac28f34f161e6c4..c02fbe2b0bddc10e81314c57f84753e43b4e2d14 100644 (file)
@@ -2,9 +2,9 @@
 ! See http://factorcode.org/license.txt for BSD license.
 ! 
 USING: tools.test kernel serialize io io.streams.byte-array math
-alien arrays byte-arrays bit-arrays float-arrays sequences math
-prettyprint parser classes math.constants io.encodings.binary
-random assocs ;
+alien arrays byte-arrays bit-arrays specialized-arrays.double
+sequences math prettyprint parser classes math.constants
+io.encodings.binary random assocs ;
 IN: serialize.tests
 
 : test-serialize-cell
@@ -48,7 +48,7 @@ C: <serialize-test> serialize-test
         T{ serialize-test f "a" 2 }
         B{ 50 13 55 64 1 }
         ?{ t f t f f t f }
-        F{ 1.0 3.0 4.0 1.0 2.35 0.33 }
+        double-array{ 1.0 3.0 4.0 1.0 2.35 0.33 }
         << 1 [ 2 ] curry parsed >>
         { { "a" "bc" } { "de" "fg" } }
         H{ { "a" "bc" } { "de" "fg" } }
diff --git a/basis/specialized-arrays/alien/alien.factor b/basis/specialized-arrays/alien/alien.factor
new file mode 100644 (file)
index 0000000..465d166
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-arrays.alien
+
+<< "void*" define-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/authors.txt b/basis/specialized-arrays/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/basis/specialized-arrays/bool/bool.factor b/basis/specialized-arrays/bool/bool.factor
new file mode 100644 (file)
index 0000000..759ee91
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..cdf78ee
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-arrays.char
+
+<< "char" define-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/alien/alien.factor b/basis/specialized-arrays/direct/alien/alien.factor
new file mode 100644 (file)
index 0000000..b1dee2e
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.alien
+
+<< "void*" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/bool/bool.factor b/basis/specialized-arrays/direct/bool/bool.factor
new file mode 100644 (file)
index 0000000..139723d
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.bool
+
+<< "bool" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/char/char.factor b/basis/specialized-arrays/direct/char/char.factor
new file mode 100644 (file)
index 0000000..cf4e361
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.char
+
+<< "char" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/direct.factor b/basis/specialized-arrays/direct/direct.factor
new file mode 100644 (file)
index 0000000..7c15c66
--- /dev/null
@@ -0,0 +1,3 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: specialized-arrays.direct
diff --git a/basis/specialized-arrays/direct/double/double.factor b/basis/specialized-arrays/direct/double/double.factor
new file mode 100644 (file)
index 0000000..423ceba
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.double
+
+<< "double" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/float/float.factor b/basis/specialized-arrays/direct/float/float.factor
new file mode 100644 (file)
index 0000000..91a117a
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.float
+
+<< "float" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/functor/functor.factor b/basis/specialized-arrays/direct/functor/functor.factor
new file mode 100644 (file)
index 0000000..dd5164b
--- /dev/null
@@ -0,0 +1,35 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: functors sequences sequences.private kernel words classes
+math alien alien.c-types byte-arrays accessors
+specialized-arrays ;
+IN: specialized-arrays.direct.functor
+
+FUNCTOR: define-direct-array ( T -- )
+
+A'      IS ${T}-array
+>A'     IS >${T}-array
+<A'>    IS <${A'}>
+
+A       DEFINES direct-${T}-array
+<A>     DEFINES <${A}>
+
+NTH     [ T dup c-getter array-accessor ]
+SET-NTH [ T dup c-setter array-accessor ]
+
+WHERE
+
+TUPLE: A
+{ underlying alien read-only }
+{ length fixnum read-only } ;
+
+: <A> A boa ; inline
+M: A length length>> ;
+M: A nth-unsafe underlying>> NTH call ;
+M: A set-nth-unsafe underlying>> SET-NTH call ;
+M: A like drop dup A instance? [ >A' execute ] unless ;
+M: A new-sequence drop <A'> execute ;
+
+INSTANCE: A sequence
+
+;FUNCTOR
diff --git a/basis/specialized-arrays/direct/int/int.factor b/basis/specialized-arrays/direct/int/int.factor
new file mode 100644 (file)
index 0000000..33410a7
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.int
+
+<< "int" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/long/long.factor b/basis/specialized-arrays/direct/long/long.factor
new file mode 100644 (file)
index 0000000..ee2ed71
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.long
+
+<< "long" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/longlong/longlong.factor b/basis/specialized-arrays/direct/longlong/longlong.factor
new file mode 100644 (file)
index 0000000..12306ff
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.longlong
+
+<< "longlong" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/short/short.factor b/basis/specialized-arrays/direct/short/short.factor
new file mode 100644 (file)
index 0000000..375696c
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.short
+
+<< "short" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/uchar/uchar.factor b/basis/specialized-arrays/direct/uchar/uchar.factor
new file mode 100644 (file)
index 0000000..d0a8f0d
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.uchar
+
+<< "uchar" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/uint/uint.factor b/basis/specialized-arrays/direct/uint/uint.factor
new file mode 100644 (file)
index 0000000..18b3b63
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.uint
+
+<< "uint" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/ulong/ulong.factor b/basis/specialized-arrays/direct/ulong/ulong.factor
new file mode 100644 (file)
index 0000000..89e6f29
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.ulong
+
+<< "ulong" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/ulonglong/ulonglong.factor b/basis/specialized-arrays/direct/ulonglong/ulonglong.factor
new file mode 100644 (file)
index 0000000..8cb6af2
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.ulonglong
+
+<< "ulonglong" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/direct/ushort/ushort.factor b/basis/specialized-arrays/direct/ushort/ushort.factor
new file mode 100644 (file)
index 0000000..09f66b9
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.direct.functor
+IN: specialized-arrays.direct.ushort
+
+<< "ushort" define-direct-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/double/double.factor b/basis/specialized-arrays/double/double.factor
new file mode 100644 (file)
index 0000000..b7fc3a8
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-arrays.double
+
+<< "double" define-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/float/float.factor b/basis/specialized-arrays/float/float.factor
new file mode 100644 (file)
index 0000000..5d9da66
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..8536e6f
--- /dev/null
@@ -0,0 +1,61 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: functors sequences sequences.private
+prettyprint.backend kernel words classes math parser
+alien.c-types byte-arrays accessors ;
+IN: specialized-arrays.functor
+
+FUNCTOR: define-array ( T -- )
+
+A       DEFINES ${T}-array
+<A>     DEFINES <${A}>
+>A      DEFINES >${A}
+A{      DEFINES ${A}{
+
+NTH     [ T dup c-getter array-accessor ]
+SET-NTH [ T dup c-setter array-accessor ]
+
+WHERE
+
+TUPLE: A
+{ length array-capacity read-only }
+{ underlying byte-array read-only } ;
+
+: <A> dup T <c-array> A boa ; inline
+
+M: A clone [ length>> ] [ underlying>> clone ] bi A boa ;
+
+M: A length length>> ;
+
+M: A nth-unsafe underlying>> NTH call ;
+
+M: A set-nth-unsafe underlying>> SET-NTH call ;
+
+: >A A new clone-like ; inline
+
+M: A like drop dup A instance? [ >A execute ] unless ;
+
+M: A new-sequence drop <A> execute ;
+
+M: A equal? over A instance? [ sequence= ] [ 2drop f ] if ;
+
+M: A resize
+    [ drop ] [
+        [ T heap-size * ] [ underlying>> ] bi*
+        resize-byte-array
+    ] 2bi
+    A boa ;
+
+M: A byte-length underlying>> length ;
+
+M: A pprint-delims drop A{ \ } ;
+
+M: A >pprint-sequence ;
+
+M: A pprint* pprint-object ;
+
+: A{ \ } [ >A execute ] parse-literal ; parsing
+
+INSTANCE: A sequence
+
+;FUNCTOR
diff --git a/basis/specialized-arrays/int/int.factor b/basis/specialized-arrays/int/int.factor
new file mode 100644 (file)
index 0000000..37f4b59
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..2cba642
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..195dd78
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-arrays.longlong
+
+<< "longlong" define-array >>
\ No newline at end of file
diff --git a/basis/specialized-arrays/short/short.factor b/basis/specialized-arrays/short/short.factor
new file mode 100644 (file)
index 0000000..3891462
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..54cb5d1
--- /dev/null
@@ -0,0 +1,37 @@
+USING: help.markup help.syntax byte-arrays ;
+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:"
+{ $table
+    { { $snippet "T-array" } { "The class of arrays with elements of type " { $snippet "T" } } }
+    { { $snippet "<T-array>" } { "Constructor for arrays with elements of type " { $snippet "T" } "; stack effect " { $snippet "( len -- array )" } } }
+    { { $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 "void*" }
+    { $snippet "bool" }
+}
+"Specialized arrays are generated with a functor in the " { $vocab-link "specialized-arrays.functor" } " vocabulary."
+$nl
+"The " { $vocab-link "specialized-vectors" } " vocabulary provides resizable versions of the above." ;
+
+ABOUT: "specialized-arrays"
diff --git a/basis/specialized-arrays/specialized-arrays-tests.factor b/basis/specialized-arrays/specialized-arrays-tests.factor
new file mode 100644 (file)
index 0000000..5810085
--- /dev/null
@@ -0,0 +1,11 @@
+IN: specialized-arrays.tests
+USING: tools.test specialized-arrays sequences
+specialized-arrays.int speicalized-arrays.bool ;
+
+[ t ] [ { 1 2 3 } >int-array int-array? ] unit-test
+
+[ t ] [ int-array{ 1 2 3 } int-array? ] unit-test
+
+[ 2 ] [ int-array{ 1 2 3 } second ] unit-test
+
+[ t ] [ { t f t } >bool-array underlying>> { 1 0 1 } >int-array underlying>> = ] unit-test
diff --git a/basis/specialized-arrays/specialized-arrays.factor b/basis/specialized-arrays/specialized-arrays.factor
new file mode 100644 (file)
index 0000000..631d28d
--- /dev/null
@@ -0,0 +1,3 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: specialized-arrays
diff --git a/basis/specialized-arrays/summary.txt b/basis/specialized-arrays/summary.txt
new file mode 100644 (file)
index 0000000..6191766
--- /dev/null
@@ -0,0 +1 @@
+Arrays of unboxed primitive C types
diff --git a/basis/specialized-arrays/tags.txt b/basis/specialized-arrays/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections
diff --git a/basis/specialized-arrays/uchar/uchar.factor b/basis/specialized-arrays/uchar/uchar.factor
new file mode 100644 (file)
index 0000000..c6ed4f3
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..1534a3d
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..27dc129
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..cbb2b3c
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..e0989aa
--- /dev/null
@@ -0,0 +1,4 @@
+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
new file mode 100644 (file)
index 0000000..e86f9f6
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.alien
+
+<< "void*" define-vector >>
\ No newline at end of file
diff --git a/basis/specialized-vectors/authors.txt b/basis/specialized-vectors/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/basis/specialized-vectors/bool/bool.factor b/basis/specialized-vectors/bool/bool.factor
new file mode 100644 (file)
index 0000000..3270c1d
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..2f0e2f0
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..b2ca65b
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..aab6b7c
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..cf82f0d
--- /dev/null
@@ -0,0 +1,46 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: functors sequences sequences.private growable
+prettyprint.backend kernel words classes math parser ;
+IN: specialized-vectors.functor
+
+FUNCTOR: define-vector ( T -- )
+
+A   IS      ${T}-array
+<A> IS      <A>
+
+V   DEFINES ${T}-vector
+<V> DEFINES <${V}>
+>V  DEFINES >${V}
+V{  DEFINES ${V}{
+
+WHERE
+
+TUPLE: V { underlying A } { length array-capacity } ;
+
+: <V> <A> execute 0 V boa ; inline
+
+M: V like
+    drop dup V instance? [
+        dup A instance? [ dup length V boa ] [ >V execute ] if
+    ] unless ;
+
+M: V new-sequence drop [ <A> execute ] [ >fixnum ] bi V boa ;
+
+M: A new-resizable drop <V> execute ;
+
+M: V equal? over V instance? [ sequence= ] [ 2drop f ] if ;
+
+: >V V new clone-like ; inline
+
+M: V pprint-delims drop V{ \ } ;
+
+M: V >pprint-sequence ;
+
+M: V pprint* pprint-object ;
+
+: V{ [ >V execute ] parse-literal ; parsing
+
+INSTANCE: V growable
+
+;FUNCTOR
diff --git a/basis/specialized-vectors/int/int.factor b/basis/specialized-vectors/int/int.factor
new file mode 100644 (file)
index 0000000..b02ec25
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..0f80bc3
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..78c86eb
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..b6d150b
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..5c0a15c
--- /dev/null
@@ -0,0 +1,35 @@
+USING: help.markup help.syntax byte-vectors ;
+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:"
+{ $table
+    { { $snippet "T-vector" } { "The class of vectors with elements of type " { $snippet "T" } } }
+    { { $snippet "<T-vector>" } { "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." ;
+
+ABOUT: "specialized-vectors"
diff --git a/basis/specialized-vectors/specialized-vectors.factor b/basis/specialized-vectors/specialized-vectors.factor
new file mode 100644 (file)
index 0000000..5df602c
--- /dev/null
@@ -0,0 +1,3 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+IN: specialized-vectors
diff --git a/basis/specialized-vectors/summary.txt b/basis/specialized-vectors/summary.txt
new file mode 100644 (file)
index 0000000..9df7115
--- /dev/null
@@ -0,0 +1 @@
+Vectors of unboxed primitive C types
diff --git a/basis/specialized-vectors/tags.txt b/basis/specialized-vectors/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections
diff --git a/basis/specialized-vectors/uchar/uchar.factor b/basis/specialized-vectors/uchar/uchar.factor
new file mode 100644 (file)
index 0000000..245d4b3
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..cb00880
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..0c0e0d3
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..f3cd2cd
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.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
new file mode 100644 (file)
index 0000000..78386ff
--- /dev/null
@@ -0,0 +1,4 @@
+USE: specialized-arrays.functor
+IN: specialized-vector.ushort
+
+<< "ushort" define-vector >>
\ No newline at end of file
index 11fb69fc7d9b6582123fc9ad436a90ccaa702448..c2fe483d35f00d5f3a8d3984bb067e5d32787f47 100644 (file)
@@ -5,7 +5,8 @@ strings quotations assocs combinators classes colors
 classes.tuple opengl opengl.gl math.vectors ui.commands ui.gadgets
 ui.gadgets.borders ui.gadgets.labels ui.gadgets.theme
 ui.gadgets.tracks ui.gadgets.packs ui.gadgets.worlds ui.gestures
-ui.render math.geometry.rect locals alien.c-types ;
+ui.render math.geometry.rect locals alien.c-types
+specialized-arrays.float ;
 
 IN: ui.gadgets.buttons
 
@@ -118,7 +119,7 @@ TUPLE: checkmark-paint < caching-pen color last-vertices ;
     } cleave 4array ;
 
 : checkmark-vertices ( dim -- vertices )
-    checkmark-points concat >c-float-array ;
+    checkmark-points concat >float-array underlying>> ;
 
 PRIVATE>
 
index 71304aca0bc2c0bcaa505c1caebde5277b35bf3f..9529e34c708b166b5b086868f861cef46edb66dd 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien alien.c-types arrays hashtables io kernel
 math namespaces opengl opengl.gl opengl.glu sequences strings
 io.styles vectors combinators math.vectors ui.gadgets colors
-math.order math.geometry.rect locals ;
+math.order math.geometry.rect locals specialized-arrays.float ;
 IN: ui.render
 
 SYMBOL: clip
@@ -140,10 +140,11 @@ TUPLE: gradient < caching-pen colors last-vertices last-colors ;
     direction dim v* dim over v- swap
     colors length dup 1- v/n [ v*n ] with map
     [ dup rot v+ 2array ] with map
-    concat concat >c-float-array ;
+    concat concat >float-array underlying>> ;
 
 : gradient-colors ( colors -- seq )
-    [ color>raw 4array dup 2array ] map concat concat >c-float-array ;
+    [ color>raw 4array dup 2array ] map concat concat
+    >float-array underlying>> ;
 
 M: gradient recompute-pen ( gadget gradient -- )
     tuck
@@ -171,7 +172,7 @@ M: gradient draw-interior
 TUPLE: polygon color vertex-array count ;
 
 : <polygon> ( color points -- polygon )
-    [ concat >c-float-array ] [ length ] bi polygon boa ;
+    [ concat >float-array underlying>> ] [ length ] bi polygon boa ;
 
 : draw-polygon ( polygon mode -- )
     swap
index 1f3a6bf78a3d744cb6fa029f4014f8d1e1a7c874..67acd3737a319383f7a8c5545a1291d8a8cecb81 100644 (file)
@@ -1,7 +1,8 @@
 ! 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 ;
+combinators.short-circuit fry kernel layouts sequences
+specialized-arrays.alien ;
 IN: unix.utilities
 
 : more? ( alien -- ? )
@@ -16,4 +17,4 @@ IN: unix.utilities
     [ ] produce nip ;
 
 : strings>alien ( strings encoding -- alien )
-    '[ _ malloc-string ] map f suffix >c-void*-array ;
+    '[ _ malloc-string ] void*-array{ } map f suffix underlying>> ;
index d376cccae2e6eede05f82ac7a710bd5b19cf535a..5cb830bc665054588fa02b3a2d828a3de3cecaf0 100644 (file)
@@ -92,9 +92,6 @@ unless
     [ [ (( -- alien )) define-declared ] pick slip ]
     with-compilation-unit ;
 
-: byte-array>malloc ( byte-array -- alien )
-    [ byte-length malloc ] [ over byte-array>memory ] bi ;
-
 : (callback-word) ( function-name interface-name counter -- word )
     [ "::" rot 3append "-callback-" ] dip number>string 3append
     "windows.com.wrapper.callbacks" create ;
@@ -132,7 +129,7 @@ unless
     1 0 rot set-ulong-nth ;
 
 : (callbacks>vtbl) ( callbacks -- vtbl )
-    [ execute ] map >c-void*-array byte-array>malloc ;
+    [ execute ] void*-array{ } map-as underlying>> malloc-byte-array ;
 : (callbacks>vtbls) ( callbacks -- vtbls )
     [ (callbacks>vtbl) ] map ;
 
index 1007b47a5b54491d5275ecba4a062b79b8ef146f..2a0a889bb9c0a1147f91292ab6c13c0838ccc3f1 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.c-types alien.strings alien.syntax arrays
 kernel math namespaces sequences io.encodings.string
-io.encodings.utf8 io.encodings.ascii x11.xlib x11.constants ;
+io.encodings.utf8 io.encodings.ascii x11.xlib x11.constants
+specialized-arrays.int ;
 IN: x11.clipboard
 
 ! This code was based on by McCLIM's Backends/CLX/port.lisp
@@ -50,7 +51,7 @@ TUPLE: x-clipboard atom contents ;
     "TARGETS" x-atom 32 PropModeReplace
     {
         "UTF8_STRING" "STRING" "TARGETS" "TIMESTAMP"
-    } [ x-atom ] map >c-int-array
+    } [ x-atom ] int-array{ } map-as underlying>>
     4 XChangeProperty drop ;
 
 : set-timestamp-prop ( evt -- )
@@ -58,7 +59,7 @@ TUPLE: x-clipboard atom contents ;
     [ XSelectionRequestEvent-requestor ] keep
     [ XSelectionRequestEvent-property ] keep
     >r "TIMESTAMP" x-atom 32 PropModeReplace r>
-    XSelectionRequestEvent-time 1array >c-int-array
+    XSelectionRequestEvent-time <int>
     1 XChangeProperty drop ;
 
 : send-notify ( evt prop -- )
index eefb93772a07235776a7e521bfdf44418768738d..99bae97b14090f4991072e1f01f7158dc3b5bd3d 100644 (file)
@@ -3,7 +3,7 @@
 !
 ! based on glx.h from xfree86, and some of glxtokens.h
 USING: alien alien.c-types alien.syntax alien.syntax.private x11.xlib
-namespaces make kernel sequences parser words ;
+namespaces make kernel sequences parser words specialized-arrays.int ;
 IN: x11.glx
 
 LIBRARY: glx
@@ -93,7 +93,7 @@ FUNCTION: void* glXGetProcAddressARB ( char* procname ) ;
         GLX_DOUBLEBUFFER ,
         GLX_DEPTH_SIZE , 16 ,
         0 ,
-    ] { } make >c-int-array
+    ] int-array{ } make underlying>>
     glXChooseVisual
     [ "Could not get a double-buffered GLX RGBA visual" throw ] unless* ;
 
index 35e1906b2b786069a0a7e04904bcd17cc563ada1..c91ff83493f07cd68f72aee98071dd3341954d2e 100644 (file)
@@ -38,17 +38,17 @@ SYMBOL: keybuf
 SYMBOL: keysym
 
 : prepare-lookup ( -- )
-    buf-size "uint" <c-array> keybuf set
+    buf-size <uint-array> keybuf set
     0 <KeySym> keysym set ;
 
 : finish-lookup ( len -- string keysym )
-    keybuf get swap c-uint-array> >string
+    keybuf get swap 2 * head utf16n decode
     keysym get *KeySym ;
 
 : lookup-string ( event xic -- string keysym )
     [
         prepare-lookup
-        swap keybuf get buf-size keysym get 0 <int>
+        swap keybuf get underlying>> buf-size keysym get 0 <int>
         XwcLookupString
         finish-lookup
     ] with-scope ;
index 105bdc325f123a6673f849956acafc418eef2d78..b27bab9b25036f01dc979ac442c5512ba18f46c8 100644 (file)
@@ -23,7 +23,7 @@ IN: bootstrap.syntax
     "syntax" lookup t "delimiter" set-word-prop ;
 
 : define-syntax ( name quot -- )
-    >r "syntax" lookup dup r> define t "parsing" set-word-prop ;
+    >r "syntax" lookup dup r> define make-parsing ;
 
 [
     { "]" "}" ";" ">>" } [ define-delimiter ] each
@@ -93,7 +93,7 @@ IN: bootstrap.syntax
     "foldable" [ word make-foldable ] define-syntax
     "flushable" [ word make-flushable ] define-syntax
     "delimiter" [ word t "delimiter" set-word-prop ] define-syntax
-    "parsing" [ word t "parsing" set-word-prop ] define-syntax
+    "parsing" [ word make-parsing ] define-syntax
 
     "SYMBOL:" [
         CREATE-WORD define-symbol
index 66c60dc06e5c322b1a94820e428903749f7817f3..f8cbaf0a22a95e5e714aa559a3e4912b3dbb48d4 100644 (file)
@@ -243,6 +243,8 @@ ERROR: bad-create name vocab ;
 
 PREDICATE: parsing-word < word "parsing" word-prop ;
 
+: make-parsing ( word -- ) t "parsing" set-word-prop ;
+
 : delimiter? ( obj -- ? )
     dup word? [ "delimiter" word-prop ] [ drop f ] if ;
 
index 7cff06d1bc68fefd6e54a9b7856572980369524c..9ece8465ab98268e5a4d9aaafb30cab41ad88c49 100644 (file)
@@ -1,19 +1,14 @@
-USING: sequences alien.c-types math hints kernel byte-arrays ;
+USING: sequences hints kernel math specialized-arrays.int ;
 IN: benchmark.dawes
 
 ! Phil Dawes's performance problem
 
-: int-length ( byte-array -- n ) length "int" heap-size /i ; inline
+: count-ones ( byte-array -- n ) [ 1 = ] sigma ;
 
-: count-ones ( byte-array -- n )
-    0 swap [ int-length ] keep [
-        int-nth 1 = [ 1 + ] when
-    ] curry each-integer ;
-
-HINTS: count-ones byte-array ;
+HINTS: count-ones int-array ;
 
 : make-byte-array ( -- byte-array )
-    120000 [ 255 bitand ] map >c-int-array ;
+    120000 [ 255 bitand ] int-array{ } map-as ;
 
 : dawes-benchmark ( -- )
     make-byte-array 200 swap [ count-ones ] curry replicate drop ;
index 0bad9cc9437131de54a3a3eff66e7fe92b80ab7b..fd420d0b7d299ebd870d8121babedc668c38b816 100644 (file)
@@ -1,5 +1,5 @@
 USING: alien.c-types continuations destructors kernel
-opengl opengl.gl bunny.model ;
+opengl opengl.gl bunny.model specialized-arrays.float ;
 IN: bunny.fixed-pipeline
 
 TUPLE: bunny-fixed-pipeline ;
@@ -13,7 +13,7 @@ M: bunny-fixed-pipeline draw-bunny
     GL_LIGHTING glEnable
     GL_LIGHT0 glEnable
     GL_COLOR_MATERIAL glEnable
-    GL_LIGHT0 GL_POSITION { 1.0 -1.0 1.0 1.0 } >c-float-array glLightfv
+    GL_LIGHT0 GL_POSITION float-array{ 1.0 -1.0 1.0 1.0 } underlying>> glLightfv
     GL_FRONT_AND_BACK GL_SHININESS 100.0 glMaterialf
     GL_FRONT_AND_BACK GL_SPECULAR glColorMaterial
     GL_FRONT_AND_BACK GL_AMBIENT_AND_DIFFUSE glColorMaterial
index 1bbaf796ade41f3e01c1818059a0f91c97490993..c9d109cb717b5d83a4b8aa2f8b52b5ac59fddd2b 100755 (executable)
@@ -2,7 +2,8 @@ USING: accessors alien.c-types arrays combinators destructors
 http.client io io.encodings.ascii io.files kernel math
 math.matrices math.parser math.vectors opengl
 opengl.capabilities opengl.gl opengl.demo-support sequences
-sequences.lib splitting vectors words ;
+sequences.lib splitting vectors words
+specialized-arrays.double specialized-arrays.uint ;
 IN: bunny.model
 
 : numbers ( str -- seq )
@@ -65,11 +66,11 @@ TUPLE: bunny-buffers array element-array nv ni ;
     {
         [
             [ first concat ] [ second concat ] bi
-            append >c-float-array
+            append >double-array underlying>>
             GL_ARRAY_BUFFER swap GL_STATIC_DRAW <gl-buffer>
         ]
         [
-            third concat >c-uint-array
+            third concat >uint-array underlying>>
             GL_ELEMENT_ARRAY_BUFFER swap GL_STATIC_DRAW <gl-buffer>
         ]
         [ first length 3 * ]
index 0f21142f2a3e94468187a8b2801256d983c609fb..bdd02c9e1330f245d2f64b06f201776dcefb20db 100644 (file)
@@ -5,7 +5,7 @@
 ! http://cairographics.org/samples/
 USING: cairo cairo.ffi locals math.constants math
 io.backend kernel alien.c-types libc namespaces
-cairo.gadgets ui.gadgets accessors ;
+cairo.gadgets ui.gadgets accessors specialized-arrays.double ;
 
 IN: cairo.samples
 
@@ -69,7 +69,7 @@ M:: clip-image-gadget render-cairo* ( gadget -- )
 
 TUPLE: dash-gadget < cairo-gadget ;
 M:: dash-gadget render-cairo* ( gadget -- )
-    [let | dashes [ { 50 10 10 10 } >c-double-array ]
+    [let | dashes [ double-array{ 50 10 10 10 } underlying>> ]
            ndash [ 4 ] |
         cr dashes ndash -50 cairo_set_dash
         cr 10 cairo_set_line_width
index 102de8fd22edc6caad73780ffd882f249130c918..8110251fb77fde969486180f6a63eb0e6b6c0478 100644 (file)
@@ -6,7 +6,7 @@ USING: kernel alien.c-types combinators namespaces make arrays
        vars colors self self.slots
        random-weighted colors.hsv cfdg.gl accessors
        ui.gadgets.handler ui.gestures assocs ui.gadgets macros
-       qualified ;
+       qualified speicalized-arrays.double ;
 QUALIFIED: syntax
 IN: cfdg
 
@@ -75,7 +75,7 @@ VAR: threshold
     2 * sin ,   2 * cos neg ,   0 ,   0 ,
           0 ,             0 ,   1 ,   0 , 
           0 ,             0 ,   0 ,   1 , ]
-  { } make >c-double-array glMultMatrixd ;
+  double-array{ } make underlying>> glMultMatrixd ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
index 219fe0ca05d583ac1d1d06615f208c8eb183a40d..a7d6620fff40ae4b9442aa2ebbaa1e09022ec6af 100755 (executable)
@@ -1,14 +1,15 @@
 USING: tools.deploy.config ;
 H{
-    { deploy-c-types? f }
-    { deploy-name "Hello world (console)" }
-    { deploy-threads? f }
+    { deploy-unicode? f }
+    { deploy-reflection 1 }
     { deploy-word-props? f }
-    { deploy-reflection 2 }
-    { deploy-io 2 }
     { deploy-math? f }
-    { deploy-ui? f }
-    { deploy-compiler? f }
-    { "stop-after-last-window?" t }
+    { deploy-name "Hello world (console)" }
     { deploy-word-defs? f }
+    { "stop-after-last-window?" t }
+    { deploy-compiler? t }
+    { deploy-ui? f }
+    { deploy-threads? f }
+    { deploy-io 2 }
+    { deploy-c-types? f }
 }
index 7bd6eb7fbcffa7c831b9c9b50590625b597e970c..b78e7de88e892008ad9a9e9c2765b090030a3e57 100644 (file)
@@ -3,7 +3,7 @@
 USING: accessors alien.c-types jamshred.game jamshred.oint
 jamshred.player jamshred.tunnel kernel math math.constants
 math.functions math.vectors opengl opengl.gl opengl.glu
-opengl.demo-support sequences float-arrays ;
+opengl.demo-support sequences specialized-arrays.float ;
 IN: jamshred.gl
 
 : min-vertices 6 ; inline
@@ -84,10 +84,10 @@ IN: jamshred.gl
     GL_FOG_DENSITY 0.09 glFogf
     GL_FRONT GL_AMBIENT_AND_DIFFUSE glColorMaterial
     GL_COLOR_MATERIAL glEnable
-    GL_LIGHT0 GL_POSITION F{ 0.0 0.0 0.0 1.0 } >c-float-array glLightfv
-    GL_LIGHT0 GL_AMBIENT F{ 0.2 0.2 0.2 1.0 } >c-float-array glLightfv
-    GL_LIGHT0 GL_DIFFUSE F{ 1.0 1.0 1.0 1.0 } >c-float-array glLightfv
-    GL_LIGHT0 GL_SPECULAR F{ 1.0 1.0 1.0 1.0 } >c-float-array glLightfv ;
+    GL_LIGHT0 GL_POSITION float-array{ 0.0 0.0 0.0 1.0 } underlying>> glLightfv
+    GL_LIGHT0 GL_AMBIENT float-array{ 0.2 0.2 0.2 1.0 } underlying>> glLightfv
+    GL_LIGHT0 GL_DIFFUSE float-array{ 1.0 1.0 1.0 1.0 } underlying>> glLightfv
+    GL_LIGHT0 GL_SPECULAR float-array{ 1.0 1.0 1.0 1.0 } underlying>> glLightfv ;
 
 : player-view ( player -- )
     [ location>> ]
index 4f50543e73ed479010b323b8a5164e4e06c22c81..0899e2d079f7f2f2c22151cbf5c750407494a023 100755 (executable)
@@ -3,7 +3,7 @@ combinators.lib combinators.short-circuit fry kernel locals macros
 math math.blas.cblas math.blas.vectors math.blas.vectors.private
 math.complex math.functions math.order multi-methods qualified
 sequences sequences.merged sequences.private generalizations
-shuffle symbols ;
+shuffle symbols speicalized-arrays.float specialized-arrays.double ;
 QUALIFIED: syntax
 IN: math.blas.matrices
 
@@ -143,14 +143,14 @@ METHOD: (blas-vector-like) { object object object double-complex-blas-matrix }
 PRIVATE>
 
 : >float-blas-matrix ( arrays -- matrix )
-    [ >c-float-array ] (>matrix) <float-blas-matrix> ;
+    [ >float-array underlying>> ] (>matrix) <float-blas-matrix> ;
 : >double-blas-matrix ( arrays -- matrix )
-    [ >c-double-array ] (>matrix) <double-blas-matrix> ;
+    [ >double-array underlying>> ] (>matrix) <double-blas-matrix> ;
 : >float-complex-blas-matrix ( arrays -- matrix )
-    [ (flatten-complex-sequence) >c-float-array ] (>matrix)
+    [ (flatten-complex-sequence) >float-array underlying>> ] (>matrix)
     <float-complex-blas-matrix> ;
 : >double-complex-blas-matrix ( arrays -- matrix )
-    [ (flatten-complex-sequence) >c-double-array ] (>matrix)
+    [ (flatten-complex-sequence) >double-array underlying>> ] (>matrix)
     <double-complex-blas-matrix> ;
 
 GENERIC: n*M.V+n*V! ( alpha A x beta y -- y=alpha*A.x+b*y )
index a135f08f28d3136961c2af375cac3d90e1e6e640..f29ef30ab7447f0ae1dd0eb96c85baa95721e434 100755 (executable)
@@ -1,7 +1,9 @@
 USING: accessors alien alien.c-types arrays byte-arrays combinators
 combinators.short-circuit fry kernel macros math math.blas.cblas
 math.complex math.functions math.order multi-methods qualified
-sequences sequences.private generalizations ;
+sequences sequences.private generalizations
+specialized-arrays.float specialized-arrays.double
+specialized-arrays.direct.float specialized-arrays.direct.double ;
 QUALIFIED: syntax
 IN: math.blas.vectors
 
@@ -90,14 +92,14 @@ MACRO: (do-copy) ( copy make-vector -- )
     [ [ real-part ] [ imaginary-part ] bi 2array ] map concat ;
 
 : (>c-complex) ( complex -- alien )
-    [ real-part ] [ imaginary-part ] bi 2array >c-float-array ;
+    [ real-part ] [ imaginary-part ] bi float-array{ } 2sequence underlying>> ;
 : (>z-complex) ( complex -- alien )
-    [ real-part ] [ imaginary-part ] bi 2array >c-double-array ;
+    [ real-part ] [ imaginary-part ] bi double-array{ } 2sequence underlying>> ;
 
 : (c-complex>) ( alien -- complex )
-    2 c-float-array> first2 rect> ;
+    2 <direct-float-array> first2 rect> ;
 : (z-complex>) ( alien -- complex )
-    2 c-double-array> first2 rect> ;
+    2 <direct-double-array> first2 rect> ;
 
 : (prepare-nth) ( n v -- n*inc v-data )
     [ inc>> ] [ data>> ] bi [ * ] dip ;
@@ -170,14 +172,14 @@ syntax:M: blas-vector-base equal?
     } 2&& ;
 
 : >float-blas-vector ( seq -- v )
-    [ >c-float-array ] [ length ] bi 1 <float-blas-vector> ;
+    [ >float-array underlying>> ] [ length ] bi 1 <float-blas-vector> ;
 : >double-blas-vector ( seq -- v )
-    [ >c-double-array ] [ length ] bi 1 <double-blas-vector> ;
+    [ >double-array underlying>> ] [ length ] bi 1 <double-blas-vector> ;
 : >float-complex-blas-vector ( seq -- v )
-    [ (flatten-complex-sequence) >c-float-array ] [ length ] bi
+    [ (flatten-complex-sequence) >float-array underlying>> ] [ length ] bi
     1 <float-complex-blas-vector> ;
 : >double-complex-blas-vector ( seq -- v )
-    [ (flatten-complex-sequence) >c-double-array ] [ length ] bi
+    [ (flatten-complex-sequence) >double-array underlying>> ] [ length ] bi
     1 <double-complex-blas-vector> ;
 
 syntax:M: float-blas-vector clone
index 2a8959b4a08e16e2823124b599eecae173e90d96..40593d1e8d7a169c0646d608d8a5e1bcdb9052a3 100644 (file)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel arrays alien system combinators alien.syntax namespaces
        alien.c-types sequences vocabs.loader shuffle combinators.lib
-       openal.backend ;
+       openal.backend specialized-arrays.uint ;
 IN: openal
 
 << "alut" {
@@ -248,10 +248,10 @@ SYMBOL: init
 : <uint-array> ( n -- byte-array ) "ALuint" <c-array> ;
 
 : gen-sources ( size -- seq )
-  dup <uint-array> 2dup alGenSources swap c-uint-array> ;
+  dup <uint-array> 2dup underlying>> alGenSources swap ;
 
 : gen-buffers ( size -- seq )
-  dup <uint-array> 2dup alGenBuffers swap c-uint-array> ;
+  dup <uint-array> 2dup underlying>> alGenBuffers swap ;
 
 : gen-buffer ( -- buffer ) 1 gen-buffers first ;
 
@@ -267,7 +267,7 @@ os macosx? "openal.macosx" "openal.other" ? require
   [ alBufferData ] 4keep alutUnloadWAV ;
 
 : queue-buffers ( source buffers -- )
-    [ length ] [ >c-uint-array ] bi alSourceQueueBuffers ;
+    [ length ] [ >uint-array underlying>> ] bi alSourceQueueBuffers ;
 
 : queue-buffer ( source buffer -- )
     1array queue-buffers ;
index d52e55417ff558f3f743f851032e77cb9908a402..93ca6b32cc8dca9bbad3815449eef4875c786dda 100755 (executable)
@@ -91,10 +91,9 @@ PREDICATE: fragment-shader < gl-shader (fragment-shader?) ;
 
 : gl-program-shaders ( program -- shaders )
     dup gl-program-shaders-length
-    dup "GLuint" <c-array>
+    dup <uint-array>
     0 <int> swap
-    [ glGetAttachedShaders ] { 3 1 } multikeep
-    c-uint-array> ;
+    [ underlying>> glGetAttachedShaders ] { 3 1 } multikeep ;
 
 : delete-gl-program-only ( program -- )
     glDeleteProgram ; inline
index faff19d8fd524dc22aa4cf9c2ff5ac3576fa566e..b0128ca52a799ce03af4c2241fd4df7722733204 100644 (file)
@@ -38,10 +38,10 @@ M: 8bit-stereo-buffer buffer-format drop AL_FORMAT_STEREO8 ;
 M: 16bit-stereo-buffer buffer-format drop AL_FORMAT_STEREO16 ;
 
 : 8bit-buffer-data ( seq -- data size )
-    [ 128 * >integer 128 + ] map [ >c-uchar-array ] [ length ] bi ;
+    [ 128 * >integer 128 + ] uchar-array{ } map-as [ underlying>> ] [ length ] bi ;
 
 : 16bit-buffer-data ( seq -- data size )
-    [ 32768 * >integer ] map [ >c-short-array ] [ length 2 * ] bi ;
+    [ 32768 * >integer ] short-array{ } map-as [ underlying>> ] [ byte-length ] bi ;
 
 : stereo-data ( stereo-buffer -- left right )
     [ left-data>> ] [ right-data>> ] bi@ ;