]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of http://alfredobeaumont.org/factor
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 14 Jul 2008 05:50:29 +0000 (00:50 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 14 Jul 2008 05:50:29 +0000 (00:50 -0500)
56 files changed:
core/alien/c-types/c-types.factor
core/assocs/assocs-docs.factor
core/bootstrap/primitives.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/cpu/architecture/architecture.factor
core/cpu/ppc/intrinsics/intrinsics.factor
core/cpu/x86/intrinsics/intrinsics.factor
core/debugger/debugger.factor
core/hashtables/hashtables-docs.factor
core/hashtables/hashtables-tests.factor
core/hashtables/hashtables.factor
core/inference/known-words/known-words.factor
core/inspector/inspector.factor
core/optimizer/allot/allot.factor [new file with mode: 0644]
core/optimizer/known-words/known-words.factor
core/optimizer/math/math.factor
core/optimizer/optimizer.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.factor
core/words/words-docs.factor
extra/benchmark/beust1/beust1.factor [new file with mode: 0644]
extra/benchmark/beust2/beust2.factor [new file with mode: 0644]
extra/boids/ui/ui.factor
extra/color-picker/color-picker.factor
extra/generalizations/generalizations-docs.factor
extra/generalizations/generalizations-tests.factor
extra/generalizations/generalizations.factor
extra/geo-ip/geo-ip.factor
extra/lsys/ui/ui.factor
extra/math/ranges/ranges-docs.factor
extra/models/models-docs.factor
extra/namespaces/lib/lib.factor
extra/nehe/nehe.factor
extra/optimizer/debugger/debugger.factor
extra/sequences/lib/lib-tests.factor
extra/sequences/lib/lib.factor
extra/ui/gadgets/buttons/buttons.factor
extra/ui/gadgets/gadgets-docs.factor
extra/ui/gadgets/gadgets.factor
extra/ui/gadgets/menus/menus.factor
extra/ui/gadgets/packs/packs-docs.factor
extra/ui/gadgets/tracks/tracks.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/ui-docs.factor
extra/usa-cities/usa-cities.factor

index 405d679f4acc043da73dc9d12b6a2106e203dfcc..c553ca5cfb178398f1651f61420b703c25c60e8f 100755 (executable)
@@ -151,8 +151,9 @@ M: byte-array byte-length length ;
     swap dup length memcpy ;
 
 : (define-nth) ( word type quot -- )
-    >r heap-size [ rot * >fixnum ] swap prefix
-    r> append define-inline ;
+    [
+        \ swap , [ heap-size , [ * >fixnum ] % ] [ % ] bi*
+    ] [ ] make define-inline ;
 
 : nth-word ( name vocab -- word )
     >r "-nth" append r> create ;
index 51293955d5f5a3295cd9472dabaad57a78a6caa9..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:"
index d748e063c2d580c31260b803f35fbbd23b2317b1..b2b6dc4e59087131ee7d53ff54a8782956387a2a 100755 (executable)
@@ -121,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 -- )
@@ -273,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
index d40b71b4776eb9aa1b1a1816909bff2f1daa2b06..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: alien TUPLE: foo { slot dll } ;" 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 51c175a2820d4f97ceb087f13f719241c9ace12e..0cf30911650c174a472ae3772408ef4332644ebf 100755 (executable)
@@ -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 71c5f3efe6288a4193b62b394e5d3cf1580e4169..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 ;
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 c9c4432d5267f12a5558c2f04f0ca5fe79c28c97..5a39cbca7122e0b3a68e5b0d6c14674aa525f54f 100755 (executable)
@@ -450,33 +450,28 @@ IN: cpu.ppc.intrinsics
     { +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 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 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 1c9138fe0b46283b4cbbebc30c81a85ff2568ed3..3636a0196337538b2fb434901f4a21eb2557ca6d 100755 (executable)
@@ -540,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 ;
diff --git a/core/optimizer/allot/allot.factor b/core/optimizer/allot/allot.factor
new file mode 100644 (file)
index 0000000..d89e3c5
--- /dev/null
@@ -0,0 +1,96 @@
+! 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 )
+    [ (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
+
+: (array) ( n -- array ) "BUG: missing (array) intrinsic" throw ;
+
+\ (array) { integer } { array } <effect> set-primitive-effect
+\ (array) make-flushable
+
+: <array>-quot ( n -- quot )
+    [
+        [ swap (array) ] %
+        [ \ 2dup , , [ swap set-array-nth ] % ] each
+        \ nip ,
+    ] [ ] 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 )
+    [
+        \ (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 7527199fe93e24ca0b6344118efa721bc08cda10..cd5ec7fda2d3684eabe61932c7ca406946662185 100755 (executable)
@@ -9,7 +9,7 @@ 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.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 c20cba99cbbd64d46c65ad23c8f555d5ebc15053..2c4e33e1833f7845197e61d7d799d5d539179413 100755 (executable)
@@ -406,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 [
@@ -438,6 +438,19 @@ most-negative-fixnum most-positive-fixnum [a,b]
     }
 } 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
 
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 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 c433ce442614bb3f65eb12cf09bd4812fb290764..11cfb975df0e37bb6c444d0774799d74a4e3558c 100755 (executable)
@@ -383,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
 
index 57d62f6480a03eb9fcd2c1c86c28e12b8dbed639..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 }
@@ -64,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 a5b2e4b3d80d421e4bb68296c84f38529c7cab43..73d674782d0135a1f83ad5151f964c75f96aac54 100755 (executable)
@@ -188,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" } }
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..8f794fb
--- /dev/null
@@ -0,0 +1,39 @@
+! 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
+
+:: (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
index 6b175eeb5e945c56815818378ea09defcc1c441c..f45b1cc0ffb0fb7bf51bda9177f20f0890f37479 100755 (executable)
@@ -114,6 +114,8 @@ VARS: population-label cohesion-label alignment-label separation-label ;
 
   <frame>
 
+  <shelf>
+
   {
     [ "ESC - Pause" [ drop toggle-loop ] button* ]
 
@@ -139,7 +141,7 @@ VARS: population-label cohesion-label alignment-label separation-label ;
       "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
 
index 6fcf3c21cd0ee80d40e4767a1c05cf08969095c2..b5938a7ad75c90eff4da40b3b7efd5912388774c 100755 (executable)
@@ -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 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 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 ;
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 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 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 2a79d8977f7f4ca4b1fd47d076d372eb57fc135c..fdae5388964499dac46f60f0b7861a02b9feac85 100755 (executable)
@@ -58,6 +58,7 @@ MATCH-VARS: ?a ?b ?c ;
         { { { ?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 ] }
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 a855a6d93ebdd7d4ef8a943a5c5147140cc627df..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 math.geometry.rect ;
+       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 b9d12847bef252694ad85a195cb380b4167b76b1..47ae6b4733f702f8a406b4aa2c9c5fc2859dc18c 100755 (executable)
@@ -180,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 ebe3773ce96b1f768f83f714eaeafec46bf0fdf7..ce0df019e7edaedf02f8091f5ce237a36c585f13 100755 (executable)
@@ -357,8 +357,6 @@ M: f request-focus-on 2drop ;
 : focus-path ( world -- seq )
     [ focus>> ] follow ;
 
-: gadget, ( gadget -- ) gadget get swap add-gadget drop ;
-
 : g ( -- gadget ) gadget get ;
 
 : g-> ( x -- x x gadget ) dup g ;
index 4f815bc33dddcddc41da8a72404d5fd8a63d0a39..2d7af473969bdd228775967d72057816d072933d 100644 (file)
@@ -48,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 eca49d3aabfdbd9784b30eebf79aa04265df8406..7a8ee65a8b99bbd69163e755f2cadaf8f67e93ce 100644 (file)
@@ -49,6 +49,10 @@ M: track pref-dim*
 : track-add ( gadget track constraint -- )
     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 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 72cb2c557ed429ee9bedac8016b5d1d3c9394331..172c57061ce5aa7a6271711703fd58b9c245e399 100755 (executable)
@@ -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 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