]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <jcg@dhcp-177-191.(none)>
Mon, 14 Jul 2008 16:35:10 +0000 (09:35 -0700)
committerJoe Groff <jcg@dhcp-177-191.(none)>
Mon, 14 Jul 2008 16:35:10 +0000 (09:35 -0700)
183 files changed:
core/alien/c-types/c-types-tests.factor
core/alien/c-types/c-types.factor
core/assocs/assocs-docs.factor
core/assocs/assocs.factor
core/bootstrap/image/image.factor
core/bootstrap/primitives.factor
core/classes/algebra/algebra-tests.factor
core/classes/singleton/singleton.factor
core/classes/tuple/parser/parser-tests.factor
core/classes/tuple/parser/parser.factor
core/classes/tuple/tuple-docs.factor
core/classes/tuple/tuple-tests.factor
core/classes/tuple/tuple.factor
core/compiler/constants/constants.factor
core/cpu/architecture/architecture.factor
core/cpu/ppc/bootstrap.factor
core/cpu/ppc/intrinsics/intrinsics.factor
core/cpu/x86/bootstrap.factor
core/cpu/x86/intrinsics/intrinsics.factor
core/debugger/debugger.factor
core/generator/fixup/fixup.factor
core/grouping/grouping-docs.factor
core/growable/growable.factor
core/hashtables/hashtables-docs.factor
core/hashtables/hashtables-tests.factor
core/hashtables/hashtables.factor
core/inference/class/class-tests.factor
core/inference/class/class.factor
core/inference/errors/errors.factor
core/inference/known-words/known-words.factor
core/inspector/inspector.factor
core/io/encodings/encodings.factor
core/io/encodings/utf8/utf8.factor
core/kernel/kernel-tests.factor
core/optimizer/allot/allot.factor [new file with mode: 0644]
core/optimizer/def-use/def-use.factor
core/optimizer/inlining/inlining-tests.factor
core/optimizer/inlining/inlining.factor
core/optimizer/known-words/known-words.factor
core/optimizer/math/math.factor
core/optimizer/math/partial/partial.factor
core/optimizer/optimizer-tests.factor
core/optimizer/optimizer.factor
core/optimizer/pattern-match/pattern-match.factor
core/prettyprint/prettyprint.factor
core/sequences/sequences-docs.factor
core/sequences/sequences.factor
core/sets/sets-docs.factor
core/sets/sets.factor
core/slots/slots-docs.factor
core/slots/slots.factor
core/words/words-docs.factor
core/words/words.factor
extra/assocs/lib/lib.factor
extra/automata/automata.factor
extra/automata/ui/ui.factor
extra/benchmark/beust1/beust1.factor [new file with mode: 0644]
extra/benchmark/beust2/beust2.factor [new file with mode: 0644]
extra/benchmark/stack/stack.factor [new file with mode: 0644]
extra/biassocs/authors.txt [new file with mode: 0644]
extra/biassocs/biassocs-docs.factor [new file with mode: 0644]
extra/biassocs/biassocs-tests.factor [new file with mode: 0644]
extra/biassocs/biassocs.factor [new file with mode: 0644]
extra/biassocs/summary.txt [new file with mode: 0644]
extra/biassocs/tags.txt [new file with mode: 0644]
extra/bit-arrays/bit-arrays.factor
extra/bitfields/tags.txt
extra/boids/boids.factor
extra/boids/ui/ui.factor
extra/bunny/bunny.factor
extra/bunny/model/model.factor
extra/bunny/outlined/outlined.factor
extra/color-picker/color-picker.factor
extra/ctags/ctags-docs.factor
extra/ctags/ctags-tests.factor
extra/ctags/ctags.factor
extra/ctags/etags/authors.txt [new file with mode: 0644]
extra/ctags/etags/etags-docs.factor [new file with mode: 0644]
extra/ctags/etags/etags-tests.factor [new file with mode: 0644]
extra/ctags/etags/etags.factor [new file with mode: 0644]
extra/ctags/etags/summary.txt [new file with mode: 0644]
extra/float-arrays/float-arrays.factor
extra/generalizations/generalizations-docs.factor
extra/generalizations/generalizations-tests.factor
extra/generalizations/generalizations.factor
extra/geo-ip/geo-ip.factor
extra/gesture-logger/gesture-logger.factor
extra/hints/hints.factor
extra/io/buffers/buffers.factor
extra/io/ports/ports.factor
extra/irc/ui/ui.factor
extra/jamshred/jamshred.factor
extra/lists/tags.txt
extra/lsys/ui/ui.factor
extra/math/geometry/rect/rect-docs.factor [new file with mode: 0644]
extra/math/geometry/rect/rect-tests.factor [new file with mode: 0644]
extra/math/geometry/rect/rect.factor [new file with mode: 0644]
extra/math/physics/pos/pos.factor [new file with mode: 0644]
extra/math/physics/vel/vel.factor [new file with mode: 0644]
extra/math/ranges/ranges-docs.factor
extra/maze/maze.factor
extra/models/models-docs.factor
extra/namespaces/lib/lib.factor
extra/nehe/2/2.factor
extra/nehe/3/3.factor
extra/nehe/4/4.factor
extra/nehe/5/5.factor
extra/nehe/nehe.factor
extra/opengl/demo-support/demo-support.factor
extra/optimizer/debugger/debugger.factor
extra/peg/peg.factor
extra/processing/processing.factor
extra/sequences/lib/lib-tests.factor
extra/sequences/lib/lib.factor
extra/spheres/spheres.factor
extra/springies/springies.factor
extra/springies/ui/ui.factor
extra/tetris/tetris.factor
extra/tools/deploy/shaker/shaker.factor
extra/tuple-arrays/tuple-arrays-tests.factor
extra/tuple-arrays/tuple-arrays.factor
extra/ui/cocoa/cocoa.factor
extra/ui/cocoa/views/views.factor
extra/ui/gadgets/books/books.factor
extra/ui/gadgets/borders/borders-tests.factor
extra/ui/gadgets/borders/borders.factor
extra/ui/gadgets/buttons/buttons.factor
extra/ui/gadgets/editors/editors.factor
extra/ui/gadgets/frame-buffer/frame-buffer.factor
extra/ui/gadgets/frames/frames.factor
extra/ui/gadgets/gadgets-docs.factor
extra/ui/gadgets/gadgets-tests.factor
extra/ui/gadgets/gadgets.factor
extra/ui/gadgets/grid-lines/grid-lines.factor
extra/ui/gadgets/grids/grids-tests.factor
extra/ui/gadgets/grids/grids.factor
extra/ui/gadgets/incremental/incremental.factor
extra/ui/gadgets/lists/lists.factor
extra/ui/gadgets/menus/menus.factor
extra/ui/gadgets/packs/packs-docs.factor
extra/ui/gadgets/packs/packs-tests.factor
extra/ui/gadgets/packs/packs.factor
extra/ui/gadgets/panes/panes.factor
extra/ui/gadgets/paragraphs/paragraphs.factor
extra/ui/gadgets/scrollers/scrollers-docs.factor
extra/ui/gadgets/scrollers/scrollers-tests.factor
extra/ui/gadgets/scrollers/scrollers.factor
extra/ui/gadgets/sliders/sliders.factor
extra/ui/gadgets/tabs/tabs.factor
extra/ui/gadgets/tracks/tracks-tests.factor
extra/ui/gadgets/tracks/tracks.factor
extra/ui/gadgets/viewports/viewports.factor
extra/ui/gadgets/worlds/worlds-tests.factor
extra/ui/gadgets/worlds/worlds.factor
extra/ui/gadgets/wrappers/wrappers.factor
extra/ui/render/render-docs.factor
extra/ui/render/render.factor
extra/ui/tools/browser/browser.factor
extra/ui/tools/debugger/debugger.factor
extra/ui/tools/deploy/deploy.factor
extra/ui/tools/inspector/inspector.factor
extra/ui/tools/search/search.factor
extra/ui/tools/traceback/traceback.factor
extra/ui/tools/walker/walker.factor
extra/ui/ui-docs.factor
extra/ui/windows/windows.factor
extra/ui/x11/x11.factor
extra/usa-cities/usa-cities.factor
extra/windows/ole32/ole32.factor
vm/code_heap.c
vm/code_heap.h
vm/cpu-ppc.S
vm/cpu-x86.32.S
vm/cpu-x86.64.S
vm/cpu-x86.S
vm/layouts.h
vm/math.c
vm/math.h
vm/primitives.c
vm/quotations.c
vm/run.c
vm/run.h
vm/types.c

index 5f57068bab0d68400e6312e7edfc1cfe64f2bccf..276dd581c51dcd36de671d65965778fadb2ca6fa 100755 (executable)
@@ -48,3 +48,5 @@ TYPEDEF: uchar* MyLPBYTE
 [
     0 B{ 1 2 3 4 } <displaced-alien> <void*>
 ] must-fail
+
+[ t ] [ { t f t } >c-bool-array { 1 0 1 } >c-int-array = ] unit-test
index 602b22881fa582f33e108a8747c15de0dd08a42c..c553ca5cfb178398f1651f61420b703c25c60e8f 100755 (executable)
@@ -151,7 +151,9 @@ M: byte-array byte-length length ;
     swap dup length memcpy ;
 
 : (define-nth) ( word type quot -- )
-    >r heap-size [ rot * ] swap prefix r> append define-inline ;
+    [
+        \ swap , [ heap-size , [ * >fixnum ] % ] [ % ] bi*
+    ] [ ] make define-inline ;
 
 : nth-word ( name vocab -- word )
     >r "-nth" append r> create ;
@@ -348,7 +350,7 @@ M: long-long-type box-return ( type -- )
 
     <c-type>
         [ alien-unsigned-4 zero? not ] >>getter
-        [ 1 0 ? set-alien-unsigned-4 ] >>setter
+        [ [ 1 0 ? ] 2dip set-alien-unsigned-4 ] >>setter
         4 >>size
         4 >>align
         "box_boolean" >>boxer
@@ -357,7 +359,7 @@ M: long-long-type box-return ( type -- )
 
     <c-type>
         [ alien-float ] >>getter
-        [ >r >r >float r> r> set-alien-float ] >>setter
+        [ [ >float ] 2dip set-alien-float ] >>setter
         4 >>size
         4 >>align
         "box_float" >>boxer
@@ -368,7 +370,7 @@ M: long-long-type box-return ( type -- )
 
     <c-type>
         [ alien-double ] >>getter
-        [ >r >r >float r> r> set-alien-double ] >>setter
+        [ [ >float ] 2dip set-alien-double ] >>setter
         8 >>size
         8 >>align
         "box_double" >>boxer
index 0e1042391c73d3e1b45e0fd4c742164b8db3d0f8..67bd8607327bcc9ca2082371ff140713ae86db7a 100755 (executable)
@@ -44,10 +44,11 @@ ARTICLE: "assocs-protocol" "Associative mapping protocol"
 { $subsection set-at }
 { $subsection delete-at }
 { $subsection clear-assoc }
-"The following two words are optional:"
+"The following three words are optional:"
+{ $subsection value-at* }
 { $subsection new-assoc }
 { $subsection assoc-like }
-"Assocs should also implement methods on the " { $link clone } ", " { $link equal? } " and " { $link hashcode } " generic words. Two utility words will help with the implementation of the last two:"
+"Assocs should also implement methods on the " { $link clone } ", " { $link equal? } " and " { $link hashcode* } " generic words. Two utility words will help with the implementation of the last two:"
 { $subsection assoc= }
 { $subsection assoc-hashcode }
 "Finally, assoc classes should define a word for converting other types of assocs; conventionally, such words are named " { $snippet ">" { $emphasis "class" } } " where " { $snippet { $emphasis "class" } } " is the class name. Such a word can be implemented using a utility:"
@@ -57,13 +58,19 @@ ARTICLE: "assocs-lookup" "Lookup and querying of assocs"
 "Utility operations built up from the " { $link "assocs-protocol" } ":"
 { $subsection key? }
 { $subsection at }
-{ $subsection value-at }
 { $subsection assoc-empty? }
 { $subsection keys }
 { $subsection values }
 { $subsection assoc-stack }
 { $see-also at* assoc-size } ;
 
+ARTICLE: "assocs-values" "Transposed assoc operations"
+"Most assoc words take a key and find the corresponding value. The following words take a value and find the corresponding key:"
+{ $subsection value-at }
+{ $subsection value-at* }
+{ $subsection value? }
+"With most assoc implementations, these words runs in linear time, proportional to the number of entries in the assoc. For fast value lookups, use " { $vocab-link "biassocs" } "." ;
+
 ARTICLE: "assocs-sets" "Set-theoretic operations on assocs"
 "It is often useful to use the keys of an associative mapping as a set, exploiting the constant or logarithmic lookup time of most implementations (" { $link "alists" } " being a notable exception)."
 { $subsection assoc-subset? }
@@ -111,6 +118,7 @@ $nl
 { $subsection "assocs-protocol" }
 "A large set of utility words work on any object whose class implements the associative mapping protocol."
 { $subsection "assocs-lookup" }
+{ $subsection "assocs-values" }
 { $subsection "assocs-mutation" }
 { $subsection "assocs-combinators" }
 { $subsection "assocs-sets" } ;
@@ -231,10 +239,17 @@ HELP: assoc-stack
 { $description "Searches for the key in successive elements of the sequence, starting from the end. If an assoc containing the key is found, the associated value is output. If no assoc contains the key, outputs " { $link f } "." }
 { $notes "This word is used to implement abstractions such as nested scopes; if the sequence is a stack represented by a vector, then the most recently pushed assoc -- the innermost scope -- will be searched first." } ;
 
+HELP: value-at*
+{ $values { "value" "an object" } { "assoc" assoc } { "key/f" "the key associated to the value, or " { $link f } } { "?" "a boolean" } }
+{ $description "Looks up the key associated with a value. The boolean flag can decide beteen the case of a missing key, and a key of " { $link f } "." } ;
+
 HELP: value-at
 { $values { "value" "an object" } { "assoc" assoc } { "key/f" "the key associated to the value, or " { $link f } } }
-{ $description "Looks up the key associated with a value. No distinction is made between a missing key and a key set to " { $link f } "." }
-{ $notes "This word runs in linear time, proportional to the number of entries in the assoc." } ;
+{ $description "Looks up the key associated with a value. No distinction is made between a missing key and a key set to " { $link f } "." } ;
+
+HELP: value?
+{ $values { "value" "an object" } { "assoc" assoc } { "?" "a boolean" } }
+{ $description "Tests if an assoc contains at least one key with the given value." } ;
 
 HELP: delete-at*
 { $values { "key" "a key" } { "assoc" assoc } { "old" "the previous value or " { $link f } } { "?" "a boolean" } }
index f56ac810d9facacb7f2ac039a10bbfb739806833..6cb89582987820dbe8b163e5cda5db06a676d666 100755 (executable)
@@ -144,10 +144,13 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
 : extract-keys ( seq assoc -- subassoc )
     [ [ dupd at ] curry ] keep map>assoc ;
 
-! M: assoc >alist [ 2array ] { } assoc>map ;
+GENERIC: value-at* ( value assoc -- key/f ? )
 
-: value-at ( value assoc -- key/f )
-    swap [ = nip ] curry assoc-find 2drop ;
+M: assoc value-at* swap [ = nip ] curry assoc-find nip ;
+
+: value-at ( value assoc -- key/f ) value-at* drop ;
+
+: value? ( value assoc -- ? ) value-at* nip ;
 
 : push-at ( value key assoc -- )
     [ ?push ] change-at ;
index 62130cb1790b124457245ba88e6dcd4c1b3c3c7a..97a95f98b85acdf6515b789b4aa5c09af2f5146b 100755 (executable)
@@ -85,8 +85,16 @@ SYMBOL: objects
 : 1-offset              8 ; inline
 : -1-offset             9 ; inline
 
+SYMBOL: sub-primitives
+
+: make-jit ( quot rc rt offset -- quad )
+    { [ { } make ] [ ] [ ] [ ] } spread 4array ; inline
+
 : jit-define ( quot rc rt offset name -- )
-    >r { [ { } make ] [ ] [ ] [ ] } spread 4array r> set ;
+    >r make-jit r> set ; inline
+
+: define-sub-primitive ( quot rc rt offset word -- )
+    >r make-jit r> sub-primitives get set-at ;
 
 ! The image being constructed; a vector of word-size integers
 SYMBOL: image
@@ -111,6 +119,7 @@ SYMBOL: jit-primitive
 SYMBOL: jit-word-jump
 SYMBOL: jit-word-call
 SYMBOL: jit-push-literal
+SYMBOL: jit-push-immediate
 SYMBOL: jit-if-word
 SYMBOL: jit-if-jump
 SYMBOL: jit-dispatch-word
@@ -118,29 +127,7 @@ 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
@@ -163,29 +150,8 @@ SYMBOL: undefined-quot
         { jit-epilog 33 }
         { jit-return 34 }
         { jit-profiling 35 }
-        { jit-tag 36 }
-        { jit-tag-word 37 }
-        { jit-eq? 38 }
-        { jit-eq?-word 39 }
-        { jit-slot 40 }
-        { jit-slot-word 41 }
+        { jit-push-immediate 36 }
         { 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 + ;
 
@@ -305,6 +271,9 @@ M: f '
 
 ! Words
 
+: word-sub-primitive ( word -- obj )
+    global [ target-word ] bind sub-primitives get at ;
+
 : emit-word ( word -- )
     [
         [ subwords [ emit-word ] each ]
@@ -316,12 +285,13 @@ M: f '
                     [ vocabulary>> , ]
                     [ def>> , ]
                     [ props>> , ]
+                    [ drop f , ]
+                    [ drop 0 , ] ! count
+                    [ word-sub-primitive , ]
+                    [ drop 0 , ] ! xt
+                    [ drop 0 , ] ! code
+                    [ drop 0 , ] ! profiling
                 } cleave
-                f ,
-                0 , ! count
-                0 , ! xt
-                0 , ! code
-                0 , ! profiling
             ] { } make [ ' ] map
         ] bi
         \ word type-number object tag-number
@@ -460,18 +430,7 @@ 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
@@ -481,6 +440,7 @@ M: quotation '
         jit-word-jump
         jit-word-call
         jit-push-literal
+        jit-push-immediate
         jit-if-word
         jit-if-jump
         jit-dispatch-word
@@ -488,29 +448,7 @@ 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 6498dfde604533a2ede5d7f0bcb1698710293089..b2b6dc4e59087131ee7d53ff54a8782956387a2a 100755 (executable)
@@ -13,6 +13,8 @@ IN: bootstrap.primitives
 
 crossref off
 
+H{ } clone sub-primitives set
+
 "resource:core/bootstrap/syntax.factor" parse-file
 
 "resource:core/cpu/" architecture get {
@@ -119,7 +121,7 @@ bootstrapping? on
     [ [ dup pair? [ first2 create ] when ] map ] map ;
 
 : define-builtin-slots ( class slots -- )
-    prepare-slots 1 make-slots
+    prepare-slots make-slots 1 finalize-slots
     [ "slots" set-word-prop ] [ define-accessors ] 2bi ;
 
 : define-builtin ( symbol slotspec -- )
@@ -256,6 +258,7 @@ bi
     "props"
     { "compiled" read-only }
     { "counter" { "fixnum" "math" } }
+    { "sub-primitive" read-only }
 } define-builtin
 
 "byte-array" "byte-arrays" create { } define-builtin
@@ -270,18 +273,16 @@ bi
     { "echelon" { "fixnum" "math" } read-only }
 } define-builtin
 
-"tuple" "kernel" create {
-    [ { } define-builtin ]
-    [ { "delegate" } "slot-names" set-word-prop ]
-    [ define-tuple-layout ]
-    [
-        { "delegate" }
-        [ drop ] [ generate-tuple-slots ] 2bi
-        [ "slots" set-word-prop ]
-        [ define-accessors ]
-        2bi
-    ]
-} cleave
+"tuple" "kernel" create
+[ { } define-builtin ]
+[ define-tuple-layout ]
+[
+    { "delegate" } make-slots
+    [ drop ] [ finalize-tuple-slots ] 2bi
+    [ "slots" set-word-prop ]
+    [ define-accessors ]
+    2bi
+] tri
 
 ! Create special tombstone values
 "tombstone" "hashtables.private" create
@@ -323,14 +324,55 @@ tuple
 [ tuple-layout [ <tuple-boa> ] curry ] tri
 (( quot1 quot2 -- compose )) define-declared
 
+! Sub-primitive words
+: make-sub-primitive ( word vocab -- )
+    create
+    dup reset-word
+    dup 1quotation define ;
+
+{
+    { "(execute)" "words.private" }
+    { "(call)" "kernel.private" }
+    { "fixnum+fast" "math.private" }
+    { "fixnum-fast" "math.private" }
+    { "fixnum*fast" "math.private" }
+    { "fixnum-bitand" "math.private" }
+    { "fixnum-bitor" "math.private" }
+    { "fixnum-bitxor" "math.private" }
+    { "fixnum-bitnot" "math.private" }
+    { "fixnum<" "math.private" }
+    { "fixnum<=" "math.private" }
+    { "fixnum>" "math.private" }
+    { "fixnum>=" "math.private" }
+    { "drop" "kernel" }
+    { "2drop" "kernel" }
+    { "3drop" "kernel" }
+    { "dup" "kernel" }
+    { "2dup" "kernel" }
+    { "3dup" "kernel" }
+    { "rot" "kernel" }
+    { "-rot" "kernel" }
+    { "dupd" "kernel" }
+    { "swapd" "kernel" }
+    { "nip" "kernel" }
+    { "2nip" "kernel" }
+    { "tuck" "kernel" }
+    { "over" "kernel" }
+    { "pick" "kernel" }
+    { "swap" "kernel" }
+    { ">r" "kernel" }
+    { "r>" "kernel" }
+    { "eq?" "kernel" }
+    { "tag" "kernel.private" }
+    { "slot" "slots.private" }
+} [ make-sub-primitive ] assoc-each
+
 ! Primitive words
 : make-primitive ( word vocab n -- )
     >r create dup reset-word r>
     [ do-primitive ] curry [ ] like define ;
 
 {
-    { "(execute)" "words.private" }
-    { "(call)" "kernel.private" }
     { "bignum>fixnum" "math.private" }
     { "float>fixnum" "math.private" }
     { "fixnum>bignum" "math.private" }
@@ -346,24 +388,13 @@ tuple
     { "bits>double" "math" }
     { "<complex>" "math.private" }
     { "fixnum+" "math.private" }
-    { "fixnum+fast" "math.private" }
     { "fixnum-" "math.private" }
-    { "fixnum-fast" "math.private" }
     { "fixnum*" "math.private" }
-    { "fixnum*fast" "math.private" }
     { "fixnum/i" "math.private" }
     { "fixnum-mod" "math.private" }
     { "fixnum/mod" "math.private" }
-    { "fixnum-bitand" "math.private" }
-    { "fixnum-bitor" "math.private" }
-    { "fixnum-bitxor" "math.private" }
-    { "fixnum-bitnot" "math.private" }
     { "fixnum-shift" "math.private" }
     { "fixnum-shift-fast" "math.private" }
-    { "fixnum<" "math.private" }
-    { "fixnum<=" "math.private" }
-    { "fixnum>" "math.private" }
-    { "fixnum>=" "math.private" }
     { "bignum=" "math.private" }
     { "bignum+" "math.private" }
     { "bignum-" "math.private" }
@@ -395,25 +426,6 @@ tuple
     { "float>=" "math.private" }
     { "<word>" "words" }
     { "word-xt" "words" }
-    { "drop" "kernel" }
-    { "2drop" "kernel" }
-    { "3drop" "kernel" }
-    { "dup" "kernel" }
-    { "2dup" "kernel" }
-    { "3dup" "kernel" }
-    { "rot" "kernel" }
-    { "-rot" "kernel" }
-    { "dupd" "kernel" }
-    { "swapd" "kernel" }
-    { "nip" "kernel" }
-    { "2nip" "kernel" }
-    { "tuck" "kernel" }
-    { "over" "kernel" }
-    { "pick" "kernel" }
-    { "swap" "kernel" }
-    { ">r" "kernel" }
-    { "r>" "kernel" }
-    { "eq?" "kernel" }
     { "getenv" "kernel.private" }
     { "setenv" "kernel.private" }
     { "(exists?)" "io.files.private" }
@@ -433,7 +445,6 @@ tuple
     { "code-room" "memory" }
     { "os-env" "system" }
     { "millis" "system" }
-    { "tag" "kernel.private" }
     { "modify-code-heap" "compiler.units" }
     { "dlopen" "alien" }
     { "dlsym" "alien" }
@@ -468,7 +479,6 @@ tuple
     { "set-alien-cell" "alien.accessors" }
     { "(throw)" "kernel.private" }
     { "alien-address" "alien" }
-    { "slot" "slots.private" }
     { "set-slot" "slots.private" }
     { "string-nth" "strings.private" }
     { "set-string-nth" "strings.private" }
index 444cf50e58165c5ddc23d4b7c0ed9f558bc1a411..665fc86ebbe8c6f0bd5055f49c7e21a59ce657fd 100755 (executable)
@@ -306,3 +306,9 @@ INTERSECTION: empty-intersection ;
 [ t ] [ object \ f class-not \ f class-or class<= ] unit-test\r
 \r
 [ ] [ object flatten-builtin-class drop ] unit-test\r
+\r
+SINGLETON: sa\r
+SINGLETON: sb\r
+SINGLETON: sc\r
+\r
+[ sa ] [ sa { sa sb sc } min-class ] unit-test\r
index a72c9f133390ad923dfdeec31050e9c079700af4..1d370c1859d4f50983f6a50347939bb6ae8d3c7b 100755 (executable)
@@ -1,6 +1,7 @@
 ! Copyright (C) 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: classes classes.predicate kernel sequences words ;
+USING: classes classes.algebra classes.predicate kernel
+sequences words ;
 IN: classes.singleton
 
 PREDICATE: singleton-class < predicate-class
@@ -11,3 +12,6 @@ PREDICATE: singleton-class < predicate-class
     \ word over [ eq? ] curry define-predicate-class ;
 
 M: singleton-class instance? eq? ;
+
+M: singleton-class (classes-intersect?)
+    over singleton-class? [ eq? ] [ call-next-method ] if ;
index 10cbe268da637a026978f22a338c06a9ff67e9eb..6f7d4af6bc3c14232b1672e6e089ae46cc63c121 100644 (file)
@@ -1,35 +1,44 @@
 IN: classes.tuple.parser.tests
 USING: accessors classes.tuple.parser lexer words classes
-sequences math kernel slots tools.test parser compiler.units ;
+sequences math kernel slots tools.test parser compiler.units
+arrays classes.tuple ;
 
 TUPLE: test-1 ;
 
-[ t ] [ test-1 "slot-names" word-prop empty? ] unit-test
+[ t ] [ test-1 "slots" word-prop empty? ] unit-test
 
 TUPLE: test-2 < test-1 ;
 
-[ t ] [ test-2 "slot-names" word-prop empty? ] unit-test
+[ t ] [ test-2 "slots" word-prop empty? ] unit-test
 [ test-1 ] [ test-2 superclass ] unit-test
 
 TUPLE: test-3 a ;
 
-[ { "a" } ] [ test-3 "slot-names" word-prop ] unit-test
+[ { "a" } ] [ test-3 "slots" word-prop [ name>> ] map ] unit-test
 
 [ object ] [ "a" test-3 "slots" word-prop slot-named class>> ] unit-test
 
 TUPLE: test-4 < test-3 b ;
 
-[ { "b" } ] [ test-4 "slot-names" word-prop ] unit-test
+[ { "b" } ] [ test-4 "slots" word-prop [ name>> ] map ] unit-test
 
 TUPLE: test-5 { a integer } ;
 
-[ { { "a" integer } } ] [ test-5 "slot-names" word-prop ] unit-test
+[ { { "a" integer } } ]
+[
+    test-5 "slots" word-prop
+    [ [ name>> ] [ class>> ] bi 2array ] map
+] unit-test
 
 TUPLE: test-6 < test-5 { b integer } ;
 
 [ integer ] [ "b" test-6 "slots" word-prop slot-named class>> ] unit-test
 
-[ { { "b" integer } } ] [ test-6 "slot-names" word-prop ] unit-test
+[ { { "b" integer } } ]
+[
+    test-6 "slots" word-prop
+    [ [ name>> ] [ class>> ] bi 2array ] map
+] unit-test
 
 TUPLE: test-7 { b integer initial: 3 } ;
 
@@ -39,6 +48,8 @@ TUPLE: test-8 { b integer read-only } ;
 
 [ t ] [ "b" test-8 "slots" word-prop slot-named read-only>> ] unit-test
 
+DEFER: foo
+
 [ "IN: classes.tuple.parser.tests TUPLE: foo < test-1 < ;" eval ]
 [ error>> invalid-slot-name? ]
 must-fail-with
@@ -51,17 +62,33 @@ must-fail-with
 [ error>> unexpected-eof? ]
 must-fail-with
 
-[ "IN: classes.tuple.parser.tests USE: generic.standard TUPLE: foo { slot no-method } ;" eval ]
-[ error>> no-initial-value? ]
-must-fail-with
+2 [
+    [ "IN: classes.tuple.parser.tests USE: alien TUPLE: foo { slot dll } ;" eval ]
+    [ error>> no-initial-value? ]
+    must-fail-with
+
+    [ f ] [ \ foo tuple-class? ] unit-test
+] times
 
-[ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo { slot array initial: 5 } ;" eval ]
-[ error>> bad-initial-value? ]
+2 [
+    [ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo { slot array initial: 5 } ;" eval ]
+    [ error>> bad-initial-value? ]
+    must-fail-with
+
+    [ f ] [ \ foo tuple-class? ] unit-test
+] times
+
+[ "IN: classes.tuple.parser.tests USE: arrays TUPLE: foo slot { slot array } ;" eval ]
+[ error>> duplicate-slot-names? ]
 must-fail-with
 
+[ f ] [ \ foo tuple-class? ] unit-test
+
 [ ] [
     [
-        { test-1 test-2 test-3 test-4 test-5 test-6 test-7 test-8 }
+        { test-1 test-2 test-3 test-4 test-5 test-6 test-7 test-8 foo }
         [ dup class? [ forget-class ] [ drop ] if ] each
     ] with-compilation-unit
 ] unit-test
+
+
index e9919ee9928e3e488339aeee4daba1402207231e..ded0ca2a728d02d976c5e226803fbaa039ed1289 100644 (file)
@@ -4,10 +4,11 @@ USING: accessors kernel sets namespaces sequences summary parser
 lexer combinators words classes.parser classes.tuple arrays ;
 IN: classes.tuple.parser
 
+: slot-names ( slots -- seq )
+    [ dup array? [ first ] when ] map ;
+
 : shadowed-slots ( superclass slots -- shadowed )
-    [ all-slots [ name>> ] map ]
-    [ [ dup array? [ first ] when ] map ]
-    bi* intersect ;
+    [ all-slots [ name>> ] map ] [ slot-names ] bi* intersect ;
 
 : check-slot-shadowing ( class superclass slots -- )
     shadowed-slots [
@@ -20,11 +21,19 @@ IN: classes.tuple.parser
         ] "" make note.
     ] with each ;
 
+ERROR: duplicate-slot-names names ;
+
+M: duplicate-slot-names summary
+    drop "Duplicate slot names" ;
+
+: check-duplicate-slots ( slots -- )
+    slot-names duplicates
+    dup empty? [ drop ] [ duplicate-slot-names ] if ;
+
 ERROR: invalid-slot-name name ;
 
 M: invalid-slot-name summary
-    drop
-    "Invalid slot name" ;
+    drop "Invalid slot name" ;
 
 : parse-long-slot-name ( -- )
     [ scan , \ } parse-until % ] { } make ;
@@ -38,7 +47,7 @@ M: invalid-slot-name summary
     #! : ...
     {
         { [ dup not ] [ unexpected-eof ] }
-        { [ dup { ":" "(" "<" "\"" } member? ] [ invalid-slot-name ] }
+        { [ dup { ":" "(" "<" "\"" "!" } member? ] [ invalid-slot-name ] }
         { [ dup ";" = ] [ drop f ] }
         [ dup "{" = [ drop parse-long-slot-name ] when , t ]
     } cond ;
@@ -52,4 +61,6 @@ M: invalid-slot-name summary
         { ";" [ tuple f ] }
         { "<" [ scan-word [ parse-tuple-slots ] { } make ] }
         [ tuple swap [ parse-slot-name [ parse-tuple-slots ] when ] { } make ]
-    } case 3dup check-slot-shadowing ;
+    } case
+    dup check-duplicate-slots
+    3dup check-slot-shadowing ;
index 114146e450edc80c8ec26f981ff30cf50c05a3e1..0cf30911650c174a472ae3772408ef4332644ebf 100755 (executable)
@@ -298,16 +298,16 @@ $nl
 "For example, compare the definitions of the " { $link sbuf } " class,"
 { $code
     "TUPLE: sbuf"
-    "{ \"underlying\" string }"
-    "{ \"length\" array-capacity } ;"
+    "{ underlying string }"
+    "{ length array-capacity } ;"
     ""
     "INSTANCE: sbuf growable"
 }
 "with that of the " { $link vector } " class:"
 { $code
     "TUPLE: vector"
-    "{ \"underlying\" array }"
-    "{ \"length\" array-capacity } ;"
+    "{ underlying array }"
+    "{ length array-capacity } ;"
     ""
     "INSTANCE: vector growable"
 } ;
@@ -346,11 +346,9 @@ HELP: tuple
 $nl
 "Tuple classes have additional word properties:"
 { $list
-    { { $snippet "\"constructor\"" } " - a word for creating instances of this tuple class" }
     { { $snippet "\"predicate\"" } " - a quotation which tests if the top of the stack is an instance of this tuple class" }
     { { $snippet "\"slots\"" } " - a sequence of " { $link slot-spec } " instances" }
-    { { $snippet "\"slot-names\"" } " - a sequence of strings naming the tuple's slots" }
-    { { $snippet "\"tuple-size\"" } " - the number of slots" }
+    { { $snippet "\"tuple-layout\"" } " - a " { $link tuple-layout } " instance" }
 } } ;
 
 HELP: define-tuple-predicate
index b89abdfd827e0b0f751a13248461b824698abbf1..35d4149d37b8f649a9e4608b6d325f0d52283d9b 100755 (executable)
@@ -443,36 +443,36 @@ TUPLE: redefinition-problem-2 ;
 ! Hardcore unit tests
 USE: threads
 
-\ thread slot-names "slot-names" set
+\ thread "slots" word-prop "slots" set
 
 [ ] [
     [
-        \ thread tuple { "xxx" } "slot-names" get append
+        \ thread tuple { "xxx" } "slots" get append
         define-tuple-class
     ] with-compilation-unit
 
     [ 1337 sleep ] "Test" spawn drop
 
     [
-        \ thread tuple "slot-names" get
+        \ thread tuple "slots" get
         define-tuple-class
     ] with-compilation-unit
 ] unit-test
 
 USE: vocabs
 
-\ vocab slot-names "slot-names" set
+\ vocab "slots" word-prop "slots" set
 
 [ ] [
     [
-        \ vocab tuple { "xxx" } "slot-names" get append
+        \ vocab tuple { "xxx" } "slots" get append
         define-tuple-class
     ] with-compilation-unit
 
     all-words drop
 
     [
-        \ vocab tuple "slot-names" get
+        \ vocab tuple "slots" get
         define-tuple-class
     ] with-compilation-unit
 ] unit-test
index 6cf6a9897ab4cd2ac73a4647b39a291177f5e102..17d8e3693527722aa7510f98500161ed8b725769 100755 (executable)
@@ -22,18 +22,6 @@ ERROR: not-a-tuple object ;
 
 <PRIVATE
 
-: (tuple) ( layout -- tuple )
-    #! In non-optimized code, this word simply calls the
-    #! <tuple> primitive. In optimized code, an intrinsic
-    #! is generated which allocates a tuple but does not set
-    #! any of its slots. This means that any code that uses
-    #! (tuple) must fill in the slots before the next
-    #! call to GC.
-    #!
-    #! This word is only used in the expansion of <tuple-boa>,
-    #! where this invariant is guaranteed to hold.
-    <tuple> ;
-
 : tuple-layout ( class -- layout )
     "layout" word-prop ;
 
@@ -86,9 +74,6 @@ M: tuple-class slots>tuple
 : >tuple ( seq -- tuple )
     unclip slots>tuple ;
 
-: slot-names ( class -- seq )
-    "slot-names" word-prop ;
-
 ERROR: bad-superclass class ;
 
 <PRIVATE
@@ -116,7 +101,7 @@ ERROR: bad-superclass class ;
 
 : superclass-size ( class -- n )
     superclasses but-last-slice
-    [ slot-names length ] sigma ;
+    [ "slots" word-prop length ] sigma ;
 
 : (instance-check-quot) ( class -- quot )
     [
@@ -150,19 +135,18 @@ ERROR: bad-superclass class ;
 : define-tuple-prototype ( class -- )
     dup tuple-prototype "prototype" set-word-prop ;
 
-: generate-tuple-slots ( class slots -- slot-specs )
-    over superclass-size 2 + make-slots deprecated-slots ;
+: finalize-tuple-slots ( class slots -- slots )
+    over superclass-size 2 + finalize-slots deprecated-slots ;
 
 : define-tuple-slots ( class -- )
-    dup dup "slot-names" word-prop generate-tuple-slots
-    [ "slots" set-word-prop ]
+    dup dup "slots" word-prop finalize-tuple-slots
     [ define-accessors ] ! new
     [ define-slots ] ! old
-    2tri ;
+    2bi ;
 
 : make-tuple-layout ( class -- layout )
     [ ]
-    [ [ superclass-size ] [ slot-names length ] bi + ]
+    [ [ superclass-size ] [ "slots" word-prop length ] bi + ]
     [ superclasses dup length 1- ] tri
     <tuple-layout> ;
 
@@ -223,8 +207,9 @@ M: tuple-class update-class
     } cleave ;
 
 : define-new-tuple-class ( class superclass slots -- )
+    make-slots
     [ drop f f tuple-class define-class ]
-    [ nip "slot-names" set-word-prop ]
+    [ nip "slots" set-word-prop ]
     [ 2drop update-classes ]
     3tri ;
 
@@ -248,7 +233,7 @@ M: tuple-class update-class
     3bi ;
 
 : tuple-class-unchanged? ( class superclass slots -- ? )
-    rot tuck [ superclass = ] [ slot-names = ] 2bi* and ;
+    rot tuck [ superclass = ] [ "slots" word-prop = ] 2bi* and ;
 
 : valid-superclass? ( class -- ? )
     [ tuple-class? ] [ tuple eq? ] bi or ;
@@ -293,7 +278,7 @@ M: tuple-class reset-class
         [ call-next-method ]
         [
             {
-                "layout" "slots" "slot-names" "boa-check" "prototype"
+                "layout" "slots" "boa-check" "prototype"
             } reset-props
         ] bi
     ] bi ;
@@ -336,6 +321,8 @@ M: tuple-class boa
     [ tuple-layout ]
     bi <tuple-boa> ;
 
