]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorU-WSCHLIEP-PC\wschliep <wschliep@wschliep-pc.(none)>
Wed, 9 Jul 2008 00:12:54 +0000 (20:12 -0400)
committerU-WSCHLIEP-PC\wschliep <wschliep@wschliep-pc.(none)>
Wed, 9 Jul 2008 00:12:54 +0000 (20:12 -0400)
193 files changed:
Makefile
core/alien/alien-tests.factor
core/alien/c-types/c-types.factor
core/bootstrap/image/image.factor
core/bootstrap/primitives.factor
core/classes/algebra/algebra-tests.factor
core/classes/algebra/algebra.factor
core/classes/builtin/builtin.factor
core/classes/classes-docs.factor
core/classes/classes.factor
core/classes/intersection/intersection.factor
core/classes/predicate/predicate.factor
core/classes/tuple/tuple-docs.factor
core/classes/tuple/tuple-tests.factor
core/classes/tuple/tuple.factor
core/classes/union/union.factor
core/compiler/tests/reload.factor
core/cpu/x86/32/bootstrap.factor
core/cpu/x86/64/64.factor
core/cpu/x86/64/bootstrap.factor
core/cpu/x86/bootstrap.factor
core/debugger/debugger.factor
core/generator/generator.factor
core/generator/registers/registers.factor
core/generic/generic-tests.factor
core/generic/standard/engines/engines.factor
core/generic/standard/engines/predicate/predicate.factor
core/generic/standard/engines/tag/tag.factor
core/generic/standard/engines/tuple/tuple.factor
core/generic/standard/standard-tests.factor
core/generic/standard/standard.factor
core/io/streams/c/c.factor
core/kernel/kernel.factor
core/math/intervals/intervals.factor
core/optimizer/inlining/inlining.factor
core/optimizer/math/math.factor
core/optimizer/specializers/specializers.factor
core/sequences/sequences-docs.factor
core/sequences/sequences.factor
core/slots/slots-docs.factor
core/threads/threads.factor
extra/alarms/alarms-docs.factor
extra/alarms/alarms.factor
extra/arrays/lib/authors.txt [deleted file]
extra/arrays/lib/lib.factor [deleted file]
extra/arrays/lib/summary.txt [deleted file]
extra/arrays/lib/tags.txt [deleted file]
extra/bake/bake.factor [changed mode: 0644->0755]
extra/bake/fry/fry-tests.factor
extra/benchmark/dispatch1/dispatch1.factor
extra/benchmark/dispatch5/dispatch5.factor
extra/bit-arrays/bit-arrays-tests.factor
extra/bit-arrays/bit-arrays.factor
extra/bitfields/bitfields.factor [changed mode: 0644->0755]
extra/calendar/calendar.factor
extra/calendar/format/format.factor
extra/color-picker/color-picker.factor
extra/columns/columns-docs.factor
extra/combinators/cleave/cleave-tests.factor [new file with mode: 0644]
extra/combinators/cleave/cleave.factor [changed mode: 0644->0755]
extra/combinators/lib/lib-docs.factor
extra/combinators/lib/lib-tests.factor
extra/combinators/lib/lib.factor
extra/combinators/short-circuit/short-circuit.factor [changed mode: 0644->0755]
extra/ctags/authors.txt [new file with mode: 0644]
extra/ctags/ctags-docs.factor [new file with mode: 0644]
extra/ctags/ctags-tests.factor [new file with mode: 0644]
extra/ctags/ctags.factor [new file with mode: 0644]
extra/ctags/summary.txt [new file with mode: 0644]
extra/db/pools/pools-tests.factor
extra/db/tuples/tuples-tests.factor
extra/delegate/delegate.factor
extra/descriptive/descriptive.factor
extra/furnace/auth/login/login.factor
extra/furnace/cache/cache.factor
extra/furnace/sessions/sessions.factor
extra/generalizations/generalizations-docs.factor [new file with mode: 0755]
extra/generalizations/generalizations-tests.factor [new file with mode: 0755]
extra/generalizations/generalizations.factor [new file with mode: 0755]
extra/html/parser/analyzer/analyzer.factor
extra/inverse/inverse.factor
extra/io/pools/pools.factor
extra/io/unix/backend/backend.factor
extra/io/windows/files/files.factor
extra/io/windows/nt/backend/backend.factor
extra/io/windows/privileges/privileges.factor
extra/koszul/koszul.factor
extra/lcd/lcd.factor
extra/logging/logging.factor
extra/math/blas/cblas/authors.txt [new file with mode: 0644]
extra/math/blas/cblas/cblas.factor [new file with mode: 0644]
extra/math/blas/cblas/summary.txt [new file with mode: 0644]
extra/math/blas/cblas/tags.txt [new file with mode: 0644]
extra/math/blas/matrices/authors.txt [new file with mode: 0644]
extra/math/blas/matrices/matrices-docs.factor [new file with mode: 0644]
extra/math/blas/matrices/matrices-tests.factor [new file with mode: 0644]
extra/math/blas/matrices/matrices.factor [new file with mode: 0755]
extra/math/blas/matrices/summary.txt [new file with mode: 0644]
extra/math/blas/matrices/tags.txt [new file with mode: 0644]
extra/math/blas/syntax/authors.txt [new file with mode: 0644]
extra/math/blas/syntax/summary.txt [new file with mode: 0644]
extra/math/blas/syntax/syntax-docs.factor [new file with mode: 0644]
extra/math/blas/syntax/syntax.factor [new file with mode: 0644]
extra/math/blas/syntax/tags.txt [new file with mode: 0644]
extra/math/blas/vectors/authors.txt [new file with mode: 0644]
extra/math/blas/vectors/summary.txt [new file with mode: 0644]
extra/math/blas/vectors/tags.txt [new file with mode: 0644]
extra/math/blas/vectors/vectors-docs.factor [new file with mode: 0644]
extra/math/blas/vectors/vectors-tests.factor [new file with mode: 0644]
extra/math/blas/vectors/vectors.factor [new file with mode: 0755]
extra/math/vectors/vectors.factor
extra/models/compose/compose-docs.factor [new file with mode: 0755]
extra/models/compose/compose-tests.factor [new file with mode: 0755]
extra/models/compose/compose.factor [new file with mode: 0755]
extra/models/delay/delay-docs.factor [new file with mode: 0755]
extra/models/delay/delay.factor [new file with mode: 0755]
extra/models/filter/filter-docs.factor [new file with mode: 0755]
extra/models/filter/filter-tests.factor [new file with mode: 0755]
extra/models/filter/filter.factor [new file with mode: 0755]
extra/models/history/history-docs.factor [new file with mode: 0755]
extra/models/history/history-tests.factor [new file with mode: 0755]
extra/models/history/history.factor [new file with mode: 0755]
extra/models/mapping/mapping-tests.factor [new file with mode: 0755]
extra/models/mapping/mapping.factor [new file with mode: 0755]
extra/models/models-docs.factor
extra/models/models-tests.factor
extra/models/models.factor
extra/models/range/range-docs.factor [new file with mode: 0755]
extra/models/range/range-tests.factor [new file with mode: 0755]
extra/models/range/range.factor [new file with mode: 0755]
extra/mortar/mortar.factor [changed mode: 0644->0755]
extra/multi-methods/multi-methods.factor
extra/newfx/newfx.factor
extra/persistent-vectors/persistent-vectors-docs.factor
extra/persistent-vectors/persistent-vectors-tests.factor
extra/persistent-vectors/persistent-vectors.factor
extra/processing/processing.factor [changed mode: 0644->0755]
extra/reports/noise/noise.factor
extra/reports/optimizer/optimizer.factor
extra/sequences/lib/lib.factor
extra/shuffle/shuffle-docs.factor [deleted file]
extra/shuffle/shuffle-tests.factor
extra/shuffle/shuffle.factor
extra/spheres/spheres.factor [changed mode: 0644->0755]
extra/springies/springies.factor [changed mode: 0644->0755]
extra/tetris/tetris.factor
extra/tools/deploy/deploy-tests.factor
extra/tools/deploy/shaker/shaker.factor
extra/tools/memory/memory.factor [changed mode: 0644->0755]
extra/tools/profiler/profiler-tests.factor
extra/tools/walker/walker-tests.factor
extra/tools/walker/walker.factor
extra/ui/gadgets/scrollers/scrollers-tests.factor
extra/ui/gadgets/scrollers/scrollers.factor
extra/ui/gadgets/sliders/sliders-docs.factor
extra/ui/gadgets/sliders/sliders.factor
extra/ui/gadgets/status-bar/status-bar.factor
extra/ui/gestures/gestures.factor
extra/ui/tools/browser/browser.factor
extra/ui/tools/deploy/deploy.factor
extra/ui/tools/interactor/interactor.factor
extra/ui/tools/search/search.factor
extra/ui/tools/walker/walker.factor
extra/ui/windows/windows.factor
extra/unix/process/process.factor
extra/unix/unix.factor
extra/webapps/planet/admin.xml
extra/webapps/planet/edit-blog.xml
extra/webapps/planet/mini-planet.xml [deleted file]
extra/webapps/planet/new-blog.xml
extra/webapps/planet/planet-common.xml
extra/webapps/planet/planet.factor
extra/webapps/planet/planet.xml
extra/webapps/wiki/initial-content/Farkup.txt [new file with mode: 0644]
extra/webapps/wiki/initial-content/Front Page.txt [new file with mode: 0644]
extra/webapps/wiki/wiki-common.xml
extra/webapps/wiki/wiki.factor
extra/websites/concatenative/concatenative.factor
extra/windows/com/com-tests.factor
extra/windows/com/syntax/syntax.factor
extra/windows/com/wrapper/wrapper-docs.factor
extra/windows/com/wrapper/wrapper.factor
extra/windows/user32/user32.factor
extra/xml/errors/errors-tests.factor
extra/xmode/utilities/utilities-tests.factor
misc/factor.el
vm/alien.c
vm/code_gc.c
vm/os-unix.c
vm/os-unix.h
vm/profiler.c
vm/quotations.c
vm/run.h

index 5f7cdca06dcc6304b8508ebdb1d951f0d1646dd6..769aeacb8cff3da989c54d82536a507651585d32 100755 (executable)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ AR = ar
 LD = ld
 
 EXECUTABLE = factor
-VERSION = 0.91
+VERSION = 0.92
 
 IMAGE = factor.image
 BUNDLE = Factor.app
index 9be28858887275dcbfe54e177d8e9fb2ce22bde3..5a880fa5a96d0fec125f4ca9b6e1c94aefb94f77 100755 (executable)
@@ -1,5 +1,5 @@
 IN: alien.tests
-USING: alien alien.accessors alien.syntax byte-arrays arrays
+USING: accessors alien alien.accessors alien.syntax byte-arrays arrays
 kernel kernel.private namespaces tools.test sequences libc math
 system prettyprint layouts ;
 
@@ -65,6 +65,10 @@ cell 8 = [
 
 [ f ] [ 0 B{ 1 2 3 } <displaced-alien> pinned-c-ptr? ] unit-test
 
+[ f ] [ 0 B{ 1 2 3 } <displaced-alien> 1 swap <displaced-alien> pinned-c-ptr? ] unit-test
+
+[ t ] [ 0 B{ 1 2 3 } <displaced-alien> 1 swap <displaced-alien> underlying>> byte-array? ] unit-test
+
 [ "( displaced alien )" ] [ 0 B{ 1 2 3 } <displaced-alien> unparse ] unit-test
 
 [ f ] [ DLL" fadfasdfsada" dll-valid? ] unit-test
index 92f5211b3505876e30ae02ba68ab0b4f1415590c..602b22881fa582f33e108a8747c15de0dd08a42c 100755 (executable)
@@ -198,9 +198,9 @@ M: long-long-type box-return ( type -- )
 : c-bool> ( int -- ? )
     zero? not ;
 
-: >c-array ( seq type word -- )
-    >r >r dup length dup r> <c-array> dup -roll r>
-    [ execute ] 2curry 2each ; inline
+: >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 ;
index 64c9299b89802909432eb7737ab4f0421fb71a05..5812a0f8e7c5a65b231aef3c82ddceb8682bde8e 100755 (executable)
@@ -8,7 +8,7 @@ grouping growable classes classes.builtin classes.tuple
 classes.tuple.private words.private io.binary io.files vocabs
 vocabs.loader source-files definitions debugger
 quotations.private sequences.private combinators
-io.encodings.binary math.order accessors ;
+io.encodings.binary math.order math.private accessors slots.private ;
 IN: bootstrap.image
 
 : my-arch ( -- arch )
@@ -75,7 +75,7 @@ SYMBOL: objects
 
 : data-base 1024 ; inline
 
-: userenv-size 64 ; inline
+: userenv-size 70 ; inline
 
 : header-size 10 ; inline
 
@@ -118,6 +118,29 @@ SYMBOL: jit-dispatch
 SYMBOL: jit-epilog
 SYMBOL: jit-return
 SYMBOL: jit-profiling
+SYMBOL: jit-tag
+SYMBOL: jit-tag-word
+SYMBOL: jit-eq?
+SYMBOL: jit-eq?-word
+SYMBOL: jit-slot
+SYMBOL: jit-slot-word
+SYMBOL: jit-declare-word
+SYMBOL: jit-drop
+SYMBOL: jit-drop-word
+SYMBOL: jit-dup
+SYMBOL: jit-dup-word
+SYMBOL: jit->r
+SYMBOL: jit->r-word
+SYMBOL: jit-r>
+SYMBOL: jit-r>-word
+SYMBOL: jit-swap
+SYMBOL: jit-swap-word
+SYMBOL: jit-over
+SYMBOL: jit-over-word
+SYMBOL: jit-fixnum-fast
+SYMBOL: jit-fixnum-fast-word
+SYMBOL: jit-fixnum>=
+SYMBOL: jit-fixnum>=-word
 
 ! Default definition for undefined words
 SYMBOL: undefined-quot
@@ -140,7 +163,30 @@ SYMBOL: undefined-quot
         { jit-epilog 33 }
         { jit-return 34 }
         { jit-profiling 35 }
-        { undefined-quot 37 }
+        { jit-tag 36 }
+        { jit-tag-word 37 }
+        { jit-eq? 38 }
+        { jit-eq?-word 39 }
+        { jit-slot 40 }
+        { jit-slot-word 41 }
+        { jit-declare-word 42 }
+        { jit-drop 43 }
+        { jit-drop-word 44 }
+        { jit-dup 45 }
+        { jit-dup-word 46 }
+        { jit->r 47 }
+        { jit->r-word 48 }
+        { jit-r> 49 }
+        { jit-r>-word 50 }
+        { jit-swap 51 }
+        { jit-swap-word 52 }
+        { jit-over 53 }
+        { jit-over-word 54 }
+        { jit-fixnum-fast 55 }
+        { jit-fixnum-fast-word 56 }
+        { jit-fixnum>= 57 }
+        { jit-fixnum>=-word 58 }
+        { undefined-quot 60 }
     } at header-size + ;
 
 : emit ( cell -- ) image get push ;
@@ -228,6 +274,12 @@ M: fixnum '
     bootstrap-most-positive-fixnum between?
     [ tag-fixnum ] [ >bignum ' ] if ;
 
+TUPLE: fake-bignum n ;
+
+C: <fake-bignum> fake-bignum
+
+M: fake-bignum ' n>> tag-fixnum ;
+
 ! Floats
 
 M: float '
@@ -408,6 +460,18 @@ M: quotation '
     \ if jit-if-word set
     \ dispatch jit-dispatch-word set
     \ do-primitive jit-primitive-word set
+    \ tag jit-tag-word set
+    \ eq? jit-eq?-word set
+    \ slot jit-slot-word set
+    \ declare jit-declare-word set
+    \ drop jit-drop-word set
+    \ dup jit-dup-word set
+    \ >r jit->r-word set
+    \ r> jit-r>-word set
+    \ swap jit-swap-word set
+    \ over jit-over-word set
+    \ fixnum-fast jit-fixnum-fast-word set
+    \ fixnum>= jit-fixnum>=-word set
     [ undefined ] undefined-quot set
     {
         jit-code-format
@@ -424,6 +488,29 @@ M: quotation '
         jit-epilog
         jit-return
         jit-profiling
+        jit-tag
+        jit-tag-word
+        jit-eq?
+        jit-eq?-word
+        jit-slot
+        jit-slot-word
+        jit-declare-word
+        jit-drop
+        jit-drop-word
+        jit-dup
+        jit-dup-word
+        jit->r
+        jit->r-word
+        jit-r>
+        jit-r>-word
+        jit-swap
+        jit-swap-word
+        jit-over
+        jit-over-word
+        jit-fixnum-fast
+        jit-fixnum-fast-word
+        jit-fixnum>=
+        jit-fixnum>=-word
         undefined-quot
     } [ emit-userenv ] each ;
 
index 6bd2ca7c984f0d88da39c98550934c33ad85ad76..6498dfde604533a2ede5d7f0bcb1698710293089 100755 (executable)
@@ -181,7 +181,7 @@ define-union-class
 ! A predicate class used for declarations
 "array-capacity" "sequences.private" create
 "fixnum" "math" lookup
-0 bootstrap-max-array-capacity [ between? ] 2curry
+0 bootstrap-max-array-capacity <fake-bignum> [ between? ] 2curry
 define-predicate-class
 
 ! Catch-all class for providing a default method.
@@ -512,7 +512,7 @@ tuple
     { "unimplemented" "kernel.private" }
     { "gc-reset" "memory" }
 }
-dup length [ >r first2 r> make-primitive ] 2each
+[ >r first2 r> make-primitive ] each-index
 
 ! Bump build number
 "build" "kernel" create build 1+ 1quotation define
index 05c254f225cb6a93279f8066b0afe53a04a3654b..444cf50e58165c5ddc23d4b7c0ed9f558bc1a411 100755 (executable)
@@ -3,7 +3,8 @@ kernel math namespaces parser prettyprint sequences strings
 tools.test vectors words quotations classes classes.algebra\r
 classes.private classes.union classes.mixin classes.predicate\r
 vectors definitions source-files compiler.units growable\r
-random inference effects kernel.private sbufs math.order ;\r
+random inference effects kernel.private sbufs math.order\r
+classes.tuple ;\r
 IN: classes.algebra.tests\r
 \r
 \ class< must-infer\r
@@ -287,6 +288,8 @@ INTERSECTION: generic-class generic class ;
     generic-class flatten-class\r
 ] unit-test\r
 \r
+[ \ + flatten-class ] must-fail\r
+\r
 INTERSECTION: empty-intersection ;\r
 \r
 [ t ] [ object empty-intersection class<= ] unit-test\r
index b7e4bebe151fe951bed5bc711b58de5f958af944..2d2498a1c3f759d2329ead737e43c85d639cb90f 100755 (executable)
@@ -1,10 +1,22 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
-USING: kernel classes classes.builtin combinators accessors\r
-sequences arrays vectors assocs namespaces words sorting layouts\r
-math hashtables kernel.private sets math.order ;\r
+USING: kernel classes combinators accessors sequences arrays\r
+vectors assocs namespaces words sorting layouts math hashtables\r
+kernel.private sets math.order ;\r
 IN: classes.algebra\r
 \r
+TUPLE: anonymous-union members ;\r
+\r
+C: <anonymous-union> anonymous-union\r
+\r
+TUPLE: anonymous-intersection participants ;\r
+\r
+C: <anonymous-intersection> anonymous-intersection\r
+\r
+TUPLE: anonymous-complement class ;\r
+\r
+C: <anonymous-complement> anonymous-complement\r
+\r
 : 2cache ( key1 key2 assoc quot -- value )\r
     >r >r 2array r> [ first2 ] r> compose cache ; inline\r
 \r
@@ -18,10 +30,19 @@ DEFER: (class-not)
 : class-not ( class -- complement )\r
     class-not-cache get [ (class-not) ] cache ;\r
 \r
-DEFER: (classes-intersect?) ( first second -- ? )\r
+GENERIC: (classes-intersect?) ( first second -- ? )\r
+\r
+: normalize-class ( class -- class' )\r
+    {\r
+        { [ dup members ] [ members <anonymous-union> ] }\r
+        { [ dup participants ] [ participants <anonymous-intersection> ] }\r
+        [ ]\r
+    } cond ;\r
 \r
 : classes-intersect? ( first second -- ? )\r
-    classes-intersect-cache get [ (classes-intersect?) ] 2cache ;\r
+    classes-intersect-cache get [\r
+        normalize-class (classes-intersect?)\r
+    ] 2cache ;\r
 \r
 DEFER: (class-and)\r
 \r
@@ -33,18 +54,6 @@ DEFER: (class-or)
 : class-or ( first second -- class )\r
     class-or-cache get [ (class-or) ] 2cache ;\r
 \r
-TUPLE: anonymous-union members ;\r
-\r
-C: <anonymous-union> anonymous-union\r
-\r
-TUPLE: anonymous-intersection participants ;\r
-\r
-C: <anonymous-intersection> anonymous-intersection\r
-\r
-TUPLE: anonymous-complement class ;\r
-\r
-C: <anonymous-complement> anonymous-complement\r
-\r
 : superclass<= ( first second -- ? )\r
     >r superclass r> class<= ;\r
 \r
@@ -63,13 +72,6 @@ C: <anonymous-complement> anonymous-complement
 : anonymous-complement<= ( first second -- ? )\r
     [ class>> ] bi@ swap class<= ;\r
 \r
-: normalize-class ( class -- class' )\r
-    {\r
-        { [ dup members ] [ members <anonymous-union> ] }\r
-        { [ dup participants ] [ participants <anonymous-intersection> ] }\r
-        [ ]\r
-    } cond ;\r
-\r
 : normalize-complement ( class -- class' )\r
     class>> normalize-class {\r
         { [ dup anonymous-union? ] [\r
@@ -116,40 +118,15 @@ PREDICATE: empty-intersection < anonymous-intersection participants>> empty? ;
         } cond\r
     ] if ;\r
 \r
-: anonymous-union-intersect? ( first second -- ? )\r
+M: anonymous-union (classes-intersect?)\r
     members>> [ classes-intersect? ] with contains? ;\r
 \r
-: anonymous-intersection-intersect? ( first second -- ? )\r
+M: anonymous-intersection (classes-intersect?)\r
     participants>> [ classes-intersect? ] with all? ;\r
 \r
-: anonymous-complement-intersect? ( first second -- ? )\r
+M: anonymous-complement (classes-intersect?)\r
     class>> class<= not ;\r
 \r
-: tuple-class-intersect? ( first second -- ? )\r
-    {\r
-        { [ over tuple eq? ] [ 2drop t ] }\r
-        { [ over builtin-class? ] [ 2drop f ] }\r
-        { [ over tuple-class? ] [ [ class<= ] [ swap class<= ] 2bi or ] }\r
-        [ swap classes-intersect? ]\r
-    } cond ;\r
-\r
-: builtin-class-intersect? ( first second -- ? )\r
-    {\r
-        { [ 2dup eq? ] [ 2drop t ] }\r
-        { [ over builtin-class? ] [ 2drop f ] }\r
-        [ swap classes-intersect? ]\r
-    } cond ;\r
-\r
-: (classes-intersect?) ( first second -- ? )\r
-    normalize-class {\r
-        { [ dup anonymous-union? ] [ anonymous-union-intersect? ] }\r
-        { [ dup anonymous-intersection? ] [ anonymous-intersection-intersect? ] }\r
-        { [ dup anonymous-complement? ] [ anonymous-complement-intersect? ] }\r
-        { [ dup tuple-class? ] [ tuple-class-intersect? ] }\r
-        { [ dup builtin-class? ] [ builtin-class-intersect? ] }\r
-        { [ dup superclass ] [ superclass classes-intersect? ] }\r
-    } cond ;\r
-\r
 : anonymous-union-and ( first second -- class )\r
     members>> [ class-and ] with map <anonymous-union> ;\r
 \r
@@ -225,26 +202,10 @@ PREDICATE: empty-intersection < anonymous-intersection participants>> empty? ;
         tuck [ class<= ] with all? [ peek ] [ drop f ] if\r
     ] if ;\r
 \r
-DEFER: (flatten-class)\r
-DEFER: flatten-builtin-class\r
-\r
-: flatten-intersection-class ( class -- )\r
-    participants [ flatten-builtin-class ] map\r
-    dup empty? [\r
-        drop builtins get [ (flatten-class) ] each\r
-    ] [\r
-        unclip [ assoc-intersect ] reduce [ swap set ] assoc-each\r
-    ] if ;\r
+GENERIC: (flatten-class) ( class -- )\r
 \r
-: (flatten-class) ( class -- )\r
-    {\r
-        { [ dup tuple-class? ] [ dup set ] }\r
-        { [ dup builtin-class? ] [ dup set ] }\r
-        { [ dup members ] [ members [ (flatten-class) ] each ] }\r
-        { [ dup participants ] [ flatten-intersection-class ] }\r
-        { [ dup superclass ] [ superclass (flatten-class) ] }\r
-        [ drop ]\r
-    } cond ;\r
+M: anonymous-union (flatten-class)\r
+    members>> [ (flatten-class) ] each ;\r
 \r
 : flatten-class ( class -- assoc )\r
     [ (flatten-class) ] H{ } make-assoc ;\r
@@ -258,8 +219,11 @@ DEFER: flatten-builtin-class
     flatten-builtin-class keys\r
     [ "type" word-prop ] map natural-sort ;\r
 \r
-: class-tags ( class -- tag/f )\r
+: class-tags ( class -- seq )\r
     class-types [\r
         dup num-tags get >=\r
         [ drop \ hi-tag tag-number ] when\r
     ] map prune ;\r
+\r
+: class-tag ( class -- tag/f )\r
+    class-tags dup length 1 = [ first ] [ drop f ] if ;\r
index acbbc5e841e5caadcca95cae51290aeb51091527..b0e4754682b9f3029fe15034a723bb480d6ab477 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: classes words kernel kernel.private namespaces
-sequences math math.private ;
+USING: accessors classes classes.algebra words kernel
+kernel.private namespaces sequences math math.private
+combinators assocs ;
 IN: classes.builtin
 
 SYMBOL: builtins
@@ -31,3 +32,23 @@ M: builtin-class rank-class drop 0 ;
 
 M: builtin-class instance?
     class>type builtin-instance? ;
+
+M: builtin-class (flatten-class) dup set ;
+
+M: builtin-class (classes-intersect?)
+    {
+        { [ 2dup eq? ] [ 2drop t ] }
+        { [ over builtin-class? ] [ 2drop f ] }
+        [ swap classes-intersect? ]
+    } cond ;
+
+M: anonymous-intersection (flatten-class)
+    participants>> [ flatten-builtin-class ] map
+    dup empty? [
+        drop builtins get sift [ (flatten-class) ] each
+    ] [
+        unclip [ assoc-intersect ] reduce [ swap set ] assoc-each
+    ] if ;
+
+M: anonymous-complement (flatten-class)
+    drop builtins get sift [ (flatten-class) ] each ;
index 5f02212bad48dbcb430521f1fdbbdf507494c17a..fcad00bb18d58bc47f05a9c3f6a79d5b00797d7e 100755 (executable)
@@ -65,10 +65,6 @@ HELP: classes
 { $values { "seq" "a sequence of class words" } }
 { $description "Finds all class words in the dictionary." } ;
 
-HELP: tuple-class
-{ $class-description "The class of tuple class words." }
-{ $examples { $example "USING: classes prettyprint ;" "IN: scratchpad" "TUPLE: name title first last ;" "name tuple-class? ." "t" } } ;
-
 HELP: update-map
 { $var-description "Assoc mapping each class to a set of classes defined in terms of this class. The " { $link define-class } " word uses this information to update generic words when classes are redefined." } ;
 
index 56c3b0a0ab4ebd787cb04408468bc031c60d207b..34f2fcf19657c58e79465981dfe46db83852a670 100755 (executable)
@@ -32,9 +32,6 @@ SYMBOL: implementors-map
 PREDICATE: class < word
     "class" word-prop ;
 
-PREDICATE: tuple-class < class
-    "metaclass" word-prop tuple-class eq? ;
-
 : classes ( -- seq ) implementors-map get keys ;
 
 : predicate-word ( word -- predicate )
index 0eae1b62d36f9073b594067bf2c94cb6dcf3c3d0..bb7e0adc6222653486ed5407125ab17ddc415a2b 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: words sequences kernel assocs combinators classes
-namespaces arrays math quotations ;
+classes.algebra classes.builtin namespaces arrays math quotations ;
 IN: classes.intersection
 
 PREDICATE: intersection-class < class
@@ -31,3 +31,6 @@ M: intersection-class rank-class drop 2 ;
 
 M: intersection-class instance?
     "participants" word-prop [ instance? ] with all? ;
+
+M: intersection-class (flatten-class)
+    participants <anonymous-intersection> (flatten-class) ;
index 3067b7d9dd5fd11bfcafe8198069424e65482c4a..e6d6b5a0d4566f2046a411e12e67e2848456ab7b 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: classes kernel namespaces words sequences quotations
-arrays kernel.private assocs combinators ;
+USING: classes classes.algebra kernel namespaces words sequences
+quotations arrays kernel.private assocs combinators ;
 IN: classes.predicate
 
 PREDICATE: predicate-class < class
@@ -51,3 +51,9 @@ M: predicate-class rank-class drop 1 ;
 M: predicate-class instance?
     2dup superclass instance?
     [ predicate-instance? ] [ 2drop f ] if ;
+
+M: predicate-class (flatten-class)
+    superclass (flatten-class) ;
+
+M: predicate-class (classes-intersect?)
+    superclass classes-intersect? ;
index 8c2525731e6c1a88e9cf5e12bc597d7ac1613719..98e1fd3e5026556a092568f405afeaa8488f08fa 100755 (executable)
@@ -332,6 +332,10 @@ $nl
 
 ABOUT: "tuples"
 
+HELP: tuple-class
+{ $class-description "The class of tuple class words." }
+{ $examples { $example "USING: classes.tuple prettyprint ;" "IN: scratchpad" "TUPLE: name title first last ;" "name tuple-class? ." "t" } } ;
+
 HELP: tuple=
 { $values { "tuple1" tuple } { "tuple2" tuple } { "?" "a boolean" } }
 { $description "Low-level tuple equality test. User code should use " { $link = } " instead." }
index 9deb6b113385e0c91b3057b810830bc5241d78e1..a269fad55646ac30cbb6311c73ddde5780cd58d9 100755 (executable)
@@ -657,6 +657,8 @@ TUPLE: boa-coercer-test { x array-capacity } ;
 
 [ fixnum ] [ 0 >bignum boa-coercer-test boa x>> class ] unit-test
 
+[ T{ boa-coercer-test f 0 } ] [ T{ boa-coercer-test } ] unit-test
+
 ! Test error classes
 ERROR: error-class-test a b c ;
 
index 83d85b68d8a491001b21334dc6e24fb48809caff..8471aa918a172d6d5aa34e17e4ba12e57aea23bc 100755 (executable)
@@ -3,10 +3,13 @@
 USING: arrays definitions hashtables kernel kernel.private math
 namespaces sequences sequences.private strings vectors words
 quotations memory combinators generic classes classes.algebra
-classes.private slots.deprecated slots.private slots
-compiler.units math.private accessors assocs effects ;
+classes.builtin classes.private slots.deprecated slots.private
+slots compiler.units math.private accessors assocs effects ;
 IN: classes.tuple
 
+PREDICATE: tuple-class < class
+    "metaclass" word-prop tuple-class eq? ;
+
 M: tuple class 1 slot 2 slot { word } declare ;
 
 ERROR: not-a-tuple object ;
@@ -14,6 +17,9 @@ ERROR: not-a-tuple object ;
 : check-tuple ( object -- tuple )
     dup tuple? [ not-a-tuple ] unless ; inline
 
+: all-slots ( class -- slots )
+    superclasses [ "slots" word-prop ] map concat ;
+
 <PRIVATE
 
 : (tuple) ( layout -- tuple )
@@ -43,6 +49,20 @@ ERROR: not-a-tuple object ;
 : copy-tuple-slots ( n tuple -- array )
     [ array-nth ] curry map ;
 
+: check-slots ( seq class -- seq class )
+    [ ] [
+        2dup all-slots [
+            class>> 2dup instance?
+            [ 2drop ] [ bad-slot-value ] if
+        ] 2each
+    ] if-bootstrapping ; inline
+
+: initial-values ( class -- slots )
+    all-slots [ initial>> ] map ;
+
+: pad-slots ( slots class -- slots' class )
+    [ initial-values over length tail append ] keep ; inline
+
 PRIVATE>
 
 : tuple>array ( tuple -- array )
@@ -53,21 +73,10 @@ PRIVATE>
 : tuple-slots ( tuple -- seq )
     prepare-tuple>array drop copy-tuple-slots ;
 
-: all-slots ( class -- slots )
-    superclasses [ "slots" word-prop ] map concat ;
-
-: check-slots ( seq class -- seq class )
-    [ ] [
-        2dup all-slots [
-            class>> 2dup instance?
-            [ 2drop ] [ bad-slot-value ] if
-        ] 2each
-    ] if-bootstrapping ; inline
-
 GENERIC: slots>tuple ( seq class -- tuple )
 
 M: tuple-class slots>tuple
-    check-slots
+    check-slots pad-slots
     tuple-layout <tuple> [
         [ tuple-size ]
         [ [ set-array-nth ] curry ]
@@ -135,7 +144,8 @@ ERROR: bad-superclass class ;
     dup boa-check-quot "boa-check" set-word-prop ;
 
 : tuple-prototype ( class -- prototype )
-    [ all-slots [ initial>> ] map ] keep slots>tuple ;
+    [ initial-values ] keep
+    over [ ] all? [ 2drop f ] [ slots>tuple ] if ;
 
 : define-tuple-prototype ( class -- )
     dup tuple-prototype "prototype" set-word-prop ;
@@ -289,6 +299,16 @@ M: tuple-class rank-class drop 0 ;
 M: tuple-class instance?
     dup tuple-layout echelon>> tuple-instance? ;
 
+M: tuple-class (flatten-class) dup set ;
+
+M: tuple-class (classes-intersect?)
+    {
+        { [ over tuple eq? ] [ 2drop t ] }
+        { [ over builtin-class? ] [ 2drop f ] }
+        { [ over tuple-class? ] [ [ class<= ] [ swap class<= ] 2bi or ] }
+        [ swap classes-intersect? ]
+    } cond ;
+
 M: tuple clone
     (clone) dup delegate clone over set-delegate ;
 
@@ -304,7 +324,8 @@ M: tuple hashcode*
     ] recursive-hashcode ;
 
 M: tuple-class new
-    "prototype" word-prop (clone) ;
+    dup "prototype" word-prop
+    [ (clone) ] [ tuple-layout <tuple> ] ?if ;
 
 M: tuple-class boa
     [ "boa-check" word-prop call ]
index 6ae4e1bdc30c8959aa031bbc474e8403c05c743a..fbb1925363b7b4fa8b530fe38db607afe07f5165 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: words sequences kernel assocs combinators classes
-namespaces arrays math quotations ;
+classes.algebra namespaces arrays math quotations ;
 IN: classes.union
 
 PREDICATE: union-class < class
@@ -32,3 +32,6 @@ M: union-class rank-class drop 2 ;
 
 M: union-class instance?
     "members" word-prop [ instance? ] with contains? ;
+
+M: union-class (flatten-class)
+    members <anonymous-union> (flatten-class) ;
index 1e31757fca8dd1c3f2a654a2e07bc5835b06f6f5..b2b65b5868bcaf8350ced989046fe6191c9c4c30 100644 (file)
@@ -1,6 +1,6 @@
 IN: compiler.tests
 USE: vocabs.loader
 
-"parser" reload
-"sequences" reload
-"kernel" reload
+"parser" reload
+"sequences" reload
+"kernel" reload
index 312b952b84a9a35569f1f9e2677a109757453343..386f1366fc0405114f7bbd24aedebb4a8e18796a 100755 (executable)
@@ -11,6 +11,7 @@ IN: bootstrap.x86
 : temp-reg ( -- reg ) EBX ;
 : stack-reg ( -- reg ) ESP ;
 : ds-reg ( -- reg ) ESI ;
+: rs-reg ( -- reg ) EDI ;
 : fixnum>slot@ ( -- ) arg0 1 SAR ;
 : rex-length ( -- n ) 0 ;
 
index 6d99b72439f362fb6452724c952b87616fee433b..bdd452f83d182057bce9e24a189290083bafff8c 100755 (executable)
@@ -178,7 +178,7 @@ stack-params "__stack_value" c-type set-c-type-reg-class >>
 
 : struct-types&offset ( struct-type -- pairs )
     struct-type-fields [
-        [ type>> ] [ offset>> ] bi 2array
+        [ class>> ] [ offset>> ] bi 2array
     ] map ;
 
 : split-struct ( pairs -- seq )
index d167c2882a72387bb9aca5021688be3a853c3a13..0c9ce92edf62a4331a8a77cfd51e9f66e6aa07f2 100755 (executable)
@@ -11,6 +11,7 @@ IN: bootstrap.x86
 : temp-reg ( -- reg ) RBX ;
 : stack-reg ( -- reg ) RSP ;
 : ds-reg ( -- reg ) R14 ;
+: rs-reg ( -- reg ) R15 ;
 : fixnum>slot@ ( -- ) ;
 : rex-length ( -- n ) 1 ;
 
index 011c27112e6a45ab2b26cc79122d3a850a6bdda2..bf176eebfa7e97b68b9c8b6e0b2b217854c24858 100755 (executable)
@@ -74,6 +74,90 @@ big-endian off
     arg0 quot-xt-offset [+] JMP                ! execute branch
 ] rc-absolute-cell rt-literal 1 rex-length + jit-dispatch jit-define
 
+[
+    arg1 ds-reg [] MOV                         ! load from stack
+    arg1 tag-mask get AND                      ! compute tag
+    arg1 tag-bits get SHL                      ! tag the tag
+    ds-reg [] arg1 MOV                         ! push to stack
+] f f f jit-tag jit-define
+
+: jit-compare ( -- )
+    arg1 0 MOV                                 ! load t
+    arg1 dup [] MOV
+    temp-reg \ f tag-number MOV                ! load f
+    arg0 ds-reg [] MOV                         ! load first value
+    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
+    ds-reg [] arg0 CMP                         ! compare with second value
+    ;
+
+[
+    jit-compare
+    arg1 temp-reg CMOVNE                       ! not equal?
+    ds-reg [] arg1 MOV                         ! store
+] rc-absolute-cell rt-literal 1 rex-length + jit-eq? jit-define
+
+[
+    arg0 ds-reg [] MOV                         ! load slot number
+    ds-reg bootstrap-cell SUB                  ! adjust stack pointer
+    arg1 ds-reg [] MOV                         ! load object
+    fixnum>slot@                               ! turn slot number into offset
+    arg1 tag-bits get SHR                      ! mask off tag
+    arg1 tag-bits get SHL
+    arg0 arg1 arg0 [+] MOV                     ! load slot value
+    ds-reg [] arg0 MOV                         ! push to stack
+] f f f jit-slot jit-define
+
+[
+    ds-reg bootstrap-cell SUB
+] f f f jit-drop jit-define
+
+[
+    arg0 ds-reg [] MOV
+    ds-reg bootstrap-cell ADD
+    ds-reg [] arg0 MOV
+] f f f jit-dup jit-define
+
+[
+    rs-reg bootstrap-cell ADD
+    arg0 ds-reg [] MOV
+    ds-reg bootstrap-cell SUB
+    rs-reg [] arg0 MOV
+] f f f jit->r jit-define
+
+[
+    ds-reg bootstrap-cell ADD
+    arg0 rs-reg [] MOV
+    rs-reg bootstrap-cell SUB
+    ds-reg [] arg0 MOV
+] f f f jit-r> jit-define
+
+[
+    arg0 ds-reg [] MOV
+    arg1 ds-reg bootstrap-cell neg [+] MOV
+    ds-reg bootstrap-cell neg [+] arg0 MOV
+    ds-reg [] arg1 MOV
+] f f f jit-swap jit-define
+
+[
+    arg0 ds-reg bootstrap-cell neg [+] MOV
+    ds-reg bootstrap-cell ADD
+    ds-reg [] arg0 MOV
+] f f f jit-over jit-define
+
+[
+    arg0 ds-reg [] MOV
+    ds-reg bootstrap-cell SUB
+    arg1 ds-reg [] MOV
+    arg1 arg0 SUB
+    ds-reg [] arg1 MOV
+] f f f jit-fixnum-fast jit-define
+
+[
+    jit-compare
+    arg1 temp-reg CMOVL                        ! not equal?
+    ds-reg [] arg1 MOV                         ! store
+] rc-absolute-cell rt-literal 1 rex-length + jit-fixnum>= jit-define
+
 [
     stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
 ] f f f jit-epilog jit-define
index f5316b08582c8bfcdc2cdb21a9603f3941bccac4..6759c43094fee377ac4a3ba4ade14d67e2943334 100755 (executable)
@@ -52,7 +52,7 @@ M: string error. print ;
         nl
         "The following restarts are available:" print
         nl
-        dup length [ restart. ] 2each
+        [ restart. ] each-index
     ] if ;
 
 : print-error ( error -- )
index d369c047d999eeca0c1189ca949de4c0af4c3214..e646010c4c6ada09a8772204826e807c6bb0c51e 100755 (executable)
@@ -13,11 +13,12 @@ SYMBOL: compiled
 
 : queue-compile ( word -- )
     {
-        { [ dup compiled get key? ] [ drop ] }
-        { [ dup inlined-block? ] [ drop ] }
-        { [ dup primitive? ] [ drop ] }
-        [ compile-queue get push-front ]
-    } cond ;
+        { [ dup "forgotten" word-prop ] [ ] }
+        { [ dup compiled get key? ] [ ] }
+        { [ dup inlined-block? ] [ ] }
+        { [ dup primitive? ] [ ] }
+        [ dup compile-queue get push-front ]
+    } cond drop ;
 
 : maybe-compile ( word -- )
     dup compiled>> [ drop ] [ queue-compile ] if ;
@@ -31,7 +32,7 @@ SYMBOL: compiling-loops
 ! Label of current word, after prologue, makes recursion faster
 SYMBOL: current-label-start
 
-: compiled-stack-traces? ( -- ? ) 36 getenv ;
+: compiled-stack-traces? ( -- ? ) 59 getenv ;
 
 : begin-compiling ( word label -- )
     H{ } clone compiling-loops set
index 61e2b82f4ff46211c6ead05d2a7da4e025adc7c8..45b6640b3a1998485cd9afa05ba1f5e0505aa08f 100755 (executable)
@@ -562,13 +562,10 @@ M: loc lazy-store
         2drop t
     ] if ;
 
-: class-tag ( class -- tag/f )
-    class-tags dup length 1 = [ first ] [ drop f ] if ;
-
 : class-matches? ( actual expected -- ? )
     {
         { f [ drop t ] }
-        { known-tag [ class-tag >boolean ] }
+        { known-tag [ dup [ class-tag >boolean ] when ] }
         [ class<= ]
     } case ;
 
@@ -639,7 +636,7 @@ PRIVATE>
     [ second template-matches? ] find nip ;
 
 : operand-tag ( operand -- tag/f )
-    operand-class class-tag ;
+    operand-class dup [ class-tag ] when ;
 
 UNION: immediate fixnum POSTPONE: f ;
 
index 88e13ec0f8611d97851f3b1c9000483928c0b365..f3c51506fb84904770ddbac9c910388e17a8a4a8 100755 (executable)
@@ -1,8 +1,8 @@
 USING: accessors alien arrays definitions generic generic.standard
 generic.math assocs hashtables io kernel math namespaces parser
 prettyprint sequences strings tools.test vectors words
-quotations classes classes.algebra continuations layouts
-classes.union sorting compiler.units ;
+quotations classes classes.algebra classes.tuple continuations
+layouts classes.union sorting compiler.units ;
 IN: generic.tests
 
 GENERIC: foobar ( x -- y )
index 20e22fde82dd77bb53ab67eabdccd5ffe7c50074..f60ee6d0d18f0f250f7a03a39e1cb00a3597dc95 100644 (file)
@@ -1,16 +1,16 @@
-USING: assocs kernel namespaces quotations generic math
-sequences combinators words classes.algebra ;
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs kernel kernel.private namespaces quotations
+generic math sequences combinators words classes.algebra arrays
+;
 IN: generic.standard.engines
 
 SYMBOL: default
 SYMBOL: assumed
+SYMBOL: (dispatch#)
 
 GENERIC: engine>quot ( engine -- quot )
 
-M: quotation engine>quot ;
-
-M: method-body engine>quot 1quotation ;
-
 : engines>quots ( assoc -- assoc' )
     [ engine>quot ] assoc-map ;
 
@@ -22,7 +22,11 @@ M: method-body engine>quot 1quotation ;
 
 : linear-dispatch-quot ( alist -- quot )
     default get [ drop ] prepend swap
-    [ >r [ dupd eq? ] curry r> \ drop prefix ] assoc-map
+    [
+        [ [ dup ] swap [ eq? ] curry compose ]
+        [ [ drop ] prepose ]
+        bi* [ ] like
+    ] assoc-map
     alist>quot ;
 
 : split-methods ( assoc class -- first second )
@@ -36,8 +40,6 @@ M: method-body engine>quot 1quotation ;
         r> execute r> pick set-at
     ] if ; inline
 
-SYMBOL: (dispatch#)
-
 : (picker) ( n -- quot )
     {
         { 0 [ [ dup ] ] }
index 9c810592a074d995f0aa58590c9cfd5132cc0fba..8846c9eee776072afa6ca39202fb7b738cb798b2 100644 (file)
@@ -1,6 +1,8 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 USING: generic.standard.engines generic namespaces kernel
-sequences classes.algebra accessors words combinators
-assocs ;
+kernel.private sequences classes.algebra accessors words
+combinators assocs arrays ;
 IN: generic.standard.engines.predicate
 
 TUPLE: predicate-dispatch-engine methods ;
@@ -24,8 +26,13 @@ C: <predicate-dispatch-engine> predicate-dispatch-engine
 : sort-methods ( assoc -- assoc' )
     >alist [ keys sort-classes ] keep extract-keys ;
 
+: methods-with-default ( engine -- assoc )
+    methods>> clone default get object bootstrap-word pick set-at ;
+
 M: predicate-dispatch-engine engine>quot
-    methods>> clone
-    default get object bootstrap-word pick set-at engines>quots
-    sort-methods prune-redundant-predicates
-    class-predicates alist>quot ;
+    methods-with-default
+    engines>quots
+    sort-methods
+    prune-redundant-predicates
+    class-predicates
+    alist>quot ;
index c1e72a65deaf0c080cfa64676ad551594cda20ee..02a7af105f8d621e96e4e813b606e42423259500 100644 (file)
@@ -44,7 +44,7 @@ C: <hi-tag-dispatch-engine> hi-tag-dispatch-engine
     "type" word-prop num-tags get - ;
 
 : hi-tag-quot ( -- quot )
-    [ hi-tag ] num-tags get [ fixnum-fast ] curry compose ;
+    [ 0 slot ] num-tags get [ fixnum-fast ] curry compose ;
 
 M: hi-tag-dispatch-engine engine>quot
     methods>> engines>quots* [ >r hi-tag-number r> ] assoc-map
index cf2d50b6e27f7c9c81dc90b3dd7cc28261c649ee..6f1773a21f34d33036b9e1cadd8be0b2a23a7a2e 100644 (file)
@@ -80,15 +80,17 @@ M: engine-word irrelevant? drop t ;
 
 : array-nth% ( n -- ) 2 + , [ slot { word } declare ] % ;
 
-: tuple-layout-superclasses ( obj -- array )
-    { tuple } declare
-    1 slot { tuple-layout } declare
-    4 slot { array } declare ; inline
+: tuple-layout-superclasses% ( -- )
+    [
+        { tuple } declare
+        1 slot { tuple-layout } declare
+        4 slot { array } declare
+    ] % ; inline
 
 : tuple-dispatch-engine-body ( engine -- quot )
     [
         picker %
-        [ tuple-layout-superclasses ] %
+        tuple-layout-superclasses%
         [ n>> array-nth% ]
         [
             methods>> [
@@ -106,7 +108,7 @@ M: echelon-dispatch-engine engine>quot
     ] [
         [
             picker %
-            [ tuple-layout-superclasses ] %
+            tuple-layout-superclasses%
             [ n>> array-nth% ]
             [
                 methods>> [
@@ -120,18 +122,24 @@ M: echelon-dispatch-engine engine>quot
 
 : >=-case-quot ( alist -- quot )
     default get [ drop ] prepend swap
-    [ >r [ dupd fixnum>= ] curry r> \ drop prefix ] assoc-map
+    [
+        [ [ dup ] swap [ fixnum>= ] curry compose ]
+        [ [ drop ] prepose ]
+        bi* [ ] like
+    ] assoc-map
     alist>quot ;
 
-: tuple-layout-echelon ( obj -- array )
-    { tuple } declare
-    1 slot { tuple-layout } declare
-    5 slot ; inline
+: tuple-layout-echelon% ( -- )
+    [
+        { tuple } declare
+        1 slot { tuple-layout } declare
+        5 slot
+    ] % ; inline
 
 M: tuple-dispatch-engine engine>quot
     [
         picker %
-        [ tuple-layout-echelon ] %
+        tuple-layout-echelon%
         [
             tuple assumed set
             echelons>> dup empty? [
index 9cee497d6d7d2a041b081926573eed55445ade90..54fc3c8ca3fc6230153b0d1056833923c2771d2b 100644 (file)
@@ -309,3 +309,11 @@ M: xref-tuple-2 xref-test (xref-test) ;
     \ xref-test
     \ xref-tuple-2 \ xref-test method [ usage unique ] closure key?
 ] unit-test
+
+[ t ] [
+    { } \ nth effective-method nip \ sequence \ nth method eq?
+] unit-test
+
+[ t ] [
+    \ + \ nth effective-method nip dup \ nth "default-method" word-prop eq? and
+] unit-test
index 89c2a2a396160b1b14486f943e0ada669e75c1d8..2a99588db829ef52b3527e96a006150eab34d007 100644 (file)
@@ -10,7 +10,16 @@ IN: generic.standard
 
 GENERIC: dispatch# ( word -- n )
 
-M: word dispatch# "combination" word-prop dispatch# ;
+M: generic dispatch#
+    "combination" word-prop dispatch# ;
+
+GENERIC: method-declaration ( class generic -- quot )
+
+M: generic method-declaration
+    "combination" word-prop method-declaration ;
+
+M: quotation engine>quot
+    assumed get generic get method-declaration prepend ;
 
 : unpickers
     {
@@ -105,7 +114,9 @@ ERROR: no-next-method class generic ;
     ] [ ] make ;
 
 : single-effective-method ( obj word -- method )
-    [ order [ instance? ] with find-last nip ] keep method ;
+    [ [ order [ instance? ] with find-last nip ] keep method ]
+    [ "default-method" word-prop ]
+    bi or ;
 
 TUPLE: standard-combination # ;
 
@@ -133,6 +144,9 @@ M: standard-combination perform-combination
 
 M: standard-combination dispatch# #>> ;
 
+M: standard-combination method-declaration
+    dispatch# object <array> swap prefix [ declare ] curry [ ] like ;
+
 M: standard-combination next-method-quot*
     [
         single-next-method-quot picker prepend
@@ -155,6 +169,8 @@ PREDICATE: hook-generic < generic
 
 M: hook-combination dispatch# drop 0 ;
 
+M: hook-combination method-declaration 2drop [ ] ;
+
 M: hook-generic extra-values drop 1 ;
 
 M: hook-generic effective-method
index 365d5b7c5d0812b117f4ed3f0cd58bfbb0d49819..de6d8519ca025ba1fc19a2aedef49b56d8b807bf 100755 (executable)
@@ -58,7 +58,7 @@ M: object init-io ;
 
 : stdin-handle 11 getenv ;
 : stdout-handle 12 getenv ;
-: stderr-handle 38 getenv ;
+: stderr-handle 61 getenv ;
 
 M: object (init-stdio)
     stdin-handle <c-reader>
index 023ded5e9ca599eb788fee5b05854cf2d12cc7b6..6b785a61ba5db03e0999d6ce46c513bc20a3a522 100755 (executable)
@@ -64,8 +64,7 @@ DEFER: if
 
 : 2keep ( x y quot -- x y ) 2over 2slip ; inline
 
-: 3keep ( x y z quot -- x y z )
-    >r 3dup r> -roll 3slip ; inline
+: 3keep ( x y z quot -- x y z ) >r 3dup r> -roll 3slip ; inline
 
 ! Cleavers
 : bi ( x p q -- )
index 9540081d5b49221c155463408affe1f66393b959..9b994b4bbfdd0b2452d9204e552a58a99dfcc545 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 ! Based on Slate's src/unfinished/interval.slate by Brian Rice.
 USING: accessors kernel sequences arrays math math.order
-combinators ;
+combinators generic ;
 IN: math.intervals
 
 TUPLE: interval { from read-only } { to read-only } ;
@@ -177,6 +177,11 @@ C: <interval> interval
 : interval/ ( i1 i2 -- i3 )
     [ [ / ] interval-op ] interval-division-op ;
 
+: interval/-safe ( i1 i2 -- i3 )
+    #! Just a hack to make the compiler work if bootstrap.math
+    #! is not loaded.
+    \ integer \ / method [ interval/ ] [ 2drop f ] if ;
+
 : interval/i ( i1 i2 -- i3 )
     [
         [ [ /i ] interval-op ] interval-integer-op
index 295dcaf496377afa622026c46b64a3048cc085ae..618a2c746d0c58e7a257ae3f19a6fe373c221d2b 100755 (executable)
@@ -191,6 +191,10 @@ DEFER: (flat-length)
 : apply-identities ( node -- node/f )
     dup find-identity f splice-quot ;
 
+: splice-word-def ( #call word def -- node )
+    [ drop +inlined+ depends-on ] [ swap 1array ] 2bi
+    splice-quot ;
+
 : optimistic-inline? ( #call -- ? )
     dup node-param "specializer" word-prop dup [
         >r node-input-classes r> specialized-length tail*
@@ -199,22 +203,20 @@ DEFER: (flat-length)
         2drop f
     ] if ;
 
-: splice-word-def ( #call word -- node )
-    dup +inlined+ depends-on
-    dup def>> swap 1array splice-quot ;
+: already-inlined? ( #call -- ? )
+    [ param>> ] [ history>> ] bi memq? ;
 
 : optimistic-inline ( #call -- node )
-    dup node-param over node-history memq? [
-        drop t
-    ] [
-        dup node-param splice-word-def
+    dup already-inlined? [ drop t ] [
+        dup param>> dup def>> splice-word-def
     ] if ;
 
 : should-inline? ( word -- ? )
     flat-length 11 <= ;
 
 : method-body-inline? ( #call -- ? )
-    node-param dup method-body? [ should-inline? ] [ drop f ] if ;
+    param>> dup [ method-body? ] [ "default" word-prop not ] bi and
+    [ should-inline? ] [ drop f ] if ;
 
 M: #call optimize-node*
     {
index b7a3ff28e71d64daf3927062fefc66338cd304cd..27ef4042e2b292cf85d37f1629754b839ac3aa84 100755 (executable)
@@ -158,7 +158,7 @@ optimizer.math.partial generic.standard system accessors ;
     { + { { fixnum integer } } interval+ }
     { - { { fixnum integer } } interval- }
     { * { { fixnum integer } } interval* }
-    { / { { fixnum rational } { integer rational } } interval/ }
+    { / { { fixnum rational } { integer rational } } interval/-safe }
     { /i { { fixnum integer } } interval/i }
     { shift { { fixnum integer } } interval-shift-safe }
 } [
index 90ae7fc6f9b7a54bd9520c59002f883b1799c6d3..18c960b129d2c8ea03d1b62d2e1378997c009b60 100755 (executable)
@@ -18,13 +18,6 @@ IN: optimizer.specializers
         unclip [ swap [ f ] \ if 3array append [ ] like ] reduce\r
     ] if ;\r
 \r
-: tag-specializer ( quot -- newquot )\r
-    [\r
-        [ dup tag ] %\r
-        num-tags get swap <array> ,\r
-        \ dispatch ,\r
-    ] [ ] make ;\r
-\r
 : specializer-cases ( quot word -- default alist )\r
     dup [ array? ] all? [ 1array ] unless [\r
         [ make-specializer ] keep\r
@@ -39,11 +32,7 @@ IN: optimizer.specializers
     method-declaration [ declare ] curry prepend ;\r
 \r
 : specialize-quot ( quot specializer -- quot' )\r
-    dup { number } = [\r
-        drop tag-specializer\r
-    ] [\r
-        specializer-cases alist>quot\r
-    ] if ;\r
+    specializer-cases alist>quot ;\r
 \r
 : standard-method? ( method -- ? )\r
     dup method-body? [\r
index dc8d7b9789a9ab84b6cd8733611361092b9e5a94..86fd9be3d76b274ac0b374cc6668b7391bc833f4 100755 (executable)
@@ -43,8 +43,8 @@ ARTICLE: "sequences-integers" "Integer sequences and counted loops"
 $nl
 "For example, the " { $link each } " combinator, given an integer, simply calls a quotation that number of times, pushing a counter on each iteration that ranges from 0 up to that integer:"
 { $example "3 [ . ] each" "0\n1\n2" }
-"A common idiom is to iterate over a sequence, while also maintaining a loop counter. This can be done using " { $link 2each } ":"
-{ $example "{ \"a\" \"b\" \"c\" } dup length [\n    \"Index: \" write . \"Element: \" write .\n] 2each" "Index: 0\nElement: \"a\"\nIndex: 1\nElement: \"b\"\nIndex: 2\nElement: \"c\"" }
+"A common idiom is to iterate over a sequence, while also maintaining a loop counter. This can be done using " { $link each-index } ", " { $link map-index } " and " { $link reduce-index } "."
+$nl
 "Combinators that produce new sequences, such as " { $link map } ", will output an array if the input is an integer." ;
 
 ARTICLE: "sequences-access" "Accessing sequence elements"
index 7560c8f73eddb5320a50bcf8a47d2d2a2f1b3333..1c6b96d0d5eadc410d0fd32de1e1f3d98cb58afd 100755 (executable)
@@ -426,6 +426,18 @@ PRIVATE>
 : follow ( obj quot -- seq )
     >r [ dup ] r> [ keep ] curry [ ] unfold nip ; inline
 
+: prepare-index ( seq quot -- seq n quot )
+    >r dup length r> ; inline
+
+: each-index ( seq quot -- )
+    prepare-index 2each ; inline
+
+: map-index ( seq quot -- )
+    prepare-index 2map ; inline
+
+: reduce-index ( seq identity quot -- )
+    swapd each-index ; inline
+
 : index ( obj seq -- n )
     [ = ] with find drop ;
 
index b11d656b03e175c2e93e6423306931fbb516541a..39a501c7f804fd8e8defe58d47decf322a807eb2 100755 (executable)
@@ -2,7 +2,7 @@ USING: help.markup help.syntax generic kernel.private parser
 words kernel quotations namespaces sequences words arrays
 effects generic.standard classes.builtin
 slots.private classes strings math assocs byte-arrays alien
-math ;
+math classes.tuple ;
 IN: slots
 
 ARTICLE: "accessors" "Slot accessors"
index 4fe4c5bcb2b54c7fa6a96b56baa4c1020d5c7a2c..552d64cfe77302977e086a0997f34d9af82fc602 100755 (executable)
@@ -15,7 +15,7 @@ id
 continuation state runnable
 mailbox variables sleep-entry ;
 
-: self ( -- thread ) 40 getenv ; inline
+: self ( -- thread ) 63 getenv ; inline
 
 ! Thread-local storage
 : tnamespace ( -- assoc )
@@ -30,7 +30,7 @@ mailbox variables sleep-entry ;
 : tchange ( key quot -- )
     tnamespace swap change-at ; inline
 
-: threads 41 getenv ;
+: threads 64 getenv ;
 
 : thread ( id -- thread ) threads at ;
 
@@ -53,7 +53,7 @@ mailbox variables sleep-entry ;
 : unregister-thread ( thread -- )
     check-registered id>> threads delete-at ;
 
-: set-self ( thread -- ) 40 setenv ; inline
+: set-self ( thread -- ) 63 setenv ; inline
 
 PRIVATE>
 
@@ -68,9 +68,9 @@ PRIVATE>
 : <thread> ( quot name -- thread )
     \ thread new-thread ;
 
-: run-queue 42 getenv ;
+: run-queue 65 getenv ;
 
-: sleep-queue 43 getenv ;
+: sleep-queue 66 getenv ;
 
 : resume ( thread -- )
     f >>state
@@ -207,9 +207,9 @@ GENERIC: error-in-thread ( error thread -- )
 <PRIVATE
 
 : init-threads ( -- )
-    H{ } clone 41 setenv
-    <dlist> 42 setenv
-    <min-heap> 43 setenv
+    H{ } clone 64 setenv
+    <dlist> 65 setenv
+    <min-heap> 66 setenv
     initial-thread global
     [ drop f "Initial" <thread> ] cache
     <box> >>continuation
index b25df236c98f6968f4cdba56411c853a796d5dc9..f07a8b9a2d925399591f4286d2a02edf70ce4c33 100755 (executable)
@@ -10,7 +10,7 @@ HELP: add-alarm
 \r
 HELP: later\r
 { $values { "quot" quotation } { "dt" duration } { "alarm" alarm } }\r
-{ $description "Creates and registers an alarm which calls the quotation once at " { $snippet "time" } { $link from-now } "." } ;\r
+{ $description "Creates and registers an alarm which calls the quotation once at " { $snippet "time" } " from now." } ;\r
 \r
 HELP: cancel-alarm\r
 { $values { "alarm" alarm } }\r
index ddc1d34121f72ab83b0eca24a676949069df0cde..a72960f20fcd56dd83c40efc55539e57f413701a 100755 (executable)
@@ -82,10 +82,10 @@ PRIVATE>
     <alarm> [ register-alarm ] keep ;
 
 : later ( quot dt -- alarm )
-    from-now f add-alarm ;
+    hence f add-alarm ;
 
 : every ( quot dt -- alarm )
-    [ from-now ] keep add-alarm ;
+    [ hence ] keep add-alarm ;
 
 : cancel-alarm ( alarm -- )
     alarm-entry [ alarms get-global heap-delete ] if-box? ;
diff --git a/extra/arrays/lib/authors.txt b/extra/arrays/lib/authors.txt
deleted file mode 100755 (executable)
index 6cfd5da..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Eduardo Cavazos
diff --git a/extra/arrays/lib/lib.factor b/extra/arrays/lib/lib.factor
deleted file mode 100644 (file)
index 6530e65..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-
-USING: kernel arrays sequences sequences.private macros ;
-
-IN: arrays.lib
-
-MACRO: narray ( n -- quot )
-    dup [ f <array> ] curry
-    swap <reversed> [
-        [ swap [ set-nth-unsafe ] keep ] curry
-    ] map concat append ;
diff --git a/extra/arrays/lib/summary.txt b/extra/arrays/lib/summary.txt
deleted file mode 100644 (file)
index 5ecd994..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Non-core array words
diff --git a/extra/arrays/lib/tags.txt b/extra/arrays/lib/tags.txt
deleted file mode 100644 (file)
index 42d711b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-collections
old mode 100644 (file)
new mode 100755 (executable)
index 4ce7bfb..db77d92
@@ -1,7 +1,7 @@
 
 USING: kernel parser namespaces sequences quotations arrays vectors splitting
        words math
-       macros arrays.lib combinators.lib combinators.conditional newfx ;
+       macros generalizations combinators.lib combinators.conditional newfx ;
 
 IN: bake
 
index 289e1b12fe453aa8e66d77d27ba3c3d106f62290..13202a78f51ad44276c5ce2188a1247e14a89c09 100755 (executable)
@@ -1,6 +1,6 @@
 
 USING: tools.test math prettyprint kernel io arrays vectors sequences
-       arrays.lib bake bake.fry ;
+       generalizations bake bake.fry ;
 
 IN: bake.fry.tests
 
index 1c8701f73f5c3964d52884498b41d519889cd4a9..430162892dd69e8f346494f7c32ceaabac839b36 100644 (file)
@@ -1,4 +1,4 @@
-USING: classes kernel sequences vocabs math ;
+USING: classes classes.tuple kernel sequences vocabs math ;
 IN: benchmark.dispatch1
 
 GENERIC: g ( obj -- obj )
index 727d28876591859f2475c2620a93eb1f07af0442..8b6bd76f3aad95d94055a7b61c36ce5e19050ccb 100755 (executable)
@@ -1,4 +1,4 @@
-USING: classes kernel sequences vocabs math ;\r
+USING: classes classes.tuple kernel sequences vocabs math ;\r
 IN: benchmark.dispatch5\r
 \r
 MIXIN: g\r
index fcba94763ff120707b9ec7ac95cad86a7c5dd43e..a5ae23dde69c049e4e59ad2e5387d0f542133424 100755 (executable)
@@ -56,6 +56,7 @@ IN: bit-arrays.tests
 [ -10 ?{ } resize ] must-fail
 
 [ -1 integer>bit-array ] must-fail
+[ ?{ } ] [ 0 integer>bit-array ] unit-test
 [ ?{ f t } ] [ 2 integer>bit-array ] unit-test
 [ ?{ t t t t t t t t t } ] [ 511 integer>bit-array ] unit-test
 [ ?{ 
@@ -68,6 +69,7 @@ IN: bit-arrays.tests
 ] unit-test
 
 [ 14 ] [ ?{ f t t t } bit-array>integer ] unit-test
+[ 0 ] [ ?{ } bit-array>integer ] unit-test
 [ HEX: ffffffffffffffffffffffffffffffff ] [ ?{
     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
     t t t t t t t t   t t t t t t t t   t t t t t t t t  t t t t t t t t
index 4fee1dfba3cccc6498b8ef9da3913b095d02a93d..3d699a2623c20afe11c9d69416cfff182a35817d 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien.c-types accessors math alien.accessors kernel
-kernel.private sequences sequences.private byte-arrays
+kernel.private locals sequences sequences.private byte-arrays
 parser prettyprint.backend ;
 IN: bit-arrays
 
@@ -72,13 +72,17 @@ M: bit-array byte-length length 7 + -3 shift ;
 : ?{ ( parsed -- parsed )
     \ } [ >bit-array ] parse-literal ; parsing
 
-: integer>bit-array ( int -- bit-array ) 
-    [ log2 1+ <bit-array> 0 ] keep
-    [ dup zero? not ] [
-        [ -8 shift ] [ 255 bitand ] bi
-        -roll [ [ >r underlying>> r> set-alien-unsigned-1 ] 2keep 1+ ] dip
-    ] [ ] while
-    2drop ;
+:: integer>bit-array ( n -- bit-array ) 
+    n zero? [ 0 <bit-array> ] [
+        [let | out [ n log2 1+ <bit-array> ] i! [ 0 ] n'! [ n ] |
+            [ n' zero? not ] [
+                n' out underlying>> i 255 bitand set-alien-unsigned-1
+                n' -8 shift n'!
+                i 1+ i!
+            ] [ ] while
+            out
+        ]
+    ] if ;
 
 : bit-array>integer ( bit-array -- int )
     0 swap underlying>> [ length ] keep [
old mode 100644 (file)
new mode 100755 (executable)
index 410fd4b..76e8d78
@@ -1,6 +1,6 @@
 USING: parser lexer kernel math sequences namespaces assocs summary
 words splitting math.parser arrays sequences.next mirrors
-shuffle compiler.units ;
+generalizations compiler.units ;
 IN: bitfields
 
 ! Example:
index 6b1f02187d768759eaf55e001da313b2a33b5e2d..0abc00b4a44561ae3dffedeb5cca2ae3e8dcf619 100755 (executable)
@@ -284,7 +284,7 @@ MEMO: unix-1970 ( -- timestamp )
 
 : now ( -- timestamp ) gmt >local-time ;
 
-: from-now ( dt -- timestamp ) now swap time+ ;
+: hence ( dt -- timestamp ) now swap time+ ;
 : ago ( dt -- timestamp ) now swap time- ;
 
 : day-counts { 0 31 28 31 30 31 30 31 31 30 31 30 31 } ; inline
@@ -303,41 +303,25 @@ GENERIC: days-in-year ( obj -- n )
 M: integer days-in-year ( year -- n ) leap-year? 366 365 ? ;
 M: timestamp days-in-year ( timestamp -- n ) year>> days-in-year ;
 
-GENERIC: days-in-month ( obj -- n )
+: (days-in-month) ( year month -- n )
+    dup 2 = [ drop leap-year? 29 28 ? ] [ nip day-counts nth ] if ;
 
-M: array days-in-month ( obj -- n )
-    first2 dup 2 = [
-        drop leap-year? 29 28 ?
-    ] [
-        nip day-counts nth
-    ] if ;
-
-M: timestamp days-in-month ( timestamp -- n )
-    >date< drop 2array days-in-month ;
-
-GENERIC: day-of-week ( obj -- n )
+: days-in-month ( timestamp -- n )
+    >date< drop (days-in-month) ;
 
-M: timestamp day-of-week ( timestamp -- n )
+: day-of-week ( timestamp -- n )
     >date< zeller-congruence ;
 
-M: array day-of-week ( array -- n )
-    first3 zeller-congruence ;
-
-GENERIC: day-of-year ( obj -- n )
-
-M: array day-of-year ( array -- n )
-    first3
-    3dup day-counts rot head-slice sum +
-    swap leap-year? [
-        -roll
-        pick 3 1 <date> >r <date> r>
+:: (day-of-year) ( year month day -- n )
+    day-counts month head-slice sum day +
+    year leap-year? [
+        year month day <date>
+        year 3 1 <date>
         after=? [ 1+ ] when
-    ] [
-        >r 3drop r>
-    ] if ;
+    ] when ;
 
-M: timestamp day-of-year ( timestamp -- n )
-    >date< 3array day-of-year ;
+: day-of-year ( timestamp -- n )
+    >date< (day-of-year) ;
 
 : day-offset ( timestamp m -- timestamp n )
     over day-of-week - ; inline
@@ -373,7 +357,7 @@ M: timestamp day-of-year ( timestamp -- n )
 
 M: timestamp sleep-until timestamp>millis sleep-until ;
 
-M: duration sleep from-now sleep-until ;
+M: duration sleep hence sleep-until ;
 
 {
     { [ os unix? ] [ "calendar.unix" ] }
index 15dee790066fa795173fcc9ed0462c5bafc22ce9..e2b6a280effd8a56b8aee9075da91e19cb92b8b8 100755 (executable)
@@ -57,9 +57,9 @@ GENERIC: month. ( obj -- )
 \r
 M: array month. ( pair -- )\r
     first2\r
-    [ month-names nth write bl number>string print ] 2keep\r
-    [ 1 zeller-congruence ] 2keep\r
-    2array days-in-month day-abbreviations2 " " join print\r
+    [ month-names nth write bl number>string print ]\r
+    [ 1 zeller-congruence ]\r
+    [ (days-in-month) day-abbreviations2 " " join print ] 2tri\r
     over "   " <repetition> concat write\r
     [\r
         [ 1+ day. ] keep\r
index c64d1e48721ab5027ae6474a7c2314b823fa6f77..b494dbc188940acec111c2fefcb60e28ee8fec68 100755 (executable)
@@ -1,9 +1,9 @@
-! Copyright (C) 2006, 2007 Slava Pestov.
+! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.functions math.parser models sequences
-ui ui.gadgets ui.gadgets.frames
-ui.gadgets.labels ui.gadgets.packs ui.gadgets.sliders ui.render
-;
+USING: kernel math math.functions math.parser models
+models.filter models.range models.compose sequences ui
+ui.gadgets ui.gadgets.frames ui.gadgets.labels ui.gadgets.packs
+ui.gadgets.sliders ui.render ;
 IN: color-picker
 
 ! Simple example demonstrating the use of models.
index a2f0cccf3bd704529178f8aa3319a50460daac27..a5b26e3fd017186e34be40dad175a6b14633b1cd 100644 (file)
@@ -11,7 +11,7 @@ HELP: column
 
 HELP: <column> ( seq n -- column )
 { $values { "seq" sequence } { "n" "a non-negative integer" } { "column" column } }
-{ $description "Outputs a new virtual sequence which presents a fixed column of a matrix represented as a sequence of rows." "The " { $snippet "i" } "th element of a column is the " { $snippet "n" } "th element of the " { $snippet "i" } "th element of" { $snippet "seq" } ". Every element of " { $snippet "seq" } " must be a sequence, and all sequences must have equal length." }
+{ $description "Outputs a new virtual sequence which presents a fixed column of a matrix represented as a sequence of rows." "The " { $snippet "i" } "th element of a column is the " { $snippet "n" } "th element of the " { $snippet "i" } "th element of " { $snippet "seq" } ". Every element of " { $snippet "seq" } " must be a sequence, and all sequences must have equal length." }
 { $examples
     { $example
         "USING: arrays prettyprint columns ;"
diff --git a/extra/combinators/cleave/cleave-tests.factor b/extra/combinators/cleave/cleave-tests.factor
new file mode 100644 (file)
index 0000000..94d8c3e
--- /dev/null
@@ -0,0 +1,19 @@
+
+USING: kernel math math.functions tools.test combinators.cleave ;
+
+IN: combinators.cleave.tests
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: unit-test* ( input output -- ) swap unit-test ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+[ { [ 1 ] [ 2 ] [ 3 ] [ 4 ] } 0arr ]       [ { 1 2 3 4 } ] unit-test*
+
+[ 3 { 1+ 1- 2^ } 1arr ]                    [ { 4 2 8 } ]   unit-test*
+
+[ 3 4 { [ + ] [ - ] [ ^ ] } 2arr ]         [ { 7 -1 81 } ] unit-test*
+
+[ 1 2 3 { [ + + ] [ - - ] [ * * ] } 3arr ] [ { 6 2 6 } ]   unit-test*
+
old mode 100644 (file)
new mode 100755 (executable)
index 8018ada..f5aeeff
@@ -1,17 +1,36 @@
 
-USING: kernel arrays sequences macros combinators ;
+USING: kernel combinators words quotations arrays sequences locals macros
+       shuffle combinators.lib generalizations fry ;
 
 IN: combinators.cleave
 
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: >quot ( obj -- quot ) dup word? [ 1quotation ] when ;
+
+: >quots ( seq -- seq ) [ >quot ] map ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+:: [ncleave] ( SEQ N -- quot )
+   SEQ >quots [ [ N nkeep ] curry ] map concat [ N ndrop ] append >quotation ;
+
+MACRO: ncleave ( seq n -- quot ) [ncleave] ;
+
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 ! Cleave into array
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-USING: words quotations fry arrays.lib ;
+: [narr] ( seq n -- quot ) over length '[ , , ncleave , narray ] ;
 
-: >quot ( obj -- quot ) dup word? [ 1quotation ] when ;
+MACRO: narr ( seq n -- array ) [narr] ;
 
-: >quots ( seq -- seq ) [ >quot ] map ;
+MACRO: 0arr ( seq -- array ) 0 [narr] ;
+MACRO: 1arr ( seq -- array ) 1 [narr] ;
+MACRO: 2arr ( seq -- array ) 2 [narr] ;
+MACRO: 3arr ( seq -- array ) 3 [narr] ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 MACRO: <arr> ( seq -- )
   [ >quots ] [ length ] bi
index ccb1fca9a1f34636bd6a53a0803b768d30e05497..fe2f3556ef905e30eaa132d80c579ff6889b844a 100755 (executable)
@@ -11,46 +11,3 @@ HELP: generate
     "[ 20 random-prime ] [ 4 mod 3 = ] generate ."
     "526367"
 } ;
-
-HELP: ndip
-{ $values { "quot" quotation } { "n" number } }
-{ $description "A generalisation of " { $link dip } " that can work " 
-"for any stack depth. The quotation will be called with a stack that "
-"has 'n' items removed first. The 'n' items are then put back on the "
-"stack. The quotation can consume and produce any number of items."
-} 
-{ $examples
-  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 [ dup ] 1 ndip .s" "1\n1\n2" }
-  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip .s" "2\n3" }
-}
-{ $see-also dip 2dip } ;
-
-HELP: nslip
-{ $values { "n" number } }
-{ $description "A generalisation of " { $link slip } " that can work " 
-"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "
-"removed from the stack, the quotation called, and the items restored."
-} 
-{ $examples
-  { $example "USING: combinators.lib prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip .s" "99\n1\n2\n3\n4\n5" }
-}
-{ $see-also slip nkeep } ;
-
-HELP: nkeep
-{ $values { "quot" quotation } { "n" number } }
-{ $description "A generalisation of " { $link keep } " that can work " 
-"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "
-"saved, the quotation called, and the items restored."
-} 
-{ $examples
-  { $example "USING: combinators.lib kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s" "99\n1\n2\n3\n4\n5" }
-}
-{ $see-also keep nslip } ;
-
-! HELP: &&
-! { $values { "quots" "a sequence of quotations with stack effect " { $snippet "( ... -- ... ? )" } } { "?" "a boolean" } }
-! { $description "Calls each quotation in turn; outputs " { $link f } " if one of the quotations output " { $link f } ", otherwise outputs " { $link t } ". As soon as a quotation outputs " { $link f } ", evaluation stops and subsequent quotations are not called." } ;
-
-! HELP: ||
-! { $values { "quots" "a sequence of quotations with stack effect " { $snippet "( ... -- ... ? )" } } { "?" "a boolean" } }
-! { $description "Calls each quotation in turn; outputs " { $link t } " if one of the quotations output " { $link t } ", otherwise outputs " { $link f } ". As soon as a quotation outputs " { $link t } ", evaluation stops and subsequent quotations are not called." } ;
index e511e88fccd8b4104fe4c1d6367e3e669e7b7840..d61674280ab586d8a56b278f675aecae7ed613ed 100755 (executable)
@@ -5,16 +5,6 @@ IN: combinators.lib.tests
 [ 5 ] [ [ 10 random ] [ 5 = ] generate ] unit-test
 [ t ] [ [ 10 random ] [ even? ] generate even? ] unit-test
 
-[ [ 99 ] 1 2 3 4 5 5 nslip ] must-infer
-{ 99 1 2 3 4 5 } [ [ 99 ] 1 2 3 4 5 5 nslip ] unit-test
-[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer
-{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test
-[ [ 1 2 3 + ] ] [ 1 2 3 [ + ] 3 ncurry ] unit-test
-[ { 1 2 } { 2 4 } { 3 8 } { 4 16 } { 5 32 } ] [ 1 2 3 4 5 [ dup 2^ 2array ] 5 napply ] unit-test
-[ [ dup 2^ 2array ] 5 napply ] must-infer
-
-[ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test
-
 [ { "foo" "xbarx" } ]
 [
     { "oof" "bar" } { [ reverse ] [ "x" swap "x" 3append ] } parallel-call
index 3fab4f62ae6ecad4143f5bf63fc89182eea5a78b..4af12a9ad6c6f5e915c0f397e8c5ada0aff1572e 100755 (executable)
@@ -4,7 +4,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel combinators fry namespaces quotations hashtables
 sequences assocs arrays inference effects math math.ranges
-arrays.lib shuffle macros continuations locals ;
+generalizations macros continuations locals ;
 
 IN: combinators.lib
 
@@ -12,30 +12,10 @@ IN: combinators.lib
 ! Generalized versions of core combinators
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-MACRO: ndip ( quot n -- ) dup saver -rot restorer 3append ;
-
-MACRO: nslip ( n -- ) dup saver [ call ] rot restorer 3append ;
-
 : 4slip ( quot a b c d -- a b c d ) 4 nslip ; inline
 
-MACRO: nkeep ( n -- )
-  [ ] [ 1+ ] [ ] tri
-  '[ [ , ndup ] dip , -nrot , nslip ] ;
-
 : 4keep ( w x y z quot -- w x y z ) 4 nkeep ; inline 
 
-MACRO: ncurry ( n -- ) [ curry ] n*quot ;
-
-MACRO:: nwith ( quot n -- )
-  [let | n' [ n 1+ ] |
-    [ n' -nrot [ n' nrot quot call ] n ncurry ] ] ;
-
-MACRO: napply ( n -- )
-  2 [a,b]
-  [ [ 1- ] [ ] bi
-    '[ , ntuck , nslip ] ]
-  map concat >quotation [ call ] append ;
-
 : 2with ( param1 param2 obj quot -- obj curry )
     with with ; inline
 
old mode 100644 (file)
new mode 100755 (executable)
index 3301633..a484e09
@@ -1,6 +1,6 @@
 
 USING: kernel combinators quotations arrays sequences assocs
-       locals shuffle macros fry ;
+       locals generalizations macros fry ;
 
 IN: combinators.short-circuit
 
@@ -16,6 +16,7 @@ IN: combinators.short-circuit
 MACRO: 0&& ( quots -- quot ) 0 n&&-rewrite ;
 MACRO: 1&& ( quots -- quot ) 1 n&&-rewrite ;
 MACRO: 2&& ( quots -- quot ) 2 n&&-rewrite ;
+MACRO: 3&& ( quots -- quot ) 3 n&&-rewrite ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -29,5 +30,6 @@ MACRO: 2&& ( quots -- quot ) 2 n&&-rewrite ;
 MACRO: 0|| ( quots -- quot ) 0 n||-rewrite ;
 MACRO: 1|| ( quots -- quot ) 1 n||-rewrite ;
 MACRO: 2|| ( quots -- quot ) 2 n||-rewrite ;
+MACRO: 3|| ( quots -- quot ) 3 n||-rewrite ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
diff --git a/extra/ctags/authors.txt b/extra/ctags/authors.txt
new file mode 100644 (file)
index 0000000..158cf94
--- /dev/null
@@ -0,0 +1 @@
+Alfredo Beaumont
diff --git a/extra/ctags/ctags-docs.factor b/extra/ctags/ctags-docs.factor
new file mode 100644 (file)
index 0000000..22d811a
--- /dev/null
@@ -0,0 +1,60 @@
+USING: help.syntax help.markup kernel prettyprint sequences strings ;
+IN: ctags
+
+ARTICLE: "ctags" "Ctags file"
+{ $emphasis "ctags" } " generates a index file of every factor word in ctags format as supported by vi and other editors. More information can be found at " { $url "http://en.wikipedia.org/wiki/Ctags" } "."
+{ $subsection ctags }
+{ $subsection ctags-write }
+{ $subsection ctag-strings }
+{ $subsection ctag } ;
+
+HELP: ctags ( path -- )
+{ $values { "path" "a pathname string" } }
+{ $description "Generates a index file in ctags format and stores in " { $snippet "path" } "." }
+{ $examples
+  { $unchecked-example
+    "USING: ctags ;"
+    "\"tags\" ctags"
+    ""
+  }
+} ;
+
+HELP: ctags-write ( seq path -- )
+{ $values { "alist" "an association list" }
+          { "path" "a pathname string" } }
+{ $description "Stores a " { $snippet "alist" } " in " { $snippet "path" } ". " { $snippet "alist" } " must be an association list with ctags format: key must be a valid word and value a sequence whose first element is a resource name and second element is a line number" }
+{ $examples
+  { $unchecked-example
+    "USING: kernel ctags ;"
+    "{ { if  { \"resource:extra/unix/unix.factor\" 91 } } } \"tags\" ctags-write"
+    ""
+  }
+}
+{ $notes
+  { $snippet "tags" } " file will contain a single line: if\\t/path/to/factor/extra/unix/unix.factor\\t91" } ;
+
+HELP: ctag-strings ( alist -- seq )
+{ $values { "alist" "an association list" }
+          { "seq" sequence } }
+{ $description "Converts an " { $snippet "alist" } " with ctag format (a word as key and a sequence whose first element is a resource name and a second element is a line number as value) in a " { $snippet "seq" } " of ctag strings." }
+{ $examples
+  { $unchecked-example
+    "USING: kernel ctags prettyprint ;"
+    "{ { if  { \"resource:extra/unix/unix.factor\" 91 } } } ctag-strings ."
+    "{ \"if\\t/path/to/factor/extra/unix/unix.factor\\t91\" }"
+  }
+} ;
+
+HELP: ctag ( seq -- str )
+{ $values { "seq" sequence }
+          { "str" string } }
+{ $description "Outputs a string " { $snippet "str" } " in ctag format for sequence with two elements, first one must be a valid word and second one a sequence whose first element is a resource name and second element is a line number" }
+{ $examples
+  { $unchecked-example
+    "USING: kernel ctags prettyprint ;"
+    "{ if  { \"resource:extra/unix/unix.factor\" 91 } } ctag ."
+    "\"if\\t/path/to/factor/extra/unix/unix.factor\\t91\""
+  }
+} ;
+
+ABOUT: "ctags"
\ No newline at end of file
diff --git a/extra/ctags/ctags-tests.factor b/extra/ctags/ctags-tests.factor
new file mode 100644 (file)
index 0000000..6c73b58
--- /dev/null
@@ -0,0 +1,12 @@
+USING: kernel ctags tools.test io.backend sequences arrays prettyprint ;
+IN: ctags.tests
+
+[ t ] [
+  "if\t" "resource:extra/unix/unix.factor" normalize-path "\t91" 3append
+  { if  { "resource:extra/unix/unix.factor" 91 } } ctag =
+] unit-test
+
+[ t ] [
+  "if\t" "resource:extra/unix/unix.factor" normalize-path "\t91" 3append 1array
+  { { if  { "resource:extra/unix/unix.factor" 91 } } } ctag-strings =
+] unit-test
\ No newline at end of file
diff --git a/extra/ctags/ctags.factor b/extra/ctags/ctags.factor
new file mode 100644 (file)
index 0000000..23d9aeb
--- /dev/null
@@ -0,0 +1,37 @@
+! Copyright (C) 2008 Alfredo Beaumont
+! See http://factorcode.org/license.txt for BSD license.
+
+! Simple Ctags generator
+! Alfredo Beaumont <alfredo.beaumont@gmail.com>
+
+USING: arrays kernel sequences io io.files io.backend
+io.encodings.ascii math.parser vocabs definitions
+namespaces words sorting ;
+IN: ctags
+
+: ctag ( seq -- str )
+  [
+    dup first ?word-name %
+    "\t" %
+    second dup first normalize-path %
+    "\t" %
+    second number>string %
+  ] "" make ;
+
+: ctag-strings ( seq1 -- seq2 )
+  { } swap [ ctag suffix ] each ;
+
+: ctags-write ( seq path -- )
+  [ ctag-strings ] dip ascii set-file-lines ;
+
+: (ctags) ( -- seq )
+  { } all-words [
+    dup where [
+      2array suffix
+    ] [
+      drop
+    ] if*
+  ] each ;
+
+: ctags ( path -- )
+  (ctags) sort-keys swap ctags-write ;
\ No newline at end of file
diff --git a/extra/ctags/summary.txt b/extra/ctags/summary.txt
new file mode 100644 (file)
index 0000000..2025e02
--- /dev/null
@@ -0,0 +1 @@
+Ctags generator
index f0534a1d3420e828d166679037a3607eb730f9f7..34e072c3a527448b3f321f1c66d76077d278756b 100644 (file)
@@ -1,8 +1,22 @@
 IN: db.pools.tests
-USING: db.pools tools.test ;
+USING: db.pools tools.test continuations io.files namespaces
+accessors kernel math destructors ;
 
 \ <db-pool> must-infer
 
 { 2 0 } [ [ ] with-db-pool ] must-infer-as
 
 { 1 0 } [ [ ] with-pooled-db ] must-infer-as
+
+! Test behavior after image save/load
+USE: db.sqlite
+
+[ "pool-test.db" temp-file delete-file ] ignore-errors
+
+[ ] [ "pool-test.db" sqlite-db <db-pool> "pool" set ] unit-test
+
+[ ] [ "pool" get expired>> t >>expired drop ] unit-test
+
+[ ] [ 1000 [ "pool" get [ ] with-pooled-db ] times ] unit-test
+
+[ ] [ "pool" get dispose ] unit-test
index 36e84187eb1306fc84e652423437ead024908df4..2edf7552cbaabd4e0f7fd969e64325d5c208c740 100755 (executable)
@@ -4,7 +4,7 @@ USING: io.files kernel tools.test db db.tuples classes
 db.types continuations namespaces math math.ranges
 prettyprint calendar sequences db.sqlite math.intervals
 db.postgresql accessors random math.bitfields.lib
-math.ranges strings sequences.lib urls ;
+math.ranges strings sequences.lib urls fry ;
 IN: db.tuples.tests
 
 TUPLE: person the-id the-name the-number the-real
@@ -201,10 +201,10 @@ TUPLE: annotation n paste-id summary author mode contents ;
 ! ] with-db
 
 : test-sqlite ( quot -- )
-    >r "tuples-test.db" temp-file sqlite-db r> with-db ;
+    [ ] swap '[ "tuples-test.db" temp-file sqlite-db , with-db ] unit-test ;
 
 : test-postgresql ( quot -- )
-    >r { "localhost" "postgres" "foob" "factor-test" } postgresql-db r> with-db ;
+    [ ] swap '[ { "localhost" "postgres" "foob" "factor-test" } postgresql-db , with-db ] unit-test ;
 
 : test-repeated-insert
     [ ] [ person ensure-table ] unit-test
@@ -463,6 +463,31 @@ fubbclass "FUBCLASS" { } define-persistent
     [ t ] [ fubbclass new select-tuples [ fubbclass? ] all? ] unit-test ;
 
 [ test-db-inheritance ] test-sqlite
+[ test-db-inheritance ] test-postgresql
+
+
+TUPLE: string-encoding-test id string ;
+
+string-encoding-test "STRING_ENCODING_TEST" {
+    { "id" "ID" +db-assigned-id+ }
+    { "string" "STRING" TEXT }
+} define-persistent
+
+: test-string-encoding ( -- )
+    [ ] [ string-encoding-test ensure-table ] unit-test
+
+    [ ] [
+        string-encoding-test new
+            "\u{copyright-sign}\u{bengali-letter-cha}" >>string
+        [ insert-tuple ] [ id>> "id" set ] bi
+    ] unit-test
+    
+    [ "\u{copyright-sign}\u{bengali-letter-cha}" ] [
+        string-encoding-test new "id" get >>id select-tuple string>>
+    ] unit-test ;
+
+[ test-string-encoding ] test-sqlite
+[ test-string-encoding ] test-postgresql
 
 ! Don't comment these out. These words must infer
 \ bind-tuple must-infer
index 915ad0c648b3c678fd0cb04efe30cca3ce4bc6ba..6cea58058e60441e735db0f5ddabe45aa4552118 100755 (executable)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2007 Daniel Ehrenberg
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors parser generic kernel classes words slots assocs
-sequences arrays vectors definitions prettyprint
-math hashtables sets macros namespaces ;
+USING: accessors parser generic kernel classes classes.tuple
+words slots assocs sequences arrays vectors definitions
+prettyprint math hashtables sets macros namespaces ;
 IN: delegate
 
 : protocol-words ( protocol -- words )
index 3b55aa0521300929d1ba87353218b70f63e868d7..4b40747e9fa704282b7405aa0ad6f40470c9e249 100755 (executable)
@@ -1,6 +1,6 @@
 USING: words kernel sequences combinators.lib locals\r
 locals.private accessors parser namespaces continuations\r
-summary definitions arrays.lib arrays ;\r
+summary definitions generalizations arrays ;\r
 IN: descriptive\r
 \r
 ERROR: descriptive-error args underlying word ;\r
index 68161382c1bd76b2b1b0fe697790fae6aa51b81f..ce533bce644036491a977c7f54b52f5e0b059fb8 100755 (executable)
@@ -40,10 +40,9 @@ M: login-realm modify-form ( responder -- )
     permit-id get realm get name>> permit-id-key <cookie>\r
         "$login-realm" resolve-base-path >>path\r
         realm get\r
-        [ timeout>> from-now >>expires ]\r
         [ domain>> >>domain ]\r
         [ secure>> >>secure ]\r
-        tri ;\r
+        bi ;\r
 \r
 : put-permit-cookie ( response -- response' )\r
     <permit-cookie> put-cookie ;\r
index a614a525488926821067924927ad7bb4d67d0d75..68786a55ab7f0c3eb21ff187a11c7e4a85707f33 100644 (file)
@@ -31,6 +31,6 @@ TUPLE: server-state-manager < filter-responder timeout ;
     new
         swap >>responder
         20 minutes >>timeout ; inline
-    
+
 : touch-state ( state manager -- )
-    timeout>> from-now >>expires drop ;
+    timeout>> hence >>expires drop ;
index 0ec9648a67c25a95ec39e1869effbb05eeff464d..5590a9e55e874e30af4114896c57b514bb23381e 100755 (executable)
@@ -116,7 +116,6 @@ M: session-saver dispose
 : <session-cookie> ( -- cookie )
     session get id>> session-id-key <cookie>
         "$sessions" resolve-base-path >>path
-        sessions get timeout>> from-now >>expires
         sessions get domain>> >>domain ;
 
 : put-session-cookie ( response -- response' )
diff --git a/extra/generalizations/generalizations-docs.factor b/extra/generalizations/generalizations-docs.factor
new file mode 100755 (executable)
index 0000000..d2af13a
--- /dev/null
@@ -0,0 +1,136 @@
+! Copyright (C) 2007 Chris Double.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: help.syntax help.markup kernel sequences quotations\r
+math ;\r
+IN: generalizations\r
+\r
+HELP: npick\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link dup } ", "\r
+{ $link over } " and " { $link pick } " that can work "\r
+"for any stack depth. The nth item down the stack will be copied and "\r
+"placed on the top of the stack."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 npick .s" "1\n2\n3\n4\n1" }\r
+}\r
+{ $see-also dup over pick } ;\r
+\r
+HELP: ndup\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link dup } ", "\r
+{ $link 2dup } " and " { $link 3dup } " that can work "\r
+"for any number of items. The n topmost items on the stack will be copied and "\r
+"placed on the top of the stack."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 ndup .s" "1\n2\n3\n4\n1\n2\n3\n4" }\r
+}\r
+{ $see-also dup 2dup 3dup } ;\r
+\r
+HELP: nnip\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link nip } " and " { $link 2nip }\r
+" that can work "\r
+"for any number of items."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 3 nnip .s" "4" }\r
+}\r
+{ $see-also nip 2nip } ;\r
+\r
+HELP: ndrop\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link drop }\r
+" that can work "\r
+"for any number of items."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 3 ndrop .s" "1" }\r
+}\r
+{ $see-also drop 2drop 3drop } ;\r
+\r
+HELP: nrot\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link rot } " that works for any "\r
+"number of items on the stack. "\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 nrot .s" "2\n3\n4\n1" }\r
+}\r
+{ $see-also rot -nrot } ;\r
+\r
+HELP: -nrot\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link -rot } " that works for any "\r
+"number of items on the stack. "\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 -nrot .s" "4\n1\n2\n3" }\r
+}\r
+{ $see-also rot nrot } ;\r
+\r
+HELP: nrev\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link spin } " that reverses any number of items at the top of the stack."\r
+}\r
+{ $examples\r
+  { $example "USING: prettyprint generalizations ;" "1 2 3 4 4 nrev .s" "4\n3\n2\n1" }\r
+}\r
+{ $see-also rot nrot } ;\r
+\r
+HELP: ndip\r
+{ $values { "quot" quotation } { "n" number } }\r
+{ $description "A generalization of " { $link dip } " that can work " \r
+"for any stack depth. The quotation will be called with a stack that "\r
+"has 'n' items removed first. The 'n' items are then put back on the "\r
+"stack. The quotation can consume and produce any number of items."\r
+} \r
+{ $examples\r
+  { $example "USING: generalizations kernel prettyprint ;" "1 2 [ dup ] 1 ndip .s" "1\n1\n2" }\r
+  { $example "USING: generalizations kernel prettyprint ;" "1 2 3 [ drop ] 2 ndip .s" "2\n3" }\r
+}\r
+{ $see-also dip 2dip } ;\r
+\r
+HELP: nslip\r
+{ $values { "n" number } }\r
+{ $description "A generalization of " { $link slip } " that can work " \r
+"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "\r
+"removed from the stack, the quotation called, and the items restored."\r
+} \r
+{ $examples\r
+  { $example "USING: generalizations prettyprint ;" "[ 99 ] 1 2 3 4 5 5 nslip .s" "99\n1\n2\n3\n4\n5" }\r
+}\r
+{ $see-also slip nkeep } ;\r
+\r
+HELP: nkeep\r
+{ $values { "quot" quotation } { "n" number } }\r
+{ $description "A generalization of " { $link keep } " that can work " \r
+"for any stack depth. The first " { $snippet "n" } " items after the quotation will be "\r
+"saved, the quotation called, and the items restored."\r
+} \r
+{ $examples\r
+  { $example "USING: generalizations kernel prettyprint ;" "1 2 3 4 5 [ drop drop drop drop drop 99 ] 5 nkeep .s" "99\n1\n2\n3\n4\n5" }\r
+}\r
+{ $see-also keep nslip } ;\r
+\r
+ARTICLE: "generalizations" "Generalized shuffle words and combinators"\r
+"A number of stack shuffling words and combinators for use in "\r
+"macros where the arity of the input quotations depends on an "\r
+"input parameter."\r
+{ $subsection narray }\r
+{ $subsection ndup }\r
+{ $subsection npick }\r
+{ $subsection nrot }\r
+{ $subsection -nrot }\r
+{ $subsection nnip }\r
+{ $subsection ndrop }\r
+{ $subsection nrev }\r
+{ $subsection ndip }\r
+{ $subsection nslip }\r
+{ $subsection nkeep }\r
+{ $subsection ncurry } \r
+{ $subsection nwith } \r
+{ $subsection napply } ;\r
+\r
+ABOUT: "generalizations"\r
diff --git a/extra/generalizations/generalizations-tests.factor b/extra/generalizations/generalizations-tests.factor
new file mode 100755 (executable)
index 0000000..af010e2
--- /dev/null
@@ -0,0 +1,34 @@
+USING: tools.test generalizations kernel math arrays sequences ;\r
+IN: generalizations.tests\r
+\r
+{ 1 2 3 4 1 } [ 1 2 3 4 4 npick ] unit-test\r
+{ 1 2 3 4 2 } [ 1 2 3 4 3 npick ] unit-test\r
+{ 1 2 3 4 3 } [ 1 2 3 4 2 npick ] unit-test\r
+{ 1 2 3 4 4 } [ 1 2 3 4 1 npick ] unit-test\r
+[ 1 1 ndup ] must-infer\r
+{ 1 1 } [ 1 1 ndup ] unit-test\r
+{ 1 2 1 2 } [ 1 2 2 ndup ] unit-test\r
+{ 1 2 3 1 2 3 } [ 1 2 3 3 ndup ] unit-test\r
+{ 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4 ndup ] unit-test\r
+[ 1 2 2 nrot ] must-infer\r
+{ 2 1 } [ 1 2 2 nrot ] unit-test\r
+{ 2 3 1 } [ 1 2 3 3 nrot ] unit-test\r
+{ 2 3 4 1 } [ 1 2 3 4 4 nrot ] unit-test\r
+[ 1 2 2 -nrot ] must-infer\r
+{ 2 1 } [ 1 2 2 -nrot ] unit-test\r
+{ 3 1 2 } [ 1 2 3 3 -nrot ] unit-test\r
+{ 4 1 2 3 } [ 1 2 3 4 4 -nrot ] unit-test\r
+[ 1 2 3 4 3 nnip ] must-infer\r
+{ 4 } [ 1 2 3 4 3 nnip ] unit-test\r
+[ 1 2 3 4 4 ndrop ] must-infer\r
+{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test\r
+\r
+[ [ 99 ] 1 2 3 4 5 5 nslip ] must-infer\r
+{ 99 1 2 3 4 5 } [ [ 99 ] 1 2 3 4 5 5 nslip ] unit-test\r
+[ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] must-infer\r
+{ 2 1 2 3 4 5 } [ 1 2 3 4 5 [ drop drop drop drop drop 2 ] 5 nkeep ] unit-test\r
+[ [ 1 2 3 + ] ] [ 1 2 3 [ + ] 3 ncurry ] unit-test\r
+[ { 1 2 } { 2 4 } { 3 8 } { 4 16 } { 5 32 } ] [ 1 2 3 4 5 [ dup 2^ 2array ] 5 napply ] unit-test\r
+[ [ dup 2^ 2array ] 5 napply ] must-infer\r
+\r
+[ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test\r
diff --git a/extra/generalizations/generalizations.factor b/extra/generalizations/generalizations.factor
new file mode 100755 (executable)
index 0000000..6cbb135
--- /dev/null
@@ -0,0 +1,56 @@
+! Copyright (C) 2007, 2008 Chris Double, Doug Coleman.\r
+! See http://factorcode.org/license.txt for BSD license.\r
+USING: kernel sequences sequences.private namespaces math math.ranges\r
+combinators macros quotations fry locals arrays ;\r
+IN: generalizations\r
+\r
+MACRO: narray ( n -- quot )\r
+    dup [ f <array> ] curry\r
+    swap <reversed> [\r
+        [ swap [ set-nth-unsafe ] keep ] curry\r
+    ] map concat append ;\r
+\r
+MACRO: npick ( n -- )\r
+    1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;\r
+\r
+MACRO: ndup ( n -- )\r
+    dup '[ , npick ] n*quot ;\r
+\r
+MACRO: nrot ( n -- )\r
+    1- dup saver swap [ r> swap ] n*quot append ;\r
+\r
+MACRO: -nrot ( n -- )\r
+    1- dup [ swap >r ] n*quot swap restorer append ;\r
+\r
+MACRO: ndrop ( n -- )\r
+    [ drop ] n*quot ;\r
+\r
+: nnip ( n -- )\r
+    swap >r ndrop r> ; inline\r
+\r
+MACRO: ntuck ( n -- )\r
+    2 + [ dupd -nrot ] curry ;\r
+\r
+MACRO: nrev ( n -- quot )\r
+    1 [a,b] [ '[ , -nrot ] ] map concat ;\r
+\r
+MACRO: ndip ( quot n -- )\r
+    dup saver -rot restorer 3append ;\r
+\r
+MACRO: nslip ( n -- )\r
+    dup saver [ call ] rot restorer 3append ;\r
+\r
+MACRO: nkeep ( n -- )\r
+    [ ] [ 1+ ] [ ] tri\r
+    '[ [ , ndup ] dip , -nrot , nslip ] ;\r
+\r
+MACRO: ncurry ( n -- ) [ curry ] n*quot ;\r
+\r
+MACRO:: nwith ( quot n -- )\r
+    [let | n' [ n 1+ ] |\r
+        [ n' -nrot [ n' nrot quot call ] n ncurry ] ] ;\r
+\r
+MACRO: napply ( n -- )\r
+    2 [a,b]\r
+    [ [ 1- ] keep '[ , ntuck , nslip ] ]\r
+    map concat >quotation [ call ] append ;\r
index f6fccd42ecc189607e26627b19a1c99238c7dd5f..dca727b9dc5857a221ffc8cc8bb5a5f36645c07a 100755 (executable)
@@ -1,6 +1,6 @@
 USING: assocs html.parser kernel math sequences strings ascii
-arrays shuffle unicode.case namespaces splitting http
-sequences.lib accessors io combinators http.client urls ;
+arrays generalizations shuffle unicode.case namespaces splitting
+http sequences.lib accessors io combinators http.client urls ;
 IN: html.parser.analyzer
 
 TUPLE: link attributes clickable ;
index 4a35fbab24f20a4eae4cb95fd8cf5010a306f6b8..5a8ef4c78721ea9ccb5aa87b43812dda0bb14028 100755 (executable)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2007, 2008 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors kernel words summary slots quotations
-sequences assocs math arrays inference effects shuffle
+sequences assocs math arrays inference effects generalizations
 continuations debugger classes.tuple namespaces vectors
 bit-arrays byte-arrays strings sbufs math.functions macros
-sequences.private combinators mirrors combinators.lib
+sequences.private combinators mirrors
 combinators.short-circuit ;
 IN: inverse
 
index 0e37e41a76414a0c4c98efe4775e46bcf274f315..aa734e68094c552d56c7908e71aeb7e7824db7bd 100644 (file)
@@ -9,7 +9,7 @@ TUPLE: pool connections disposed expired ;
 : check-pool ( pool -- )
     dup check-disposed
     dup expired>> expired? [
-        ALIEN: 31337 >>expired
+        31337 <alien> >>expired
         connections>> delete-all
     ] [ drop ] if ;
 
index 2128142615993c98411460233f49361efc115393..b984b1f156cb226255178830565091940bd392c2 100755 (executable)
@@ -125,7 +125,8 @@ M: fd refill
     } cond ;
 
 M: unix (wait-to-read) ( port -- )
-    dup dup handle>> refill dup
+    dup
+    dup handle>> dup check-disposed refill dup
     [ dupd wait-for-port (wait-to-read) ] [ 2drop ] if ;
 
 ! Writers
@@ -144,7 +145,9 @@ M: fd drain
     } cond ;
 
 M: unix (wait-to-write) ( port -- )
-    dup dup handle>> drain dup [ wait-for-port ] [ 2drop ] if ;
+    dup
+    dup handle>> dup check-disposed drain
+    dup [ wait-for-port ] [ 2drop ] if ;
 
 M: unix io-multiplex ( ms/f -- )
     mx get-global wait-for-events ;
@@ -168,7 +171,7 @@ M: stdin dispose
 
 : wait-for-stdin ( stdin -- n )
     [ control>> CHAR: X over io:stream-write1 io:stream-flush ]
-    [ size>> "uint" heap-size swap io:stream-read *uint ]
+    [ size>> "ssize_t" heap-size swap io:stream-read *int ]
     bi ;
 
 :: refill-stdin ( buffer stdin size -- )
index 419509f124bfd767c1bb0962329217753a9b02c5..e25be71872e215e278d6c521b0c8badf926adb8e 100755 (executable)
@@ -61,6 +61,7 @@ C: <FileArgs> FileArgs
 
 : make-FileArgs ( port -- <FileArgs> )
     {
+        [ handle>> check-disposed ]
         [ handle>> handle>> ]
         [ buffer>> ]
         [ buffer>> buffer-length ]
index 786275c736342ba4a0386c7dc5746fb79632f538..e9df2ddab9bf325ca7d0e5c69dd6de2d5405957a 100755 (executable)
@@ -74,7 +74,7 @@ M: winnt add-completion ( win32-handle -- )
     ] if ;
 
 M: win32-handle cancel-operation
-    handle>> CancelIo drop ;
+    [ check-disposed ] [ handle>> CancelIo drop ] bi ;
 
 M: winnt io-multiplex ( ms -- )
     handle-overlapped [ 0 io-multiplex ] when ;
index 144c799912fa68bc6a2c26cd67929173236bdd35..e169bdf12f514369dec22779c90042a672fa6665 100755 (executable)
@@ -1,4 +1,5 @@
-USING: io.backend kernel continuations sequences ;\r
+USING: io.backend kernel continuations sequences\r
+system vocabs.loader combinators ;\r
 IN: io.windows.privileges\r
 \r
 HOOK: set-privilege io-backend ( name ? -- ) inline\r
@@ -6,3 +7,8 @@ HOOK: set-privilege io-backend ( name ? -- ) inline
 : with-privileges ( seq quot -- )\r
     over [ [ t set-privilege ] each ] curry compose\r
     swap [ [ f set-privilege ] each ] curry [ ] cleanup ; inline\r
+\r
+{\r
+    { [ os winnt? ] [ "io.windows.nt.privileges" require ] }\r
+    { [ os wince? ] [ "io.windows.ce.privileges" require ] }\r
+} cond\r
index 188cfaa1cfe308a73a4a3daec954051456f02d95..37c2137433a4b32892c4c71b77c83361711d1ec3 100755 (executable)
@@ -257,11 +257,11 @@ DEFER: (d)
     [ laplacian-kernel ] graded-laplacian ;
 
 : graded-basis. ( seq -- )
-    dup length [
+    [
         "=== Degree " write pprint
         ": dimension " write dup length .
         [ alt. ] each
-    ] 2each ;
+    ] each-index ;
 
 : bigraded-triple ( u-deg z-deg bigraded-basis -- triple )
     #! d: C(u,z) ---> C(u+2,z-1)
@@ -289,11 +289,11 @@ DEFER: (d)
     [ laplacian-kernel ] bigraded-laplacian ;
 
 : bigraded-basis. ( seq -- )
-    dup length [
+    [
         "=== U-degree " write .
-        dup length [
+        [
             "  === Z-degree " write pprint
             ": dimension " write dup length .
             [ "  " write alt. ] each
-        ] 2each
-    ] 2each ;
+        ] each-index
+    ] each-index ;
index 952bc17f1735032a3c915f1bb0257eb34f10c89d..b0d5060b4a50c6bf1bc8404fbe39310f660e16d1 100755 (executable)
@@ -1,7 +1,8 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 USING: sequences kernel math io calendar calendar.format
-calendar.model arrays models namespaces ui.gadgets
-ui.gadgets.labels
-ui.gadgets.theme ui ;
+calendar.model arrays models models.filter namespaces ui.gadgets
+ui.gadgets.labels ui.gadgets.theme ui ;
 IN: lcd
 
 : lcd-digit ( row digit -- str )
index 37ea9ac50744ada1c587abfa7ed5292b952368e8..78a3002906fcf2a14541ca4f4c0b20a2f84b5b67 100755 (executable)
@@ -3,7 +3,7 @@
 USING: logging.server sequences namespaces concurrency.messaging\r
 words kernel arrays shuffle tools.annotations\r
 prettyprint.config prettyprint debugger io.streams.string\r
-splitting continuations effects arrays.lib parser strings\r
+splitting continuations effects generalizations parser strings\r
 quotations fry symbols accessors ;\r
 IN: logging\r
 \r
diff --git a/extra/math/blas/cblas/authors.txt b/extra/math/blas/cblas/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/extra/math/blas/cblas/cblas.factor b/extra/math/blas/cblas/cblas.factor
new file mode 100644 (file)
index 0000000..31807b7
--- /dev/null
@@ -0,0 +1,557 @@
+USING: alien alien.c-types alien.syntax kernel system combinators ;
+IN: math.blas.cblas
+
+<< "cblas" {
+    { [ os macosx? ] [ "libblas.dylib" "cdecl" add-library ] }
+    { [ os windows? ] [ "blas.dll" "cdecl" add-library ] }
+    [ "libblas.so" "cdecl" add-library ]
+} cond >>
+
+LIBRARY: cblas
+
+TYPEDEF: int CBLAS_ORDER
+: CblasRowMajor 101 ; inline
+: CblasColMajor 102 ; inline
+
+TYPEDEF: int CBLAS_TRANSPOSE
+: CblasNoTrans   111 ; inline
+: CblasTrans     112 ; inline
+: CblasConjTrans 113 ; inline
+
+TYPEDEF: int CBLAS_UPLO
+: CblasUpper 121 ; inline
+: CblasLower 122 ; inline
+
+TYPEDEF: int CBLAS_DIAG
+: CblasNonUnit 131 ; inline
+: CblasUnit    132 ; inline
+
+TYPEDEF: int CBLAS_SIDE
+: CblasLeft  141 ; inline
+: CblasRight 142 ; inline
+
+TYPEDEF: int CBLAS_INDEX
+
+C-STRUCT: CBLAS_C
+    { "float" "real" }
+    { "float" "imag" } ;
+C-STRUCT: CBLAS_Z
+    { "double" "real" }
+    { "double" "imag" } ;
+
+! Level 1 BLAS (scalar-vector and vector-vector)
+
+FUNCTION: float  cblas_sdsdot
+    ( int N, float    alpha, float*   X, int incX, float*   Y, int incY ) ;
+FUNCTION: double cblas_dsdot
+    ( int N,                 float*   X, int incX, float*   Y, int incY ) ;
+FUNCTION: float  cblas_sdot
+    ( int N,                 float*   X, int incX, float*   Y, int incY ) ;
+FUNCTION: double cblas_ddot
+    ( int N,                 double*  X, int incX, double*  Y, int incY ) ;
+
+FUNCTION: void   cblas_cdotu_sub
+    ( int N,                 CBLAS_C* X, int incX, CBLAS_C* Y, int incY, CBLAS_C* dotu ) ;
+FUNCTION: void   cblas_cdotc_sub
+    ( int N,                 CBLAS_C* X, int incX, CBLAS_C* Y, int incY, CBLAS_C* dotc ) ;
+
+FUNCTION: void   cblas_zdotu_sub
+    ( int N,                 CBLAS_Z* X, int incX, CBLAS_Z* Y, int incY, CBLAS_Z* dotu ) ;
+FUNCTION: void   cblas_zdotc_sub
+    ( int N,                 CBLAS_Z* X, int incX, CBLAS_Z* Y, int incY, CBLAS_Z* dotc ) ;
+
+FUNCTION: float  cblas_snrm2
+    ( int N,                 float*   X, int incX ) ;
+FUNCTION: float  cblas_sasum
+    ( int N,                 float*   X, int incX ) ;
+
+FUNCTION: double cblas_dnrm2
+    ( int N,                 double*  X, int incX ) ;
+FUNCTION: double cblas_dasum
+    ( int N,                 double*  X, int incX ) ;
+
+FUNCTION: float  cblas_scnrm2
+    ( int N,                 CBLAS_C* X, int incX ) ;
+FUNCTION: float  cblas_scasum
+    ( int N,                 CBLAS_C* X, int incX ) ;
+
+FUNCTION: double cblas_dznrm2
+    ( int N,                 CBLAS_Z* X, int incX ) ;
+FUNCTION: double cblas_dzasum
+    ( int N,                 CBLAS_Z* X, int incX ) ;
+
+FUNCTION: CBLAS_INDEX cblas_isamax
+    ( int N,                 float*   X, int incX ) ;
+FUNCTION: CBLAS_INDEX cblas_idamax
+    ( int N,                 double*  X, int incX ) ;
+FUNCTION: CBLAS_INDEX cblas_icamax
+    ( int N,                 CBLAS_C* X, int incX ) ;
+FUNCTION: CBLAS_INDEX cblas_izamax
+    ( int N,                 CBLAS_Z* X, int incX ) ;
+
+FUNCTION: void cblas_sswap
+    ( int N,                 float*   X, int incX, float*   Y, int incY ) ;
+FUNCTION: void cblas_scopy
+    ( int N,                 float*   X, int incX, float*   Y, int incY ) ;
+FUNCTION: void cblas_saxpy
+    ( int N, float    alpha, float*   X, int incX, float*   Y, int incY ) ;
+
+FUNCTION: void cblas_dswap
+    ( int N,                 double*  X, int incX, double*  Y, int incY ) ;
+FUNCTION: void cblas_dcopy
+    ( int N,                 double*  X, int incX, double*  Y, int incY ) ;
+FUNCTION: void cblas_daxpy
+    ( int N, double   alpha, double*  X, int incX, double*  Y, int incY ) ;
+
+FUNCTION: void cblas_cswap
+    ( int N,                 CBLAS_C* X, int incX, CBLAS_C* Y, int incY ) ;
+FUNCTION: void cblas_ccopy
+    ( int N,                 CBLAS_C* X, int incX, CBLAS_C* Y, int incY ) ;
+FUNCTION: void cblas_caxpy
+    ( int N, CBLAS_C* alpha, CBLAS_C* X, int incX, CBLAS_C* Y, int incY ) ;
+
+FUNCTION: void cblas_zswap
+    ( int N,                 CBLAS_Z* X, int incX, CBLAS_Z* Y, int incY ) ;
+FUNCTION: void cblas_zcopy
+    ( int N,                 CBLAS_Z* X, int incX, CBLAS_Z* Y, int incY ) ;
+FUNCTION: void cblas_zaxpy
+    ( int N, CBLAS_Z* alpha, CBLAS_Z* X, int incX, CBLAS_Z* Y, int incY ) ;
+
+FUNCTION: void cblas_sscal
+    ( int N, float    alpha, float*   X, int incX ) ;
+FUNCTION: void cblas_dscal
+    ( int N, double   alpha, double*  X, int incX ) ;
+FUNCTION: void cblas_cscal
+    ( int N, CBLAS_C* alpha, CBLAS_C* X, int incX ) ;
+FUNCTION: void cblas_zscal
+    ( int N, CBLAS_Z* alpha, CBLAS_Z* X, int incX ) ;
+FUNCTION: void cblas_csscal
+    ( int N, float    alpha, CBLAS_C* X, int incX ) ;
+FUNCTION: void cblas_zdscal
+    ( int N, double   alpha, CBLAS_Z* X, int incX ) ;
+
+FUNCTION: void cblas_srotg
+    ( float* a, float* b, float* c, float* s ) ;
+FUNCTION: void cblas_srotmg
+    ( float* d1, float* d2, float* b1, float b2, float* P ) ;
+FUNCTION: void cblas_srot
+    ( int N, float* X, int incX, float* Y, int incY, float c, float s ) ;
+FUNCTION: void cblas_srotm
+    ( int N, float* X, int incX, float* Y, int incY, float* P ) ;
+
+FUNCTION: void cblas_drotg
+    ( double* a, double* b, double* c, double* s ) ;
+FUNCTION: void cblas_drotmg
+    ( double* d1, double* d2, double* b1, double b2, double* P ) ;
+FUNCTION: void cblas_drot
+    ( int N, double* X, int incX, double* Y, int incY, double c, double s ) ;
+FUNCTION: void cblas_drotm
+    ( int N, double* X, int incX, double* Y, int incY, double* P ) ;
+! Level 2 BLAS (matrix-vector)
+
+FUNCTION: void cblas_sgemv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 float alpha, float* A, int lda,
+                 float* X, int incX, float beta,
+                 float* Y, int incY ) ;
+FUNCTION: void cblas_sgbmv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 int KL, int KU, float alpha,
+                 float* A, int lda, float* X,
+                 int incX, float beta, float* Y, int incY ) ;
+FUNCTION: void cblas_strmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, float* A, int lda,
+                 float* X, int incX ) ;
+FUNCTION: void cblas_stbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, float* A, int lda,
+                 float* X, int incX ) ;
+FUNCTION: void cblas_stpmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, float* Ap, float* X, int incX ) ;
+FUNCTION: void cblas_strsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, float* A, int lda, float* X,
+                 int incX ) ;
+FUNCTION: void cblas_stbsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, float* A, int lda,
+                 float* X, int incX ) ;
+FUNCTION: void cblas_stpsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, float* Ap, float* X, int incX ) ;
+
+FUNCTION: void cblas_dgemv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 double alpha, double* A, int lda,
+                 double* X, int incX, double beta,
+                 double* Y, int incY ) ;
+FUNCTION: void cblas_dgbmv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 int KL, int KU, double alpha,
+                 double* A, int lda, double* X,
+                 int incX, double beta, double* Y, int incY ) ;
+FUNCTION: void cblas_dtrmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, double* A, int lda,
+                 double* X, int incX ) ;
+FUNCTION: void cblas_dtbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, double* A, int lda,
+                 double* X, int incX ) ;
+FUNCTION: void cblas_dtpmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, double* Ap, double* X, int incX ) ;
+FUNCTION: void cblas_dtrsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, double* A, int lda, double* X,
+                 int incX ) ;
+FUNCTION: void cblas_dtbsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, double* A, int lda,
+                 double* X, int incX ) ;
+FUNCTION: void cblas_dtpsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, double* Ap, double* X, int incX ) ;
+
+FUNCTION: void cblas_cgemv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* X, int incX, void* beta,
+                 void* Y, int incY ) ;
+FUNCTION: void cblas_cgbmv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 int KL, int KU, void* alpha,
+                 void* A, int lda, void* X,
+                 int incX, void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_ctrmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* A, int lda,
+                 void* X, int incX ) ;
+FUNCTION: void cblas_ctbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, void* A, int lda,
+                 void* X, int incX ) ;
+FUNCTION: void cblas_ctpmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* Ap, void* X, int incX ) ;
+FUNCTION: void cblas_ctrsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* A, int lda, void* X,
+                 int incX ) ;
+FUNCTION: void cblas_ctbsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, void* A, int lda,
+                 void* X, int incX ) ;
+FUNCTION: void cblas_ctpsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* Ap, void* X, int incX ) ;
+
+FUNCTION: void cblas_zgemv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* X, int incX, void* beta,
+                 void* Y, int incY ) ;
+FUNCTION: void cblas_zgbmv ( CBLAS_ORDER Order,
+                 CBLAS_TRANSPOSE TransA, int M, int N,
+                 int KL, int KU, void* alpha,
+                 void* A, int lda, void* X,
+                 int incX, void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_ztrmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* A, int lda,
+                 void* X, int incX ) ;
+FUNCTION: void cblas_ztbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, void* A, int lda,
+                 void* X, int incX ) ;
+FUNCTION: void cblas_ztpmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* Ap, void* X, int incX ) ;
+FUNCTION: void cblas_ztrsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* A, int lda, void* X,
+                 int incX ) ;
+FUNCTION: void cblas_ztbsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, int K, void* A, int lda,
+                 void* X, int incX ) ;
+FUNCTION: void cblas_ztpsv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE TransA, CBLAS_DIAG Diag,
+                 int N, void* Ap, void* X, int incX ) ;
+
+
+FUNCTION: void cblas_ssymv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, float alpha, float* A,
+                 int lda, float* X, int incX,
+                 float beta, float* Y, int incY ) ;
+FUNCTION: void cblas_ssbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, int K, float alpha, float* A,
+                 int lda, float* X, int incX,
+                 float beta, float* Y, int incY ) ;
+FUNCTION: void cblas_sspmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, float alpha, float* Ap,
+                 float* X, int incX,
+                 float beta, float* Y, int incY ) ;
+FUNCTION: void cblas_sger ( CBLAS_ORDER Order, int M, int N,
+                float alpha, float* X, int incX,
+                float* Y, int incY, float* A, int lda ) ;
+FUNCTION: void cblas_ssyr ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, float alpha, float* X,
+                int incX, float* A, int lda ) ;
+FUNCTION: void cblas_sspr ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, float alpha, float* X,
+                int incX, float* Ap ) ;
+FUNCTION: void cblas_ssyr2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, float alpha, float* X,
+                int incX, float* Y, int incY, float* A,
+                int lda ) ;
+FUNCTION: void cblas_sspr2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, float alpha, float* X,
+                int incX, float* Y, int incY, float* A ) ;
+
+FUNCTION: void cblas_dsymv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, double alpha, double* A,
+                 int lda, double* X, int incX,
+                 double beta, double* Y, int incY ) ;
+FUNCTION: void cblas_dsbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, int K, double alpha, double* A,
+                 int lda, double* X, int incX,
+                 double beta, double* Y, int incY ) ;
+FUNCTION: void cblas_dspmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, double alpha, double* Ap,
+                 double* X, int incX,
+                 double beta, double* Y, int incY ) ;
+FUNCTION: void cblas_dger ( CBLAS_ORDER Order, int M, int N,
+                double alpha, double* X, int incX,
+                double* Y, int incY, double* A, int lda ) ;
+FUNCTION: void cblas_dsyr ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, double alpha, double* X,
+                int incX, double* A, int lda ) ;
+FUNCTION: void cblas_dspr ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, double alpha, double* X,
+                int incX, double* Ap ) ;
+FUNCTION: void cblas_dsyr2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, double alpha, double* X,
+                int incX, double* Y, int incY, double* A,
+                int lda ) ;
+FUNCTION: void cblas_dspr2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, double alpha, double* X,
+                int incX, double* Y, int incY, double* A ) ;
+
+
+FUNCTION: void cblas_chemv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, void* alpha, void* A,
+                 int lda, void* X, int incX,
+                 void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_chbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, int K, void* alpha, void* A,
+                 int lda, void* X, int incX,
+                 void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_chpmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, void* alpha, void* Ap,
+                 void* X, int incX,
+                 void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_cgeru ( CBLAS_ORDER Order, int M, int N,
+                 void* alpha, void* X, int incX,
+                 void* Y, int incY, void* A, int lda ) ;
+FUNCTION: void cblas_cgerc ( CBLAS_ORDER Order, int M, int N,
+                 void* alpha, void* X, int incX,
+                 void* Y, int incY, void* A, int lda ) ;
+FUNCTION: void cblas_cher ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, float alpha, void* X, int incX,
+                void* A, int lda ) ;
+FUNCTION: void cblas_chpr ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, float alpha, void* X,
+                int incX, void* A ) ;
+FUNCTION: void cblas_cher2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo, int N,
+                void* alpha, void* X, int incX,
+                void* Y, int incY, void* A, int lda ) ;
+FUNCTION: void cblas_chpr2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo, int N,
+                void* alpha, void* X, int incX,
+                void* Y, int incY, void* Ap ) ;
+
+FUNCTION: void cblas_zhemv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, void* alpha, void* A,
+                 int lda, void* X, int incX,
+                 void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_zhbmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, int K, void* alpha, void* A,
+                 int lda, void* X, int incX,
+                 void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_zhpmv ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 int N, void* alpha, void* Ap,
+                 void* X, int incX,
+                 void* beta, void* Y, int incY ) ;
+FUNCTION: void cblas_zgeru ( CBLAS_ORDER Order, int M, int N,
+                 void* alpha, void* X, int incX,
+                 void* Y, int incY, void* A, int lda ) ;
+FUNCTION: void cblas_zgerc ( CBLAS_ORDER Order, int M, int N,
+                 void* alpha, void* X, int incX,
+                 void* Y, int incY, void* A, int lda ) ;
+FUNCTION: void cblas_zher ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, double alpha, void* X, int incX,
+                void* A, int lda ) ;
+FUNCTION: void cblas_zhpr ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                int N, double alpha, void* X,
+                int incX, void* A ) ;
+FUNCTION: void cblas_zher2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo, int N,
+                void* alpha, void* X, int incX,
+                void* Y, int incY, void* A, int lda ) ;
+FUNCTION: void cblas_zhpr2 ( CBLAS_ORDER Order, CBLAS_UPLO Uplo, int N,
+                void* alpha, void* X, int incX,
+                void* Y, int incY, void* Ap ) ;
+
+! Level 3 BLAS (matrix-matrix) 
+
+FUNCTION: void cblas_sgemm ( CBLAS_ORDER Order, CBLAS_TRANSPOSE TransA,
+                 CBLAS_TRANSPOSE TransB, int M, int N,
+                 int K, float alpha, float* A,
+                 int lda, float* B, int ldb,
+                 float beta, float* C, int ldc ) ;
+FUNCTION: void cblas_ssymm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, int M, int N,
+                 float alpha, float* A, int lda,
+                 float* B, int ldb, float beta,
+                 float* C, int ldc ) ;
+FUNCTION: void cblas_ssyrk ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE Trans, int N, int K,
+                 float alpha, float* A, int lda,
+                 float beta, float* C, int ldc ) ;
+FUNCTION: void cblas_ssyr2k ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                  CBLAS_TRANSPOSE Trans, int N, int K,
+                  float alpha, float* A, int lda,
+                  float* B, int ldb, float beta,
+                  float* C, int ldc ) ;
+FUNCTION: void cblas_strmm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 float alpha, float* A, int lda,
+                 float* B, int ldb ) ;
+FUNCTION: void cblas_strsm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 float alpha, float* A, int lda,
+                 float* B, int ldb ) ;
+
+FUNCTION: void cblas_dgemm ( CBLAS_ORDER Order, CBLAS_TRANSPOSE TransA,
+                 CBLAS_TRANSPOSE TransB, int M, int N,
+                 int K, double alpha, double* A,
+                 int lda, double* B, int ldb,
+                 double beta, double* C, int ldc ) ;
+FUNCTION: void cblas_dsymm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, int M, int N,
+                 double alpha, double* A, int lda,
+                 double* B, int ldb, double beta,
+                 double* C, int ldc ) ;
+FUNCTION: void cblas_dsyrk ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE Trans, int N, int K,
+                 double alpha, double* A, int lda,
+                 double beta, double* C, int ldc ) ;
+FUNCTION: void cblas_dsyr2k ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                  CBLAS_TRANSPOSE Trans, int N, int K,
+                  double alpha, double* A, int lda,
+                  double* B, int ldb, double beta,
+                  double* C, int ldc ) ;
+FUNCTION: void cblas_dtrmm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 double alpha, double* A, int lda,
+                 double* B, int ldb ) ;
+FUNCTION: void cblas_dtrsm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 double alpha, double* A, int lda,
+                 double* B, int ldb ) ;
+
+FUNCTION: void cblas_cgemm ( CBLAS_ORDER Order, CBLAS_TRANSPOSE TransA,
+                 CBLAS_TRANSPOSE TransB, int M, int N,
+                 int K, void* alpha, void* A,
+                 int lda, void* B, int ldb,
+                 void* beta, void* C, int ldc ) ;
+FUNCTION: void cblas_csymm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb, void* beta,
+                 void* C, int ldc ) ;
+FUNCTION: void cblas_csyrk ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE Trans, int N, int K,
+                 void* alpha, void* A, int lda,
+                 void* beta, void* C, int ldc ) ;
+FUNCTION: void cblas_csyr2k ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                  CBLAS_TRANSPOSE Trans, int N, int K,
+                  void* alpha, void* A, int lda,
+                  void* B, int ldb, void* beta,
+                  void* C, int ldc ) ;
+FUNCTION: void cblas_ctrmm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb ) ;
+FUNCTION: void cblas_ctrsm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb ) ;
+
+FUNCTION: void cblas_zgemm ( CBLAS_ORDER Order, CBLAS_TRANSPOSE TransA,
+                 CBLAS_TRANSPOSE TransB, int M, int N,
+                 int K, void* alpha, void* A,
+                 int lda, void* B, int ldb,
+                 void* beta, void* C, int ldc ) ;
+FUNCTION: void cblas_zsymm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb, void* beta,
+                 void* C, int ldc ) ;
+FUNCTION: void cblas_zsyrk ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE Trans, int N, int K,
+                 void* alpha, void* A, int lda,
+                 void* beta, void* C, int ldc ) ;
+FUNCTION: void cblas_zsyr2k ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                  CBLAS_TRANSPOSE Trans, int N, int K,
+                  void* alpha, void* A, int lda,
+                  void* B, int ldb, void* beta,
+                  void* C, int ldc ) ;
+FUNCTION: void cblas_ztrmm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb ) ;
+FUNCTION: void cblas_ztrsm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, CBLAS_TRANSPOSE TransA,
+                 CBLAS_DIAG Diag, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb ) ;
+
+FUNCTION: void cblas_chemm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb, void* beta,
+                 void* C, int ldc ) ;
+FUNCTION: void cblas_cherk ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE Trans, int N, int K,
+                 float alpha, void* A, int lda,
+                 float beta, void* C, int ldc ) ;
+FUNCTION: void cblas_cher2k ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                  CBLAS_TRANSPOSE Trans, int N, int K,
+                  void* alpha, void* A, int lda,
+                  void* B, int ldb, float beta,
+                  void* C, int ldc ) ;
+FUNCTION: void cblas_zhemm ( CBLAS_ORDER Order, CBLAS_SIDE Side,
+                 CBLAS_UPLO Uplo, int M, int N,
+                 void* alpha, void* A, int lda,
+                 void* B, int ldb, void* beta,
+                 void* C, int ldc ) ;
+FUNCTION: void cblas_zherk ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                 CBLAS_TRANSPOSE Trans, int N, int K,
+                 double alpha, void* A, int lda,
+                 double beta, void* C, int ldc ) ;
+FUNCTION: void cblas_zher2k ( CBLAS_ORDER Order, CBLAS_UPLO Uplo,
+                  CBLAS_TRANSPOSE Trans, int N, int K,
+                  void* alpha, void* A, int lda,
+                  void* B, int ldb, double beta,
+                  void* C, int ldc ) ;
+
diff --git a/extra/math/blas/cblas/summary.txt b/extra/math/blas/cblas/summary.txt
new file mode 100644 (file)
index 0000000..c72e78e
--- /dev/null
@@ -0,0 +1 @@
+Low-level bindings to the C Basic Linear Algebra Subroutines (BLAS) library
diff --git a/extra/math/blas/cblas/tags.txt b/extra/math/blas/cblas/tags.txt
new file mode 100644 (file)
index 0000000..241ec1e
--- /dev/null
@@ -0,0 +1,2 @@
+math
+bindings
diff --git a/extra/math/blas/matrices/authors.txt b/extra/math/blas/matrices/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/extra/math/blas/matrices/matrices-docs.factor b/extra/math/blas/matrices/matrices-docs.factor
new file mode 100644 (file)
index 0000000..0d9ac69
--- /dev/null
@@ -0,0 +1,235 @@
+USING: alien byte-arrays help.markup help.syntax math.blas.vectors sequences ;
+IN: math.blas.matrices
+
+ARTICLE: "math.blas-summary" "Basic Linear Algebra Subroutines (BLAS) interface"
+"Factor provides an interface to high-performance vector and matrix math routines available in the system's BLAS library. A set of specialized types are provided for handling packed, unboxed vector data:"
+{ $subsection "math.blas-types" }
+"Scalar-vector and vector-vector operations are available in the " { $vocab-link "math.blas.vectors" } " vocabulary:"
+{ $subsection "math.blas.vectors" }
+"Vector-matrix and matrix-matrix operations are available in the " { $vocab-link "math.blas.matrices" } " vocabulary:"
+{ $subsection "math.blas.matrices" }
+"The low-level BLAS C interface can be accessed directly through the " { $vocab-link "math.blas.cblas" } " vocabulary." ;
+
+ARTICLE: "math.blas-types" "BLAS interface types"
+"BLAS vectors come in single- and double-precision, real and complex flavors:"
+{ $subsection float-blas-vector }
+{ $subsection double-blas-vector }
+{ $subsection float-complex-blas-vector }
+{ $subsection double-complex-blas-vector }
+"These vector types all follow the " { $link sequence } " protocol. In addition, there are corresponding types for matrix data:"
+{ $subsection float-blas-matrix }
+{ $subsection double-blas-matrix }
+{ $subsection float-complex-blas-matrix }
+{ $subsection double-complex-blas-matrix } 
+"Syntax words are provided for constructing literal vectors and matrices in the " { $vocab-link "math.blas.syntax" } " vocabulary:"
+{ $subsection "math.blas.syntax" }
+"There are BOA constructors for all vector and matrix types, which provide the most flexibility in specifying memory layout:"
+{ $subsection <float-blas-vector> }
+{ $subsection <double-blas-vector> }
+{ $subsection <float-complex-blas-vector> }
+{ $subsection <double-complex-blas-vector> }
+{ $subsection <float-blas-matrix> }
+{ $subsection <double-blas-matrix> }
+{ $subsection <float-complex-blas-matrix> }
+{ $subsection <double-complex-blas-matrix> }
+"For the simple case of creating a dense, zero-filled vector or matrix, simple empty object constructors are provided:"
+{ $subsection <empty-vector> }
+{ $subsection <empty-matrix> } ;
+
+ARTICLE: "math.blas.matrices" "BLAS interface matrix operations"
+"Transposing and slicing matrices:"
+{ $subsection Mtranspose }
+{ $subsection Mrows }
+{ $subsection Mcols }
+{ $subsection Msub }
+"Matrix-vector products:"
+{ $subsection n*M.V+n*V-in-place }
+{ $subsection n*M.V+n*V }
+{ $subsection n*M.V }
+{ $subsection M.V }
+"Vector outer products:"
+{ $subsection n*V(*)V+M-in-place }
+{ $subsection n*V(*)Vconj+M-in-place }
+{ $subsection n*V(*)V+M }
+{ $subsection n*V(*)Vconj+M }
+{ $subsection n*V(*)V }
+{ $subsection n*V(*)Vconj }
+{ $subsection V(*) }
+{ $subsection V(*)conj }
+"Matrix products:"
+{ $subsection n*M.M+n*M-in-place }
+{ $subsection n*M.M+n*M }
+{ $subsection n*M.M }
+{ $subsection M. }
+"Scalar-matrix products:"
+{ $subsection n*M-in-place }
+{ $subsection n*M }
+{ $subsection M*n }
+{ $subsection M/n } ;
+
+ABOUT: "math.blas.matrices"
+
+HELP: blas-matrix-base
+{ $class-description "The base class for all BLAS matrix types. Objects of this type should not be created directly; instead, instantiate one of the typed subclasses:"
+{ $list
+    { { $link float-blas-matrix } }
+    { { $link double-blas-matrix } }
+    { { $link float-complex-blas-matrix } }
+    { { $link double-complex-blas-matrix } }
+}
+"All of these subclasses share the same tuple layout:"
+{ $list
+    { { $snippet "data" } " contains an alien pointer referencing or byte-array containing a packed, column-major array of float, double, float complex, or double complex values;" }
+    { { $snippet "ld" } " indicates the distance, in elements, between matrix columns;" }
+    { { $snippet "rows" } " and " { $snippet "cols" } " indicate the number of significant rows and columns in the matrix;" }
+    { "and " { $snippet "transpose" } ", if set to a true value, indicates that the matrix should be treated as transposed relative to its in-memory representation." }
+} } ;
+
+{ blas-vector-base blas-matrix-base } related-words
+
+HELP: float-blas-matrix
+{ $class-description "A matrix of single-precision floating-point values. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
+HELP: double-blas-matrix
+{ $class-description "A matrix of double-precision floating-point values. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
+HELP: float-complex-blas-matrix
+{ $class-description "A matrix of single-precision floating-point complex values. Complex values are stored in memory as two consecutive float values, real part then imaginary part. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
+HELP: double-complex-blas-matrix
+{ $class-description "A matrix of double-precision floating-point complex values. Complex values are stored in memory as two consecutive float values, real part then imaginary part. For details on the tuple layout, see " { $link blas-matrix-base } "." } ;
+
+{
+    float-blas-matrix double-blas-matrix float-complex-blas-matrix double-complex-blas-matrix
+    float-blas-vector double-blas-vector float-complex-blas-vector double-complex-blas-vector
+} related-words
+
+HELP: Mwidth
+{ $values { "matrix" "a BLAS matrix inherited from " { $link blas-matrix-base } } { "width" "The number of columns" } }
+{ $description "Returns the number of columns in " { $snippet "matrix" } "." } ;
+
+HELP: Mheight
+{ $values { "matrix" "a BLAS matrix inherited from " { $link blas-matrix-base } } { "width" "The number of columns" } }
+{ $description "Returns the number of rows in " { $snippet "matrix" } "." } ;
+
+{ Mwidth Mheight } related-words
+
+HELP: n*M.V+n*V-in-place
+{ $values { "alpha" "a number" } { "A" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } { "x" "an N-element BLAS vector inherited from " { $link blas-vector-base } } { "beta" "a number" } { "y" "an M-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the matrix-vector product " { $snippet "αAx + βy" } ", and overwrite the current contents of " { $snippet "y" } " with the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ", and the height must match the length of " { $snippet "y" } ". Corresponds to the xGEMV routines in BLAS." }
+{ $side-effects "y" } ;
+
+HELP: n*V(*)V+M-in-place
+{ $values { "alpha" "a number" } { "x" "an M-element BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element BLAS vector inherited from " { $link blas-vector-base } } { "A" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the outer product " { $snippet "αx⊗y + A" } " and overwrite the current contents of A with the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". Corresponds to the xGER and xGERU routines in BLAS." }
+{ $side-effects "A" } ;
+
+HELP: n*V(*)Vconj+M-in-place
+{ $values { "alpha" "a number" } { "x" "an M-element complex BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element complex BLAS vector inherited from " { $link blas-vector-base } } { "A" "an M-row, N-column complex BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the conjugate outer product " { $snippet "αx⊗y̅ + A" } " and overwrite the current contents of A with the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". Corresponds to the xGERC routines in BLAS." }
+{ $side-effects "A" } ;
+
+HELP: n*M.M+n*M-in-place
+{ $values { "alpha" "a number" } { "A" "an M-row, K-column BLAS matrix inherited from " { $link blas-matrix-base } } { "B" "a K-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } { "beta" "a number" } { "C" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the matrix product " { $snippet "αAB + βC" } " and overwrite the current contents of C with the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match, as must the heights of " { $snippet "A" } " and " { $snippet "C" } ", and the widths of " { $snippet "B" } " and " { $snippet "C" } ". Corresponds to the xGEMM routines in BLAS." } ;
+
+HELP: <empty-matrix>
+{ $values { "rows" "the number of rows the new matrix will have" } { "cols" "the number of columns the new matrix will have" } { "exemplar" "A BLAS vector inherited from " { $link blas-vector-base } " or BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Create a matrix of all zeros with the given dimensions and the same element type as " { $snippet "exemplar" } "." } ;
+
+{ <zero-vector> <empty-vector> <empty-matrix> } related-words
+
+HELP: n*M.V+n*V
+{ $values { "alpha" "a number" } { "A" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } { "x" "an N-element BLAS vector inherited from " { $link blas-vector-base } } { "beta" "a number" } { "y" "an M-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the matrix-vector product " { $snippet "αAx + βy" } " and return a freshly allocated vector containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ", and the height must match the length of " { $snippet "y" } ". The returned vector will have the same length as " { $snippet "y" } ". Corresponds to the xGEMV routines in BLAS." } ;
+
+HELP: n*V(*)V+M
+{ $values { "alpha" "a number" } { "x" "an M-element BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element BLAS vector inherited from " { $link blas-vector-base } } { "A" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the outer product " { $snippet "αx⊗y + A" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". The returned matrix will have the same dimensions as " { $snippet "A" } ". Corresponds to the xGER and xGERU routines in BLAS." } ;
+
+HELP: n*V(*)Vconj+M
+{ $values { "alpha" "a number" } { "x" "an M-element complex BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element complex BLAS vector inherited from " { $link blas-vector-base } } { "A" "an M-row, N-column complex BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the conjugate outer product " { $snippet "αx⊗y̅ + A" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "y" } ", and its height must match the length of " { $snippet "x" } ". The returned matrix will have the same dimensions as " { $snippet "A" } ". Corresponds to the xGERC routines in BLAS." } ;
+
+HELP: n*M.M+n*M
+{ $values { "alpha" "a number" } { "A" "an M-row, K-column BLAS matrix inherited from " { $link blas-matrix-base } } { "B" "a K-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } { "beta" "a number" } { "C" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the matrix product " { $snippet "αAB + βC" } " and overwrite the current contents of C with the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match, as must the heights of " { $snippet "A" } " and " { $snippet "C" } ", and the widths of " { $snippet "B" } " and " { $snippet "C" } ". Corresponds to the xGEMM routines in BLAS." } ;
+
+HELP: n*M.V
+{ $values { "alpha" "a number" } { "A" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } { "x" "an N-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the matrix-vector product " { $snippet "αAx" } " and return a freshly allocated vector containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ". The length of the returned vector will match the height of " { $snippet "A" } ". Corresponds to the xGEMV routines in BLAS." } ;
+
+HELP: M.V
+{ $values { "A" "an M-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } { "x" "an N-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the matrix-vector product " { $snippet "Ax" } " and return a freshly allocated vector containing the result. The width of " { $snippet "A" } " must match the length of " { $snippet "x" } ". The length of the returned vector will match the height of " { $snippet "A" } ". Corresponds to the xGEMV routines in BLAS." } ;
+
+{ n*M.V+n*V-in-place n*M.V+n*V n*M.V M.V } related-words
+
+HELP: n*V(*)V
+{ $values { "alpha" "a number" } { "x" "an M-element BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the outer product " { $snippet "αx⊗y" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGER and xGERU routines in BLAS." } ;
+
+HELP: n*V(*)Vconj
+{ $values { "alpha" "a number" } { "x" "an M-element BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the outer product " { $snippet "αx⊗y̅" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGERC routines in BLAS." } ;
+
+HELP: V(*)
+{ $values { "x" "an M-element BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the outer product " { $snippet "x⊗y" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGER and xGERU routines in BLAS." } ;
+
+HELP: V(*)conj
+{ $values { "x" "an M-element BLAS vector inherited from " { $link blas-vector-base } } { "y" "an N-element BLAS vector inherited from " { $link blas-vector-base } } }
+{ $description "Calculate the conjugate outer product " { $snippet "x⊗y̅" } " and return a freshly allocated matrix containing the result. The returned matrix's height will match the length of " { $snippet "x" } ", and its width will match the length of " { $snippet "y" } ". Corresponds to the xGERC routines in BLAS." } ;
+
+{ n*V(*)V+M-in-place n*V(*)Vconj+M-in-place n*V(*)V+M n*V(*)Vconj+M n*V(*)V n*V(*)Vconj V(*) V(*)conj V. V.conj } related-words
+
+HELP: n*M.M
+{ $values { "alpha" "a number" } { "A" "an M-row, K-column BLAS matrix inherited from " { $link blas-matrix-base } } { "B" "a K-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the matrix product " { $snippet "αAB" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match. The returned matrix's height will be the same as " { $snippet "A" } "'s, and its width will match " { $snippet "B" } "'s. Corresponds to the xGEMM routines in BLAS." } ;
+
+HELP: M.
+{ $values { "A" "an M-row, K-column BLAS matrix inherited from " { $link blas-matrix-base } } { "B" "a K-row, N-column BLAS matrix inherited from " { $link blas-matrix-base } } }
+{ $description "Calculate the matrix product " { $snippet "AB" } " and return a freshly allocated matrix containing the result. The width of " { $snippet "A" } " and the height of " { $snippet "B" } " must match. The returned matrix's height will be the same as " { $snippet "A" } "'s, and its width will match " { $snippet "B" } "'s. Corresponds to the xGEMM routines in BLAS." } ;
+
+{ n*M.M+n*M-in-place n*M.M+n*M n*M.M M. } related-words
+
+HELP: Msub
+{ $values { "matrix" "A BLAS matrix inheriting from " { $link blas-matrix-base } } { "row" "The topmost row of the slice" } { "col" "The leftmost column of the slice" } { "height" "The height of the slice" } { "width" "The width of the slice" } }
+{ $description "Select a rectangular submatrix of " { $snippet "matrix" } " with the given dimensions. The returned submatrix will share the parent matrix's storage." } ;
+
+HELP: Mrows
+{ $values { "matrix" "A BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Return a sequence of BLAS vectors representing the rows of " { $snippet "matrix" } ". Each vector will share the parent matrix's storage." } ;
+
+HELP: Mcols
+{ $values { "matrix" "A BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Return a sequence of BLAS vectors representing the columns of " { $snippet "matrix" } ". Each vector will share the parent matrix's storage." } ;
+
+HELP: n*M-in-place
+{ $values { "n" "a number" } { "A" "A BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Calculate the scalar-matrix product " { $snippet "nA" } " and overwrite the current contents of A with the result." }
+{ $side-effects "A" } ;
+
+HELP: n*M
+{ $values { "n" "a number" } { "A" "A BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Calculate the scalar-matrix product " { $snippet "nA" } " and return a freshly allocated matrix with the same dimensions as " { $snippet "A" } " containing the result." } ;
+
+HELP: M*n
+{ $values { "A" "A BLAS matrix inheriting from " { $link blas-matrix-base } } { "n" "a number" } }
+{ $description "Calculate the scalar-matrix product " { $snippet "nA" } " and return a freshly allocated matrix with the same dimensions as " { $snippet "A" } " containing the result." } ;
+
+HELP: M/n
+{ $values { "A" "A BLAS matrix inheriting from " { $link blas-matrix-base } } { "n" "a number" } }
+{ $description "Calculate the scalar-matrix product " { $snippet "(1/n)A" } " and return a freshly allocated matrix with the same dimensions as " { $snippet "A" } " containing the result." } ;
+
+{ n*M-in-place n*M M*n M/n } related-words
+
+HELP: Mtranspose
+{ $values { "matrix" "A BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Returns the transpose of " { $snippet "matrix" } ". The returned matrix shares storage with the original matrix." } ;
+
+HELP: element-type
+{ $values { "v" "a BLAS vector inheriting from " { $link blas-vector-base } ", or a BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Return the C type of the elements in the given BLAS vector or matrix." } ;
+
+HELP: <empty-vector>
+{ $values { "length" "The length of the new vector" } { "exemplar" "a BLAS vector inheriting from " { $link blas-vector-base } ", or a BLAS matrix inheriting from " { $link blas-matrix-base } } }
+{ $description "Return a vector of zeros with the given length and the same element type as " { $snippet "v" } "." } ;
+
diff --git a/extra/math/blas/matrices/matrices-tests.factor b/extra/math/blas/matrices/matrices-tests.factor
new file mode 100644 (file)
index 0000000..dabf3c3
--- /dev/null
@@ -0,0 +1,710 @@
+USING: kernel math.blas.matrices math.blas.vectors math.blas.syntax
+sequences tools.test ;
+IN: math.blas.matrices.tests
+
+! clone
+
+[ smatrix{
+    { 1.0 2.0 3.0 }
+    { 4.0 5.0 6.0 }
+    { 7.0 8.0 9.0 }
+} ] [
+    smatrix{
+        { 1.0 2.0 3.0 }
+        { 4.0 5.0 6.0 }
+        { 7.0 8.0 9.0 }
+    } clone
+] unit-test
+[ f ] [
+    smatrix{
+        { 1.0 2.0 3.0 }
+        { 4.0 5.0 6.0 }
+        { 7.0 8.0 9.0 }
+    } dup clone eq?
+] unit-test
+
+[ dmatrix{
+    { 1.0 2.0 3.0 }
+    { 4.0 5.0 6.0 }
+    { 7.0 8.0 9.0 }
+} ] [
+    dmatrix{
+        { 1.0 2.0 3.0 }
+        { 4.0 5.0 6.0 }
+        { 7.0 8.0 9.0 }
+    } clone
+] unit-test
+[ f ] [
+    dmatrix{
+        { 1.0 2.0 3.0 }
+        { 4.0 5.0 6.0 }
+        { 7.0 8.0 9.0 }
+    } dup clone eq?
+] unit-test
+
+[ cmatrix{
+    { C{ 1.0 1.0 } 2.0          3.0          }
+    { 4.0          C{ 5.0 2.0 } 6.0          }
+    { 7.0          8.0          C{ 9.0 3.0 } }
+} ] [
+    cmatrix{
+        { C{ 1.0 1.0 } 2.0          3.0          }
+        { 4.0          C{ 5.0 2.0 } 6.0          }
+        { 7.0          8.0          C{ 9.0 3.0 } }
+    } clone
+] unit-test
+[ f ] [
+    cmatrix{
+        { C{ 1.0 1.0 } 2.0          3.0          }
+        { 4.0          C{ 5.0 2.0 } 6.0          }
+        { 7.0          8.0          C{ 9.0 3.0 } }
+    } dup clone eq?
+] unit-test
+
+[ zmatrix{
+    { C{ 1.0 1.0 } 2.0          3.0          }
+    { 4.0          C{ 5.0 2.0 } 6.0          }
+    { 7.0          8.0          C{ 9.0 3.0 } }
+} ] [
+    zmatrix{
+        { C{ 1.0 1.0 } 2.0          3.0          }
+        { 4.0          C{ 5.0 2.0 } 6.0          }
+        { 7.0          8.0          C{ 9.0 3.0 } }
+    } clone
+] unit-test
+[ f ] [
+    zmatrix{
+        { C{ 1.0 1.0 } 2.0          3.0          }
+        { 4.0          C{ 5.0 2.0 } 6.0          }
+        { 7.0          8.0          C{ 9.0 3.0 } }
+    } dup clone eq?
+] unit-test
+
+! M.V
+
+[ svector{ 3.0 1.0 6.0 } ] [
+    smatrix{
+        {  0.0 1.0 0.0 1.0 }
+        { -1.0 0.0 0.0 2.0 }
+        {  0.0 0.0 1.0 3.0 }
+    }
+    svector{ 1.0 2.0 3.0 1.0 }
+    M.V
+] unit-test 
+[ svector{ -2.0 1.0 3.0 14.0 } ] [
+    smatrix{
+        {  0.0 1.0 0.0 1.0 }
+        { -1.0 0.0 0.0 2.0 }
+        {  0.0 0.0 1.0 3.0 }
+    } Mtranspose
+    svector{ 1.0 2.0 3.0 }
+    M.V
+] unit-test 
+
+[ dvector{ 3.0 1.0 6.0 } ] [
+    dmatrix{
+        {  0.0 1.0 0.0 1.0 }
+        { -1.0 0.0 0.0 2.0 }
+        {  0.0 0.0 1.0 3.0 }
+    }
+    dvector{ 1.0 2.0 3.0 1.0 }
+    M.V
+] unit-test 
+[ dvector{ -2.0 1.0 3.0 14.0 } ] [
+    dmatrix{
+        {  0.0 1.0 0.0 1.0 }
+        { -1.0 0.0 0.0 2.0 }
+        {  0.0 0.0 1.0 3.0 }
+    } Mtranspose
+    dvector{ 1.0 2.0 3.0 }
+    M.V
+] unit-test 
+
+[ cvector{ 3.0 C{ 1.0 2.0 } 6.0 } ] [
+    cmatrix{
+        {  0.0 1.0          0.0 1.0 }
+        { -1.0 C{ 0.0 1.0 } 0.0 2.0 }
+        {  0.0 0.0          1.0 3.0 }
+    }
+    cvector{ 1.0 2.0 3.0 1.0 }
+    M.V
+] unit-test 
+[ cvector{ -2.0 C{ 1.0 2.0 } 3.0 14.0 } ] [
+    cmatrix{
+        {  0.0 1.0          0.0 1.0 }
+        { -1.0 C{ 0.0 1.0 } 0.0 2.0 }
+        {  0.0 0.0          1.0 3.0 }
+    } Mtranspose
+    cvector{ 1.0 2.0 3.0 }
+    M.V
+] unit-test 
+
+[ zvector{ 3.0 C{ 1.0 2.0 } 6.0 } ] [
+    zmatrix{
+        {  0.0 1.0          0.0 1.0 }
+        { -1.0 C{ 0.0 1.0 } 0.0 2.0 }
+        {  0.0 0.0          1.0 3.0 }
+    }
+    zvector{ 1.0 2.0 3.0 1.0 }
+    M.V
+] unit-test
+[ zvector{ -2.0 C{ 1.0 2.0 } 3.0 14.0 } ] [
+    zmatrix{
+        {  0.0 1.0          0.0 1.0 }
+        { -1.0 C{ 0.0 1.0 } 0.0 2.0 }
+        {  0.0 0.0          1.0 3.0 }
+    } Mtranspose
+    zvector{ 1.0 2.0 3.0 }
+    M.V
+] unit-test 
+
+! V(*)
+
+[ smatrix{
+    { 1.0 2.0 3.0  4.0 }
+    { 2.0 4.0 6.0  8.0 }
+    { 3.0 6.0 9.0 12.0 }
+} ] [
+    svector{ 1.0 2.0 3.0 } svector{ 1.0 2.0 3.0 4.0 } V(*)
+] unit-test
+
+[ dmatrix{
+    { 1.0 2.0 3.0  4.0 }
+    { 2.0 4.0 6.0  8.0 }
+    { 3.0 6.0 9.0 12.0 }
+} ] [
+    dvector{ 1.0 2.0 3.0 } dvector{ 1.0 2.0 3.0 4.0 } V(*)
+] unit-test
+
+[ cmatrix{
+    { 1.0          2.0          C{ 3.0 -3.0 } 4.0            }
+    { 2.0          4.0          C{ 6.0 -6.0 } 8.0            }
+    { C{ 3.0 3.0 } C{ 6.0 6.0 } 18.0          C{ 12.0 12.0 } }
+} ] [
+    cvector{ 1.0 2.0 C{ 3.0 3.0 } } cvector{ 1.0 2.0 C{ 3.0 -3.0 } 4.0 } V(*)
+] unit-test
+
+[ zmatrix{
+    { 1.0          2.0          C{ 3.0 -3.0 } 4.0            }
+    { 2.0          4.0          C{ 6.0 -6.0 } 8.0            }
+    { C{ 3.0 3.0 } C{ 6.0 6.0 } 18.0          C{ 12.0 12.0 } }
+} ] [
+    zvector{ 1.0 2.0 C{ 3.0 3.0 } } zvector{ 1.0 2.0 C{ 3.0 -3.0 } 4.0 } V(*)
+] unit-test
+
+! M.
+
+[ smatrix{
+    { 1.0 0.0  0.0 4.0  0.0 }
+    { 0.0 0.0 -3.0 0.0  0.0 }
+    { 0.0 4.0  0.0 0.0 10.0 }
+    { 0.0 0.0  0.0 0.0  0.0 }
+} ] [
+    smatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } smatrix{
+        { 1.0 0.0 0.0 4.0 0.0 }
+        { 0.0 2.0 0.0 0.0 5.0 }
+        { 0.0 0.0 3.0 0.0 0.0 }
+    } M.
+] unit-test
+
+[ smatrix{
+    { 1.0  0.0  0.0 0.0 }
+    { 0.0  0.0  4.0 0.0 }
+    { 0.0 -3.0  0.0 0.0 }
+    { 4.0  0.0  0.0 0.0 }
+    { 0.0  0.0 10.0 0.0 }
+} ] [
+    smatrix{
+        { 1.0 0.0 0.0 4.0 0.0 }
+        { 0.0 2.0 0.0 0.0 5.0 }
+        { 0.0 0.0 3.0 0.0 0.0 }
+    } Mtranspose smatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } Mtranspose M.
+] unit-test
+
+[ dmatrix{
+    { 1.0 0.0  0.0 4.0  0.0 }
+    { 0.0 0.0 -3.0 0.0  0.0 }
+    { 0.0 4.0  0.0 0.0 10.0 }
+    { 0.0 0.0  0.0 0.0  0.0 }
+} ] [
+    dmatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } dmatrix{
+        { 1.0 0.0 0.0 4.0 0.0 }
+        { 0.0 2.0 0.0 0.0 5.0 }
+        { 0.0 0.0 3.0 0.0 0.0 }
+    } M.
+] unit-test
+
+[ dmatrix{
+    { 1.0  0.0  0.0 0.0 }
+    { 0.0  0.0  4.0 0.0 }
+    { 0.0 -3.0  0.0 0.0 }
+    { 4.0  0.0  0.0 0.0 }
+    { 0.0  0.0 10.0 0.0 }
+} ] [
+    dmatrix{
+        { 1.0 0.0 0.0 4.0 0.0 }
+        { 0.0 2.0 0.0 0.0 5.0 }
+        { 0.0 0.0 3.0 0.0 0.0 }
+    } Mtranspose dmatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } Mtranspose M.
+] unit-test
+
+[ cmatrix{
+    { 1.0 0.0            0.0 4.0  0.0 }
+    { 0.0 0.0           -3.0 0.0  0.0 }
+    { 0.0 C{ 4.0 -4.0 }  0.0 0.0 10.0 }
+    { 0.0 0.0            0.0 0.0  0.0 }
+} ] [
+    cmatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } cmatrix{
+        { 1.0 0.0           0.0 4.0 0.0 }
+        { 0.0 C{ 2.0 -2.0 } 0.0 0.0 5.0 }
+        { 0.0 0.0           3.0 0.0 0.0 }
+    } M.
+] unit-test
+
+[ cmatrix{
+    { 1.0  0.0  0.0          0.0 }
+    { 0.0  0.0 C{ 4.0 -4.0 } 0.0 }
+    { 0.0 -3.0  0.0          0.0 }
+    { 4.0  0.0  0.0          0.0 }
+    { 0.0  0.0 10.0          0.0 }
+} ] [
+    cmatrix{
+        { 1.0 0.0           0.0 4.0 0.0 }
+        { 0.0 C{ 2.0 -2.0 } 0.0 0.0 5.0 }
+        { 0.0 0.0           3.0 0.0 0.0 }
+    } Mtranspose cmatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } Mtranspose M.
+] unit-test
+
+[ zmatrix{
+    { 1.0 0.0            0.0 4.0  0.0 }
+    { 0.0 0.0           -3.0 0.0  0.0 }
+    { 0.0 C{ 4.0 -4.0 }  0.0 0.0 10.0 }
+    { 0.0 0.0            0.0 0.0  0.0 }
+} ] [
+    zmatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } zmatrix{
+        { 1.0 0.0           0.0 4.0 0.0 }
+        { 0.0 C{ 2.0 -2.0 } 0.0 0.0 5.0 }
+        { 0.0 0.0           3.0 0.0 0.0 }
+    } M.
+] unit-test
+
+[ zmatrix{
+    { 1.0  0.0  0.0          0.0 }
+    { 0.0  0.0 C{ 4.0 -4.0 } 0.0 }
+    { 0.0 -3.0  0.0          0.0 }
+    { 4.0  0.0  0.0          0.0 }
+    { 0.0  0.0 10.0          0.0 }
+} ] [
+    zmatrix{
+        { 1.0 0.0           0.0 4.0 0.0 }
+        { 0.0 C{ 2.0 -2.0 } 0.0 0.0 5.0 }
+        { 0.0 0.0           3.0 0.0 0.0 }
+    } Mtranspose zmatrix{
+        { 1.0 0.0  0.0 }
+        { 0.0 0.0 -1.0 }
+        { 0.0 2.0  0.0 }
+        { 0.0 0.0  0.0 }
+    } Mtranspose M.
+] unit-test
+
+! n*M
+
+[ smatrix{
+    { 2.0 0.0 }
+    { 0.0 2.0 }
+} ] [
+    2.0 smatrix{
+        { 1.0 0.0 }
+        { 0.0 1.0 }
+    } n*M
+] unit-test
+
+[ dmatrix{
+    { 2.0 0.0 }
+    { 0.0 2.0 }
+} ] [
+    2.0 dmatrix{
+        { 1.0 0.0 }
+        { 0.0 1.0 }
+    } n*M
+] unit-test
+
+[ cmatrix{
+    { C{ 2.0 1.0 } 0.0           }
+    { 0.0          C{ -1.0 2.0 } }
+} ] [
+    C{ 2.0 1.0 } cmatrix{
+        { 1.0 0.0          }
+        { 0.0 C{ 0.0 1.0 } }
+    } n*M
+] unit-test
+
+[ zmatrix{
+    { C{ 2.0 1.0 } 0.0           }
+    { 0.0          C{ -1.0 2.0 } }
+} ] [
+    C{ 2.0 1.0 } zmatrix{
+        { 1.0 0.0          }
+        { 0.0 C{ 0.0 1.0 } }
+    } n*M
+] unit-test
+
+! Mrows, Mcols
+
+[ svector{ 3.0 3.0 3.0 } ] [
+    2 smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mcols nth
+] unit-test
+[ svector{ 3.0 2.0 3.0 4.0 } ] [
+    2 smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mrows nth
+] unit-test
+[ 3 ] [
+    smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mrows length
+] unit-test
+[ 4 ] [
+    smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mcols length
+] unit-test
+[ svector{ 3.0 3.0 3.0 } ] [
+    2 smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mrows nth
+] unit-test
+[ svector{ 3.0 2.0 3.0 4.0 } ] [
+    2 smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mcols nth
+] unit-test
+[ 3 ] [
+    smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mcols length
+] unit-test
+[ 4 ] [
+    smatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mrows length
+] unit-test
+
+[ dvector{ 3.0 3.0 3.0 } ] [
+    2 dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mcols nth
+] unit-test
+[ dvector{ 3.0 2.0 3.0 4.0 } ] [
+    2 dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mrows nth
+] unit-test
+[ 3 ] [
+    dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mrows length
+] unit-test
+[ 4 ] [
+    dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mcols length
+] unit-test
+[ dvector{ 3.0 3.0 3.0 } ] [
+    2 dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mrows nth
+] unit-test
+[ dvector{ 3.0 2.0 3.0 4.0 } ] [
+    2 dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mcols nth
+] unit-test
+[ 3 ] [
+    dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mcols length
+] unit-test
+[ 4 ] [
+    dmatrix{
+        { 1.0 2.0 3.0 4.0 }
+        { 2.0 2.0 3.0 4.0 }
+        { 3.0 2.0 3.0 4.0 }
+    } Mtranspose Mrows length
+] unit-test
+
+[ cvector{ C{ 3.0 1.0 } C{ 3.0 2.0 } C{ 3.0 3.0 } } ] [
+    2 cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mcols nth
+] unit-test
+[ cvector{ C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } } ] [
+    2 cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mrows nth
+] unit-test
+[ 3 ] [
+    cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mrows length
+] unit-test
+[ 4 ] [
+    cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mcols length
+] unit-test
+[ cvector{ C{ 3.0 1.0 } C{ 3.0 2.0 } C{ 3.0 3.0 } } ] [
+    2 cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mrows nth
+] unit-test
+[ cvector{ C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } } ] [
+    2 cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mcols nth
+] unit-test
+[ 3 ] [
+    cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mcols length
+] unit-test
+[ 4 ] [
+    cmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mrows length
+] unit-test
+
+[ zvector{ C{ 3.0 1.0 } C{ 3.0 2.0 } C{ 3.0 3.0 } } ] [
+    2 zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mcols nth
+] unit-test
+[ zvector{ C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } } ] [
+    2 zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mrows nth
+] unit-test
+[ 3 ] [
+    zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mrows length
+] unit-test
+[ 4 ] [
+    zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mcols length
+] unit-test
+[ zvector{ C{ 3.0 1.0 } C{ 3.0 2.0 } C{ 3.0 3.0 } } ] [
+    2 zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mrows nth
+] unit-test
+[ zvector{ C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } } ] [
+    2 zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mcols nth
+] unit-test
+[ 3 ] [
+    zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mcols length
+] unit-test
+[ 4 ] [
+    zmatrix{
+        { C{ 1.0 1.0 } C{ 2.0 1.0 } C{ 3.0 1.0 } C{ 4.0 1.0 } }
+        { C{ 1.0 2.0 } C{ 2.0 2.0 } C{ 3.0 2.0 } C{ 4.0 2.0 } }
+        { C{ 1.0 3.0 } C{ 2.0 3.0 } C{ 3.0 3.0 } C{ 4.0 3.0 } }
+    } Mtranspose Mrows length
+] unit-test
+
+! Msub
+
+[ smatrix{
+    { 3.0 2.0 1.0 }
+    { 0.0 1.0 0.0 }
+} ] [
+    smatrix{
+        { 0.0 1.0 2.0 3.0 2.0 }
+        { 1.0 0.0 3.0 2.0 1.0 }
+        { 2.0 3.0 0.0 1.0 0.0 }
+    } 1 2 2 3 Msub
+] unit-test
+
+[ smatrix{
+    { 3.0 0.0 }
+    { 2.0 1.0 }
+    { 1.0 0.0 }
+} ] [
+    smatrix{
+        { 0.0 1.0 2.0 3.0 2.0 }
+        { 1.0 0.0 3.0 2.0 1.0 }
+        { 2.0 3.0 0.0 1.0 0.0 }
+    } Mtranspose 2 1 3 2 Msub
+] unit-test
+
+[ dmatrix{
+    { 3.0 2.0 1.0 }
+    { 0.0 1.0 0.0 }
+} ] [
+    dmatrix{
+        { 0.0 1.0 2.0 3.0 2.0 }
+        { 1.0 0.0 3.0 2.0 1.0 }
+        { 2.0 3.0 0.0 1.0 0.0 }
+    } 1 2 2 3 Msub
+] unit-test
+
+[ dmatrix{
+    { 3.0 0.0 }
+    { 2.0 1.0 }
+    { 1.0 0.0 }
+} ] [
+    dmatrix{
+        { 0.0 1.0 2.0 3.0 2.0 }
+        { 1.0 0.0 3.0 2.0 1.0 }
+        { 2.0 3.0 0.0 1.0 0.0 }
+    } Mtranspose 2 1 3 2 Msub
+] unit-test
+
+[ cmatrix{
+    { C{ 3.0 3.0 } 2.0 1.0 }
+    { 0.0          1.0 0.0 }
+} ] [
+    cmatrix{
+        { 0.0 1.0 2.0          3.0 2.0 }
+        { 1.0 0.0 C{ 3.0 3.0 } 2.0 1.0 }
+        { 2.0 3.0 0.0          1.0 0.0 }
+    } 1 2 2 3 Msub
+] unit-test
+
+[ cmatrix{
+    { C{ 3.0 3.0 } 0.0 }
+    { 2.0          1.0 }
+    { 1.0          0.0 }
+} ] [
+    cmatrix{
+        { 0.0 1.0 2.0          3.0 2.0 }
+        { 1.0 0.0 C{ 3.0 3.0 } 2.0 1.0 }
+        { 2.0 3.0 0.0          1.0 0.0 }
+    } Mtranspose 2 1 3 2 Msub
+] unit-test
+
+[ zmatrix{
+    { C{ 3.0 3.0 } 2.0 1.0 }
+    { 0.0          1.0 0.0 }
+} ] [
+    zmatrix{
+        { 0.0 1.0 2.0          3.0 2.0 }
+        { 1.0 0.0 C{ 3.0 3.0 } 2.0 1.0 }
+        { 2.0 3.0 0.0          1.0 0.0 }
+    } 1 2 2 3 Msub
+] unit-test
+
+[ zmatrix{
+    { C{ 3.0 3.0 } 0.0 }
+    { 2.0          1.0 }
+    { 1.0          0.0 }
+} ] [
+    zmatrix{
+        { 0.0 1.0 2.0          3.0 2.0 }
+        { 1.0 0.0 C{ 3.0 3.0 } 2.0 1.0 }
+        { 2.0 3.0 0.0          1.0 0.0 }
+    } Mtranspose 2 1 3 2 Msub
+] unit-test
+
diff --git a/extra/math/blas/matrices/matrices.factor b/extra/math/blas/matrices/matrices.factor
new file mode 100755 (executable)
index 0000000..c07dfca
--- /dev/null
@@ -0,0 +1,306 @@
+USING: accessors alien alien.c-types arrays byte-arrays combinators
+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 ;
+QUALIFIED: syntax
+IN: math.blas.matrices
+
+TUPLE: blas-matrix-base data ld rows cols transpose ;
+TUPLE: float-blas-matrix < blas-matrix-base ;
+TUPLE: double-blas-matrix < blas-matrix-base ;
+TUPLE: float-complex-blas-matrix < blas-matrix-base ;
+TUPLE: double-complex-blas-matrix < blas-matrix-base ;
+
+C: <float-blas-matrix> float-blas-matrix
+C: <double-blas-matrix> double-blas-matrix
+C: <float-complex-blas-matrix> float-complex-blas-matrix
+C: <double-complex-blas-matrix> double-complex-blas-matrix
+
+METHOD: element-type { float-blas-matrix }
+    drop "float" ;
+METHOD: element-type { double-blas-matrix }
+    drop "double" ;
+METHOD: element-type { float-complex-blas-matrix }
+    drop "CBLAS_C" ;
+METHOD: element-type { double-complex-blas-matrix }
+    drop "CBLAS_Z" ;
+
+: Mtransposed? ( matrix -- ? )
+    transpose>> ; inline
+: Mwidth ( matrix -- width )
+    dup Mtransposed? [ rows>> ] [ cols>> ] if ; inline
+: Mheight ( matrix -- height )
+    dup Mtransposed? [ cols>> ] [ rows>> ] if ; inline
+
+<PRIVATE
+
+: (blas-transpose) ( matrix -- integer )
+    transpose>> [ CblasTrans ] [ CblasNoTrans ] if ;
+
+GENERIC: (blas-matrix-like) ( data ld rows cols transpose exemplar -- matrix )
+
+METHOD: (blas-matrix-like) { object object object object object float-blas-matrix }
+    drop <float-blas-matrix> ;
+METHOD: (blas-matrix-like) { object object object object object double-blas-matrix }
+    drop <double-blas-matrix> ;
+METHOD: (blas-matrix-like) { object object object object object float-complex-blas-matrix }
+    drop <float-complex-blas-matrix> ;
+METHOD: (blas-matrix-like) { object object object object object double-complex-blas-matrix }
+    drop <double-complex-blas-matrix> ;
+
+METHOD: (blas-matrix-like) { object object object object object float-blas-vector }
+    drop <float-blas-matrix> ;
+METHOD: (blas-matrix-like) { object object object object object double-blas-vector }
+    drop <double-blas-matrix> ;
+METHOD: (blas-matrix-like) { object object object object object float-complex-blas-vector }
+    drop <float-complex-blas-matrix> ;
+METHOD: (blas-matrix-like) { object object object object object double-complex-blas-vector }
+    drop <double-complex-blas-matrix> ;
+
+METHOD: (blas-vector-like) { object object object float-blas-matrix }
+    drop <float-blas-vector> ;
+METHOD: (blas-vector-like) { object object object double-blas-matrix }
+    drop <double-blas-vector> ;
+METHOD: (blas-vector-like) { object object object float-complex-blas-matrix }
+    drop <float-complex-blas-vector> ;
+METHOD: (blas-vector-like) { object object object double-complex-blas-matrix }
+    drop <double-complex-blas-vector> ;
+
+: (validate-gemv) ( A x y -- )
+    {
+        [ drop [ Mwidth  ] [ length>> ] bi* = ]
+        [ nip  [ Mheight ] [ length>> ] bi* = ]
+    } 3&&
+    [ "Mismatched matrix and vectors in matrix-vector multiplication" throw ] unless ;
+
+:: (prepare-gemv) ( alpha A x beta y >c-arg -- order A-trans m n alpha A-data A-ld x-data x-inc beta y-data y-inc y )
+    A x y (validate-gemv)
+    CblasColMajor
+    A (blas-transpose)
+    A rows>>
+    A cols>>
+    alpha >c-arg call
+    A data>>
+    A ld>>
+    x data>>
+    x inc>>
+    beta >c-arg call
+    y data>>
+    y inc>>
+    y ; inline
+
+: (validate-ger) ( x y A -- )
+    {
+        [ nip  [ length>> ] [ Mheight ] bi* = ]
+        [ nipd [ length>> ] [ Mwidth  ] bi* = ]
+    } 3&&
+    [ "Mismatched vertices and matrix in vector outer product" throw ] unless ;
+
+:: (prepare-ger) ( alpha x y A >c-arg -- order m n alpha x-data x-inc y-data y-inc A-data A-ld A )
+    x y A (validate-ger)
+    CblasColMajor
+    A rows>>
+    A cols>>
+    alpha >c-arg call
+    x data>>
+    x inc>>
+    y data>>
+    y inc>>
+    A data>>
+    A ld>>
+    A f >>transpose ; inline
+
+: (validate-gemm) ( A B C -- )
+    {
+        [ drop [ Mwidth  ] [ Mheight ] bi* = ]
+        [ nip  [ Mheight ] bi@ = ]
+        [ nipd [ Mwidth  ] bi@ = ]
+    } 3&& [ "Mismatched matrices in matrix multiplication" throw ] unless ;
+
+:: (prepare-gemm) ( alpha A B beta C >c-arg -- order A-trans B-trans m n k alpha A-data A-ld B-data B-ld beta C-data C-ld C )
+    A B C (validate-gemm)
+    CblasColMajor
+    A (blas-transpose)
+    B (blas-transpose)
+    C rows>>
+    C cols>>
+    A Mwidth
+    alpha >c-arg call
+    A data>>
+    A ld>>
+    B data>>
+    B ld>>
+    beta >c-arg call
+    C data>>
+    C ld>>
+    C f >>transpose ; inline
+
+: (>matrix) ( arrays >c-array -- c-array ld rows cols transpose )
+    '[ <merged> @ ] [ length dup ] [ first length ] tri f ; inline
+
+PRIVATE>
+
+: >float-blas-matrix ( arrays -- matrix )
+    [ >c-float-array ] (>matrix) <float-blas-matrix> ;
+: >double-blas-matrix ( arrays -- matrix )
+    [ >c-double-array ] (>matrix) <double-blas-matrix> ;
+: >float-complex-blas-matrix ( arrays -- matrix )
+    [ (flatten-complex-sequence) >c-float-array ] (>matrix)
+    <float-complex-blas-matrix> ;
+: >double-complex-blas-matrix ( arrays -- matrix )
+    [ (flatten-complex-sequence) >c-double-array ] (>matrix)
+    <double-complex-blas-matrix> ;
+
+GENERIC: n*M.V+n*V-in-place ( alpha A x beta y -- y=alpha*A.x+b*y )
+GENERIC: n*V(*)V+M-in-place ( alpha x y A -- A=alpha*x(*)y+A )
+GENERIC: n*V(*)Vconj+M-in-place ( alpha x y A -- A=alpha*x(*)yconj+A )
+GENERIC: n*M.M+n*M-in-place ( alpha A B beta C -- C=alpha*A.B+beta*C )
+
+METHOD: n*M.V+n*V-in-place { real float-blas-matrix float-blas-vector real float-blas-vector }
+    [ ] (prepare-gemv) [ cblas_sgemv ] dip ;
+METHOD: n*M.V+n*V-in-place { real double-blas-matrix double-blas-vector real double-blas-vector }
+    [ ] (prepare-gemv) [ cblas_dgemv ] dip ;
+METHOD: n*M.V+n*V-in-place { number float-complex-blas-matrix float-complex-blas-vector number float-complex-blas-vector }
+    [ (>c-complex) ] (prepare-gemv) [ cblas_cgemv ] dip ;
+METHOD: n*M.V+n*V-in-place { number double-complex-blas-matrix double-complex-blas-vector number double-complex-blas-vector }
+    [ (>z-complex) ] (prepare-gemv) [ cblas_zgemv ] dip ;
+
+METHOD: n*V(*)V+M-in-place { real float-blas-vector float-blas-vector float-blas-matrix }
+    [ ] (prepare-ger) [ cblas_sger ] dip ;
+METHOD: n*V(*)V+M-in-place { real double-blas-vector double-blas-vector double-blas-matrix }
+    [ ] (prepare-ger) [ cblas_dger ] dip ;
+METHOD: n*V(*)V+M-in-place { number float-complex-blas-vector float-complex-blas-vector float-complex-blas-matrix }
+    [ (>c-complex) ] (prepare-ger) [ cblas_cgeru ] dip ;
+METHOD: n*V(*)V+M-in-place { number double-complex-blas-vector double-complex-blas-vector double-complex-blas-matrix }
+    [ (>z-complex) ] (prepare-ger) [ cblas_zgeru ] dip ;
+
+METHOD: n*V(*)Vconj+M-in-place { number float-complex-blas-vector float-complex-blas-vector float-complex-blas-matrix }
+    [ (>c-complex) ] (prepare-ger) [ cblas_cgerc ] dip ;
+METHOD: n*V(*)Vconj+M-in-place { number double-complex-blas-vector double-complex-blas-vector double-complex-blas-matrix }
+    [ (>z-complex) ] (prepare-ger) [ cblas_zgerc ] dip ;
+
+METHOD: n*M.M+n*M-in-place { real float-blas-matrix float-blas-matrix real float-blas-matrix }
+    [ ] (prepare-gemm) [ cblas_sgemm ] dip ;
+METHOD: n*M.M+n*M-in-place { real double-blas-matrix double-blas-matrix real double-blas-matrix }
+    [ ] (prepare-gemm) [ cblas_dgemm ] dip ;
+METHOD: n*M.M+n*M-in-place { number float-complex-blas-matrix float-complex-blas-matrix number float-complex-blas-matrix }
+    [ (>c-complex) ] (prepare-gemm) [ cblas_cgemm ] dip ;
+METHOD: n*M.M+n*M-in-place { number double-complex-blas-matrix double-complex-blas-matrix number double-complex-blas-matrix }
+    [ (>z-complex) ] (prepare-gemm) [ cblas_zgemm ] dip ;
+
+! XXX should do a dense clone
+syntax:M: blas-matrix-base clone
+    [ 
+        [
+            { data>> ld>> cols>> element-type } get-slots
+            heap-size * * memory>byte-array
+        ] [ { ld>> rows>> cols>> transpose>> } get-slots ] bi
+    ] keep (blas-matrix-like) ;
+
+! XXX try rounding stride to next 128 bit bound for better vectorizin'
+: <empty-matrix> ( rows cols exemplar -- matrix )
+    [ element-type [ * ] dip <c-array> ]
+    [ 2drop ]
+    [ f swap (blas-matrix-like) ] 3tri ;
+
+: n*M.V+n*V ( alpha A x beta y -- alpha*A.x+b*y )
+    clone n*M.V+n*V-in-place ;
+: n*V(*)V+M ( alpha x y A -- alpha*x(*)y+A )
+    clone n*V(*)V+M-in-place ;
+: n*V(*)Vconj+M ( alpha x y A -- alpha*x(*)yconj+A )
+    clone n*V(*)Vconj+M-in-place ;
+: n*M.M+n*M ( alpha A B beta C -- alpha*A.B+beta*C )
+    clone n*M.M+n*M-in-place ;
+
+: n*M.V ( alpha A x -- alpha*A.x )
+    1.0 2over [ Mheight ] dip <empty-vector>
+    n*M.V+n*V-in-place ; inline
+
+: M.V ( A x -- A.x )
+    1.0 -rot n*M.V ; inline
+
+: n*V(*)V ( n x y -- n*x(*)y )
+    2dup [ length>> ] bi@ pick <empty-matrix>
+    n*V(*)V+M-in-place ;
+: n*V(*)Vconj ( n x y -- n*x(*)yconj )
+    2dup [ length>> ] bi@ pick <empty-matrix>
+    n*V(*)Vconj+M-in-place ;
+
+: V(*) ( x y -- x(*)y )
+    1.0 -rot n*V(*)V ; inline
+: V(*)conj ( x y -- x(*)yconj )
+    1.0 -rot n*V(*)Vconj ; inline
+
+: n*M.M ( n A B -- n*A.B )
+    2dup [ Mheight ] [ Mwidth ] bi* pick <empty-matrix> 
+    1.0 swap n*M.M+n*M-in-place ;
+
+: M. ( A B -- A.B )
+    1.0 -rot n*M.M ; inline
+
+:: (Msub) ( matrix row col height width -- data ld rows cols )
+    matrix ld>> col * row + matrix element-type heap-size *
+    matrix data>> <displaced-alien>
+    matrix ld>>
+    height
+    width ;
+
+: Msub ( matrix row col height width -- submatrix )
+    5 npick dup transpose>>
+    [ nip [ [ swap ] 2dip swap ] when (Msub) ] 2keep
+    swap (blas-matrix-like) ;
+
+TUPLE: blas-matrix-rowcol-sequence parent inc rowcol-length rowcol-jump length ;
+C: <blas-matrix-rowcol-sequence> blas-matrix-rowcol-sequence
+
+INSTANCE: blas-matrix-rowcol-sequence sequence
+
+syntax:M: blas-matrix-rowcol-sequence length
+    length>> ;
+syntax:M: blas-matrix-rowcol-sequence nth-unsafe
+    {
+        [
+            [ rowcol-jump>> ]
+            [ parent>> element-type heap-size ]
+            [ parent>> data>> ] tri
+            [ * * ] dip <displaced-alien>
+        ]
+        [ rowcol-length>> ]
+        [ inc>> ]
+        [ parent>> ]
+    } cleave (blas-vector-like) ;
+
+: (Mcols) ( A -- columns )
+    { [ ] [ drop 1 ] [ rows>> ] [ ld>> ] [ cols>> ] } cleave
+    <blas-matrix-rowcol-sequence> ;
+: (Mrows) ( A -- rows )
+    { [ ] [ ld>> ] [ cols>> ] [ drop 1 ] [ rows>> ] } cleave
+    <blas-matrix-rowcol-sequence> ;
+
+: Mrows ( A -- rows )
+    dup transpose>> [ (Mcols) ] [ (Mrows) ] if ;
+: Mcols ( A -- rows )
+    dup transpose>> [ (Mrows) ] [ (Mcols) ] if ;
+
+: n*M-in-place ( n A -- A=n*A )
+    [ (Mcols) [ n*V-in-place drop ] with each ] keep ;
+
+: n*M ( n A -- n*A )
+    clone n*M-in-place ; inline
+
+: M*n ( A n -- A*n )
+    swap n*M ; inline
+: M/n ( A n -- A/n )
+    recip swap n*M ; inline
+
+: Mtranspose ( matrix -- matrix^T )
+    [ { data>> ld>> rows>> cols>> transpose>> } get-slots not ] keep (blas-matrix-like) ;
+
+syntax:M: blas-matrix-base equal?
+    {
+        [ [ Mwidth ] bi@ = ]
+        [ [ Mcols ] bi@ [ = ] 2all? ]
+    } 2&& ;
+
diff --git a/extra/math/blas/matrices/summary.txt b/extra/math/blas/matrices/summary.txt
new file mode 100644 (file)
index 0000000..4cc5684
--- /dev/null
@@ -0,0 +1 @@
+BLAS level 2 and 3 matrix-vector and matrix-matrix operations
diff --git a/extra/math/blas/matrices/tags.txt b/extra/math/blas/matrices/tags.txt
new file mode 100644 (file)
index 0000000..241ec1e
--- /dev/null
@@ -0,0 +1,2 @@
+math
+bindings
diff --git a/extra/math/blas/syntax/authors.txt b/extra/math/blas/syntax/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/extra/math/blas/syntax/summary.txt b/extra/math/blas/syntax/summary.txt
new file mode 100644 (file)
index 0000000..a71bebb
--- /dev/null
@@ -0,0 +1 @@
+Literal syntax for BLAS vectors and matrices
diff --git a/extra/math/blas/syntax/syntax-docs.factor b/extra/math/blas/syntax/syntax-docs.factor
new file mode 100644 (file)
index 0000000..6b58df7
--- /dev/null
@@ -0,0 +1,78 @@
+USING: help.markup help.syntax math.blas.matrices math.blas.vectors multiline ;
+IN: math.blas.syntax
+
+ARTICLE: "math.blas.syntax" "BLAS interface literal syntax"
+"Vectors:"
+{ $subsection POSTPONE: svector{ }
+{ $subsection POSTPONE: dvector{ }
+{ $subsection POSTPONE: cvector{ }
+{ $subsection POSTPONE: zvector{ }
+"Matrices:"
+{ $subsection POSTPONE: smatrix{ }
+{ $subsection POSTPONE: dmatrix{ }
+{ $subsection POSTPONE: cmatrix{ }
+{ $subsection POSTPONE: zmatrix{ } ;
+
+ABOUT: "math.blas.syntax"
+
+HELP: svector{
+{ $syntax "svector{ 1.0 -2.0 3.0 }" }
+{ $description "Construct a literal " { $link float-blas-vector } "." } ;
+
+HELP: dvector{
+{ $syntax "dvector{ 1.0 -2.0 3.0 }" }
+{ $description "Construct a literal " { $link double-blas-vector } "." } ;
+
+HELP: cvector{
+{ $syntax "cvector{ 1.0 -2.0 C{ 3.0 -1.0 } }" }
+{ $description "Construct a literal " { $link float-complex-blas-vector } "." } ;
+
+HELP: zvector{
+{ $syntax "dvector{ 1.0 -2.0 C{ 3.0 -1.0 } }" }
+{ $description "Construct a literal " { $link double-complex-blas-vector } "." } ;
+
+{
+    POSTPONE: svector{ POSTPONE: dvector{
+    POSTPONE: cvector{ POSTPONE: zvector{
+} related-words
+
+HELP: smatrix{
+{ $syntax <" smatrix{
+    { 1.0 0.0 0.0 1.0 }
+    { 0.0 1.0 0.0 2.0 }
+    { 0.0 0.0 1.0 3.0 }
+    { 0.0 0.0 0.0 1.0 }
+} "> }
+{ $description "Construct a literal " { $link float-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
+
+HELP: dmatrix{
+{ $syntax <" dmatrix{
+    { 1.0 0.0 0.0 1.0 }
+    { 0.0 1.0 0.0 2.0 }
+    { 0.0 0.0 1.0 3.0 }
+    { 0.0 0.0 0.0 1.0 }
+} "> }
+{ $description "Construct a literal " { $link double-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
+
+HELP: cmatrix{
+{ $syntax <" cmatrix{
+    { 1.0 0.0           0.0 1.0           }
+    { 0.0 C{ 0.0 1.0 }  0.0 2.0           }
+    { 0.0 0.0          -1.0 3.0           }
+    { 0.0 0.0           0.0 C{ 0.0 -1.0 } }
+} "> }
+{ $description "Construct a literal " { $link float-complex-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
+
+HELP: zmatrix{
+{ $syntax <" zmatrix{
+    { 1.0 0.0           0.0 1.0           }
+    { 0.0 C{ 0.0 1.0 }  0.0 2.0           }
+    { 0.0 0.0          -1.0 3.0           }
+    { 0.0 0.0           0.0 C{ 0.0 -1.0 } }
+} "> }
+{ $description "Construct a literal " { $link double-complex-blas-matrix } ". Note that although BLAS matrices are stored in column-major order, the literal is specified in row-major order." } ;
+
+{
+    POSTPONE: smatrix{ POSTPONE: dmatrix{
+    POSTPONE: cmatrix{ POSTPONE: zmatrix{
+} related-words
diff --git a/extra/math/blas/syntax/syntax.factor b/extra/math/blas/syntax/syntax.factor
new file mode 100644 (file)
index 0000000..895e6f3
--- /dev/null
@@ -0,0 +1,20 @@
+USING: kernel math.blas.matrices math.blas.vectors parser ;
+IN: math.blas.syntax
+
+: svector{ ( accum -- accum )
+    \ } [ >float-blas-vector ] parse-literal ; parsing
+: dvector{ ( accum -- accum )
+    \ } [ >double-blas-vector ] parse-literal ; parsing
+: cvector{ ( accum -- accum )
+    \ } [ >float-complex-blas-vector ] parse-literal ; parsing
+: zvector{ ( accum -- accum )
+    \ } [ >double-complex-blas-vector ] parse-literal ; parsing
+
+: smatrix{ ( accum -- accum )
+    \ } [ >float-blas-matrix ] parse-literal ; parsing
+: dmatrix{ ( accum -- accum )
+    \ } [ >double-blas-matrix ] parse-literal ; parsing
+: cmatrix{ ( accum -- accum )
+    \ } [ >float-complex-blas-matrix ] parse-literal ; parsing
+: zmatrix{ ( accum -- accum )
+    \ } [ >double-complex-blas-matrix ] parse-literal ; parsing
diff --git a/extra/math/blas/syntax/tags.txt b/extra/math/blas/syntax/tags.txt
new file mode 100644 (file)
index 0000000..ede10ab
--- /dev/null
@@ -0,0 +1 @@
+math
diff --git a/extra/math/blas/vectors/authors.txt b/extra/math/blas/vectors/authors.txt
new file mode 100644 (file)
index 0000000..f13c9c1
--- /dev/null
@@ -0,0 +1 @@
+Joe Groff
diff --git a/extra/math/blas/vectors/summary.txt b/extra/math/blas/vectors/summary.txt
new file mode 100644 (file)
index 0000000..f983e85
--- /dev/null
@@ -0,0 +1 @@
+BLAS level 1 vector operations
diff --git a/extra/math/blas/vectors/tags.txt b/extra/math/blas/vectors/tags.txt
new file mode 100644 (file)
index 0000000..ede10ab
--- /dev/null
@@ -0,0 +1 @@
+math
diff --git a/extra/math/blas/vectors/vectors-docs.factor b/extra/math/blas/vectors/vectors-docs.factor
new file mode 100644 (file)
index 0000000..4fad9c7
--- /dev/null
@@ -0,0 +1,131 @@
+USING: alien byte-arrays help.markup help.syntax sequences ;
+IN: math.blas.vectors
+
+ARTICLE: "math.blas.vectors" "BLAS interface vector operations"
+"Slicing vectors:"
+{ $subsection Vsub }
+"Taking the norm (magnitude) of a vector:"
+{ $subsection Vnorm }
+"Summing and taking the maximum of elements:"
+{ $subsection Vasum }
+{ $subsection Viamax }
+{ $subsection Vamax }
+"Scalar-vector products:"
+{ $subsection n*V-in-place }
+{ $subsection n*V }
+{ $subsection V*n }
+{ $subsection V/n }
+{ $subsection Vneg }
+"Vector addition:" 
+{ $subsection n*V+V-in-place }
+{ $subsection n*V+V }
+{ $subsection V+ }
+{ $subsection V- }
+"Vector inner products:"
+{ $subsection V. }
+{ $subsection V.conj } ;
+
+ABOUT: "math.blas.vectors"
+
+HELP: blas-vector-base
+{ $class-description "The base class for all BLAS vector types. Objects of this type should not be created directly; instead, instantiate one of the typed subclasses:"
+{ $list
+    { { $link float-blas-vector } }
+    { { $link double-blas-vector } }
+    { { $link float-complex-blas-vector } }
+    { { $link double-complex-blas-vector } }
+}
+"All of these subclasses share the same tuple layout:"
+{ $list
+    { { $snippet "data" } " contains an alien pointer referencing or byte-array containing a packed array of float, double, float complex, or double complex values;" }
+    { { $snippet "length" } " indicates the length of the vector;" }
+    { "and " { $snippet "inc" } " indicates the distance, in elements, between elements." }
+} } ;
+
+HELP: float-blas-vector
+{ $class-description "A vector of single-precision floating-point values. For details on the tuple layout, see " { $link blas-vector-base } "." } ;
+HELP: double-blas-vector
+{ $class-description "A vector of double-precision floating-point values. For details on the tuple layout, see " { $link blas-vector-base } "." } ;
+HELP: float-complex-blas-vector
+{ $class-description "A vector of single-precision floating-point complex values. Complex values are stored in memory as two consecutive float values, real part then imaginary part. For details on the tuple layout, see " { $link blas-vector-base } "." } ;
+HELP: double-complex-blas-vector
+{ $class-description "A vector of single-precision floating-point complex values. Complex values are stored in memory as two consecutive float values, real part then imaginary part. For details on the tuple layout, see " { $link blas-vector-base } "." } ;
+
+HELP: n*V+V-in-place
+{ $values { "alpha" "a number" } { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the vector sum " { $snippet "αx + y" } " and replace the existing contents of y with the result. Corresponds to the xAXPY routines in BLAS." }
+{ $side-effects "y" } ;
+
+HELP: n*V-in-place
+{ $values { "alpha" "a number" } { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the scalar-vector product " { $snippet "αx" } " and replace the existing contents of x with the result. Corresponds to the xSCAL routines in BLAS." }
+{ $side-effects "x" } ;
+
+HELP: V.
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the inner product " { $snippet "x⋅y" } ". Corresponds to the xDOT and xDOTU routines in BLAS." } ;
+
+HELP: V.conj
+{ $values { "x" "a complex BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a complex BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the conjugate inner product " { $snippet "x̅⋅y" } ". Corresponds to the xDOTC routines in BLAS." } ;
+
+HELP: Vnorm
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the norm-2, i.e., the magnitude or absolute value, of " { $snippet "x" } " (" { $snippet "‖x‖₂" } "). Corresponds to the xNRM2 routines in BLAS." } ;
+
+HELP: Vasum
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the sum of the norm-1s of the elements of " { $snippet "x" } " (" { $snippet "Σ ‖xᵢ‖₁" } "). Corresponds to the xASUM routines in BLAS." } ;
+
+HELP: Vswap
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Swap the contents of " { $snippet "x" } " and " { $snippet "y" } " in place. Corresponds to the xSWAP routines in BLAS." }
+{ $side-effects "x" "y" } ;
+
+HELP: Viamax
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Return the index of the element in " { $snippet "x" } " with the largest norm-1. If more than one element has the same norm-1, returns the smallest index. Corresponds to the IxAMAX routines in BLAS." } ;
+
+HELP: Vamax
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Return the value of the element in " { $snippet "x" } " with the largest norm-1. If more than one element has the same norm-1, returns the first element. Corresponds to the IxAMAX routines in BLAS." } ;
+
+{ Viamax Vamax } related-words
+
+HELP: <zero-vector>
+{ $values { "exemplar" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Return a vector of zeros with the same length and element type as " { $snippet "v" } ". The vector is constructed with an " { $snippet "inc" } " of zero, so it is not suitable for receiving results from BLAS functions; it is intended to be used as a term in other vector calculations. To construct an empty vector that can be used to receive results, see " { $link <empty-vector> } "." } ;
+
+HELP: n*V+V
+{ $values { "alpha" "a number" } { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the vector sum " { $snippet "αx + y" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result. Corresponds to the xAXPY routines in BLAS." } ;
+
+HELP: n*V
+{ $values { "alpha" "a number" } { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the scalar-vector product " { $snippet "αx" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result. Corresponds to the xSCAL routines in BLAS." } ;
+
+HELP: V+
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the vector sum " { $snippet "x + y" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result. Corresponds to the xAXPY routines in BLAS." } ;
+
+HELP: V-
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Calculate the vector difference " { $snippet "x – y" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result. Corresponds to the xAXPY routines in BLAS." } ;
+
+HELP: Vneg
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "y" "a BLAS vector inheriting from " { $link blas-vector-base } } }
+{ $description "Negate the elements of " { $snippet "x" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " and " { $snippet "y" } " containing the result." } ;
+
+HELP: V*n
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "alpha" "a number" } }
+{ $description "Calculate the scalar-vector product " { $snippet "αx" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result. Corresponds to the xSCAL routines in BLAS." } ;
+
+HELP: V/n
+{ $values { "x" "a BLAS vector inheriting from " { $link blas-vector-base } } { "alpha" "a number" } }
+{ $description "Calculate the scalar-vector product " { $snippet "(1/α)x" } " and return a freshly-allocated vector with the same length as " { $snippet "x" } " containing the result. Corresponds to the xSCAL routines in BLAS." } ;
+
+{ n*V+V-in-place n*V-in-place n*V+V n*V V+ V- Vneg V*n V/n } related-words
+
+HELP: Vsub
+{ $values { "v" "a BLAS vector inheriting from " { $link blas-vector-base } } { "start" "The index of the first element of the slice" } { "length" "The length of the slice" } }
+{ $description "Slice a subvector out of " { $snippet "v" } " with the given length. The subvector will share storage with the parent vector." } ;
diff --git a/extra/math/blas/vectors/vectors-tests.factor b/extra/math/blas/vectors/vectors-tests.factor
new file mode 100644 (file)
index 0000000..d4cff82
--- /dev/null
@@ -0,0 +1,180 @@
+USING: kernel math.blas.vectors math.blas.syntax sequences tools.test ;
+IN: math.blas.vectors.tests
+
+! clone
+
+[ svector{ 1.0 2.0 3.0 } ] [ svector{ 1.0 2.0 3.0 } clone ] unit-test
+[ f ] [ svector{ 1.0 2.0 3.0 } dup clone eq? ] unit-test
+[ dvector{ 1.0 2.0 3.0 } ] [ dvector{ 1.0 2.0 3.0 } clone ] unit-test
+[ f ] [ dvector{ 1.0 2.0 3.0 } dup clone eq? ] unit-test
+[ cvector{ 1.0 C{ 2.0 3.0 } 4.0 } ] [ cvector{ 1.0 C{ 2.0 3.0 } 4.0 } clone ] unit-test
+[ f ] [ cvector{ 1.0 C{ 2.0 3.0 } 4.0 } dup clone eq? ] unit-test
+[ zvector{ 1.0 C{ 2.0 3.0 } 4.0 } ] [ zvector{ 1.0 C{ 2.0 3.0 } 4.0 } clone ] unit-test
+[ f ] [ zvector{ 1.0 C{ 2.0 3.0 } 4.0 } dup clone eq? ] unit-test
+
+! nth
+
+[ 1.0 ] [ 2 svector{ 3.0 2.0 1.0 } nth ] unit-test
+[ 1.0 ] [ 2 dvector{ 3.0 2.0 1.0 } nth ] unit-test
+
+[ C{ 1.0 2.0 } ]
+[ 2 cvector{ C{ -3.0 -2.0 } C{ -1.0 0.0 } C{ 1.0 2.0 } } nth ] unit-test
+
+[ C{ 1.0 2.0 } ]
+[ 2 zvector{ C{ -3.0 -2.0 } C{ -1.0 0.0 } C{ 1.0 2.0 } } nth ] unit-test
+
+! set-nth
+
+[ svector{ 3.0 2.0 0.0 } ] [ 0.0 2 svector{ 3.0 2.0 1.0 } [ set-nth ] keep ] unit-test
+[ dvector{ 3.0 2.0 0.0 } ] [ 0.0 2 dvector{ 3.0 2.0 1.0 } [ set-nth ] keep ] unit-test
+
+[ cvector{ C{ -3.0 -2.0 } C{ -1.0 0.0 } C{ 3.0 4.0 } } ] [
+    C{ 3.0 4.0 } 2
+    cvector{ C{ -3.0 -2.0 } C{ -1.0 0.0 } C{ 1.0 2.0 } }
+    [ set-nth ] keep
+] unit-test
+[ zvector{ C{ -3.0 -2.0 } C{ -1.0 0.0 } C{ 3.0 4.0 } } ] [
+    C{ 3.0 4.0 } 2
+    zvector{ C{ -3.0 -2.0 } C{ -1.0 0.0 } C{ 1.0 2.0 } }
+    [ set-nth ] keep
+] unit-test
+
+! V+
+
+[ svector{ 11.0 22.0 } ] [ svector{ 1.0 2.0 } svector{ 10.0 20.0 } V+ ] unit-test
+[ dvector{ 11.0 22.0 } ] [ dvector{ 1.0 2.0 } dvector{ 10.0 20.0 } V+ ] unit-test
+
+[ cvector{ 11.0 C{ 22.0 33.0 } } ]
+[ cvector{ 1.0 C{ 2.0 3.0 } } cvector{ 10.0 C{ 20.0 30.0 } } V+ ]
+unit-test
+
+[ zvector{ 11.0 C{ 22.0 33.0 } } ]
+[ zvector{ 1.0 C{ 2.0 3.0 } } zvector{ 10.0 C{ 20.0 30.0 } } V+ ]
+unit-test
+
+! V-
+
+[ svector{ 9.0 18.0 } ] [ svector{ 10.0 20.0 } svector{ 1.0 2.0 } V- ] unit-test
+[ dvector{ 9.0 18.0 } ] [ dvector{ 10.0 20.0 } dvector{ 1.0 2.0 } V- ] unit-test
+
+[ cvector{ 9.0 C{ 18.0 27.0 } } ]
+[ cvector{ 10.0 C{ 20.0 30.0 } } cvector{ 1.0 C{ 2.0 3.0 } } V- ]
+unit-test
+
+[ zvector{ 9.0 C{ 18.0 27.0 } } ]
+[ zvector{ 10.0 C{ 20.0 30.0 } } zvector{ 1.0 C{ 2.0 3.0 } } V- ]
+unit-test
+
+! Vneg
+
+[ svector{ 1.0 -2.0 } ] [ svector{ -1.0 2.0 } Vneg ] unit-test
+[ dvector{ 1.0 -2.0 } ] [ dvector{ -1.0 2.0 } Vneg ] unit-test
+
+[ cvector{ 1.0 C{ -2.0 3.0 } } ] [ cvector{ -1.0 C{ 2.0 -3.0 } } Vneg ] unit-test
+[ zvector{ 1.0 C{ -2.0 3.0 } } ] [ zvector{ -1.0 C{ 2.0 -3.0 } } Vneg ] unit-test
+
+! n*V
+
+[ svector{ 100.0 200.0 } ] [ 10.0 svector{ 10.0 20.0 } n*V ] unit-test
+[ dvector{ 100.0 200.0 } ] [ 10.0 dvector{ 10.0 20.0 } n*V ] unit-test
+
+[ cvector{ C{ 20.0 4.0 } C{ 8.0 12.0 } } ]
+[ C{ 10.0 2.0 } cvector{ 2.0 C{ 1.0 1.0 } } n*V ]
+unit-test
+
+[ zvector{ C{ 20.0 4.0 } C{ 8.0 12.0 } } ]
+[ C{ 10.0 2.0 } zvector{ 2.0 C{ 1.0 1.0 } } n*V ]
+unit-test
+
+! V*n
+
+[ svector{ 100.0 200.0 } ] [ svector{ 10.0 20.0 } 10.0 V*n ] unit-test
+[ dvector{ 100.0 200.0 } ] [ dvector{ 10.0 20.0 } 10.0 V*n ] unit-test
+
+[ cvector{ C{ 20.0 4.0 } C{ 8.0 12.0 } } ]
+[ cvector{ 2.0 C{ 1.0 1.0 } } C{ 10.0 2.0 } V*n ]
+unit-test
+
+[ zvector{ C{ 20.0 4.0 } C{ 8.0 12.0 } } ]
+[ zvector{ 2.0 C{ 1.0 1.0 } } C{ 10.0 2.0 } V*n ]
+unit-test
+
+! V/n
+
+[ svector{ 1.0 2.0 } ] [ svector{ 4.0 8.0 } 4.0 V/n ] unit-test
+[ dvector{ 1.0 2.0 } ] [ dvector{ 4.0 8.0 } 4.0 V/n ] unit-test
+
+[ cvector{ 2.0 1.0 } ]
+[ cvector{ C{ 16.0 4.0 } C{ 8.0 2.0 } } C{ 8.0 2.0 } V/n ]
+unit-test
+
+[ cvector{ 2.0 1.0 } ]
+[ cvector{ C{ 16.0 4.0 } C{ 8.0 2.0 } } C{ 8.0 2.0 } V/n ]
+unit-test
+
+! V.
+
+[ 7.0 ] [ svector{ 1.0 2.5 } svector{ 2.0 2.0 } V. ] unit-test
+[ 7.0 ] [ dvector{ 1.0 2.5 } dvector{ 2.0 2.0 } V. ] unit-test
+[ C{ 7.0 7.0 } ] [ cvector{ C{ 1.0 1.0 } 2.5 } cvector{ 2.0 C{ 2.0 2.0 } } V. ] unit-test
+[ C{ 7.0 7.0 } ] [ zvector{ C{ 1.0 1.0 } 2.5 } zvector{ 2.0 C{ 2.0 2.0 } } V. ] unit-test
+
+! V.conj
+
+[ C{ 7.0 3.0 } ] [ cvector{ C{ 1.0 1.0 } 2.5 } cvector{ 2.0 C{ 2.0 2.0 } } V.conj ] unit-test
+[ C{ 7.0 3.0 } ] [ zvector{ C{ 1.0 1.0 } 2.5 } zvector{ 2.0 C{ 2.0 2.0 } } V.conj ] unit-test
+
+! Vnorm
+
+[ 5.0 ] [ svector{ 3.0 4.0 } Vnorm ] unit-test
+[ 5.0 ] [ dvector{ 3.0 4.0 } Vnorm ] unit-test
+
+[ 13.0 ] [ cvector{ C{ 3.0 4.0 } 12.0 } Vnorm ] unit-test
+[ 13.0 ] [ zvector{ C{ 3.0 4.0 } 12.0 } Vnorm ] unit-test
+
+! Vasum
+
+[ 6.0 ] [ svector{ 1.0 2.0 -3.0 } Vasum ] unit-test
+[ 6.0 ] [ dvector{ 1.0 2.0 -3.0 } Vasum ] unit-test
+
+[ 15.0 ] [ cvector{ 1.0 C{ -2.0 3.0 } C{ 4.0 -5.0 } } Vasum ] unit-test
+[ 15.0 ] [ zvector{ 1.0 C{ -2.0 3.0 } C{ 4.0 -5.0 } } Vasum ] unit-test
+
+! Vswap
+
+[ svector{ 2.0 2.0 } svector{ 1.0 1.0 } ]
+[ svector{ 1.0 1.0 } svector{ 2.0 2.0 } Vswap ]
+unit-test
+
+[ dvector{ 2.0 2.0 } dvector{ 1.0 1.0 } ]
+[ dvector{ 1.0 1.0 } dvector{ 2.0 2.0 } Vswap ]
+unit-test
+
+[ cvector{ 2.0 C{ 2.0 2.0 } } cvector{ C{ 1.0 1.0 } 1.0 } ]
+[ cvector{ C{ 1.0 1.0 } 1.0 } cvector{ 2.0 C{ 2.0 2.0 } } Vswap ]
+unit-test
+
+[ zvector{ 2.0 C{ 2.0 2.0 } } zvector{ C{ 1.0 1.0 } 1.0 } ]
+[ zvector{ C{ 1.0 1.0 } 1.0 } zvector{ 2.0 C{ 2.0 2.0 } } Vswap ]
+unit-test
+
+! Viamax
+
+[ 3 ] [ svector{ 1.0 -5.0 4.0 -6.0 -1.0 } Viamax ] unit-test
+[ 3 ] [ dvector{ 1.0 -5.0 4.0 -6.0 -1.0 } Viamax ] unit-test
+[ 0 ] [ cvector{ C{ 2.0 -5.0 } 4.0 -6.0 -1.0 } Viamax ] unit-test
+[ 0 ] [ zvector{ C{ 2.0 -5.0 } 4.0 -6.0 -1.0 } Viamax ] unit-test
+
+! Vamax
+
+[ -6.0 ] [ svector{ 1.0 -5.0 4.0 -6.0 -1.0 } Vamax ] unit-test
+[ -6.0 ] [ dvector{ 1.0 -5.0 4.0 -6.0 -1.0 } Vamax ] unit-test
+[ C{ 2.0 -5.0 } ] [ cvector{ C{ 2.0 -5.0 } 4.0 -6.0 -1.0 } Vamax ] unit-test
+[ C{ 2.0 -5.0 } ] [ zvector{ C{ 2.0 -5.0 } 4.0 -6.0 -1.0 } Vamax ] unit-test
+
+! Vsub
+
+[ svector{ -5.0 4.0 -6.0 } ] [ svector{ 1.0 -5.0 4.0 -6.0 -1.0 } 1 3 Vsub ] unit-test
+[ dvector{ -5.0 4.0 -6.0 } ] [ dvector{ 1.0 -5.0 4.0 -6.0 -1.0 } 1 3 Vsub ] unit-test
+[ cvector{ -5.0 C{ 4.0 3.0 } -6.0 } ] [ cvector{ 1.0 -5.0 C{ 4.0 3.0 } -6.0 -1.0 } 1 3 Vsub ] unit-test
+[ zvector{ -5.0 C{ 4.0 3.0 } -6.0 } ] [ zvector{ 1.0 -5.0 C{ 4.0 3.0 } -6.0 -1.0 } 1 3 Vsub ] unit-test
diff --git a/extra/math/blas/vectors/vectors.factor b/extra/math/blas/vectors/vectors.factor
new file mode 100755 (executable)
index 0000000..18370f1
--- /dev/null
@@ -0,0 +1,297 @@
+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 ;
+QUALIFIED: syntax
+IN: math.blas.vectors
+
+TUPLE: blas-vector-base data length inc ;
+TUPLE: float-blas-vector < blas-vector-base ;
+TUPLE: double-blas-vector < blas-vector-base ;
+TUPLE: float-complex-blas-vector < blas-vector-base ;
+TUPLE: double-complex-blas-vector < blas-vector-base ;
+
+INSTANCE: float-blas-vector sequence
+INSTANCE: double-blas-vector sequence
+INSTANCE: float-complex-blas-vector sequence
+INSTANCE: double-complex-blas-vector sequence
+
+C: <float-blas-vector> float-blas-vector
+C: <double-blas-vector> double-blas-vector
+C: <float-complex-blas-vector> float-complex-blas-vector
+C: <double-complex-blas-vector> double-complex-blas-vector
+
+GENERIC: n*V+V-in-place ( alpha x y -- y=alpha*x+y )
+GENERIC: n*V-in-place   ( alpha x -- x=alpha*x )
+
+GENERIC: V. ( x y -- x.y )
+GENERIC: V.conj ( x y -- xconj.y )
+GENERIC: Vnorm ( x -- norm )
+GENERIC: Vasum ( x -- sum )
+GENERIC: Vswap ( x y -- x=y y=x )
+
+GENERIC: Viamax ( x -- max-i )
+
+GENERIC: element-type ( v -- type )
+
+METHOD: element-type { float-blas-vector }
+    drop "float" ;
+METHOD: element-type { double-blas-vector }
+    drop "double" ;
+METHOD: element-type { float-complex-blas-vector }
+    drop "CBLAS_C" ;
+METHOD: element-type { double-complex-blas-vector }
+    drop "CBLAS_Z" ;
+
+<PRIVATE
+
+GENERIC: (blas-vector-like) ( data length inc exemplar -- vector )
+
+METHOD: (blas-vector-like) { object object object float-blas-vector }
+    drop <float-blas-vector> ;
+METHOD: (blas-vector-like) { object object object double-blas-vector }
+    drop <double-blas-vector> ;
+METHOD: (blas-vector-like) { object object object float-complex-blas-vector }
+    drop <float-complex-blas-vector> ;
+METHOD: (blas-vector-like) { object object object double-complex-blas-vector }
+    drop <double-complex-blas-vector> ;
+
+: (prepare-copy) ( v element-size -- length v-data v-inc v-dest-data v-dest-inc )
+    [ [ length>> ] [ data>> ] [ inc>> ] tri ] dip
+    4 npick * <byte-array>
+    1 ;
+
+MACRO: (do-copy) ( copy make-vector -- )
+    '[ over 6 npick , 2dip 1 @ ] ;
+
+: (prepare-swap) ( v1 v2 -- length v1-data v1-inc v2-data v2-inc v1 v2 )
+    [
+        [ [ length>> ] bi@ min ]
+        [ [ [ data>> ] [ inc>> ] bi ] bi@ ] 2bi
+    ] 2keep ;
+
+: (prepare-axpy) ( n v1 v2 -- length n v1-data v1-inc v2-data v2-inc v2 )
+    [
+        [ [ length>> ] bi@ min swap ]
+        [ [ [ data>> ] [ inc>> ] bi ] bi@ ] 2bi
+    ] keep ;
+
+: (prepare-scal) ( n v -- length n v-data v-inc v )
+    [ [ length>> swap ] [ data>> ] [ inc>> ] tri ] keep ;
+
+: (prepare-dot) ( v1 v2 -- length v1-data v1-inc v2-data v2-inc )
+    [ [ length>> ] bi@ min ]
+    [ [ [ data>> ] [ inc>> ] bi ] bi@ ] 2bi ;
+
+: (prepare-nrm2) ( v -- length v1-data v1-inc )
+    [ length>> ] [ data>> ] [ inc>> ] tri ;
+
+: (flatten-complex-sequence) ( seq -- seq' )
+    [ [ real-part ] [ imaginary-part ] bi 2array ] map concat ;
+
+: (>c-complex) ( complex -- alien )
+    [ real-part ] [ imaginary-part ] bi 2array >c-float-array ;
+: (>z-complex) ( complex -- alien )
+    [ real-part ] [ imaginary-part ] bi 2array >c-double-array ;
+
+: (c-complex>) ( alien -- complex )
+    2 c-float-array> first2 rect> ;
+: (z-complex>) ( alien -- complex )
+    2 c-double-array> first2 rect> ;
+
+: (prepare-nth) ( n v -- n*inc v-data )
+    [ inc>> ] [ data>> ] bi [ * ] dip ;
+
+MACRO: (complex-nth) ( nth-quot -- )
+    '[ 
+        [ 2 * dup 1+ ] dip
+        , curry bi@ rect>
+    ] ;
+
+: (c-complex-nth) ( n alien -- complex )
+    [ float-nth ] (complex-nth) ;
+: (z-complex-nth) ( n alien -- complex )
+    [ double-nth ] (complex-nth) ;
+
+MACRO: (set-complex-nth) ( set-nth-quot -- )
+    '[
+        [
+            [ [ real-part ] [ imaginary-part ] bi ]
+            [ 2 * dup 1+ ] bi*
+            swapd
+        ] dip
+        , curry 2bi@ 
+    ] ;
+
+: (set-c-complex-nth) ( complex n alien -- )
+    [ set-float-nth ] (set-complex-nth) ;
+: (set-z-complex-nth) ( complex n alien -- )
+    [ set-double-nth ] (set-complex-nth) ;
+
+PRIVATE>
+
+: <zero-vector> ( exemplar -- zero )
+    [ element-type <c-object> ]
+    [ length>> 0 ]
+    [ (blas-vector-like) ] tri ;
+
+: <empty-vector> ( length exemplar -- vector )
+    [ element-type <c-array> ]
+    [ 1 swap ] 2bi
+    (blas-vector-like) ;
+
+syntax:M: blas-vector-base length
+    length>> ;
+
+syntax:M: float-blas-vector nth-unsafe
+    (prepare-nth) float-nth ;
+syntax:M: float-blas-vector set-nth-unsafe
+    (prepare-nth) set-float-nth ;
+
+syntax:M: double-blas-vector nth-unsafe
+    (prepare-nth) double-nth ;
+syntax:M: double-blas-vector set-nth-unsafe
+    (prepare-nth) set-double-nth ;
+
+syntax:M: float-complex-blas-vector nth-unsafe
+    (prepare-nth) (c-complex-nth) ;
+syntax:M: float-complex-blas-vector set-nth-unsafe
+    (prepare-nth) (set-c-complex-nth) ;
+
+syntax:M: double-complex-blas-vector nth-unsafe
+    (prepare-nth) (z-complex-nth) ;
+syntax:M: double-complex-blas-vector set-nth-unsafe
+    (prepare-nth) (set-z-complex-nth) ;
+
+syntax:M: blas-vector-base equal?
+    {
+        [ [ length ] bi@ = ]
+        [ [ = ] 2all? ]
+    } 2&& ;
+
+: >float-blas-vector ( seq -- v )
+    [ >c-float-array ] [ length ] bi 1 <float-blas-vector> ;
+: >double-blas-vector ( seq -- v )
+    [ >c-double-array ] [ length ] bi 1 <double-blas-vector> ;
+: >float-complex-blas-vector ( seq -- v )
+    [ (flatten-complex-sequence) >c-float-array ] [ length ] bi
+    1 <float-complex-blas-vector> ;
+: >double-complex-blas-vector ( seq -- v )
+    [ (flatten-complex-sequence) >c-double-array ] [ length ] bi
+    1 <double-complex-blas-vector> ;
+
+syntax:M: float-blas-vector clone
+    "float" heap-size (prepare-copy)
+    [ cblas_scopy ] [ <float-blas-vector> ] (do-copy) ;
+syntax:M: double-blas-vector clone
+    "double" heap-size (prepare-copy)
+    [ cblas_dcopy ] [ <double-blas-vector> ] (do-copy) ;
+syntax:M: float-complex-blas-vector clone
+    "CBLAS_C" heap-size (prepare-copy)
+    [ cblas_ccopy ] [ <float-complex-blas-vector> ] (do-copy) ;
+syntax:M: double-complex-blas-vector clone
+    "CBLAS_Z" heap-size (prepare-copy)
+    [ cblas_zcopy ] [ <double-complex-blas-vector> ] (do-copy) ;
+
+METHOD: Vswap { float-blas-vector float-blas-vector }
+    (prepare-swap) [ cblas_sswap ] 2dip ;
+METHOD: Vswap { double-blas-vector double-blas-vector }
+    (prepare-swap) [ cblas_dswap ] 2dip ;
+METHOD: Vswap { float-complex-blas-vector float-complex-blas-vector }
+    (prepare-swap) [ cblas_cswap ] 2dip ;
+METHOD: Vswap { double-complex-blas-vector double-complex-blas-vector }
+    (prepare-swap) [ cblas_zswap ] 2dip ;
+
+METHOD: n*V+V-in-place { real float-blas-vector float-blas-vector }
+    (prepare-axpy) [ cblas_saxpy ] dip ;
+METHOD: n*V+V-in-place { real double-blas-vector double-blas-vector }
+    (prepare-axpy) [ cblas_daxpy ] dip ;
+METHOD: n*V+V-in-place { number float-complex-blas-vector float-complex-blas-vector }
+    [ (>c-complex) ] 2dip
+    (prepare-axpy) [ cblas_caxpy ] dip ;
+METHOD: n*V+V-in-place { number double-complex-blas-vector double-complex-blas-vector }
+    [ (>z-complex) ] 2dip
+    (prepare-axpy) [ cblas_zaxpy ] dip ;
+
+METHOD: n*V-in-place { real float-blas-vector }
+    (prepare-scal) [ cblas_sscal ] dip ;
+METHOD: n*V-in-place { real double-blas-vector }
+    (prepare-scal) [ cblas_dscal ] dip ;
+METHOD: n*V-in-place { number float-complex-blas-vector }
+    [ (>c-complex) ] dip
+    (prepare-scal) [ cblas_cscal ] dip ;
+METHOD: n*V-in-place { number double-complex-blas-vector }
+    [ (>z-complex) ] dip
+    (prepare-scal) [ cblas_zscal ] dip ;
+
+: n*V+V ( alpha x y -- alpha*x+y ) clone n*V+V-in-place ; inline
+: n*V ( alpha x -- alpha*x ) clone n*V-in-place ; inline
+
+: V+ ( x y -- x+y )
+    1.0 -rot n*V+V ; inline
+: V- ( x y -- x-y )
+    -1.0 spin n*V+V ; inline
+
+: Vneg ( x -- -x )
+    -1.0 swap n*V ; inline
+
+: V*n ( x alpha -- x*alpha )
+    swap n*V ; inline
+: V/n ( x alpha -- x/alpha )
+    recip swap n*V ; inline
+
+METHOD: V. { float-blas-vector float-blas-vector }
+    (prepare-dot) cblas_sdot ;
+METHOD: V. { double-blas-vector double-blas-vector }
+    (prepare-dot) cblas_ddot ;
+METHOD: V. { float-complex-blas-vector float-complex-blas-vector }
+    (prepare-dot)
+    "CBLAS_C" <c-object> [ cblas_cdotu_sub ] keep (c-complex>) ;
+METHOD: V. { double-complex-blas-vector double-complex-blas-vector }
+    (prepare-dot)
+    "CBLAS_Z" <c-object> [ cblas_zdotu_sub ] keep (z-complex>) ;
+
+METHOD: V.conj { float-complex-blas-vector float-complex-blas-vector }
+    (prepare-dot)
+    "CBLAS_C" <c-object> [ cblas_cdotc_sub ] keep (c-complex>) ;
+METHOD: V.conj { double-complex-blas-vector double-complex-blas-vector }
+    (prepare-dot)
+    "CBLAS_Z" <c-object> [ cblas_zdotc_sub ] keep (z-complex>) ;
+
+METHOD: Vnorm { float-blas-vector }
+    (prepare-nrm2) cblas_snrm2 ;
+METHOD: Vnorm { double-blas-vector }
+    (prepare-nrm2) cblas_dnrm2 ;
+METHOD: Vnorm { float-complex-blas-vector }
+    (prepare-nrm2) cblas_scnrm2 ;
+METHOD: Vnorm { double-complex-blas-vector }
+    (prepare-nrm2) cblas_dznrm2 ;
+
+METHOD: Vasum { float-blas-vector }
+    (prepare-nrm2) cblas_sasum ;
+METHOD: Vasum { double-blas-vector }
+    (prepare-nrm2) cblas_dasum ;
+METHOD: Vasum { float-complex-blas-vector }
+    (prepare-nrm2) cblas_scasum ;
+METHOD: Vasum { double-complex-blas-vector }
+    (prepare-nrm2) cblas_dzasum ;
+
+METHOD: Viamax { float-blas-vector }
+    (prepare-nrm2) cblas_isamax ;
+METHOD: Viamax { double-blas-vector }
+    (prepare-nrm2) cblas_idamax ;
+METHOD: Viamax { float-complex-blas-vector }
+    (prepare-nrm2) cblas_icamax ;
+METHOD: Viamax { double-complex-blas-vector }
+    (prepare-nrm2) cblas_izamax ;
+
+: Vamax ( x -- max )
+    [ Viamax ] keep nth ; inline
+
+: Vsub ( v start length -- vsub )
+    rot [
+        [
+            nip [ inc>> ] [ element-type heap-size ] [ data>> ] tri
+            [ * * ] dip <displaced-alien>
+        ] [ swap 2nip ] [ 2nip inc>> ] 3tri
+    ] keep (blas-vector-like) ;
index 5572a0cf53197ed3db3e8189d7368fe950d4fa98..b6ac45912377e4f881a359fd60359064123e9339 100755 (executable)
@@ -25,7 +25,7 @@ IN: math.vectors
 : normalize ( u -- v ) dup norm v/n ;
 
 : set-axis ( u v axis -- w )
-    dup length [ >r zero? 2over ? r> swap nth ] 2map 2nip ;
+    [ >r zero? 2over ? r> swap nth ] map-index 2nip ;
 
 HINTS: vneg { array } ;
 HINTS: norm-sq { array } ;
diff --git a/extra/models/compose/compose-docs.factor b/extra/models/compose/compose-docs.factor
new file mode 100755 (executable)
index 0000000..8c07b2f
--- /dev/null
@@ -0,0 +1,31 @@
+USING: help.syntax help.markup kernel math classes classes.tuple\r
+calendar models ;\r
+IN: models.compose\r
+\r
+HELP: compose\r
+{ $class-description "Composed model values are computed by collecting the values from a sequence of underlying models into a new sequence. Composed models are automatically updated when underlying models change. Composed models are constructed by " { $link <compose> } "."\r
+$nl\r
+"A composed model whose children are all " { $link "models-range" } " conforms to the " { $link "range-model-protocol" } " and represents a point in n-dimensional space which is bounded by a rectangle." }\r
+{ $examples\r
+    "The following code displays a pair of sliders, and an updating label showing their current values:"\r
+    { $code\r
+        "USING: models ui.gadgets.labels ui.gadgets.sliders ui.gadgets.panes ;"\r
+        ": <funny-slider> <x-slider> 100 over set-slider-max ;"\r
+        "<funny-slider> <funny-slider> 2array"\r
+        "dup make-pile gadget."\r
+        "dup [ gadget-model ] map <compose> [ unparse ] <filter>"\r
+        "<label-control> gadget."\r
+    }\r
+} ;\r
+\r
+HELP: <compose>\r
+{ $values { "models" "a sequence of models" } { "compose" "a new " { $link compose } } }\r
+{ $description "Creates a new instance of " { $link compose } ". The value of the new compose model is obtained by mapping " { $link model-value } " over the given sequence of models." }\r
+{ $examples "See the example in the documentation for " { $link compose } "." } ;\r
+\r
+ARTICLE: "models-compose" "Composed models"\r
+"Composed model values are computed by collecting the values from a sequence of underlying models into a new sequence."\r
+{ $subsection compose }\r
+{ $subsection <compose> } ;\r
+\r
+ABOUT: "models-compose"\r
diff --git a/extra/models/compose/compose-tests.factor b/extra/models/compose/compose-tests.factor
new file mode 100755 (executable)
index 0000000..25ba001
--- /dev/null
@@ -0,0 +1,24 @@
+IN: models.compose.tests\r
+USING: arrays generic kernel math models namespaces sequences assocs\r
+tools.test models.compose ;\r
+\r
+! Test compose\r
+[ ] [\r
+    1 <model> "a" set\r
+    2 <model> "b" set\r
+    "a" get "b" get 2array <compose> "c" set\r
+] unit-test\r
+\r
+[ ] [ "c" get activate-model ] unit-test\r
+\r
+[ { 1 2 } ] [ "c" get model-value ] unit-test\r
+\r
+[ ] [ 3 "b" get set-model ] unit-test\r
+\r
+[ { 1 3 } ] [ "c" get model-value ] unit-test\r
+\r
+[ ] [ { 4 5 } "c" get set-model ] unit-test\r
+\r
+[ { 4 5 } ] [ "c" get model-value ] unit-test\r
+\r
+[ ] [ "c" get deactivate-model ] unit-test\r
diff --git a/extra/models/compose/compose.factor b/extra/models/compose/compose.factor
new file mode 100755 (executable)
index 0000000..0dfc655
--- /dev/null
@@ -0,0 +1,49 @@
+USING: models kernel sequences ;\r
+IN: models.compose\r
+\r
+TUPLE: compose ;\r
+\r
+: <compose> ( models -- compose )\r
+    f compose construct-model\r
+    swap clone over set-model-dependencies ;\r
+\r
+: composed-value >r model-dependencies r> map ; inline\r
+\r
+: set-composed-value >r model-dependencies r> 2each ; inline\r
+\r
+M: compose model-changed\r
+    nip\r
+    dup [ model-value ] composed-value swap delegate set-model ;\r
+\r
+M: compose model-activated dup model-changed ;\r
+\r
+M: compose update-model\r
+    dup model-value swap [ set-model ] set-composed-value ;\r
+\r
+M: compose range-value\r
+    [ range-value ] composed-value ;\r
+\r
+M: compose range-page-value\r
+    [ range-page-value ] composed-value ;\r
+\r
+M: compose range-min-value\r
+    [ range-min-value ] composed-value ;\r
+\r
+M: compose range-max-value\r
+    [ range-max-value ] composed-value ;\r
+\r
+M: compose range-max-value*\r
+    [ range-max-value* ] composed-value ;\r
+\r
+M: compose set-range-value\r
+    [ clamp-value ] keep\r
+    [ set-range-value ] set-composed-value ;\r
+\r
+M: compose set-range-page-value\r
+    [ set-range-page-value ] set-composed-value ;\r
+\r
+M: compose set-range-min-value\r
+    [ set-range-min-value ] set-composed-value ;\r
+\r
+M: compose set-range-max-value\r
+    [ set-range-max-value ] set-composed-value ;\r
diff --git a/extra/models/delay/delay-docs.factor b/extra/models/delay/delay-docs.factor
new file mode 100755 (executable)
index 0000000..1f7aff1
--- /dev/null
@@ -0,0 +1,29 @@
+USING: help.syntax help.markup kernel math classes classes.tuple\r
+calendar models ;\r
+IN: models.delay\r
+\r
+HELP: delay\r
+{ $class-description "Delay models have the same value as their underlying model, however the value only changes after a timer expires. If the underlying model's value changes again before the timer expires, the timer restarts. Delay models are constructed by " { $link <delay> } "." }\r
+{ $examples\r
+    "The following code displays a sliders and a label which is updated half a second after the slider stops changing:"\r
+    { $code\r
+        "USING: models ui.gadgets.labels ui.gadgets.sliders ui.gadgets.panes calendar ;"\r
+        ": <funny-slider>"\r
+        "    0 0 0 100 <range> <x-slider> 500 over set-slider-max ;"\r
+        "<funny-slider> dup gadget."\r
+        "gadget-model 1/2 seconds <delay> [ number>string ] <filter>"\r
+        "<label-control> gadget."\r
+    }\r
+} ;\r
+\r
+HELP: <delay>\r
+{ $values { "model" model } { "timeout" duration } { "delay" delay } }\r
+{ $description "Creates a new instance of " { $link delay } ". The timeout must elapse from the time the underlying model last changed to when the delay model value is changed and its connections are notified." }\r
+{ $examples "See the example in the documentation for " { $link delay } "." } ;\r
+\r
+ARTICLE: "models-delay" "Delay models"\r
+"Delay models are used to implement delayed updating of gadgets in response to user input."\r
+{ $subsection delay }\r
+{ $subsection <delay> } ;\r
+\r
+ABOUT: "models-delay"\r
diff --git a/extra/models/delay/delay.factor b/extra/models/delay/delay.factor
new file mode 100755 (executable)
index 0000000..40b669d
--- /dev/null
@@ -0,0 +1,25 @@
+USING: kernel models alarms ;\r
+IN: models.delay\r
+\r
+TUPLE: delay model timeout alarm ;\r
+\r
+: update-delay-model ( delay -- )\r
+    dup delay-model model-value swap set-model ;\r
+\r
+: <delay> ( model timeout -- delay )\r
+    f delay construct-model\r
+    [ set-delay-timeout ] keep\r
+    [ set-delay-model ] 2keep\r
+    [ add-dependency ] keep ;\r
+\r
+: cancel-delay ( delay -- )\r
+    delay-alarm [ cancel-alarm ] when* ;\r
+\r
+: start-delay ( delay -- )\r
+    dup [ f over set-delay-alarm update-delay-model ] curry\r
+    over delay-timeout later\r
+    swap set-delay-alarm ;\r
+\r
+M: delay model-changed nip dup cancel-delay start-delay ;\r
+\r
+M: delay model-activated update-delay-model ;\r
diff --git a/extra/models/filter/filter-docs.factor b/extra/models/filter/filter-docs.factor
new file mode 100755 (executable)
index 0000000..8c50aac
--- /dev/null
@@ -0,0 +1,27 @@
+USING: help.syntax help.markup kernel math classes classes.tuple\r
+calendar models ;\r
+IN: models.filter\r
+\r
+HELP: filter\r
+{ $class-description "Filter model values are computed by applying a quotation to the value of another model. Filters are automatically updated when the underlying model changes. Filters are constructed by " { $link <filter> } "." }\r
+{ $examples\r
+    "The following code displays a label showing the result of applying " { $link sq } " to the value 5:"\r
+    { $code\r
+        "USING: models ui.gadgets.labels ui.gadgets.panes ;"\r
+        "5 <model> [ sq ] <filter> [ number>string ] <filter>"\r
+        "<label-control> gadget."\r
+    }\r
+    "An exercise for the reader is to keep the original model around on the stack, and change its value to 6, observing that the label will immediately display 36."\r
+} ;\r
+\r
+HELP: <filter>\r
+{ $values { "model" model } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } { "filter" "a new " { $link filter } } }\r
+{ $description "Creates a new instance of " { $link filter } ". The value of the new filter model is computed by applying the quotation to the value." }\r
+{ $examples "See the example in the documentation for " { $link filter } "." } ;\r
+\r
+ARTICLE: "models-filter" "Filter models"\r
+"Filter model values are computed by applying a quotation to the value of another model."\r
+{ $subsection filter }\r
+{ $subsection <filter> } ;\r
+\r
+ABOUT: "models-filter"\r
diff --git a/extra/models/filter/filter-tests.factor b/extra/models/filter/filter-tests.factor
new file mode 100755 (executable)
index 0000000..bdf3273
--- /dev/null
@@ -0,0 +1,24 @@
+IN: models.filter.tests\r
+USING: arrays generic kernel math models namespaces sequences assocs\r
+tools.test models.filter ;\r
+\r
+! Test multiple filters\r
+3 <model> "x" set\r
+"x" get [ 2 * ] <filter> dup "z" set\r
+[ 1+ ] <filter> "y" set\r
+[ ] [ "y" get activate-model ] unit-test\r
+[ t ] [ "z" get "x" get model-connections memq? ] unit-test\r
+[ 7 ] [ "y" get model-value ] unit-test\r
+[ ] [ 4 "x" get set-model ] unit-test\r
+[ 9 ] [ "y" get model-value ] unit-test\r
+[ ] [ "y" get deactivate-model ] unit-test\r
+[ f ] [ "z" get "x" get model-connections memq? ] unit-test\r
+\r
+3 <model> "x" set\r
+"x" get [ sq ] <filter> "y" set\r
+\r
+4 "x" get set-model\r
+\r
+"y" get activate-model\r
+[ 16 ] [ "y" get model-value ] unit-test\r
+"y" get deactivate-model\r
diff --git a/extra/models/filter/filter.factor b/extra/models/filter/filter.factor
new file mode 100755 (executable)
index 0000000..78b1ce0
--- /dev/null
@@ -0,0 +1,16 @@
+USING: models kernel ;\r
+IN: models.filter\r
+\r
+TUPLE: filter model quot ;\r
+\r
+: <filter> ( model quot -- filter )\r
+    f filter construct-model\r
+    [ set-filter-quot ] keep\r
+    [ set-filter-model ] 2keep\r
+    [ add-dependency ] keep ;\r
+\r
+M: filter model-changed\r
+    swap model-value over filter-quot call\r
+    swap set-model ;\r
+\r
+M: filter model-activated dup filter-model swap model-changed ;\r
diff --git a/extra/models/history/history-docs.factor b/extra/models/history/history-docs.factor
new file mode 100755 (executable)
index 0000000..d157729
--- /dev/null
@@ -0,0 +1,36 @@
+USING: help.syntax help.markup kernel math classes classes.tuple\r
+calendar models ;\r
+IN: models.history\r
+\r
+HELP: history\r
+{ $class-description "History models record a timeline of previous values on calls to " { $link add-history } ", and can travel back and forth on the timeline with " { $link go-back } " and " { $link go-forward } ". History models are constructed by " { $link <history> } "." } ;\r
+\r
+HELP: <history>\r
+{ $values { "value" object } { "history" "a new " { $link history } } }\r
+{ $description "Creates a new history model with an initial value." } ;\r
+\r
+{ <history> add-history go-back go-forward } related-words\r
+\r
+HELP: go-back\r
+{ $values { "history" history } }\r
+{ $description "Restores the previous value and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." } ;\r
+\r
+HELP: go-forward\r
+{ $values { "history" history } }\r
+{ $description "Restores the value set prior to the last call to " { $link go-back } " and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." } ;\r
+\r
+HELP: add-history\r
+{ $values { "history" history } }\r
+{ $description "Adds the current value to the history." } ;\r
+\r
+ARTICLE: "models-history" "History models"\r
+"History models record previous values."\r
+{ $subsection history }\r
+{ $subsection <history> }\r
+"Recording history:"\r
+{ $subsection add-history }\r
+"Navigating the history:"\r
+{ $subsection go-back }\r
+{ $subsection go-forward } ;\r
+\r
+ABOUT: "models-history"\r
diff --git a/extra/models/history/history-tests.factor b/extra/models/history/history-tests.factor
new file mode 100755 (executable)
index 0000000..40d1176
--- /dev/null
@@ -0,0 +1,37 @@
+IN: models.history.tests\r
+USING: arrays generic kernel math models namespaces sequences assocs\r
+tools.test models.history ;\r
+\r
+f <history> "history" set\r
+\r
+"history" get add-history\r
+\r
+[ t ] [ "history" get history-back empty? ] unit-test\r
+[ t ] [ "history" get history-forward empty? ] unit-test\r
+\r
+"history" get add-history\r
+3 "history" get set-model\r
+\r
+[ t ] [ "history" get history-back empty? ] unit-test\r
+[ t ] [ "history" get history-forward empty? ] unit-test\r
+\r
+"history" get add-history\r
+4 "history" get set-model\r
+\r
+[ f ] [ "history" get history-back empty? ] unit-test\r
+[ t ] [ "history" get history-forward empty? ] unit-test\r
+\r
+"history" get go-back\r
+\r
+[ 3 ] [ "history" get model-value ] unit-test\r
+\r
+[ t ] [ "history" get history-back empty? ] unit-test\r
+[ f ] [ "history" get history-forward empty? ] unit-test\r
+\r
+"history" get go-forward\r
+\r
+[ 4 ] [ "history" get model-value ] unit-test\r
+\r
+[ f ] [ "history" get history-back empty? ] unit-test\r
+[ t ] [ "history" get history-forward empty? ] unit-test\r
+\r
diff --git a/extra/models/history/history.factor b/extra/models/history/history.factor
new file mode 100755 (executable)
index 0000000..067b76c
--- /dev/null
@@ -0,0 +1,29 @@
+USING: kernel models sequences ;\r
+IN: models.history\r
+\r
+TUPLE: history back forward ;\r
+\r
+: reset-history ( history -- )\r
+    V{ } clone over set-history-back\r
+    V{ } clone swap set-history-forward ;\r
+\r
+: <history> ( value -- history )\r
+    history construct-model dup reset-history ;\r
+\r
+: (add-history) ( history to -- )\r
+    swap model-value dup [ swap push ] [ 2drop ] if ;\r
+\r
+: go-back/forward ( history to from -- )\r
+    dup empty?\r
+    [ 3drop ]\r
+    [ >r dupd (add-history) r> pop swap set-model ] if ;\r
+\r
+: go-back ( history -- )\r
+    dup history-forward over history-back go-back/forward ;\r
+\r
+: go-forward ( history -- )\r
+    dup history-back over history-forward go-back/forward ;\r
+\r
+: add-history ( history -- )\r
+    dup history-forward delete-all\r
+    dup history-back (add-history) ;\r
diff --git a/extra/models/mapping/mapping-tests.factor b/extra/models/mapping/mapping-tests.factor
new file mode 100755 (executable)
index 0000000..43c1883
--- /dev/null
@@ -0,0 +1,34 @@
+IN: models.mapping.tests\r
+USING: arrays generic kernel math models namespaces sequences assocs\r
+tools.test models.mapping ;\r
+\r
+! Test mapping\r
+[ ] [\r
+    [\r
+        1 <model> "one" set\r
+        2 <model> "two" set\r
+    ] H{ } make-assoc\r
+    <mapping> "m" set\r
+] unit-test\r
+\r
+[ ] [ "m" get activate-model ] unit-test\r
+\r
+[ H{ { "one" 1 } { "two" 2 } } ] [\r
+    "m" get model-value\r
+] unit-test\r
+\r
+[ ] [\r
+    H{ { "one" 3 } { "two" 4 } } \r
+    "m" get set-model\r
+] unit-test\r
+\r
+[ H{ { "one" 3 } { "two" 4 } } ] [\r
+    "m" get model-value\r
+] unit-test\r
+\r
+[ H{ { "one" 5 } { "two" 4 } } ] [\r
+    5 "one" "m" get mapping-assoc at set-model\r
+    "m" get model-value\r
+] unit-test\r
+\r
+[ ] [ "m" get deactivate-model ] unit-test\r
diff --git a/extra/models/mapping/mapping.factor b/extra/models/mapping/mapping.factor
new file mode 100755 (executable)
index 0000000..4e12dbc
--- /dev/null
@@ -0,0 +1,20 @@
+USING: models kernel assocs ;\r
+IN: models.mapping\r
+\r
+TUPLE: mapping assoc ;\r
+\r
+: <mapping> ( models -- mapping )\r
+    f mapping construct-model\r
+    over values over set-model-dependencies\r
+    tuck set-mapping-assoc ;\r
+\r
+M: mapping model-changed\r
+    nip\r
+    dup mapping-assoc [ model-value ] assoc-map\r
+    swap delegate set-model ;\r
+\r
+M: mapping model-activated dup model-changed ;\r
+\r
+M: mapping update-model\r
+    dup model-value swap mapping-assoc\r
+    [ swapd at set-model ] curry assoc-each ;\r
index da275e934ac3eff040f6229159094ff5cc518e6a..c31ae3e733129a0590a864bdd33de69921cc416d 100755 (executable)
@@ -5,10 +5,10 @@ IN: models
 HELP: model
 { $class-description "A mutable cell holding a single value. When the value is changed, a sequence of connected objects are notified. Models have the following slots:"
     { $list
-        { { $link model-value } " - the value of the model. Use " { $link set-model } " to change the value." }
-        { { $link model-connections } " - a sequence of objects implementing the " { $link model-changed } " generic word, to be notified when the model's value changes." }
-        { { $link model-dependencies } " - a sequence of models which should have this model added to their sequence of connections when activated." }
-        { { $link model-ref } " - a reference count tracking the number of models which depend on this one." }
+        { { $snippet "value" } " - the value of the model. Use " { $link set-model } " to change the value." }
+        { { $snippet "connections" } " - a sequence of objects implementing the " { $link model-changed } " generic word, to be notified when the model's value changes." }
+        { { $snippet "dependencies" } " - a sequence of models which should have this model added to their sequence of connections when activated." }
+        { { $snippet "ref" } " - a reference count tracking the number of models which depend on this one." }
     }
 "Other classes may delegate to " { $link model } "."
 } ;
@@ -79,84 +79,6 @@ HELP: (change-model)
 { $description "Applies the quotation to the current value of the model to yield a new value, then changes the value of the model to the new value without notifying any observers registered with " { $link add-connection } "." }
 { $notes "There are very few reasons for user code to call this word. Instead, call " { $link change-model } ", which notifies observers." } ;
 
-HELP: filter
-{ $class-description "Filter model values are computed by applying a quotation to the value of another model. Filters are automatically updated when the underlying model changes. Filters are constructed by " { $link <filter> } "." }
-{ $examples
-    "The following code displays a label showing the result of applying " { $link sq } " to the value 5:"
-    { $code
-        "USING: models ui.gadgets.labels ui.gadgets.panes ;"
-        "5 <model> [ sq ] <filter> [ number>string ] <filter>"
-        "<label-control> gadget."
-    }
-    "An exercise for the reader is to keep the original model around on the stack, and change its value to 6, observing that the label will immediately display 36."
-} ;
-
-HELP: <filter>
-{ $values { "model" model } { "quot" "a quotation with stack effect " { $snippet "( obj -- newobj )" } } { "filter" "a new " { $link filter } } }
-{ $description "Creates a new instance of " { $link filter } ". The value of the new filter model is computed by applying the quotation to the value." }
-{ $examples "See the example in the documentation for " { $link filter } "." } ;
-
-HELP: compose
-{ $class-description "Composed model values are computed by collecting the values from a sequence of underlying models into a new sequence. Composed models are automatically updated when underlying models change. Composed models are constructed by " { $link <compose> } "."
-$nl
-"A composed model whose children are all " { $link "models-range" } " conforms to the " { $link "range-model-protocol" } " and represents a point in n-dimensional space which is bounded by a rectangle." }
-{ $examples
-    "The following code displays a pair of sliders, and an updating label showing their current values:"
-    { $code
-        "USING: models ui.gadgets.labels ui.gadgets.sliders ui.gadgets.panes ;"
-        ": <funny-slider> <x-slider> 100 over set-slider-max ;"
-        "<funny-slider> <funny-slider> 2array"
-        "dup make-pile gadget."
-        "dup [ gadget-model ] map <compose> [ unparse ] <filter>"
-        "<label-control> gadget."
-    }
-} ;
-
-HELP: <compose>
-{ $values { "models" "a sequence of models" } { "compose" "a new " { $link compose } } }
-{ $description "Creates a new instance of " { $link compose } ". The value of the new compose model is obtained by mapping " { $link model-value } " over the given sequence of models." }
-{ $examples "See the example in the documentation for " { $link compose } "." } ;
-
-HELP: history
-{ $class-description "History models record a timeline of previous values on calls to " { $link add-history } ", and can travel back and forth on the timeline with " { $link go-back } " and " { $link go-forward } ". History models are constructed by " { $link <history> } "." } ;
-
-HELP: <history>
-{ $values { "value" object } { "history" "a new " { $link history } } }
-{ $description "Creates a new history model with an initial value." } ;
-
-{ <history> add-history go-back go-forward } related-words
-
-HELP: go-back
-{ $values { "history" history } }
-{ $description "Restores the previous value and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." } ;
-
-HELP: go-forward
-{ $values { "history" history } }
-{ $description "Restores the value set prior to the last call to " { $link go-back } " and calls " { $link model-changed } " on all observers registered with " { $link add-connection } "." } ;
-
-HELP: add-history
-{ $values { "history" history } }
-{ $description "Adds the current value to the history." } ;
-
-HELP: delay
-{ $class-description "Delay models have the same value as their underlying model, however the value only changes after a timer expires. If the underlying model's value changes again before the timer expires, the timer restarts. Delay models are constructed by " { $link <delay> } "." }
-{ $examples
-    "The following code displays a sliders and a label which is updated half a second after the slider stops changing:"
-    { $code
-        "USING: models ui.gadgets.labels ui.gadgets.sliders ui.gadgets.panes calendar ;"
-        ": <funny-slider>"
-        "    0 0 0 100 <range> <x-slider> 500 over set-slider-max ;"
-        "<funny-slider> dup gadget."
-        "gadget-model 1/2 seconds <delay> [ number>string ] <filter>"
-        "<label-control> gadget."
-    }
-} ;
-
-HELP: <delay>
-{ $values { "model" model } { "timeout" duration } { "delay" delay } }
-{ $description "Creates a new instance of " { $link delay } ". The timeout must elapse from the time the underlying model last changed to when the delay model value is changed and its connections are notified." }
-{ $examples "See the example in the documentation for " { $link delay } "." } ;
-
 HELP: range-value
 { $values { "model" model } { "value" object } }
 { $contract "Outputs the current value of a range model." } ;
@@ -197,40 +119,6 @@ HELP: set-range-max-value
 { $description "Sets the maximum value of a range model." }
 { $side-effects "model" } ;
 
-HELP: range
-{ $class-description "Range models implement the " { $link "range-model-protocol" } " with real numbers as the minimum, current, maximum, and page size. Range models are created with " { $link <range> } "." }
-{ $notes { $link "ui.gadgets.sliders" } " use range models." } ;
-
-HELP: range-model
-{ $values { "range" range } { "model" model } }
-{ $description "Outputs a model holding a range model's current value." }
-{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;
-
-HELP: range-min
-{ $values { "range" range } { "model" model } }
-{ $description "Outputs a model holding a range model's minimum value." }
-{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;
-
-HELP: range-max
-{ $values { "range" range } { "model" model } }
-{ $description "Outputs a model holding a range model's maximum value." }
-{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;
-
-HELP: range-page
-{ $values { "range" range } { "model" model } }
-{ $description "Outputs a model holding a range model's page size." }
-{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;
-
-HELP: move-by
-{ $values { "amount" real } { "range" range } }
-{ $description "Adds a number to a range model's current value." }
-{ $side-effects "range" } ;
-
-HELP: move-by-page
-{ $values { "amount" real } { "range" range } }
-{ $description "Adds a multiple of the page size to a range model's current value." }
-{ $side-effects "range" } ;
-
 ARTICLE: "models" "Models"
 "The " { $vocab-link "models" } " vocabulary provides basic support for dataflow programming. A model is an observable value. Changing a model's value notifies other objects which depend on the model automatically, and models may depend on each other's values."
 $nl
@@ -246,60 +134,10 @@ $nl
 "When using models which are not associated with controls (or when unit testing controls), you must activate and deactivate models manually:"
 { $subsection activate-model }
 { $subsection deactivate-model }
-"Special types of models:"
-{ $subsection "models-filter" }
-{ $subsection "models-compose" }
-{ $subsection "models-history" }
-{ $subsection "models-delay" }
-{ $subsection "models-range" }
 { $subsection "models-impl" } ;
 
-ARTICLE: "models-filter" "Filter models"
-"Filter model values are computed by applying a quotation to the value of another model."
-{ $subsection filter }
-{ $subsection <filter> } ;
-
-ARTICLE: "models-compose" "Composed models"
-"Composed model values are computed by collecting the values from a sequence of underlying models into a new sequence."
-{ $subsection compose }
-{ $subsection <compose> } ;
-
-ARTICLE: "models-history" "History models"
-"History models record previous values."
-{ $subsection history }
-{ $subsection <history> }
-"Recording history:"
-{ $subsection add-history }
-"Navigating the history:"
-{ $subsection go-back }
-{ $subsection go-forward } ;
-
-ARTICLE: "models-delay" "Delay models"
-"Delay models are used to implement delayed updating of gadgets in response to user input."
-{ $subsection delay }
-{ $subsection <delay> } ;
-
-ARTICLE: "models-range" "Range models"
-"Range models ensure their value is a real number within a fixed range."
-{ $subsection range }
-{ $subsection <range> }
-"Range models conform to a protocol for getting and setting the current value, as well as the endpoints of the range."
-{ $subsection "range-model-protocol" } ;
-
-ARTICLE: "range-model-protocol" "Range model protocol"
-"The range model protocol is implemented by the " { $link range } " and " { $link compose } " classes. User-defined models may implement it too."
-{ $subsection range-value          }
-{ $subsection range-page-value     } 
-{ $subsection range-min-value      } 
-{ $subsection range-max-value      } 
-{ $subsection range-max-value*     } 
-{ $subsection set-range-value      } 
-{ $subsection set-range-page-value } 
-{ $subsection set-range-min-value  } 
-{ $subsection set-range-max-value  } ;
-
 ARTICLE: "models-impl" "Implementing models"
-"New types of models can be defined, along the lines of " { $link filter } " and such."
+"New types of models can be defined, for example see " { $vocab-link "models.filter" } "."
 $nl
 "Models can execute hooks when activated:"
 { $subsection model-activated }
index 7964f8929e21dfbfed66191b735492069d284d09..ee1bb542f08b30019a6e108d2ed460b5a872199e 100755 (executable)
@@ -1,5 +1,6 @@
 IN: models.tests
-USING: arrays generic kernel math models namespaces sequences assocs
+USING: arrays generic kernel math models models.compose
+namespaces sequences assocs
 tools.test ;
 
 TUPLE: model-tester hit? ;
@@ -31,144 +32,3 @@ T{ model-tester f f } "tester" set
     "tester" get
     "model-c" get model-value
 ] unit-test
-
-f <history> "history" set
-
-"history" get add-history
-
-[ t ] [ "history" get history-back empty? ] unit-test
-[ t ] [ "history" get history-forward empty? ] unit-test
-
-"history" get add-history
-3 "history" get set-model
-
-[ t ] [ "history" get history-back empty? ] unit-test
-[ t ] [ "history" get history-forward empty? ] unit-test
-
-"history" get add-history
-4 "history" get set-model
-
-[ f ] [ "history" get history-back empty? ] unit-test
-[ t ] [ "history" get history-forward empty? ] unit-test
-
-"history" get go-back
-
-[ 3 ] [ "history" get model-value ] unit-test
-
-[ t ] [ "history" get history-back empty? ] unit-test
-[ f ] [ "history" get history-forward empty? ] unit-test
-
-"history" get go-forward
-
-[ 4 ] [ "history" get model-value ] unit-test
-
-[ f ] [ "history" get history-back empty? ] unit-test
-[ t ] [ "history" get history-forward empty? ] unit-test
-
-! Test multiple filters
-3 <model> "x" set
-"x" get [ 2 * ] <filter> dup "z" set
-[ 1+ ] <filter> "y" set
-[ ] [ "y" get activate-model ] unit-test
-[ t ] [ "z" get "x" get model-connections memq? ] unit-test
-[ 7 ] [ "y" get model-value ] unit-test
-[ ] [ 4 "x" get set-model ] unit-test
-[ 9 ] [ "y" get model-value ] unit-test
-[ ] [ "y" get deactivate-model ] unit-test
-[ f ] [ "z" get "x" get model-connections memq? ] unit-test
-
-3 <model> "x" set
-"x" get [ sq ] <filter> "y" set
-
-4 "x" get set-model
-
-"y" get activate-model
-[ 16 ] [ "y" get model-value ] unit-test
-"y" get deactivate-model
-
-! Test compose
-[ ] [
-    1 <model> "a" set
-    2 <model> "b" set
-    "a" get "b" get 2array <compose> "c" set
-] unit-test
-
-[ ] [ "c" get activate-model ] unit-test
-
-[ { 1 2 } ] [ "c" get model-value ] unit-test
-
-[ ] [ 3 "b" get set-model ] unit-test
-
-[ { 1 3 } ] [ "c" get model-value ] unit-test
-
-[ ] [ { 4 5 } "c" get set-model ] unit-test
-
-[ { 4 5 } ] [ "c" get model-value ] unit-test
-
-[ ] [ "c" get deactivate-model ] unit-test
-
-! Test mapping
-[ ] [
-    [
-        1 <model> "one" set
-        2 <model> "two" set
-    ] H{ } make-assoc
-    <mapping> "m" set
-] unit-test
-
-[ ] [ "m" get activate-model ] unit-test
-
-[ H{ { "one" 1 } { "two" 2 } } ] [
-    "m" get model-value
-] unit-test
-
-[ ] [
-    H{ { "one" 3 } { "two" 4 } } 
-    "m" get set-model
-] unit-test
-
-[ H{ { "one" 3 } { "two" 4 } } ] [
-    "m" get model-value
-] unit-test
-
-[ H{ { "one" 5 } { "two" 4 } } ] [
-    5 "one" "m" get mapping-assoc at set-model
-    "m" get model-value
-] unit-test
-
-[ ] [ "m" get deactivate-model ] unit-test
-
-! Test <range> 
-: setup-range 0 0 0 255 <range> ;
-
-! clamp-value should not go past range ends
-[ 0   ] [ -10 setup-range clamp-value ] unit-test
-[ 255 ] [ 2000 setup-range clamp-value ] unit-test
-[ 14  ] [ 14 setup-range clamp-value ] unit-test
-
-! range min/max/page values should be correct
-[ 0 ] [ setup-range range-page-value ] unit-test
-[ 0 ] [ setup-range range-min-value ] unit-test
-[ 255 ] [ setup-range range-max-value ] unit-test
-
-! should be able to set the value within the range and get back
-[ 15 ] [ setup-range 15 over set-range-value range-value ] unit-test
-[ 0 ] [ setup-range -15 over set-range-value range-value ] unit-test
-[ 255 ] [ setup-range 4000 over set-range-value range-value ] unit-test
-
-! should be able to change the range min/max/page value
-[ 1 ] [ setup-range 1 over set-range-page-value range-page-value ] unit-test
-[ 50 ] [ setup-range 50 over set-range-min-value range-min-value ] unit-test
-[ 4000 ] [ setup-range 4000 over set-range-max-value range-max-value ] unit-test
-
-! should be able to move by positive and negative values
-[ 30 ] [ setup-range 30 over move-by range-value ] unit-test
-[ 0 ] [ setup-range 30 over move-by -30 over move-by range-value ] unit-test
-
-! should be able to move by a page of 10
-[ 10 ] [ 
-  setup-range 10 over set-range-page-value 
-  1 over move-by-page range-value 
-] unit-test
-
-
index 2caf6e9940c2db0158518e058bf8eb42169a77d7..48c43d9368da8b5638a9bfdeb73f07ce646c2449 100755 (executable)
@@ -1,14 +1,21 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: generic kernel math sequences arrays assocs alarms
-calendar math.order ;
+USING: accessors generic kernel math sequences arrays assocs
+alarms calendar math.order ;
 IN: models
 
 TUPLE: model < identity-tuple
 value connections dependencies ref locked? ;
 
+: new-model ( value class -- model )
+    new
+        swap >>value
+        V{ } clone >>connections
+        V{ } clone >>dependencies
+        0 >>ref ; inline
+
 : <model> ( value -- model )
-    V{ } clone V{ } clone 0 f model boa ;
+    model new-model ;
 
 M: model hashcode* drop model hashcode* ;
 
@@ -96,107 +103,6 @@ M: model update-model drop ;
 : construct-model ( value class -- instance )
     >r <model> { set-delegate } r> construct ; inline
 
-TUPLE: filter model quot ;
-
-: <filter> ( model quot -- filter )
-    f filter construct-model
-    [ set-filter-quot ] keep
-    [ set-filter-model ] 2keep
-    [ add-dependency ] keep ;
-
-M: filter model-changed
-    swap model-value over filter-quot call
-    swap set-model ;
-
-M: filter model-activated dup filter-model swap model-changed ;
-
-TUPLE: compose ;
-
-: <compose> ( models -- compose )
-    f compose construct-model
-    swap clone over set-model-dependencies ;
-
-: composed-value >r model-dependencies r> map ; inline
-
-: set-composed-value >r model-dependencies r> 2each ; inline
-
-M: compose model-changed
-    nip
-    dup [ model-value ] composed-value swap delegate set-model ;
-
-M: compose model-activated dup model-changed ;
-
-M: compose update-model
-    dup model-value swap [ set-model ] set-composed-value ;
-
-TUPLE: mapping assoc ;
-
-: <mapping> ( models -- mapping )
-    f mapping construct-model
-    over values over set-model-dependencies
-    tuck set-mapping-assoc ;
-
-M: mapping model-changed
-    nip
-    dup mapping-assoc [ model-value ] assoc-map
-    swap delegate set-model ;
-
-M: mapping model-activated dup model-changed ;
-
-M: mapping update-model
-    dup model-value swap mapping-assoc
-    [ swapd at set-model ] curry assoc-each ;
-
-TUPLE: history back forward ;
-
-: reset-history ( history -- )
-    V{ } clone over set-history-back
-    V{ } clone swap set-history-forward ;
-
-: <history> ( value -- history )
-    history construct-model dup reset-history ;
-
-: (add-history) ( history to -- )
-    swap model-value dup [ swap push ] [ 2drop ] if ;
-
-: go-back/forward ( history to from -- )
-    dup empty?
-    [ 3drop ]
-    [ >r dupd (add-history) r> pop swap set-model ] if ;
-
-: go-back ( history -- )
-    dup history-forward over history-back go-back/forward ;
-
-: go-forward ( history -- )
-    dup history-back over history-forward go-back/forward ;
-
-: add-history ( history -- )
-    dup history-forward delete-all
-    dup history-back (add-history) ;
-
-TUPLE: delay model timeout alarm ;
-
-: update-delay-model ( delay -- )
-    dup delay-model model-value swap set-model ;
-
-: <delay> ( model timeout -- delay )
-    f delay construct-model
-    [ set-delay-timeout ] keep
-    [ set-delay-model ] 2keep
-    [ add-dependency ] keep ;
-
-: cancel-delay ( delay -- )
-    delay-alarm [ cancel-alarm ] when* ;
-
-: start-delay ( delay -- )
-    dup [ f over set-delay-alarm update-delay-model ] curry
-    over delay-timeout later
-    swap set-delay-alarm ;
-
-M: delay model-changed nip dup cancel-delay start-delay ;
-
-M: delay model-activated update-delay-model ;
-
 GENERIC: range-value ( model -- value )
 GENERIC: range-page-value ( model -- value )
 GENERIC: range-min-value ( model -- value )
@@ -207,72 +113,6 @@ GENERIC: set-range-page-value ( value model -- )
 GENERIC: set-range-min-value ( value model -- )
 GENERIC: set-range-max-value ( value model -- )
 
-TUPLE: range ;
-
-: <range> ( value min max page -- range )
-    4array [ <model> ] map <compose>
-    { set-delegate } range construct ;
-
-: range-model ( range -- model ) model-dependencies first ;
-: range-page ( range -- model ) model-dependencies second ;
-: range-min ( range -- model ) model-dependencies third ;
-: range-max ( range -- model ) model-dependencies fourth ;
-
 : clamp-value ( value range -- newvalue )
     [ range-min-value max ] keep
     range-max-value* min ;
-
-M: range range-value
-    [ range-model model-value ] keep clamp-value ;
-
-M: range range-page-value range-page model-value ;
-
-M: range range-min-value range-min model-value ;
-
-M: range range-max-value range-max model-value ;
-
-M: range range-max-value*
-    dup range-max-value swap range-page-value [-] ;
-
-M: range set-range-value
-    [ clamp-value ] keep range-model set-model ;
-
-M: range set-range-page-value range-page set-model ;
-
-M: range set-range-min-value range-min set-model ;
-
-M: range set-range-max-value range-max set-model ;
-
-M: compose range-value
-    [ range-value ] composed-value ;
-
-M: compose range-page-value
-    [ range-page-value ] composed-value ;
-
-M: compose range-min-value
-    [ range-min-value ] composed-value ;
-
-M: compose range-max-value
-    [ range-max-value ] composed-value ;
-
-M: compose range-max-value*
-    [ range-max-value* ] composed-value ;
-
-M: compose set-range-value
-    [ clamp-value ] keep
-    [ set-range-value ] set-composed-value ;
-
-M: compose set-range-page-value
-    [ set-range-page-value ] set-composed-value ;
-
-M: compose set-range-min-value
-    [ set-range-min-value ] set-composed-value ;
-
-M: compose set-range-max-value
-    [ set-range-max-value ] set-composed-value ;
-
-: move-by ( amount range -- )
-    [ range-value + ] keep set-range-value ;
-
-: move-by-page ( amount range -- )
-    [ range-page-value * ] keep move-by ;
diff --git a/extra/models/range/range-docs.factor b/extra/models/range/range-docs.factor
new file mode 100755 (executable)
index 0000000..6a767b2
--- /dev/null
@@ -0,0 +1,58 @@
+USING: help.syntax help.markup kernel math classes classes.tuple\r
+calendar models ;\r
+IN: models.range\r
+\r
+HELP: range\r
+{ $class-description "Range models implement the " { $link "range-model-protocol" } " with real numbers as the minimum, current, maximum, and page size. Range models are created with " { $link <range> } "." }\r
+{ $notes { $link "ui.gadgets.sliders" } " use range models." } ;\r
+\r
+HELP: range-model\r
+{ $values { "range" range } { "model" model } }\r
+{ $description "Outputs a model holding a range model's current value." }\r
+{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;\r
+\r
+HELP: range-min\r
+{ $values { "range" range } { "model" model } }\r
+{ $description "Outputs a model holding a range model's minimum value." }\r
+{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;\r
+\r
+HELP: range-max\r
+{ $values { "range" range } { "model" model } }\r
+{ $description "Outputs a model holding a range model's maximum value." }\r
+{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;\r
+\r
+HELP: range-page\r
+{ $values { "range" range } { "model" model } }\r
+{ $description "Outputs a model holding a range model's page size." }\r
+{ $notes "This word is not part of the " { $link "range-model-protocol" } ", and can only be used on direct instances of " { $link range } "." } ;\r
+\r
+HELP: move-by\r
+{ $values { "amount" real } { "range" range } }\r
+{ $description "Adds a number to a range model's current value." }\r
+{ $side-effects "range" } ;\r
+\r
+HELP: move-by-page\r
+{ $values { "amount" real } { "range" range } }\r
+{ $description "Adds a multiple of the page size to a range model's current value." }\r
+{ $side-effects "range" } ;\r
+\r
+ARTICLE: "models-range" "Range models"\r
+"Range models ensure their value is a real number within a fixed range."\r
+{ $subsection range }\r
+{ $subsection <range> }\r
+"Range models conform to a protocol for getting and setting the current value, as well as the endpoints of the range."\r
+{ $subsection "range-model-protocol" } ;\r
+\r
+ARTICLE: "range-model-protocol" "Range model protocol"\r
+"The range model protocol is implemented by the " { $link range } " and " { $link compose } " classes. User-defined models may implement it too."\r
+{ $subsection range-value          }\r
+{ $subsection range-page-value     } \r
+{ $subsection range-min-value      } \r
+{ $subsection range-max-value      } \r
+{ $subsection range-max-value*     } \r
+{ $subsection set-range-value      } \r
+{ $subsection set-range-page-value } \r
+{ $subsection set-range-min-value  } \r
+{ $subsection set-range-max-value  } ;\r
+\r
+ABOUT: "models-range"\r
diff --git a/extra/models/range/range-tests.factor b/extra/models/range/range-tests.factor
new file mode 100755 (executable)
index 0000000..c8a2d1a
--- /dev/null
@@ -0,0 +1,36 @@
+IN: models.range.tests\r
+USING: arrays generic kernel math models namespaces sequences assocs\r
+tools.test models.range ;\r
+\r
+! Test <range> \r
+: setup-range 0 0 0 255 <range> ;\r
+\r
+! clamp-value should not go past range ends\r
+[ 0   ] [ -10 setup-range clamp-value ] unit-test\r
+[ 255 ] [ 2000 setup-range clamp-value ] unit-test\r
+[ 14  ] [ 14 setup-range clamp-value ] unit-test\r
+\r
+! range min/max/page values should be correct\r
+[ 0 ] [ setup-range range-page-value ] unit-test\r
+[ 0 ] [ setup-range range-min-value ] unit-test\r
+[ 255 ] [ setup-range range-max-value ] unit-test\r
+\r
+! should be able to set the value within the range and get back\r
+[ 15 ] [ setup-range 15 over set-range-value range-value ] unit-test\r
+[ 0 ] [ setup-range -15 over set-range-value range-value ] unit-test\r
+[ 255 ] [ setup-range 4000 over set-range-value range-value ] unit-test\r
+\r
+! should be able to change the range min/max/page value\r
+[ 1 ] [ setup-range 1 over set-range-page-value range-page-value ] unit-test\r
+[ 50 ] [ setup-range 50 over set-range-min-value range-min-value ] unit-test\r
+[ 4000 ] [ setup-range 4000 over set-range-max-value range-max-value ] unit-test\r
+\r
+! should be able to move by positive and negative values\r
+[ 30 ] [ setup-range 30 over move-by range-value ] unit-test\r
+[ 0 ] [ setup-range 30 over move-by -30 over move-by range-value ] unit-test\r
+\r
+! should be able to move by a page of 10\r
+[ 10 ] [ \r
+  setup-range 10 over set-range-page-value \r
+  1 over move-by-page range-value \r
+] unit-test\r
diff --git a/extra/models/range/range.factor b/extra/models/range/range.factor
new file mode 100755 (executable)
index 0000000..761e077
--- /dev/null
@@ -0,0 +1,41 @@
+USING: kernel models arrays sequences math math.order\r
+models.compose ;\r
+IN: models.range\r
+\r
+TUPLE: range ;\r
+\r
+: <range> ( value min max page -- range )\r
+    4array [ <model> ] map <compose>\r
+    { set-delegate } range construct ;\r
+\r
+: range-model ( range -- model ) model-dependencies first ;\r
+: range-page ( range -- model ) model-dependencies second ;\r
+: range-min ( range -- model ) model-dependencies third ;\r
+: range-max ( range -- model ) model-dependencies fourth ;\r
+\r
+M: range range-value\r
+    [ range-model model-value ] keep clamp-value ;\r
+\r
+M: range range-page-value range-page model-value ;\r
+\r
+M: range range-min-value range-min model-value ;\r
+\r
+M: range range-max-value range-max model-value ;\r
+\r
+M: range range-max-value*\r
+    dup range-max-value swap range-page-value [-] ;\r
+\r
+M: range set-range-value\r
+    [ clamp-value ] keep range-model set-model ;\r
+\r
+M: range set-range-page-value range-page set-model ;\r
+\r
+M: range set-range-min-value range-min set-model ;\r
+\r
+M: range set-range-max-value range-max set-model ;\r
+\r
+: move-by ( amount range -- )\r
+    [ range-value + ] keep set-range-value ;\r
+\r
+: move-by-page ( amount range -- )\r
+    [ range-page-value * ] keep move-by ;\r
old mode 100644 (file)
new mode 100755 (executable)
index 1b5b6f2..5b7f335
@@ -1,6 +1,6 @@
 
 USING: kernel io parser lexer words namespaces quotations arrays assocs sequences
-       splitting grouping math shuffle ;
+       splitting grouping math generalizations ;
 
 IN: mortar
 
index c8128c33eeafd1160e94441048c87bfb760dfe17..69dca2affc22e760b9f9df3adc2d5b490c9a06a6 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math sequences vectors classes classes.algebra
 combinators arrays words assocs parser namespaces definitions
-prettyprint prettyprint.backend quotations arrays.lib
+prettyprint prettyprint.backend quotations generalizations
 debugger io compiler.units kernel.private effects accessors
 hashtables sorting shuffle math.order sets ;
 IN: multi-methods
index 9335c61025322fabaf6831b455167391ce7fed7e..9cc63fd57e7e67fa7f5337319196316b89083360 100644 (file)
@@ -237,3 +237,9 @@ METHOD: as-mutate { object object assoc }       set-at ;
 
 : prepend!   ( a b -- ba  ) over append 0 pick copy ;
 : prepended! ( a b --     ) over append 0 rot  copy ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+: insert ( seq i obj -- seq ) >r cut r> prefix append ;
+
+: splice ( seq i seq -- seq ) >r cut r> prepend append ;
\ No newline at end of file
index dc9222cedb5260bb26cddc285a24b2256abf6dc7..0be443e38d4bbc1c075e49f07ba32b1edbcaf80c 100644 (file)
@@ -27,10 +27,6 @@ HELP: >persistent-vector
 HELP: persistent-vector
 { $class-description "The class of persistent vectors." } ;
 
-HELP: pempty
-{ $values { "pvec" persistent-vector } }
-{ $description "Outputs an empty " { $link persistent-vector } "." } ;
-
 ARTICLE: "persistent-vectors" "Persistent vectors"
 "A " { $emphasis "persistent vector" } " differs from an ordinary vector (" { $link "vectors" } ") in that it is immutable, and all operations yield new persistent vectors instead of modifying inputs. Unlike immutable operations on ordinary sequences, persistent vector operations are efficient and run in sub-linear time."
 $nl
@@ -42,12 +38,12 @@ $nl
 { $subsection new-nth }
 { $subsection ppush }
 { $subsection ppop }
-"The empty persistent vector, used for building up all other persistent vectors:"
-{ $subsection pempty }
 "Converting a sequence into a persistent vector:"
 { $subsection >persistent-vector }
 "Persistent vectors have a literal syntax:"
 { $subsection POSTPONE: PV{ }
+"The empty persistent vector, written " { $snippet "PV{ }" } ", is used for building up all other persistent vectors."
+$nl
 "This implementation of persistent vectors is based on the " { $snippet "clojure.lang.PersistentVector" } " class from Rich Hickey's Clojure language for the JVM (" { $url "http://clojure.org" } ")." ;
 
 ABOUT: "persistent-vectors"
index 45eb894e67058fc75723c13ed7f2e5bf6cc79363..1e2fae6a392a32a255139ce1b2eb94aa23949e79 100644 (file)
@@ -1,23 +1,23 @@
 IN: persistent-vectors.tests
-USING: tools.test persistent-vectors sequences kernel arrays
-random namespaces vectors math math.order ;
+USING: accessors tools.test persistent-vectors sequences kernel
+arrays random namespaces vectors math math.order ;
 
 \ new-nth must-infer
 \ ppush must-infer
 \ ppop must-infer
 
-[ 0 ] [ pempty length ] unit-test
+[ 0 ] [ PV{ } length ] unit-test
 
-[ 1 ] [ 3 pempty ppush length ] unit-test
+[ 1 ] [ 3 PV{ } ppush length ] unit-test
 
-[ 3 ] [ 3 pempty ppush first ] unit-test
+[ 3 ] [ 3 PV{ } ppush first ] unit-test
 
 [ PV{ 3 1 3 3 7 } ] [
-    pempty { 3 1 3 3 7 } [ swap ppush ] each
+    PV{ } { 3 1 3 3 7 } [ swap ppush ] each
 ] unit-test
 
 [ { 3 1 3 3 7 } ] [
-    pempty { 3 1 3 3 7 } [ swap ppush ] each >array
+    PV{ } { 3 1 3 3 7 } [ swap ppush ] each >array
 ] unit-test
 
 { 100 1060 2000 10000 100000 1000000 } [
@@ -52,6 +52,16 @@ random namespaces vectors math math.order ;
 
 [ ] [ PV{ } 10000 [ push/pop-test ] times drop ] unit-test
 
+[ PV{ } ] [
+    PV{ }
+    10000 [ 1 swap ppush ] times
+    10000 [ ppop ] times
+] unit-test
+
+[ t ] [
+    10000 >persistent-vector 752 [ ppop ] times dup length sequence=
+] unit-test
+
 [ t ] [
     100 [
         drop
index 691ebfcf4d20d2ddb2958c48ed395256e8b6cef1..e071ae69d2e99612ed4118a82e84e214cbe804d9 100644 (file)
@@ -4,6 +4,12 @@ USING: math accessors kernel sequences.private sequences arrays
 combinators combinators.short-circuit parser prettyprint.backend ;
 IN: persistent-vectors
 
+<PRIVATE
+
+TUPLE: node { children array } { level fixnum } ;
+
+PRIVATE>
+
 ERROR: empty-error pvec ;
 
 GENERIC: ppush ( val seq -- seq' )
@@ -18,14 +24,13 @@ GENERIC: new-nth ( val i seq -- seq' )
 
 M: sequence new-nth clone [ set-nth ] keep ;
 
-TUPLE: persistent-vector count root tail ;
+TUPLE: persistent-vector
+{ count fixnum }
+{ root node initial: T{ node f { } 1 } }
+{ tail node initial: T{ node f { } 0 } } ;
 
 M: persistent-vector length count>> ;
 
-<PRIVATE
-
-TUPLE: node children level ;
-
 : node-size 32 ; inline
 
 : node-mask node-size mod ; inline
@@ -33,12 +38,12 @@ TUPLE: node children level ;
 : node-shift -5 * shift ; inline
 
 : node-nth ( i node -- obj )
-    [ node-mask ] [ children>> ] bi* nth ; inline
+    [ node-mask ] [ children>> ] bi* nth ;
 
 : body-nth ( i node -- i node' )
     dup level>> [
         dupd [ level>> node-shift ] keep node-nth
-    ] times ; inline
+    ] times ;
 
 : tail-offset ( pvec -- n )
     [ count>> ] [ tail>> children>> length ] bi - ;
@@ -58,9 +63,7 @@ M: persistent-vector nth-unsafe
     children>> length node-size = ;
 
 : 1node ( val level -- node )
-    node new
-        swap >>level
-        swap 1array >>children ;
+    [ 1array ] dip node boa ;
 
 : 2node ( first second -- node )
     [ 2array ] [ drop level>> 1+ ] 2bi node boa ;
@@ -123,6 +126,10 @@ M: persistent-vector new-nth ( obj i pvec -- pvec' )
         ] if
     ] if ;
 
+! The pop code is really convoluted. I don't understand Rich Hickey's
+! original code. It uses a 'Box' out parameter which is passed around
+! inside a recursive function, and gets mutated along the way to boot.
+! Super-confusing.
 : ppop-tail ( pvec -- pvec' )
     [ clone [ ppop ] change-children ] change-tail ;
 
@@ -137,10 +144,12 @@ M: persistent-vector new-nth ( obj i pvec -- pvec' )
 
 : (ppop-new-tail) ( root -- root' tail' )
     dup level>> 1 > [
-        dup children>> peek (ppop-new-tail) over
-        [ [ swap node-set-last ] dip ]
-        [ 2drop ppop-contraction ]
-        if
+        dup children>> peek (ppop-new-tail) [
+            dup
+            [ swap node-set-last ]
+            [ drop ppop-contraction drop ]
+            if
+        ] dip
     ] [
         ppop-contraction
     ] if ;
@@ -159,13 +168,10 @@ M: persistent-vector new-nth ( obj i pvec -- pvec' )
 
 PRIVATE>
 
-: pempty ( -- pvec )
-    T{ persistent-vector f 0 T{ node f { } 1 } T{ node f { } 0 } } ; inline
-
 M: persistent-vector ppop ( pvec -- pvec' )
     dup count>> {
         { 0 [ empty-error ] }
-        { 1 [ drop pempty ] }
+        { 1 [ drop T{ persistent-vector } ] }
         [
             [
                 clone
@@ -176,12 +182,13 @@ M: persistent-vector ppop ( pvec -- pvec' )
     } case ;
 
 M: persistent-vector like
-    drop pempty [ swap ppush ] reduce ;
+    drop T{ persistent-vector } [ swap ppush ] reduce ;
 
 M: persistent-vector equal?
     over persistent-vector? [ sequence= ] [ 2drop f ] if ;
 
-: >persistent-vector ( seq -- pvec ) pempty like ; inline
+: >persistent-vector ( seq -- pvec )
+    T{ persistent-vector } like ;
 
 : PV{ \ } [ >persistent-vector ] parse-literal ; parsing
 
old mode 100644 (file)
new mode 100755 (executable)
index e089b15..fb9f321
@@ -1,7 +1,7 @@
 
 USING: kernel namespaces threads combinators sequences arrays
        math math.functions math.ranges random
-       opengl.gl opengl.glu vars multi-methods shuffle
+       opengl.gl opengl.glu vars multi-methods generalizations shuffle
        ui
        ui.gestures
        ui.gadgets
index 32a43a4fb4d9ef97543aaba9520bab571216e907..ff88abad612d25c6b105fa54fa7a315fd3792421 100755 (executable)
@@ -1,7 +1,7 @@
-USING: accessors assocs math kernel shuffle combinators.lib\r
+USING: accessors assocs math kernel shuffle generalizations\r
 words quotations arrays combinators sequences math.vectors\r
 io.styles prettyprint vocabs sorting io generic locals.private\r
-math.statistics math.order ;\r
+math.statistics math.order combinators.lib ;\r
 IN: reports.noise\r
 \r
 : badness ( word -- n )\r
index 501637105246430cc40bf7b23a14f7289122d11a..ec3668b83b98290273e4126371ede7cfd5ae68aa 100755 (executable)
@@ -2,20 +2,31 @@
 ! See http://factorcode.org/license.txt for BSD license.\r
 USING: accessors assocs words sequences arrays compiler\r
 tools.time io.styles io prettyprint vocabs kernel sorting\r
-generator optimizer math math.order ;\r
+generator optimizer math math.order math.statistics combinators ;\r
 IN: report.optimizer\r
 \r
 : count-optimization-passes ( nodes n -- n )\r
     >r optimize-1\r
     [ r> 1+ count-optimization-passes ] [ drop r> ] if ;\r
 \r
-: results\r
-    [ [ second ] prepose compare ] curry sort 20 tail*\r
-    print\r
+: table. ( alist -- )\r
+    20 short tail*\r
     standard-table-style\r
     [\r
         [ [ [ pprint-cell ] each ] with-row ] each\r
-    ] tabular-output ; inline\r
+    ] tabular-output ;\r
+\r
+: results ( results quot title -- )\r
+    print\r
+    [ second ] prepose\r
+    [ [ compare ] curry sort table. ]\r
+    [\r
+        map\r
+        [ "Mean: " write mean >float . ]\r
+        [ "Median: " write median >float . ]\r
+        [ "Standard deviation: " write std >float . ]\r
+        tri\r
+    ] 2bi ; inline\r
 \r
 : optimizer-measurements ( -- alist )\r
     all-words [ compiled>> ] filter\r
@@ -26,8 +37,10 @@ IN: report.optimizer
     ] { } map>assoc ;\r
 \r
 : optimizer-measurements. ( alist -- )\r
-    [ [ first ] "Worst number of optimizer passes:" results ]\r
-    [ [ second ] "Worst compile times:" results ] bi ;\r
+    {\r
+        [ [ first ] "Optimizer passes:" results ]\r
+        [ [ second ] "Compile times:" results ]\r
+    } cleave ;\r
 \r
 : optimizer-report ( -- )\r
     optimizer-measurements optimizer-measurements. ;\r
index 1debe3f91b7d163a8f424bb8573cec88ce06882c..3b54abfeab46588fef54100f698df4cf8973411c 100755 (executable)
@@ -4,7 +4,8 @@
 USING: combinators.lib kernel sequences math namespaces assocs 
 random sequences.private shuffle math.functions
 arrays math.parser math.private sorting strings ascii macros
-assocs.lib quotations hashtables math.order locals ;
+assocs.lib quotations hashtables math.order locals
+generalizations ;
 IN: sequences.lib
 
 : each-withn ( seq quot n -- ) nwith each ; inline
@@ -24,21 +25,6 @@ MACRO: firstn ( n -- )
     concat >quotation
     [ drop ] compose ;
 
-: prepare-index ( seq quot -- seq n quot )
-    >r dup length r> ; inline
-
-: each-index ( seq quot -- )
-    #! quot: ( elt index -- )
-    prepare-index 2each ; inline
-
-: map-index ( seq quot -- )
-    #! quot: ( elt index -- obj )
-    prepare-index 2map ; inline
-
-: reduce-index ( seq identity quot -- )
-    #! quot: ( prev elt index -- next )
-    swapd each-index ; inline
-
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : each-percent ( seq quot -- )
diff --git a/extra/shuffle/shuffle-docs.factor b/extra/shuffle/shuffle-docs.factor
deleted file mode 100755 (executable)
index 4caace3..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-! Copyright (C) 2007 Chris Double.
-! See http://factorcode.org/license.txt for BSD license.
-USING: help.syntax help.markup kernel sequences ;
-IN: shuffle
-
-HELP: npick
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link dup } ", "
-{ $link over } " and " { $link pick } " that can work "
-"for any stack depth. The nth item down the stack will be copied and "
-"placed on the top of the stack."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 npick .s" "1\n2\n3\n4\n1" }
-}
-{ $see-also dup over pick } ;
-
-HELP: ndup
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link dup } ", "
-{ $link 2dup } " and " { $link 3dup } " that can work "
-"for any number of items. The n topmost items on the stack will be copied and "
-"placed on the top of the stack."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 ndup .s" "1\n2\n3\n4\n1\n2\n3\n4" }
-}
-{ $see-also dup 2dup 3dup } ;
-
-HELP: nnip
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link nip } " and " { $link 2nip }
-" that can work "
-"for any number of items."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 3 nnip .s" "4" }
-}
-{ $see-also nip 2nip } ;
-
-HELP: ndrop
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link drop }
-" that can work "
-"for any number of items."
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 3 ndrop .s" "1" }
-}
-{ $see-also drop 2drop 3drop } ;
-
-HELP: nrot
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link rot } " that works for any "
-"number of items on the stack. "
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 nrot .s" "2\n3\n4\n1" }
-}
-{ $see-also rot -nrot } ;
-
-HELP: -nrot
-{ $values { "n" "a number" } }
-{ $description "A generalisation of " { $link -rot } " that works for any "
-"number of items on the stack. "
-}
-{ $examples
-  { $example "USING: prettyprint shuffle ;" "1 2 3 4 4 -nrot .s" "4\n1\n2\n3" }
-}
-{ $see-also rot nrot } ;
-
-ARTICLE: { "shuffle" "overview" } "Extra shuffle words"
-"A number of stack shuffling words for those rare times when you "
-"need to deal with tricky stack situations and can't refactor the "
-"code to work around it."
-{ $subsection ndup }
-{ $subsection npick }
-{ $subsection nrot }
-{ $subsection -nrot }
-{ $subsection nnip }
-{ $subsection ndrop }  ;
-
-IN: shuffle
-ABOUT: { "shuffle" "overview" }
\ No newline at end of file
index 9f2b8e01a9527eb7fe962546be6d2e16f22c63eb..b5168b903ce4fe1909ad7101d85f04c80d9489f9 100755 (executable)
@@ -1,25 +1,4 @@
-USING: arrays shuffle kernel math tools.test inference words ;
+USING: shuffle tools.test ;
 
 [ 8 ] [ 5 6 7 8 3nip ] unit-test
-{ 1 2 3 4 1 } [ 1 2 3 4 4 npick ] unit-test
-{ 1 2 3 4 2 } [ 1 2 3 4 3 npick ] unit-test
-{ 1 2 3 4 3 } [ 1 2 3 4 2 npick ] unit-test
-{ 1 2 3 4 4 } [ 1 2 3 4 1 npick ] unit-test
-{ t } [ [ 1 1 ndup ] infer >boolean ] unit-test
-{ 1 1 } [ 1 1 ndup ] unit-test
-{ 1 2 1 2 } [ 1 2 2 ndup ] unit-test
-{ 1 2 3 1 2 3 } [ 1 2 3 3 ndup ] unit-test
-{ 1 2 3 4 1 2 3 4 } [ 1 2 3 4 4 ndup ] unit-test
-{ t } [ [ 1 2 2 nrot ] infer >boolean ] unit-test
-{ 2 1 } [ 1 2 2 nrot ] unit-test
-{ 2 3 1 } [ 1 2 3 3 nrot ] unit-test
-{ 2 3 4 1 } [ 1 2 3 4 4 nrot ] unit-test
-{ t } [ [ 1 2 2 -nrot ] infer >boolean ] unit-test
-{ 2 1 } [ 1 2 2 -nrot ] unit-test
-{ 3 1 2 } [ 1 2 3 3 -nrot ] unit-test
-{ 4 1 2 3 } [ 1 2 3 4 4 -nrot ] unit-test
-{ t } [ [ 1 2 3 4 3 nnip ] infer >boolean ] unit-test
-{ 4 } [ 1 2 3 4 3 nnip ] unit-test
-{ t } [ [ 1 2 3 4 4 ndrop ] infer >boolean ] unit-test
-{ 0 } [ 0 1 2 3 4 4 ndrop ] unit-test
 [ 3 1 2 3 ] [ 1 2 3 tuckd ] unit-test
index 2366d15cff2cb0967b5f7227c09d28e065f4a164..9a0dfe0e88d6b91d7d97a854f047fb2824dbd03c 100644 (file)
@@ -1,24 +1,9 @@
 ! Copyright (C) 2007 Chris Double, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel sequences namespaces math inference.transforms
-       combinators macros quotations math.ranges fry ;
+USING: kernel generalizations ;
 
 IN: shuffle
 
-MACRO: npick ( n -- ) 1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;
-
-MACRO: ndup ( n -- ) dup [ npick ] curry n*quot ;
-
-MACRO: nrot ( n -- ) 1- dup saver swap [ r> swap ] n*quot append ;
-
-MACRO: -nrot ( n -- ) 1- dup [ swap >r ] n*quot swap restorer append ;
-
-MACRO: ndrop ( n -- ) [ drop ] n*quot ;
-
-: nnip ( n -- ) swap >r ndrop r> ; inline
-
-MACRO: ntuck ( n -- ) 2 + '[ dup , -nrot ] ;
-
 : 2swap ( x y z t -- z t x y ) rot >r rot r> ; inline
 
 : nipd ( a b c -- b c ) rot drop ; inline
@@ -32,8 +17,3 @@ MACRO: ntuck ( n -- ) 2 + '[ dup , -nrot ] ;
 : 4drop ( a b c d -- ) 3drop drop ; inline
 
 : tuckd ( x y z -- z x y z ) 2 ntuck ; inline
-
-MACRO: nrev ( n -- quot )
-  [ 1+ ] map
-  reverse
-  [ [ -nrot ] curry ] map concat ;
old mode 100644 (file)
new mode 100755 (executable)
index 9d06987..dff7313
@@ -1,6 +1,6 @@
 USING: kernel opengl.demo-support opengl.gl opengl.shaders opengl.framebuffers
 opengl multiline ui.gadgets accessors sequences ui.render ui math 
-arrays arrays.lib combinators ;
+arrays generalizations combinators ;
 IN: spheres
 
 STRING: plane-vertex-shader
old mode 100644 (file)
new mode 100755 (executable)
index cd6e1a7..1856115
@@ -1,6 +1,6 @@
 
 USING: kernel combinators sequences arrays math math.vectors
-       shuffle vars ;
+       generalizations vars ;
 
 IN: springies
 
index 02f8f240d28d71afacc0c6c5d4c03e138ef7ef5f..c2f874598c2666edd52802da3e13f3a6e2a0601f 100644 (file)
@@ -45,7 +45,7 @@ tetris-gadget H{
     dup tetris-gadget-tetris maybe-update relayout-1 ;
 
 M: tetris-gadget graft* ( gadget -- )
-    dup [ tick ] curry 100 milliseconds from-now 100 milliseconds add-alarm
+    dup [ tick ] curry 100 milliseconds every
     swap set-tetris-gadget-alarm ;
 
 M: tetris-gadget ungraft* ( gadget -- )
index 86691e89a0263170375639c46e54eac756024ce5..b66688b63aa17fba81af9e5811c4a6959dfe2bfc 100755 (executable)
@@ -12,42 +12,36 @@ namespaces continuations layouts accessors ;
     ] with-directory ;\r
 \r
 : small-enough? ( n -- ? )\r
-    >r "test.image" temp-file file-info size>> r> <= ;\r
+    >r "test.image" temp-file file-info size>> r> cell 4 / * <= ;\r
 \r
 [ ] [ "hello-world" shake-and-bake ] unit-test\r
 \r
-[ t ] [\r
-    cell 8 = 8 5 ? 100000 * small-enough?\r
-] unit-test\r
+[ t ] [ 500000 small-enough? ] unit-test\r
 \r
 [ ] [ "sudoku" shake-and-bake ] unit-test\r
 \r
-[ t ] [\r
-    cell 8 = 20 10 ? 100000 * small-enough?\r
-] unit-test\r
+[ t ] [ 800000 small-enough? ] unit-test\r
 \r
 [ ] [ "hello-ui" shake-and-bake ] unit-test\r
 \r
+[ t ] [ 1300000 small-enough? ] unit-test\r
+\r
 [ "staging.math-compiler-ui-strip.image" ] [\r
     "hello-ui" deploy-config\r
     [ bootstrap-profile staging-image-name file-name ] bind\r
 ] unit-test\r
 \r
-[ t ] [\r
-    cell 8 = 35 17 ? 100000 * small-enough?\r
-] unit-test\r
-\r
 [ ] [ "maze" shake-and-bake ] unit-test\r
 \r
-[ t ] [\r
-    cell 8 = 30 15 ? 100000 * small-enough?\r
-] unit-test\r
+[ t ] [ 1200000 small-enough? ] unit-test\r
+\r
+[ ] [ "tetris" shake-and-bake ] unit-test\r
+\r
+[ t ] [ 1500000 small-enough? ] unit-test\r
 \r
 [ ] [ "bunny" shake-and-bake ] unit-test\r
 \r
-[ t ] [\r
-    cell 8 = 50 30 ? 100000 * small-enough?\r
-] unit-test\r
+[ t ] [ 2500000 small-enough? ] unit-test\r
 \r
 {\r
     "tools.deploy.test.1"\r
index 05bf3c964227c4bd40b4094590054fe92e296377..2dd334d0241270b7358a6522f164dcb7e748b0bc 100755 (executable)
@@ -4,7 +4,7 @@ USING: accessors qualified io.streams.c init fry namespaces
 assocs kernel parser lexer strings.parser tools.deploy.config
 vocabs sequences words words.private memory kernel.private
 continuations io prettyprint vocabs.loader debugger system
-strings sets ;
+strings sets vectors quotations byte-arrays ;
 QUALIFIED: bootstrap.stage2
 QUALIFIED: classes
 QUALIFIED: command-line
@@ -79,8 +79,8 @@ IN: tools.deploy.shaker
     [
         [
             props>> swap
-            '[ drop , member? not ] assoc-filter
-            sift-assoc f assoc-like
+            '[ drop , member? not ] assoc-filter sift-assoc
+            dup assoc-empty? [ drop f ] [ >alist >vector ] if
         ] keep (>>props)
     ] with each ;
 
@@ -93,7 +93,10 @@ IN: tools.deploy.shaker
                 "compiled-uses"
                 "constraints"
                 "declared-effect"
+                "default"
+                "default-method"
                 "default-output-classes"
+                "derived-from"
                 "identities"
                 "if-intrinsics"
                 "infer"
@@ -103,15 +106,18 @@ IN: tools.deploy.shaker
                 "loc"
                 "members"
                 "methods"
+                "method-class"
+                "method-generic"
                 "combination"
                 "cannot-infer"
-                "default-method"
+                "no-compile"
                 "optimizer-hooks"
                 "output-classes"
                 "participants"
                 "predicate"
                 "predicate-definition"
                 "predicating"
+                "tuple-dispatch-generic"
                 "slots"
                 "slot-names"
                 "specializer"
@@ -127,6 +133,8 @@ IN: tools.deploy.shaker
         
         strip-prettyprint? [
             {
+                "break-before"
+                "break-after"
                 "delimiter"
                 "flushable"
                 "foldable"
@@ -265,13 +273,27 @@ IN: tools.deploy.shaker
         21 setenv
     ] [ drop ] if ;
 
+: compress ( pred string -- )
+    "Compressing " prepend show
+    instances
+    dup H{ } clone [ [ ] cache ] curry map
+    become ; inline
+
+: compress-byte-arrays ( -- )
+    [ byte-array? ] "byte arrays" compress ;
+
+: compress-quotations ( -- )
+    [ quotation? ] "quotations" compress ;
+
+: compress-strings ( -- )
+    [ string? ] "strings" compress ;
+
 : finish-deploy ( final-image -- )
     "Finishing up" show
     >r { } set-datastack r>
     { } set-retainstack
     V{ } set-namestack
     V{ } set-catchstack
-    
     "Saving final image" show
     [ save-image-and-exit ] call-clear ;
 
@@ -295,7 +317,10 @@ SYMBOL: deploy-vocab
     deploy-vocab get vocab-main set-boot-quot*
     stripped-word-props >r
     stripped-globals strip-globals
-    r> strip-words ;
+    r> strip-words
+    compress-byte-arrays
+    compress-quotations
+    compress-strings ;
 
 : (deploy) ( final-image vocab config -- )
     #! Does the actual work of a deployment in the slave
old mode 100644 (file)
new mode 100755 (executable)
index 83da7f2..f61694d
@@ -33,10 +33,10 @@ IN: tools.memory
     [ [ write-cell ] each ] with-row ;
 
 : (data-room.) ( -- )
-    data-room 2 <groups> dup length [
+    data-room 2 <groups> [
         [ first2 ] [ number>string "Generation " prepend ] bi*
         write-total/used/free
-    ] 2each
+    ] each-index
     "Decks" write-total
     "Cards" write-total ;
 
index d78e6fcbea013db685d1cd3dd423b4f764ffcd5a..75ca5ede8c4060f9c6bcf63714d4d8ef2546880a 100755 (executable)
@@ -1,6 +1,6 @@
 IN: tools.profiler.tests
 USING: accessors tools.profiler tools.test kernel memory math
-threads alien tools.profiler.private sequences ;
+threads alien tools.profiler.private sequences compiler.units ;
 
 [ t ] [
     \ length counter>>
@@ -42,3 +42,15 @@ threads alien tools.profiler.private sequences ;
 [ 1 ] [ \ foobaz counter>> ] unit-test
 
 [ 2 ] [ \ fooblah counter>> ] unit-test
+
+: recompile-while-profiling-test ( -- ) ;
+
+[ ] [
+    [
+        333 [ recompile-while-profiling-test ] times
+        { recompile-while-profiling-test } compile
+        333 [ recompile-while-profiling-test ] times
+    ] profile
+] unit-test
+
+[ 666 ] [ \ recompile-while-profiling-test counter>> ] unit-test
index 2d4a6c3396cacdd68af56b119be47af57b5052a0..e002af8f6da9f72ba07af47f4ea419c89927bef9 100755 (executable)
@@ -1,6 +1,7 @@
 USING: tools.walker io io.streams.string kernel math
 math.private namespaces prettyprint sequences tools.test
-continuations math.parser threads arrays tools.walker.debug ;
+continuations math.parser threads arrays tools.walker.debug
+generic.standard sequences.private kernel.private ;
 IN: tools.walker.tests
 
 [ { } ] [
@@ -49,6 +50,10 @@ IN: tools.walker.tests
     [ 5 6 number= ] test-walker
 ] unit-test
 
+[ { 0 } ] [
+    [ 0 { array-capacity } declare ] test-walker
+] unit-test
+
 [ { f } ] [
     [ "XYZ" "XYZ" mismatch ] test-walker
 ] unit-test
@@ -97,6 +102,9 @@ IN: tools.walker.tests
 [ { 6 } ]
 [ [ [ 3 throw ] [ 2 * ] recover ] test-walker ] unit-test
 
+[ { T{ no-method f + nth } } ]
+[ [ [ 0 \ + nth ] [ ] recover ] test-walker ] unit-test
+
 [ { } ] [
     [ "a" "b" set "c" "d" set [ ] test-walker ] with-scope
 ] unit-test
index 07a5759af2ca7d4c5db8de6a56680ce0a1a6625d..f9055fb6cf714ee59abcb38c03b2372801f439b6 100755 (executable)
@@ -3,7 +3,7 @@
 USING: threads kernel namespaces continuations combinators
 sequences math namespaces.private continuations.private
 concurrency.messaging quotations kernel.private words
-sequences.private assocs models arrays accessors
+sequences.private assocs models models.filter arrays accessors
 generic generic.standard definitions ;
 IN: tools.walker
 
@@ -83,6 +83,9 @@ M: object add-breakpoint ;
 : (step-into-continuation) ( -- )
     continuation callstack >>call break ;
 
+: (step-into-call-next-method) ( class generic -- )
+    next-method-quot (step-into-quot) ;
+
 ! Messages sent to walker thread
 SYMBOL: step
 SYMBOL: step-out
@@ -132,6 +135,7 @@ SYMBOL: +stopped+
     { if [ (step-into-if) ] }
     { dispatch [ (step-into-dispatch) ] }
     { continuation [ (step-into-continuation) ] }
+    { (call-next-method) [ (step-into-call-next-method) ] }
 } [ "step-into" set-word-prop ] assoc-each
 
 {
index 5ccd6c7cd813f8b408f59a35a178b9eb426d3f84..4df92141baed6b7f6670e84b0f2349e7180adf74 100755 (executable)
@@ -1,6 +1,6 @@
 IN: ui.gadgets.scrollers.tests
-USING: ui.gadgets ui.gadgets.scrollers
-namespaces tools.test kernel models ui.gadgets.viewports
+USING: ui.gadgets ui.gadgets.scrollers namespaces tools.test
+kernel models models.compose models.range ui.gadgets.viewports
 ui.gadgets.labels ui.gadgets.grids ui.gadgets.frames
 ui.gadgets.sliders math math.vectors arrays sequences
 tools.test.ui ;
index e58fbc5925ee772802dede95a89f1bf4d903e0c9..2492348d56204349fe80bc6bfcf8098b1c6ad708 100755 (executable)
@@ -3,7 +3,8 @@
 USING: accessors arrays ui.gadgets ui.gadgets.viewports
 ui.gadgets.frames ui.gadgets.grids ui.gadgets.theme
 ui.gadgets.sliders ui.gestures kernel math namespaces sequences
-models combinators math.vectors classes.tuple ;
+models models.range models.compose
+combinators math.vectors classes.tuple ;
 IN: ui.gadgets.scrollers
 
 TUPLE: scroller viewport x y follows ;
index e5de7c2208a8ffb0400274f7dd2dd5d415a6a7ef..e58e4fe7e9dc3601ff19610253ddc759675113e6 100755 (executable)
@@ -1,4 +1,4 @@
-USING: help.markup help.syntax ui.gadgets models ;
+USING: help.markup help.syntax ui.gadgets models models.range ;
 IN: ui.gadgets.sliders
 
 HELP: elevator
index eb22a5a82332f41461d21f27eaeaf44107b786bd..120e8e8a4cd55038fc5a1ec66296895abdd168dd 100755 (executable)
@@ -3,7 +3,8 @@
 USING: accessors arrays ui.gestures ui.gadgets ui.gadgets.buttons
 ui.gadgets.frames ui.gadgets.grids math.order
 ui.gadgets.theme ui.render kernel math namespaces sequences
-vectors models math.vectors math.functions quotations colors ;
+vectors models models.range math.vectors math.functions
+quotations colors ;
 IN: ui.gadgets.sliders
 
 TUPLE: elevator direction ;
index 417826a680f8b1768806d68363468069f8e24a6f..12c365c6a48542182e912ed342f95fb0e3e59c58 100755 (executable)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors models sequences ui.gadgets.labels
-ui.gadgets.theme ui.gadgets.tracks ui.gadgets.worlds ui.gadgets
-ui kernel calendar ;
+USING: accessors models models.delay models.filter
+sequences ui.gadgets.labels ui.gadgets.theme ui.gadgets.tracks
+ui.gadgets.worlds ui.gadgets ui kernel calendar ;
 IN: ui.gadgets.status-bar
 
 : <status-bar> ( model -- gadget )
index 88bc2bcee73d22c9f56a9bf13890e4d72dc10df5..5c00fbfdb0b6a50db1d4a8d1f85f91705448e5d2 100755 (executable)
@@ -121,7 +121,7 @@ SYMBOL: drag-timer
 : start-drag-timer ( -- )
     hand-buttons get-global empty? [
         [ drag-gesture ]
-        300 milliseconds from-now
+        300 milliseconds hence
         100 milliseconds
         add-alarm drag-timer get-global >box
     ] when ;
index ae39b3e116be15f1684e8fe515542d1d3c618491..5cc955e03171502b5fc56ea0b79c06cfe65b0ca1 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: debugger ui.tools.workspace help help.topics kernel
-models ui.commands ui.gadgets ui.gadgets.panes
+models models.history ui.commands ui.gadgets ui.gadgets.panes
 ui.gadgets.scrollers ui.gadgets.tracks ui.gestures
 ui.gadgets.buttons compiler.units assocs words vocabs
 accessors ;
index f0454f5cc26c1fa70e1796b21cd1f3ba56c55249..12d327ab4386261dd81e3dacc23e3c1a294cef85 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: ui.gadgets colors kernel ui.render namespaces
-models sequences ui.gadgets.buttons
+models models.mapping sequences ui.gadgets.buttons
 ui.gadgets.packs ui.gadgets.labels tools.deploy.config
 namespaces ui.gadgets.editors ui.gadgets.borders ui.gestures
 ui.commands assocs ui.gadgets.tracks ui ui.tools.listener
index fcd3f9ab224c7933b6fed19e09b6f214546ae932..791d9bcfd79224813dd26ecef4ed57b73beff149 100755 (executable)
@@ -2,12 +2,12 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays assocs combinators continuations documents
 hashtables io io.styles kernel math math.order math.vectors
-models namespaces parser lexer prettyprint quotations sequences
-strings threads listener classes.tuple ui.commands ui.gadgets
-ui.gadgets.editors ui.gadgets.presentations ui.gadgets.worlds
-ui.gestures definitions calendar concurrency.flags
-concurrency.mailboxes ui.tools.workspace accessors sets
-destructors ;
+models models.delay namespaces parser lexer prettyprint
+quotations sequences strings threads listener classes.tuple
+ui.commands ui.gadgets ui.gadgets.editors
+ui.gadgets.presentations ui.gadgets.worlds ui.gestures
+definitions calendar concurrency.flags concurrency.mailboxes
+ui.tools.workspace accessors sets destructors ;
 IN: ui.tools.interactor
 
 ! If waiting is t, we're waiting for user input, and invoking
index f4320273673cebc3896ae9c1d7cfd7cc47e53f35..d08384913ea7c40b1c81b53f2ccb37b34f886924 100755 (executable)
@@ -2,12 +2,13 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors assocs ui.tools.interactor ui.tools.listener
 ui.tools.workspace help help.topics io.files io.styles kernel
-models namespaces prettyprint quotations sequences sorting
-source-files definitions strings tools.completion tools.crossref
-classes.tuple ui.commands ui.gadgets ui.gadgets.editors
-ui.gadgets.lists ui.gadgets.scrollers ui.gadgets.tracks
-ui.gestures ui.operations vocabs words vocabs.loader
-tools.vocabs unicode.case calendar ui ;
+models models.delay models.filter namespaces prettyprint
+quotations sequences sorting source-files definitions strings
+tools.completion tools.crossref classes.tuple ui.commands
+ui.gadgets ui.gadgets.editors ui.gadgets.lists
+ui.gadgets.scrollers ui.gadgets.tracks ui.gestures ui.operations
+vocabs words vocabs.loader tools.vocabs unicode.case calendar ui
+;
 IN: ui.tools.search
 
 TUPLE: live-search field list ;
index 8d205daebf39c60e567126681b9f6cf8de54c747..4398afa3e083cf57cbfb1dc5f8ec62c39ceeee50 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel concurrency.messaging inspector ui.tools.listener
 ui.tools.traceback ui.gadgets.buttons ui.gadgets.status-bar
-ui.gadgets.tracks ui.commands ui.gadgets models
+ui.gadgets.tracks ui.commands ui.gadgets models models.filter
 ui.tools.workspace ui.gestures ui.gadgets.labels ui threads
 namespaces tools.walker assocs combinators ;
 IN: ui.tools.walker
index dda9a1dc0e5cedeaade575b1177a23a5820ab214..f8228b3177af64a54862d704eea515a8a85d8840 100755 (executable)
@@ -207,9 +207,9 @@ SYMBOLS: msg-obj class-name-ptr mouse-captured ;
     wParam keystroke>gesture <key-up>
     hWnd window-focus send-gesture drop ;
 
-: set-window-active ( hwnd uMsg wParam lParam ? -- n )
-    >r 4dup r> 2nip nip
-    swap window set-world-active? DefWindowProc ;
+:: set-window-active ( hwnd uMsg wParam lParam ? -- n )
+    ? hwnd window set-world-active?
+    hwnd uMsg wParam lParam DefWindowProc ;
 
 : handle-wm-syscommand ( hWnd uMsg wParam lParam -- n )
     {
index 644276ef7d869e0cc1ff33c2fe0a3218d748e3cf..7d3d7577053733925ce06eb813a57a38804650ed 100755 (executable)
@@ -37,7 +37,8 @@ FUNCTION: int execve ( char* path, char** argv, char** envp ) ;
     >r [ first ] [ ] bi r> exec-with-env ;
 
 : with-fork ( child parent -- )
-    fork-process dup zero? -roll swap curry if ; inline
+    [ [ fork-process dup zero? ] dip [ drop ] prepose ] dip
+    if ; inline
 
 : SIGKILL 9 ; inline
 : SIGTERM 15 ; inline
index 07eb2950fad1a64bcb2668916841bdea9e11a611..083700493d02702f2fde96c1c2973b28541b6511 100755 (executable)
@@ -4,7 +4,7 @@
 USING: alien alien.c-types alien.syntax kernel libc structs sequences
        continuations byte-arrays strings
        math namespaces system combinators vocabs.loader qualified
-       accessors inference macros locals shuffle arrays.lib 
+       accessors inference macros locals generalizations 
        unix.types debugger io prettyprint ;
 
 IN: unix
index 192592489e35a04065d65d7b67b59059bcd02f88..531332eadaaeb6819af39daf9aa3737204e00f9c 100644 (file)
@@ -2,12 +2,12 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-       <t:title>Planet Factor Administration</t:title>
+       <t:title>Concatenative Planet: Administration</t:title>
 
        <ul>
                <t:bind-each t:name="blogroll">
                        <li>
-                               <t:a t:href="$planet-factor/admin/edit-blog" t:query="id">
+                               <t:a t:href="$planet/admin/edit-blog" t:query="id">
                                        <t:label t:name="name" />
                                </t:a>
                        </li>
@@ -15,8 +15,8 @@
        </ul>
 
        <div>
-               <t:a t:href="$planet-factor/admin/new-blog">Add Blog</t:a>
-               | <t:button t:action="$planet-factor/admin/update" class="link-button link">Update</t:button>
+               <t:a t:href="$planet/admin/new-blog">Add Blog</t:a>
+               | <t:button t:action="$planet/admin/update" class="link-button link">Update</t:button>
        </div>
 
 </t:chloe>
index fd9c659f59835226cfc5ed19ddfcf541d3d25d24..d1c7013c68137f8c478102215f1db77b7167c1dc 100644 (file)
@@ -4,7 +4,7 @@
 
        <t:title>Edit Blog</t:title>
 
-       <t:form t:action="$planet-factor/admin/edit-blog" t:for="id">
+       <t:form t:action="$planet/admin/edit-blog" t:for="id">
 
                <table>
 
@@ -29,6 +29,6 @@
 
        </t:form>
 
-       <t:button t:action="$planet-factor/admin/delete-blog" t:for="id" class="link-button link">Delete</t:button>
+       <t:button t:action="$planet/admin/delete-blog" t:for="id" class="link-button link">Delete</t:button>
 
 </t:chloe>
diff --git a/extra/webapps/planet/mini-planet.xml b/extra/webapps/planet/mini-planet.xml
deleted file mode 100644 (file)
index 661c2dc..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version='1.0' ?>
-
-<t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
-
-       <t:bind-each t:name="postings">
-
-               <p class="news">
-                       <strong><t:label t:name="title" /></strong> <br/>
-                       <t:a value="link" class="more">Read More...</t:a>
-               </p>
-
-       </t:bind-each>
-
-</t:chloe>
index 4a9638da03f6ef160f67e8aa526c931f9549dcd9..6f75addda55dd58ce21cc7072c67734ff028d6cf 100644 (file)
@@ -4,7 +4,7 @@
 
        <t:title>Edit Blog</t:title>
 
-       <t:form t:action="$planet-factor/admin/new-blog">
+       <t:form t:action="$planet/admin/new-blog">
 
                <table>
 
index 6c0affd17f44e317d7f22f8ebade515ee27dd7d5..f4e390056a6c5689a1886b286460435aedb76aed 100644 (file)
@@ -5,9 +5,9 @@
        <t:style t:include="resource:extra/webapps/planet/planet.css" />
 
        <div class="navbar">
-                 <t:a t:href="$planet-factor/list">Front Page</t:a>
-               | <t:a t:href="$planet-factor/feed.xml">Atom Feed</t:a>
-               | <t:a t:href="$planet-factor/admin">Admin</t:a>
+                 <t:a t:href="$planet/list">Front Page</t:a>
+               | <t:a t:href="$planet/feed.xml">Atom Feed</t:a>
+               | <t:a t:href="$planet/admin">Admin</t:a>
 
                <t:if t:code="furnace.auth:logged-in?">
                        <t:if t:code="furnace.auth.features.edit-profile:allow-edit-profile?">
index ca74b7e6421fe066f89d8549f9c96220efa4565f..10e706598e08c2be776f9edcc4f014b38cee7587 100755 (executable)
@@ -17,13 +17,13 @@ furnace.auth
 furnace.syndication ;
 IN: webapps.planet
 
-TUPLE: planet-factor < dispatcher ;
+TUPLE: planet < dispatcher ;
 
-SYMBOL: can-administer-planet-factor?
+SYMBOL: can-administer-planet?
 
-can-administer-planet-factor? define-capability
+can-administer-planet? define-capability
 
-TUPLE: planet-factor-admin < dispatcher ;
+TUPLE: planet-admin < dispatcher ;
 
 TUPLE: blog id name www-url feed-url ;
 
@@ -65,7 +65,7 @@ posting "POSTINGS"
 : <edit-blogroll-action> ( -- action )
     <page-action>
         [ blogroll "blogroll" set-value ] >>init
-        { planet-factor "admin" } >>template ;
+        { planet "admin" } >>template ;
 
 : <planet-action> ( -- action )
     <page-action>
@@ -74,12 +74,12 @@ posting "POSTINGS"
             postings "postings" set-value
         ] >>init
 
-        { planet-factor "planet" } >>template ;
+        { planet "planet" } >>template ;
 
 : <planet-feed-action> ( -- action )
     <feed-action>
         [ "Planet Factor" ] >>title
-        [ URL" $planet-factor" ] >>url
+        [ URL" $planet" ] >>url
         [ postings ] >>entries ;
 
 :: <posting> ( entry name -- entry' )
@@ -111,7 +111,7 @@ posting "POSTINGS"
     <action>
         [
             update-cached-postings
-            URL" $planet-factor/admin" <redirect>
+            URL" $planet/admin" <redirect>
         ] >>submit ;
 
 : <delete-blog-action> ( -- action )
@@ -120,7 +120,7 @@ posting "POSTINGS"
 
         [
             "id" value <blog> delete-tuples
-            URL" $planet-factor/admin" <redirect>
+            URL" $planet/admin" <redirect>
         ] >>submit ;
 
 : validate-blog ( -- )
@@ -136,7 +136,7 @@ posting "POSTINGS"
 : <new-blog-action> ( -- action )
     <page-action>
 
-        { planet-factor "new-blog" } >>template
+        { planet "new-blog" } >>template
 
         [ validate-blog ] >>validate
 
@@ -146,7 +146,7 @@ posting "POSTINGS"
             [ insert-tuple ]
             [
                 <url>
-                    "$planet-factor/admin/edit-blog" >>path
+                    "$planet/admin/edit-blog" >>path
                     swap id>> "id" set-query-param
                 <redirect>
             ]
@@ -161,7 +161,7 @@ posting "POSTINGS"
             "id" value <blog> select-tuple from-object
         ] >>init
 
-        { planet-factor "edit-blog" } >>template
+        { planet "edit-blog" } >>template
 
         [
             validate-integer-id
@@ -174,15 +174,15 @@ posting "POSTINGS"
             [ update-tuple ]
             [
                 <url>
-                    "$planet-factor/admin" >>path
+                    "$planet/admin" >>path
                     swap id>> "id" set-query-param
                 <redirect>
             ]
             tri
         ] >>submit ;
 
-: <planet-factor-admin> ( -- responder )
-    planet-factor-admin new-dispatcher
+: <planet-admin> ( -- responder )
+    planet-admin new-dispatcher
         <edit-blogroll-action> "blogroll" add-main-responder
         <update-action> "update" add-responder
         <new-blog-action> "new-blog" add-responder
@@ -190,15 +190,15 @@ posting "POSTINGS"
         <delete-blog-action> "delete-blog" add-responder
     <protected>
         "administer Planet Factor" >>description
-        { can-administer-planet-factor? } >>capabilities ;
+        { can-administer-planet? } >>capabilities ;
 
-: <planet-factor> ( -- responder )
-    planet-factor new-dispatcher
+: <planet> ( -- responder )
+    planet new-dispatcher
         <planet-action> "list" add-main-responder
         <planet-feed-action> "feed.xml" add-responder
-        <planet-factor-admin> "admin" add-responder
+        <planet-admin> "admin" add-responder
     <boilerplate>
-        { planet-factor "planet-common" } >>template ;
+        { planet "planet-common" } >>template ;
 
 : start-update-task ( db params -- )
     '[ , , [ update-cached-postings ] with-db ] 10 minutes every drop ;
index fe4d23bd3bbc74feca29736f4ff4d42c305c7b8f..340e6c4bee9a81fda7bed238437eac18b4485cd6 100644 (file)
@@ -2,7 +2,7 @@
 
 <t:chloe xmlns:t="http://factorcode.org/chloe/1.0">
 
-       <t:title>Planet Factor</t:title>
+       <t:title>Concatenative Planet</t:title>
 
        <table width="100%" cellpadding="10">
                <tr>
diff --git a/extra/webapps/wiki/initial-content/Farkup.txt b/extra/webapps/wiki/initial-content/Farkup.txt
new file mode 100644 (file)
index 0000000..8814af6
--- /dev/null
@@ -0,0 +1,63 @@
+Look at the source to this page by clicking *Edit* to compare the farkup language with resulting output.
+
+= level 1 heading =
+
+== level 2 heading ==
+
+=== level 3 heading ===
+
+==== level 4 heading ====
+
+Here is a paragraph of text, with _emphasized_ and *strong* text, together with an inline %code snippet%. Did you know that E=mc^2^, and L~2~ spaces are cool? Of course, if you want to include \_ special \* characters \^ you \~ can \% do that, too.
+
+You can make [[Wiki Links]] just like that, as well as links to external sites: [[http://sbcl.sourceforge.net]]. [[Factor|Custom link text]] can be used [[http://www.apple.com|with both types of links]].
+
+Images can be embedded in the text:
+
+[[image:http://factorcode.org/graphics/logo.png]]
+
+- a list
+- with three
+- items
+
+|a table|with|four|columns|
+|and|two|rows|...|
+
+Here is some code:
+
+[{HAI
+CAN HAS STDIO?
+VISIBLE "HAI WORLD!"
+KTHXBYE}]
+
+There is syntax highlighting various languages, too:
+
+[factor{PEG: parse-request-line ( string -- triple )
+    #! Triple is { method url version }
+    [ 
+        'space' ,
+        'http-method' ,
+        'space' ,
+        'url' ,
+        'space' ,
+        'http-version' ,
+        'space' ,
+    ] seq* just ;}]
+
+Some Java:
+
+[java{/**
+ * Returns the extension of the specified filename, or an empty
+ * string if there is none.
+ * @param path The path
+ */
+public static String getFileExtension(String path)
+{
+    int fsIndex = getLastSeparatorIndex(path);
+    int index = path.lastIndexOf('.');
+    // there could be a dot in the path and no file extension
+    if(index == -1 || index < fsIndex )
+        return "";
+    else
+        return path.substring(index);
+}}]
diff --git a/extra/webapps/wiki/initial-content/Front Page.txt b/extra/webapps/wiki/initial-content/Front Page.txt
new file mode 100644 (file)
index 0000000..37351ee
--- /dev/null
@@ -0,0 +1,5 @@
+Congratulations, you are now running your very own Wiki.
+
+You can now click *Edit* below and begin editing the content of the [[Front Page]]. This Wiki uses [[Farkup]] to mark up text.
+
+Two special article names are recognized by the Wiki: [[Sidebar]] and [[Footer]]. They do not exist by default, but if you create them, they will be visible on every page.
index 0abd36a7cd936d2965a5efdd90f9095170f2af32..5cddcee628294a9fe8bcd69a84e3f15111097041 100644 (file)
@@ -13,6 +13,7 @@
                <t:a t:href="$wiki">Front Page</t:a>
                | <t:a t:href="$wiki/articles">All Articles</t:a>
                | <t:a t:href="$wiki/changes">Recent Changes</t:a>
+               | <t:a t:href="$wiki/random">Random Article</t:a>
 
                <t:if t:code="furnace.auth:logged-in?">
 
                                </td>
                        </t:if>
                </tr>
+
+               <tr>
+                       <td>
+                               <t:bind t:name="footer">
+                                       <small>
+                                               <t:farkup t:name="content" />
+                                       </small>
+                               </t:bind>
+                       </td>
+               </tr>
        </table>
 
 </t:chloe>
index 77ee24266884eda5a3ea5b8d552b9ea84f659d18..3c87f3cd4926105c486cceee6183907e01420fc4 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2008 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel hashtables calendar
+USING: accessors kernel hashtables calendar random assocs
 namespaces splitting sequences sorting math.order present
+io.files io.encodings.ascii
 syndication
 html.components html.forms
 http.server
@@ -115,6 +116,14 @@ M: revision feed-entry-url id>> revision-url ;
 
         { wiki "view" } >>template ;
 
+: <random-article-action> ( -- action )
+    <action>
+        [
+            article new select-tuples random
+            [ title>> ] [ "Front Page" ] if*
+            view-url <redirect>
+        ] >>display ;
+
 : amend-article ( revision article -- )
     swap id>> >>revision update-tuple ;
 
@@ -286,15 +295,15 @@ M: revision feed-entry-url id>> revision-url ;
         { wiki "page-common" } >>template ;
 
 : init-sidebar ( -- )
-    "Sidebar" latest-revision [
-        "sidebar" [ from-object ] nest-form
-    ] when* ;
+    "Sidebar" latest-revision [ "sidebar" [ from-object ] nest-form ] when*
+    "Footer" latest-revision [ "footer" [ from-object ] nest-form ] when* ;
 
 : <wiki> ( -- dispatcher )
     wiki new-dispatcher
         <main-article-action> <article-boilerplate> "" add-responder
         <view-article-action> <article-boilerplate> "view" add-responder
         <view-revision-action> <article-boilerplate> "revision" add-responder
+        <random-article-action> "random" add-responder
         <list-revisions-action> <article-boilerplate> "revisions" add-responder
         <list-revisions-feed-action> "revisions.atom" add-responder
         <diff-action> <article-boilerplate> "diff" add-responder
@@ -309,3 +318,15 @@ M: revision feed-entry-url id>> revision-url ;
     <boilerplate>
         [ init-sidebar ] >>init
         { wiki "wiki-common" } >>template ;
+
+: init-wiki ( -- )
+    "resource:extra/webapps/wiki/initial-content" directory* keys
+    [
+        [ ascii file-contents ] [ file-name "." split1 drop ] bi
+        f <revision>
+            swap >>title
+            swap >>content
+            "slava" >>author
+            now >>date
+        add-revision
+    ] each ;
index 6d65f10783b36467092cc9b938fd34894c33d03c..1ae7f63a27f9e4b71b132ae50b2964589ea7ac0f 100644 (file)
@@ -25,7 +25,7 @@ webapps.wee-url
 webapps.user-admin ;
 IN: websites.concatenative
 
-: test-db ( -- db params ) "resource:test.db" sqlite-db ;
+: test-db ( -- params db ) "resource:test.db" sqlite-db ;
 
 : init-factor-db ( -- )
     test-db [
@@ -48,7 +48,7 @@ TUPLE: factor-website < dispatcher ;
         <blogs> "blogs" add-responder
         <todo-list> "todo" add-responder
         <pastebin> "pastebin" add-responder
-        <planet-factor> "planet" add-responder
+        <planet> "planet" add-responder
         <wiki> "wiki" add-responder
         <wee-url> "wee-url" add-responder
         <user-admin> "user-admin" add-responder
index c04fd8f544b278d3bd1eb4db605361f3534075d5..394bec2dfba3af9d4b873b8f09ddb9cb4e70de2a 100755 (executable)
@@ -1,5 +1,5 @@
 USING: kernel windows.com windows.com.syntax windows.ole32
-alien alien.syntax tools.test libc alien.c-types arrays.lib 
+alien alien.syntax tools.test libc alien.c-types 
 namespaces arrays continuations accessors math windows.com.wrapper
 windows.com.wrapper.private destructors effects ;
 IN: windows.com.tests
index e0ea65e8be2d49c37ef1a1afc02f0f5ee4bd83b3..dd7d058a77a8f7c6db1e122ad66d988889c0210d 100755 (executable)
@@ -1,6 +1,6 @@
 USING: alien alien.c-types effects kernel windows.ole32
-parser lexer splitting grouping sequences.lib sequences namespaces
-assocs quotations shuffle accessors words macros alien.syntax
+parser lexer splitting grouping sequences namespaces
+assocs quotations generalizations accessors words macros alien.syntax
 fry arrays ;
 IN: windows.com.syntax
 
index 89b199a38bbffcc1a4eca9cc3e8ef880f3613453..c863bb27621cb25c22ac6a73928ac262bedb332b 100755 (executable)
@@ -5,7 +5,7 @@ IN: windows.com.wrapper
 \r
 HELP: <com-wrapper>\r
 { $values { "implementations" "an assoc relating COM interface names to arrays of quotations implementing that interface" } { "wrapper" "a " { $link com-wrapper } " tuple" } }\r
-{ $description "Constructs a " { $link com-wrapper } " tuple. Each key in the " { $snippet "implementations" } " assoc must be the name of an interface defined with " { $link POSTPONE: COM-INTERFACE: } ". The corresponding value must be an array of quotations implementing the methods of that interface in order, including those of its parent interfaces. The " { $snippet "IUnknown" } " methods (" { $link IUnknown::QueryInterface } ", " { $link IUnknown::AddRef } ", and " { $link IUnknown::Release } ") will be defined automatically and must not be specified in the array. These quotations should have stack effects mirroring those of the interface methods being implemented; for example, a method " { $snippet "void foobar ( int foo, int bar )" } " should be implemented with a quotation of effect " { $snippet "( this foo bar -- )" } ". The " { $snippet "this" } " parameter (that is, the leftmost parameter of any COM method) will be automatically converted from an alien pointer to the underlying Factor object before the quotation is invoked.\n\nThe resulting wrapper can be applied to a Factor object using the " { $link com-wrap } " word. The COM interface pointer returned by " { $snippet "com-wrap" } " can then be passed to C functions requiring a COM object as a parameter. The vtables constructed by " { $snippet "<com-wrapper>" } " are stored on the non-GC heap in order to be accessible to C functions; when the wrapper objects and its vtables are no longer needed, the object's resources must be freed using " { $link dispose } ".\n\nExample:" }\r
+{ $description "Constructs a " { $link com-wrapper } " tuple. Each key in the " { $snippet "implementations" } " assoc must be the name of an interface defined with " { $link POSTPONE: COM-INTERFACE: } ". The corresponding value must be an array of quotations implementing the methods of that interface in order, including those of its parent interfaces. The " { $snippet "IUnknown" } " methods (" { $link IUnknown::QueryInterface } ", " { $link IUnknown::AddRef } ", and " { $link IUnknown::Release } ") will be defined automatically and must not be specified in the array. These quotations should have stack effects mirroring those of the interface methods being implemented; for example, a method " { $snippet "void foobar ( int foo, int bar )" } " should be implemented with a quotation of effect " { $snippet "( this foo bar -- )" } ". The " { $snippet "this" } " parameter (that is, the leftmost parameter of any COM method) will be automatically converted from an alien pointer to the underlying Factor object before the quotation is invoked.\n\nThe resulting wrapper can be applied to a Factor object using the " { $link com-wrap } " word. The COM interface pointer returned by " { $snippet "com-wrap" } " can then be passed to C functions requiring a COM object as a parameter. The vtables constructed by " { $snippet "<com-wrapper>" } " are stored on the non-GC heap in order to be accessible to C functions; when the wrapper object and its vtables are no longer needed, the object's resources must be freed using " { $link dispose } ".\n\nExample:" }\r
 { $code <"\r
 COM-INTERFACE: ISimple IUnknown {216fb341-0eb2-44b1-8edb-60b76e353abc}\r
     HRESULT returnOK ( )\r
@@ -38,4 +38,4 @@ HELP: com-wrap
 { $description "Allocates a COM object using the implementations in the " { $snippet "wrapper" } " object for the vtables and " { $snippet "object" } " for the \"this\" parameter. The COM object is allocated on the heap with an initial reference count of 1. The object will automatically deallocate itself when its reference count reaches 0 as a result of calling " { $link IUnknown::Release } " or " { $link com-release } " on it.\n\nNote that if " { $snippet "wrapper" } " implements multiple interfaces, you cannot count on the returned COM object pointer implementing any particular interface beyond " { $snippet "IUnknown" } ". You will need to use " { $link com-query-interface } " or " { $link IUnknown::QueryInterface } " to ask the object for the particular interface you need." } ;\r
 \r
 HELP: com-wrapper\r
-{ $class-description "The tuple class used to store COM wrapper information. Objects of this class should be treated as opaque by user code. A com-wrapper can be constructed using the " { $link <com-wrapper> } " constructor and applied to a Factor object using " { $link com-wrap } "." } ;\r
+{ $class-description "The tuple class used to store COM wrapper information. Objects of this class should be treated as opaque by user code. A com-wrapper can be constructed using the " { $link <com-wrapper> } " constructor and applied to a Factor object using " { $link com-wrap } ". When no longer needed, release the com-wrapper's internally allocated data with " { $link dispose } "." } ;\r
index 266439ad799a848a01fb3524e6286fc0b3e2421d..40c61dfbe7a556586289983d6e5d27d0f9ba2a88 100755 (executable)
@@ -1,9 +1,8 @@
 USING: alien alien.c-types windows.com.syntax
 windows.com.syntax.private windows.com continuations kernel
-sequences.lib namespaces windows.ole32 libc vocabs
-assocs accessors arrays sequences quotations combinators
-math words compiler.units destructors fry
-math.parser combinators.lib ;
+namespaces windows.ole32 libc vocabs assocs accessors arrays
+sequences quotations combinators math words compiler.units
+destructors fry math.parser generalizations ;
 IN: windows.com.wrapper
 
 TUPLE: com-wrapper vtbls disposed ;
index 49a04dcb48625ca5de78a5017b57dc2e35bfa309..241eddf9f0c825c7c8ff0f38dc8b2c609cc267c5 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2006 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien alien.syntax parser namespaces kernel math
-windows.types shuffle math.bitfields alias ;
+windows.types generalizations math.bitfields alias ;
 IN: windows.user32
 
 ! HKL for ActivateKeyboardLayout
@@ -1285,10 +1285,10 @@ FUNCTION: void SetLastErrorEx ( DWORD dwErrCode, DWORD dwType ) ;
 ! FUNCTION: SetWindowPlacement
 FUNCTION: BOOL SetWindowPos ( HWND hWnd, HWND hWndInsertAfter, int X, int Y, int cx, int cy, UINT uFlags ) ;
 
-: HWND_BOTTOM ALIEN: 1 ;
-: HWND_NOTOPMOST ALIEN: -2 ;
-: HWND_TOP ALIEN: 0 ;
-: HWND_TOPMOST ALIEN: -1 ;
+: HWND_BOTTOM ( -- alien ) 1 <alien> ;
+: HWND_NOTOPMOST ( -- alien ) -2 <alien> ;
+: HWND_TOP ( -- alien ) 0 <alien> ;
+: HWND_TOPMOST ( -- alien ) -1 <alien> ;
 
 ! FUNCTION: SetWindowRgn
 ! FUNCTION: SetWindowsHookA
index 402c76dc0126defb0a88d8821b90648682bcbd00..ab061530fec23d44157f06cefe736b0d7a1912be 100755 (executable)
@@ -14,7 +14,7 @@ T{ not-yes/no f 1 41 "maybe" } "<?xml version='1.0' standalone='maybe'?><x/>" xm
 T{ extra-attrs f 1 32 V{ T{ name f "" "foo" f } }
 } "<?xml version='1.1' foo='bar'?><x/>" xml-error-test
 T{ bad-version f 1 28 "5 million" } "<?xml version='5 million'?><x/>" xml-error-test
-T{ notags f 1 0 } "" xml-error-test
+T{ notags f } "" xml-error-test
 T{ multitags } "<x/><y/>" xml-error-test
 T{ bad-prolog  f 1 26 T{ prolog f "1.0" "UTF-8" f }
 } "<x/><?xml version='1.0'?>" xml-error-test
index a2183edbc9f936c88ec0c59a44903fac2ea423d8..55b6bbe26a945c87a288834b28cdca063383d66b 100755 (executable)
@@ -45,7 +45,6 @@ TAGS>
             T{ employee f "Jane" "CFO" }
         }
         "PUBLIC"
-        "This is a great company"
     }
 ] [
     "resource:extra/xmode/utilities/test.xml"
index 300c95c430ae2cc289dbc718d0c33bfa0de9926d..5c9d050468995654569ed81c5ee3739f363dbec6 100644 (file)
 (defvar factor-mode-syntax-table nil
   "Syntax table used while in Factor mode.")
 
+(defcustom factor-display-compilation-output t
+  "Display the REPL buffer before compiling files."
+  :type '(choice (const :tag "Enable" t) (const :tag "Disable" nil))
+  :group 'factor)
+
+
 (if factor-mode-syntax-table
     ()
   (let ((i 0))
 
 (defun factor-run-file ()
   (interactive)
+  (when (and (buffer-modified-p)
+                        (y-or-n-p (format "Save file %s? " (buffer-file-name))))
+       (save-buffer))
+  (when factor-display-compilation-output
+       (factor-display-output-buffer))
   (comint-send-string "*factor*" (format "\"%s\"" (buffer-file-name)))
   (comint-send-string "*factor*" " run-file\n"))
 
+(defun factor-display-output-buffer ()
+  (with-current-buffer "*factor*"
+       (goto-char (point-max))
+       (unless (get-buffer-window (current-buffer) t)
+         (display-buffer (current-buffer) t))))
+
 ;; (defun factor-send-region (start end)
 ;;   (interactive "r")
 ;;   (comint-send-region "*factor*" start end)
index 7fdf9ccdb2f9c41e56ae27a2485c8c9ee5915dfa..5b4ff3b8321c341cb82b6e0d5d9ff0d0c8240912 100755 (executable)
@@ -62,7 +62,7 @@ CELL allot_alien(CELL delegate, CELL displacement)
        {
                F_ALIEN *delegate_alien = untag_object(delegate);
                displacement += delegate_alien->displacement;
-               alien->alien = F;
+               alien->alien = delegate_alien->alien;
        }
        else
                alien->alien = delegate;
index e0abdc5a61bbe3f7826099e303d5c6b2aea3a840..03661999c52fc49811bf08d25b0ca28efcb5ef81 100755 (executable)
@@ -308,6 +308,8 @@ DEFINE_PRIMITIVE(code_room)
 /* Dump all code blocks for debugging */
 void dump_heap(F_HEAP *heap)
 {
+       CELL size = 0;
+
        F_BLOCK *scan = first_block(heap);
 
        while(scan)
@@ -319,9 +321,11 @@ void dump_heap(F_HEAP *heap)
                        status = "free";
                        break;
                case B_ALLOCATED:
+                       size += object_size(block_to_compiled(scan)->relocation);
                        status = "allocated";
                        break;
                case B_MARKED:
+                       size += object_size(block_to_compiled(scan)->relocation);
                        status = "marked";
                        break;
                default:
@@ -333,6 +337,8 @@ void dump_heap(F_HEAP *heap)
 
                scan = next_block(heap,scan);
        }
+       
+       printf("%ld bytes of relocation data\n",size);
 }
 
 /* Compute where each block is going to go, after compaction */
index be1d2c0c1843bf72c67cf4c8bbd2167f7ab40485..48d9a2dea81147e0a3f89c7451d2a3ce9c38a140 100755 (executable)
@@ -322,8 +322,16 @@ void safe_write(int fd, void *data, size_t size)
 
 void safe_read(int fd, void *data, size_t size)
 {
-       if(read(fd,data,size) != size)
-               fatal_error("error reading fd",errno);
+       ssize_t bytes = read(fd,data,size);
+       if(bytes < 0)
+       {
+               if(errno == EINTR)
+                       safe_read(fd,data,size);
+               else
+                       fatal_error("error reading fd",errno);
+       }
+       else if(bytes != size)
+               fatal_error("unexpected eof on fd",bytes);
 }
 
 void *stdin_loop(void *arg)
@@ -339,7 +347,7 @@ void *stdin_loop(void *arg)
 
                for(;;)
                {
-                       size_t bytes = read(0,buf,sizeof(buf));
+                       ssize_t bytes = read(0,buf,sizeof(buf));
                        if(bytes < 0)
                        {
                                if(errno == EINTR)
index 6d220de9035d5666105ca433ca4449787ecc68eb..6db03148cd7fa56d3a2e1ff2e6e414164c2290bf 100755 (executable)
@@ -27,6 +27,8 @@ typedef char F_SYMBOL;
 #define OPEN_WRITE(path) fopen(path,"wb")
 #define FPRINTF(stream,format,arg) fprintf(stream,format,arg)
 
+void start_thread(void *(*start_routine)(void *));
+
 void init_ffi(void);
 void ffi_dlopen(F_DLL *dll);
 void *ffi_dlsym(F_DLL *dll, F_SYMBOL *symbol);
index 58a4aa035e8050ab35208977d22d48476abf3c69..27e903178b3b8427b835234e70d9db6ed661dee1 100755 (executable)
@@ -35,8 +35,6 @@ void update_word_xt(F_WORD *word)
        /* If we just enabled the profiler, reset call count */
        if(profiling_p)
        {
-               word->counter = tag_fixnum(0);
-
                if(!word->profiling)
                {
                        REGISTER_UNTAGGED(word);
@@ -71,6 +69,8 @@ void set_profiling(bool profiling)
        for(i = 0; i < length; i++)
        {
                F_WORD *word = untag_word(array_nth(untag_array(words),i));
+               if(profiling)
+                       word->counter = tag_fixnum(0);
                update_word_xt(word);
        }
 
index e092aab4bf455458a27271d97ebde7adc4958bdd..7eab41688a389585f1dead4dcc4b0ba6f4a8ca38 100755 (executable)
@@ -25,6 +25,13 @@ bool jit_fast_dispatch_p(F_ARRAY *array, CELL i)
                && array_nth(array,i + 1) == userenv[JIT_DISPATCH_WORD];
 }
 
+bool jit_ignore_declare_p(F_ARRAY *array, CELL i)
+{
+       return (i + 1) < array_capacity(array)
+               && type_of(array_nth(array,i)) == ARRAY_TYPE
+               && array_nth(array,i + 1) == userenv[JIT_DECLARE_WORD];
+}
+
 F_ARRAY *code_to_emit(CELL name)
 {
        return untag_object(array_nth(untag_object(userenv[name]),0));
@@ -72,8 +79,24 @@ bool jit_stack_frame_p(F_ARRAY *array)
 
        for(i = 0; i < length - 1; i++)
        {
-               if(type_of(array_nth(array,i)) == WORD_TYPE)
-                       return true;
+               CELL obj = array_nth(array,i);
+               if(type_of(obj) == WORD_TYPE)
+               {
+                       if(obj != userenv[JIT_TAG_WORD]
+                               && obj != userenv[JIT_EQP_WORD]
+                               && obj != userenv[JIT_SLOT_WORD]
+                               && obj != userenv[JIT_DROP_WORD]
+                               && obj != userenv[JIT_DUP_WORD]
+                               && obj != userenv[JIT_TO_R_WORD]
+                               && obj != userenv[JIT_FROM_R_WORD]
+                               && obj != userenv[JIT_SWAP_WORD]
+                               && obj != userenv[JIT_OVER_WORD]
+                               && obj != userenv[JIT_FIXNUM_MINUS_WORD]
+                               && obj != userenv[JIT_FIXNUM_GE_WORD])
+                       {
+                               return true;
+                       }
+               }
        }
 
        return false;
@@ -131,24 +154,74 @@ void jit_compile(CELL quot, bool relocate)
                switch(type_of(obj))
                {
                case WORD_TYPE:
-                       /* Emit the epilog before the primitive call gate
-                       so that we save the C stack pointer minus the
-                       current stack frame. */
-                       word = untag_object(obj);
+                       /* Intrinsics */
+                       if(obj == userenv[JIT_TAG_WORD])
+                       {
+                               EMIT(JIT_TAG,0);
+                       }
+                       else if(obj == userenv[JIT_EQP_WORD])
+                       {
+                               GROWABLE_ARRAY_ADD(literals,T);
+                               EMIT(JIT_EQP,literals_count - 1);
+                       }
+                       else if(obj == userenv[JIT_SLOT_WORD])
+                       {
+                               EMIT(JIT_SLOT,0);
+                       }
+                       else if(obj == userenv[JIT_DROP_WORD])
+                       {
+                               EMIT(JIT_DROP,0);
+                       }
+                       else if(obj == userenv[JIT_DUP_WORD])
+                       {
+                               EMIT(JIT_DUP,0);
+                       }
+                       else if(obj == userenv[JIT_TO_R_WORD])
+                       {
+                               EMIT(JIT_TO_R,0);
+                       }
+                       else if(obj == userenv[JIT_FROM_R_WORD])
+                       {
+                               EMIT(JIT_FROM_R,0);
+                       }
+                       else if(obj == userenv[JIT_SWAP_WORD])
+                       {
+                               EMIT(JIT_SWAP,0);
+                       }
+                       else if(obj == userenv[JIT_OVER_WORD])
+                       {
+                               EMIT(JIT_OVER,0);
+                       }
+                       else if(obj == userenv[JIT_FIXNUM_MINUS_WORD])
+                       {
+                               EMIT(JIT_FIXNUM_MINUS,0);
+                       }
+                       else if(obj == userenv[JIT_FIXNUM_GE_WORD])
+                       {
+                               GROWABLE_ARRAY_ADD(literals,T);
+                               EMIT(JIT_FIXNUM_GE,literals_count - 1);
+                       }
+                       else
+                       {
+                               /* Emit the epilog before the primitive call gate
+                               so that we save the C stack pointer minus the
+                               current stack frame. */
+                               word = untag_object(obj);
 
-                       GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
+                               GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
 
-                       if(i == length - 1)
-                       {
-                               if(stack_frame)
-                                       EMIT(JIT_EPILOG,0);
+                               if(i == length - 1)
+                               {
+                                       if(stack_frame)
+                                               EMIT(JIT_EPILOG,0);
 
-                               EMIT(JIT_WORD_JUMP,literals_count - 1);
+                                       EMIT(JIT_WORD_JUMP,literals_count - 1);
 
-                               tail_call = true;
+                                       tail_call = true;
+                               }
+                               else
+                                       EMIT(JIT_WORD_CALL,literals_count - 1);
                        }
-                       else
-                               EMIT(JIT_WORD_CALL,literals_count - 1);
                        break;
                case WRAPPER_TYPE:
                        wrapper = untag_object(obj);
@@ -194,6 +267,11 @@ void jit_compile(CELL quot, bool relocate)
                                tail_call = true;
                                break;
                        }
+                       else if(jit_ignore_declare_p(untag_object(array),i))
+                       {
+                               i++;
+                               break;
+                       }
                default:
                        GROWABLE_ARRAY_ADD(literals,obj);
                        EMIT(JIT_PUSH_LITERAL,literals_count - 1);
@@ -261,24 +339,47 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
        for(i = 0; i < length; i++)
        {
                CELL obj = array_nth(untag_object(array),i);
-               F_WORD *word;
 
                switch(type_of(obj))
                {
                case WORD_TYPE:
-                       word = untag_object(obj);
-
-                       if(i == length - 1)
+                       /* Intrinsics */
+                       if(obj == userenv[JIT_TAG_WORD])
+                               COUNT(JIT_TAG,i)
+                       else if(obj == userenv[JIT_EQP_WORD])
+                               COUNT(JIT_EQP,i)
+                       else if(obj == userenv[JIT_SLOT_WORD])
+                               COUNT(JIT_SLOT,i)
+                       else if(obj == userenv[JIT_DROP_WORD])
+                               COUNT(JIT_DROP,i)
+                       else if(obj == userenv[JIT_DUP_WORD])
+                               COUNT(JIT_DUP,i)
+                       else if(obj == userenv[JIT_TO_R_WORD])
+                               COUNT(JIT_TO_R,i)
+                       else if(obj == userenv[JIT_FROM_R_WORD])
+                               COUNT(JIT_FROM_R,i)
+                       else if(obj == userenv[JIT_SWAP_WORD])
+                               COUNT(JIT_SWAP,i)
+                       else if(obj == userenv[JIT_OVER_WORD])
+                               COUNT(JIT_OVER,i)
+                       else if(obj == userenv[JIT_FIXNUM_MINUS_WORD])
+                               COUNT(JIT_FIXNUM_MINUS,i)
+                       else if(obj == userenv[JIT_FIXNUM_GE_WORD])
+                               COUNT(JIT_FIXNUM_GE,i)
+                       else
                        {
-                               if(stack_frame)
-                                       COUNT(JIT_EPILOG,i);
-
-                               COUNT(JIT_WORD_JUMP,i)
-
-                               tail_call = true;
+                               if(i == length - 1)
+                               {
+                                       if(stack_frame)
+                                               COUNT(JIT_EPILOG,i);
+       
+                                       COUNT(JIT_WORD_JUMP,i)
+       
+                                       tail_call = true;
+                               }
+                               else
+                                       COUNT(JIT_WORD_CALL,i)
                        }
-                       else
-                               COUNT(JIT_WORD_CALL,i)
                        break;
                case WRAPPER_TYPE:
                        COUNT(JIT_PUSH_LITERAL,i)
@@ -319,6 +420,14 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
                                tail_call = true;
                                break;
                        }
+                       if(jit_ignore_declare_p(untag_object(array),i))
+                       {
+                               if(offset == 0) return i;
+
+                               i++;
+
+                               break;
+                       }
                default:
                        COUNT(JIT_PUSH_LITERAL,i)
                        break;
index cc980453cfbfe0d74ed44cde62ee15b4d81d3bbd..b54640ec8af6f78b55ca6f67a3757f935c587130 100755 (executable)
--- a/vm/run.h
+++ b/vm/run.h
@@ -1,4 +1,4 @@
-#define USER_ENV 64
+#define USER_ENV 70
 
 typedef enum {
        NAMESTACK_ENV,            /* used by library only */
@@ -47,20 +47,43 @@ typedef enum {
        JIT_EPILOG,
        JIT_RETURN,
        JIT_PROFILING,
-
-       STACK_TRACES_ENV    = 36,
-
-       UNDEFINED_ENV       = 37, /* default quotation for undefined words */
-
-       STDERR_ENV          = 38, /* stderr FILE* handle */
-
-       STAGE2_ENV          = 39, /* have we bootstrapped? */
-
-       CURRENT_THREAD_ENV  = 40,
-
-       THREADS_ENV         = 41,
-       RUN_QUEUE_ENV       = 42,
-       SLEEP_QUEUE_ENV     = 43,
+       JIT_TAG,
+       JIT_TAG_WORD,
+       JIT_EQP,
+       JIT_EQP_WORD,
+       JIT_SLOT,
+       JIT_SLOT_WORD,
+       JIT_DECLARE_WORD,
+       JIT_DROP,
+       JIT_DROP_WORD,
+       JIT_DUP,
+       JIT_DUP_WORD,
+       JIT_TO_R,
+       JIT_TO_R_WORD,
+       JIT_FROM_R,
+       JIT_FROM_R_WORD,
+       JIT_SWAP,
+       JIT_SWAP_WORD,
+       JIT_OVER,
+       JIT_OVER_WORD,
+       JIT_FIXNUM_MINUS,
+       JIT_FIXNUM_MINUS_WORD,
+       JIT_FIXNUM_GE,
+       JIT_FIXNUM_GE_WORD,
+
+       STACK_TRACES_ENV    = 59,
+
+       UNDEFINED_ENV       = 60, /* default quotation for undefined words */
+
+       STDERR_ENV          = 61, /* stderr FILE* handle */
+
+       STAGE2_ENV          = 62, /* have we bootstrapped? */
+
+       CURRENT_THREAD_ENV  = 63,
+
+       THREADS_ENV         = 64,
+       RUN_QUEUE_ENV       = 65,
+       SLEEP_QUEUE_ENV     = 66,
 } F_ENVTYPE;
 
 #define FIRST_SAVE_ENV BOOT_ENV