From eb6cdcc06eb439c7ad67e9511cf8a02f318637ca Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 17:41:39 -0600 Subject: [PATCH 01/39] Fix parser tests --- core/parser/parser-tests.factor | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/parser/parser-tests.factor b/core/parser/parser-tests.factor index c4fa0890f9..d2d407e147 100644 --- a/core/parser/parser-tests.factor +++ b/core/parser/parser-tests.factor @@ -428,7 +428,7 @@ must-fail-with "USE: this-better-not-exist" eval ] must-fail -[ ": foo ;" eval ] [ error>> no-current-vocab? ] must-fail-with +[ ": foo ;" eval ] [ error>> error>> no-current-vocab? ] must-fail-with [ 92 ] [ "CHAR: \\" eval ] unit-test [ 92 ] [ "CHAR: \\\\" eval ] unit-test @@ -483,7 +483,7 @@ must-fail-with [ t ] [ "staging-problem-test-2" "parser.tests" lookup >boolean ] unit-test -[ "DEFER: blah" eval ] [ error>> no-current-vocab? ] must-fail-with +[ "DEFER: blah" eval ] [ error>> error>> no-current-vocab? ] must-fail-with [ "IN: parser.tests : blah ; parsing FORGET: blah" eval From 6e9b2a6c739f911fc721ab017473b1ab8d785a89 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 17:47:12 -0600 Subject: [PATCH 02/39] Make limited scrollers more versatile: they now have a min-dim and a max-dim --- basis/ui/gadgets/scrollers/scrollers.factor | 10 ++++++---- basis/ui/tools/deploy/deploy.factor | 7 +++++-- basis/ui/tools/listener/listener.factor | 4 +++- basis/ui/tools/traceback/traceback.factor | 5 ++++- basis/ui/tools/workspace/workspace.factor | 11 +++++++---- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/basis/ui/gadgets/scrollers/scrollers.factor b/basis/ui/gadgets/scrollers/scrollers.factor index 6c37c37acf..045ecc7990 100644 --- a/basis/ui/gadgets/scrollers/scrollers.factor +++ b/basis/ui/gadgets/scrollers/scrollers.factor @@ -129,10 +129,12 @@ M: scroller focusable-child* M: scroller model-changed nip f >>follows drop ; -TUPLE: limited-scroller < scroller fixed-dim ; +TUPLE: limited-scroller < scroller +{ min-dim initial: { 0 0 } } +{ max-dim initial: { 1/0. 1/0. } } ; -: ( gadget dim -- scroller ) - >r limited-scroller new-scroller r> >>fixed-dim ; +: ( gadget -- scroller ) + limited-scroller new-scroller ; M: limited-scroller pref-dim* - fixed-dim>> ; + [ call-next-method ] [ min-dim>> vmax ] [ max-dim>> vmin ] tri ; diff --git a/basis/ui/tools/deploy/deploy.factor b/basis/ui/tools/deploy/deploy.factor index 0ac89e122f..f310f72780 100644 --- a/basis/ui/tools/deploy/deploy.factor +++ b/basis/ui/tools/deploy/deploy.factor @@ -96,9 +96,12 @@ TUPLE: deploy-gadget < pack vocab settings ; : com-close ( gadget -- ) close-window ; +deploy-gadget "misc" "Miscellaneous commands" { + { T{ key-down f f "ESC" } com-close } +} define-command-map + deploy-gadget "toolbar" f { - { f com-close } - { f com-help } + { T{ key-down f f "F1" } com-help } { f com-revert } { f com-save } { T{ key-down f f "RET" } com-deploy } diff --git a/basis/ui/tools/listener/listener.factor b/basis/ui/tools/listener/listener.factor index d842bf8a68..49ce5203d3 100644 --- a/basis/ui/tools/listener/listener.factor +++ b/basis/ui/tools/listener/listener.factor @@ -25,7 +25,9 @@ TUPLE: listener-gadget < track input output stack ; : listener-input, ( listener -- listener ) dup >>input dup input>> - { 0 100 } + + { 0 100 } >>min-dim + { 1/0. 100 } >>max-dim "Input" f track-add ; diff --git a/basis/ui/tools/traceback/traceback.factor b/basis/ui/tools/traceback/traceback.factor index 6cb79916e0..7e2158e0e9 100644 --- a/basis/ui/tools/traceback/traceback.factor +++ b/basis/ui/tools/traceback/traceback.factor @@ -43,7 +43,10 @@ M: traceback-gadget pref-dim* drop { 550 600 } ; ; : ( model -- gadget ) - { 400 400 } ; + + + { 400 400 } >>min-dim + { 400 400 } >>max-dim ; : variables ( traceback -- ) model>> diff --git a/basis/ui/tools/workspace/workspace.factor b/basis/ui/tools/workspace/workspace.factor index bbe4b12712..f06e0aae26 100644 --- a/basis/ui/tools/workspace/workspace.factor +++ b/basis/ui/tools/workspace/workspace.factor @@ -47,12 +47,15 @@ M: gadget tool-scroller drop f ; : get-tool ( class -- gadget ) get-workspace find-tool nip ; +: ( topic -- pane ) + [ [ help ] with-pane ] keep ; + : help-window ( topic -- ) [ - [ [ help ] with-pane ] keep - { 550 700 } - ] keep - article-title open-window ; + + { 550 700 } >>max-dim + ] [ article-title ] bi + open-window ; : hide-popup ( workspace -- ) dup popup>> track-remove From b9e1f5bf8ae2382f5f4b247bd7751452ec4eda2a Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 17:47:25 -0600 Subject: [PATCH 03/39] M: track pref-dim did not take the gap into account --- basis/ui/gadgets/tracks/tracks.factor | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/basis/ui/gadgets/tracks/tracks.factor b/basis/ui/gadgets/tracks/tracks.factor index 5a9683ceff..771c489ce3 100644 --- a/basis/ui/gadgets/tracks/tracks.factor +++ b/basis/ui/gadgets/tracks/tracks.factor @@ -1,8 +1,8 @@ ! 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 - math.geometry.rect fry ; +USING: accessors io kernel namespaces fry +math math.vectors math.geometry.rect math.order +sequences words ui.gadgets ui.gadgets.packs ; IN: ui.gadgets.tracks @@ -35,13 +35,16 @@ TUPLE: track < pack sizes ; M: track layout* ( track -- ) dup track-layout pack-layout ; -: track-pref-dims-1 ( track -- dim ) children>> pref-dims max-dim ; +: track-pref-dims-1 ( track -- dim ) + children>> pref-dims max-dim ; : track-pref-dims-2 ( track -- dim ) - [ children>> pref-dims ] [ normalized-sizes ] bi - [ [ v/n ] when* ] 2map - max-dim - [ >fixnum ] map ; + [ + [ children>> pref-dims ] [ normalized-sizes ] bi + [ [ v/n ] when* ] 2map max-dim [ >fixnum ] map + ] + [ [ gap>> ] [ children>> length 1 [-] ] bi v*n ] bi + v+ ; M: track pref-dim* ( gadget -- dim ) [ track-pref-dims-1 ] From 503c0a09710c5b465d6f357e7912b02c44f064eb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 18:23:19 -0600 Subject: [PATCH 04/39] Add a new cookbook page --- basis/help/cookbook/cookbook.factor | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/basis/help/cookbook/cookbook.factor b/basis/help/cookbook/cookbook.factor index 9fb837a873..6e27bd9256 100644 --- a/basis/help/cookbook/cookbook.factor +++ b/basis/help/cookbook/cookbook.factor @@ -1,5 +1,6 @@ USING: help.markup help.syntax io kernel math namespaces parser -prettyprint sequences vocabs.loader namespaces stack-checker ; +prettyprint sequences vocabs.loader namespaces stack-checker +help ; IN: help.cookbook ARTICLE: "cookbook-syntax" "Basic syntax cookbook" @@ -324,6 +325,19 @@ ARTICLE: "cookbook-pitfalls" "Pitfalls to avoid" { "If " { $link run-file } " throws a stack depth assertion, it means that the top-level form in the file left behind values on the stack. The stack depth is compared before and after loading a source file, since this type of situation is almost always an error. If you have a legitimate need to load a source file which returns data in some manner, define a word in the source file which produces this data on the stack and call the word after loading the file." } } ; +ARTICLE: "cookbook-next" "Next steps" +"Once you have read through " { $link "first-program" } " and " { $link "cookbook" } ", the best way to keep learning Factor is to start looking at some simple example programs. Here are a few particularly nice vocabularies which should keep you busy for a little while:" +{ $list + { $vocab-link "base64" } + { $vocab-link "roman" } + { $vocab-link "rot13" } + { $vocab-link "smtp" } + { $vocab-link "time-server" } + { $vocab-link "tools.hexdump" } + { $vocab-link "webapps.counter" } +} +"If you see code in there that you do not understand, use " { $link see } " and " { $link help } " to explore." ; + ARTICLE: "cookbook" "Factor cookbook" "The Factor cookbook is a high-level overview of the most important concepts required to program in Factor." { $subsection "cookbook-syntax" } @@ -336,6 +350,7 @@ ARTICLE: "cookbook" "Factor cookbook" { $subsection "cookbook-scripts" } { $subsection "cookbook-compiler" } { $subsection "cookbook-philosophy" } -{ $subsection "cookbook-pitfalls" } ; +{ $subsection "cookbook-pitfalls" } +{ $subsection "cookbook-next" } ; ABOUT: "cookbook" From af5e5611dceb9c625ba085ab2f2238e56da3f6ef Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 18:59:30 -0600 Subject: [PATCH 05/39] Better invalid callable check --- basis/prettyprint/backend/backend.factor | 16 +++++++++++++--- basis/prettyprint/prettyprint-tests.factor | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/basis/prettyprint/backend/backend.factor b/basis/prettyprint/backend/backend.factor index 31b6ba3f26..2af0224e32 100644 --- a/basis/prettyprint/backend/backend.factor +++ b/basis/prettyprint/backend/backend.factor @@ -217,14 +217,24 @@ M: vector pprint* pprint-object ; M: byte-vector pprint* pprint-object ; M: hashtable pprint* pprint-object ; +GENERIC: valid-callable? ( obj -- ? ) + +M: object valid-callable? drop f ; + +M: quotation valid-callable? drop t ; + +M: curry valid-callable? quot>> valid-callable? ; + +M: compose valid-callable? + [ first>> ] [ second>> ] bi [ valid-callable? ] both? ; + M: curry pprint* - dup quot>> callable? [ pprint-object ] [ + dup valid-callable? [ pprint-object ] [ "( invalid curry )" swap present-text ] if ; M: compose pprint* - dup [ first>> callable? ] [ second>> callable? ] bi and - [ pprint-object ] [ + dup valid-callable? [ pprint-object ] [ "( invalid compose )" swap present-text ] if ; diff --git a/basis/prettyprint/prettyprint-tests.factor b/basis/prettyprint/prettyprint-tests.factor index 8eaaab3c1d..7fa3c5a1a3 100644 --- a/basis/prettyprint/prettyprint-tests.factor +++ b/basis/prettyprint/prettyprint-tests.factor @@ -365,3 +365,8 @@ M: started-out-hustlin' ended-up-ballin' ; inline [ "USING: prettyprint.tests ;\nM: started-out-hustlin' ended-up-ballin' ; inline\n" ] [ [ { started-out-hustlin' ended-up-ballin' } see ] with-string-writer ] unit-test + +[ "( invalid curry )" ] [ 1 2 curry unparse ] unit-test +[ "( invalid curry )" ] [ 1 2 3 curry curry unparse ] unit-test +[ "( invalid compose )" ] [ 1 2 compose unparse ] unit-test +[ "( invalid compose )" ] [ [ 1 ] 2 3 curry compose unparse ] unit-test From e687d179e6b9fa4b1448464cf36b8cf25fd4974f Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 18:59:53 -0600 Subject: [PATCH 06/39] Re-word fry docs slightly --- basis/fry/fry-docs.factor | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/basis/fry/fry-docs.factor b/basis/fry/fry-docs.factor index 286dbb469e..03ac01ad61 100644 --- a/basis/fry/fry-docs.factor +++ b/basis/fry/fry-docs.factor @@ -15,7 +15,7 @@ HELP: fry } ; HELP: '[ -{ $syntax "code... ]" } +{ $syntax "'[ code... ]" } { $description "Literal fried quotation. Expands into code which takes values from the stack and substitutes them in place of the fry specifiers " { $link _ } " and " { $link @ } "." } { $examples "See " { $link "fry.examples" } "." } ; @@ -49,6 +49,8 @@ $nl "{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry 3compose map" "{ 8 13 14 27 } [ even? dup 5 ? ] map" } +"The following is a no-op:" +{ $code "'[ @ ]" } "Here are some built-in combinators rewritten in terms of fried quotations:" { $table { { $link literalize } { $snippet ": literalize '[ _ ] ;" } } @@ -74,14 +76,14 @@ ARTICLE: "fry.limitations" "Fried quotation limitations" "As with " { $vocab-link "locals" } ", fried quotations cannot contain " { $link >r } " and " { $link r> } ". This is not a real limitation in practice, since " { $link dip } " can be used instead." ; ARTICLE: "fry" "Fried quotations" -"A " { $emphasis "fried quotation" } " differs from a literal quotation in that when it is evaluated, instead of just pushing itself on the stack, it consumes zero or more stack values and inserts them into the quotation." +"The " { $vocab-link "fry" } " vocabulary implements " { $emphasis "fried quotation" } ". Conceptually, fried quotations are quotations with ``holes'' (more formally, " { $emphasis "fry specifiers" } "), and the holes are filled in when the fried quotation is pushed on the stack." $nl -"Fried quotations are denoted with a special parsing word:" +"Fried quotations are started by a special parsing word:" { $subsection POSTPONE: '[ } -"Fried quotations contain zero or more " { $emphasis "fry specifiers" } ":" +"There are two types of fry specifiers; the first can hold a value, and the second ``splices'' a quotation, as if it were inserted without surrounding brackets:" { $subsection _ } { $subsection @ } -"When a fried quotation is being evaluated, values are consumed from the stack and spliced into the quotation from right to left." +"The holes are filled in with the top of stack going in the rightmost hole, the second item on the stack going in the second hole from the right, and so on." { $subsection "fry.examples" } { $subsection "fry.philosophy" } { $subsection "fry.limitations" } From 044d3f06659cdcbfbc550a40f53229deb5098d9c Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 19:06:41 -0600 Subject: [PATCH 07/39] Add another piece of info --- basis/fry/fry-docs.factor | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/basis/fry/fry-docs.factor b/basis/fry/fry-docs.factor index 03ac01ad61..8f402f2e8c 100644 --- a/basis/fry/fry-docs.factor +++ b/basis/fry/fry-docs.factor @@ -87,7 +87,10 @@ $nl { $subsection "fry.examples" } { $subsection "fry.philosophy" } { $subsection "fry.limitations" } -"Quotations can also be fried without using a parsing word:" -{ $subsection fry } ; +"Fry is implemented as a parsing word which reads a quotation and scans for occurrences of " { $link _ } " and " { $link @ } "; these words are not actually executed, and doing so raises an error (this can happen if they're accidentally used outside of a fry)." +$nl +"Fried quotations can also be constructed without using a parsing word; this is useful when meta-programming:" +{ $subsection fry } +"Fried quotations are an abstraction on top of the " { $link "compositional-combinators" } "; their use is encouraged over the combinators, because often the fry form is shorter and clearer than the combinator form." ; ABOUT: "fry" From c75c4efefd73a599485fa3d9963c0ced0b5739a2 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 19:08:12 -0600 Subject: [PATCH 08/39] Add unit test for pack pref-dim bug --- basis/ui/gadgets/labels/labels-tests.factor | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 basis/ui/gadgets/labels/labels-tests.factor diff --git a/basis/ui/gadgets/labels/labels-tests.factor b/basis/ui/gadgets/labels/labels-tests.factor new file mode 100644 index 0000000000..a9b5074e4c --- /dev/null +++ b/basis/ui/gadgets/labels/labels-tests.factor @@ -0,0 +1,9 @@ +USING: accessors tools.test ui.gadgets ui.gadgets.labels ; +IN: ui.gadgets.labels.tests + +[ { 119 14 } ] [ + { 100 14 } >>dim + { 14 14 } >>dim + label-on-right { 5 5 } >>gap + pref-dim +] unit-test From ae2f5e54398575e258b7602798b00b5ba7dc3231 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 19:17:47 -0600 Subject: [PATCH 09/39] Clarify tail-call optimization documentation --- basis/help/handbook/handbook.factor | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/basis/help/handbook/handbook.factor b/basis/help/handbook/handbook.factor index d1d9ca049a..2ed86a0a19 100644 --- a/basis/help/handbook/handbook.factor +++ b/basis/help/handbook/handbook.factor @@ -65,6 +65,11 @@ $nl { "word" { "the basic unit of code, analogous to a function or procedure in other programming languages. See " { $link "words" } } } } ; +ARTICLE: "tail-call-opt" "Tail-call optimization" +"If the last action performed is the execution of a word, the current quotation is not saved on the call stack; this is known as " { $emphasis "tail-call optimization" } " and the Factor implementation guarantees that it will be performed." +$nl +"Tail-call optimization allows iterative algorithms to be implemented in an efficient manner using recursion, without the need for any kind of primitive looping construct in the language. However, in practice, most iteration is performed via combinators such as " { $link while } ", " { $link each } ", " { $link map } ", " { $link assoc-each } ", and so on. The definitions of these combinators do bottom-out in recursive words, however." ; + ARTICLE: "evaluator" "Evaluation semantics" { $link "quotations" } " are evaluated sequentially from beginning to end. When the end is reached, the quotation returns to its caller. As each object in the quotation is evaluated in turn, an action is taken based on its type:" { $list @@ -72,7 +77,7 @@ ARTICLE: "evaluator" "Evaluation semantics" { "a " { $link wrapper } " - the wrapped object is pushed on the data stack. Wrappers are used to push word objects directly on the stack when they would otherwise execute. See the " { $link POSTPONE: \ } " parsing word." } { "All other types of objects are pushed on the data stack." } } -"If the last action performed is the execution of a word, the current quotation is not saved on the call stack; this is known as " { $snippet "tail-recursion" } " and allows iterative algorithms to execute without incurring unbounded call stack usage." +{ $subsection "tail-call-opt" } { $see-also "compiler" } ; ARTICLE: "objects" "Objects" From 3d8f432856044bbd56c2ec18c0dc3aa445397292 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 19:23:11 -0600 Subject: [PATCH 10/39] Clarify math.bitwise -vs- bitwise-arithmetic docs --- basis/math/bitwise/bitwise-docs.factor | 5 +++-- core/math/math-docs.factor | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/basis/math/bitwise/bitwise-docs.factor b/basis/math/bitwise/bitwise-docs.factor index 4f2606bda0..9ed164330b 100644 --- a/basis/math/bitwise/bitwise-docs.factor +++ b/basis/math/bitwise/bitwise-docs.factor @@ -310,8 +310,9 @@ ARTICLE: "math-bitfields" "Constructing bit fields" "Some applications, such as binary communication protocols and assemblers, need to construct integers from elaborate bit field specifications. Hand-coding this using " { $link shift } " and " { $link bitor } " results in repetitive code. A higher-level facility exists to factor out this repetition:" { $subsection bitfield } ; -ARTICLE: "math.bitwise" "Bitwise arithmetic" -"The " { $vocab-link "math.bitwise" } " vocabulary can implements bitwise arithmetic words that are useful for efficiency, low-level programming, and interfacing with C libraries." $nl +ARTICLE: "math.bitwise" "Additional bitwise arithmetic" +"The " { $vocab-link "math.bitwise" } " vocabulary provides bitwise arithmetic words extending " { $link "bitwise-arithmetic" } ". They are useful for efficiency, low-level programming, and interfacing with C libraries." +$nl "Setting and clearing bits:" { $subsection set-bit } { $subsection clear-bit } diff --git a/core/math/math-docs.factor b/core/math/math-docs.factor index 20b4e0bbbe..aca43add5c 100644 --- a/core/math/math-docs.factor +++ b/core/math/math-docs.factor @@ -348,6 +348,7 @@ ARTICLE: "bitwise-arithmetic" "Bitwise arithmetic" { $subsection 2/ } { $subsection 2^ } { $subsection bit? } +"The " { $vocab-link "math.bitwise" } " vocabulary implements additional bitwise integer operations." { $see-also "conditionals" } ; ARTICLE: "arithmetic" "Arithmetic" From d6264a32ce82a1bfb427d92a36cec5de0929c7f6 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 19:43:11 -0600 Subject: [PATCH 11/39] Better values docs --- basis/values/values-docs.factor | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/basis/values/values-docs.factor b/basis/values/values-docs.factor index 69e2801110..866af469e9 100644 --- a/basis/values/values-docs.factor +++ b/basis/values/values-docs.factor @@ -2,7 +2,7 @@ USING: help.markup help.syntax ; IN: values ARTICLE: "values" "Global values" -"Usually, dynamically scoped variables are sufficient for holding data which is not literal. But occasionally, for global information that's calculated just once, it's useful to use the word mechanism instead, and set the word to the appropriate value just once. Values abstract over this concept. To create a new word as a value, use the following syntax:" +"Usually, dynamically scoped variables are sufficient for holding data which is not literal. But occasionally, for global information that's calculated just once, it's useful to use the word mechanism instead, and set the word to the appropriate value just once. The " { $vocab-link "values" } " vocabulary implements " { $emphasis "values" } ", which abstract over this concept. To create a new word as a value, use the following syntax:" { $subsection POSTPONE: VALUE: } "To get the value, just call the word. The following words manipulate values:" { $subsection get-value } @@ -10,6 +10,8 @@ ARTICLE: "values" "Global values" { $subsection POSTPONE: to: } { $subsection change-value } ; +ABOUT: "values" + HELP: VALUE: { $syntax "VALUE: word" } { $values { "word" "a word to be created" } } From 825ad4e59de9bb6a2afea502850c9e7590bfb33f Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:02:21 -0600 Subject: [PATCH 12/39] Remove unmaintained/io/ since basis/io/ now has all of the features from the old I/O library --- unmaintained/io/load.factor | 24 ------- unmaintained/io/os-unix-shell.factor | 46 ------------- unmaintained/io/os-unix.factor | 24 ------- unmaintained/io/os-winnt-shell.factor | 55 --------------- unmaintained/io/os-winnt.factor | 96 --------------------------- unmaintained/io/shell.factor | 40 ----------- unmaintained/io/test/io.factor | 42 ------------ unmaintained/io/test/mmap.factor | 21 ------ 8 files changed, 348 deletions(-) delete mode 100644 unmaintained/io/load.factor delete mode 100644 unmaintained/io/os-unix-shell.factor delete mode 100644 unmaintained/io/os-unix.factor delete mode 100644 unmaintained/io/os-winnt-shell.factor delete mode 100644 unmaintained/io/os-winnt.factor delete mode 100644 unmaintained/io/shell.factor delete mode 100644 unmaintained/io/test/io.factor delete mode 100644 unmaintained/io/test/mmap.factor diff --git a/unmaintained/io/load.factor b/unmaintained/io/load.factor deleted file mode 100644 index ac9b9542c5..0000000000 --- a/unmaintained/io/load.factor +++ /dev/null @@ -1,24 +0,0 @@ -USING: kernel ; - -REQUIRES: libs/calendar libs/shuffle ; - -PROVIDE: libs/io -{ +files+ { - "io.factor" - "mmap.factor" - "shell.factor" - { "os-unix.factor" [ unix? ] } - { "os-unix-shell.factor" [ unix? ] } - { "mmap-os-unix.factor" [ unix? ] } - - { "os-winnt.factor" [ winnt? ] } - { "os-winnt-shell.factor" [ winnt? ] } - { "mmap-os-winnt.factor" [ winnt? ] } - - { "os-wince.factor" [ wince? ] } -} } -{ +tests+ { - "test/io.factor" - "test/mmap.factor" -} } ; - diff --git a/unmaintained/io/os-unix-shell.factor b/unmaintained/io/os-unix-shell.factor deleted file mode 100644 index 6c3919ddb2..0000000000 --- a/unmaintained/io/os-unix-shell.factor +++ /dev/null @@ -1,46 +0,0 @@ -USING: arrays kernel libs-io sequences prettyprint unix-internals -calendar namespaces math ; -USE: io -IN: shell - -TUPLE: unix-shell ; - -T{ unix-shell } \ shell set-global - -TUPLE: file name mode nlink uid gid size mtime symbol ; - -M: unix-shell directory* ( path -- seq ) - dup (directory) [ tuck >r "/" r> 3append stat* 2array ] map-with ; - -M: unix-shell make-file ( path -- file ) - first2 - [ stat-mode ] keep - [ stat-nlink ] keep - [ stat-uid ] keep - [ stat-gid ] keep - [ stat-size ] keep - [ stat-mtime timespec>timestamp >local-time ] keep - stat-mode mode>symbol ; - -M: unix-shell file. ( file -- ) - [ [ file-mode >oct write ] keep ] with-cell - [ bl ] with-cell - [ [ file-nlink unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-uid unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-gid unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-size unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-mtime file-time-string write ] keep ] with-cell - [ bl ] with-cell - [ file-name write ] with-cell ; - -USE: unix-internals -M: unix-shell touch-file ( path -- ) - dup open-append dup -1 = [ - drop now dup set-file-times - ] [ - nip [ now dup set-file-times* ] keep close - ] if ; diff --git a/unmaintained/io/os-unix.factor b/unmaintained/io/os-unix.factor deleted file mode 100644 index 280908b406..0000000000 --- a/unmaintained/io/os-unix.factor +++ /dev/null @@ -1,24 +0,0 @@ -! Copyright (C) 2007 Doug Coleman. -! See http://factorcode.org/license.txt for BSD license. -USING: alien arrays calendar errors io io-internals kernel -math nonblocking-io sequences unix-internals unix-io ; -IN: libs-io - -: O_APPEND HEX: 100 ; inline -: O_EXCL HEX: 800 ; inline -: SEEK_SET 0 ; inline -: SEEK_CUR 1 ; inline -: SEEK_END 2 ; inline -: EEXIST 17 ; inline - -: mode>symbol ( mode -- ch ) - S_IFMT bitand - { - { [ dup S_IFDIR = ] [ drop "/" ] } - { [ dup S_IFIFO = ] [ drop "|" ] } - { [ dup S_IXUSR = ] [ drop "*" ] } - { [ dup S_IFLNK = ] [ drop "@" ] } - { [ dup S_IFWHT = ] [ drop "%" ] } - { [ dup S_IFSOCK = ] [ drop "=" ] } - { [ t ] [ drop "" ] } - } cond ; diff --git a/unmaintained/io/os-winnt-shell.factor b/unmaintained/io/os-winnt-shell.factor deleted file mode 100644 index a2be22daf8..0000000000 --- a/unmaintained/io/os-winnt-shell.factor +++ /dev/null @@ -1,55 +0,0 @@ -USING: alien calendar io io-internals kernel libs-io math -namespaces prettyprint sequences windows-api ; -IN: shell - -TUPLE: winnt-shell ; - -T{ winnt-shell } \ shell set-global - -TUPLE: file name size mtime attributes ; - -: ((directory*)) ( handle -- ) - "WIN32_FIND_DATA" [ FindNextFile ] 2keep - rot zero? [ 2drop ] [ , ((directory*)) ] if ; - -: (directory*) ( path -- ) - "WIN32_FIND_DATA" [ - FindFirstFile dup INVALID_HANDLE_VALUE = [ - win32-error - ] when - ] keep , - [ ((directory*)) ] keep FindClose win32-error=0/f ; - -: append-star ( path -- path ) - dup peek CHAR: \\ = "*" "\\*" ? append ; - -M: winnt-shell directory* ( path -- seq ) - normalize-pathname append-star [ (directory*) ] { } make ; - -: WIN32_FIND_DATA>file-size ( WIN32_FILE_ATTRIBUTE_DATA -- n ) - [ WIN32_FIND_DATA-nFileSizeLow ] keep - WIN32_FIND_DATA-nFileSizeHigh 32 shift + ; - -M: winnt-shell make-file ( WIN32_FIND_DATA -- file ) - [ WIN32_FIND_DATA-cFileName alien>u16-string ] keep - [ WIN32_FIND_DATA>file-size ] keep - [ - WIN32_FIND_DATA-ftCreationTime - FILETIME>timestamp >local-time - ] keep - WIN32_FIND_DATA-dwFileAttributes ; - -M: winnt-shell file. ( file -- ) - [ [ file-attributes >oct write ] keep ] with-cell - [ bl ] with-cell - [ [ file-size unparse write ] keep ] with-cell - [ bl ] with-cell - [ [ file-mtime file-time-string write ] keep ] with-cell - [ bl ] with-cell - [ file-name write ] with-cell ; - -M: winnt-shell touch-file ( path -- ) - #! Set the file write time to 'now' - normalize-pathname - dup maybe-create-file [ drop ] [ now set-file-write-time ] if ; - diff --git a/unmaintained/io/os-winnt.factor b/unmaintained/io/os-winnt.factor deleted file mode 100644 index 971ae79097..0000000000 --- a/unmaintained/io/os-winnt.factor +++ /dev/null @@ -1,96 +0,0 @@ -USING: alien calendar errors generic io io-internals kernel -math namespaces nonblocking-io parser quotations sequences -shuffle windows-api words ; -IN: libs-io - -: stat* ( path -- WIN32_FIND_DATA ) - "WIN32_FIND_DATA" - [ - FindFirstFile - [ INVALID_HANDLE_VALUE = [ win32-error ] when ] keep - FindClose win32-error=0/f - ] keep ; - -: set-file-time ( path timestamp/f timestamp/f timestamp/f -- ) - #! timestamp order: creation access write - >r >r >r open-existing dup r> r> r> - [ timestamp>FILETIME ] 3 napply - SetFileTime win32-error=0/f - close-handle ; - -: set-file-times ( path timestamp/f timestamp/f -- ) - f -rot set-file-time ; - -: set-file-create-time ( path timestamp -- ) - f f set-file-time ; - -: set-file-access-time ( path timestamp -- ) - >r f r> f set-file-time ; - -: set-file-write-time ( path timestamp -- ) - >r f f r> set-file-time ; - -: maybe-make-filetime ( ? -- FILETIME/f ) - [ "FILETIME" ] [ f ] if ; - -: file-time ( path ? ? ? -- FILETIME/f FILETIME/f FILETIME/f ) - >r >r >r open-existing dup r> r> r> - [ maybe-make-filetime ] 3 napply - [ GetFileTime win32-error=0/f close-handle ] 3keep ; - -: file-times ( path -- FILETIME FILETIME FILETIME ) - t t t file-time [ FILETIME>timestamp ] 3 napply ; - -: file-create-time ( path -- FILETIME ) - t f f file-time 2drop FILETIME>timestamp ; - -: file-access-time ( path -- FILETIME ) - f t f file-time drop nip FILETIME>timestamp ; - -: file-write-time ( path -- FILETIME ) - f f t file-time 2nip FILETIME>timestamp ; - -: attrib ( path -- n ) - [ stat* WIN32_FIND_DATA-dwFileAttributes ] catch - [ drop 0 ] when ; - -: (read-only?) ( mode -- ? ) - FILE_ATTRIBUTE_READONLY bit-set? ; - -: read-only? ( path -- ? ) - attrib (read-only?) ; - -: (hidden?) ( mode -- ? ) - FILE_ATTRIBUTE_HIDDEN bit-set? ; - -: hidden? ( path -- ? ) - attrib (hidden?) ; - -: (system?) ( mode -- ? ) - FILE_ATTRIBUTE_SYSTEM bit-set? ; - -: system? ( path -- ? ) - attrib (system?) ; - -: (directory?) ( mode -- ? ) - FILE_ATTRIBUTE_DIRECTORY bit-set? ; - -: directory? ( path -- ? ) - attrib (directory?) ; - -: (archive?) ( mode -- ? ) - FILE_ATTRIBUTE_ARCHIVE bit-set? ; - -: archive? ( path -- ? ) - attrib (archive?) ; - -! FILE_ATTRIBUTE_DEVICE -! FILE_ATTRIBUTE_NORMAL -! FILE_ATTRIBUTE_TEMPORARY -! FILE_ATTRIBUTE_SPARSE_FILE -! FILE_ATTRIBUTE_REPARSE_POINT -! FILE_ATTRIBUTE_COMPRESSED -! FILE_ATTRIBUTE_OFFLINE -! FILE_ATTRIBUTE_NOT_CONTENT_INDEXED -! FILE_ATTRIBUTE_ENCRYPTED - diff --git a/unmaintained/io/shell.factor b/unmaintained/io/shell.factor deleted file mode 100644 index 5213eb22c7..0000000000 --- a/unmaintained/io/shell.factor +++ /dev/null @@ -1,40 +0,0 @@ -USING: calendar io io-internals kernel math namespaces -nonblocking-io prettyprint quotations sequences ; -IN: shell - -SYMBOL: shell -HOOK: directory* shell ( path -- seq ) -HOOK: make-file shell ( bytes -- file ) -HOOK: file. shell ( file -- ) -HOOK: touch-file shell ( path -- ) - -: (ls) ( path -- ) - >r H{ } r> directory* - [ - [ [ make-file file. ] with-row ] each - ] curry tabular-output ; - -: ls ( -- ) - cwd (ls) ; - -: pwd ( -- ) - cwd pprint nl ; - -: (slurp) ( quot -- ) - >r default-buffer-size read r> over [ - dup slip (slurp) - ] [ - 2drop - ] if ; - -: slurp ( stream quot -- ) - [ (slurp) ] curry with-stream ; - -: cat ( path -- ) - stdio get - duplex-stream-out - [ write ] slurp ; - -: copy-file ( path path -- ) - >r r> - [ write ] slurp ; diff --git a/unmaintained/io/test/io.factor b/unmaintained/io/test/io.factor deleted file mode 100644 index 379e1233f0..0000000000 --- a/unmaintained/io/test/io.factor +++ /dev/null @@ -1,42 +0,0 @@ -USING: calendar errors io kernel libs-io math namespaces sequences -shell test ; -IN: temporary - -SYMBOL: file "file-appender-test.txt" \ file set -[ \ file get delete-file ] catch drop -[ f ] [ \ file get exists? ] unit-test -\ file get [ "asdf" write ] with-stream -[ t ] [ \ file get exists? ] unit-test -[ 4 ] [ \ file get file-length ] unit-test -\ file get [ "jkl;" write ] with-stream -[ t ] [ \ file get exists? ] unit-test -[ 8 ] [ \ file get file-length ] unit-test -[ "asdfjkl;" ] [ \ file get contents ] unit-test -\ file get delete-file -[ f ] [ \ file get exists? ] unit-test - -SYMBOL: directory "test-directory" \ directory set -\ directory get create-directory -[ t ] [ \ directory get directory? ] unit-test -\ directory get delete-directory -[ f ] [ \ directory get directory? ] unit-test - -SYMBOL: time "time-test.txt" \ time set -[ \ time get delete-file ] catch drop -\ time get touch-file -[ 0 ] [ \ time get file-length ] unit-test -[ t ] [ \ time get exists? ] unit-test -\ time get 0 unix-time>timestamp dup set-file-times -[ t ] [ \ time get file-write-time 0 unix-time>timestamp = ] unit-test -[ t ] [ \ time get file-access-time 0 unix-time>timestamp = ] unit-test -\ time get touch-file -[ t ] [ now \ time get file-write-time timestamp- 10 < ] unit-test -\ time get delete-file - -SYMBOL: longname "" 255 CHAR: a pad-left \ longname set -\ longname get touch-file -[ t ] [ \ longname get exists? ] unit-test -[ 0 ] [ \ longname get file-length ] unit-test -\ longname get delete-file -[ f ] [ \ longname get exists? ] unit-test - diff --git a/unmaintained/io/test/mmap.factor b/unmaintained/io/test/mmap.factor deleted file mode 100644 index faeca551c0..0000000000 --- a/unmaintained/io/test/mmap.factor +++ /dev/null @@ -1,21 +0,0 @@ -USING: alien errors io kernel libs-io mmap namespaces test ; - -IN: temporary -SYMBOL: mmap "mmap-test.txt" \ mmap set - -[ \ mmap get delete-file ] catch drop -\ mmap get [ - "Four" write -] with-file-writer - -\ mmap get [ - >r CHAR: R r> mmap-address 3 set-alien-unsigned-1 -] with-mmap - -\ mmap get [ - mmap-address 3 alien-unsigned-1 CHAR: R = [ - "mmap test failed" throw - ] unless -] with-mmap - -[ \ mmap get delete-file ] catch drop From 8f0b335f4b7c3acbbd3240231ceef6bd415626d7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:13:50 -0600 Subject: [PATCH 13/39] Clean up --- basis/ui/gadgets/frames/frames.factor | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/basis/ui/gadgets/frames/frames.factor b/basis/ui/gadgets/frames/frames.factor index c210d1b7e2..2005fefed7 100644 --- a/basis/ui/gadgets/frames/frames.factor +++ b/basis/ui/gadgets/frames/frames.factor @@ -11,16 +11,16 @@ TUPLE: frame < grid ; : ( -- grid ) 9 [ ] replicate 3 group ; -: @center 1 1 ; -: @left 0 1 ; -: @right 2 1 ; -: @top 1 0 ; -: @bottom 1 2 ; +: @center 1 1 ; inline +: @left 0 1 ; inline +: @right 2 1 ; inline +: @top 1 0 ; inline +: @bottom 1 2 ; inline -: @top-left 0 0 ; -: @top-right 2 0 ; -: @bottom-left 0 2 ; -: @bottom-right 2 2 ; +: @top-left 0 0 ; inline +: @top-right 2 0 ; inline +: @bottom-left 0 2 ; inline +: @bottom-right 2 2 ; inline : new-frame ( class -- frame ) swap new-grid ; inline @@ -28,13 +28,12 @@ TUPLE: frame < grid ; : ( -- frame ) frame new-frame ; -: (fill-center) ( vec n -- ) - over first pick third v+ [v-] 1 rot set-nth ; +: (fill-center) ( n vec -- ) + [ [ first ] [ third ] bi v+ [v-] ] keep set-second ; -: fill-center ( horiz vert dim -- ) - tuck (fill-center) (fill-center) ; +: fill-center ( dim horiz vert -- ) + [ over ] dip [ (fill-center) ] 2bi@ ; M: frame layout* dup compute-grid - [ rot rect-dim fill-center ] 3keep - grid-layout ; + [ [ rect-dim ] 2dip fill-center ] [ grid-layout ] 3bi ; From bcd2ffc830fa5d35b39872462fe52cc7d8e00cbb Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:57:59 -0600 Subject: [PATCH 14/39] If rendering an error popup fails, don't open an endless stream --- basis/ui/gadgets/worlds/worlds.factor | 4 ++-- basis/ui/tools/debugger/debugger.factor | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/basis/ui/gadgets/worlds/worlds.factor b/basis/ui/gadgets/worlds/worlds.factor index 6f901c37ee..e338d6d4f4 100644 --- a/basis/ui/gadgets/worlds/worlds.factor +++ b/basis/ui/gadgets/worlds/worlds.factor @@ -30,7 +30,7 @@ ERROR: no-world-found ; : (request-focus) ( child world ? -- ) pick parent>> pick eq? [ - >r >r dup parent>> dup r> r> + [ dup parent>> dup ] 2dip [ (request-focus) ] keep ] unless focus-child ; @@ -80,7 +80,7 @@ SYMBOL: ui-error-hook : ui-error ( error -- ) ui-error-hook get [ call ] [ print-error ] if* ; -[ rethrow ] ui-error-hook set-global +ui-error-hook global [ [ rethrow ] or ] change-at : draw-world ( world -- ) dup draw-world? [ diff --git a/basis/ui/tools/debugger/debugger.factor b/basis/ui/tools/debugger/debugger.factor index 4ba4374bb8..1f019fca7c 100644 --- a/basis/ui/tools/debugger/debugger.factor +++ b/basis/ui/tools/debugger/debugger.factor @@ -35,7 +35,15 @@ M: debugger focusable-child* restarts>> ; #! No restarts for the debugger window f [ drop ] "Error" open-window ; -[ debugger-window ] ui-error-hook set-global +GENERIC: error-in-debugger? ( error -- ? ) + +M: world-error error-in-debugger? world>> gadget-child debugger? ; + +M: object error-in-debugger? drop f ; + +[ + dup error-in-debugger? [ rethrow ] [ debugger-window ] if +] ui-error-hook set-global M: world-error error. "An error occurred while drawing the world " write From 4af2592369d2ddeb41436398b84be36e45a09a6f Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 19 Nov 2008 21:58:45 -0600 Subject: [PATCH 15/39] Fix some scrollers problems --- .../gadgets/scrollers/scrollers-tests.factor | 23 ++++++- basis/ui/gadgets/scrollers/scrollers.factor | 62 ++++++++++--------- 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/basis/ui/gadgets/scrollers/scrollers-tests.factor b/basis/ui/gadgets/scrollers/scrollers-tests.factor index 625bfd7880..d6792abd49 100644 --- a/basis/ui/gadgets/scrollers/scrollers-tests.factor +++ b/basis/ui/gadgets/scrollers/scrollers-tests.factor @@ -2,7 +2,8 @@ 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 math.geometry.rect accessors ; +tools.test.ui math.geometry.rect accessors ui.gadgets.buttons +ui.gadgets.packs ; IN: ui.gadgets.scrollers.tests [ ] [ @@ -74,7 +75,7 @@ dup layout "g2" get scroll>gadget "s" get layout "s" get scroller-value - ] map [ { 3 0 } = ] all? + ] map [ { 2 0 } = ] all? ] unit-test [ ] [ "Hi"