+M: tuple-class initial-value* new ;
+
 ! Deprecated
 M: object get-slots ( obj slots -- ... )
     [ execute ] with each ;
index 622c63d7f0fefe7666a246abbd2fd934ff61efd2..80f0b4f51570d5fe816651ca32f052484da9b782 100755 (executable)
@@ -18,8 +18,8 @@ IN: compiler.constants
 : underlying-alien-offset ( -- n ) bootstrap-cell object tag-number - ;
 : tuple-class-offset ( -- n ) bootstrap-cell tuple tag-number - ;
 : class-hash-offset ( -- n ) bootstrap-cell object tag-number - ;
-: word-xt-offset ( -- n ) 8 bootstrap-cells object tag-number - ;
+: word-xt-offset ( -- n ) 9 bootstrap-cells object tag-number - ;
 : quot-xt-offset ( -- n ) 3 bootstrap-cells object tag-number - ;
-: word-code-offset ( -- n ) 9 bootstrap-cells object tag-number - ;
+: word-code-offset ( -- n ) 10 bootstrap-cells object tag-number - ;
 : array-start-offset ( -- n ) 2 bootstrap-cells object tag-number - ;
 : compiled-header-size ( -- n ) 4 bootstrap-cells ;
index bd6f639415124ba5cd2a8068606a34a58a4d1d49..56b4630962b4c6e5aa66d3ca5846d68ea8a55221 100755 (executable)
@@ -162,8 +162,6 @@ PREDICATE: small-slot < integer cells small-enough? ;
 
 PREDICATE: small-tagged < integer v>operand small-enough? ;
 
-PREDICATE: inline-array < integer 32 < ;
-
 : if-small-struct ( n size true false -- ? )
     >r >r over not over struct-small-enough? and
     [ nip r> call r> drop ] [ r> drop r> call ] if ;
index cf380d69f153ca8d04ad55cef4d4d50eca495173..705ddac06d5b4651a52cb19a52a0029265ee4a21 100755 (executable)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.\r
 ! See http://factorcode.org/license.txt for BSD license.\r
-USING: bootstrap.image.private kernel namespaces system\r
-cpu.ppc.assembler generator.fixup compiler.units\r
-compiler.constants math layouts words vocabs ;\r
+USING: bootstrap.image.private kernel kernel.private namespaces\r
+system cpu.ppc.assembler generator.fixup compiler.units\r
+compiler.constants math math.private layouts words words.private\r
+vocabs slots.private ;\r
 IN: bootstrap.ppc\r
 \r
 4 \ cell set\r
@@ -11,9 +12,7 @@ big-endian on
 4 jit-code-format set\r
 \r
 : ds-reg 14 ;\r
-: quot-reg 3 ;\r
-: temp-reg 6 ;\r
-: aux-reg 11 ;\r
+: rs-reg 15 ;\r
 \r
 : factor-area-size 4 bootstrap-cells ;\r
 \r
@@ -24,86 +23,286 @@ big-endian on
 : xt-save stack-frame 2 bootstrap-cells - ;\r
 \r
 [\r
-    ! Load word\r
-    0 temp-reg LOAD32\r
-    temp-reg dup 0 LWZ\r
-    ! Bump profiling counter\r
-    aux-reg temp-reg profile-count-offset LWZ\r
-    aux-reg dup 1 tag-fixnum ADDI\r
-    aux-reg temp-reg profile-count-offset STW\r
-    ! Load word->code\r
-    aux-reg temp-reg word-code-offset LWZ\r
-    ! Compute word XT\r
-    aux-reg dup compiled-header-size ADDI\r
-    ! Jump to XT\r
-    aux-reg MTCTR\r
+    0 6 LOAD32\r
+    6 dup 0 LWZ\r
+    11 6 profile-count-offset LWZ\r
+    11 11 1 tag-fixnum ADDI\r
+    11 6 profile-count-offset STW\r
+    11 6 word-code-offset LWZ\r
+    11 11 compiled-header-size ADDI\r
+    11 MTCTR\r
     BCTR\r
 ] rc-absolute-ppc-2/2 rt-literal 1 jit-profiling jit-define\r
 \r
 [\r
-    0 temp-reg LOAD32                          ! load XT\r
-    0 MFLR                                     ! load return address\r
-    1 1 stack-frame neg ADDI                   ! create stack frame\r
-    temp-reg 1 xt-save STW                     ! save XT\r
-    stack-frame temp-reg LI                    ! load frame size\r
-    temp-reg 1 next-save STW                   ! save frame size\r
-    0 1 lr-save stack-frame + STW              ! save return address\r
+    0 6 LOAD32\r
+    0 MFLR\r
+    1 1 stack-frame SUBI\r
+    6 1 xt-save STW\r
+    stack-frame 6 LI\r
+    6 1 next-save STW\r
+    0 1 lr-save stack-frame + STW\r
 ] rc-absolute-ppc-2/2 rt-label 1 jit-prolog jit-define\r
 \r
 [\r
-    0 temp-reg LOAD32                          ! load literal\r
-    temp-reg dup 0 LWZ                         ! indirection\r
-    temp-reg ds-reg 4 STWU                     ! push literal\r
+    0 6 LOAD32\r
+    6 dup 0 LWZ\r
+    6 ds-reg 4 STWU\r
 ] rc-absolute-ppc-2/2 rt-literal 1 jit-push-literal jit-define\r
 \r
 [\r
-    0 temp-reg LOAD32                          ! load primitive address\r
-    4 1 MR                                     ! pass stack pointer to primitive\r
-    temp-reg MTCTR                             ! jump to primitive\r
+    0 6 LOAD32\r
+    6 ds-reg 4 STWU\r
+] rc-absolute-ppc-2/2 rt-immediate 1 jit-push-immediate jit-define\r
+\r
+[\r
+    0 6 LOAD32\r
+    4 1 MR\r
+    6 MTCTR\r
     BCTR\r
 ] rc-absolute-ppc-2/2 rt-primitive 1 jit-primitive jit-define\r
 \r
-[\r
-    0 BL\r
-] rc-relative-ppc-3 rt-xt 0 jit-word-call jit-define\r
+[ 0 BL ] rc-relative-ppc-3 rt-xt 0 jit-word-call jit-define\r
 \r
-[\r
-    0 B\r
-] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define\r
+[ 0 B ] rc-relative-ppc-3 rt-xt 0 jit-word-jump jit-define\r
 \r
 : jit-call-quot ( -- )\r
-    temp-reg quot-reg quot-xt-offset LWZ       ! load quotation-xt\r
-    temp-reg MTCTR                             ! jump to quotation-xt\r
+    4 3 quot-xt-offset LWZ\r
+    4 MTCTR\r
     BCTR ;\r
 \r
 [\r
-    0 quot-reg LOAD32                          ! point quot-reg at false branch\r
-    temp-reg ds-reg 0 LWZ                      ! load boolean\r
-    0 temp-reg \ f tag-number CMPI             ! compare it with f\r
-    2 BNE                                      ! skip next insn if its not f\r
-    quot-reg dup 4 ADDI                        ! point quot-reg at true branch\r
-    quot-reg dup 0 LWZ                         ! load the branch\r
-    ds-reg dup 4 SUBI                          ! pop boolean\r
+    0 3 LOAD32\r
+    6 ds-reg 0 LWZ\r
+    0 6 \ f tag-number CMPI\r
+    2 BNE\r
+    3 3 4 ADDI\r
+    3 3 0 LWZ\r
+    ds-reg dup 4 SUBI\r
     jit-call-quot\r
 ] rc-absolute-ppc-2/2 rt-literal 1 jit-if-jump jit-define\r
 \r
 [\r
-    0 quot-reg LOAD32                          ! load dispatch array\r
-    quot-reg dup 0 LWZ                         ! indirection\r
-    temp-reg ds-reg 0 LWZ                      ! load index\r
-    temp-reg dup 1 SRAWI                       ! turn it into an array offset\r
-    quot-reg dup temp-reg ADD                  ! compute quotation location\r
-    quot-reg dup array-start-offset LWZ        ! load quotation\r
-    ds-reg dup 4 SUBI                          ! pop index\r
+    0 3 LOAD32\r
+    3 3 0 LWZ\r
+    6 ds-reg 0 LWZ\r
+    6 6 1 SRAWI\r
+    3 3 6 ADD\r
+    3 3 array-start-offset LWZ\r
+    ds-reg dup 4 SUBI\r
     jit-call-quot\r
 ] rc-absolute-ppc-2/2 rt-literal 1 jit-dispatch jit-define\r
 \r
 [\r
-    0 1 lr-save stack-frame + LWZ              ! load return address\r
-    1 1 stack-frame ADDI                       ! pop stack frame\r
-    0 MTLR                                     ! get ready to return\r
+    0 1 lr-save stack-frame + LWZ\r
+    1 1 stack-frame ADDI\r
+    0 MTLR\r
 ] f f f jit-epilog jit-define\r
 \r
 [ BLR ] f f f jit-return jit-define\r
 \r
+! Sub-primitives\r
+\r
+! Quotations and words\r
+[\r
+    3 ds-reg 0 LWZ\r
+    ds-reg dup 4 SUBI\r
+    jit-call-quot\r
+] f f f \ (call) define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    ds-reg dup 4 SUBI\r
+    4 3 word-xt-offset LWZ\r
+    4 MTCTR\r
+    BCTR\r
+] f f f \ (execute) define-sub-primitive\r
+\r
+! Objects\r
+[\r
+    3 ds-reg 0 LWZ\r
+    3 3 tag-mask get ANDI\r
+    3 3 tag-bits get SLWI\r
+    3 ds-reg 0 STW\r
+] f f f \ tag define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZU\r
+    3 3 1 SRAWI\r
+    4 4 0 0 31 tag-bits get - RLWINM\r
+    4 3 3 LWZX\r
+    3 ds-reg 0 STW\r
+] f f f \ slot define-sub-primitive\r
+\r
+! Shufflers\r
+[\r
+    ds-reg dup 4 SUBI\r
+] f f f \ drop define-sub-primitive\r
+\r
+[\r
+    ds-reg dup 8 SUBI\r
+] f f f \ 2drop define-sub-primitive\r
+\r
+[\r
+    ds-reg dup 12 SUBI\r
+] f f f \ 3drop define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    3 ds-reg 4 STWU\r
+] f f f \ dup define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    ds-reg dup 8 ADDI\r
+    3 ds-reg 0 STW\r
+    4 ds-reg -4 STW\r
+] f f f \ 2dup define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    5 ds-reg -8 LWZ\r
+    ds-reg dup 12 ADDI\r
+    3 ds-reg 0 STW\r
+    4 ds-reg -4 STW\r
+    5 ds-reg -8 STW\r
+] f f f \ 3dup define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    ds-reg dup 4 SUBI\r
+    3 ds-reg 0 STW\r
+] f f f \ nip define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    ds-reg dup 8 SUBI\r
+    3 ds-reg 0 STW\r
+] f f f \ 2nip define-sub-primitive\r
+\r
+[\r
+    3 ds-reg -4 LWZ\r
+    3 ds-reg 4 STWU\r
+] f f f \ over define-sub-primitive\r
+\r
+[\r
+    3 ds-reg -8 LWZ\r
+    3 ds-reg 4 STWU\r
+] f f f \ pick define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    4 ds-reg 0 STW\r
+    3 ds-reg 4 STWU\r
+] f f f \ dupd define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    3 ds-reg 4 STWU\r
+    4 ds-reg -4 STW\r
+    3 ds-reg -8 STW\r
+] f f f \ tuck define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    3 ds-reg -4 STW\r
+    4 ds-reg 0 STW\r
+] f f f \ swap define-sub-primitive\r
+\r
+[\r
+    3 ds-reg -4 LWZ\r
+    4 ds-reg -8 LWZ\r
+    3 ds-reg -8 STW\r
+    4 ds-reg -4 STW\r
+] f f f \ swapd define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    5 ds-reg -8 LWZ\r
+    4 ds-reg -8 STW\r
+    3 ds-reg -4 STW\r
+    5 ds-reg 0 STW\r
+] f f f \ rot define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZ\r
+    5 ds-reg -8 LWZ\r
+    3 ds-reg -8 STW\r
+    5 ds-reg -4 STW\r
+    4 ds-reg 0 STW\r
+] f f f \ -rot define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    ds-reg dup 4 SUBI\r
+    3 rs-reg 4 STWU\r
+] f f f \ >r define-sub-primitive\r
+\r
+[\r
+    3 rs-reg 0 LWZ\r
+    rs-reg dup 4 SUBI\r
+    3 ds-reg 4 STWU\r
+] f f f \ r> define-sub-primitive\r
+\r
+! Comparisons\r
+: jit-compare ( insn -- )\r
+    0 3 LOAD32\r
+    3 3 0 LWZ\r
+    4 ds-reg 0 LWZ\r
+    5 ds-reg -4 LWZU\r
+    5 0 4 CMP\r
+    2 swap execute ! magic number\r
+    \ f tag-number 3 LI\r
+    3 ds-reg 0 STW ;\r
+\r
+: define-jit-compare ( insn word -- )\r
+    [ [ jit-compare ] curry rc-absolute-ppc-2/2 rt-literal 1 ] dip\r
+    define-sub-primitive ;\r
+\r
+\ BEQ \ eq? define-jit-compare\r
+\ BGE \ fixnum>= define-jit-compare\r
+\ BLE \ fixnum<= define-jit-compare\r
+\ BGT \ fixnum> define-jit-compare\r
+\ BLT \ fixnum< define-jit-compare\r
+\r
+! Math\r
+: jit-math ( insn -- )\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZU\r
+    [ 5 3 4 ] dip execute\r
+    5 ds-reg 0 STW ;\r
+\r
+[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive\r
+\r
+[ \ SUBF jit-math ] f f f \ fixnum-fast define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    4 ds-reg -4 LWZU\r
+    4 4 tag-bits get SRAWI\r
+    5 3 4 MULLW\r
+    5 ds-reg 0 STW\r
+] f f f \ fixnum*fast define-sub-primitive\r
+\r
+[ \ AND jit-math ] f f f \ fixnum-bitand define-sub-primitive\r
+\r
+[ \ OR jit-math ] f f f \ fixnum-bitor define-sub-primitive\r
+\r
+[ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive\r
+\r
+[\r
+    3 ds-reg 0 LWZ\r
+    3 3 NOT\r
+    3 3 tag-mask get XORI\r
+    3 ds-reg 0 STW\r
+] f f f \ fixnum-bitnot define-sub-primitive\r
+\r
 [ "bootstrap.ppc" forget-vocab ] with-compilation-unit\r
index c9c4432d5267f12a5558c2f04f0ca5fe79c28c97..4e1c3512afd65453be9e41cc6398d3233d404b4d 100755 (executable)
@@ -1,14 +1,13 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: alien alien.accessors alien.c-types arrays cpu.ppc.assembler
-cpu.ppc.architecture cpu.ppc.allot cpu.architecture kernel
-kernel.private math math.private namespaces sequences words
-generic quotations byte-arrays hashtables hashtables.private
-generator generator.registers generator.fixup sequences.private
-sbufs vectors system layouts math.floats.private
-classes classes.tuple classes.tuple.private sbufs.private
-vectors.private strings.private slots.private combinators
-compiler.constants ;
+USING: accessors alien alien.accessors alien.c-types arrays
+cpu.ppc.assembler cpu.ppc.architecture cpu.ppc.allot
+cpu.architecture kernel kernel.private math math.private
+namespaces sequences words generic quotations byte-arrays
+hashtables hashtables.private generator generator.registers
+generator.fixup sequences.private sbufs vectors system layouts
+math.floats.private classes slots.private combinators
+compiler.constants optimizer.allot ;
 IN: cpu.ppc.intrinsics
 
 : %slot-literal-known-tag
@@ -445,38 +444,33 @@ IN: cpu.ppc.intrinsics
     ! Store tagged ptr in reg
     "tuple" get tuple %store-tagged
 ] H{
-    { +input+ { { [ tuple-layout? ] "layout" } } }
+    { +input+ { { [ ] "layout" } } }
     { +scratch+ { { f "tuple" } } }
     { +output+ { "tuple" } }
 } define-intrinsic
 
-\ <array> [
+\ (array) [
     array "n" get 2 + cells %allot
     ! Store length
     "n" operand 12 LI
     12 11 cell STW
-    ! Store initial element
-    "n" get [ "initial" operand 11 rot 2 + cells STW ] each
     ! Store tagged ptr in reg
     "array" get object %store-tagged
 ] H{
-    { +input+ { { [ inline-array? ] "n" } { f "initial" } } }
+    { +input+ { { [ ] "n" } } }
     { +scratch+ { { f "array" } } }
     { +output+ { "array" } }
 } define-intrinsic
 
-\ <byte-array> [
+\ (byte-array) [
     byte-array "n" get 2 cells + %allot
     ! Store length
     "n" operand 12 LI
     12 11 cell STW
-    ! Store initial element
-    0 12 LI
-    "n" get cell align cell /i [ 12 11 rot 2 + cells STW ] each
     ! Store tagged ptr in reg
     "array" get object %store-tagged
 ] H{
-    { +input+ { { [ inline-array? ] "n" } } }
+    { +input+ { { [ ] "n" } } }
     { +scratch+ { { f "array" } } }
     { +output+ { "array" } }
 } define-intrinsic
index bf176eebfa7e97b68b9c8b6e0b2b217854c24858..76a42b3f2d7132b68655ff8af7200362d417df8a 100755 (executable)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2007, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: bootstrap.image.private kernel namespaces system
-cpu.x86.assembler layouts compiler.units math generator.fixup
-compiler.constants vocabs ;
+USING: bootstrap.image.private kernel kernel.private namespaces
+system cpu.x86.assembler layouts compiler.units math math.private
+generator.fixup compiler.constants vocabs slots.private words
+words.private ;
 IN: bootstrap.x86
 
 big-endian off
@@ -39,6 +40,12 @@ big-endian off
     ds-reg [] arg0 MOV                         ! store literal on datastack
 ] rc-absolute-cell rt-literal 1 rex-length + jit-push-literal jit-define
 
+[
+    arg0 0 MOV                                 ! load literal
+    ds-reg bootstrap-cell ADD                  ! increment datastack pointer
+    ds-reg [] arg0 MOV                         ! store literal on datastack
+] rc-absolute-cell rt-immediate 1 rex-length + jit-push-immediate jit-define
+
 [
     arg0 0 MOV                                 ! load XT
     arg1 stack-reg MOV                         ! pass callstack pointer as arg 2
@@ -74,27 +81,34 @@ big-endian off
     arg0 quot-xt-offset [+] JMP                ! execute branch
 ] rc-absolute-cell rt-literal 1 rex-length + jit-dispatch jit-define
 
+[
+    stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
+] f f f jit-epilog jit-define
+
+[ 0 RET ] f f f jit-return jit-define
+
+! Sub-primitives
+
+! Quotations and words
+[
+    arg0 ds-reg [] MOV                         ! load from stack
+    ds-reg bootstrap-cell SUB                  ! pop stack
+    arg0 quot-xt-offset [+] JMP                ! call quotation
+] f f f \ (call) define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV                         ! load from stack
+    ds-reg bootstrap-cell SUB                  ! pop stack
+    arg0 word-xt-offset [+] JMP                ! execute word
+] f f f \ (execute) define-sub-primitive
+
+! Objects
 [
     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
+] f f f \ tag define-sub-primitive
 
 [
     arg0 ds-reg [] MOV                         ! load slot number
@@ -105,63 +119,187 @@ big-endian off
     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
+] f f f \ slot define-sub-primitive
 
+! Shufflers
 [
     ds-reg bootstrap-cell SUB
-] f f f jit-drop jit-define
+] f f f \ drop define-sub-primitive
+
+[
+    ds-reg 2 bootstrap-cells SUB
+] f f f \ 2drop define-sub-primitive
+
+[
+    ds-reg 3 bootstrap-cells SUB
+] f f f \ 3drop define-sub-primitive
 
 [
     arg0 ds-reg [] MOV
     ds-reg bootstrap-cell ADD
     ds-reg [] arg0 MOV
-] f f f jit-dup jit-define
+] f f f \ dup define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV
+    arg1 ds-reg bootstrap-cell neg [+] MOV
+    ds-reg 2 bootstrap-cells ADD
+    ds-reg [] arg0 MOV
+    ds-reg bootstrap-cell neg [+] arg1 MOV
+] f f f \ 2dup define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    temp-reg ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg 3 bootstrap-cells ADD
+    ds-reg [] arg0 MOV
+    ds-reg -1 bootstrap-cells [+] arg1 MOV
+    ds-reg -2 bootstrap-cells [+] temp-reg MOV
+] f f f \ 3dup define-sub-primitive
 
 [
-    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 [] arg0 MOV
+] f f f \ nip define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV
+    ds-reg 2 bootstrap-cells SUB
+    ds-reg [] arg0 MOV
+] f f f \ 2nip define-sub-primitive
 
 [
+    arg0 ds-reg -1 bootstrap-cells [+] MOV
     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
+] f f f \ over define-sub-primitive
+
+[
+    arg0 ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg bootstrap-cell ADD
+    ds-reg [] arg0 MOV
+] f f f \ pick define-sub-primitive
 
 [
     arg0 ds-reg [] MOV
-    arg1 ds-reg bootstrap-cell neg [+] MOV
-    ds-reg bootstrap-cell neg [+] arg0 MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
     ds-reg [] arg1 MOV
-] f f f jit-swap jit-define
+    ds-reg bootstrap-cell ADD
+    ds-reg [] arg0 MOV
+] f f f \ dupd define-sub-primitive
 
 [
-    arg0 ds-reg bootstrap-cell neg [+] MOV
+    arg0 ds-reg [] MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
     ds-reg bootstrap-cell ADD
     ds-reg [] arg0 MOV
-] f f f jit-over jit-define
+    ds-reg -1 bootstrap-cells [+] arg1 MOV
+    ds-reg -2 bootstrap-cells [+] arg0 MOV
+] f f f \ tuck define-sub-primitive
 
 [
     arg0 ds-reg [] MOV
-    ds-reg bootstrap-cell SUB
-    arg1 ds-reg [] MOV
-    arg1 arg0 SUB
+    arg1 ds-reg bootstrap-cell neg [+] MOV
+    ds-reg bootstrap-cell neg [+] arg0 MOV
     ds-reg [] arg1 MOV
-] f f f jit-fixnum-fast jit-define
+] f f f \ swap define-sub-primitive
+
+[
+    arg0 ds-reg -1 bootstrap-cells [+] MOV
+    arg1 ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg -2 bootstrap-cells [+] arg0 MOV
+    ds-reg -1 bootstrap-cells [+] arg1 MOV
+] f f f \ swapd define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    temp-reg ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg -2 bootstrap-cells [+] arg1 MOV
+    ds-reg -1 bootstrap-cells [+] arg0 MOV
+    ds-reg [] temp-reg MOV
+] f f f \ rot define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV
+    arg1 ds-reg -1 bootstrap-cells [+] MOV
+    temp-reg ds-reg -2 bootstrap-cells [+] MOV
+    ds-reg -2 bootstrap-cells [+] arg0 MOV
+    ds-reg -1 bootstrap-cells [+] temp-reg MOV
+    ds-reg [] arg1 MOV
+] f f f \ -rot define-sub-primitive
+
+[
+    rs-reg bootstrap-cell ADD
+    arg0 ds-reg [] MOV
+    ds-reg bootstrap-cell SUB
+    rs-reg [] arg0 MOV
+] f f f \ >r define-sub-primitive
 
 [
-    jit-compare
-    arg1 temp-reg CMOVL                        ! not equal?
+    ds-reg bootstrap-cell ADD
+    arg0 rs-reg [] MOV
+    rs-reg bootstrap-cell SUB
+    ds-reg [] arg0 MOV
+] f f f \ r> define-sub-primitive
+
+! Comparisons
+: jit-compare ( insn -- )
+    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
+    [ arg1 temp-reg ] dip execute              ! move t if true
     ds-reg [] arg1 MOV                         ! store
-] rc-absolute-cell rt-literal 1 rex-length + jit-fixnum>= jit-define
+    ;
+
+: define-jit-compare ( insn word -- )
+    [ [ jit-compare ] curry rc-absolute-cell rt-literal 1 rex-length + ] dip
+    define-sub-primitive ;
+
+\ CMOVNE \ eq? define-jit-compare
+\ CMOVL \ fixnum>= define-jit-compare
+\ CMOVG \ fixnum<= define-jit-compare
+\ CMOVLE \ fixnum> define-jit-compare
+\ CMOVGE \ fixnum< define-jit-compare
+
+! Math
+: jit-math ( insn -- )
+    arg0 ds-reg [] MOV                         ! load second input
+    ds-reg bootstrap-cell SUB                  ! pop stack
+    arg1 ds-reg [] MOV                         ! load first input
+    [ arg1 arg0 ] dip execute                  ! compute result
+    ds-reg [] arg1 MOV                         ! push result
+    ;
+
+[ \ ADD jit-math ] f f f \ fixnum+fast define-sub-primitive
+
+[ \ SUB jit-math ] f f f \ fixnum-fast define-sub-primitive
 
 [
-    stack-reg stack-frame-size bootstrap-cell - ADD ! unwind stack frame
-] f f f jit-epilog jit-define
+    arg0 ds-reg [] MOV                         ! load second input
+    ds-reg bootstrap-cell SUB                  ! pop stack
+    arg1 ds-reg [] MOV                         ! load first input
+    arg0 tag-bits get SAR                      ! untag second input
+    arg0 arg1 IMUL2                            ! multiply
+    ds-reg [] arg1 MOV                         ! push result
+] f f f \ fixnum*fast define-sub-primitive
 
-[ 0 RET ] f f f jit-return jit-define
+[ \ AND jit-math ] f f f \ fixnum-bitand define-sub-primitive
+
+[ \ OR jit-math ] f f f \ fixnum-bitor define-sub-primitive
+
+[ \ XOR jit-math ] f f f \ fixnum-bitxor define-sub-primitive
+
+[
+    arg0 ds-reg [] MOV                         ! load input input
+    arg0 NOT                                   ! complement
+    arg0 tag-mask get XOR                      ! clear tag bits
+    ds-reg [] arg0 MOV                         ! save
+] f f f \ fixnum-bitnot define-sub-primitive
 
 [ "bootstrap.x86" forget-vocab ] with-compilation-unit
index d19749ae3917dce3c8a82b8f8079bc55c66ff15e..3cf131087e97eeaffb27a9d09eefc166f498b2f3 100755 (executable)
@@ -6,8 +6,7 @@ kernel.private math math.private namespaces quotations sequences
 words generic byte-arrays hashtables hashtables.private
 generator generator.registers generator.fixup sequences.private
 sbufs sbufs.private vectors vectors.private layouts system
-classes.tuple.private strings.private slots.private
-compiler.constants ;
+strings.private slots.private compiler.constants optimizer.allot ;
 IN: cpu.x86.intrinsics
 
 ! Type checks
@@ -298,37 +297,33 @@ IN: cpu.x86.intrinsics
         "tuple" get tuple %store-tagged
     ] %allot
 ] H{
-    { +input+ { { [ tuple-layout? ] "layout" } } }
+    { +input+ { { [ ] "layout" } } }
     { +scratch+ { { f "tuple" } { f "scratch" } } }
     { +output+ { "tuple" } }
 } define-intrinsic
 
-\ <array> [
+\ (array) [
     array "n" get 2 + cells [
         ! Store length
         1 object@ "n" operand MOV
-        ! Zero out the rest of the tuple
-        "n" get [ 2 + object@ "initial" operand MOV ] each
         ! Store tagged ptr in reg
         "array" get object %store-tagged
     ] %allot
 ] H{
-    { +input+ { { [ inline-array? ] "n" } { f "initial" } } }
+    { +input+ { { [ ] "n" } } }
     { +scratch+ { { f "array" } } }
     { +output+ { "array" } }
 } define-intrinsic
 
-\ <byte-array> [
+\ (byte-array) [
     byte-array "n" get 2 cells + [
         ! Store length
         1 object@ "n" operand MOV
-        ! Store initial element
-        "n" get cell align cell /i [ 2 + object@ 0 MOV ] each
         ! Store tagged ptr in reg
         "array" get object %store-tagged
     ] %allot
 ] H{
-    { +input+ { { [ inline-array? ] "n" } } }
+    { +input+ { { [ ] "n" } } }
     { +scratch+ { { f "array" } } }
     { +output+ { "array" } }
 } define-intrinsic
index 6759c43094fee377ac4a3ba4ade14d67e2943334..151ef3b6e9654b8a6a1e01b07da8a5b6b4a53606 100755 (executable)
@@ -212,6 +212,12 @@ M: not-a-tuple summary
 M: bad-superclass summary
     drop "Tuple classes can only inherit from other tuple classes" ;
 
+M: no-initial-value summary
+    drop "Initial value must be provided for slots specialized to this class" ;
+
+M: bad-initial-value summary
+    drop "Incompatible initial value" ;
+
 M: no-cond summary
     drop "Fall-through in cond" ;
 
index 058822bf2f5e48f70a7f51490636f8c7aebc4632..9be8151bee0c9e4c7defdf64223bc2535cfd5838 100755 (executable)
@@ -72,6 +72,7 @@ SYMBOL: label-table
 : rt-xt        4 ;
 : rt-here      5 ;
 : rt-label     6 ;
+: rt-immediate 7 ;
 
 TUPLE: label-fixup label class ;
 
index f7a37691a6fc6badd83fca916581eca7e6deacb5..3b3a98eabd17b470045a12b5477fd3c2d055de92 100644 (file)
@@ -2,10 +2,14 @@ USING: help.markup help.syntax sequences strings ;
 IN: grouping
 
 ARTICLE: "grouping" "Groups and clumps"
+"Splitting a sequence into disjoint, fixed-length subsequences:"
+{ $subsection group }
 "A virtual sequence for splitting a sequence into disjoint, fixed-length subsequences:"
 { $subsection groups }
 { $subsection <groups> }
 { $subsection <sliced-groups> }
+"Splitting a sequence into overlapping, fixed-length subsequences:"
+{ $subsection clump }
 "A virtual sequence for splitting a sequence into overlapping, fixed-length subsequences:"
 { $subsection clumps }
 { $subsection <clumps> }
index 57919671c822dd9289739afb293dbdb3082054d3..336f1da91a5d55f164710d57d2a921e8d1e3bedb 100644 (file)
@@ -59,4 +59,11 @@ M: growable lengthen ( n seq -- )
         2dup (>>length)
     ] when 2drop ;
 
+M: growable shorten ( n seq -- )
+    growable-check
+    2dup length < [
+        2dup contract
+        2dup (>>length)
+    ] when 2drop ;
+
 INSTANCE: growable sequence
index 3cd9ee23af7c1286307b6b662c31ef0390591d29..07517afdf7f9b6514ee2cdf1fb9ef43c93efeab6 100755 (executable)
@@ -93,11 +93,6 @@ HELP: hash-deleted+
 { $description "Called to increment the deleted entry counter when an entry is removed with " { $link delete-at } }
 { $side-effects "hash" } ;
 
-HELP: (set-hash)
-{ $values { "value" "a value" } { "key" "a key to add" } { "hash" hashtable } { "new?" "a boolean" } }
-{ $description "Stores the key/value pair into the hashtable. This word does not grow the hashtable if it exceeds capacity, therefore a hang can result. User code should use " { $link set-at } " instead, which grows the hashtable if necessary." }
-{ $side-effects "hash" } ;
-
 HELP: grow-hash
 { $values { "hash" hashtable } }
 { $description "Enlarges the capacity of a hashtable. User code does not need to call this word directly." }
index 4e80ed1f6e41e22a8ee33fae543d06f0281f2ddf..32684b92dcfbc6c7727de0186439ae1542071bd5 100755 (executable)
@@ -164,3 +164,16 @@ H{ } "x" set
 [ { "one" "two" 3 } ] [
     { 1 2 3 } H{ { 1 "one" } { 2 "two" } } substitute
 ] unit-test
+
+! We want this to work
+[ ] [ hashtable new "h" set ] unit-test
+
+[ 0 ] [ "h" get assoc-size ] unit-test
+
+[ f f ] [ "goo" "h" get at* ] unit-test
+
+[ ] [ 1 2 "h" get set-at ] unit-test
+
+[ 1 ] [ "h" get assoc-size ] unit-test
+
+[ 1 ] [ 2 "h" get at ] unit-test
index 3b794d1715c10528a0f63aac586229901b3cd278..e804bb76fab665e3315c9af4bf2c3a8fa192d336 100755 (executable)
@@ -20,15 +20,18 @@ TUPLE: hashtable
 : probe ( array i -- array i )
     2 fixnum+fast over wrap ; inline
 
-: (key@) ( key keys i -- array n ? )
+: no-key ( key array -- array n ? ) nip f f ; inline
+
+: (key@) ( key array i -- array n ? )
     3dup swap array-nth
     dup ((empty)) eq?
-    [ 3drop nip f f ] [
+    [ 3drop no-key ] [
         = [ rot drop t ] [ probe (key@) ] if
     ] if ; inline
 
 : key@ ( key hash -- array n ? )
-    array>> 2dup hash@ (key@) ; inline
+    array>> dup array-capacity 0 eq?
+    [ no-key ] [ 2dup hash@ (key@) ] if ; inline
 
 : <hash-array> ( n -- array )
     1+ next-power-of-2 4 * ((empty)) <array> ; inline
@@ -63,25 +66,20 @@ TUPLE: hashtable
 : hash-deleted+ ( hash -- )
     [ 1+ ] change-deleted drop ; inline
 
-: (set-hash) ( value key hash -- new? )
-    2dup new-key@
-    [ rot hash-count+ set-nth-pair t ]
-    [ rot drop set-nth-pair f ] if ; inline
-
 : (rehash) ( hash alist -- )
-    swap [ swapd (set-hash) drop ] curry assoc-each ;
+    swap [ swapd set-at ] curry assoc-each ; inline
 
 : hash-large? ( hash -- ? )
-    [ count>> 3 fixnum*fast  ]
-    [ array>> array-capacity ] bi > ;
+    [ count>> 3 fixnum*fast 1 fixnum+fast ]
+    [ array>> array-capacity ] bi fixnum> ; inline
 
 : hash-stale? ( hash -- ? )
-    [ deleted>> 10 fixnum*fast ] [ count>> ] bi fixnum> ;
+    [ deleted>> 10 fixnum*fast ] [ count>> ] bi fixnum> ; inline
 
 : grow-hash ( hash -- )
     [ dup >alist swap assoc-size 1+ ] keep
     [ reset-hash ] keep
-    swap (rehash) ;
+    swap (rehash) ; inline
 
 : ?grow-hash ( hash -- )
     dup hash-large? [
@@ -122,7 +120,10 @@ M: hashtable assoc-size ( hash -- n )
     r> (rehash) ;
 
 M: hashtable set-at ( value key hash -- )
-    dup >r (set-hash) [ r> ?grow-hash ] [ r> drop ] if ;
+    dup ?grow-hash
+    2dup new-key@
+    [ rot hash-count+ set-nth-pair ]
+    [ rot drop set-nth-pair ] if ;
 
 : associate ( value key -- hash )
     2 <hashtable> [ set-at ] keep ;
index 591baf128793427ddf351801b12ca9acf7d51a98..7be70f1ad4bae1ccdfcc7bdcb3e9723912fba8ba 100755 (executable)
@@ -5,8 +5,9 @@ sequences words inference.class quotations alien
 alien.c-types strings sbufs sequences.private
 slots.private combinators definitions compiler.units
 system layouts vectors optimizer.math.partial
-optimizer.inlining optimizer.backend math.order
-accessors hashtables classes assocs ;
+optimizer.inlining optimizer.backend math.order math.functions
+accessors hashtables classes assocs io.encodings.utf8
+io.encodings.ascii io.encodings ;
 
 [ t ] [ T{ literal-constraint f 1 2 } T{ literal-constraint f 1 2 } equal? ] unit-test
 
@@ -193,19 +194,15 @@ M: fixnum detect-fx ;
 
 
 [ t ] [
-    [ { string sbuf } declare push-all ] \ push-all inlined?
+    [ { string sbuf } declare ] \ push-all def>> append \ + inlined?
 ] unit-test
 
 [ t ] [
-    [ { string sbuf } declare push-all ] \ + inlined?
+    [ { string sbuf } declare ] \ push-all def>> append \ fixnum+ inlined?
 ] unit-test
 
 [ t ] [
-    [ { string sbuf } declare push-all ] \ fixnum+ inlined?
-] unit-test
-
-[ t ] [
-    [ { string sbuf } declare push-all ] \ >fixnum inlined?
+    [ { string sbuf } declare ] \ push-all def>> append \ >fixnum inlined?
 ] unit-test
 
 [ t ] [
@@ -600,6 +597,29 @@ TUPLE: declared-fixnum { x fixnum } ;
     { slot } inlined?
 ] unit-test
 
+[ t ] [
+    [
+        { array } declare length
+        1 + dup 100 fixnum> [ 1 fixnum+ ] when
+    ] \ fixnum+ inlined?
+] unit-test
+[ t ] [
+    [ [ resize-array ] keep length ] \ length inlined?
+] unit-test
+
+[ t ] [
+    [ dup 0 > [ sqrt ] when ] \ sqrt inlined?
+] unit-test
+
+[ t ] [
+    [ { utf8 } declare decode-char ] \ decode-char inlined?
+] unit-test
+
+[ t ] [
+    [ { ascii } declare decode-char ] \ decode-char inlined?
+] unit-test
+
 ! Later
 
 ! [ t ] [
index 2f7058ba9650294a436eef7c8b7b0ed8a81e0403..7cd0c1d54008bda9c10ab46369713255e396f2dd 100755 (executable)
@@ -129,8 +129,12 @@ GENERIC: infer-classes-before ( node -- )
 
 GENERIC: infer-classes-around ( node -- )
 
+GENERIC: infer-classes-after ( node -- )
+
 M: node infer-classes-before drop ;
 
+M: node infer-classes-after drop ;
+
 M: node child-constraints
     children>> length
     dup zero? [ drop f ] [ f <repetition> ] if ;
@@ -203,11 +207,19 @@ M: pair constraint-satisfied?
     [ ] [ param>> "default-output-classes" word-prop ] ?if
     r> ;
 
-M: #call infer-classes-before
-    [ compute-constraints ] keep
-    [ output-classes ] [ out-d>> ] bi
+: intersect-values ( classes intervals values -- )
     tuck [ intersect-classes ] [ intersect-intervals ] 2bi* ;
 
+M: #call infer-classes-before
+    [ compute-constraints ]
+    [ [ output-classes ] [ out-d>> ] bi intersect-values ] bi ;
+
+: input-classes ( #call -- classes )
+    param>> "input-classes" word-prop ;
+
+M: #call infer-classes-after
+    [ input-classes ] [ in-d>> ] bi intersect-classes ;
+
 M: #push infer-classes-before
     out-d>> [ [ value-literal ] keep set-value-literal* ] each ;
 
@@ -340,6 +352,7 @@ M: object infer-classes-around
     {
         [ infer-classes-before ]
         [ annotate-node ]
+        [ infer-classes-after ]
         [ infer-children ]
         [ merge-children ]
     } cleave ;
index e1d5bd434c8c761a8f4ee1c7138a90e9e1195ad0..9e01492529fb922b19456e845f6804c337693cc1 100644 (file)
@@ -1,9 +1,9 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
+USING: kernel generic sequences prettyprint io words arrays
+summary effects debugger assocs accessors inference.backend
+inference.dataflow ;
 IN: inference.errors
-USING: inference.backend inference.dataflow kernel generic
-sequences prettyprint io words arrays summary effects debugger
-assocs accessors ;
 
 M: inference-error error-help error>> error-help ;
 
index ac79cce799ed76f5f4789c2c961352d400ebd64d..3636a0196337538b2fb434901f4a21eb2557ca6d 100755 (executable)
@@ -104,6 +104,8 @@ M: object infer-call
     ] if
 ] "infer" set-word-prop
 
+\ execute t "no-compile" set-word-prop
+
 \ if [
     3 ensure-values
     2 d-tail [ special? ] contains? [
@@ -123,6 +125,8 @@ M: object infer-call
     [ #dispatch ] infer-branches
 ] "infer" set-word-prop
 
+\ dispatch t "no-compile" set-word-prop
+
 \ curry [
     2 ensure-values
     pop-d pop-d swap <curried> push-d
@@ -149,8 +153,10 @@ M: object infer-call
 ] "infer" set-word-prop
 
 :  set-primitive-effect ( word effect -- )
-    2dup effect-out "default-output-classes" set-word-prop
-    dupd [ make-call-node ] 2curry "infer" set-word-prop ;
+    [ in>> "input-classes" set-word-prop ]
+    [ out>> "default-output-classes" set-word-prop ]
+    [ dupd [ make-call-node ] 2curry "infer" set-word-prop ]
+    2tri ;
 
 ! Stack effects for all primitives
 \ fixnum< { fixnum fixnum } { object } <effect> set-primitive-effect
@@ -534,9 +540,6 @@ set-primitive-effect
 \ <tuple> { tuple-layout } { tuple } <effect> set-primitive-effect
 \ <tuple> make-flushable
 
-\ (tuple) { tuple-layout } { tuple } <effect> set-primitive-effect
-\ (tuple) make-flushable
-
 \ <tuple-layout> { word fixnum array fixnum } { tuple-layout } <effect> set-primitive-effect
 \ <tuple-layout> make-foldable
 
index 0f925d1ea1821d977123fb2dd166f2bca2f193a8..7d7af5d4fd0343789bfc373d62dc1e80a6ed1a05 100755 (executable)
@@ -33,10 +33,10 @@ SYMBOL: +editable+
 : write-value ( mirror key -- )
     <value-ref> write-slot-editor ;
 
-: describe-row ( obj key n -- )
+: describe-row ( mirror key n -- )
     [
         +number-rows+ get [ pprint-cell ] [ drop ] if
-        2dup write-key write-value
+        [ write-key ] [ write-value ] 2bi
     ] with-row ;
 
 : summary. ( obj -- ) [ summary ] keep write-object nl ;
@@ -48,21 +48,19 @@ SYMBOL: +editable+
         sort-keys values
     ] [ keys ] if ;
 
-: describe* ( obj flags -- )
-    clone [
-        dup summary.
-        make-mirror dup sorted-keys dup empty? [
-            2drop
-        ] [
-            dup enum? [ +sequence+ on ] when
-            standard-table-style [
-                dup length
-                rot [ -rot describe-row ] curry 2each
-            ] tabular-output
-        ] if
-    ] bind ;
+: describe* ( obj mirror keys -- )
+    rot summary.
+    dup empty? [
+        2drop
+    ] [
+        dup enum? [ +sequence+ on ] when
+        standard-table-style [
+            swap [ -rot describe-row ] curry each-index
+        ] tabular-output
+    ] if ;
 
-: describe ( obj -- ) H{ } describe* ;
+: describe ( obj -- )
+    dup make-mirror dup sorted-keys describe* ;
 
 M: tuple error. describe ;
 
@@ -78,19 +76,21 @@ M: tuple error. describe ;
 
 SYMBOL: inspector-hook
 
-[ H{ { +number-rows+ t } } describe* ] inspector-hook set-global
+[ t +number-rows+ [ describe* ] with-variable ] inspector-hook set-global
 
 SYMBOL: inspector-stack
 
 SYMBOL: me
 
 : reinspect ( obj -- )
-    dup me set
-    dup make-mirror dup mirror set keys \ keys set
-    inspector-hook get call ;
+    [ me set ]
+    [
+        dup make-mirror dup mirror set dup sorted-keys dup \ keys set
+        inspector-hook get call
+    ] bi ;
 
 : (inspect) ( obj -- )
-    dup inspector-stack get push reinspect ;
+    [ inspector-stack get push ] [ reinspect ] bi ;
 
 : key@ ( n -- key ) \ keys get nth ;
 
@@ -123,6 +123,7 @@ SYMBOL: me
     "&add ( value key -- ) add new slot" print
     "&delete ( n -- ) remove a slot" print
     "&rename ( key n -- ) change a slot's key" print
+    "&globals ( -- ) inspect global namespace" print
     "&help -- display this message" print
     nl ;
 
@@ -133,3 +134,5 @@ SYMBOL: me
 
 : inspect ( obj -- )
     inspector-stack get [ (inspect) ] [ inspector ] if ;
+
+: &globals ( -- ) global inspect ;
index 942476616fa95aa0d2f0cdfb2fdb453d05a06326..0181f80af444999c5c52743d3fda5c14253c4d89 100755 (executable)
@@ -99,14 +99,20 @@ M: decoder stream-read-partial stream-read ;
     [ >r drop "" like r> ]
     [ pick push ((read-until)) ] if ; inline
 
-: (read-until) ( seps stream -- string/f sep/f )
-    SBUF" " clone -rot >decoder<
+: (read-until) ( quot -- string/f sep/f )
+    100 <sbuf> swap ((read-until)) ; inline
+
+: decoder-read-until ( seps stream encoding -- string/f sep/f )
     [ decode-char dup [ dup rot member? ] [ 2drop f t ] if ] 3curry
-    ((read-until)) ; inline
+    (read-until) ;
+
+M: decoder stream-read-until >decoder< decoder-read-until ;
 
-M: decoder stream-read-until (read-until) ;
+: decoder-readln ( stream encoding -- string/f sep/f )
+    [ decode-char dup [ dup "\r\n" member? ] [ drop f t ] if ] 2curry
+    (read-until) ;
 
-M: decoder stream-readln "\r\n" over (read-until) handle-readln ;
+M: decoder stream-readln dup >decoder< decoder-readln handle-readln ;
 
 M: decoder dispose stream>> dispose ;
 
@@ -119,8 +125,11 @@ M: object <encoder> encoder boa ;
 M: encoder stream-write1
     >encoder< encode-char ;
 
+: decoder-write ( string stream encoding -- )
+    [ encode-char ] 2curry each ;
+
 M: encoder stream-write
-    >encoder< [ encode-char ] 2curry each ;
+    >encoder< decoder-write ;
 
 M: encoder dispose encoder-stream dispose ;
 
index 09524802e0e568b2c3ac22258ef9ec01e850a69e..ae8a455c71587d8b2f99d88c000e9fa6bff21b31 100755 (executable)
@@ -11,21 +11,21 @@ SINGLETON: utf8
 <PRIVATE 
 
 : starts-2? ( char -- ? )
-    dup [ -6 shift BIN: 10 number= ] when ;
+    dup [ -6 shift BIN: 10 number= ] when ; inline
 
 : append-nums ( stream byte -- stream char )
     over stream-read1 dup starts-2?
     [ swap 6 shift swap BIN: 111111 bitand bitor ]
-    [ 2drop replacement-char ] if ;
+    [ 2drop replacement-char ] if ; inline
 
 : double ( stream byte -- stream char )
-    BIN: 11111 bitand append-nums ;
+    BIN: 11111 bitand append-nums ; inline
 
 : triple ( stream byte -- stream char )
-    BIN: 1111 bitand append-nums append-nums ;
+    BIN: 1111 bitand append-nums append-nums ; inline
 
 : quad ( stream byte -- stream char )
-    BIN: 111 bitand append-nums append-nums append-nums ;
+    BIN: 111 bitand append-nums append-nums append-nums ; inline
 
 : begin-utf8 ( stream byte -- stream char )
     {
@@ -34,10 +34,10 @@ SINGLETON: utf8
         { [ dup -4 shift BIN: 1110 number= ] [ triple ] }
         { [ dup -3 shift BIN: 11110 number= ] [ quad ] }
         [ drop replacement-char ]
-    } cond ;
+    } cond ; inline
 
 : decode-utf8 ( stream -- char/f )
-    dup stream-read1 dup [ begin-utf8 ] when nip ;
+    dup stream-read1 dup [ begin-utf8 ] when nip ; inline
 
 M: utf8 decode-char
     drop decode-utf8 ;
index c5bd0615a713ca3b89c542c3753fce3056c0417a..195e9becaefd56d8af096eff1a4d2035da9a0fc5 100755 (executable)
@@ -114,10 +114,6 @@ IN: kernel.tests
 
 [ total-failure-1 ] must-fail
 
-: total-failure-2 [ ] (call) unimplemented ;
-
-[ total-failure-2 ] must-fail
-
 ! From combinators.lib
 [ 1 1 2 2 3 3 ] [ 1 2 3 [ dup ] tri@ ] unit-test
 [ 1 4 9 ] [ 1 2 3 [ sq ] tri@ ] unit-test
diff --git a/core/optimizer/allot/allot.factor b/core/optimizer/allot/allot.factor
new file mode 100644 (file)
index 0000000..eff2eaf
--- /dev/null
@@ -0,0 +1,100 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors sequences sequences.private classes.tuple
+classes.tuple.private kernel effects words quotations namespaces
+definitions math math.order layouts alien.accessors
+slots.private arrays byte-arrays inference.dataflow
+inference.known-words inference.state optimizer.inlining
+optimizer.backend ;
+IN: optimizer.allot
+
+! Expand memory allocation primitives into simpler constructs
+! to simplify the backend.
+
+: first-input ( #call -- obj ) dup in-d>> first node-literal ;
+
+: (tuple) ( layout -- tuple ) "BUG: missing (tuple) intrinsic" throw ;
+
+\ (tuple) { tuple-layout } { tuple } <effect> set-primitive-effect
+\ (tuple) make-flushable
+
+! if the input to new is a literal tuple class, we can expand it
+: literal-new? ( #call -- ? )
+    first-input tuple-class? ;
+
+: new-quot ( class -- quot )
+    dup all-slots 1 tail ! delegate slot
+    [ [ initial>> literalize , ] each literalize , \ boa , ] [ ] make ;
+
+: expand-new ( #call -- node )
+    dup first-input
+    [ +inlined+ depends-on ] [ new-quot ] bi
+    f splice-quot ;
+
+\ new {
+    { [ dup literal-new? ] [ expand-new ] }
+} define-optimizers
+
+: tuple-boa-quot ( layout -- quot )
+    [
+        dup ,
+        [ nip (tuple) ] %
+        size>> 1 - [ 3 + ] map <reversed>
+        [ [ set-slot ] curry [ keep ] curry % ] each
+        [ f over 2 set-slot ] %
+    ] [ ] make ;
+
+: expand-tuple-boa ( #call -- node )
+    dup in-d>> peek value-literal tuple-boa-quot f splice-quot ;
+
+\ <tuple-boa> {
+    { [ t ] [ expand-tuple-boa ] }
+} define-optimizers
+
+: (array) ( n -- array ) "BUG: missing (array) intrinsic" throw ;
+
+\ (array) { integer } { array } <effect> set-primitive-effect
+\ (array) make-flushable
+
+: <array>-quot ( n -- quot )
+    [
+        dup ,
+        [ (array) ] %
+        [ \ 2dup , , [ swap set-array-nth ] % ] each
+        \ 2nip ,
+    ] [ ] make ;
+
+: literal-<array>? ( #call -- ? )
+    first-input dup integer? [ 0 32 between? ] [ drop f ] if ;
+
+: expand-<array> ( #call -- node )
+    dup first-input <array>-quot f splice-quot ;
+
+\ <array> {
+    { [ dup literal-<array>? ] [ expand-<array> ] }
+} define-optimizers
+
+: (byte-array) ( n -- byte-array ) "BUG: missing (byte-array) intrinsic" throw ;
+
+\ (byte-array) { integer } { byte-array } <effect> set-primitive-effect
+\ (byte-array) make-flushable
+
+: bytes>cells ( m -- n ) cell align cell /i ;
+
+: <byte-array>-quot ( n -- quot )
+    [
+        dup ,
+        [ nip (byte-array) ] %
+        bytes>cells [ cell * ] map
+        [ [ 0 over ] % , [ set-alien-unsigned-cell ] % ] each
+    ] [ ] make ;
+
+: literal-<byte-array>? ( #call -- ? )
+    first-input dup integer? [ 0 128 between? ] [ drop f ] if ;
+
+: expand-<byte-array> ( #call -- node )
+    dup first-input <byte-array>-quot f splice-quot ;
+
+\ <byte-array> {
+    { [ dup literal-<byte-array>? ] [ expand-<byte-array> ] }
+} define-optimizers
index d4905a171808ac44da84f2fcab7480e957023e2a..55088fd7e2420927fb9a163b394b3f992d1a17a7 100755 (executable)
@@ -1,8 +1,7 @@
 ! Copyright (C) 2004, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: namespaces assocs sequences inference.dataflow
-inference.backend kernel generic assocs classes vectors
-accessors combinators ;
+USING: namespaces assocs sequences kernel generic assocs classes
+vectors accessors combinators inference.dataflow inference.backend ;
 IN: optimizer.def-use
 
 SYMBOL: def-use
index 7d98183160723e46652170c05cc6df6646073bb7..64852e42ade3617d9f8cf673a20cbecfa5ad506b 100644 (file)
@@ -7,14 +7,3 @@ sequences growable sbufs vectors sequences.private accessors kernel ;
 \ optimistic-inline? must-infer
 \ find-identity must-infer
 \ dispatching-class must-infer
-
-! Make sure we have sane heuristics
-[ t ] [ \ fixnum \ shift method should-inline? ] unit-test
-[ f ] [ \ array \ equal? method should-inline? ] unit-test
-[ f ] [ \ sequence \ hashcode* method should-inline? ] unit-test
-[ t ] [ \ array \ nth-unsafe method should-inline? ] unit-test
-[ t ] [ \ growable \ nth-unsafe method should-inline? ] unit-test
-[ t ] [ \ sbuf \ set-nth-unsafe method should-inline? ] unit-test
-[ t ] [ \ growable \ set-nth-unsafe method should-inline? ] unit-test
-[ t ] [ \ growable \ set-nth method should-inline? ] unit-test
-[ t ] [ \ vector \ (>>length) method should-inline? ] unit-test
index 618a2c746d0c58e7a257ae3f19a6fe373c221d2b..30acdb1b48d5244dac8b155bad62868740dd32ae 100755 (executable)
@@ -2,12 +2,13 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays generic assocs inference inference.class
 inference.dataflow inference.backend inference.state io kernel
-math namespaces sequences vectors words quotations hashtables
-combinators classes classes.algebra generic.math
-optimizer.math.partial continuations optimizer.def-use
-optimizer.backend generic.standard optimizer.specializers
-optimizer.def-use optimizer.pattern-match generic.standard
-optimizer.control kernel.private definitions sets ;
+math math.order namespaces sequences vectors words quotations
+hashtables combinators effects classes classes.union
+classes.algebra generic.math optimizer.math.partial
+continuations optimizer.def-use optimizer.backend
+generic.standard optimizer.specializers optimizer.def-use
+optimizer.pattern-match generic.standard optimizer.control
+kernel.private definitions sets summary ;
 IN: optimizer.inlining
 
 : remember-inlining ( node history -- )
@@ -31,9 +32,9 @@ DEFER: (flat-length)
 : word-flat-length ( word -- n )
     {
         ! not inline
-        { [ dup inline? not ] [ drop 0 ] }
+        { [ dup inline? not ] [ drop 1 ] }
         ! recursive and inline
-        { [ dup recursive-calls get key? ] [ drop 4 ] }
+        { [ dup recursive-calls get key? ] [ drop 10 ] }
         ! inline
         [ [ recursive-calls get conjoin ] [ def>> (flat-length) ] bi ]
     } cond ;
@@ -41,7 +42,7 @@ DEFER: (flat-length)
 : (flat-length) ( seq -- n )
     [
         {
-            { [ dup quotation? ] [ (flat-length) 1+ ] }
+            { [ dup quotation? ] [ (flat-length) + ] }
             { [ dup array? ] [ (flat-length) ] }
             { [ dup word? ] [ word-flat-length ] }
             [ drop 0 ]
@@ -51,7 +52,7 @@ DEFER: (flat-length)
 : flat-length ( word -- n )
     H{ } clone recursive-calls [
         [ recursive-calls get conjoin ]
-        [ def>> (flat-length) ]
+        [ def>> (flat-length) 5 /i ]
         bi
     ] with-variable ;
 
@@ -102,7 +103,7 @@ DEFER: (flat-length)
     [ f splice-quot ] [ 2drop t ] if ;
 
 : inline-method ( #call -- node )
-    dup node-param {
+    dup param>> {
         { [ dup standard-generic? ] [ inline-standard-method ] }
         { [ dup math-generic? ] [ inline-math-method ] }
         { [ dup math-partial? ] [ inline-math-partial ] }
@@ -155,15 +156,35 @@ DEFER: (flat-length)
     (optimize-predicate) optimize-check ;
 
 : flush-eval? ( #call -- ? )
-    dup node-param "flushable" word-prop [
-        node-out-d [ unused? ] all?
-    ] [
-        drop f
-    ] if ;
+    dup node-param "flushable" word-prop
+    [ node-out-d [ unused? ] all? ] [ drop f ] if ;
+
+ERROR: flushed-eval-error word ;
+
+M: flushed-eval-error summary
+    drop "Flushed evaluation of word would have thrown an error" ;
+
+: flushed-eval-quot ( #call -- quot )
+    #! A quotation to replace flushed evaluations with. We can't
+    #! just remove the code altogether, because if the optimizer
+    #! knows the input types of a word, it assumes the inputs are
+    #! of this type after the word returns, since presumably
+    #! the word would have checked input types itself. However,
+    #! if the word gets flushed, then it won't do this checking;
+    #! so we have to do it here.
+    [
+        dup param>> "input-classes" word-prop [
+            make-specializer %
+            [ dup param>> literalize , \ flushed-eval-error , ] [ ] make ,
+            \ unless ,
+        ] when*
+        dup in-d>> length [ \ drop , ] times
+        out-d>> length [ f , ] times
+    ] [ ] make ;
 
 : flush-eval ( #call -- node )
-    dup node-param +inlined+ depends-on
-    dup node-out-d length f <repetition> inline-literals ;
+    dup param>> +inlined+ depends-on
+    dup flushed-eval-quot f splice-quot ;
 
 : partial-eval? ( #call -- ? )
     dup node-param "foldable" word-prop [
@@ -195,13 +216,28 @@ DEFER: (flat-length)
     [ drop +inlined+ depends-on ] [ swap 1array ] 2bi
     splice-quot ;
 
+: classes-known? ( #call -- ? )
+    node-input-classes [
+        [ class-types length 1 = ]
+        [ union-class? not ]
+        bi and
+    ] contains? ;
+
+: inlining-rank ( #call -- n )
+    {
+        [ param>> flat-length 24 swap [-] 4 /i ]
+        [ param>> "default" word-prop -4 0 ? ]
+        [ param>> "specializer" word-prop 1 0 ? ]
+        [ param>> method-body? 1 0 ? ]
+        [ classes-known? 2 0 ? ]
+    } cleave + + + + ;
+
+: should-inline? ( #call -- ? )
+    inlining-rank 5 >= ;
+
 : optimistic-inline? ( #call -- ? )
-    dup node-param "specializer" word-prop dup [
-        >r node-input-classes r> specialized-length tail*
-        [ class-types length 1 = ] all?
-    ] [
-        2drop f
-    ] if ;
+    dup param>> "specializer" word-prop
+    [ should-inline? ] [ drop f ] if ;
 
 : already-inlined? ( #call -- ? )
     [ param>> ] [ history>> ] bi memq? ;
@@ -211,11 +247,8 @@ DEFER: (flat-length)
         dup param>> dup def>> splice-word-def
     ] if ;
 
-: should-inline? ( word -- ? )
-    flat-length 11 <= ;
-
 : method-body-inline? ( #call -- ? )
-    param>> dup [ method-body? ] [ "default" word-prop not ] bi and
+    dup param>> method-body?
     [ should-inline? ] [ drop f ] if ;
 
 M: #call optimize-node*
index 76ad0009cb05a5a1d38ef53e394a15049befb978..cd5ec7fda2d3684eabe61932c7ca406946662185 100755 (executable)
@@ -1,15 +1,15 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors alien arrays generic hashtables definitions
-inference.dataflow inference.state inference.class kernel assocs
-math math.order math.private kernel.private sequences words
-parser vectors strings sbufs io namespaces assocs quotations
-sequences.private io.binary io.streams.string layouts splitting
-math.intervals math.floats.private classes.tuple classes.predicate
-classes.tuple.private classes classes.algebra optimizer.def-use
-optimizer.backend optimizer.pattern-match optimizer.inlining
-sequences.private combinators byte-arrays byte-vectors
-slots.private ;
+kernel assocs math math.order math.private kernel.private
+sequences words parser vectors strings sbufs io namespaces
+assocs quotations sequences.private io.binary io.streams.string
+layouts splitting math.intervals math.floats.private
+classes.tuple classes.predicate classes.tuple.private classes
+classes.algebra sequences.private combinators byte-arrays
+byte-vectors slots.private inference.dataflow inference.state
+inference.class optimizer.def-use optimizer.backend
+optimizer.pattern-match optimizer.inlining optimizer.allot ;
 IN: optimizer.known-words
 
 { <tuple> <tuple-boa> (tuple) } [
@@ -25,37 +25,6 @@ IN: optimizer.known-words
     dup class? [ drop tuple ] unless 1array f
 ] "output-classes" set-word-prop
 
-! if the input to new is a literal tuple class, we can expand it
-: literal-new? ( #call -- ? )
-    dup in-d>> first node-literal tuple-class? ;
-
-: new-quot ( class -- quot )
-    dup all-slots 1 tail ! delegate slot
-    [ [ initial>> literalize , ] each literalize , \ boa , ] [ ] make ;
-
-: expand-new ( #call -- node )
-    dup dup in-d>> first node-literal
-    [ +inlined+ depends-on ] [ new-quot ] bi
-    f splice-quot ;
-
-\ new {
-    { [ dup literal-new? ] [ expand-new ] }
-} define-optimizers
-
-: tuple-boa-quot ( layout -- quot )
-    [ (tuple) ]
-    swap size>> 1 - [ 3 + ] map <reversed>
-    [ [ set-slot ] curry [ keep ] curry ] map concat
-    [ f over 2 set-slot ]
-    3append ;
-
-: expand-tuple-boa ( #call -- node )
-    dup in-d>> peek value-literal tuple-boa-quot f splice-quot ;
-
-\ <tuple-boa> {
-    { [ t ] [ expand-tuple-boa ] }
-} define-optimizers
-
 ! the output of clone has the same type as the input
 { clone (clone) } [
     [
index 27ef4042e2b292cf85d37f1629754b839ac3aa84..2c4e33e1833f7845197e61d7d799d5d539179413 100755 (executable)
@@ -1,14 +1,15 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
+USING: effects alien alien.accessors arrays generic hashtables
+kernel assocs math math.libm math.private kernel.private
+sequences words parser vectors strings sbufs io namespaces
+assocs quotations math.intervals sequences.private combinators
+splitting layouts math.parser classes classes.algebra
+generic.math inference.class inference.dataflow
+optimizer.pattern-match optimizer.backend optimizer.def-use
+optimizer.inlining optimizer.math.partial generic.standard
+system accessors ;
 IN: optimizer.math
-USING: alien alien.accessors arrays generic hashtables kernel
-assocs math math.private kernel.private sequences words parser
-inference.class inference.dataflow vectors strings sbufs io
-namespaces assocs quotations math.intervals sequences.private
-combinators splitting layouts math.parser classes
-classes.algebra generic.math optimizer.pattern-match
-optimizer.backend optimizer.def-use optimizer.inlining
-optimizer.math.partial generic.standard system accessors ;
 
 : define-math-identities ( word identities -- )
     >r all-derived-ops r> define-identities ;
@@ -169,6 +170,22 @@ optimizer.math.partial generic.standard system accessors ;
     ] 2curry each-derived-op
 ] each
 
+: math-output-class/interval-2-fast ( node word -- classes intervals )
+    math-output-interval-2 fixnum [ 1array ] bi@ swap ; inline
+
+[
+    { + interval+ }
+    { - interval- }
+    { * interval* }
+    { shift interval-shift-safe }
+] [
+    first2 [
+        [
+            math-output-class/interval-2-fast
+        ] curry "output-classes" set-word-prop
+    ] curry each-fast-derived-op
+] each
+
 : real-value? ( value -- n ? )
     dup value? [ value-literal dup real? ] [ drop f f ] if ;
 
@@ -389,7 +406,7 @@ most-negative-fixnum most-positive-fixnum [a,b]
 
 : convert-mod-to-and ( #call -- node )
     dup
-    dup node-in-d second node-literal 1-
+    dup in-d>> second node-literal 1-
     [ nip bitand ] curry f splice-quot ;
 
 \ mod [
@@ -420,3 +437,53 @@ most-negative-fixnum most-positive-fixnum [a,b]
         [ fixnumify-bitand ]
     }
 } define-optimizers
+
+: convert-*-to-shift? ( #call -- ? )
+    dup in-d>> second node-literal
+    dup integer? [ power-of-2? ] [ drop f ] if ;
+
+: convert-*-to-shift ( #call -- ? )
+    dup dup in-d>> second node-literal log2
+    [ nip fixnum-shift-fast ] curry
+    f splice-quot ;
+
+\ fixnum*fast {
+    { [ dup convert-*-to-shift? ] [ convert-*-to-shift ] }
+} define-optimizers
+
+{ + - * / }
+[ { number number } "input-classes" set-word-prop ] each
+
+{ /f < > <= >= }
+[ { real real } "input-classes" set-word-prop ] each
+
+{ /i mod /mod }
+[ { rational rational } "input-classes" set-word-prop ] each
+
+{ bitand bitor bitxor bitnot shift }
+[ { integer integer } "input-classes" set-word-prop ] each
+
+{
+    fcosh
+    flog
+    fsinh
+    fexp
+    fasin
+    facosh
+    fasinh
+    ftanh
+    fatanh
+    facos
+    fpow
+    fatan
+    fatan2
+    fcos
+    ftan
+    fsin
+    fsqrt
+} [
+    dup stack-effect
+    [ in>> length real <repetition> "input-classes" set-word-prop ]
+    [ out>> length float <repetition> "default-output-classes" set-word-prop ]
+    2bi
+] each
index 4f9bfaef12af4f0941f65093887697d15da0b68b..ad9feeed4a243fee49f4e3bfcfcd9fedfb707b01 100644 (file)
@@ -170,3 +170,6 @@ SYMBOL: fast-math-ops
 
 : each-derived-op ( word quot -- )
     >r derived-ops r> each ; inline
+
+: each-fast-derived-op ( word quot -- )
+    >r fast-derived-ops r> each ; inline
index 655b54ea964ed2f4244eb52975605e9db4b60cf0..ab808d79142762a87b5f5673b7b32deafc8356d9 100755 (executable)
@@ -375,3 +375,19 @@ PREDICATE: list < improper-list
 [ 2 3 ] [ 2 interval-inference-bug ] unit-test
 [ 1 4 ] [ 1 interval-inference-bug ] unit-test
 [ 0 5 ] [ 0 interval-inference-bug ] unit-test
+
+: aggressive-flush-regression ( a -- b )
+    f over >r <array> drop r> 1 + ;
+
+[ 1.0 aggressive-flush-regression drop ] must-fail
+
+[ 1 [ "hi" + drop ] compile-call ] must-fail
+
+[ "hi" f [ <array> drop ] compile-call ] must-fail
+
+TUPLE: some-tuple x ;
+
+: allot-regression ( a -- b )
+    [ ] curry some-tuple boa ;
+
+[ T{ some-tuple f [ 3 ] } ] [ 3 allot-regression ] unit-test
index 23cba3ea4c836138abc072f50c291c5caa3c2d55..d3c5a3ab9136e64c24970334579cfffabd5009c4 100755 (executable)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel namespaces optimizer.backend optimizer.def-use
-optimizer.known-words optimizer.math optimizer.control
-optimizer.collect optimizer.inlining inference.class ;
+optimizer.known-words optimizer.math optimizer.allot
+optimizer.control optimizer.collect optimizer.inlining
+inference.class ;
 IN: optimizer
 
 : optimize-1 ( node -- newnode ? )
index 51fa254a258e81d9e625148f479381e0fdada8af..647dda368f24c3d550f80f515e9ffd8efebf9a46 100755 (executable)
@@ -1,8 +1,9 @@
 ! Copyright (C) 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
+USING: kernel sequences namespaces generic
+combinators classes classes.algebra
+inference inference.dataflow ;
 IN: optimizer.pattern-match
-USING: kernel sequences inference namespaces generic
-combinators classes classes.algebra inference.dataflow ;
 
 ! Funny pattern matching
 SYMBOL: @
index f15106d78b7784eb7306d320719b35767fa42ac9..804895f6c450bda6fc946096a73724a315cbb5d9 100755 (executable)
@@ -277,13 +277,32 @@ M: array pprint-slot-name
     f <inset unclip text pprint-elements block>
     \ } pprint-word block> ;
 
+: unparse-slot ( slot-spec -- array )
+    [
+        dup name>> ,
+        dup class>> object eq? [
+            dup class>> ,
+            initial: ,
+            dup initial>> ,
+        ] unless
+        dup read-only>> [
+            read-only ,
+        ] when
+        drop
+    ] { } make ;
+
+: pprint-slot ( slot-spec -- )
+    unparse-slot
+    dup length 1 = [ first ] when
+    pprint-slot-name ;
+
 M: tuple-class see-class*
     <colon \ TUPLE: pprint-word
     dup pprint-word
     dup superclass tuple eq? [
         "<" text dup superclass pprint-word
     ] unless
-    <block slot-names [ pprint-slot-name ] each block>
+    <block "slots" word-prop [ pprint-slot ] each block>
     pprint-; block> ;
 
 M: word see-class* drop ;
index f67b01e1bf2116e002e21e533a5d40b946d1fc21..1bb7666447efa672bf716240086e4b3855dc2fc4 100755 (executable)
@@ -124,16 +124,28 @@ ARTICLE: "sequences-combinators" "Sequence combinators"
 { $subsection each }
 { $subsection reduce }
 { $subsection interleave }
-{ $subsection 2each }
-{ $subsection 2reduce }
 "Mapping:"
 { $subsection map }
-{ $subsection 2map }
+{ $subsection map-as }
 { $subsection accumulate }
 { $subsection produce }
 "Filtering:"
 { $subsection push-if }
-{ $subsection filter } ;
+{ $subsection filter }
+"Testing if a sequence contains elements satisfying a predicate:"
+{ $subsection contains? }
+{ $subsection all? }
+"Testing how elements are related:"
+{ $subsection monotonic? }
+{ $subsection "sequence-2combinators" } ;
+
+ARTICLE: "sequence-2combinators" "Pair-wise sequence combinators"
+"There is a set of combinators which traverse two sequences pairwise. If one sequence is shorter than the other, than only the prefix having the length of the minimum of the two is examined."
+{ $subsection 2each }
+{ $subsection 2reduce }
+{ $subsection 2map }
+{ $subsection 2map-as }
+{ $subsection 2all? } ;
 
 ARTICLE: "sequences-tests" "Testing sequences"
 "Testing for an empty sequence:"
@@ -147,12 +159,7 @@ ARTICLE: "sequences-tests" "Testing sequences"
 { $subsection head? }
 { $subsection tail? }
 { $subsection subseq? }
-"Testing if a sequence contains elements satisfying a predicate:"
-{ $subsection contains? }
-{ $subsection all? }
-{ $subsection 2all? }
 "Testing how elements are related:"
-{ $subsection monotonic? }
 { $subsection all-eq? }
 { $subsection all-equal? } ;
 
@@ -456,6 +463,15 @@ HELP: map
 { $values { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( old -- new )" } } { "newseq" "a new sequence" } }
 { $description "Applies the quotation to each element of the sequence in order. The new elements are collected into a sequence of the same class as the input sequence." } ;
 
+HELP: map-as
+{ $values { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( old -- new )" } } { "newseq" "a new sequence" } { "exemplar" sequence } }
+{ $description "Applies the quotation to each element of the sequence in order. The new elements are collected into a sequence of the same class as " { $snippet "exemplar" } "." }
+{ $examples
+    "The following example converts a string into an array of one-element strings:"
+    { $example "USING: prettyprint strings sequences ;" "\"Hello\" [ 1string ] { } map-as ." "{ \"H\" \"e\" \"l\" \"l\" \"o\" }" }
+    "Note that " { $link map } " could not be used here, because it would create another string to hold results, and one-element strings cannot themselves be elements of strings."
+} ;
+
 HELP: change-nth
 { $values { "i" "a non-negative integer" } { "seq" "a mutable sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- newelt )" } } }
 { $description "Applies the quotation to the " { $snippet "i" } "th element of the sequence, storing the result back into the sequence." }
@@ -478,8 +494,7 @@ HELP: max-length
 
 HELP: 2each
 { $values { "seq1" sequence } { "seq2" sequence } { "quot" "a quotation with stack effect " { $snippet "( elt1 elt2 -- )" } } }
-{ $description "Applies the quotation to pairs of elements from " { $snippet "seq1" } " and " { $snippet "seq2" } "." }
-{ $notes "If one sequence is shorter than the other, than only the prefix having the length of the minimum of the two is examined." } ;
+{ $description "Applies the quotation to pairs of elements from " { $snippet "seq1" } " and " { $snippet "seq2" } "." } ;
 
 HELP: 2reduce
 { $values { "seq1" sequence }
@@ -488,18 +503,19 @@ HELP: 2reduce
           { "quot" "a quotation with stack effect "
                    { $snippet "( prev elt1 elt2 -- next )" } }
           { "result" "the final result" } }
-{ $description "Combines successive pairs of elements from the two sequences using a ternary operation. The first input value at each iteration except the first one is the result of the previous iteration. The first input value at the first iteration is " { $snippet "identity" } "." }
-{ $notes "If one sequence is shorter than the other, then only the prefix having the length of the minimum of the two is examined." } ;
+{ $description "Combines successive pairs of elements from the two sequences using a ternary operation. The first input value at each iteration except the first one is the result of the previous iteration. The first input value at the first iteration is " { $snippet "identity" } "." } ;
 
 HELP: 2map
 { $values { "seq1" sequence } { "seq2" sequence } { "quot" "a quotation with stack effect " { $snippet "( elt1 elt2 -- new )" } } { "newseq" "a new sequence" } }
-{ $description "Applies the quotation to each pair of elements in turn, yielding new elements which are collected into a new sequence having the same class as " { $snippet "seq1" } "." }
-{ $notes "If one sequence is shorter than the other, than only the prefix having the length of the minimum of the two is examined." } ;
+{ $description "Applies the quotation to each pair of elements in turn, yielding new elements which are collected into a new sequence having the same class as " { $snippet "seq1" } "." } ;
+
+HELP: 2map-as
+{ $values { "seq1" sequence } { "seq2" sequence } { "quot" "a quotation with stack effect " { $snippet "( elt1 elt2 -- new )" } } { "exemplar" sequence } { "newseq" "a new sequence" } }
+{ $description "Applies the quotation to each pair of elements in turn, yielding new elements which are collected into a new sequence having the same class as " { $snippet "exemplar" } "." } ;
 
 HELP: 2all?
 { $values { "seq1" sequence } { "seq2" sequence } { "quot" "a quotation with stack effect " { $snippet "( elt1 elt2 -- ? )" } } { "?" "a boolean" } }
-{ $description "Tests the predicate pairwise against elements of " { $snippet "seq1" } " and " { $snippet "seq2" } "." }
-{ $notes "If one sequence is shorter than the other, than only the prefix having the length of the minimum of the two is examined." } ;
+{ $description "Tests the predicate pairwise against elements of " { $snippet "seq1" } " and " { $snippet "seq2" } "." } ;
 
 HELP: find
 { $values { "seq" sequence }
index bc92055338b1564f1b22a1f1454548f3212e2508..11cfb975df0e37bb6c444d0774799d74a4e3558c 100755 (executable)
@@ -21,9 +21,12 @@ GENERIC: clone-like ( seq exemplar -- newseq ) flushable
 M: sequence like drop ;
 
 GENERIC: lengthen ( n seq -- )
+GENERIC: shorten ( n seq -- )
 
 M: sequence lengthen 2dup length > [ set-length ] [ 2drop ] if ;
 
+M: sequence shorten 2dup length < [ set-length ] [ 2drop ] if ;
+
 : empty? ( seq -- ? ) length zero? ; inline
 : delete-all ( seq -- ) 0 swap set-length ;
 
@@ -380,10 +383,13 @@ PRIVATE>
 : 2reduce ( seq1 seq2 identity quot -- result )
     >r -rot r> 2each ; inline
 
-: 2map ( seq1 seq2 quot -- newseq )
-    pick >r (2each) over r>
+: 2map-as ( seq1 seq2 quot exemplar -- newseq )
+    >r (2each) over r>
     [ [ collect ] keep ] new-like ; inline
 
+: 2map ( seq1 seq2 quot -- newseq )
+    pick 2map-as ; inline
+
 : 2all? ( seq1 seq2 quot -- ? )
     (2each) all-integers? ; inline
 
@@ -530,7 +536,7 @@ M: slice equal? over slice? [ sequence= ] [ 2drop f ] if ;
 
 : peek ( seq -- elt ) [ length 1- ] [ nth ] bi ;
 
-: pop* ( seq -- ) [ length 1- ] [ set-length ] bi ;
+: pop* ( seq -- ) [ length 1- ] [ shorten ] bi ;
 
 : move-backward ( shift from to seq -- )
     2over number= [
@@ -575,7 +581,7 @@ M: slice equal? over slice? [ sequence= ] [ 2drop f ] if ;
     copy ;
 
 : pop ( seq -- elt )
-    [ length 1- ] [ [ nth ] [ set-length ] 2bi ] bi ;
+    [ length 1- ] [ [ nth ] [ shorten ] 2bi ] bi ;
 
 : all-equal? ( seq -- ? ) [ = ] monotonic? ;
 
index 205d4d34bfed39ec66eb5ed11773844a03f68082..b3fa649dd13af08cf040120a1361a2bd087b3cdb 100644 (file)
@@ -8,6 +8,7 @@ $nl
 { $subsection prune }
 "Test for duplicates:"
 { $subsection all-unique? }
+{ $subsection duplicates }
 "Set operations on sequences:"
 { $subsection diff }
 { $subsection intersect }
@@ -38,6 +39,18 @@ HELP: adjoin
 }
 { $side-effects "seq" } ;
 
+HELP: conjoin
+{ $values { "elt" object } { "assoc" "an assoc" } }
+{ $description "Stores a key/value pair, both equal to " { $snippet "elt" } ", into the assoc." }
+{ $examples
+    { $example
+        "USING: kernel prettyprint sets ;"
+        "H{ } clone 1 over conjoin ."
+        "H{ { 1 1 } }"
+    }
+}
+{ $side-effects "assoc" } ;
+
 HELP: unique
 { $values { "seq" "a sequence" } { "assoc" "an assoc" } }
 { $description "Outputs a new assoc where the keys and values are equal." }
@@ -52,6 +65,13 @@ HELP: prune
     { $example "USING: sets prettyprint ;" "{ 1 1 t 3 t } prune ." "V{ 1 t 3 }" }
 } ;
 
+HELP: duplicates
+{ $values { "seq" "a sequence" } { "newseq" "a sequence" } }
+{ $description "Outputs a new sequence consisting of elements which occur more than once in " { $snippet "seq" } "." }
+{ $examples
+    { $example "USING: sets prettyprint ;" "{ 1 2 3 1 2 1 } duplicates ." "{ 1 2 1 }" }
+} ;
+
 HELP: all-unique?
 { $values { "seq" sequence } { "?" "a boolean" } }
 { $description "Tests whether a sequence contains any repeated elements." }
index d825faf921f3a871f210fc0e6237669ebf580c1b..c411bfcdcdcc4dda1d565f1d9e923cefb5f749dc 100644 (file)
@@ -16,6 +16,9 @@ IN: sets
     [ ] [ length <hashtable> ] [ length <vector> ] tri
     [ [ (prune) ] 2curry each ] keep ;
 
+: duplicates ( seq -- newseq )
+    H{ } clone [ [ key? ] [ conjoin ] 2bi ] curry filter ;
+
 : gather ( seq quot -- newseq )
     map concat prune ; inline
 
index 39a501c7f804fd8e8defe58d47decf322a807eb2..acca168a4c3176ad880bd530de5437d03339825f 100755 (executable)
@@ -77,6 +77,7 @@ $nl
 "All other classes are handled with one of two cases:"
 { $list
     { "If the class is a union or mixin class which " { $emphasis "contains" } " one of the above known classes, then the initial value of the class is that of the known class, with preference given to classes earlier in the list. For example, if the slot is declared " { $link object } " (this is the default), the initial value is " { $link f } ". Similarly for " { $link sequence } " and " { $link assoc } "." }
+    { "If the class is a tuple class, the initial value of the slot is a new, shared instance of the class created with " { $link new } "." }
     { "Otherwise, a " { $link no-initial-value } " error is thrown. In this case, an initial value must be specified explicitly using " { $link initial: } "." }
 }
 "A word can be used to check if a class has an initial value or not:"
index 1453393a27d04b22efd26637807702377d6151ea..73d674782d0135a1f83ad5151f964c75f96aac54 100755 (executable)
@@ -125,6 +125,10 @@ ERROR: bad-slot-value value class ;
 
 ERROR: no-initial-value class ;
 
+GENERIC: initial-value* ( class -- object )
+
+M: class initial-value* no-initial-value ;
+
 : initial-value ( class -- object )
     {
         { [ \ f bootstrap-word over class<= ] [ f ] }
@@ -134,7 +138,7 @@ ERROR: no-initial-value class ;
         { [ array bootstrap-word over class<= ] [ { } ] }
         { [ byte-array bootstrap-word over class<= ] [ B{ } ] }
         { [ simple-alien bootstrap-word over class<= ] [ <bad-alien> ] }
-        [ no-initial-value ]
+        [ dup initial-value* ]
     } cond nip ;
 
 GENERIC: make-slot ( desc -- slot-spec )
@@ -184,9 +188,14 @@ M: array make-slot
         [ dup empty? not ] [ peel-off-attributes ] [ ] while drop
     check-initial-value ;
 
-: make-slots ( slots base -- specs )
-    over length [ + ] with map
-    [ [ make-slot ] dip >>offset ] 2map ;
+M: slot-spec make-slot
+    check-initial-value ;
+
+: make-slots ( slots -- specs )
+    [ make-slot ] map ;
+
+: finalize-slots ( specs base -- specs )
+    over length [ + ] with map [ >>offset ] 2map ;
 
 : slot-named ( name specs -- spec/f )
-    [ slot-spec-name = ] with find nip ;
+    [ name>> = ] with find nip ;
index 2f0d0614993b479dff1b343822360ebad2477901..5d053b3b5ee224dbea712142597c106768459c89 100755 (executable)
@@ -140,8 +140,6 @@ $nl
     
     { { $snippet "\"constructor\"" } { $link "tuple-constructors" } }
     
-    { { $snippet "\"slot-names\"" } { $link "tuples" } }
-    
     { { $snippet "\"type\"" } { $link "builtin-classes" } }
     
     { { { $snippet "\"superclass\"" } ", " { $snippet "\"predicate-definition\"" } } { $link "predicates" } }
index 9bf006fa16df1e5277b3ab069694d25d8b78270f..1d84acbc1404ce0b9ff56f21960db4615cb81d99 100755 (executable)
@@ -34,7 +34,9 @@ M: symbol definer drop \ SYMBOL: f ;
 M: symbol definition drop f ;
 
 PREDICATE: primitive < word ( obj -- ? )
-    def>> [ do-primitive ] tail? ;
+    [ def>> [ do-primitive ] tail? ]
+    [ sub-primitive>> >boolean ]
+    bi or ;
 M: primitive definer drop \ PRIMITIVE: f ;
 M: primitive definition drop f ;
 
index 14632df771f2403203b6f5dac9c77d05fb6a46f2..5036a13d78006df3a4410d88a644b46afefecb75 100755 (executable)
@@ -1,12 +1,7 @@
 USING: arrays assocs kernel vectors sequences namespaces
-random math.parser math fry ;
-IN: assocs.lib
-
-: ref-at ( table key -- value ) swap at ;
+       random math.parser math fry ;
 
-: put-at* ( table key value -- ) swap rot set-at ;
-
-: put-at ( table key value -- table ) swap pick set-at ;
+IN: assocs.lib
 
 : set-assoc-stack ( value key seq -- )
     dupd [ key? ] with find-last nip set-at ;
index b6d4152d0eb5906ea03471e636510abe26c0e097..979a7336925da52196dbbd984f3ae8c3cbb1429b 100644 (file)
@@ -1,6 +1,6 @@
 
 USING: kernel math math.parser random arrays hashtables assocs sequences
-       vars ;
+       grouping vars ;
 
 IN: automata
 
@@ -32,18 +32,6 @@ dup >rule-number rule-values rule-keys [ rule> set-at ] 2each ;
 ! step-wrapped-line
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: 3nth ( n seq -- slice ) >r dup 3 + r> <slice> ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-: map3-i ( seq -- i ) length 2 - ;
-
-: map3-quot ( seq quot -- quot ) >r [ 3nth ] curry r> compose ; inline
-
-: map3 ( seq quot -- seq ) >r dup map3-i swap r> map3-quot map ; inline
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
 : pattern>state ( {_a_b_c_} -- state ) rule> at ;
 
 : cap-line ( line -- 0-line-0 ) { 0 } prepend { 0 } append ;
@@ -51,10 +39,9 @@ dup >rule-number rule-values rule-keys [ rule> set-at ] 2each ;
 : wrap-line ( a-line-z -- za-line-za )
 dup peek 1array swap dup first 1array append append ;
 
-: step-line ( line -- new-line ) [ >array pattern>state ] map3 ;
-
-: step-capped-line ( line -- new-line ) cap-line step-line ;
+: step-line ( line -- new-line ) 3 <clumps> [ pattern>state ] map ;
 
+: step-capped-line  ( line -- new-line ) cap-line  step-line ;
 : step-wrapped-line ( line -- new-line ) wrap-line step-line ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
index 467db53366e7488a970cd1c695d64427c24668a9..78f1074eb80b1fb9b1083ae62031815307ff75ee 100644 (file)
@@ -14,13 +14,22 @@ USING: kernel namespaces math quotations arrays hashtables sequences threads
        ui.gadgets.packs
        ui.gadgets.grids
        ui.gadgets.theme
+       accessors
+       qualified
        namespaces.lib assocs.lib vars
-       rewrite-closures automata ;
+       rewrite-closures automata math.geometry.rect newfx ;
 
 IN: automata.ui
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
+QUALIFIED: ui.gadgets.grids
+
+: grid-add ( grid child i j -- grid )
+  >r >r dupd swap r> r> ui.gadgets.grids:grid-add ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
 : draw-point ( y x value -- ) 1 = [ swap glVertex2i ] [ 2drop ] if ;
 
 : draw-line ( y line -- ) 0 swap [ >r 2dup r> draw-point 1+ ] each 2drop ;
@@ -57,29 +66,40 @@ slate> relayout-1 ;
 
 DEFER: automata-window
 
-: automata-window* ( -- ) init-rule set-interesting <frame>
-
-{
-[ "1 - Center"      [ start-center    ] view-button ]
-[ "2 - Random"      [ start-random    ] view-button ]
-[ "3 - Continue"    [ run-rule        ] view-button ]
-[ "5 - Random Rule" [ random-rule     ] view-button ]
-[ "n - New"         [ automata-window ] view-button ]
-} make*
-[ [ gadget, ] curry ] map concat ! Hack
-make-shelf over @top grid-add
-
-[ display ] closed-quot <slate> { 400 400 } over set-slate-dim dup >slate
-over @center grid-add
-
-{
-{ T{ key-down f f "1" } [ [ start-center    ] view-action ] }
-{ T{ key-down f f "2" } [ [ start-random    ] view-action ] }
-{ T{ key-down f f "3" } [ [ run-rule        ] view-action ] }
-{ T{ key-down f f "5" } [ [ random-rule     ] view-action ] }
-{ T{ key-down f f "n" } [ [ automata-window ] view-action ] }
-} [ make* ] map >hashtable <handler> tuck set-gadget-delegate
-"Automata" open-window ;
+: automata-window* ( -- )
+  init-rule
+  set-interesting
+
+  <frame>
+
+    <shelf>
+
+      "1 - Center"      [ start-center    ] view-button add-gadget
+      "2 - Random"      [ start-random    ] view-button add-gadget
+      "3 - Continue"    [ run-rule        ] view-button add-gadget
+      "5 - Random Rule" [ random-rule     ] view-button add-gadget
+      "n - New"         [ automata-window ] view-button add-gadget
+
+    @top grid-add
+
+    C[ display ] <slate>
+      { 400 400 } >>dim
+    dup >slate
+
+    @center grid-add
+
+  H{ }
+    T{ key-down f f "1" } [ start-center    ] view-action is
+    T{ key-down f f "2" } [ start-random    ] view-action is
+    T{ key-down f f "3" } [ run-rule        ] view-action is
+    T{ key-down f f "5" } [ random-rule     ] view-action is
+    T{ key-down f f "n" } [ automata-window ] view-action is
+
+  <handler>
+
+    tuck set-gadget-delegate
+
+  "Automata" open-window ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
diff --git a/extra/benchmark/beust1/beust1.factor b/extra/benchmark/beust1/beust1.factor
new file mode 100644 (file)
index 0000000..9849ac2
--- /dev/null
@@ -0,0 +1,14 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math.ranges math.parser math.vectors sets sequences
+kernel io ;
+IN: benchmark.beust1
+
+: count-numbers ( max -- n )
+    1 [a,b] [ number>string all-unique? ] count ; inline
+
+: beust ( -- )
+    10000000 count-numbers
+    number>string " unique numbers." append print ;
+
+MAIN: beust
diff --git a/extra/benchmark/beust2/beust2.factor b/extra/benchmark/beust2/beust2.factor
new file mode 100644 (file)
index 0000000..833c1fa
--- /dev/null
@@ -0,0 +1,41 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: math math.ranges math.parser sequences kernel io locals ;
+IN: benchmark.beust2
+
+! http://crazybob.org/BeustSequence.java.html
+
+:: (count-numbers) ( remaining first value used max listener -- ? )
+    10 first - [| i |
+        [let* | digit [ i first + ]
+                mask [ digit 2^ ]
+                value' [ i value + ] |
+            used mask bitand zero? [
+                value max > [ t ] [
+                    remaining 1 <= [
+                        listener call f
+                    ] [
+                        remaining 1-
+                        0
+                        value' 10 *
+                        used mask bitor
+                        max
+                        listener
+                        (count-numbers)
+                    ] if
+                ] if
+            ] [ f ] if
+        ]
+    ] contains? ; inline
+
+:: count-numbers ( max listener -- )
+    10 [ 1+ 1 1 0 max listener (count-numbers) ] contains? drop ;
+    inline
+
+:: beust ( -- )
+    [let | i! [ 0 ] |
+        10000000000 [ i 1+ i! ] count-numbers
+        i number>string " unique numbers." append print
+    ] ;
+
+MAIN: beust
diff --git a/extra/benchmark/stack/stack.factor b/extra/benchmark/stack/stack.factor
new file mode 100644 (file)
index 0000000..d4dc18e
--- /dev/null
@@ -0,0 +1,19 @@
+USING: kernel sequences math math.functions vectors ;
+IN: benchmark.stack
+
+: stack-loop ( vec -- )
+    1000 [
+        10000 [
+            dup pop dup ! dup 10 > [ sqrt dup 1 + ] [ dup 2 * ] if
+            pick push
+            over push
+        ] times
+        10000 [ dup pop* ] times
+    ] times
+    drop ;
+
+: stack-benchmark ( -- )
+    V{ 123456 } clone stack-loop
+    20000 <vector> 123456 over set-first stack-loop ;
+
+MAIN: stack-benchmark
diff --git a/extra/biassocs/authors.txt b/extra/biassocs/authors.txt
new file mode 100644 (file)
index 0000000..1901f27
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
diff --git a/extra/biassocs/biassocs-docs.factor b/extra/biassocs/biassocs-docs.factor
new file mode 100644 (file)
index 0000000..1fde3d0
--- /dev/null
@@ -0,0 +1,28 @@
+IN: biassocs
+USING: help.markup help.syntax assocs kernel ;
+
+HELP: biassoc
+{ $class-description "The class of bidirectional assocs. Bidirectional assoc are implemented by combining two assocs, with one the transpose of the other." } ;
+
+HELP: <biassoc>
+{ $values { "exemplar" assoc } { "biassoc" biassoc } }
+{ $description "Creates a new biassoc using a new assoc of the same type as " { $snippet "exemplar" } " for underlying storage." } ;
+
+HELP: <bihash>
+{ $values { "biassoc" biassoc } }
+{ $description "Creates a new biassoc using a pair of hashtables for underlying storage." } ;
+
+HELP: once-at
+{ $values { "value" object } { "key" object } { "assoc" assoc } }
+{ $description "If the assoc does not contain the given key, adds the key/value pair to the assoc, otherwise does nothing." } ;
+
+ARTICLE: "biassocs" "Bidirectional assocs"
+"A " { $emphasis "bidirectional assoc" } " combines a pair of assocs to form a data structure where both normal assoc opeartions (eg, " { $link at } "), as well as " { $link "assocs-values" } " (eg, " { $link value-at } ") run in sub-linear time."
+$nl
+"Bidirectional assocs implement the entire assoc protocol with the exception of " { $link delete-at } ". Duplicate values are allowed, however value lookups with " { $link value-at } " only return the first key that a given value was stored with."
+{ $subsection biassoc }
+{ $subsection biassoc? }
+{ $subsection <biassoc> }
+{ $subsection <bihash> } ;
+
+ABOUT: "biassocs"
diff --git a/extra/biassocs/biassocs-tests.factor b/extra/biassocs/biassocs-tests.factor
new file mode 100644 (file)
index 0000000..4cd7f00
--- /dev/null
@@ -0,0 +1,22 @@
+IN: biassocs.tests
+USING: biassocs assocs namespaces tools.test ;
+
+<bihash> "h" set
+
+[ 0 ] [ "h" get assoc-size ] unit-test
+
+[ ] [ 1 2 "h" get set-at ] unit-test
+
+[ 1 ] [ 2 "h" get at ] unit-test
+
+[ 2 ] [ 1 "h" get value-at ] unit-test
+
+[ 1 ] [ "h" get assoc-size ] unit-test
+
+[ ] [ 1 3 "h" get set-at ] unit-test
+
+[ 1 ] [ 3 "h" get at ] unit-test
+
+[ 2 ] [ 1 "h" get value-at ] unit-test
+
+[ 2 ] [ "h" get assoc-size ] unit-test
diff --git a/extra/biassocs/biassocs.factor b/extra/biassocs/biassocs.factor
new file mode 100644 (file)
index 0000000..cd1e57f
--- /dev/null
@@ -0,0 +1,35 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: kernel assocs accessors ;
+IN: biassocs
+
+TUPLE: biassoc from to ;
+
+: <biassoc> ( exemplar -- biassoc )
+    [ clone ] [ clone ] bi biassoc boa ;
+
+: <bihash> ( -- biassoc )
+    H{ } <biassoc> ;
+
+M: biassoc assoc-size from>> assoc-size ;
+
+M: biassoc at* from>> at* ;
+
+M: biassoc value-at* to>> at* ;
+
+: once-at ( value key assoc -- )
+    2dup key? [ 3drop ] [ set-at ] if ;
+
+M: biassoc set-at
+    [ from>> set-at ] [ swapd to>> once-at ] 3bi ;
+
+M: biassoc delete-at
+    "biassocs do not support deletion" throw ;
+
+M: biassoc >alist
+    from>> >alist ;
+
+M: biassoc clear-assoc
+    [ from>> clear-assoc ] [ to>> clear-assoc ] bi ;
+
+INSTANCE: biassoc assoc
diff --git a/extra/biassocs/summary.txt b/extra/biassocs/summary.txt
new file mode 100644 (file)
index 0000000..84c5b15
--- /dev/null
@@ -0,0 +1 @@
+Bidirectional assocs
diff --git a/extra/biassocs/tags.txt b/extra/biassocs/tags.txt
new file mode 100644 (file)
index 0000000..42d711b
--- /dev/null
@@ -0,0 +1 @@
+collections
index 3d699a2623c20afe11c9d69416cfff182a35817d..4e6f7428b055efd9732b063a96338dfb074c9f57 100755 (executable)
@@ -76,7 +76,7 @@ M: bit-array byte-length length 7 + -3 shift ;
     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' out underlying>> i set-alien-unsigned-1
                 n' -8 shift n'!
                 i 1+ i!
             ] [ ] while
index 9ffc038dbd52dd643321b7fe9989b8dbf5180abd..f4274299b1c36db85f10b2e3f3e38f18fded1061 100644 (file)
@@ -1,2 +1 @@
-collections
 extensions
index e6c97b90ddf06a51757eeefa061dbedbd7201819..ab624a606bfc7abd2d39a9ef5d47ec0c19c37e52 100644 (file)
@@ -6,14 +6,17 @@ USING: combinators.short-circuit kernel namespaces
        math.order
        math.vectors
        math.trig
+       math.physics.pos
+       math.physics.vel
        combinators arrays sequences random vars
-       combinators.lib ;
+       combinators.lib
+       accessors ;
 
 IN: boids
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-TUPLE: boid pos vel ;
+TUPLE: boid < vel ;
 
 C: <boid> boid
 
@@ -70,10 +73,6 @@ VAR: separation-radius
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: distance ( boid boid -- n ) [ boid-pos ] [ boid-pos ] bi* v- norm ;
-
-! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
 : constrain ( n a b -- n ) rot min max ;
 
 : angle-between ( vec vec -- angle )
@@ -81,10 +80,10 @@ VAR: separation-radius
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: relative-position ( self other -- v ) swap [ boid-pos ] bi@ v- ;
+: relative-position ( self other -- v ) swap [ pos>> ] bi@ v- ;
 
 : relative-angle ( self other -- angle )
-over boid-vel -rot relative-position angle-between ;
+over vel>> -rot relative-position angle-between ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -92,9 +91,9 @@ over boid-vel -rot relative-position angle-between ;
 
 : vaverage ( seq-of-vectors -- seq ) [ vsum ] [ length ] bi v/n ;
 
-: average-position ( boids -- pos ) [ boid-pos ] map vaverage ;
+: average-position ( boids -- pos ) [ pos>> ] map vaverage ;
 
-: average-velocity ( boids -- vel ) [ boid-vel ] map vaverage ;
+: average-velocity ( boids -- vel ) [ vel>> ] map vaverage ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -123,7 +122,7 @@ over boid-vel -rot relative-position angle-between ;
   dup cohesion-neighborhood
   dup empty?
   [ 2drop { 0 0 } ]
-  [ average-position swap boid-pos v- normalize* cohesion-weight> v*n ]
+  [ average-position swap pos>> v- normalize* cohesion-weight> v*n ]
   if ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -143,7 +142,7 @@ over boid-vel -rot relative-position angle-between ;
   dup separation-neighborhood
   dup empty?
   [ 2drop { 0 0 } ]
-  [ average-position swap boid-pos swap v- normalize* separation-weight> v*n ]
+  [ average-position swap pos>> swap v- normalize* separation-weight> v*n ]
   if ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -206,10 +205,10 @@ cond ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: new-pos ( boid -- pos ) [ boid-pos ] [ boid-vel time-slice> v*n ] bi v+ ;
+: new-pos ( boid -- pos ) [ pos>> ] [ vel>> time-slice> v*n ] bi v+ ;
 
 : new-vel ( boid -- vel )
-  [ boid-vel ] [ acceleration time-slice> v*n ] bi v+ normalize* ;
+  [ vel>> ] [ acceleration time-slice> v*n ] bi v+ normalize* ;
 
 : wrap-pos ( pos -- pos ) { [ wrap-x ] [ wrap-y ] } parallel-call ;
 
index e3c54e0744d07e2d3193aa5bb9c3062b886a8e25..f45b1cc0ffb0fb7bf51bda9177f20f0890f37479 100755 (executable)
@@ -19,7 +19,9 @@ USING: combinators.short-circuit kernel namespaces
        ui.gadgets.packs
        ui.gadgets.grids
        ui.gestures
-       assocs.lib vars rewrite-closures boids ;
+       assocs.lib vars rewrite-closures boids accessors
+       math.geometry.rect
+       newfx ;
 
 IN: boids.ui
 
@@ -27,9 +29,9 @@ IN: boids.ui
 ! draw-boid
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: point-a ( boid -- a ) boid-pos ;
+: point-a ( boid -- a ) pos>> ;
 
-: point-b ( boid -- b ) [ boid-pos ] [ boid-vel normalize* 20 v*n ] bi v+ ;
+: point-b ( boid -- b ) [ pos>> ] [ vel>> normalize* 20 v*n ] bi v+ ;
 
 : boid-points ( boid -- point-a point-b ) [ point-a ] [ point-b ] bi ;
 
@@ -112,52 +114,54 @@ VARS: population-label cohesion-label alignment-label separation-label ;
 
   <frame>
 
+  <shelf>
+
   {
     [ "ESC - Pause" [ drop toggle-loop ] button* ]
 
     [ "1 - Randomize" [ drop randomize ] button* ]
 
     [ <pile> 1 over set-pack-fill
-      population-label> over add-gadget
-      "3 - Add 10" [ drop add-10-boids ] button* over add-gadget
-      "2 - Sub 10" [ drop sub-10-boids ] button* over add-gadget ]
+      population-label> add-gadget
+      "3 - Add 10" [ drop add-10-boids ] button* add-gadget
+      "2 - Sub 10" [ drop sub-10-boids ] button* add-gadget ]
 
     [ <pile> 1 over set-pack-fill
-      cohesion-label> over add-gadget
-      "q - +0.1" [ drop inc-cohesion-weight ] button* over add-gadget
-      "a - -0.1" [ drop dec-cohesion-weight ] button* over add-gadget ]
+      cohesion-label> add-gadget
+      "q - +0.1" [ drop inc-cohesion-weight ] button* add-gadget
+      "a - -0.1" [ drop dec-cohesion-weight ] button* add-gadget ]
 
     [ <pile> 1 over set-pack-fill
-      alignment-label> over add-gadget
-      "w - +0.1" [ drop inc-alignment-weight ] button* over add-gadget
-      "s - -0.1" [ drop dec-alignment-weight ] button* over add-gadget ]
+      alignment-label> add-gadget
+      "w - +0.1" [ drop inc-alignment-weight ] button* add-gadget
+      "s - -0.1" [ drop dec-alignment-weight ] button* add-gadget ]
 
     [ <pile> 1 over set-pack-fill
-      separation-label> over add-gadget
-      "e - +0.1" [ drop inc-separation-weight ] button* over add-gadget
-      "d - -0.1" [ drop dec-separation-weight ] button* over add-gadget ]
+      separation-label> add-gadget
+      "e - +0.1" [ drop inc-separation-weight ] button* add-gadget
+      "d - -0.1" [ drop dec-separation-weight ] button* add-gadget ]
 
-  } [ call ] map [ [ gadget, ] each ] make-shelf
+  } [ call ] map [ add-gadget ] each
     1 over set-pack-fill
     over @top grid-add
 
   slate> over @center grid-add
 
   H{ } clone
-    T{ key-down f f "1" } C[ drop randomize    ] put-at
-    T{ key-down f f "2" } C[ drop sub-10-boids ] put-at
-    T{ key-down f f "3" } C[ drop add-10-boids ] put-at
+    T{ key-down f f "1" } C[ drop randomize    ] is
+    T{ key-down f f "2" } C[ drop sub-10-boids ] is
+    T{ key-down f f "3" } C[ drop add-10-boids ] is
 
-    T{ key-down f f "q" } C[ drop inc-cohesion-weight ] put-at
-    T{ key-down f f "a" } C[ drop dec-cohesion-weight ] put-at
+    T{ key-down f f "q" } C[ drop inc-cohesion-weight ] is
+    T{ key-down f f "a" } C[ drop dec-cohesion-weight ] is
 
-    T{ key-down f f "w" } C[ drop inc-alignment-weight ] put-at
-    T{ key-down f f "s" } C[ drop dec-alignment-weight ] put-at
+    T{ key-down f f "w" } C[ drop inc-alignment-weight ] is
+    T{ key-down f f "s" } C[ drop dec-alignment-weight ] is
 
-    T{ key-down f f "e" } C[ drop inc-separation-weight ] put-at
-    T{ key-down f f "d" } C[ drop dec-separation-weight ] put-at
+    T{ key-down f f "e" } C[ drop inc-separation-weight ] is
+    T{ key-down f f "d" } C[ drop dec-separation-weight ] is
 
-    T{ key-down f f "ESC" } C[ drop toggle-loop ] put-at
+    T{ key-down f f "ESC" } C[ drop toggle-loop ] is
   <handler> tuck set-gadget-delegate "Boids" open-window ;
 
 : boids-window ( -- ) [ [ boids-window* ] with-scope ] with-ui ;
index b4cefbc5bd0e10e032220aa7376497d530401ee6..ed89f2a809ccf8308f8e1a608ac71f2b76a82810 100755 (executable)
@@ -1,34 +1,25 @@
-USING: alien alien.c-types arrays sequences math math.vectors
-math.matrices math.parser io io.files kernel opengl opengl.gl
-opengl.glu shuffle http.client vectors namespaces ui.gadgets
-ui.gadgets.canvas ui.render ui splitting combinators
-system combinators.lib float-arrays continuations
-opengl.demo-support multiline ui.gestures bunny.fixed-pipeline
-bunny.cel-shaded bunny.outlined bunny.model accessors destructors ;
+USING: accessors arrays bunny.cel-shaded bunny.fixed-pipeline
+bunny.model bunny.outlined destructors kernel math opengl.demo-support
+opengl.gl sequences ui ui.gadgets ui.gestures ui.render words ;
 IN: bunny
 
-TUPLE: bunny-gadget model geom draw-seq draw-n ;
+TUPLE: bunny-gadget < demo-gadget model-triangles geom draw-seq draw-n ;
 
 : <bunny-gadget> ( -- bunny-gadget )
-    0.0 0.0 0.375 <demo-gadget>
-    maybe-download read-model {
-        set-delegate
-        (>>model)
-    } bunny-gadget construct ;
+    0.0 0.0 0.375 bunny-gadget new-demo-gadget
+    maybe-download read-model >>model-triangles ;
 
 : bunny-gadget-draw ( gadget -- draw )
-    { draw-n>> draw-seq>> }
-    get-slots nth ;
+    [ draw-n>> ] [ draw-seq>> ] bi nth ;
 
 : bunny-gadget-next-draw ( gadget -- )
-    dup { draw-seq>> draw-n>> }
-    get-slots
+    dup [ draw-seq>> ] [ draw-n>> ] bi
     1+ swap length mod
     >>draw-n relayout-1 ;
 
 M: bunny-gadget graft* ( gadget -- )
     GL_DEPTH_TEST glEnable
-    dup model>> <bunny-geom> >>geom
+    dup model-triangles>> <bunny-geom> >>geom
     dup
     [ <bunny-fixed-pipeline> ]
     [ <bunny-cel-shaded> ]
@@ -48,8 +39,7 @@ M: bunny-gadget draw-gadget* ( gadget -- )
         dup demo-gadget-set-matrices
         GL_MODELVIEW glMatrixMode
         0.02 -0.105 0.0 glTranslatef
-        { geom>> bunny-gadget-draw } get-slots
-        draw-bunny
+        [ geom>> ] [ bunny-gadget-draw ] bi draw-bunny
     ] if ;
 
 M: bunny-gadget pref-dim* ( gadget -- dim )
index fce73785b57b62199038499d8101b8ed3a721507..f64030ff707adc650f99d4a2e09b35ab7fb955f5 100755 (executable)
@@ -1,9 +1,7 @@
-USING: alien alien.c-types arrays sequences math math.vectors
-math.matrices math.parser io io.files kernel opengl opengl.gl
-opengl.glu io.encodings.ascii opengl.capabilities shuffle
-http.client vectors splitting system combinators
-float-arrays continuations destructors namespaces sequences.lib
-accessors ;
+USING: accessors alien.c-types arrays combinators destructors http.client
+io io.encodings.ascii io.files kernel math math.matrices math.parser
+math.vectors opengl opengl.capabilities opengl.gl sequences sequences.lib
+splitting vectors words ;
 IN: bunny.model
 
 : numbers ( str -- seq )
@@ -66,7 +64,7 @@ TUPLE: bunny-buffers array element-array nv ni ;
     {
         [
             [ first concat ] [ second concat ] bi
-            append >c-double-array
+            append >c-float-array
             GL_ARRAY_BUFFER swap GL_STATIC_DRAW <gl-buffer>
         ]
         [
@@ -86,10 +84,10 @@ M: bunny-dlist bunny-geom
 M: bunny-buffers bunny-geom
     dup { array>> element-array>> } get-slots [
         { GL_VERTEX_ARRAY GL_NORMAL_ARRAY } [
-            GL_DOUBLE 0 0 buffer-offset glNormalPointer
+            GL_FLOAT 0 0 buffer-offset glNormalPointer
             [
-                nv>> "double" heap-size * buffer-offset
-                3 GL_DOUBLE 0 roll glVertexPointer
+                nv>> "float" heap-size * buffer-offset
+                3 GL_FLOAT 0 roll glVertexPointer
             ] [
                 ni>>
                 GL_TRIANGLES swap GL_UNSIGNED_INT 0 buffer-offset glDrawElements
index f3ee4594c7b847b620c5ebde4a9b631cab65a35e..fcba98a0e924dff19d79bfe8f924365aff9a018a 100755 (executable)
@@ -181,10 +181,9 @@ TUPLE: bunny-outlined
     ] [ drop ] if ;
 
 : remake-framebuffer-if-needed ( draw -- )
-    dup [ gadget>> dim>> ] [ framebuffer-dim>> ] bi
-    over =
-    [ 2drop ] [
-        [ dup dispose-framebuffer dup ] dip {
+    dup [ gadget>> dim>> ] [ framebuffer-dim>> ] bi =
+    [ drop ] [
+        [ dispose-framebuffer ] [ dup ] [ gadget>> dim>> ] tri {
             [
                 GL_RGBA16F_ARB GL_RGBA (framebuffer-texture)
                 [ >>color-texture drop ] keep
@@ -196,7 +195,8 @@ TUPLE: bunny-outlined
                 [ >>depth-texture drop ] keep
             ]
         } 2cleave
-        (make-framebuffer) >>framebuffer drop
+        [ (make-framebuffer) >>framebuffer ] [ >>framebuffer-dim ] bi
+        drop
     ] if ;
 
 : clear-framebuffer ( -- )
index 99968ca3c30ebe5418d4337bc0b4f4de052b8c5b..b5938a7ad75c90eff4da40b3b7efd5912388774c 100755 (executable)
@@ -3,7 +3,7 @@
 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 ;
+ui.gadgets.sliders ui.render math.geometry.rect ;
 IN: color-picker
 
 ! Simple example demonstrating the use of models.
@@ -15,7 +15,8 @@ TUPLE: color-preview < gadget ;
 
 : <color-preview> ( model -- gadget )
     color-preview new-gadget
-    { 100 100 } over set-rect-dim ;
+      swap        >>model
+      { 100 100 } >>dim ;
 
 M: color-preview model-changed
     swap model-value over set-gadget-interior relayout-1 ;
@@ -26,7 +27,10 @@ M: color-preview model-changed
 : <color-sliders> ( -- model gadget )
     3 [ 0 0 0 255 <range> ] replicate
     dup [ range-model ] map <compose>
-    swap [ [ <color-slider> gadget, ] each ] make-filled-pile ;
+    swap
+    <filled-pile>
+    swap
+      [ <color-slider> add-gadget ] each ;
 
 : <color-picker> ( -- gadget )
     [
index 22d811ad3fda0cbba02f9b4a54c7c4cbdde81a73..32f3e05c6e41ab4a20428082146b740b64112bf8 100644 (file)
@@ -1,4 +1,4 @@
-USING: help.syntax help.markup kernel prettyprint sequences strings ;
+USING: help.syntax help.markup kernel prettyprint sequences strings words math ;
 IN: ctags
 
 ARTICLE: "ctags" "Ctags file"
@@ -6,7 +6,10 @@ ARTICLE: "ctags" "Ctags file"
 { $subsection ctags }
 { $subsection ctags-write }
 { $subsection ctag-strings }
-{ $subsection ctag } ;
+{ $subsection ctag }
+{ $subsection ctag-word }
+{ $subsection ctag-path }
+{ $subsection ctag-lineno } ;
 
 HELP: ctags ( path -- )
 { $values { "path" "a pathname string" } }
@@ -57,4 +60,41 @@ HELP: ctag ( seq -- str )
   }
 } ;
 
+HELP: ctag-lineno ( ctag -- n )
+{ $values { "ctag" sequence }
+          { "n" integer } }
+{ $description "Provides de line number " { $snippet "n" } " from a sequence in ctag format " }
+{ $examples
+  { $example
+    "USING: kernel ctags prettyprint ;"
+    "{ if  { \"resource:extra/unix/unix.factor\" 91 } } ctag-lineno ."
+    "91"
+  }
+} ;
+
+HELP: ctag-path ( ctag -- path )
+{ $values { "ctag" sequence }
+          { "path" string } }
+{ $description "Provides a path string " { $snippet "path" } " from a sequence in ctag format" }
+{ $examples
+  { $example
+    "USING: kernel ctags prettyprint ;"
+    "{ if  { \"resource:extra/unix/unix.factor\" 91 } } ctag-path ."
+    "\"resource:extra/unix/unix.factor\""
+  }
+} ;
+
+HELP: ctag-word ( ctag -- word )
+{ $values { "ctag" sequence }
+          { "word" word } }
+{ $description "Provides the " { $snippet "word" } " from a sequence in ctag format " }
+{ $examples
+  { $example
+    "USING: kernel ctags prettyprint ;"
+    "{ if  { \"resource:extra/unix/unix.factor\" 91 } } ctag-word ."
+    "if"
+  }
+} ;
+
+
 ABOUT: "ctags"
\ No newline at end of file
index 6c73b58ecb7837a59cf60d2728a19ab5a28b5c6a..700b8976570ab85bb46aacba5151c8ced80e52c8 100644 (file)
@@ -1,6 +1,21 @@
 USING: kernel ctags tools.test io.backend sequences arrays prettyprint ;
 IN: ctags.tests
 
+[ t ] [
+  91
+  { { if  { "resource:extra/unix/unix.factor" 91 } } } ctag-lineno =
+] unit-test
+
+[ t ] [
+  "resource:extra/unix/unix.factor"
+  { { if  { "resource:extra/unix/unix.factor" 91 } } } ctag-path =
+] unit-test
+
+[ t ] [
+  if
+  { { if  { "resource:extra/unix/unix.factor" 91 } } } ctag-word =
+] unit-test
+
 [ t ] [
   "if\t" "resource:extra/unix/unix.factor" normalize-path "\t91" 3append
   { if  { "resource:extra/unix/unix.factor" 91 } } ctag =
@@ -9,4 +24,5 @@ IN: ctags.tests
 [ 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
+] unit-test
+
index 23d9aeb90cdca789874ae50f01684294fd7862d9..e8c5608375cb9e569658ce1c5f64399a429c3513 100644 (file)
@@ -9,29 +9,36 @@ io.encodings.ascii math.parser vocabs definitions
 namespaces words sorting ;
 IN: ctags
 
+: ctag-word ( ctag -- word )
+  first ;
+
+: ctag-path ( ctag -- path )
+  second first ;
+
+: ctag-lineno ( ctag -- n )
+  second second ;
+
 : ctag ( seq -- str )
   [
-    dup first ?word-name %
+    dup ctag-word ?word-name %
     "\t" %
-    second dup first normalize-path %
+    dup ctag-path normalize-path %
     "\t" %
-    second number>string %
+    ctag-lineno number>string %
   ] "" make ;
 
 : ctag-strings ( seq1 -- seq2 )
-  { } swap [ ctag suffix ] each ;
+  [ ctag ] map ;
 
 : ctags-write ( seq path -- )
   [ ctag-strings ] dip ascii set-file-lines ;
 
 : (ctags) ( -- seq )
-  { } all-words [
+  all-words [
     dup where [
-      2array suffix
-    ] [
-      drop
-    ] if*
-  ] each ;
+      2array
+    ] when*
+  ] map [ sequence? ] filter ;
 
 : ctags ( path -- )
   (ctags) sort-keys swap ctags-write ;
\ No newline at end of file
diff --git a/extra/ctags/etags/authors.txt b/extra/ctags/etags/authors.txt
new file mode 100644 (file)
index 0000000..158cf94
--- /dev/null
@@ -0,0 +1 @@
+Alfredo Beaumont
diff --git a/extra/ctags/etags/etags-docs.factor b/extra/ctags/etags/etags-docs.factor
new file mode 100644 (file)
index 0000000..5bd4e10
--- /dev/null
@@ -0,0 +1,39 @@
+USING: help.syntax help.markup kernel prettyprint sequences strings words math ;
+IN: ctags.etags
+
+ARTICLE: "etags" "Etags file"
+{ $emphasis "Etags" } " generates a index file of every factor word in etags format as supported by emacs and other editors. More information can be found at " { $url "http://en.wikipedia.org/wiki/Ctags#Etags_2" } "."
+{ $subsection etags }
+{ $subsection etags-write }
+{ $subsection etag-strings }
+{ $subsection etag-header }
+
+HELP: etags ( path -- )
+{ $values { "path" string } }
+{ $description "Generates a index file in etags format and stores in " { $snippet "path" } "." }
+{ $examples
+  { $unchecked-example
+    "USING: ctags.etags ;"
+    "\"ETAGS\" etags"
+    ""
+  }
+} ;
+
+HELP: etags-write ( alist path -- )
+{ $values { "alist" sequence }
+          { "path" string } }
+{ $description "Stores a " { $snippet "alist" } " in " { $snippet "path" } ". " { $snippet "alist" } " must be an association list with etags format: its key must be a resource path and its value a vector, containing pairs of words and lines" }
+{ $examples
+  { $unchecked-example
+    "USING: kernel etags.ctags ;"
+    "{ { \"resource:extra/unix/unix.factor\" V{ { dup2 91 } } } } \"ETAGS\" etags-write"
+    ""
+  }
+} ;
+
+HELP: etag-strings ( alist -- seq )
+{ $values { "alist" sequence }
+          { "seq" sequence } }
+{ $description "Converts an " { $snippet "alist" } " with etag format (a path as key and a vector containing word/line pairs) in a " { $snippet "seq" } " of strings." } ;
+
+ABOUT: "etags" ;
\ No newline at end of file
diff --git a/extra/ctags/etags/etags-tests.factor b/extra/ctags/etags/etags-tests.factor
new file mode 100644 (file)
index 0000000..6ab97e0
--- /dev/null
@@ -0,0 +1,72 @@
+USING: kernel ctags ctags.etags tools.test io.backend sequences arrays prettyprint hashtables assocs ;
+IN: ctags.etags.tests
+
+! etag-at
+[ t ]
+[
+  V{ }
+  "path" H{ } clone etag-at =
+] unit-test
+
+[ t ]
+[
+  V{ if { "path" 1 } }
+  "path" H{ { "path" V{ if { "path" 1 } } } } etag-at =
+] unit-test
+
+! etag-vector
+[ t ]
+[
+  V{ }
+  { if { "path" 1 } } H{ } clone etag-vector =
+] unit-test
+
+[ t ]
+[
+  V{ if { "path" 1 } }
+  { if { "path" 1 } }
+  { { "path" V{ if { "path" 1 } } } } >hashtable
+  etag-vector = 
+] unit-test
+
+! etag-pair 
+[ t ]
+[
+  { if 28 }
+  { if { "resource:core/kernel/kernel.factor" 28 } } etag-pair =
+] unit-test
+
+! etag-add
+[ t ]
+[
+  H{ { "path" V{ { if  1 } } } }
+  { if { "path" 1 } } H{ } clone [ etag-add ] keep =
+] unit-test
+
+! etag-hash
+[ t ]
+[
+  H{ { "path" V{ { if 1 } } } }
+  { { if { "path" 1 } } } etag-hash =
+] unit-test
+
+! line-bytes (note that for each line implicit \n is counted)
+[ t ]
+[
+  17
+  { "1234567890" "12345" } 2 lines>bytes =
+] unit-test
+  
+! etag
+[ t ]
+[
+  "if\7f2,11"
+  { "1234567890" "12345" } { if 2 } etag =
+] unit-test
+
+! etag-length
+[ t ]
+[
+  14
+  V{ "if\7f2,11" "if\7f2,11" } etag-length =
+] unit-test
diff --git a/extra/ctags/etags/etags.factor b/extra/ctags/etags/etags.factor
new file mode 100644 (file)
index 0000000..8cc8c28
--- /dev/null
@@ -0,0 +1,75 @@
+! Copyright (C) 2008 Alfredo Beaumont
+! See http://factorcode.org/license.txt for BSD license.
+
+! Emacs Etags generator
+! Alfredo Beaumont <alfredo.beaumont@gmail.com>
+USING: kernel sequences sorting assocs words prettyprint ctags
+io.encodings.ascii io.files math math.parser namespaces strings locals
+shuffle io.backend arrays ;
+IN: ctags.etags
+
+: etag-at ( key hash -- vector )
+  at [ V{ } clone ] unless* ;
+
+: etag-vector ( alist hash -- vector )
+  [ ctag-path ] dip etag-at ;
+
+: etag-pair ( ctag -- seq )
+  dup [
+    first ,
+    second second ,
+  ] { } make ;
+
+: etag-add ( ctag hash -- )
+  [ etag-vector ] 2keep [
+    [ etag-pair ] [ ctag-path ] bi [ suffix ] dip
+  ] dip set-at ;
+    
+: etag-hash ( seq -- hash )
+  H{ } clone swap [ swap [ etag-add ] keep ] each ;
+
+: lines>bytes ( seq n -- bytes )
+  head 0 [ length 1+ + ] reduce ;
+
+: file>lines ( path -- lines )
+  ascii file-lines ;
+
+: etag ( lines seq -- str )
+  [
+    dup first ?word-name %
+    1 HEX: 7f <string> %
+    second dup number>string %
+    1 CHAR: , <string> %
+    1- lines>bytes number>string %
+  ] "" make ;
+
+: etag-length ( vector -- n )
+  0 [ length + ] reduce ;
+
+: (etag-header) ( n path -- str )
+  [
+    %
+    1 CHAR: , <string> %
+    number>string %
+  ] "" make ;
+
+: etag-header ( vec1 n resource -- vec2 )
+  normalize-path (etag-header) prefix
+  1 HEX: 0c <string> prefix ;
+
+: etag-strings ( alist -- seq )
+  { } swap [
+    [
+      [ first file>lines ]
+      [ second ] bi
+      [ etag ] with map
+      dup etag-length
+    ] keep first 
+    etag-header append
+  ] each ;
+
+: etags-write ( alist path -- )
+  [ etag-strings ] dip ascii set-file-lines ; 
+
+: etags ( path -- )
+  [ (ctags) sort-values etag-hash >alist ] dip etags-write ;
\ No newline at end of file
diff --git a/extra/ctags/etags/summary.txt b/extra/ctags/etags/summary.txt
new file mode 100644 (file)
index 0000000..4766e20
--- /dev/null
@@ -0,0 +1 @@
+Etags generator
index 025a580633c52a982f55d5067e83ed54c98c6c22..0aa7fa50564e659b726fe6e2f30c8005ac9729ec 100755 (executable)
@@ -9,16 +9,8 @@ TUPLE: float-array
 { length array-capacity read-only }
 { underlying byte-array read-only } ;
 
-<PRIVATE
-
-: floats>bytes 8 * ; inline
-
-: float-array@ underlying>> swap >fixnum floats>bytes ; inline
-
-PRIVATE>
-
 : <float-array> ( n -- float-array )
-    dup floats>bytes <byte-array> float-array boa ; inline
+    dup "double" <c-array> float-array boa ; inline
 
 M: float-array clone
     [ length>> ] [ underlying>> clone ] bi float-array boa ;
@@ -26,13 +18,13 @@ M: float-array clone
 M: float-array length length>> ;
 
 M: float-array nth-unsafe
-    float-array@ alien-double ;
+    underlying>> double-nth ;
 
 M: float-array set-nth-unsafe
-    [ >float ] 2dip float-array@ set-alien-double ;
+    [ >float ] 2dip underlying>> set-double-nth ;
 
 : >float-array ( seq -- float-array )
-    T{ float-array f 0 B{ } } clone-like ; inline
+    T{ float-array } clone-like ; inline
 
 M: float-array like
     drop dup float-array? [ >float-array ] unless ;
@@ -45,7 +37,7 @@ M: float-array equal?
 
 M: float-array resize
     [ drop ] [
-        [ floats>bytes ] [ underlying>> ] bi*
+        [ "double" heap-size * ] [ underlying>> ] bi*
         resize-byte-array
     ] 2bi
     float-array boa ;
@@ -58,13 +50,13 @@ INSTANCE: float-array sequence
     1 <float-array> [ set-first ] keep ; flushable
 
 : 2float-array ( x y -- array )
-    T{ float-array f 0 B{ } } 2sequence ; flushable
+    T{ float-array } 2sequence ; flushable
 
 : 3float-array ( x y z -- array )
-    T{ float-array f 0 B{ } } 3sequence ; flushable
+    T{ float-array } 3sequence ; flushable
 
 : 4float-array ( w x y z -- array )
-    T{ float-array f 0 B{ } } 4sequence ; flushable
+    T{ float-array } 4sequence ; flushable
 
 : F{ ( parsed -- parsed )
     \ } [ >float-array ] parse-literal ; parsing
@@ -72,3 +64,20 @@ INSTANCE: float-array sequence
 M: float-array pprint-delims drop \ F{ \ } ;
 
 M: float-array >pprint-sequence ;
+
+USING: hints math.vectors arrays ;
+
+HINTS: vneg { float-array } { array } ;
+HINTS: v*n { float-array object } { array object } ;
+HINTS: v/n { float-array object } { array object } ;
+HINTS: n/v { object float-array } { object array } ;
+HINTS: v+ { float-array float-array } { array array } ;
+HINTS: v- { float-array float-array } { array array } ;
+HINTS: v* { float-array float-array } { array array } ;
+HINTS: v/ { float-array float-array } { array array } ;
+HINTS: vmax { float-array float-array } { array array } ;
+HINTS: vmin { float-array float-array } { array array } ;
+HINTS: v. { float-array float-array } { array array } ;
+HINTS: norm-sq { float-array } { array } ;
+HINTS: norm { float-array } { array } ;
+HINTS: normalize { float-array } { array } ;
index d2af13a9c3393bc43bf7cd880a62bdc39a4aa8e9..a702f452da6d8764c29d8f499e66b83336b65829 100755 (executable)
@@ -1,9 +1,21 @@
-! 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
+math arrays ;\r
 IN: generalizations\r
 \r
+HELP: narray\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link 1array } ", "\r
+{ $link 2array } ", " { $link 3array } " and " { $link 4array } " "\r
+"that constructs an array from the top " { $snippet "n" } " elements of the stack."\r
+} ;\r
+\r
+HELP: firstn\r
+{ $values { "n" integer } }\r
+{ $description "A generalization of " { $link first } ", "\r
+{ $link first2 } ", " { $link first3 } " and " { $link first4 } " "\r
+"that pushes the first " { $snippet "n" } " elements of a sequence on the stack."\r
+} ;\r
+\r
 HELP: npick\r
 { $values { "n" integer } }\r
 { $description "A generalization of " { $link dup } ", "\r
@@ -119,6 +131,7 @@ ARTICLE: "generalizations" "Generalized shuffle words and combinators"
 "macros where the arity of the input quotations depends on an "\r
 "input parameter."\r
 { $subsection narray }\r
+{ $subsection firstn }\r
 { $subsection ndup }\r
 { $subsection npick }\r
 { $subsection nrot }\r
index af010e202682e6418612a211d2e0eb565b788d2c..75985c936892c74b92bcd009eab187057134811a 100755 (executable)
@@ -32,3 +32,7 @@ IN: generalizations.tests
 [ [ dup 2^ 2array ] 5 napply ] must-infer\r
 \r
 [ { "xyc" "xyd" } ] [ "x" "y" { "c" "d" } [ 3append ] 2 nwith map ] unit-test\r
+\r
+[ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test\r
+[ ] [ { } 0 firstn ] unit-test\r
+[ "a" ] [ { "a" } 1 firstn ] unit-test\r
index 6cbb13518e05d25b027f29a6b246531bb9b420aa..e4d5249a30620115b24a54d43fb35786c386a180 100755 (executable)
@@ -1,14 +1,20 @@
-! Copyright (C) 2007, 2008 Chris Double, Doug Coleman.\r
+! Copyright (C) 2007, 2008 Chris Double, Doug Coleman, Eduardo\r
+! Cavazos, Slava Pestov.\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
+USING: kernel sequences sequences.private namespaces math\r
+math.ranges combinators macros quotations fry 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
+    [ <reversed> ] [ '[ , f <array> ] ] bi\r
+    [ '[ @ [ , swap set-nth-unsafe ] keep ] ] reduce ;\r
+\r
+MACRO: firstn ( n -- )\r
+    dup zero? [ drop [ drop ] ] [\r
+        [ [ '[ , _ nth-unsafe ] ] map ]\r
+        [ 1- '[ , _ bounds-check 2drop ] ]\r
+        bi prefix '[ , cleave ]\r
+    ] if ;\r
 \r
 MACRO: npick ( n -- )\r
     1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ;\r
@@ -32,7 +38,7 @@ MACRO: ntuck ( n -- )
     2 + [ dupd -nrot ] curry ;\r
 \r
 MACRO: nrev ( n -- quot )\r
-    1 [a,b] [ '[ , -nrot ] ] map concat ;\r
+    1 [a,b] [ ] [ '[ @ , -nrot ] ] reduce ;\r
 \r
 MACRO: ndip ( quot n -- )\r
     dup saver -rot restorer 3append ;\r
@@ -44,11 +50,11 @@ MACRO: nkeep ( n -- )
     [ ] [ 1+ ] [ ] tri\r
     '[ [ , ndup ] dip , -nrot , nslip ] ;\r
 \r
-MACRO: ncurry ( n -- ) [ curry ] n*quot ;\r
+MACRO: ncurry ( n -- )\r
+    [ curry ] n*quot ;\r
 \r
-MACRO:: nwith ( quot n -- )\r
-    [let | n' [ n 1+ ] |\r
-        [ n' -nrot [ n' nrot quot call ] n ncurry ] ] ;\r
+MACRO: nwith ( n -- )\r
+    [ with ] n*quot ;\r
 \r
 MACRO: napply ( n -- )\r
     2 [a,b]\r
index 62cc65939440bdb17ba0016f6f22799c314773fb..aee53f24f50e1dda34747e1af1e6347b381f232d 100644 (file)
@@ -1,5 +1,7 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences io.files io.launcher io.encodings.ascii
-io.streams.string http.client sequences.lib combinators
+io.streams.string http.client generalizations combinators
 math.parser math.vectors math.intervals interval-maps memoize
 csv accessors assocs strings math splitting grouping arrays ;
 IN: geo-ip
index ba0ff5bedd6b43a586170a2b2e70c4fd0bb43967..d79593c337fe4bbacdbccdd9059009eed7e26e46 100644 (file)
@@ -5,10 +5,10 @@ ui.gadgets.scrollers ui.gadgets.theme ui.gestures colors
 accessors ;
 IN: gesture-logger
 
-TUPLE: gesture-logger stream ;
+TUPLE: gesture-logger < gadget stream ;
 
 : <gesture-logger> ( stream -- gadget )
-    \ gesture-logger construct-gadget
+    \ gesture-logger new-gadget
     swap >>stream
     { 100 100 } >>dim
     black solid-interior ;
index 266e635867a2e505797bb03b84213eec573f0d4a..82941a69dedfbd686a9a787adfdd50edba7f8288 100644 (file)
@@ -1,6 +1,10 @@
+! Copyright (C) 2008 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: parser words definitions kernel ;
 IN: hints
-USING: parser words ;
 
-: HINTS: 
-    scan-word parse-definition "specializer" set-word-prop ;
+: HINTS:
+    scan-word
+    [ +inlined+ changed-definition ]
+    [ parse-definition "specializer" set-word-prop ] bi ;
     parsing
index f08082c4ee4941f3b7559dcb8fafeb7c8d86cd8c..e6a0070ee0e5bc13c08d70cda15d3a279bfc8999 100755 (executable)
@@ -25,7 +25,7 @@ M: buffer dispose* ptr>> free ;
     [ size>> ] [ fill>> ] bi - ; inline
 
 : buffer-empty? ( buffer -- ? )
-    fill>> zero? ;
+    fill>> zero? ; inline
 
 : buffer-consume ( n buffer -- )
     [ + ] change-pos
index 77e984e6e5d79c4ca86dd63e7d7c5124536d95f1..26b06dba8ba5219e667aaefa5466a7b0bad0adaf 100755 (executable)
@@ -19,7 +19,7 @@ M: port set-timeout (>>timeout) ;
 : <port> ( handle class -- port )
     new swap >>handle ; inline
 
-TUPLE: buffered-port < port buffer ;
+TUPLE: buffered-port < port { buffer buffer } ;
 
 : <buffered-port> ( handle class -- port )
     <port>
@@ -35,7 +35,7 @@ HOOK: (wait-to-read) io-backend ( port -- )
 : wait-to-read ( port -- eof? )
     dup buffer>> buffer-empty? [
         dup (wait-to-read) buffer>> buffer-empty?
-    ] [ drop f ] if ;
+    ] [ drop f ] if ; inline
 
 M: input-port stream-read1
     dup check-disposed
@@ -140,9 +140,7 @@ M: output-port dispose*
     ] with-destructors ;
 
 M: buffered-port dispose*
-    [ call-next-method ]
-    [ [ [ dispose ] when* f ] change-buffer drop ]
-    bi ;
+    [ call-next-method ] [ buffer>> dispose ] bi ;
 
 M: port cancel-operation handle>> cancel-operation ;
 
@@ -152,3 +150,13 @@ M: port dispose*
         [ handle>> shutdown ]
         bi
     ] with-destructors ;
+
+! Fast-path optimization
+USING: hints strings io.encodings.utf8 io.encodings.ascii
+io.encodings.private ;
+
+HINTS: decoder-read-until { string input-port utf8 } { string input-port ascii } ;
+
+HINTS: decoder-readln { input-port utf8 } { input-port ascii } ;
+
+HINTS: decoder-write { string output-port utf8 } { string output-port ascii } ;
index ef2bfd3d55c47de457dcd49b4acc9483fdc3ab84..cc138dad92f68dbd06d2cd3664b889613ded7b2e 100755 (executable)
@@ -82,10 +82,10 @@ M: irc-message write-irc
     <scrolling-pane>\r
     [ <pane-stream> swap display ] keep ;\r
 \r
-TUPLE: irc-editor outstream listener client ;\r
+TUPLE: irc-editor < editor outstream listener client ;\r
 \r
 : <irc-editor> ( pane listener client -- editor )\r
-    [ <editor> irc-editor construct-editor\r
+    [ irc-editor new-editor\r
     swap >>listener swap <pane-stream> >>outstream\r
     ] dip client>> >>client ;\r
 \r
index b7764894d10d42c813a5974b26dfaaf352be36ab..d9a0f84b53c0544781b6cb2dd7cb3b464ef162d3 100755 (executable)
@@ -1,6 +1,9 @@
 ! Copyright (C) 2007, 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alarms arrays calendar jamshred.game jamshred.gl jamshred.player jamshred.log kernel math math.constants namespaces sequences threads ui ui.backend ui.gadgets ui.gadgets.worlds ui.gestures ui.render math.vectors ;
+USING: accessors alarms arrays calendar jamshred.game jamshred.gl
+jamshred.player jamshred.log kernel math math.constants namespaces
+sequences threads ui ui.backend ui.gadgets ui.gadgets.worlds
+ui.gestures ui.render math.vectors math.geometry.rect ;
 IN: jamshred
 
 TUPLE: jamshred-gadget jamshred last-hand-loc alarm ;
index e44334b2b56a45f9dccaee0021df1aa19112d66c..42d711b32ba66957d114e76b2aedcc5a59c9c58a 100644 (file)
@@ -1,3 +1 @@
-cons
-lists
-sequences
+collections
index 8f9513ff2aae02a812f651813b227f719eb1b7e5..f7ec181f61ade5e37fabedc79d98e716153b9cec 100644 (file)
@@ -17,7 +17,7 @@ USING: kernel namespaces threads math math.order math.vectors
        self pos ori turtle opengl.camera
        lsys.tortoise lsys.tortoise.graphics
        lsys.strings.rewrite lsys.strings.interpret
-       combinators.short-circuit ;
+       combinators.short-circuit accessors ;
 
        ! lsys.strings
        ! lsys.strings.rewrite
@@ -99,6 +99,8 @@ DEFER: empty-model
 
 : lsys-controller ( -- )
 
+<pile>
+
 {
 
 [ "Load" <label> reverse-video-theme ]
@@ -145,9 +147,11 @@ DEFER: empty-model
   [ pos> norm reset-turtle 45 turn-left 45 pitch-up step-turtle 180 turn-left ]
   camera-action <bevel-button> ]
 
-} make*
-[ [ gadget, ] curry ] map concat ! Hack
-make-pile 1 over set-pack-fill "L-system control" open-window ;
+}
+
+[ call add-gadget ] each
+1 >>fill
+"L-system control" open-window ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -469,7 +473,7 @@ H{ } >rules ;
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : model-chooser ( -- )
-
+<pile>
 {
 [ "abop-1" <label> [ drop abop-1 build-model ] closed-quot <bevel-button> ]
 [ "abop-2" <label> [ drop abop-2 build-model ] closed-quot <bevel-button> ]
@@ -481,18 +485,21 @@ H{ } >rules ;
 [ "airhorse" <label> [ drop airhorse build-model ] closed-quot <bevel-button> ]
 [ "spiral-0" <label> [ drop spiral-0 build-model ] closed-quot <bevel-button> ]
 [ "koch" <label> [ drop koch build-model ] closed-quot <bevel-button> ]
-} make*
-[ [ gadget, ] curry ] map concat ! Hack
-make-pile 1 over set-pack-fill "L-system models" open-window ;
+}
+[ call add-gadget ] each
+1 >>fill
+"L-system models" open-window ;
 
 : scene-chooser ( -- )
+<pile>
 {
 [ "abop-1" <label> [ drop abop-1-scene ] closed-quot <bevel-button> ]
 [ "abop-2" <label> [ drop abop-2-scene ] closed-quot <bevel-button> ]
 [ "tree-5" <label> [ drop tree-5-scene ] closed-quot <bevel-button> ]
-} make*
-[ [ gadget, ] curry ] map concat ! Hack
-make-pile 1 over set-pack-fill "L-system scenes" open-window ;
+}
+[ call add-gadget ] each
+1 >>fill
+"L-system scenes" open-window ;
 
 : lsys-window* ( -- )
 [ lsys-controller lsys-viewer ] with-ui ;
diff --git a/extra/math/geometry/rect/rect-docs.factor b/extra/math/geometry/rect/rect-docs.factor
new file mode 100644 (file)
index 0000000..3e21dfe
--- /dev/null
@@ -0,0 +1,54 @@
+USING: help.markup help.syntax ;
+
+IN: math.geometry.rect
+
+HELP: rect
+{ $class-description "A rectangle with the following slots:"
+    { $list
+        { { $link rect-loc } " - the top-left corner of the rectangle as an x/y pair" }
+        { { $link rect-dim } " - the dimensions of the rectangle as a width/height pair" }
+    }
+    "Rectangles are constructed by calling " { $link <rect> } " and " { $link <extent-rect> } "."
+} ;
+
+HELP: <rect> ( loc dim -- rect )
+{ $values { "loc" "a pair of integers" } { "dim" "a pair of integers" } { "rect" "a new " { $link rect } } }
+{ $description "Creates a new rectangle with the specified top-left location and dimensions." } ;
+
+{ <zero-rect> <rect> <extent-rect> } related-words
+
+HELP: set-rect-dim ( dim rect -- )
+{ $values { "dim" "a pair of integers" } { "rect" rect } }
+{ $description "Modifies the dimensions of a rectangle." }
+{ $side-effects "rect" } ;
+
+HELP: rect-bounds
+{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
+{ $description "Outputs the location and dimensions of a rectangle." } ;
+
+{ rect-bounds rect-extent } related-words
+
+HELP: <extent-rect> ( loc ext -- rect )
+{ $values { "loc" "a pair of integers" } { "ext" "a pair of integers" } { "rect" "a new " { $link rect } } }
+{ $description "Creates a new rectangle with the specified top-left and bottom-right corner locations." } ;
+
+HELP: rect-extent
+{ $values { "rect" rect } { "loc" "a pair of integers" } { "ext" "a pair of integers" } }
+{ $description "Outputs the location of the top-left and bottom-right corners of a rectangle." } ;
+
+HELP: offset-rect
+{ $values { "rect" rect } { "loc" "a pair of integers" } { "newrect" "a new " { $link rect } } }
+{ $description "Creates a new rectangle with the same dimensions, and top-left corner translated by " { $snippet "loc" } "." } ;
+
+HELP: rect-intersect
+{ $values { "rect1" rect } { "rect2" rect } { "newrect" "a new " { $link rect } } }
+{ $description "Computes the intersection of two rectangles." } ;
+
+HELP: intersects?
+{ $values { "rect/point" "a " { $link rect } " or a pair of integers" } { "rect" rect } { "?" "a boolean" } }
+{ $description "Tests if two rectangles (or a point and a rectangle, respectively) have a non-empty intersection." } ;
+
+HELP: <zero-rect>
+{ $values { "rect" "a new " { $link rect } } }
+{ $description "Creates a rectangle located at the origin with zero dimensions." } ;
+
diff --git a/extra/math/geometry/rect/rect-tests.factor b/extra/math/geometry/rect/rect-tests.factor
new file mode 100644 (file)
index 0000000..0d2a8bc
--- /dev/null
@@ -0,0 +1,37 @@
+
+USING: tools.test math.geometry.rect ;
+
+IN: math.geometry.rect.tests
+
+[ T{ rect f { 10 10 } { 20 20 } } ]
+[
+    T{ rect f { 10 10 } { 50 50 } }
+    T{ rect f { -10 -10 } { 40 40 } }
+    rect-intersect
+] unit-test
+
+[ T{ rect f { 200 200 } { 0 0 } } ]
+[
+    T{ rect f { 100 100 } { 50 50 } }
+    T{ rect f { 200 200 } { 40 40 } }
+    rect-intersect
+] unit-test
+
+[ f ] [
+    T{ rect f { 100 100 } { 50 50 } }
+    T{ rect f { 200 200 } { 40 40 } }
+    intersects?
+] unit-test
+
+[ t ] [
+    T{ rect f { 100 100 } { 50 50 } }
+    T{ rect f { 120 120 } { 40 40 } }
+    intersects?
+] unit-test
+
+[ f ] [
+    T{ rect f { 1000 100 } { 50 50 } }
+    T{ rect f { 120 120 } { 40 40 } }
+    intersects?
+] unit-test
+
diff --git a/extra/math/geometry/rect/rect.factor b/extra/math/geometry/rect/rect.factor
new file mode 100644 (file)
index 0000000..51f42c2
--- /dev/null
@@ -0,0 +1,42 @@
+
+USING: kernel arrays math.vectors ;
+
+IN: math.geometry.rect
+
+TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
+
+: <zero-rect> ( -- rect ) rect new ;
+
+C: <rect> rect
+
+M: array rect-loc ;
+
+M: array rect-dim drop { 0 0 } ;
+
+: rect-bounds ( rect -- loc dim ) dup rect-loc swap rect-dim ;
+
+: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
+
+: 2rect-extent ( rect rect -- loc1 loc2 ext1 ext2 )
+    [ rect-extent ] bi@ swapd ;
+
+: <extent-rect> ( loc ext -- rect ) over [v-] <rect> ;
+
+: offset-rect ( rect loc -- newrect )
+    over rect-loc v+ swap rect-dim <rect> ;
+
+: (rect-intersect) ( rect rect -- array array )
+    2rect-extent vmin >r vmax r> ;
+
+: rect-intersect ( rect1 rect2 -- newrect )
+    (rect-intersect) <extent-rect> ;
+
+: intersects? ( rect/point rect -- ? )
+    (rect-intersect) [v-] { 0 0 } = ;
+
+: (rect-union) ( rect rect -- array array )
+    2rect-extent vmax >r vmin r> ;
+
+: rect-union ( rect1 rect2 -- newrect )
+    (rect-union) <extent-rect> ;
+
diff --git a/extra/math/physics/pos/pos.factor b/extra/math/physics/pos/pos.factor
new file mode 100644 (file)
index 0000000..6915568
--- /dev/null
@@ -0,0 +1,17 @@
+
+USING: kernel sequences multi-methods accessors math.vectors ;
+
+IN: math.physics.pos
+
+TUPLE: pos pos ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+GENERIC: distance ( a b -- c )
+
+METHOD: distance { sequence sequence } v- norm ;
+
+METHOD: distance { pos pos } [ pos>> ] bi@ distance ;
+
+! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
diff --git a/extra/math/physics/vel/vel.factor b/extra/math/physics/vel/vel.factor
new file mode 100644 (file)
index 0000000..5fc815e
--- /dev/null
@@ -0,0 +1,7 @@
+
+USING: math.physics.pos ;
+
+IN: math.physics.vel
+
+TUPLE: vel < pos vel ;
+
index a8783ee4101b158c91689bdf24ceedaab073d7cf..714fc67c9f9789241f0c0d0a9d16d7e539ca9f17 100644 (file)
@@ -4,8 +4,8 @@ IN: math.ranges
 
 ARTICLE: "ranges" "Ranges"
 
-  "A " { $emphasis "range" } " is a virtual sequence with elements "
-  "ranging from a to b by step."
+  "A " { $emphasis "range" } " is a virtual sequence with real elements "
+  "ranging from " { $emphasis "a" } " to " { $emphasis "b" } " by " { $emphasis "step" } "."
 
   $nl
 
index dbf983be62b6e9f5ef9fac024f0c282c38856e64..389dabc0f6c0bfd25af734325fae53eda31f5185 100644 (file)
@@ -1,7 +1,7 @@
 ! From http://www.ffconsultancy.com/ocaml/maze/index.html
 USING: sequences namespaces math math.vectors opengl opengl.gl
 arrays kernel random ui ui.gadgets ui.gadgets.canvas ui.render
-math.order ;
+math.order math.geometry.rect ;
 IN: maze
 
 : line-width 8 ;
index c31ae3e733129a0590a864bdd33de69921cc416d..8decf3251ce5dd42fe6f194928091f03ad975be5 100755 (executable)
@@ -134,7 +134,12 @@ $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 }
-{ $subsection "models-impl" } ;
+{ $subsection "models-impl" }
+{ $subsection "models-filter" }
+{ $subsection "models-compose" }
+{ $subsection "models-history" }
+{ $subsection "models-range" }
+{ $subsection "models-delay" } ;
 
 ARTICLE: "models-impl" "Implementing models"
 "New types of models can be defined, for example see " { $vocab-link "models.filter" } "."
index 9ad8978bf34e26099b84f23360c12a3c0c06e79c..4da3935727ec56f04ec612c71715a9f24686ee36 100755 (executable)
@@ -2,7 +2,7 @@
 ! USING: kernel quotations namespaces sequences assocs.lib ;
 
 USING: kernel namespaces namespaces.private quotations sequences
-       assocs.lib math.parser math sequences.lib locals mirrors ;
+       assocs.lib math.parser math generalizations locals mirrors ;
 
 IN: namespaces.lib
 
index 1084a3303ef388497d964cb7b30326e53342a545..d9560c92f6405652775e151b9a6521660a977fbd 100644 (file)
@@ -2,13 +2,13 @@ USING: arrays kernel math opengl opengl.gl opengl.glu ui
 ui.gadgets ui.render ;
 IN: nehe.2
 
-TUPLE: nehe2-gadget ;
+TUPLE: nehe2-gadget < gadget ;
 
 : width 256 ;
 : height 256 ;
 
 : <nehe2-gadget> (  -- gadget )
-  nehe2-gadget construct-gadget ;
+  nehe2-gadget new-gadget ;
 
 M: nehe2-gadget pref-dim* ( gadget -- dim )
   drop width height 2array ;
index fff58380d62ec16d529c7785bac87a13b923f185..8a2149e370cffa5d43c0b5ce718e27bd0019c1fd 100644 (file)
@@ -2,13 +2,13 @@ USING: arrays kernel math opengl opengl.gl opengl.glu ui
 ui.gadgets ui.render ;
 IN: nehe.3
 
-TUPLE: nehe3-gadget ;
+TUPLE: nehe3-gadget < gadget ;
 
 : width 256 ;
 : height 256 ;
 
 : <nehe3-gadget> (  -- gadget )
-  nehe3-gadget construct-gadget ;
+  nehe3-gadget new-gadget ;
 
 M: nehe3-gadget pref-dim* ( gadget -- dim )
   drop width height 2array ;
index b87b4a230866c631a4294a9dc6e8b41119ca3bce..fc2727159b48c118a1d2f6bd09e4f9e3ce8c5a4a 100644 (file)
@@ -2,14 +2,14 @@ USING: arrays kernel math opengl opengl.gl opengl.glu ui
 ui.gadgets ui.render threads ;
 IN: nehe.4
 
-TUPLE: nehe4-gadget rtri rquad thread quit? ;
+TUPLE: nehe4-gadget < gadget rtri rquad thread quit? ;
 
 : width 256 ;
 : height 256 ;
 : redraw-interval 10 ;
 
 : <nehe4-gadget> (  -- gadget )
-  nehe4-gadget construct-gadget
+  nehe4-gadget new-gadget
   0.0 over set-nehe4-gadget-rtri
   0.0 over set-nehe4-gadget-rquad ;
 
index 31a7d059aecfc4d32c89d41be609a4eb955ecaba..f399a116ed095ec2841f45bff84ab6560d13a082 100755 (executable)
@@ -2,13 +2,13 @@ USING: arrays kernel math opengl opengl.gl opengl.glu ui
 ui.gadgets ui.render threads ;\r
 IN: nehe.5\r
 \r
-TUPLE: nehe5-gadget rtri rquad thread quit? ;\r
+TUPLE: nehe5-gadget < gadget rtri rquad thread quit? ;\r
 : width 256 ;\r
 : height 256 ;\r
 : redraw-interval 10 ;\r
 \r
 : <nehe5-gadget> (  -- gadget )\r
-  nehe5-gadget construct-gadget\r
+  nehe5-gadget new-gadget\r
   0.0 over set-nehe5-gadget-rtri\r
   0.0 over set-nehe5-gadget-rquad ;\r
 \r
index b074e85f3b1c8876ef2ce1d49635c52e0b013a0b..a96c024683b54d01771180acece45367aab6096f 100644 (file)
@@ -4,12 +4,12 @@ IN: nehe
 
 : nehe-window ( -- )
     [
-        [
-            "Nehe 2" [ drop run2 ] <bevel-button> gadget,
-            "Nehe 3" [ drop run3 ] <bevel-button> gadget,
-            "Nehe 4" [ drop run4 ] <bevel-button> gadget,
-            "Nehe 5" [ drop run5 ] <bevel-button> gadget,
-        ] make-filled-pile "Nehe examples" open-window
+        <filled-pile>
+            "Nehe 2" [ drop run2 ] <bevel-button> add-gadget
+            "Nehe 3" [ drop run3 ] <bevel-button> add-gadget
+            "Nehe 4" [ drop run4 ] <bevel-button> add-gadget
+            "Nehe 5" [ drop run5 ] <bevel-button> add-gadget
+        "Nehe examples" open-window
     ] with-ui ;
 
 MAIN: nehe-window
index 5dcbd526f262e975f97096157275dc079acd27fd..2bf2abae95751384c065051bd16ef0e03832e299 100755 (executable)
@@ -9,10 +9,10 @@ IN: opengl.demo-support
 
 SYMBOL: last-drag-loc
 
-TUPLE: demo-gadget yaw pitch distance ;
+TUPLE: demo-gadget < gadget yaw pitch distance ;
 
-: <demo-gadget> ( yaw pitch distance -- gadget )
-    demo-gadget construct-gadget
+: new-demo-gadget ( yaw pitch distance class -- gadget )
+    new-gadget
         swap >>distance
         swap >>pitch
         swap >>yaw ;
@@ -31,19 +31,19 @@ M: demo-gadget distance-step ( gadget -- dz )
 : fov-ratio ( gadget -- fov ) dim>> dup first2 min v/n ;
 
 : yaw-demo-gadget ( yaw gadget -- )
-    [ [ demo-gadget-yaw + ] keep set-demo-gadget-yaw ] keep relayout-1 ;
+    [ + ] with change-yaw relayout-1 ;
 
 : pitch-demo-gadget ( pitch gadget -- )
-    [ [ demo-gadget-pitch + ] keep set-demo-gadget-pitch ] keep relayout-1 ;
+    [ + ] with change-pitch relayout-1 ;
 
 : zoom-demo-gadget ( distance gadget -- )
-    [ [ demo-gadget-distance + ] keep set-demo-gadget-distance ] keep relayout-1 ;
+    [ + ] with change-distance relayout-1 ;
 
 M: demo-gadget pref-dim* ( gadget -- dim )
     drop { 640 480 } ;
 
 : -+ ( x -- -x x )
-    dup neg swap ;
+    [ neg ] keep ;
 
 : demo-gadget-frustum ( gadget -- -x x -y y near far )
     [ near-plane ] [ far-plane ] [ fov-ratio ] tri [
index e3740f9cba4cd6ca944f92a3a426a9a0a4fa1501..fdae5388964499dac46f60f0b7861a02b9feac85 100755 (executable)
@@ -1,10 +1,10 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: classes inference inference.dataflow io kernel
-kernel.private math.parser namespaces optimizer prettyprint
-prettyprint.backend sequences words arrays match macros
-assocs sequences.private optimizer.specializers generic
-combinators sorting math quotations accessors ;
+USING: classes io kernel kernel.private math.parser namespaces
+optimizer prettyprint prettyprint.backend sequences words arrays
+match macros assocs sequences.private generic combinators
+sorting math quotations accessors inference inference.dataflow
+optimizer.specializers ;
 IN: optimizer.debugger
 
 ! A simple tool for turning dataflow IR into quotations, for
@@ -47,24 +47,29 @@ MATCH-VARS: ?a ?b ?c ;
 
 : pretty-shuffle ( in out -- word/f )
     2array {
-        { { { ?a } { } } drop }
-        { { { ?a ?b } { } } 2drop }
-        { { { ?a ?b ?c } { } } 3drop }
-        { { { ?a } { ?a ?a } } dup }
-        { { { ?a ?b } { ?a ?b ?a ?b } } 2dup }
-        { { { ?a ?b ?c } { ?a ?b ?c ?a ?b ?c } } 3dup }
-        { { { ?a ?b } { ?a ?b ?a } } over }
-        { { { ?b ?a } { ?a ?b } } swap }
-        { { { ?a ?b ?c } { ?a ?b ?c ?a } } pick }
-        { { { ?a ?b ?c } { ?c ?a ?b } } -rot }
-        { { { ?a ?b ?c } { ?b ?c ?a } } rot }
-        { { { ?a ?b } { ?b } } nip }
+        { { { ?a } { ?a } } [ ] }
+        { { { ?a ?b } { ?a ?b } } [ ] }
+        { { { ?a ?b ?c } { ?a ?b ?c } } [ ] }
+        { { { ?a } { } } [ drop ] }
+        { { { ?a ?b } { } } [ 2drop ] }
+        { { { ?a ?b ?c } { } } [ 3drop ] }
+        { { { ?a } { ?a ?a } } [ dup ] }
+        { { { ?a ?b } { ?a ?b ?a ?b } } [ 2dup ] }
+        { { { ?a ?b ?c } { ?a ?b ?c ?a ?b ?c } } [ 3dup ] }
+        { { { ?a ?b } { ?a ?b ?a } } [ over ] }
+        { { { ?b ?a } { ?a ?b } } [ swap ] }
+        { { { ?a ?b } { ?b ?a ?b } } [ tuck ] }
+        { { { ?a ?b ?c } { ?a ?b ?c ?a } } [ pick ] }
+        { { { ?a ?b ?c } { ?c ?a ?b } } [ -rot ] }
+        { { { ?a ?b ?c } { ?b ?c ?a } } [ rot ] }
+        { { { ?a ?b } { ?b } } [ nip ] }
+        { { { ?a ?b ?c } { ?c } } [ 2nip ] }
         { _ f }
     } match-choose ;
 
 M: #shuffle node>quot
     dup [ in-d>> ] [ out-d>> ] bi pretty-shuffle
-    [ , ] [ >r drop t r> ] if*
+    [ % ] [ >r drop t r> ] if*
     dup effect-str "#shuffle: " prepend comment, ;
 
 : pushed-literals ( node -- seq )
index 147e5b892ecc1483fae14c14f0929c088ecc39d9..cee04934590ff0a14b85daf4411055fbdbf9854d 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2007, 2008 Chris Double.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel sequences strings fry namespaces math assocs shuffle debugger io
-       vectors arrays math.parser math.order vectors combinators combinators.lib
+       vectors arrays math.parser math.order vectors combinators
        classes sets unicode.categories compiler.units parser
        words quotations effects memoize accessors locals effects splitting 
        combinators.short-circuit combinators.short-circuit.smart ;
index fb9f321f47c4d16cd0ea4c3c2c5a508ece8ecae1..4c9dd787e5462ea982a9c6a07a247784c10c444c 100755 (executable)
@@ -10,7 +10,7 @@ USING: kernel namespaces threads combinators sequences arrays
        combinators.cleave
        rewrite-closures fry accessors newfx
        processing.color
-       processing.gadget ;
+       processing.gadget math.geometry.rect ;
        
 IN: processing
 
index 4b8114f67fab08e2a60504b1d2529f4b20600445..3744a7217a6a3a1cb5a1aa7330186fab03e4f4b5 100755 (executable)
@@ -67,11 +67,6 @@ IN: sequences.lib.tests
 { 13 } [ 1 2 { 3 4 } [ + + ] 2 each-withn + ] unit-test
 [ { 910 911 912 } ] [ 10 900 3 [ + + ] map-with2 ] unit-test
 
-[ 1 2 3 4 ] [ { 1 2 3 4 } 4 firstn ] unit-test
-
-[ ] [ { } 0 firstn ] unit-test
-[ "a" ] [ { "a" } 1 firstn ] unit-test
-
 [ "empty" ] [ { } [ "not empty" ] [ "empty" ] if-seq ] unit-test
 [ { 1 } "not empty" ] [ { 1 } [ "not empty" ] [ "empty" ] if-seq ] unit-test
 
index 0049320b94c453d050499267a8122333ccda6923..9f8e5be3d5ce9e6d7ec915a4c9603370d15d3cf0 100755 (executable)
@@ -20,11 +20,6 @@ IN: sequences.lib
 
 : map-with2 ( obj obj list quot -- newseq ) 2 map-withn ; inline
 
-MACRO: firstn ( n -- )
-    [ [ swap nth ] curry [ keep ] curry ] map
-    concat >quotation
-    [ drop ] compose ;
-
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : each-percent ( seq quot -- )
index dff7313eecfcaec6a5e0b972f665ba16ca681ece..9607f6d2018ff20df20b8614d42b91010eee1734 100755 (executable)
@@ -99,14 +99,13 @@ main()
 }
 ;
 
-TUPLE: spheres-gadget
+TUPLE: spheres-gadget < demo-gadget
     plane-program solid-sphere-program texture-sphere-program
     reflection-framebuffer reflection-depthbuffer
     reflection-texture ;
 
 : <spheres-gadget> ( -- gadget )
-    20.0 10.0 20.0 <demo-gadget>
-    { set-delegate } spheres-gadget construct ;
+    20.0 10.0 20.0 spheres-gadget new-demo-gadget ;
 
 M: spheres-gadget near-plane ( gadget -- z )
     drop 1.0 ;
index 185611586357af05f504be7aa15bed7e76527869..818aa675e2b26cbd20779e2fcc43d47370329161 100755 (executable)
@@ -1,6 +1,6 @@
 
 USING: kernel combinators sequences arrays math math.vectors
-       generalizations vars ;
+       generalizations vars accessors math.physics.vel ;
 
 IN: springies
 
@@ -28,27 +28,27 @@ VAR: gravity
 ! node
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-TUPLE: node mass elas pos vel force ;
+TUPLE: node < vel mass elas force ;
 
 C: <node> node
 
-: >>pos ( node pos -- node ) over set-node-pos ;
+: node-vel ( node -- vel ) vel>> ;
 
-: >>vel ( node vel -- node ) over set-node-vel ;
+: set-node-vel ( vel node -- ) swap >>vel drop ;
 
-: pos-x ( node -- x ) node-pos first ;
-: pos-y ( node -- y ) node-pos second ;
-: vel-x ( node -- y ) node-vel first ;
-: vel-y ( node -- y ) node-vel second ;
+: pos-x ( node -- x ) pos>> first ;
+: pos-y ( node -- y ) pos>> second ;
+: vel-x ( node -- y ) vel>> first ;
+: vel-y ( node -- y ) vel>> second ;
 
-: >>pos-x ( node x -- node ) over node-pos set-first ;
-: >>pos-y ( node y -- node ) over node-pos set-second ;
-: >>vel-x ( node x -- node ) over node-vel set-first ;
-: >>vel-y ( node y -- node ) over node-vel set-second ;
+: >>pos-x ( node x -- node ) over pos>> set-first ;
+: >>pos-y ( node y -- node ) over pos>> set-second ;
+: >>vel-x ( node x -- node ) over vel>> set-first ;
+: >>vel-y ( node y -- node ) over vel>> set-second ;
 
-: apply-force ( node vec -- ) over node-force v+ swap set-node-force ;
+: apply-force ( node vec -- ) over force>> v+ >>force drop ;
 
-: reset-force ( node -- ) 0 0 2array swap set-node-force ;
+: reset-force ( node -- node ) 0 0 2array >>force ;
 
 : node-id ( id -- node ) 1- nodes> nth ;
 
@@ -61,12 +61,12 @@ TUPLE: spring rest-length k damp node-a node-b ;
 C: <spring> spring
 
 : end-points ( spring -- b-pos a-pos )
-  [ spring-node-b node-pos ] [ spring-node-a node-pos ] bi ;
+  [ node-b>> pos>> ] [ node-a>> pos>> ] bi ;
 
 : spring-length ( spring -- length ) end-points v- norm ;
 
 : stretch-length ( spring -- length )
-  [ spring-length ] [ spring-rest-length ] bi - ;
+  [ spring-length ] [ rest-length>> ] bi - ;
 
 : dir ( spring -- vec ) end-points v- normalize ;
 
@@ -81,14 +81,14 @@ C: <spring> spring
 ! 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: hooke-force-mag ( spring -- mag ) [ spring-k ] [ stretch-length ] bi * ;
+: hooke-force-mag ( spring -- mag ) [ k>> ] [ stretch-length ] bi * ;
 
 : hooke-force ( spring -- force ) [ dir ] [ hooke-force-mag ] bi v*n ;
 
 : hooke-forces ( spring -- a b ) hooke-force dup vneg ;
 
 : act-on-nodes-hooke ( spring -- )
-  [ spring-node-a ] [ spring-node-b ] [ ] tri hooke-forces swapd
+  [ node-a>> ] [ node-b>> ] [ ] tri hooke-forces swapd
   apply-force
   apply-force ;
 
@@ -112,37 +112,37 @@ C: <spring> spring
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : relative-velocity-a ( spring -- vel )
-  [ spring-node-a node-vel ] [ spring-node-b node-vel ] bi v- ;
+  [ node-a>> vel>> ] [ node-b>> vel>> ] bi v- ;
 
 : unit-vec-b->a ( spring -- vec )
-  [ spring-node-a node-pos ] [ spring-node-b node-pos ] bi v- ;
+  [ node-a>> pos>> ] [ node-b>> pos>> ] bi v- ;
 
 : relative-velocity-along-spring-a ( spring -- vel )
   [ relative-velocity-a ] [ unit-vec-b->a ] bi vector-projection ;
 
 : damping-force-a ( spring -- vec )
-  [ relative-velocity-along-spring-a ] [ spring-damp ] bi v*n vneg ;
+  [ relative-velocity-along-spring-a ] [ damp>> ] bi v*n vneg ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : relative-velocity-b ( spring -- vel )
-  [ spring-node-b node-vel ] [ spring-node-a node-vel ] bi v- ;
+  [ node-b>> vel>> ] [ node-a>> vel>> ] bi v- ;
 
 : unit-vec-a->b ( spring -- vec )
-  [ spring-node-b node-pos ] [ spring-node-a node-pos ] bi v- ;
+  [ node-b>> pos>> ] [ node-a>> pos>> ] bi v- ;
 
 : relative-velocity-along-spring-b ( spring -- vel )
   [ relative-velocity-b ] [ unit-vec-a->b ] bi vector-projection ;
 
 : damping-force-b ( spring -- vec )
-  [ relative-velocity-along-spring-b ] [ spring-damp ] bi v*n vneg ;
+  [ relative-velocity-along-spring-b ] [ damp>> ] bi v*n vneg ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : act-on-nodes-damping ( spring -- )
   dup
-  [ spring-node-a ] [ damping-force-a ] bi apply-force
-  [ spring-node-b ] [ damping-force-b ] bi apply-force ;
+  [ node-a>> ] [ damping-force-a ] bi apply-force
+  [ node-b>> ] [ damping-force-b ] bi apply-force ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@@ -158,22 +158,22 @@ C: <spring> spring
 
 : bounce-top ( node -- )
   world-height 1- >>pos-y
-  dup [ vel-y ] [ node-elas ] bi * neg >>vel-y
+  dup [ vel-y ] [ elas>> ] bi * neg >>vel-y
   drop ;
 
 : bounce-bottom ( node -- )
   0 >>pos-y
-  dup [ vel-y ] [ node-elas ] bi * neg >>vel-y
+  dup [ vel-y ] [ elas>> ] bi * neg >>vel-y
   drop ;
 
 : bounce-left ( node -- )
   0 >>pos-x
-  dup [ vel-x ] [ node-elas ] bi * neg >>vel-x
+  dup [ vel-x ] [ elas>> ] bi * neg >>vel-x
   drop ;
 
 : bounce-right ( node -- )
   world-width 1- >>pos-x
-  dup [ vel-x ] [ node-elas ] bi * neg >>vel-x
+  dup [ vel-x ] [ elas>> ] bi * neg >>vel-x
   drop ;
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@@ -207,17 +207,17 @@ C: <spring> spring
 
 ! F = ma
 
-: calc-acceleration ( node -- vec ) [ node-force ] [ node-mass ] bi v/n ;
+: calc-acceleration ( node -- vec ) [ force>> ] [ mass>> ] bi v/n ;
 
 : new-vel ( node -- vel )
-  [ node-vel ] [ calc-acceleration time-slice> v*n ] bi v+ ;
+  [ vel>> ] [ calc-acceleration time-slice> v*n ] bi v+ ;
 
-: new-pos ( node -- pos ) [ node-pos ] [ node-vel time-slice> v*n ] bi v+ ;
+: new-pos ( node -- pos ) [ pos>> ] [ vel>> time-slice> v*n ] bi v+ ;
 
 : iterate-node ( node -- )
   dup new-pos >>pos
   dup new-vel >>vel
-  dup reset-force
+  reset-force
   handle-bounce ;
 
 : iterate-nodes ( -- ) nodes> [ iterate-node ] each ;
@@ -231,16 +231,21 @@ C: <spring> spring
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 : mass ( id x y x-vel y-vel mass elas -- )
-  7 nrot drop
-  6 nrot 6 nrot 2array
-  5 nrot 5 nrot 2array
-  0 0 2array <node>
-  nodes> swap suffix >nodes ;
+  node new
+    swap >>elas
+    swap >>mass
+    -rot 2array >>vel
+    -rot 2array >>pos
+    0 0  2array >>force
+  nodes> swap suffix >nodes
+  drop ;
 
 : spng ( id id-a id-b k damp rest-length -- )
-  6 nrot drop
-  -rot
-  5 nrot node-id
-  5 nrot node-id
-  <spring>
-  springs> swap suffix >springs ;
+   spring new
+     swap >>rest-length
+     swap >>damp
+     swap >>k
+     swap node-id >>node-b
+     swap node-id >>node-a
+   springs> swap suffix >springs
+   drop ;
\ No newline at end of file
index 8aabe6b70bfe703560af56b27fe8a6d9cd457910..365632e9744038258a1789ee05510838e12b54d6 100644 (file)
@@ -1,16 +1,16 @@
 
 USING: kernel namespaces threads sequences math math.vectors
        opengl.gl opengl colors ui ui.gadgets ui.gadgets.slate
-       fry rewrite-closures vars springies ;
+       fry rewrite-closures vars springies accessors math.geometry.rect ;
 
 IN: springies.ui
 
 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
-: draw-node ( node -- ) node-pos { -5 -5 } v+ dup { 10 10 } v+ gl-rect ;
+: draw-node ( node -- ) pos>> { -5 -5 } v+ dup { 10 10 } v+ gl-rect ;
 
 : draw-spring ( spring -- )
-  [ spring-node-a node-pos ] [ spring-node-b node-pos ] bi gl-line ;
+  [ spring-node-a pos>> ] [ spring-node-b pos>> ] bi gl-line ;
 
 : draw-nodes ( -- ) nodes> [ draw-node ] each ;
 
index c2f874598c2666edd52802da3e13f3a6e2a0601f..d01cec3790c0cfe4420bf28c294d393f5f9cd171 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alarms arrays calendar kernel ui.gadgets ui.gadgets.labels
 ui.gadgets.worlds ui.gadgets.status-bar ui.gestures ui.render ui
-tetris.game tetris.gl sequences system math math.parser namespaces ;
+tetris.game tetris.gl sequences system math math.parser namespaces
+math.geometry.rect ;
 IN: tetris
 
 TUPLE: tetris-gadget tetris alarm ;
index 2dd334d0241270b7358a6522f164dcb7e748b0bc..0e203848399a83ccbd78153a6222d7b7985550a2 100755 (executable)
@@ -101,6 +101,7 @@ IN: tools.deploy.shaker
                 "if-intrinsics"
                 "infer"
                 "inferred-effect"
+                "input-classes"
                 "interval"
                 "intrinsics"
                 "loc"
index dd9510405f8891f862d96fb405960e6756be96fb..132a11f4a6c0ffe67ad7a4f4831bde28309e891b 100755 (executable)
@@ -6,7 +6,7 @@ TUPLE: foo bar ;
 C: <foo> foo
 [ 2 ] [ 2 T{ foo } <tuple-array> dup mat set length ] unit-test
 [ T{ foo } ] [ mat get first ] unit-test
-[ T{ foo f 1 } ] [ T{ foo 2 1 } 0 mat get [ set-nth ] keep first ] unit-test
+[ T{ foo 2 1 } ] [ T{ foo 2 1 } 0 mat get [ set-nth ] keep first ] unit-test
 [ t ] [ { T{ foo f 1 } T{ foo f 2 } } >tuple-array dup mat set tuple-array? ] unit-test
 [ T{ foo f 3 } t ] 
 [ mat get [ foo-bar 2 + <foo> ] map [ first ] keep tuple-array? ] unit-test
index 6a31dac808de82e4524ae4a01ce3b71a06658201..63e7541c95e11287fd85b57674f6f63eded1c3b4 100644 (file)
@@ -1,35 +1,26 @@
 ! Copyright (C) 2007 Daniel Ehrenberg.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: splitting grouping classes.tuple classes math kernel
-sequences arrays ;
+sequences arrays accessors ;
 IN: tuple-arrays
 
-TUPLE: tuple-array example ;
-
-: prepare-example ( tuple -- seq n )
-    dup class over delegate [ 1array ] [ f 2array ] if
-    swap tuple>array length over length - ;
+TUPLE: tuple-array seq class ;
 
 : <tuple-array> ( length example -- tuple-array )
-    prepare-example [ rot * { } new-sequence ] keep
-    <sliced-groups> tuple-array construct-delegate
-    [ set-tuple-array-example ] keep ;
-
-: reconstruct ( seq example -- tuple )
-    prepend >tuple ;
+    [ tuple>array length 1- [ * { } new-sequence ] keep <sliced-groups> ]
+    [ class ] bi tuple-array boa ;
 
 M: tuple-array nth
-    [ delegate nth ] keep
-    tuple-array-example reconstruct ;
+    [ seq>> nth ] [ class>> ] bi prefix >tuple ;
 
-: deconstruct ( tuple example -- seq )
-    >r tuple>array r> length tail-slice ;
+: deconstruct ( tuple -- seq )
+    tuple>array 1 tail ;
 
 M: tuple-array set-nth ( elt n seq -- )
-    tuck >r >r tuple-array-example deconstruct r> r>
-    delegate set-nth ;
+    >r >r deconstruct r> r> seq>> set-nth ;
 
-M: tuple-array new-sequence tuple-array-example >tuple <tuple-array> ;
+M: tuple-array new-sequence
+    class>> new <tuple-array> ;
 
 : >tuple-array ( seq -- tuple-array/seq )
     dup empty? [
@@ -39,4 +30,6 @@ M: tuple-array new-sequence tuple-array-example >tuple <tuple-array> ;
 M: tuple-array like 
     drop dup tuple-array? [ >tuple-array ] unless ;
 
+M: tuple-array length seq>> length ;
+
 INSTANCE: tuple-array sequence
index bf28740ecccc0489784ce4294d8c8b9db0083338..0085376eaabd8b7936d789743e4699d2f75d5e6c 100755 (executable)
@@ -5,7 +5,7 @@ command-line kernel memory namespaces cocoa.messages
 cocoa.runtime cocoa.subclassing cocoa.pasteboard cocoa.types
 cocoa.windows cocoa.classes cocoa.application sequences system
 ui ui.backend ui.clipboards ui.gadgets ui.gadgets.worlds
-ui.cocoa.views core-foundation threads ;
+ui.cocoa.views core-foundation threads math.geometry.rect ;
 IN: ui.cocoa
 
 TUPLE: handle view window ;
index 68db5954d5b569792218938a7c85139871cb2a5c..3bacad20b45da7bab9e7b2881d0db347494ffdf8 100755 (executable)
@@ -4,7 +4,7 @@ USING: accessors alien alien.c-types arrays assocs cocoa kernel
 math cocoa.messages cocoa.subclassing cocoa.classes cocoa.views
 cocoa.application cocoa.pasteboard cocoa.types cocoa.windows
 sequences ui ui.gadgets ui.gadgets.worlds ui.gestures
-core-foundation threads combinators ;
+core-foundation threads combinators math.geometry.rect ;
 IN: ui.cocoa.views
 
 : send-mouse-moved ( view event -- )
index 219a9709438f3627a485137a4bfe2626ce74a40c..ce15bd9e6c3ca514a287d2a35e17af84fbe4847d 100755 (executable)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel sequences models ui.gadgets ;
+USING: accessors kernel sequences models ui.gadgets math.geometry.rect ;
 IN: ui.gadgets.books
 
 TUPLE: book < gadget ;
@@ -19,7 +19,7 @@ M: book model-changed
 : new-book ( pages model class -- book )
     new-gadget
         swap >>model
-        [ add-gadgets ] keep ; inline
+        [ swap add-gadgets drop ] keep ; inline
 
 : <book> ( pages model -- book )
     book new-book ;
index 268d1ab0a3858702f6885fc8638afc7eb69b2bb0..0151996c02dbeaebb0e110d91a290abcf15ed889 100644 (file)
@@ -1,6 +1,6 @@
 IN: ui.gadgets.borders.tests
 USING: tools.test accessors namespaces kernel
-ui.gadgets ui.gadgets.borders ;
+ui.gadgets ui.gadgets.borders math.geometry.rect ;
 
 [ { 110 210 } ] [ <gadget> { 100 200 } >>dim 5 <border> pref-dim ] unit-test
 
index 55d1993b1d35fcbc2ea3409ce4284b811744364b..d1cf7cfb297b7728cd34aa5f69b657d6dfba943c 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays ui.gadgets kernel math
-namespaces vectors sequences math.vectors ;
+namespaces vectors sequences math.vectors math.geometry.rect ;
 IN: ui.gadgets.borders
 
 TUPLE: border < gadget
@@ -10,7 +10,7 @@ TUPLE: border < gadget
 { align initial: { 1/2 1/2 } } ;
 
 : new-border ( child class -- border )
-    new-gadget [ add-gadget ] keep ; inline
+    new-gadget [ swap add-gadget drop ] keep ; inline
 
 : <border> ( child gap -- border )
     swap border new-border
@@ -33,7 +33,8 @@ M: border pref-dim*
     [ border-major-dim ] [ border-minor-dim ] [ fill>> ] tri scale ;
 
 : border-loc ( border dim -- loc )
-    [ [ size>> ] [ align>> ] [ border-major-dim ] tri ] dip v- v* v+ ;
+    [ [ size>> ] [ align>> ] [ border-major-dim ] tri ] dip
+    v- v* v+ [ >fixnum ] map ;
 
 : border-child-rect ( border -- rect )
     dup border-dim [ border-loc ] keep <rect> ;
index 96a89e8aa6f381bb47a506fcccb67eb99a80bada..4c4efec20f9f33a2b22b88454a1f7cf051f0ac75 100755 (executable)
@@ -1,12 +1,13 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays kernel math models namespaces sequences
-strings quotations assocs combinators classes colors
-classes.tuple opengl math.vectors
-ui.commands ui.gadgets ui.gadgets.borders
-ui.gadgets.labels ui.gadgets.theme
-ui.gadgets.tracks ui.gadgets.packs ui.gadgets.worlds ui.gestures
-ui.render ;
+       strings quotations assocs combinators classes colors
+       classes.tuple opengl math.vectors
+       ui.commands ui.gadgets ui.gadgets.borders
+       ui.gadgets.labels ui.gadgets.theme
+       ui.gadgets.tracks ui.gadgets.packs ui.gadgets.worlds ui.gestures
+       ui.render math.geometry.rect ;
+
 IN: ui.gadgets.buttons
 
 TUPLE: button < border pressed? selected? quot ;
@@ -187,9 +188,9 @@ M: radio-control model-changed
     over set-button-selected?
     relayout-1 ;
 
-: <radio-controls> ( model assoc quot -- )
-    #! quot has stack effect ( value model label -- )
-    swapd [ swapd call gadget, ] 2curry assoc-each ; inline
+: <radio-controls> ( parent model assoc quot -- parent )
+  #! quot has stack effect ( value model label -- )
+  swapd [ swapd call add-gadget ] 2curry assoc-each ; inline
 
 : radio-button-theme ( gadget -- gadget )
     { 5 5 } >>gap
@@ -202,14 +203,18 @@ M: radio-control model-changed
     { 5 5 } >>gap drop ;
 
 : <radio-buttons> ( model assoc -- gadget )
-    [ [ <radio-button> ] <radio-controls> ] make-filled-pile
-    dup radio-buttons-theme ;
+  <filled-pile>
+    -rot
+    [ <radio-button> ] <radio-controls>
+  dup radio-buttons-theme ;
 
 : <toggle-button> ( value model label -- gadget )
     <radio-control> bevel-button-theme ;
 
 : <toggle-buttons> ( model assoc -- gadget )
-    [ [ <toggle-button> ] <radio-controls> ] make-shelf ;
+  <shelf>
+    -rot
+    [ <toggle-button> ] <radio-controls> ;
 
 : command-button-quot ( target command -- quot )
     [ invoke-command drop ] 2curry ;
@@ -221,9 +226,9 @@ M: radio-control model-changed
     <bevel-button> ;
 
 : <toolbar> ( target -- toolbar )
-    [
-        "toolbar" over class command-map commands>> swap
-        [ -rot <command-button> gadget, ] curry assoc-each
-    ] make-shelf ;
+  <shelf>
+    swap
+    "toolbar" over class command-map commands>> swap
+    [ -rot <command-button> add-gadget ] curry assoc-each ;
 
 : toolbar, ( -- ) g <toolbar> f track, ;
index 1732d404ca85c4daeaad0230b4eebc3e4afdf5cd..8b0244900a9b7c450505fcdd483159c69a94fdc7 100755 (executable)
@@ -5,7 +5,8 @@ namespaces opengl opengl.gl sequences strings io.styles
 math.vectors sorting colors combinators assocs math.order
 ui.clipboards ui.commands ui.gadgets ui.gadgets.borders
 ui.gadgets.buttons ui.gadgets.labels ui.gadgets.scrollers
-ui.gadgets.theme ui.gadgets.wrappers ui.render ui.gestures ;
+ui.gadgets.theme ui.gadgets.wrappers ui.render ui.gestures
+math.geometry.rect ;
 IN: ui.gadgets.editors
 
 TUPLE: editor < gadget
index a288f74f64b0d687ad98e6fbbed985b7a1243865..7d77db24ccbb8bbcec586d6b5a297dc68ec96433 100644 (file)
@@ -1,7 +1,7 @@
 
 USING: kernel alien.c-types combinators sequences splitting grouping
        opengl.gl ui.gadgets ui.render
-       math math.vectors accessors ;
+       math math.vectors accessors math.geometry.rect ;
 
 IN: ui.gadgets.frame-buffer
 
index 096d916a9b89c58d8230be45d1fb497eaca8f07f..717323c69a526376e5841d2a48b721c83846c03f 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2005, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays generic kernel math namespaces sequences words
-splitting grouping math.vectors ui.gadgets.grids ui.gadgets ;
+splitting grouping math.vectors ui.gadgets.grids ui.gadgets
+math.geometry.rect ;
 IN: ui.gadgets.frames
 
 ! A frame arranges gadgets in a 3x3 grid, where the center
index 8093aa5dc5a8ca91ab3cde80a17e1d5a39839849..47ae6b4733f702f8a406b4aa2c9c5fc2859dc18c 100755 (executable)
@@ -1,53 +1,7 @@
 USING: help.markup help.syntax opengl kernel strings
-classes.tuple classes quotations models ;
+       classes.tuple classes quotations models math.geometry.rect ;
 IN: ui.gadgets
 
-HELP: rect
-{ $class-description "A rectangle with the following slots:"
-    { $list
-        { { $link rect-loc } " - the top-left corner of the rectangle as an x/y pair" }
-        { { $link rect-dim } " - the dimensions of the rectangle as a width/height pair" }
-    }
-    "Rectangles are constructed by calling " { $link <rect> } " and " { $link <extent-rect> } "."
-} ;
-
-HELP: <rect> ( loc dim -- rect )
-{ $values { "loc" "a pair of integers" } { "dim" "a pair of integers" } { "rect" "a new " { $link rect } } }
-{ $description "Creates a new rectangle with the specified top-left location and dimensions." } ;
-
-{ <zero-rect> <rect> <extent-rect> } related-words
-
-HELP: set-rect-dim ( dim rect -- )
-{ $values { "dim" "a pair of integers" } { "rect" rect } }
-{ $description "Modifies the dimensions of a rectangle. To resize a gadget, use " { $link set-gadget-dim } " or " { $link set-layout-dim } " instead." }
-{ $side-effects "rect" } ;
-
-HELP: rect-bounds
-{ $values { "rect" rect } { "loc" "a pair of integers" } { "dim" "a pair of integers" } }
-{ $description "Outputs the location and dimensions of a rectangle." } ;
-
-{ rect-bounds rect-extent } related-words
-
-HELP: <extent-rect> ( loc ext -- rect )
-{ $values { "loc" "a pair of integers" } { "ext" "a pair of integers" } { "rect" "a new " { $link rect } } }
-{ $description "Creates a new rectangle with the specified top-left and bottom-right corner locations." } ;
-
-HELP: rect-extent
-{ $values { "rect" rect } { "loc" "a pair of integers" } { "ext" "a pair of integers" } }
-{ $description "Outputs the location of the top-left and bottom-right corners of a rectangle." } ;
-
-HELP: offset-rect
-{ $values { "rect" rect } { "loc" "a pair of integers" } { "newrect" "a new " { $link rect } } }
-{ $description "Creates a new rectangle with the same dimensions, and top-left corner translated by " { $snippet "loc" } "." } ;
-
-HELP: rect-intersect
-{ $values { "rect1" rect } { "rect2" rect } { "newrect" "a new " { $link rect } } }
-{ $description "Computes the intersection of two rectangles." } ;
-
-HELP: intersects?
-{ $values { "rect/point" "a " { $link rect } " or a pair of integers" } { "rect" rect } { "?" "a boolean" } }
-{ $description "Tests if two rectangles (or a point and a rectangle, respectively) have a non-empty intersection." } ;
-
 HELP: gadget-child
 { $values { "gadget" gadget } { "child" gadget } }
 { $description "Outputs the first child of the gadget. Typically this word is used with gadgets which are known to have an only child." } ;
@@ -57,10 +11,6 @@ HELP: nth-gadget
 { $description "Outputs the " { $snippet "n" } "th child of the gadget." }
 { $errors "Throws an error if " { $snippet "n" } " is negative or greater than or equal to the number of children." } ;
 
-HELP: <zero-rect>
-{ $values { "rect" "a new " { $link rect } } }
-{ $description "Creates a rectangle located at the origin with zero dimensions." } ;
-
 HELP: <gadget>
 { $values { "gadget" "a new " { $link gadget } } }
 { $description "Creates a new gadget." } ;
@@ -230,10 +180,6 @@ HELP: focusable-child
 { $values { "gadget" gadget } { "child" gadget } }
 { $description "Outputs the child of the gadget which would prefer to receive keyboard focus." } ;
 
-HELP: gadget,
-{ $values { "gadget" gadget } }
-{ $description "Adds a new child to the gadget being constructed. This word can only be used from a quotation passed to " { $link make-gadget } "." } ;
-
 HELP: make-gadget
 { $values { "gadget" gadget } { "quot" quotation } }
 { $description "Calls the quotation in a new scope with the gadget stored in the " { $link gadget } " variable." } ;
index dbb2919277973874c9f11f733a8b413b0210ce7a..1a2555d5381276feabc417caced99f93d5cd8d30 100755 (executable)
@@ -2,48 +2,16 @@ IN: ui.gadgets.tests
 USING: accessors ui.gadgets ui.gadgets.packs ui.gadgets.worlds
 tools.test namespaces models kernel dlists dequeues math sets
 math.parser ui sequences hashtables assocs io arrays prettyprint
-io.streams.string ;
-
-[ T{ rect f { 10 10 } { 20 20 } } ]
-[
-    T{ rect f { 10 10 } { 50 50 } }
-    T{ rect f { -10 -10 } { 40 40 } }
-    rect-intersect
-] unit-test
-
-[ T{ rect f { 200 200 } { 0 0 } } ]
-[
-    T{ rect f { 100 100 } { 50 50 } }
-    T{ rect f { 200 200 } { 40 40 } }
-    rect-intersect
-] unit-test
-
-[ f ] [
-    T{ rect f { 100 100 } { 50 50 } }
-    T{ rect f { 200 200 } { 40 40 } }
-    intersects?
-] unit-test
-
-[ t ] [
-    T{ rect f { 100 100 } { 50 50 } }
-    T{ rect f { 120 120 } { 40 40 } }
-    intersects?
-] unit-test
-
-[ f ] [
-    T{ rect f { 1000 100 } { 50 50 } }
-    T{ rect f { 120 120 } { 40 40 } }
-    intersects?
-] unit-test
+io.streams.string math.geometry.rect ;
 
 [ { 300 300 } ]
 [
     ! c contains b contains a
     <gadget> "a" set
     <gadget> "b" set
-    "a" get "b" get add-gadget
+    "a" get "b" get swap add-gadget drop
     <gadget> "c" set
-    "b" get "c" get add-gadget
+    "b" get "c" get swap add-gadget drop
 
     ! position a and b
     { 100 200 } "a" get set-rect-loc
@@ -65,8 +33,8 @@ io.streams.string ;
 <gadget> "g3" set
 { 100 200 } "g3" get set-rect-dim
 
-"g1" get "g2" get add-gadget
-"g2" get "g3" get add-gadget
+"g1" get "g2" get swap add-gadget drop
+"g2" get "g3" get swap add-gadget drop
 
 [ { 30 30 } ] [ "g1" get screen-loc ] unit-test
 [ { 30 30 } ] [ "g1" get screen-rect rect-loc ] unit-test
@@ -81,11 +49,11 @@ io.streams.string ;
 <gadget> "g1" set
 { 300 300 } "g1" get set-rect-dim
 <gadget> "g2" set
-"g2" get "g1" get add-gadget
+"g2" get "g1" get swap add-gadget drop
 { 20 20 } "g2" get set-rect-loc
 { 20 20 } "g2" get set-rect-dim
 <gadget> "g3" set
-"g3" get "g1" get add-gadget
+"g3" get "g1" get swap add-gadget drop
 { 100 100 } "g3" get set-rect-loc
 { 20 20 } "g3" get set-rect-dim
 
@@ -98,7 +66,7 @@ io.streams.string ;
 [ t ] [ { 110 110 } "g1" get pick-up "g3" get eq? ] unit-test
 
 <gadget> "g4" set
-"g4" get "g2" get add-gadget
+"g4" get "g2" get swap add-gadget drop
 { 5 5 } "g4" get set-rect-loc
 { 1 1 } "g4" get set-rect-dim
 
@@ -155,7 +123,7 @@ M: mock-gadget ungraft*
     : add-some-children
         3 [
             <mock-gadget> over <model> over set-gadget-model
-            dup "g" get add-gadget
+            dup "g" get swap add-gadget drop
             swap 1+ number>string set
         ] each ;
 
index 5bfb5a1b05203c45b8bb3087ed1bba92c520dfe5..ce0df019e7edaedf02f8091f5ce237a36c585f13 100755 (executable)
@@ -1,56 +1,21 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays hashtables kernel models math namespaces
-sequences quotations math.vectors combinators sorting vectors
-dlists dequeues models threads concurrency.flags math.order ;
+       sequences quotations math.vectors combinators sorting vectors
+       dlists dequeues models threads concurrency.flags
+       math.order math.geometry.rect ;
+
 IN: ui.gadgets
 
 SYMBOL: ui-notify-flag
 
 : notify-ui-thread ( -- ) ui-notify-flag get-global raise-flag ;
 
-TUPLE: rect { loc initial: { 0 0 } } { dim initial: { 0 0 } } ;
-
-: <zero-rect> ( -- rect ) rect new ;
-
-C: <rect> rect
-
-M: array rect-loc ;
-
-M: array rect-dim drop { 0 0 } ;
-
-: rect-bounds ( rect -- loc dim ) dup rect-loc swap rect-dim ;
-
-: rect-extent ( rect -- loc ext ) rect-bounds over v+ ;
-
-: 2rect-extent ( rect rect -- loc1 loc2 ext1 ext2 )
-    [ rect-extent ] bi@ swapd ;
-
-: <extent-rect> ( loc ext -- rect ) over [v-] <rect> ;
-
-: offset-rect ( rect loc -- newrect )
-    over rect-loc v+ swap rect-dim <rect> ;
-
-: (rect-intersect) ( rect rect -- array array )
-    2rect-extent vmin >r vmax r> ;
-
-: rect-intersect ( rect1 rect2 -- newrect )
-    (rect-intersect) <extent-rect> ;
-
-: intersects? ( rect/point rect -- ? )
-    (rect-intersect) [v-] { 0 0 } = ;
-
-: (rect-union) ( rect rect -- array array )
-    2rect-extent vmax >r vmin r> ;
-
-: rect-union ( rect1 rect2 -- newrect )
-    (rect-union) <extent-rect> ;
-
 TUPLE: gadget < rect
-pref-dim parent children orientation focus
-visible? root? clipped? layout-state graft-state graft-node
-interior boundary
-model ;
+       pref-dim parent children orientation focus
+       visible? root? clipped? layout-state graft-state graft-node
+       interior boundary
+       model ;
 
 M: gadget equal? 2drop f ;
 
@@ -58,9 +23,9 @@ M: gadget hashcode* drop gadget hashcode* ;
 
 M: gadget model-changed 2drop ;
 
-: gadget-child ( gadget -- child ) gadget-children first ;
+: gadget-child ( gadget -- child ) children>> first ;
 
-: nth-gadget ( n gadget -- child ) gadget-children nth ;
+: nth-gadget ( n gadget -- child ) children>> nth ;
 
 : new-gadget ( class -- gadget )
     new
@@ -72,7 +37,7 @@ M: gadget model-changed 2drop ;
     gadget new-gadget ;
 
 : activate-control ( gadget -- )
-    dup gadget-model dup [
+    dup model>> dup [
         2dup add-connection
         swap model-changed
     ] [
@@ -80,20 +45,20 @@ M: gadget model-changed 2drop ;
     ] if ;
 
 : deactivate-control ( gadget -- )
-    dup gadget-model dup [ 2dup remove-connection ] when 2drop ;
+    dup model>> dup [ 2dup remove-connection ] when 2drop ;
 
 : control-value ( control -- value )
-    gadget-model model-value ;
+    model>> model-value ;
 
 : set-control-value ( value control -- )
-    gadget-model set-model ;
+    model>> set-model ;
 
 : relative-loc ( fromgadget togadget -- loc )
     2dup eq? [
         2drop { 0 0 }
     ] [
         over rect-loc >r
-        >r gadget-parent r> relative-loc
+        >r parent>> r> relative-loc
         r> v+
     ] if ;
 
@@ -103,22 +68,18 @@ M: gadget user-input* 2drop t ;
 
 GENERIC: children-on ( rect/point gadget -- seq )
 
-M: gadget children-on nip gadget-children ;
+M: gadget children-on nip children>> ;
 
 : (fast-children-on) ( dim axis gadgets -- i )
     swapd [ rect-loc v- over v. 0 <=> ] binsearch nip ;
 
 : fast-children-on ( rect axis children -- from to )
-    3dup
-    >r >r dup rect-loc swap rect-dim v+
-    r> r> (fast-children-on) ?1+
-    >r
-    >r >r rect-loc
-    r> r> (fast-children-on) 0 or
-    r> ;
+    [ >r >r rect-loc r> r> (fast-children-on) 0 or ]
+    [ >r >r dup rect-loc swap rect-dim v+ r> r> (fast-children-on) ?1+ ]
+    3bi ;
 
 : inside? ( bounds gadget -- ? )
-    dup gadget-visible? [ intersects? ] [ 2drop f ] if ;
+    dup visible?>> [ intersects? ] [ 2drop f ] if ;
 
 : (pick-up) ( point gadget -- gadget )
     dupd children-on [ inside? ] with find-last nip ;
@@ -132,10 +93,10 @@ M: gadget children-on nip gadget-children ;
 : dim-sum ( seq -- dim ) { 0 0 } [ v+ ] reduce ;
 
 : orient ( gadget seq1 seq2 -- seq )
-    >r >r gadget-orientation r> r> [ pick set-axis ] 2map nip ;
+    >r >r orientation>> r> r> [ pick set-axis ] 2map nip ;
 
 : each-child ( gadget quot -- )
-    >r gadget-children r> each ; inline
+    >r children>> r> each ; inline
 
 ! Selection protocol
 GENERIC: gadget-selection? ( gadget -- ? )
@@ -152,14 +113,14 @@ GENERIC: gadget-text* ( gadget -- )
 GENERIC: gadget-text-separator ( gadget -- str )
 
 M: gadget gadget-text-separator
-    gadget-orientation { 0 1 } = "\n" "" ? ;
+    orientation>> { 0 1 } = "\n" "" ? ;
 
 : gadget-seq-text ( seq gadget -- )
     gadget-text-separator swap
     [ dup % ] [ gadget-text* ] interleave drop ;
 
 M: gadget gadget-text*
-    dup gadget-children swap gadget-seq-text ;
+    dup children>> swap gadget-seq-text ;
 
 M: array gadget-text*
     [ gadget-text* ] each ;
@@ -167,9 +128,9 @@ M: array gadget-text*
 : gadget-text ( gadget -- string ) [ gadget-text* ] "" make ;
 
 : invalidate ( gadget -- )
-    \ invalidate swap set-gadget-layout-state ;
+    \ invalidate swap (>>layout-state) ;
 
-: forget-pref-dim ( gadget -- ) f swap set-gadget-pref-dim ;
+: forget-pref-dim ( gadget -- ) f swap (>>pref-dim) ;
 
 : layout-queue ( -- queue ) \ layout-queue get ;
 
@@ -182,22 +143,22 @@ M: array gadget-text*
 DEFER: relayout
 
 : invalidate* ( gadget -- )
-    \ invalidate* over set-gadget-layout-state
+    \ invalidate* over (>>layout-state)
     dup forget-pref-dim
     dup gadget-root?
-    [ layout-later ] [ gadget-parent [ relayout ] when* ] if ;
+    [ layout-later ] [ parent>> [ relayout ] when* ] if ;
 
 : relayout ( gadget -- )
-    dup gadget-layout-state \ invalidate* eq?
+    dup layout-state>> \ invalidate* eq?
     [ drop ] [ invalidate* ] if ;
 
 : relayout-1 ( gadget -- )
-    dup gadget-layout-state
+    dup layout-state>>
     [ drop ] [ dup invalidate layout-later ] if ;
 
-: show-gadget ( gadget -- ) t swap set-gadget-visible? ;
+: show-gadget ( gadget -- ) t swap (>>visible?) ;
 
-: hide-gadget ( gadget -- ) f swap set-gadget-visible? ;
+: hide-gadget ( gadget -- ) f swap (>>visible?) ;
 
 : (set-rect-dim) ( dim gadget quot -- )
     >r 2dup rect-dim =
@@ -213,11 +174,11 @@ DEFER: relayout
 GENERIC: pref-dim* ( gadget -- dim )
 
 : ?set-gadget-pref-dim ( dim gadget -- )
-    dup gadget-layout-state
-    [ 2drop ] [ set-gadget-pref-dim ] if ;
+    dup layout-state>>
+    [ 2drop ] [ (>>pref-dim) ] if ;
 
 : pref-dim ( gadget -- dim )
-    dup gadget-pref-dim [ ] [
+    dup pref-dim>> [ ] [
         [ pref-dim* dup ] keep ?set-gadget-pref-dim
     ] ?if ;
 
@@ -231,10 +192,10 @@ M: gadget layout* drop ;
 
 : prefer ( gadget -- ) dup pref-dim swap set-layout-dim ;
 
-: validate ( gadget -- ) f swap set-gadget-layout-state ;
+: validate ( gadget -- ) f swap (>>layout-state) ;
 
 : layout ( gadget -- )
-    dup gadget-layout-state [
+    dup layout-state>> [
         dup validate
         dup layout*
         dup [ layout ] each-child
@@ -258,7 +219,7 @@ M: gadget layout* drop ;
     { t f } (queue-graft) ;
 
 : graft-later ( gadget -- )
-    dup gadget-graft-state {
+    dup graft-state>> {
         { { f t } [ drop ] }
         { { t t } [ drop ] }
         { { t f } [ unqueue-graft ] }
@@ -266,7 +227,7 @@ M: gadget layout* drop ;
     } case ;
 
 : ungraft-later ( gadget -- )
-    dup gadget-graft-state {
+    dup graft-state>> {
         { { f f } [ drop ] }
         { { t f } [ drop ] }
         { { f t } [ unqueue-graft ] }
@@ -290,11 +251,11 @@ M: gadget ungraft* drop ;
 : (unparent) ( gadget -- )
     dup ungraft
     dup forget-pref-dim
-    f swap set-gadget-parent ;
+    f swap (>>parent) ;
 
 : unfocus-gadget ( child gadget -- )
-    tuck gadget-focus eq?
-    [ f swap set-gadget-focus ] [ drop ] if ;
+    tuck focus>> eq?
+    [ f swap (>>focus) ] [ drop ] if ;
 
 SYMBOL: in-layout?
 
@@ -305,10 +266,10 @@ SYMBOL: in-layout?
 : unparent ( gadget -- )
     not-in-layout
     [
-        dup gadget-parent dup [
+        dup parent>> dup [
             over (unparent)
             [ unfocus-gadget ] 2keep
-            [ gadget-children delete ] keep
+            [ children>> delete ] keep
             relayout
         ] [
             2drop
@@ -317,32 +278,37 @@ SYMBOL: in-layout?
 
 : (clear-gadget) ( gadget -- )
     dup [ (unparent) ] each-child
-    f over set-gadget-focus
-    f swap set-gadget-children ;
+    f over (>>focus)
+    f swap (>>children) ;
 
 : clear-gadget ( gadget -- )
     not-in-layout
     dup (clear-gadget) relayout ;
 
-: ((add-gadget)) ( gadget box -- )
-    [ gadget-children ?push ] keep set-gadget-children ;
+: ((add-gadget)) ( parent child -- parent )
+    over children>> ?push >>children ;
 
-: (add-gadget) ( gadget box -- )
-    over unparent
-    dup pick set-gadget-parent
-    [ ((add-gadget)) ] 2keep
-    gadget-graft-state second [ graft ] [ drop ] if ;
+: (add-gadget) ( parent child -- parent )
+    dup unparent
+    over >>parent
+    tuck ((add-gadget))
+    tuck graft-state>> second
+        [ graft ]
+        [ drop  ]
+    if ;
 
-: add-gadget ( gadget parent -- )
+: add-gadget ( parent child -- parent )
     not-in-layout
-    [ (add-gadget) ] keep relayout ;
-
-: add-gadgets ( seq parent -- )
+    (add-gadget)
+    dup relayout ;
+  
+: add-gadgets ( parent children -- parent )
     not-in-layout
-    swap [ over (add-gadget) ] each relayout ;
+    [ (add-gadget) ] each
+    dup relayout ;
 
 : parents ( gadget -- seq )
-    [ gadget-parent ] follow ;
+    [ parent>> ] follow ;
 
 : each-parent ( gadget quot -- ? )
     >r parents r> all? ; inline
@@ -354,7 +320,7 @@ SYMBOL: in-layout?
     parents { 0 0 } [ rect-loc v+ ] reduce ;
 
 : (screen-rect) ( gadget -- loc ext )
-    dup gadget-parent [
+    dup parent>> [
         >r rect-extent r> (screen-rect)
         >r tuck v+ r> vmin >r v+ r>
     ] [
@@ -368,7 +334,7 @@ SYMBOL: in-layout?
     {
         { [ 2dup eq? ] [ 2drop t ] }
         { [ dup not ] [ 2drop f ] }
-        [ gadget-parent child? ]
+        [ parent>> child? ]
     } cond ;
 
 GENERIC: focusable-child* ( gadget -- child/t )
@@ -381,7 +347,7 @@ M: gadget focusable-child* drop t ;
 
 GENERIC: request-focus-on ( child gadget -- )
 
-M: gadget request-focus-on gadget-parent request-focus-on ;
+M: gadget request-focus-on parent>> request-focus-on ;
 
 M: f request-focus-on 2drop ;
 
@@ -389,9 +355,7 @@ M: f request-focus-on 2drop ;
     [ focusable-child ] keep request-focus-on ;
 
 : focus-path ( world -- seq )
-    [ gadget-focus ] follow ;
-
-: gadget, ( gadget -- ) gadget get add-gadget ;
+    [ focus>> ] follow ;
 
 : g ( -- gadget ) gadget get ;
 
@@ -406,7 +370,7 @@ M: f request-focus-on 2drop ;
 ! Deprecated
 : set-gadget-delegate ( gadget tuple -- )
     over [
-        dup pick [ set-gadget-parent ] with each-child
+        dup pick [ (>>parent) ] with each-child
     ] when set-delegate ;
 
 : construct-gadget ( class -- tuple )
index 533116824bb48213d744c427f1a6b0847e081ce3..d0cedc985b697b108ec468a9baaefbbc3cd06af1 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel math namespaces opengl opengl.gl sequences
-math.vectors ui.gadgets ui.gadgets.grids ui.render ;
+math.vectors ui.gadgets ui.gadgets.grids ui.render math.geometry.rect ;
 IN: ui.gadgets.grid-lines
 
 TUPLE: grid-lines color ;
index f20275ff2581bc2c293d976f7ebe33aff8beaaf8..cfca5d5a93d5d318b120244bddf3a1f447b8679d 100644 (file)
@@ -1,5 +1,5 @@
 USING: ui.gadgets ui.gadgets.grids tools.test kernel arrays
-namespaces ;
+namespaces math.geometry.rect ;
 IN: ui.gadgets.grids.tests
 
 [ { 0 0 } ] [ { } <grid> pref-dim ] unit-test
index 70aee4d1e38ba72bc74fe651f5eb204010b1fa06..474e6b95c04a764fe74202d1255a11df81f83370 100644 (file)
@@ -1,7 +1,8 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays kernel math namespaces sequences words io
-io.streams.string math.vectors ui.gadgets columns accessors ;
+io.streams.string math.vectors ui.gadgets columns accessors
+math.geometry.rect ;
 IN: ui.gadgets.grids
 
 TUPLE: grid < gadget
@@ -11,7 +12,7 @@ grid
 
 : new-grid ( children class -- grid )
     new-gadget
-    [ (>>grid) ] [ >r concat r> add-gadgets ] [ nip ] 2tri ;
+    [ (>>grid) ] [ >r concat r> swap add-gadgets drop ] [ nip ] 2tri ;
     inline
 
 : <grid> ( children -- grid )
@@ -20,7 +21,7 @@ grid
 : grid-child ( grid i j -- gadget ) rot grid>> nth nth ;
 
 : grid-add ( gadget grid i j -- )
-    >r >r 2dup add-gadget r> r>
+    >r >r 2dup swap add-gadget drop r> r>
     3dup grid-child unparent rot grid>> nth set-nth ;
 
 : grid-remove ( grid i j -- )
index 418dd3b7c647c05d259177c2614874c57f65003b..8c227d76ce8354ad4752e95c65e010327cfea515 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: io kernel math namespaces math.vectors ui.gadgets
-ui.gadgets.packs accessors ;
+ui.gadgets.packs accessors math.geometry.rect ;
 IN: ui.gadgets.incremental
 
 ! Incremental layout allows adding lines to panes to be O(1).
@@ -45,7 +45,7 @@ M: incremental pref-dim*
 
 : add-incremental ( gadget incremental -- )
     not-in-layout
-    2dup (add-gadget)
+    2dup swap (add-gadget) drop
     over prefer-incremental
     over layout-later
     2dup incremental-loc
index 2b50453cf49782ebb426e37f9afc94f1816ad49e..c2539e146ab2054b3bde29fa31fe31203fd4be91 100755 (executable)
@@ -4,7 +4,7 @@ USING: accessors ui.commands ui.gestures ui.render ui.gadgets
 ui.gadgets.labels ui.gadgets.scrollers
 kernel sequences models opengl math math.order namespaces
 ui.gadgets.presentations ui.gadgets.viewports ui.gadgets.packs
-math.vectors classes.tuple ;
+math.vectors classes.tuple math.geometry.rect ;
 IN: ui.gadgets.lists
 
 TUPLE: list < pack index presenter color hook ;
@@ -48,7 +48,7 @@ TUPLE: list < pack index presenter color hook ;
 M: list model-changed
     nip
     dup clear-gadget
-    dup <list-items> over add-gadgets
+    dup <list-items> over swap add-gadgets drop
     bound-index ;
 
 : selected-rect ( list -- rect )
index 66dbb05d66b258cf87109140166e967463e1b274..2d7af473969bdd228775967d72057816d072933d 100644 (file)
@@ -3,7 +3,8 @@
 USING: arrays ui.commands ui.gadgets ui.gadgets.buttons
 ui.gadgets.worlds ui.gestures generic hashtables kernel math
 models namespaces opengl sequences math.vectors
-ui.gadgets.theme ui.gadgets.packs ui.gadgets.borders colors ;
+ui.gadgets.theme ui.gadgets.packs ui.gadgets.borders colors
+math.geometry.rect ;
 IN: ui.gadgets.menus
 
 : menu-loc ( world menu -- loc )
@@ -14,7 +15,7 @@ TUPLE: menu-glass < gadget ;
 : <menu-glass> ( menu world -- glass )
     menu-glass new-gadget
     >r over menu-loc over set-rect-loc r>
-    [ add-gadget ] keep ;
+    [ swap add-gadget drop ] keep ;
 
 M: menu-glass layout* gadget-child prefer ;
 
@@ -25,7 +26,7 @@ M: menu-glass layout* gadget-child prefer ;
 : show-glass ( gadget world -- )
     over hand-clicked set-global
     [ hide-glass ] keep
-    [ add-gadget ] 2keep
+    [ swap add-gadget drop ] 2keep
     set-world-glass ;
 
 : show-menu ( gadget owner -- )
@@ -47,6 +48,7 @@ M: menu-glass layout* gadget-child prefer ;
     faint-boundary ;
 
 : <commands-menu> ( hook target commands -- gadget )
-    [
-        [ >r 2dup r> <menu-item> gadget, ] each 2drop
-    ] make-filled-pile 5 <border> menu-theme ;
+  <filled-pile>
+  -roll
+    [ <menu-item> add-gadget ] with with each
+  5 <border> menu-theme ;
index d44c9fa87d2037af35e24fdbe93c6e8c82169427..7b87e8c441ab81b3565e1769df370564a958da46 100755 (executable)
@@ -13,7 +13,7 @@ ARTICLE: "ui-pack-layout" "Pack layouts"
 { $subsection make-pile }
 { $subsection make-filled-pile }
 { $subsection make-shelf }
-{ $subsection gadget, }
+
 "For more control, custom layouts can reuse portions of pack layout logic:"
 { $subsection pack-pref-dim }
 { $subsection pack-layout } ;
@@ -66,14 +66,14 @@ HELP: pack-pref-dim
 
 HELP: make-pile
 { $values { "quot" quotation } { "pack" "a new " { $link pack } } }
-{ $description "Creates a new " { $link pack } " which lays out a sequence of gadgets vertically. The quotation can add children by calling the " { $link gadget, } " word." } ;
+{ $description "Creates a new " { $link pack } " which lays out a sequence of gadgets vertically. The quotation can add children by calling the gadget, word." } ;
 
 HELP: make-filled-pile
 { $values { "quot" quotation } { "pack" "a new " { $link pack } } }
-{ $description "Creates a new " { $link pack } " which lays out a sequence of gadgets vertically, such that all gadgets have the same width. The quotation can add children by calling the " { $link gadget, } " word." } ;
+{ $description "Creates a new " { $link pack } " which lays out a sequence of gadgets vertically, such that all gadgets have the same width. The quotation can add children by calling the gadget, word." } ;
 
 HELP: make-shelf
 { $values { "quot" quotation } { "pack" "a new " { $link pack } } }
-{ $description "Creates a new " { $link pack } " which lays out a sequence of gadgets horizontally. The quotation can add children by calling the " { $link gadget, } " word." } ;
+{ $description "Creates a new " { $link pack } " which lays out a sequence of gadgets horizontally. The quotation can add children by calling the gadget, word." } ;
 
 ABOUT: "ui-pack-layout"
index 28a656e2ad89df539ed830e3f61bf07364f6b171..4ae84f83df347f5c6e330f533a1a6d63d9d390df 100644 (file)
@@ -1,6 +1,6 @@
 IN: ui.gadgets.packs.tests
 USING: ui.gadgets.packs ui.gadgets.labels ui.gadgets ui.render
-kernel namespaces tools.test math.parser sequences ;
+kernel namespaces tools.test math.parser sequences math.geometry.rect ;
 
 [ t ] [
     { 0 0 } { 100 100 } <rect> clip set
index 00f27af2706c1839288d098884a1a130db1f493f..7ae222c279ae77fc0dff8bcb5dfbaddb1ce5ecb8 100755 (executable)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: sequences ui.gadgets kernel math math.functions
-math.vectors namespaces math.order accessors ;
+math.vectors namespaces math.order accessors math.geometry.rect ;
 IN: ui.gadgets.packs
 
 TUPLE: pack < gadget
index 87eec35871d03af965328a3a9fa5f2c94bccaaa0..9b547ce5447f6b1e22af1c98baa115d9bf12ff4a 100755 (executable)
@@ -9,7 +9,7 @@ quotations math opengl combinators math.vectors
 sorting splitting io.streams.nested assocs
 ui.gadgets.presentations ui.gadgets.slots ui.gadgets.grids
 ui.gadgets.grid-lines classes.tuple models continuations
-destructors accessors ;
+destructors accessors math.geometry.rect ;
 IN: ui.gadgets.panes
 
 TUPLE: pane < pack
@@ -22,10 +22,10 @@ selection-color caret mark selecting? ;
     drop ;
 
 : add-output ( current pane -- )
-    [ set-pane-output ] [ add-gadget ] 2bi ;
+    [ set-pane-output ] [ swap add-gadget drop ] 2bi ;
 
 : add-current ( current pane -- )
-    [ set-pane-current ] [ add-gadget ] 2bi ;
+    [ set-pane-current ] [ swap add-gadget drop ] 2bi ;
 
 : prepare-line ( pane -- )
     [ clear-selection ]
@@ -120,7 +120,7 @@ C: <pane-stream> pane-stream
 GENERIC: write-gadget ( gadget stream -- )
 
 M: pane-stream write-gadget
-    pane-stream-pane pane-current add-gadget ;
+    pane-stream-pane pane-current swap add-gadget drop ;
 
 M: style-stream write-gadget
     stream>> write-gadget ;
@@ -299,12 +299,12 @@ M: paragraph dispose drop ;
 
 : gadget-write ( string gadget -- )
     over empty?
-    [ 2drop ] [ >r <label> text-theme r> add-gadget ] if ;
+    [ 2drop ] [ >r <label> text-theme r> swap add-gadget drop ] if ;
 
 M: pack stream-write gadget-write ;
 
 : gadget-bl ( style stream -- )
-    >r " " <word-break-gadget> style-label r> add-gadget ;
+    >r " " <word-break-gadget> style-label r> swap add-gadget drop ;
 
 M: paragraph stream-write
     swap " " split
@@ -322,7 +322,7 @@ M: paragraph stream-write1
 
 : gadget-format ( string style stream -- )
     pick empty?
-    [ 3drop ] [ >r swap <styled-label> r> add-gadget ] if ;
+    [ 3drop ] [ >r swap <styled-label> r> swap add-gadget drop ] if ;
 
 M: pack stream-format
     gadget-format ;
index 12382be9cdafcd22d323ccc948c733e707961ae3..1946ff6db681091297d21354dc80353a313a790f 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2005, 2007 Slava Pestov
 ! See http://factorcode.org/license.txt for BSD license.
 USING: arrays ui.gadgets ui.gadgets.labels ui.render kernel math
-namespaces sequences math.order ;
+namespaces sequences math.order math.geometry.rect ;
 IN: ui.gadgets.paragraphs
 
 ! A word break gadget
index ee82339f33134ebdc1dc5e2e95788bbe4de3f13d..3554c735a7711a069c1e68010533a301d0efaa5d 100755 (executable)
@@ -1,5 +1,5 @@
 USING: ui.gadgets help.markup help.syntax ui.gadgets.viewports
-ui.gadgets.sliders ;
+ui.gadgets.sliders math.geometry.rect ;
 IN: ui.gadgets.scrollers
 
 HELP: scroller
index 4df92141baed6b7f6670e84b0f2349e7180adf74..fb3e6cec23f013846e14f1f4ee0b255fb4dd09cb 100755 (executable)
@@ -3,7 +3,7 @@ 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 ;
+tools.test.ui math.geometry.rect ;
 
 [ ] [
     <gadget> "g" set
@@ -61,7 +61,7 @@ tools.test.ui ;
 
 <gadget> { 600 400 } over set-rect-dim "g1" set
 <gadget> { 600 10 } over set-rect-dim "g2" set
-"g2" get "g1" get add-gadget
+"g2" get "g1" get swap add-gadget drop
 
 "g1" get <scroller>
 { 300 300 } over set-rect-dim
index 8cac3f4400ca6203f0ba42ac0a72c17b51017aa2..1fe3c606bb755e17d8e5ebd9f6d0c60a630c0428 100755 (executable)
@@ -4,7 +4,7 @@ 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 models.range models.compose
-combinators math.vectors classes.tuple ;
+combinators math.vectors classes.tuple math.geometry.rect ;
 IN: ui.gadgets.scrollers
 
 TUPLE: scroller < frame viewport x y follows ;
index da18dea1429b76e2405c4a7292e9e3b5e7f3fd09..641883e7e1ce7afc327679332ac1d345811da1a8 100755 (executable)
@@ -4,7 +4,7 @@ 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 models.range math.vectors math.functions
-quotations colors ;
+quotations colors math.geometry.rect ;
 IN: ui.gadgets.sliders
 
 TUPLE: elevator < gadget direction ;
@@ -140,7 +140,7 @@ M: elevator layout*
 
 : elevator, ( orientation -- )
     dup <elevator> g-> set-slider-elevator
-    swap <thumb> g-> set-slider-thumb over add-gadget
+    swap <thumb> g-> set-slider-thumb add-gadget
     @center frame, ;
 
 : <left-button> ( -- button )
index 1b4f63360923edf639616b1f8ee5005e6b7a90ab..ce7e68c6224954118fd189756406818832d7c26d 100755 (executable)
@@ -16,7 +16,7 @@ DEFER: (del-page)
     [ [ gadget-parent '[ , , , (del-page) ] "X" swap\r
        <bevel-button> @right frame, ] 3keep \r
       [ swapd <toggle-button> @center frame, ] dip ] make-frame\r
-    swap add-gadget ;\r
+    add-gadget drop ;\r
 \r
 : redo-toggler ( tabbed -- )\r
      [ names>> ] [ model>> ] [ toggler>> ] tri\r
@@ -41,7 +41,7 @@ DEFER: (del-page)
     [ [ model>> swap ]\r
       [ names>> length 1 - swap ]\r
       [ toggler>> ] tri add-toggle ]\r
-    [ content>> add-gadget ]\r
+    [ content>> swap add-gadget drop ]\r
     [ refresh-book ] tri ;\r
 \r
 : del-page ( name tabbed -- )\r
@@ -51,6 +51,6 @@ DEFER: (del-page)
     tabbed new-frame\r
     [ g 0 <model> >>model\r
       <pile> 1 >>fill [ >>toggler ] keep swap @left grid-add\r
-      [ keys g swap >>names ]\r
+      [ keys >vector g swap >>names ]\r
       [ values g model>> <book> [ >>content ] keep swap @center grid-add ] bi\r
       g redo-toggler g ] with-gadget ;\r
index e2db914089c3a1108d40bc62082da411255cc88f..d3264b24701f589de9acd88bac7fc590dee4c1f6 100644 (file)
@@ -1,4 +1,4 @@
-USING: kernel ui.gadgets ui.gadgets.tracks tools.test ;
+USING: kernel ui.gadgets ui.gadgets.tracks tools.test math.geometry.rect ;
 IN: ui.gadgets.tracks.tests
 
 [ { 100 100 } ] [
index f9276fd1a1e71c0935e17973d03ed5ab48e26871..7a8ee65a8b99bbd69163e755f2cadaf8f67e93ce 100644 (file)
@@ -1,7 +1,7 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors io kernel math namespaces
-sequences words math.vectors ui.gadgets ui.gadgets.packs ;
+sequences words math.vectors ui.gadgets ui.gadgets.packs math.geometry.rect ;
 IN: ui.gadgets.tracks
 
 TUPLE: track < pack sizes ;
@@ -47,7 +47,11 @@ M: track pref-dim*
     rot gadget-orientation set-axis ;
 
 : track-add ( gadget track constraint -- )
-    over track-sizes push add-gadget ;
+    over track-sizes push swap add-gadget drop ;
+
+: track-add* ( track gadget constraint -- track )
+    pick sizes>> push
+    add-gadget ;
 
 : track, ( gadget constraint -- )
     gadget get swap track-add ;
index 2e7e130404d4c4f0d3816fbe7f017b2b7c638339..91265abcfacc72373fbc683e06b06df7c3b3e370 100755 (executable)
@@ -2,7 +2,7 @@
 ! See http://factorcode.org/license.txt for BSD license.
 IN: ui.gadgets.viewports
 USING: accessors arrays ui.gadgets ui.gadgets.borders
-kernel math namespaces sequences models math.vectors ;
+kernel math namespaces sequences models math.vectors math.geometry.rect ;
 
 : viewport-gap { 3 3 } ; inline
 
@@ -18,7 +18,7 @@ TUPLE: viewport < gadget ;
     viewport new-gadget
         swap >>model
         t >>clipped?
-        [ add-gadget ] keep ;
+        [ swap add-gadget drop ] keep ;
 
 M: viewport layout*
     dup rect-dim viewport-gap 2 v*n v-
index ea4612cd4eeeebff86828e80c24ca8167bef032d..4ce54c583f16e3cd7fecc8fab7a6776ee67f4baf 100644 (file)
@@ -18,7 +18,7 @@ namespaces models kernel ;
 
 <gadget> "g1" set
 <gadget> "g2" set
-"g1" get "g2" get add-gadget
+"g1" get "g2" get swap add-gadget drop
 
 [ ] [
     "g2" get <test-world> "w" set
@@ -33,8 +33,8 @@ namespaces models kernel ;
 <gadget> "g1" set
 <gadget> "g2" set
 <gadget> "g3" set
-"g1" get "g3" get add-gadget
-"g2" get "g3" get add-gadget
+"g1" get "g3" get swap add-gadget drop
+"g2" get "g3" get swap add-gadget drop
 
 [ ] [
     "g3" get <test-world> "w" set
@@ -55,7 +55,7 @@ TUPLE: focus-test < gadget ;
 
 : <focus-test>
     focus-test new-gadget
-    <focusing> over add-gadget ;
+    <focusing> over swap add-gadget drop ;
 
 M: focus-test focusable-child* gadget-child ;
 
index 7064045cc477fb0d2a2edab33ea880c2c3b58d80..dc4debd90055c5f63ed97f02869fab7618a1de72 100755 (executable)
@@ -3,7 +3,7 @@
 USING: accessors arrays assocs continuations kernel math models
 namespaces opengl sequences io combinators math.vectors
 ui.gadgets ui.gestures ui.render ui.backend ui.gadgets.tracks
-debugger ;
+debugger math.geometry.rect ;
 IN: ui.gadgets.worlds
 
 TUPLE: world < track
index 24fc13a4bee564d4c06cb3fb1ed77a21b5e3a97d..55846b22556d776b90d27f2522c71a461181330b 100644 (file)
@@ -7,7 +7,7 @@ TUPLE: wrapper < gadget ;
 
 : new-wrapper ( child class -- wrapper )
     new-gadget
-        [ add-gadget ] keep ; inline
+        [ swap add-gadget drop ] keep ; inline
 
 : <wrapper> ( child -- border )
     wrapper new-wrapper ;
index d48d7c99d9d595f915188cb51bac3a49f51aff44..0133b7bb1c851b003601cecb84730d9b41b249f9 100755 (executable)
@@ -1,5 +1,5 @@
 USING: ui.gadgets ui.gestures help.markup help.syntax
-kernel classes strings opengl.gl models ;
+kernel classes strings opengl.gl models math.geometry.rect ;
 IN: ui.render
 
 HELP: gadget
index 8f40bec1c3cab84fb5486d73b3f49fcfdbe097fe..6e9a4778a7fe7f9b8d36dbc9371676be7415fb3a 100644 (file)
@@ -2,7 +2,8 @@
 ! See http://factorcode.org/license.txt for BSD license.
 USING: alien arrays hashtables io kernel math namespaces opengl
 opengl.gl opengl.glu sequences strings io.styles vectors
-combinators math.vectors ui.gadgets colors math.order ;
+combinators math.vectors ui.gadgets colors
+math.order math.geometry.rect ;
 IN: ui.render
 
 SYMBOL: clip
index 421ffdbaaf4927618ea71dac78f37c9c83365e77..ee427625f535bca77e4401b16807df04f86c52f6 100755 (executable)
@@ -20,13 +20,11 @@ TUPLE: browser-gadget < track pane history ;
     "handbook" >link <history> >>history drop ;
 
 : <browser-gadget> ( -- gadget )
-    { 0 1 } browser-gadget new-track
+  { 0 1 } browser-gadget new-track
     dup init-history
-    [
-        toolbar,
-        g <help-pane> g-> set-browser-gadget-pane
-        <scroller> 1 track,
-    ] make-gadget ;
+    dup <toolbar> f track-add*
+    dup <help-pane> >>pane
+    dup pane>> <scroller> 1 track-add* ;
 
 M: browser-gadget call-tool* show-help ;
 
index fbf9b28937d17afa0540ad327d2f155e10ed5fbd..6ed98f49647ba72803065cfa6751f5f9830ea542 100644 (file)
@@ -1,12 +1,13 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays ui ui.commands ui.gestures ui.gadgets
-ui.gadgets.worlds ui.gadgets.packs ui.gadgets.buttons
-ui.gadgets.labels ui.gadgets.panes ui.gadgets.presentations
-ui.gadgets.viewports ui.gadgets.lists ui.gadgets.tracks
-ui.gadgets.scrollers ui.gadgets.panes hashtables io kernel math
-models namespaces sequences sequences words continuations
-debugger prettyprint ui.tools.traceback help editors ;
+       ui.gadgets.worlds ui.gadgets.packs ui.gadgets.buttons
+       ui.gadgets.labels ui.gadgets.panes ui.gadgets.presentations
+       ui.gadgets.viewports ui.gadgets.lists ui.gadgets.tracks
+       ui.gadgets.scrollers ui.gadgets.panes hashtables io kernel math
+       models namespaces sequences sequences words continuations
+       debugger prettyprint ui.tools.traceback help editors ;
+
 IN: ui.tools.debugger
 
 : <restart-list> ( restarts restart-hook -- gadget )
@@ -15,18 +16,18 @@ IN: ui.tools.debugger
 TUPLE: debugger < track restarts ;
 
 : <debugger-display> ( restart-list error -- gadget )
-    [
-        <pane> [ [ print-error ] with-pane ] keep gadget,
-        gadget,
-    ] make-filled-pile ;
+    <filled-pile>
+        <pane>
+            swapd tuck [ print-error ] with-pane
+        add-gadget
+
+        swap add-gadget ;
 
 : <debugger> ( error restarts restart-hook -- gadget )
     { 0 1 } debugger new-track
-    [
-        toolbar,
-        <restart-list> g-> set-debugger-restarts
-        swap <debugger-display> <scroller> 1 track,
-    ] make-gadget ;
+        dup <toolbar> f track-add*
+        -rot <restart-list> >>restarts
+        dup restarts>> rot <debugger-display> <scroller> 1 track-add* ;
 
 M: debugger focusable-child* debugger-restarts ;
 
index 3395c95663a45d8e54ea704d5ce61e91be72f067..636323e7a860b4e1f20b6bdff757abd97f1b8412 100755 (executable)
@@ -1,62 +1,65 @@
 ! Copyright (C) 2007 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: ui.gadgets colors kernel ui.render namespaces
-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
-tools.deploy vocabs ui.tools.workspace system accessors ;
+       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
+       tools.deploy vocabs ui.tools.workspace system accessors ;
+
 IN: ui.tools.deploy
 
 TUPLE: deploy-gadget < pack vocab settings ;
 
-: bundle-name ( -- )
+: bundle-name ( parent -- parent )
     deploy-name get <field>
-    "Executable name:" label-on-left gadget, ;
+    "Executable name:" label-on-left add-gadget ;
 
-: deploy-ui ( -- )
+: deploy-ui ( parent -- parent )
     deploy-ui? get
-    "Include user interface framework" <checkbox> gadget, ;
+    "Include user interface framework" <checkbox> add-gadget ;
 
-: exit-when-windows-closed ( -- )
+: exit-when-windows-closed ( parent -- parent )
     "stop-after-last-window?" get
-    "Exit when last UI window closed" <checkbox> gadget, ;
-
-: io-settings ( -- )
-    "Input/output support:" <label> gadget,
-    deploy-io get deploy-io-options <radio-buttons> gadget, ;
-
-: reflection-settings ( -- )
-    "Reflection support:" <label> gadget,
-    deploy-reflection get deploy-reflection-options <radio-buttons> gadget, ;
-
-: advanced-settings ( -- )
-    "Advanced:" <label> gadget,
-    deploy-compiler? get "Use optimizing compiler" <checkbox> gadget,
-    deploy-math? get "Rational and complex number support" <checkbox> gadget,
-    deploy-threads? get "Threading support" <checkbox> gadget,
-    deploy-random? get "Random number generator support" <checkbox> gadget,
-    deploy-word-props? get "Retain all word properties" <checkbox> gadget,
-    deploy-word-defs? get "Retain all word definitions" <checkbox> gadget,
-    deploy-c-types? get "Retain all C types" <checkbox> gadget, ;
-
-: deploy-settings-theme ( gadget -- )
-    { 10 10 } >>gap
-    1 >>fill
-    drop ;
+    "Exit when last UI window closed" <checkbox> add-gadget ;
+
+: io-settings ( parent -- parent )
+    "Input/output support:" <label> add-gadget
+    deploy-io get deploy-io-options <radio-buttons> add-gadget ;
+
+: reflection-settings ( parent -- parent )
+    "Reflection support:" <label> add-gadget
+    deploy-reflection get deploy-reflection-options <radio-buttons> add-gadget ;
+
+: advanced-settings ( parent -- parent )
+    "Advanced:" <label> add-gadget
+    deploy-compiler? get "Use optimizing compiler" <checkbox> add-gadget
+    deploy-math? get "Rational and complex number support" <checkbox> add-gadget
+    deploy-threads? get "Threading support" <checkbox> add-gadget
+    deploy-random? get "Random number generator support" <checkbox> add-gadget
+    deploy-word-props? get "Retain all word properties" <checkbox> add-gadget
+    deploy-word-defs? get "Retain all word definitions" <checkbox> add-gadget
+    deploy-c-types? get "Retain all C types" <checkbox> add-gadget ;
+
+: deploy-settings-theme ( gadget -- gadget )
+  { 10 10 } >>gap
+  1         >>fill ;
 
 : <deploy-settings> ( vocab -- control )
-    default-config [ <model> ] assoc-map [
+    default-config [ <model> ] assoc-map
         [
+            <pile>
             bundle-name
             deploy-ui
             os macosx? [ exit-when-windows-closed ] when
             io-settings
             reflection-settings
             advanced-settings
-        ] make-pile dup deploy-settings-theme
-        namespace <mapping> over set-gadget-model
-    ] bind ;
+
+            deploy-settings-theme
+            namespace <mapping> over set-gadget-model
+        ]
+    bind ;
 
 : find-deploy-gadget ( gadget -- deploy-gadget )
     [ deploy-gadget? ] find-parent ;
@@ -101,21 +104,16 @@ deploy-gadget "toolbar" f {
     { T{ key-down f f "RET" } com-deploy }
 } define-command-map
 
-: buttons, ( -- )
-    g <toolbar> { 10 10 } over set-pack-gap gadget, ;
-
 : <deploy-gadget> ( vocab -- gadget )
     deploy-gadget new-gadget
-        swap >>vocab
-        { 0 1 } >>orientation
-    [
-        g vocab>> <deploy-settings>
-        g-> set-deploy-gadget-settings gadget,
-        buttons,
-    ] make-gadget
-    dup deploy-settings-theme
+      over                           >>vocab
+      { 0 1 }                        >>orientation
+      swap <deploy-settings>         >>settings    
+      dup settings>>                 add-gadget
+      dup <toolbar> { 10 10 } >>gap  add-gadget
+    deploy-settings-theme
     dup com-revert ;
-
+    
 : deploy-tool ( vocab -- )
     vocab-name dup <deploy-gadget> 10 <border>
     "Deploying \"" rot "\"" 3append open-window ;
index 4aaf31881e58468efdea77112d8fe50b6f1af5b8..1d17de723785dcfb9f26a7e4fee1b633e3a60054 100644 (file)
@@ -1,6 +1,6 @@
-! Copyright (C) 2006, 2007 Slava Pestov.
+! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: ui.tools.workspace inspector kernel ui.commands
+USING: accessors ui.tools.workspace inspector kernel ui.commands
 ui.gadgets ui.gadgets.panes ui.gadgets.scrollers
 ui.gadgets.slots ui.gadgets.tracks ui.gestures
 ui.gadgets.buttons namespaces ;
@@ -9,8 +9,10 @@ IN: ui.tools.inspector
 TUPLE: inspector-gadget < track object pane ;
 
 : refresh ( inspector -- )
-    dup inspector-gadget-object swap inspector-gadget-pane [
-        H{ { +editable+ t } { +number-rows+ t } } describe*
+    [ object>> ] [ pane>> ] bi [
+        +editable+ on
+        +number-rows+ on
+        describe
     ] with-pane ;
 
 : <inspector-gadget> ( -- gadget )
@@ -20,16 +22,14 @@ TUPLE: inspector-gadget < track object pane ;
         <pane> g-> set-inspector-gadget-pane <scroller> 1 track,
     ] make-gadget ;
 
-: inspect-object ( obj inspector -- )
-    [ set-inspector-gadget-object ] keep refresh ;
+: inspect-object ( obj mirror keys inspector -- )
+    2nip swap >>object refresh ;
 
 \ &push H{ { +nullary+ t } { +listener+ t } } define-command
 
 \ &back H{ { +nullary+ t } { +listener+ t } } define-command
 
-: globals ( -- ) global inspect ;
-
-\ globals H{ { +nullary+ t } { +listener+ t } } define-command
+\ &globals H{ { +nullary+ t } { +listener+ t } } define-command
 
 : inspector-help ( -- ) "ui-inspector" help-window ;
 
@@ -39,7 +39,7 @@ inspector-gadget "toolbar" f {
     { T{ update-object } refresh }
     { f &push }
     { f &back }
-    { f globals }
+    { f &globals }
     { T{ key-down f f "F1" } inspector-help }
 } define-command-map
 
index 1d8f16de5a2d5a1f135320186b3892cf19ce9047..0a8fe92762b52ed24396874a060eb68390d5bbfe 100755 (executable)
@@ -47,12 +47,12 @@ search-field H{
     { T{ key-down f f "RET" } [ find-search-list invoke-value-action ] }
 } set-gestures
 
-: <search-model> ( producer -- model )
-    >r g live-search-field gadget-model
+: <search-model> ( live-search producer -- live-search filter )
+    >r dup field>> model>>                   ! live-search model :: producer
     ui-running? [ 1/5 seconds <delay> ] when
     [ "\n" join ] r> append <filter> ;
 
-: <search-list> ( seq limited? presenter -- gadget )
+: <search-list> ( live-search seq limited? presenter -- live-search list )
     >r
     [ limited-completions ] [ completions ] ? curry
     <search-model>
@@ -60,14 +60,15 @@ search-field H{
     swap <list> ;
 
 : <live-search> ( string seq limited? presenter -- gadget )
-    { 0 1 } live-search new-track
-    [
-        <search-field> g-> set-live-search-field f track,
-        <search-list> g-> set-live-search-list
-        <scroller> 1 track,
-    ] make-gadget
-    [ live-search-field set-editor-string ] keep
-    [ live-search-field end-of-document ] keep ;
+  { 0 1 } live-search new-track
+    <search-field> >>field
+    dup field>> f track-add*
+    -roll <search-list> >>list
+    dup list>> <scroller> 1 track-add*
+
+  swap                         
+    over field>> set-editor-string
+  dup field>> end-of-document ;
 
 M: live-search focusable-child* live-search-field ;
 
index e1743a4bc835819f21ea66ea8fe8ad39919552a3..ffea85742969ba095280fb4a668a6faefbed57d3 100755 (executable)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2006, 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors continuations kernel models namespaces
-prettyprint ui ui.commands ui.gadgets ui.gadgets.labelled assocs
-ui.gadgets.tracks ui.gadgets.buttons ui.gadgets.panes
-ui.gadgets.status-bar ui.gadgets.scrollers ui.gestures sequences
-hashtables inspector ;
+       prettyprint ui ui.commands ui.gadgets ui.gadgets.labelled assocs
+       ui.gadgets.tracks ui.gadgets.buttons ui.gadgets.panes
+       ui.gadgets.status-bar ui.gadgets.scrollers ui.gestures sequences
+       hashtables inspector ;
+
 IN: ui.tools.traceback
 
 : <callstack-display> ( model -- gadget )
@@ -24,20 +25,18 @@ TUPLE: traceback-gadget < track ;
 M: traceback-gadget pref-dim* drop { 550 600 } ;
 
 : <traceback-gadget> ( model -- gadget )
-    { 0 1 } traceback-gadget new-track
-        swap >>model
-    [
-        g model>>
-        [
-            [
-                [ <datastack-display> 1/2 track, ]
-                [ <retainstack-display> 1/2 track, ]
-                bi
-            ] { 1 0 } make-track 1/3 track,
-        ]
-        [ <callstack-display> 2/3 track, ] bi
-        toolbar,
-    ] make-gadget ;
+  { 0 1 } traceback-gadget new-track
+    swap >>model
+
+    dup model>>
+      { 1 0 } <track>
+        over <datastack-display>   1/2 track-add*
+        swap <retainstack-display> 1/2 track-add*
+      1/3 track-add*
+
+    dup model>> <callstack-display> 2/3 track-add*
+
+    dup <toolbar> f track-add* ;
 
 : <namestack-display> ( model -- gadget )
     [ [ continuation-name namestack. ] when* ]
index 3588b446441ea28efc0dc5c99d8dd47fd2948282..e5141fb8441a990af5931bb3712f9bdc2b76e33a 100755 (executable)
@@ -61,12 +61,11 @@ M: walker-gadget focusable-child*
         swap >>continuation
         swap >>status
         dup continuation>> <traceback-gadget> >>traceback
-    [
-        toolbar,
-        g status>> self <thread-status> f track,
-        g traceback>> 1 track,
-    ] make-gadget ;
 
+        dup <toolbar>                     f track-add*
+        dup status>> self <thread-status> f track-add*
+        dup traceback>>                   1 track-add* ;
+    
 : walker-help ( -- ) "ui-walker" help-window ;
 
 \ walker-help H{ { +nullary+ t } } define-command
index 1a541090c5907f75746516516a342c1ad39ed949..172c57061ce5aa7a6271711703fd58b9c245e399 100755 (executable)
@@ -1,6 +1,6 @@
 USING: help.markup help.syntax strings quotations debugger
 io.styles namespaces ui.backend ui.gadgets ui.gadgets.worlds
-ui.gadgets.tracks ui.gadgets.packs ui.gadgets.grids ;
+ui.gadgets.tracks ui.gadgets.packs ui.gadgets.grids math.geometry.rect ;
 IN: ui
 
 HELP: windows
@@ -235,7 +235,7 @@ $nl
 $nl
 "Gadget construction combinators whose names are prefixed with " { $snippet "make-" } " construct new gadgets and push them on the stack. The primitive combinator used to define all combinators of this form:"
 { $subsection make-gadget }
-"Words such as " { $link gadget, } " and " { $link track, } " access the gadget through the " { $link gadget } " variable."
+"Words such as " { $link track, } " access the gadget through the " { $link gadget } " variable."
 $nl
 "A combinator which stores a gadget in the " { $link gadget } " variable:"
 { $subsection with-gadget }
index 231dd7f8a59c17edd009cf5474b3e57847a56199..a210287439c599925ff559266eb9f526d5883d60 100755 (executable)
@@ -8,7 +8,7 @@ sequences strings vectors words windows.kernel32 windows.gdi32
 windows.user32 windows.opengl32 windows.messages windows.types
 windows.nt windows threads libc combinators continuations
 command-line shuffle opengl ui.render unicode.case ascii
-math.bitfields locals symbols accessors ;
+math.bitfields locals symbols accessors math.geometry.rect ;
 IN: ui.windows
 
 SINGLETON: windows-ui-backend
index 35f22ec64f061a81c9e362a42750d0709bc6c155..b75daf89fa8da606c4bbfd537f88c5b645f53ce2 100755 (executable)
@@ -6,7 +6,7 @@ assocs kernel math namespaces opengl sequences strings x11.xlib
 x11.events x11.xim x11.glx x11.clipboard x11.constants
 x11.windows io.encodings.string io.encodings.ascii
 io.encodings.utf8 combinators debugger command-line qualified
-math.vectors classes.tuple opengl.gl threads ;
+math.vectors classes.tuple opengl.gl threads math.geometry.rect ;
 QUALIFIED: system
 IN: ui.x11
 
index fb392542f3dd160d303c76c1df47620c73126a3e..968bf9d053fd636ef255d1815bf2bcb39b92bb15 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: io.files io.encodings.ascii sequences sequences.lib
+USING: io.files io.encodings.ascii sequences generalizations
 math.parser combinators kernel memoize csv symbols summary
 words accessors math.order sorting ;
 IN: usa-cities
index 7daba37063939ee4d2479999f006770ffd306a77..0e74dcfca3dc1a5de10263d0333272395ed3a7d4 100755 (executable)
@@ -10,6 +10,7 @@ TYPEDEF: void* LPUNKNOWN
 TYPEDEF: wchar_t* LPOLESTR
 TYPEDEF: wchar_t* LPCOLESTR
 
+TYPEDEF: REFGUID LPGUID
 TYPEDEF: REFGUID REFIID
 TYPEDEF: REFGUID REFCLSID
 
index 69ffdeb2aa2a1fdb45b883c3827c375871d8e8d9..1435caa9d2caf659cd76e00ac561d3eaccb1fb0d 100755 (executable)
@@ -63,6 +63,8 @@ INLINE CELL compute_code_rel(F_REL *rel,
                return (CELL)get_rel_symbol(rel,literals_start);
        case RT_LITERAL:
                return CREF(literals_start,REL_ARGUMENT(rel));
+       case RT_IMMEDIATE:
+               return get(CREF(literals_start,REL_ARGUMENT(rel)));
        case RT_XT:
                return (CELL)untag_word(get(CREF(literals_start,REL_ARGUMENT(rel))))->xt;
        case RT_HERE:
index 80605b1d28164d04a5393d9990d86225d0cae9a1..c3b476c4b53dc111bc19b06882ff22ba633baa79 100755 (executable)
@@ -12,7 +12,9 @@ typedef enum {
        /* current offset */
        RT_HERE,
        /* a local label */
-       RT_LABEL
+       RT_LABEL,
+       /* immeditae literal */
+       RT_IMMEDIATE
 } F_RELTYPE;
 
 typedef enum {
index 55c4f01df07ea65c4ab41a4a9c7ae2f14730d44f..412e277ea6e2085bbf4a26c9180332c9d0b515b0 100755 (executable)
@@ -103,20 +103,6 @@ DEF(void,c_to_factor,(CELL quot)):
         EPILOGUE
         blr
 
-/* We must pass the XT to the quotation in r11. */
-DEF(void,primitive_call,(void)):
-        lwz r3,0(r14)      /* load quotation from data stack */
-        subi r14,r14,4     /* pop quotation from data stack */
-        JUMP_QUOT
-
-/* We must preserve r4 here in case we're calling a primitive */
-DEF(void,primitive_execute,(void)):
-        lwz r3,0(r14)      /* load word from data stack */
-        lwz r11,29(r3)     /* load word-xt slot */
-        mtctr r11          /* prepare to call XT */
-        subi r14,r14,4     /* pop word from data stack */
-        bctr               /* go */
-
 /* We pass a function pointer to memcpy in r6 to work around a Mac OS X ABI
 limitation which would otherwise require us to do a bizzaro PC-relative
 trampoline to retrieve the function address */
index 6233b4a14f22812af88ac9829fe9db9a650a0576..b1a356197486aabcde1020bbb3d43c26cfc57bc3 100644 (file)
@@ -6,7 +6,6 @@ and the callstack top is passed in EDX */
 
 #define ARG0 %eax
 #define ARG1 %edx
-#define XT_REG %ecx
 #define STACK_REG %esp
 #define DS_REG %esi
 #define RETURN_REG %eax
@@ -22,9 +21,6 @@ and the callstack top is passed in EDX */
        pop %ebx
 
 #define QUOT_XT_OFFSET 9
-#define PROFILING_OFFSET 25
-#define WORD_DEF_OFFSET 13
-#define WORD_XT_OFFSET 29
 
 /* We pass a function pointer to memcpy to work around a Mac OS X
 ABI limitation which would otherwise require us to do a bizzaro PC-relative
index 4e8faa18de1903baa7028dd538cd3090e3c0ebec..57bfcee87b7e1fb8f732a780b2d8f2ec2eb73129 100644 (file)
@@ -2,7 +2,6 @@
 
 #define ARG0 %rdi
 #define ARG1 %rsi
-#define XT_REG %rcx
 #define STACK_REG %rsp
 #define DS_REG %r14
 #define RETURN_REG %rax
@@ -22,9 +21,6 @@
        pop %rbx
 
 #define QUOT_XT_OFFSET 21
-#define PROFILING_OFFSET 53
-#define WORD_DEF_OFFSET 29
-#define WORD_XT_OFFSET 61
 
 /* We pass a function pointer to memcpy to work around a Mac OS X
 ABI limitation which would otherwise require us to do a bizzaro PC-relative
index 5c0a105a55cd34c89de726a4bbdcfd2ca225a761..e8e2af7b25ba6464a29e10d8a0991d87f034c554 100755 (executable)
@@ -1,5 +1,3 @@
-#define JUMP_QUOT jmp *QUOT_XT_OFFSET(ARG0)
-
 DEF(F_FASTCALL void,c_to_factor,(CELL quot)):
        PUSH_NONVOLATILE
        push ARG0                             /* Save quot */
@@ -14,20 +12,9 @@ DEF(F_FASTCALL void,c_to_factor,(CELL quot)):
        POP_NONVOLATILE
        ret
 
-DEF(F_FASTCALL void,primitive_call,(void)):
-        mov (DS_REG),ARG0                     /* Load quotation from data stack */
-       sub $CELL_SIZE,DS_REG                 /* Pop data stack */
-       JUMP_QUOT
-
-/* Don't mess up EDX, it's the callstack top parameter to primitives. */
-DEF(F_FASTCALL void,primitive_execute,(void)):
-       mov (DS_REG),ARG0                     /* Load word from data stack */
-       sub $CELL_SIZE,DS_REG                 /* Pop data stack */
-        jmp *WORD_XT_OFFSET(ARG0)             /* Load word-xt slot */
-
 DEF(F_FASTCALL void,throw_impl,(CELL quot, F_STACK_FRAME *rewind_to)):
        mov ARG1,STACK_REG                    /* rewind_to */
-       JUMP_QUOT
+       jmp *QUOT_XT_OFFSET(ARG0)
 
 DEF(FASTCALL void,lazy_jit_compile,(CELL quot)):
        mov STACK_REG,ARG1           /* Save stack pointer */
@@ -39,7 +26,7 @@ DEF(FASTCALL void,lazy_jit_compile,(CELL quot)):
        pop ARG1                     /* OK to clobber ARG1 here */
        pop ARG1
        pop ARG1
-        JUMP_QUOT                    /* Call the quotation */
+        jmp *QUOT_XT_OFFSET(ARG0)    /* Call the quotation */
 
 #ifdef WINDOWS
        .section .drectve
index 06a37672a79a514229d9e5aca8e0ba35ce273abc..7ebfe50dd4be09ea60d604d50893ab06f3983afb 100755 (executable)
@@ -129,6 +129,8 @@ typedef struct {
        CELL compiledp;
        /* TAGGED call count for profiling */
        CELL counter;
+       /* TAGGED machine code for sub-primitive */
+       CELL subprimitive;
        /* UNTAGGED execution token: jump here to execute word */
        XT xt;
        /* UNTAGGED compiled code block */
index 8c4e7d537ad0e098426e369d7443898b37aa47b4..c1e13951dca223d5b24c70ff507f62c592f06621 100644 (file)
--- a/vm/math.c
+++ b/vm/math.c
@@ -35,33 +35,18 @@ DEFINE_PRIMITIVE(float_to_fixnum)
        F_FIXNUM y = untag_fixnum_fast(dpop()); \
        F_FIXNUM x = untag_fixnum_fast(dpop());
 
-/* The fixnum arithmetic operations defined in C are relatively slow.
-The Factor compiler has optimized assembly intrinsics for some of these
-operations. */
 DEFINE_PRIMITIVE(fixnum_add)
 {
        POP_FIXNUMS(x,y)
        box_signed_cell(x + y);
 }
 
-DEFINE_PRIMITIVE(fixnum_add_fast)
-{
-       POP_FIXNUMS(x,y)
-       dpush(tag_fixnum(x + y));
-}
-
 DEFINE_PRIMITIVE(fixnum_subtract)
 {
        POP_FIXNUMS(x,y)
        box_signed_cell(x - y);
 }
 
-DEFINE_PRIMITIVE(fixnum_subtract_fast)
-{
-       POP_FIXNUMS(x,y)
-       dpush(tag_fixnum(x - y));
-}
-
 /* Multiply two integers, and trap overflow.
 Thanks to David Blaikie (The_Vulture from freenode #java) for the hint. */
 DEFINE_PRIMITIVE(fixnum_multiply)
@@ -87,12 +72,6 @@ DEFINE_PRIMITIVE(fixnum_multiply)
        }
 }
 
-DEFINE_PRIMITIVE(fixnum_multiply_fast)
-{
-       POP_FIXNUMS(x,y)
-       dpush(tag_fixnum(x * y));
-}
-
 DEFINE_PRIMITIVE(fixnum_divint)
 {
        POP_FIXNUMS(x,y)
@@ -112,24 +91,6 @@ DEFINE_PRIMITIVE(fixnum_mod)
        dpush(tag_fixnum(x % y));
 }
 
-DEFINE_PRIMITIVE(fixnum_and)
-{
-       POP_FIXNUMS(x,y)
-       dpush(tag_fixnum(x & y));
-}
-
-DEFINE_PRIMITIVE(fixnum_or)
-{
-       POP_FIXNUMS(x,y)
-       dpush(tag_fixnum(x | y));
-}
-
-DEFINE_PRIMITIVE(fixnum_xor)
-{
-       POP_FIXNUMS(x,y)
-       dpush(tag_fixnum(x ^ y));
-}
-
 /*
  * Note the hairy overflow check.
  * If we're shifting right by n bits, we won't overflow as long as none of the
@@ -172,35 +133,6 @@ DEFINE_PRIMITIVE(fixnum_shift_fast)
        dpush(tag_fixnum(y < 0 ? (x >> -y) : (x << y)));
 }
 
-DEFINE_PRIMITIVE(fixnum_less)
-{
-       POP_FIXNUMS(x,y)
-       box_boolean(x < y);
-}
-
-DEFINE_PRIMITIVE(fixnum_lesseq)
-{
-       POP_FIXNUMS(x,y)
-       box_boolean(x <= y);
-}
-
-DEFINE_PRIMITIVE(fixnum_greater)
-{
-       POP_FIXNUMS(x,y)
-       box_boolean(x > y);
-}
-
-DEFINE_PRIMITIVE(fixnum_greatereq)
-{
-       POP_FIXNUMS(x,y)
-       box_boolean(x >= y);
-}
-
-DEFINE_PRIMITIVE(fixnum_not)
-{
-       drepl(tag_fixnum(~untag_fixnum_fast(dpeek())));
-}
-
 /* Bignums */
 DEFINE_PRIMITIVE(fixnum_to_bignum)
 {
index d82a373571445c2d803c00cb73c540de6e6d6d78..6f81ece8a8c452cdc8f611021e45150761d60239 100644 (file)
--- a/vm/math.h
+++ b/vm/math.h
@@ -11,23 +11,12 @@ DECLARE_PRIMITIVE(float_to_fixnum);
 
 DECLARE_PRIMITIVE(fixnum_add);
 DECLARE_PRIMITIVE(fixnum_subtract);
-DECLARE_PRIMITIVE(fixnum_add_fast);
-DECLARE_PRIMITIVE(fixnum_subtract_fast);
 DECLARE_PRIMITIVE(fixnum_multiply);
-DECLARE_PRIMITIVE(fixnum_multiply_fast);
 DECLARE_PRIMITIVE(fixnum_divint);
 DECLARE_PRIMITIVE(fixnum_divmod);
 DECLARE_PRIMITIVE(fixnum_mod);
-DECLARE_PRIMITIVE(fixnum_and);
-DECLARE_PRIMITIVE(fixnum_or);
-DECLARE_PRIMITIVE(fixnum_xor);
 DECLARE_PRIMITIVE(fixnum_shift);
 DECLARE_PRIMITIVE(fixnum_shift_fast);
-DECLARE_PRIMITIVE(fixnum_less);
-DECLARE_PRIMITIVE(fixnum_lesseq);
-DECLARE_PRIMITIVE(fixnum_greater);
-DECLARE_PRIMITIVE(fixnum_greatereq);
-DECLARE_PRIMITIVE(fixnum_not);
 
 CELL bignum_zero;
 CELL bignum_pos_one;
index d670b41897be95e4b46e7ee8dde76611e10d5629..b5d9403342b25313265268c32874a093e0c8989a 100755 (executable)
@@ -1,8 +1,6 @@
 #include "master.h"
 
 void *primitives[] = {
-       primitive_execute,
-       primitive_call,
        primitive_bignum_to_fixnum,
        primitive_float_to_fixnum,
        primitive_fixnum_to_bignum,
@@ -18,24 +16,13 @@ void *primitives[] = {
        primitive_bits_double,
        primitive_from_rect,
        primitive_fixnum_add,
-       primitive_fixnum_add_fast,
        primitive_fixnum_subtract,
-       primitive_fixnum_subtract_fast,
        primitive_fixnum_multiply,
-       primitive_fixnum_multiply_fast,
        primitive_fixnum_divint,
        primitive_fixnum_mod,
        primitive_fixnum_divmod,
-       primitive_fixnum_and,
-       primitive_fixnum_or,
-       primitive_fixnum_xor,
-       primitive_fixnum_not,
        primitive_fixnum_shift,
        primitive_fixnum_shift_fast,
-       primitive_fixnum_less,
-       primitive_fixnum_lesseq,
-       primitive_fixnum_greater,
-       primitive_fixnum_greatereq,
        primitive_bignum_eq,
        primitive_bignum_add,
        primitive_bignum_subtract,
@@ -67,25 +54,6 @@ void *primitives[] = {
        primitive_float_greatereq,
        primitive_word,
        primitive_word_xt,
-       primitive_drop,
-       primitive_2drop,
-       primitive_3drop,
-       primitive_dup,
-       primitive_2dup,
-       primitive_3dup,
-       primitive_rot,
-       primitive__rot,
-       primitive_dupd,
-       primitive_swapd,
-       primitive_nip,
-       primitive_2nip,
-       primitive_tuck,
-       primitive_over,
-       primitive_pick,
-       primitive_swap,
-       primitive_to_r,
-       primitive_from_r,
-       primitive_eq,
        primitive_getenv,
        primitive_setenv,
        primitive_existsp,
@@ -105,7 +73,6 @@ void *primitives[] = {
        primitive_code_room,
        primitive_os_env,
        primitive_millis,
-       primitive_tag,
        primitive_modify_code_heap,
        primitive_dlopen,
        primitive_dlsym,
@@ -140,7 +107,6 @@ void *primitives[] = {
        primitive_set_alien_cell,
        primitive_throw,
        primitive_alien_address,
-       primitive_slot,
        primitive_set_slot,
        primitive_string_nth,
        primitive_set_string_nth,
index 7eab41688a389585f1dead4dcc4b0ba6f4a8ca38..b75d3f79e00c6776c3964cd7cec72ffe05e3ca95 100755 (executable)
@@ -1,8 +1,37 @@
 #include "master.h"
 
-/* Simple JIT compiler. This is one of the two compilers implementing Factor;
-the second one is written in Factor and performs a lot of optimizations.
-See core/compiler/compiler.factor */
+/* Simple non-optimizing compiler.
+
+This is one of the two compilers implementing Factor; the second one is written
+in Factor and performs advanced optimizations. See core/compiler/compiler.factor.
+
+The non-optimizing compiler compiles a quotation at a time by concatenating
+machine code chunks; prolog, epilog, call word, jump to word, etc. These machine
+code chunks are generated from Factor code in core/cpu/.../bootstrap.factor.
+
+It actually does do a little bit of very simple optimization:
+
+1) Tail call optimization.
+
+2) If a quotation is determined to not call any other words (except for a few
+special words which are open-coded, see below), then no prolog/epilog is
+generated.
+
+3) When in tail position and immediately preceded by literal arguments, the
+'if' and 'dispatch' conditionals are generated inline, instead of as a call to
+the 'if' word.
+
+4) When preceded by an array, calls to the 'declare' word are optimized out
+entirely. This word is only used by the optimizing compiler, and with the
+non-optimizing compiler it would otherwise just decrease performance to have to
+push the array and immediately drop it after.
+
+5) Sub-primitives are primitive words which are implemented in assembly and not
+in the VM. They are open-coded and no subroutine call is generated. This
+includes stack shufflers, some fixnum arithmetic words, and words such as tag,
+slot and eq?. A primitive call is relatively expensive (two subroutine calls)
+so this results in a big speedup for relatively little effort. */
+
 bool jit_primitive_call_p(F_ARRAY *array, CELL i)
 {
        return (i + 2) == array_capacity(array)
@@ -32,15 +61,15 @@ bool jit_ignore_declare_p(F_ARRAY *array, CELL i)
                && array_nth(array,i + 1) == userenv[JIT_DECLARE_WORD];
 }
 
-F_ARRAY *code_to_emit(CELL name)
+F_ARRAY *code_to_emit(CELL code)
 {
-       return untag_object(array_nth(untag_object(userenv[name]),0));
+       return untag_object(array_nth(untag_object(code),0));
 }
 
-F_REL rel_to_emit(CELL name, CELL code_format, CELL code_length,
+F_REL rel_to_emit(CELL code, CELL code_format, CELL code_length,
        CELL rel_argument, bool *rel_p)
 {
-       F_ARRAY *quadruple = untag_object(userenv[name]);
+       F_ARRAY *quadruple = untag_object(code);
        CELL rel_class = array_nth(quadruple,1);
        CELL rel_type = array_nth(quadruple,2);
        CELL offset = array_nth(quadruple,3);
@@ -82,20 +111,9 @@ bool jit_stack_frame_p(F_ARRAY *array)
                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])
-                       {
+                       F_WORD *word = untag_object(obj);
+                       if(word->subprimitive == F && obj != userenv[JIT_DECLARE_WORD])
                                return true;
-                       }
                }
        }
 
@@ -139,7 +157,7 @@ void jit_compile(CELL quot, bool relocate)
        bool stack_frame = jit_stack_frame_p(untag_object(array));
 
        if(stack_frame)
-               EMIT(JIT_PROLOG,0);
+               EMIT(userenv[JIT_PROLOG],0);
 
        CELL i;
        CELL length = array_capacity(untag_object(array));
@@ -154,84 +172,44 @@ void jit_compile(CELL quot, bool relocate)
                switch(type_of(obj))
                {
                case WORD_TYPE:
+                       word = untag_object(obj);
+
                        /* Intrinsics */
-                       if(obj == userenv[JIT_TAG_WORD])
+                       if(word->subprimitive != F)
                        {
-                               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);
+                               if(array_nth(untag_object(word->subprimitive),1) != F)
+                               {
+                                       GROWABLE_ARRAY_ADD(literals,T);
+                               }
+
+                               EMIT(word->subprimitive,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));
 
                                if(i == length - 1)
                                {
                                        if(stack_frame)
-                                               EMIT(JIT_EPILOG,0);
+                                               EMIT(userenv[JIT_EPILOG],0);
 
-                                       EMIT(JIT_WORD_JUMP,literals_count - 1);
+                                       EMIT(userenv[JIT_WORD_JUMP],literals_count - 1);
 
                                        tail_call = true;
                                }
                                else
-                                       EMIT(JIT_WORD_CALL,literals_count - 1);
+                                       EMIT(userenv[JIT_WORD_CALL],literals_count - 1);
                        }
                        break;
                case WRAPPER_TYPE:
                        wrapper = untag_object(obj);
                        GROWABLE_ARRAY_ADD(literals,wrapper->object);
-                       EMIT(JIT_PUSH_LITERAL,literals_count - 1);
+                       EMIT(userenv[JIT_PUSH_LITERAL],literals_count - 1);
                        break;
                case FIXNUM_TYPE:
                        if(jit_primitive_call_p(untag_object(array),i))
                        {
-                               EMIT(JIT_PRIMITIVE,to_fixnum(obj));
+                               EMIT(userenv[JIT_PRIMITIVE],to_fixnum(obj));
 
                                i++;
 
@@ -242,11 +220,11 @@ void jit_compile(CELL quot, bool relocate)
                        if(jit_fast_if_p(untag_object(array),i))
                        {
                                if(stack_frame)
-                                       EMIT(JIT_EPILOG,0);
+                                       EMIT(userenv[JIT_EPILOG],0);
 
                                GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
                                GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i + 1));
-                               EMIT(JIT_IF_JUMP,literals_count - 2);
+                               EMIT(userenv[JIT_IF_JUMP],literals_count - 2);
 
                                i += 2;
 
@@ -257,10 +235,10 @@ void jit_compile(CELL quot, bool relocate)
                        if(jit_fast_dispatch_p(untag_object(array),i))
                        {
                                if(stack_frame)
-                                       EMIT(JIT_EPILOG,0);
+                                       EMIT(userenv[JIT_EPILOG],0);
 
                                GROWABLE_ARRAY_ADD(literals,array_nth(untag_object(array),i));
-                               EMIT(JIT_DISPATCH,literals_count - 1);
+                               EMIT(userenv[JIT_DISPATCH],literals_count - 1);
 
                                i++;
 
@@ -274,7 +252,7 @@ void jit_compile(CELL quot, bool relocate)
                        }
                default:
                        GROWABLE_ARRAY_ADD(literals,obj);
-                       EMIT(JIT_PUSH_LITERAL,literals_count - 1);
+                       EMIT(userenv[immediate_p(obj) ? JIT_PUSH_IMMEDIATE : JIT_PUSH_LITERAL],literals_count - 1);
                        break;
                }
        }
@@ -282,9 +260,9 @@ void jit_compile(CELL quot, bool relocate)
        if(!tail_call)
        {
                if(stack_frame)
-                       EMIT(JIT_EPILOG,0);
+                       EMIT(userenv[JIT_EPILOG],0);
 
-               EMIT(JIT_RETURN,0);
+               EMIT(userenv[JIT_RETURN],0);
        }
 
        GROWABLE_ARRAY_TRIM(code);
@@ -330,7 +308,7 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
        bool stack_frame = jit_stack_frame_p(untag_object(array));
 
        if(stack_frame)
-               COUNT(JIT_PROLOG,0)
+               COUNT(userenv[JIT_PROLOG],0)
 
        CELL i;
        CELL length = array_capacity(untag_object(array));
@@ -339,55 +317,34 @@ 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:
                        /* 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
+                       word = untag_object(obj);
+                       if(word->subprimitive != F)
+                               COUNT(word->subprimitive,i)
+                       else if(i == length - 1)
                        {
-                               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)
+                               if(stack_frame)
+                                       COUNT(userenv[JIT_EPILOG],i);
+
+                               COUNT(userenv[JIT_WORD_JUMP],i)
+
+                               tail_call = true;
                        }
+                       else
+                               COUNT(userenv[JIT_WORD_CALL],i)
                        break;
                case WRAPPER_TYPE:
-                       COUNT(JIT_PUSH_LITERAL,i)
+                       COUNT(userenv[JIT_PUSH_LITERAL],i)
                        break;
                case FIXNUM_TYPE:
                        if(jit_primitive_call_p(untag_object(array),i))
                        {
-                               COUNT(JIT_PRIMITIVE,i);
+                               COUNT(userenv[JIT_PRIMITIVE],i);
 
                                i++;
 
@@ -398,11 +355,11 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
                        if(jit_fast_if_p(untag_object(array),i))
                        {
                                if(stack_frame)
-                                       COUNT(JIT_EPILOG,i)
+                                       COUNT(userenv[JIT_EPILOG],i)
 
                                i += 2;
 
-                               COUNT(JIT_IF_JUMP,i)
+                               COUNT(userenv[JIT_IF_JUMP],i)
 
                                tail_call = true;
                                break;
@@ -411,11 +368,11 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
                        if(jit_fast_dispatch_p(untag_object(array),i))
                        {
                                if(stack_frame)
-                                       COUNT(JIT_EPILOG,i)
+                                       COUNT(userenv[JIT_EPILOG],i)
 
                                i++;
 
-                               COUNT(JIT_DISPATCH,i)
+                               COUNT(userenv[JIT_DISPATCH],i)
 
                                tail_call = true;
                                break;
@@ -429,7 +386,7 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
                                break;
                        }
                default:
-                       COUNT(JIT_PUSH_LITERAL,i)
+                       COUNT(userenv[immediate_p(obj) ? JIT_PUSH_IMMEDIATE : JIT_PUSH_LITERAL],i)
                        break;
                }
        }
@@ -437,9 +394,9 @@ F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
        if(!tail_call)
        {
                if(stack_frame)
-                       COUNT(JIT_EPILOG,length)
+                       COUNT(userenv[JIT_EPILOG],length)
 
-               COUNT(JIT_RETURN,length)
+               COUNT(userenv[JIT_RETURN],length)
        }
 
        return -1;
index ae0c91d9e610f827e7d918a5afbb59e7968c94dd..c4a3e115c13708c336a67cf6c7677ee3458c248e 100755 (executable)
--- a/vm/run.c
+++ b/vm/run.c
@@ -90,133 +90,6 @@ void init_stacks(CELL ds_size_, CELL rs_size_)
        stack_chain = NULL;
 }
 
-DEFINE_PRIMITIVE(drop)
-{
-       dpop();
-}
-
-DEFINE_PRIMITIVE(2drop)
-{
-       ds -= 2 * CELLS;
-}
-
-DEFINE_PRIMITIVE(3drop)
-{
-       ds -= 3 * CELLS;
-}
-
-DEFINE_PRIMITIVE(dup)
-{
-       dpush(dpeek());
-}
-
-DEFINE_PRIMITIVE(2dup)
-{
-       CELL top = dpeek();
-       CELL next = get(ds - CELLS);
-       ds += CELLS * 2;
-       put(ds - CELLS,next);
-       put(ds,top);
-}
-
-DEFINE_PRIMITIVE(3dup)
-{
-       CELL c1 = dpeek();
-       CELL c2 = get(ds - CELLS);
-       CELL c3 = get(ds - CELLS * 2);
-       ds += CELLS * 3;
-       put (ds,c1);
-       put (ds - CELLS,c2);
-       put (ds - CELLS * 2,c3);
-}
-
-DEFINE_PRIMITIVE(rot)
-{
-       CELL c1 = dpeek();
-       CELL c2 = get(ds - CELLS);
-       CELL c3 = get(ds - CELLS * 2);
-       put(ds,c3);
-       put(ds - CELLS,c1);
-       put(ds - CELLS * 2,c2);
-}
-
-DEFINE_PRIMITIVE(_rot)
-{
-       CELL c1 = dpeek();
-       CELL c2 = get(ds - CELLS);
-       CELL c3 = get(ds - CELLS * 2);
-       put(ds,c2);
-       put(ds - CELLS,c3);
-       put(ds - CELLS * 2,c1);
-}
-
-DEFINE_PRIMITIVE(dupd)
-{
-       CELL top = dpeek();
-       CELL next = get(ds - CELLS);
-       put(ds,next);
-       put(ds - CELLS,next);
-       dpush(top);
-}
-
-DEFINE_PRIMITIVE(swapd)
-{
-       CELL top = get(ds - CELLS);
-       CELL next = get(ds - CELLS * 2);
-       put(ds - CELLS,next);
-       put(ds - CELLS * 2,top);
-}
-
-DEFINE_PRIMITIVE(nip)
-{
-       CELL top = dpop();
-       drepl(top);
-}
-
-DEFINE_PRIMITIVE(2nip)
-{
-       CELL top = dpeek();
-       ds -= CELLS * 2;
-       drepl(top);
-}
-
-DEFINE_PRIMITIVE(tuck)
-{
-       CELL top = dpeek();
-       CELL next = get(ds - CELLS);
-       put(ds,next);
-       put(ds - CELLS,top);
-       dpush(top);
-}
-
-DEFINE_PRIMITIVE(over)
-{
-       dpush(get(ds - CELLS));
-}
-
-DEFINE_PRIMITIVE(pick)
-{
-       dpush(get(ds - CELLS * 2));
-}
-
-DEFINE_PRIMITIVE(swap)
-{
-       CELL top = dpeek();
-       CELL next = get(ds - CELLS);
-       put(ds,next);
-       put(ds - CELLS,top);
-}
-
-DEFINE_PRIMITIVE(to_r)
-{
-       rpush(dpop());
-}
-
-DEFINE_PRIMITIVE(from_r)
-{
-       dpush(rpop());
-}
-
 bool stack_to_array(CELL bottom, CELL top)
 {
        F_FIXNUM depth = (F_FIXNUM)(top - bottom + CELLS);
@@ -280,13 +153,6 @@ DEFINE_PRIMITIVE(exit)
        exit(to_fixnum(dpop()));
 }
 
-DEFINE_PRIMITIVE(eq)
-{
-       CELL lhs = dpop();
-       CELL rhs = dpeek();
-       drepl((lhs == rhs) ? T : F);
-}
-
 DEFINE_PRIMITIVE(millis)
 {
        box_unsigned_8(current_millis());
@@ -297,18 +163,6 @@ DEFINE_PRIMITIVE(sleep)
        sleep_millis(to_cell(dpop()));
 }
 
-DEFINE_PRIMITIVE(tag)
-{
-       drepl(tag_fixnum(TAG(dpeek())));
-}
-
-DEFINE_PRIMITIVE(slot)
-{
-       F_FIXNUM slot = untag_fixnum_fast(dpop());
-       CELL obj = dpop();
-       dpush(get(SLOT(obj,slot)));
-}
-
 DEFINE_PRIMITIVE(set_slot)
 {
        F_FIXNUM slot = untag_fixnum_fast(dpop());
index b54640ec8af6f78b55ca6f67a3757f935c587130..96e606e38cba5302edad54ff3e7b9f015e7345df 100755 (executable)
--- a/vm/run.h
+++ b/vm/run.h
@@ -47,29 +47,9 @@ typedef enum {
        JIT_EPILOG,
        JIT_RETURN,
        JIT_PROFILING,
-       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,
+       JIT_PUSH_IMMEDIATE,
+
+       JIT_DECLARE_WORD    = 42,
 
        STACK_TRACES_ENV    = 59,
 
@@ -245,28 +225,9 @@ DLLEXPORT void save_stacks(void);
 DLLEXPORT void nest_stacks(void);
 DLLEXPORT void unnest_stacks(void);
 void init_stacks(CELL ds_size, CELL rs_size);
-DECLARE_PRIMITIVE(drop);
-DECLARE_PRIMITIVE(2drop);
-DECLARE_PRIMITIVE(3drop);
-DECLARE_PRIMITIVE(dup);
-DECLARE_PRIMITIVE(2dup);
-DECLARE_PRIMITIVE(3dup);
-DECLARE_PRIMITIVE(rot);
-DECLARE_PRIMITIVE(_rot);
-DECLARE_PRIMITIVE(dupd);
-DECLARE_PRIMITIVE(swapd);
-DECLARE_PRIMITIVE(nip);
-DECLARE_PRIMITIVE(2nip);
-DECLARE_PRIMITIVE(tuck);
-DECLARE_PRIMITIVE(over);
-DECLARE_PRIMITIVE(pick);
-DECLARE_PRIMITIVE(swap);
-DECLARE_PRIMITIVE(to_r);
-DECLARE_PRIMITIVE(from_r);
+
 DECLARE_PRIMITIVE(datastack);
 DECLARE_PRIMITIVE(retainstack);
-DECLARE_PRIMITIVE(execute);
-DECLARE_PRIMITIVE(call);
 DECLARE_PRIMITIVE(getenv);
 DECLARE_PRIMITIVE(setenv);
 DECLARE_PRIMITIVE(exit);
@@ -275,11 +236,8 @@ DECLARE_PRIMITIVE(os_envs);
 DECLARE_PRIMITIVE(set_os_env);
 DECLARE_PRIMITIVE(unset_os_env);
 DECLARE_PRIMITIVE(set_os_envs);
-DECLARE_PRIMITIVE(eq);
 DECLARE_PRIMITIVE(millis);
 DECLARE_PRIMITIVE(sleep);
-DECLARE_PRIMITIVE(tag);
-DECLARE_PRIMITIVE(slot);
 DECLARE_PRIMITIVE(set_slot);
 
 bool stage2;
index 3941f13042e37be17ea080bf637abd6eb57d9137..59581ecee50c0c3146d2bb182062de35b6d73ab5 100755 (executable)
@@ -49,6 +49,7 @@ F_WORD *allot_word(CELL vocab, CELL name)
        word->props = F;
        word->counter = tag_fixnum(0);
        word->compiledp = F;
+       word->subprimitive = F;
        word->profiling = NULL;
        word->code = NULL;