From d52535b63a71b216cac816cc87fe14db0ca57924 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 13:42:38 -0500 Subject: [PATCH 01/14] set non-key/value attributes to themselves --- extra/html/parser/parser-tests.factor | 2 +- extra/html/parser/parser.factor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/html/parser/parser-tests.factor b/extra/html/parser/parser-tests.factor index 25251159b1..ca276fc54e 100644 --- a/extra/html/parser/parser-tests.factor +++ b/extra/html/parser/parser-tests.factor @@ -50,7 +50,7 @@ V{ { "foo" "bar" } { "href" "http://factorcode.org/" } { "baz" "quux" } - { "nofollow" f } + { "nofollow" "nofollow" } } f f } } ] [ "" parse-html ] unit-test diff --git a/extra/html/parser/parser.factor b/extra/html/parser/parser.factor index 4aae6a25c4..61315a4925 100644 --- a/extra/html/parser/parser.factor +++ b/extra/html/parser/parser.factor @@ -85,7 +85,7 @@ SYMBOL: tagstack : parse-key/value ( state-parser -- key value ) [ read-key >lower ] [ skip-whitespace "=" take-sequence ] - [ swap [ read-value ] [ drop f ] if ] tri ; + [ swap [ read-value ] [ drop dup ] if ] tri ; : (parse-attributes) ( state-parser -- ) skip-whitespace From 1e4eebda3a5e82bcdf30ee5e30790f2c2161ca39 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 14:36:08 -0500 Subject: [PATCH 02/14] refactor state parser some more, add a word to parse escaped strings --- extra/html/parser/state/state-tests.factor | 14 +++++++++++ extra/html/parser/state/state.factor | 29 +++++++++++++++------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/extra/html/parser/state/state-tests.factor b/extra/html/parser/state/state-tests.factor index 6766cfddc2..4e0d512e89 100644 --- a/extra/html/parser/state/state-tests.factor +++ b/extra/html/parser/state/state-tests.factor @@ -52,3 +52,17 @@ IN: html.parser.state.tests [ "cd" ] [ "abcd" [ "ab" take-sequence drop ] [ "cd" take-sequence ] bi ] unit-test + + +[ f ] +[ + "\"abc\" asdf" + [ CHAR: \ CHAR: " take-quoted-string drop ] [ "asdf" take-sequence ] bi +] unit-test + +[ "asdf" ] +[ + "\"abc\" asdf" + [ CHAR: \ CHAR: " take-quoted-string drop ] + [ skip-whitespace "asdf" take-sequence ] bi +] unit-test diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 4a050306e9..22e901a310 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. USING: namespaces math kernel sequences accessors fry circular -unicode.case unicode.categories locals ; +unicode.case unicode.categories locals combinators.short-circuit ; IN: html.parser.state @@ -12,21 +12,22 @@ TUPLE: state-parser sequence n ; swap >>sequence 0 >>n ; -: state-parser-nth ( n state-parser -- char/f ) - sequence>> ?nth ; inline +: offset ( state-parser offset -- char/f ) + swap + [ n>> + ] [ sequence>> ?nth ] bi ; inline -: current ( state-parser -- char/f ) - [ n>> ] keep state-parser-nth ; inline +: current ( state-parser -- char/f ) 0 offset ; inline -: previous ( state-parser -- char/f ) - [ n>> 1 - ] keep state-parser-nth ; inline +: previous ( state-parser -- char/f ) -1 offset ; inline -: peek-next ( state-parser -- char/f ) - [ n>> 1 + ] keep state-parser-nth ; inline +: peek-next ( state-parser -- char/f ) 1 offset ; inline : advance ( state-parser -- state-parser ) [ 1 + ] change-n ; inline +: advance* ( state-parser -- ) + advance drop ; inline + : get+increment ( state-parser -- char/f ) [ current ] [ advance drop ] bi ; inline @@ -80,3 +81,13 @@ TUPLE: state-parser sequence n ; : state-parse ( sequence quot -- ) [ ] dip call ; inline + +:: take-quoted-string ( state-parser escape-char quote-char -- string ) + state-parser advance + [ + { + [ { [ previous quote-char = ] [ current quote-char = ] } 1&& ] + [ current quote-char = not ] + } 1|| + ] take-while + state-parser advance* ; From 947bcc3d3323e9895a8b8ea187a8f1fcfbf08a80 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 14:50:43 -0500 Subject: [PATCH 03/14] state-parser take-quoted-string rewinds if the string is not found --- extra/html/parser/state/state-tests.factor | 13 +++++++++++++ extra/html/parser/state/state.factor | 9 +++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/extra/html/parser/state/state-tests.factor b/extra/html/parser/state/state-tests.factor index 4e0d512e89..316fe31805 100644 --- a/extra/html/parser/state/state-tests.factor +++ b/extra/html/parser/state/state-tests.factor @@ -66,3 +66,16 @@ IN: html.parser.state.tests [ CHAR: \ CHAR: " take-quoted-string drop ] [ skip-whitespace "asdf" take-sequence ] bi ] unit-test + +[ f ] +[ + "\"abc asdf" + CHAR: \ CHAR: " take-quoted-string +] unit-test + +[ "\"abc" ] +[ + "\"abc asdf" + [ CHAR: \ CHAR: " take-quoted-string drop ] + [ "\"abc" take-sequence ] bi +] unit-test diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 22e901a310..8a9084b91b 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -83,11 +83,16 @@ TUPLE: state-parser sequence n ; [ ] dip call ; inline :: take-quoted-string ( state-parser escape-char quote-char -- string ) + state-parser n>> :> start-n state-parser advance [ { [ { [ previous quote-char = ] [ current quote-char = ] } 1&& ] [ current quote-char = not ] } 1|| - ] take-while - state-parser advance* ; + ] take-while :> string + state-parser current quote-char = [ + state-parser advance* string + ] [ + start-n state-parser (>>n) f + ] if ; From 432ff9b07fbe4da2f23c8cabec4c2c4637df99c8 Mon Sep 17 00:00:00 2001 From: Joe Groff Date: Wed, 1 Apr 2009 14:52:43 -0500 Subject: [PATCH 04/14] Make math.blas library and ABI choice configurable --- basis/alien/fortran/fortran-docs.factor | 8 +++---- basis/math/blas/config/config-docs.factor | 23 +++++++++++++++++++ basis/math/blas/config/config.factor | 23 +++++++++++++++++++ basis/math/blas/ffi/ffi.factor | 15 +++--------- basis/math/blas/matrices/matrices-docs.factor | 5 ++-- 5 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 basis/math/blas/config/config-docs.factor create mode 100644 basis/math/blas/config/config.factor diff --git a/basis/alien/fortran/fortran-docs.factor b/basis/alien/fortran/fortran-docs.factor index c5d124e198..8027020c75 100644 --- a/basis/alien/fortran/fortran-docs.factor +++ b/basis/alien/fortran/fortran-docs.factor @@ -7,10 +7,10 @@ IN: alien.fortran ARTICLE: "alien.fortran-abis" "Fortran ABIs" "Fortran does not have a standard ABI like C does. Factor supports the following Fortran ABIs:" { $list - { { $subsection gfortran-abi } " is used by gfortran, the Fortran compiler included with GCC 4." } - { { $subsection f2c-abi } " is used by the F2C Fortran-to-C translator and G77, the Fortran compiler included with GCC 3.x and earlier. It is also used by gfortran when compiling with the -ff2c flag." } - { { $subsection intel-unix-abi } " is used by the Intel Fortran Compiler on Linux and Mac OS X." } - { { $subsection intel-windows-abi } " is used by the Intel Fortran Compiler on Windows." } + { { $link gfortran-abi } " is used by gfortran, the Fortran compiler included with GCC 4." } + { { $link f2c-abi } " is used by the F2C Fortran-to-C translator and G77, the Fortran compiler included with GCC 3.x and earlier. It is also used by gfortran when compiling with the -ff2c flag." } + { { $link intel-unix-abi } " is used by the Intel Fortran Compiler on Linux and Mac OS X." } + { { $link intel-windows-abi } " is used by the Intel Fortran Compiler on Windows." } } "A library's ABI is specified when that library is opened by the " { $link add-fortran-library } " word." ; diff --git a/basis/math/blas/config/config-docs.factor b/basis/math/blas/config/config-docs.factor new file mode 100644 index 0000000000..60eaff25c2 --- /dev/null +++ b/basis/math/blas/config/config-docs.factor @@ -0,0 +1,23 @@ +USING: alien.fortran help.markup help.syntax math.blas.config multiline ; +IN: math.blas.config + +ARTICLE: "math.blas.config" "Configuring the BLAS interface" +"The " { $link "math.blas-summary" } " chooses the underlying BLAS interface to use based on the values of the following global variables:" +{ $subsection blas-library } +{ $subsection blas-fortran-abi } +"The interface attempts to set default values based on the ones encountered on the Factor project's build machines. If these settings don't work with your system's BLAS, or you wish to use a commercial BLAS, you may change the global values of those variables in your " { $link "factor-rc" } ". For example, to use AMD's ACML library on Windows with " { $snippet "math.blas" } ", your " { $snippet "factor-rc" } " would look like this:" +{ $code <" +USING: math.blas.config namespaces ; +"X:\\path\\to\\acml.dll" blas-library set-global +intel-windows-abi blas-fortran-abi set-global +"> } +"To take effect, the " { $snippet "blas-library" } " and " { $snippet "blas-fortran-abi" } " variables must be set before any other " { $snippet "math.blas" } " vocabularies are loaded." +; + +HELP: blas-library +{ $description "The name of the shared library containing the BLAS interface to load. The value of this variable must be a valid shared library name that can be passed to " { $link add-fortran-library } ". To take effect, this variable must be set before any other " { $snippet "math.blas" } " vocabularies are loaded. See " { $link "math.blas.config" } " for details and examples." } ; + +HELP: blas-fortran-abi +{ $description "The Fortran ABI used by the BLAS interface specified in the " { $link blas-library } " variable. The value of " { $snippet "blas-fortran-abi" } " must be one of the " { $link "alien.fortran-abis" } " that can be passed to " { $link add-fortran-library } ". To take effect, this variable must be set before any other " { $snippet "math.blas" } " vocabularies are loaded. See " { $link "math.blas.config" } " for details and examples." } ; + +ABOUT: "math.blas.config" diff --git a/basis/math/blas/config/config.factor b/basis/math/blas/config/config.factor new file mode 100644 index 0000000000..8ed515625d --- /dev/null +++ b/basis/math/blas/config/config.factor @@ -0,0 +1,23 @@ +USING: alien.fortran combinators kernel namespaces system ; +IN: math.blas.config + +SYMBOLS: blas-library blas-fortran-abi ; + +blas-library [ + { + { [ os macosx? ] [ "libblas.dylib" ] } + { [ os windows? ] [ "blas.dll" ] } + [ "libblas.so" ] + } cond +] initialize + +blas-fortran-abi [ + { + { [ os macosx? ] [ intel-unix-abi ] } + { [ os windows? cpu x86.32? and ] [ f2c-abi ] } + { [ os windows? cpu x86.64? and ] [ gfortran-abi ] } + { [ os freebsd? ] [ gfortran-abi ] } + { [ os linux? cpu x86.32? and ] [ gfortran-abi ] } + [ f2c-abi ] + } cond +] initialize diff --git a/basis/math/blas/ffi/ffi.factor b/basis/math/blas/ffi/ffi.factor index bc98f72d8b..b7748f500f 100644 --- a/basis/math/blas/ffi/ffi.factor +++ b/basis/math/blas/ffi/ffi.factor @@ -1,18 +1,9 @@ -USING: alien alien.fortran kernel system combinators -alien.libraries ; +USING: alien.fortran kernel math.blas.config namespaces ; IN: math.blas.ffi << -"blas" { - { [ os macosx? ] [ "libblas.dylib" intel-unix-abi add-fortran-library ] } - { [ os windows? cpu x86.32? and ] [ "blas.dll" f2c-abi add-fortran-library ] } - { [ os windows? cpu x86.64? and ] [ "blas.dll" gfortran-abi add-fortran-library ] } - { - [ os [ freebsd? ] [ linux? cpu x86.32? and ] bi or ] - [ "libblas.so" gfortran-abi add-fortran-library ] - } - [ "libblas.so" f2c-abi add-fortran-library ] -} cond +"blas" blas-library blas-fortran-abi [ get ] bi@ +add-fortran-library >> LIBRARY: blas diff --git a/basis/math/blas/matrices/matrices-docs.factor b/basis/math/blas/matrices/matrices-docs.factor index 17d2f9ccd1..5662cd9905 100644 --- a/basis/math/blas/matrices/matrices-docs.factor +++ b/basis/math/blas/matrices/matrices-docs.factor @@ -2,13 +2,14 @@ USING: alien byte-arrays help.markup help.syntax math math.blas.vectors sequence IN: math.blas.matrices ARTICLE: "math.blas-summary" "Basic Linear Algebra Subroutines (BLAS) interface" -"Factor provides an interface to high-performance vector and matrix math routines available in the system's BLAS library. A set of specialized types are provided for handling packed, unboxed vector data:" +"Factor provides an interface to high-performance vector and matrix math routines available in implementations of the BLAS math library. A set of specialized types are provided for handling packed, unboxed vector data:" { $subsection "math.blas-types" } "Scalar-vector and vector-vector operations are available in the " { $vocab-link "math.blas.vectors" } " vocabulary:" { $subsection "math.blas.vectors" } "Vector-matrix and matrix-matrix operations are available in the " { $vocab-link "math.blas.matrices" } " vocabulary:" { $subsection "math.blas.matrices" } -"The low-level BLAS Fortran interface can be accessed directly through the " { $vocab-link "math.blas.ffi" } " vocabulary." ; +"The low-level BLAS Fortran interface can be accessed directly through the " { $vocab-link "math.blas.ffi" } " vocabulary. The BLAS interface can be configured to use different underlying BLAS implementations:" +{ $subsection "math.blas.config" } ; ARTICLE: "math.blas-types" "BLAS interface types" "BLAS vectors come in single- and double-precision, real and complex flavors:" From d64e07af8b2b3cd8243b8a4a818209215814e95f Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 15:23:05 -0500 Subject: [PATCH 05/14] fix bug in state-parser, add take-token --- extra/html/parser/state/state-tests.factor | 3 +++ extra/html/parser/state/state.factor | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/extra/html/parser/state/state-tests.factor b/extra/html/parser/state/state-tests.factor index 316fe31805..b7a929284b 100644 --- a/extra/html/parser/state/state-tests.factor +++ b/extra/html/parser/state/state-tests.factor @@ -79,3 +79,6 @@ IN: html.parser.state.tests [ CHAR: \ CHAR: " take-quoted-string drop ] [ "\"abc" take-sequence ] bi ] unit-test + +[ "c" ] +[ "c" take-token ] unit-test diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 8a9084b91b..1b83089c98 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -36,7 +36,7 @@ TUPLE: state-parser sequence n ; state-parser quot call [ state-parser advance quot skip-until ] unless ] when ; inline recursive -: state-parse-end? ( state-parser -- ? ) peek-next not ; +: state-parse-end? ( state-parser -- ? ) current not ; : take-until ( state-parser quot: ( obj -- ? ) -- sequence/f ) over state-parse-end? [ @@ -96,3 +96,6 @@ TUPLE: state-parser sequence n ; ] [ start-n state-parser (>>n) f ] if ; + +: take-token ( state-parser -- string ) + skip-whitespace [ current { [ blank? ] [ f = ] } 1|| ] take-until ; From 6af6de1aacaa7b39c95c9d192a11fe29fb64c7bc Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 15:51:39 -0500 Subject: [PATCH 06/14] make tokenize-line configurable, fix bug in take-quoted-string --- extra/html/parser/state/state-tests.factor | 10 +++++++++- extra/html/parser/state/state.factor | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/extra/html/parser/state/state-tests.factor b/extra/html/parser/state/state-tests.factor index b7a929284b..e655dbb699 100644 --- a/extra/html/parser/state/state-tests.factor +++ b/extra/html/parser/state/state-tests.factor @@ -53,13 +53,18 @@ IN: html.parser.state.tests [ "cd" ] [ "abcd" [ "ab" take-sequence drop ] [ "cd" take-sequence ] bi ] unit-test - [ f ] [ "\"abc\" asdf" [ CHAR: \ CHAR: " take-quoted-string drop ] [ "asdf" take-sequence ] bi ] unit-test +[ "abc\\\"def" ] +[ + "\"abc\\\"def\" asdf" + CHAR: \ CHAR: " take-quoted-string +] unit-test + [ "asdf" ] [ "\"abc\" asdf" @@ -82,3 +87,6 @@ IN: html.parser.state.tests [ "c" ] [ "c" take-token ] unit-test + +[ { "a" "b" "c" "abcd e \\\"f g" } ] +[ "a b c \"abcd e \\\"f g\"" CHAR: \ CHAR: " tokenize-line ] unit-test diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 1b83089c98..6cca9f72a9 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. USING: namespaces math kernel sequences accessors fry circular -unicode.case unicode.categories locals combinators.short-circuit ; +unicode.case unicode.categories locals combinators.short-circuit +make combinators ; IN: html.parser.state @@ -87,7 +88,7 @@ TUPLE: state-parser sequence n ; state-parser advance [ { - [ { [ previous quote-char = ] [ current quote-char = ] } 1&& ] + [ { [ previous escape-char = ] [ current quote-char = ] } 1&& ] [ current quote-char = not ] } 1|| ] take-while :> string @@ -99,3 +100,17 @@ TUPLE: state-parser sequence n ; : take-token ( state-parser -- string ) skip-whitespace [ current { [ blank? ] [ f = ] } 1|| ] take-until ; + +:: (tokenize-line) ( state-parser escape-char quote-char -- ) + state-parser skip-whitespace + dup current { + { quote-char [ + [ escape-char quote-char take-quoted-string , ] + [ escape-char quote-char (tokenize-line) ] bi + ] } + { f [ drop ] } + [ drop [ take-token , ] [ escape-char quote-char (tokenize-line) ] bi ] + } case ; + +: tokenize-line ( line escape-char quote-char -- seq ) + [ ] 2dip [ (tokenize-line) ] { } make ; From 7b6260ca8c8471e20d30a6bffa760cc93f9e0461 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 17:28:36 -0500 Subject: [PATCH 07/14] remove tokenize-line --- extra/html/parser/state/state-tests.factor | 7 +++++-- extra/html/parser/state/state.factor | 17 +++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/extra/html/parser/state/state-tests.factor b/extra/html/parser/state/state-tests.factor index e655dbb699..63916a3c1c 100644 --- a/extra/html/parser/state/state-tests.factor +++ b/extra/html/parser/state/state-tests.factor @@ -88,5 +88,8 @@ IN: html.parser.state.tests [ "c" ] [ "c" take-token ] unit-test -[ { "a" "b" "c" "abcd e \\\"f g" } ] -[ "a b c \"abcd e \\\"f g\"" CHAR: \ CHAR: " tokenize-line ] unit-test +[ f ] +[ "" take-token ] unit-test + +[ "abcd e \\\"f g" ] +[ "\"abcd e \\\"f g\"" CHAR: \ CHAR: " take-token* ] unit-test diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 6cca9f72a9..86adb0f914 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -98,19 +98,16 @@ TUPLE: state-parser sequence n ; start-n state-parser (>>n) f ] if ; -: take-token ( state-parser -- string ) +: (take-token) ( state-parser -- string ) skip-whitespace [ current { [ blank? ] [ f = ] } 1|| ] take-until ; -:: (tokenize-line) ( state-parser escape-char quote-char -- ) +:: take-token* ( state-parser escape-char quote-char -- string/f ) state-parser skip-whitespace dup current { - { quote-char [ - [ escape-char quote-char take-quoted-string , ] - [ escape-char quote-char (tokenize-line) ] bi - ] } - { f [ drop ] } - [ drop [ take-token , ] [ escape-char quote-char (tokenize-line) ] bi ] + { quote-char [ escape-char quote-char take-quoted-string ] } + { f [ drop f ] } + [ drop (take-token) ] } case ; -: tokenize-line ( line escape-char quote-char -- seq ) - [ ] 2dip [ (tokenize-line) ] { } make ; +: take-token ( state-parser -- string/f ) + CHAR: \ CHAR: " take-token* ; From 1b0c301005c9ddedec40cf6cef362d88ff4b0e33 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 17:29:58 -0500 Subject: [PATCH 08/14] move assoc-heaps to extra --- {basis => extra}/assoc-heaps/assoc-heaps-docs.factor | 0 {basis => extra}/assoc-heaps/assoc-heaps-tests.factor | 0 {basis => extra}/assoc-heaps/assoc-heaps.factor | 0 {basis => extra}/assoc-heaps/authors.txt | 0 {basis => extra}/assoc-heaps/summary.txt | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {basis => extra}/assoc-heaps/assoc-heaps-docs.factor (100%) rename {basis => extra}/assoc-heaps/assoc-heaps-tests.factor (100%) rename {basis => extra}/assoc-heaps/assoc-heaps.factor (100%) rename {basis => extra}/assoc-heaps/authors.txt (100%) rename {basis => extra}/assoc-heaps/summary.txt (100%) diff --git a/basis/assoc-heaps/assoc-heaps-docs.factor b/extra/assoc-heaps/assoc-heaps-docs.factor similarity index 100% rename from basis/assoc-heaps/assoc-heaps-docs.factor rename to extra/assoc-heaps/assoc-heaps-docs.factor diff --git a/basis/assoc-heaps/assoc-heaps-tests.factor b/extra/assoc-heaps/assoc-heaps-tests.factor similarity index 100% rename from basis/assoc-heaps/assoc-heaps-tests.factor rename to extra/assoc-heaps/assoc-heaps-tests.factor diff --git a/basis/assoc-heaps/assoc-heaps.factor b/extra/assoc-heaps/assoc-heaps.factor similarity index 100% rename from basis/assoc-heaps/assoc-heaps.factor rename to extra/assoc-heaps/assoc-heaps.factor diff --git a/basis/assoc-heaps/authors.txt b/extra/assoc-heaps/authors.txt similarity index 100% rename from basis/assoc-heaps/authors.txt rename to extra/assoc-heaps/authors.txt diff --git a/basis/assoc-heaps/summary.txt b/extra/assoc-heaps/summary.txt similarity index 100% rename from basis/assoc-heaps/summary.txt rename to extra/assoc-heaps/summary.txt From 318da06a71a837489d07123157ccbc291a678eec Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 1 Apr 2009 22:05:12 -0500 Subject: [PATCH 09/14] ensure-port outputs a new URL instead of mutating its input --- basis/urls/urls-docs.factor | 5 ++--- basis/urls/urls.factor | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/basis/urls/urls-docs.factor b/basis/urls/urls-docs.factor index 707caf3188..eb8e452ca4 100644 --- a/basis/urls/urls-docs.factor +++ b/basis/urls/urls-docs.factor @@ -65,9 +65,8 @@ HELP: derive-url } ; HELP: ensure-port -{ $values { "url" url } } -{ $description "If the URL does not specify a port number, fill in the default for the URL's protocol. If the protocol is unknown, the port number is not changed." } -{ $side-effects "url" } +{ $values { "url" url } { "url'" url } } +{ $description "If the URL does not specify a port number, create a new URL which is equal except the port number is set to the default for the URL's protocol. If the protocol is unknown, outputs an exact copy of the input URL." } { $examples { $example "USING: accessors prettyprint urls ;" diff --git a/basis/urls/urls.factor b/basis/urls/urls.factor index 38d0016d56..1e886ae3e2 100644 --- a/basis/urls/urls.factor +++ b/basis/urls/urls.factor @@ -175,8 +175,8 @@ PRIVATE> ] [ protocol>> ] bi secure-protocol? [ >secure-addr ] when ; -: ensure-port ( url -- url ) - dup protocol>> '[ _ protocol-port or ] change-port ; +: ensure-port ( url -- url' ) + clone dup protocol>> '[ _ protocol-port or ] change-port ; ! Literal syntax SYNTAX: URL" lexer get skip-blank parse-string >url parsed ; From 4dbb2aa491c2a691bcbd2abf5555a7c0ff28bea1 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Wed, 1 Apr 2009 22:24:49 -0500 Subject: [PATCH 10/14] Partial fix for pane selection --- basis/ui/gadgets/panes/panes.factor | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/basis/ui/gadgets/panes/panes.factor b/basis/ui/gadgets/panes/panes.factor index a6bd5c4e29..41e983eb28 100644 --- a/basis/ui/gadgets/panes/panes.factor +++ b/basis/ui/gadgets/panes/panes.factor @@ -75,7 +75,8 @@ M: pane gadget-selection ( pane -- string/f ) GENERIC: draw-selection ( loc obj -- ) : if-fits ( rect quot -- ) - [ clip get over contains-rect? ] dip [ drop ] if ; inline + [ clip get origin get vneg offset-rect over contains-rect? ] dip + [ drop ] if ; inline M: gadget draw-selection ( loc gadget -- ) swap offset-rect [ From 9bee1fe0041be56b814fe47d0cbe09173a8bdcda Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 1 Apr 2009 22:39:20 -0500 Subject: [PATCH 11/14] fix take-rest for out of bounds --- extra/html/parser/state/state-tests.factor | 6 ++++++ extra/html/parser/state/state.factor | 13 ++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/extra/html/parser/state/state-tests.factor b/extra/html/parser/state/state-tests.factor index 63916a3c1c..75db1a373e 100644 --- a/extra/html/parser/state/state-tests.factor +++ b/extra/html/parser/state/state-tests.factor @@ -93,3 +93,9 @@ IN: html.parser.state.tests [ "abcd e \\\"f g" ] [ "\"abcd e \\\"f g\"" CHAR: \ CHAR: " take-token* ] unit-test + +[ "" ] +[ "" take-rest ] unit-test + +[ "" ] +[ "abc" dup "abc" take-sequence drop take-rest ] unit-test diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index 86adb0f914..b7936f6005 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -1,8 +1,8 @@ ! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. USING: namespaces math kernel sequences accessors fry circular -unicode.case unicode.categories locals combinators.short-circuit -make combinators ; +unicode.case ascii locals combinators.short-circuit +make combinators io splitting ; IN: html.parser.state @@ -74,8 +74,12 @@ TUPLE: state-parser sequence n ; : skip-whitespace ( state-parser -- state-parser ) [ [ current blank? not ] take-until drop ] keep ; +: take-rest-slice ( state-parser -- sequence/f ) + [ sequence>> ] [ n>> ] bi + 2dup [ length ] dip < [ 2drop f ] [ tail-slice ] if ; inline + : take-rest ( state-parser -- sequence ) - [ drop f ] take-until ; inline + [ take-rest-slice ] [ sequence>> like ] bi ; : take-until-object ( state-parser obj -- sequence ) '[ current _ = ] take-until ; @@ -111,3 +115,6 @@ TUPLE: state-parser sequence n ; : take-token ( state-parser -- string/f ) CHAR: \ CHAR: " take-token* ; + +: write-full ( state-parser -- ) sequence>> write ; +: write-rest ( state-parser -- ) take-rest write ; From 4ef0344477d4619c5127579279395a2b74aa7289 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Thu, 2 Apr 2009 01:12:09 -0500 Subject: [PATCH 12/14] Tabs are blank (better unicode whitespace support coming soon) --- basis/unicode/categories/categories-tests.factor | 5 +++++ basis/unicode/categories/categories.factor | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/basis/unicode/categories/categories-tests.factor b/basis/unicode/categories/categories-tests.factor index 1e718cf9b7..0970df7ad8 100644 --- a/basis/unicode/categories/categories-tests.factor +++ b/basis/unicode/categories/categories-tests.factor @@ -12,3 +12,8 @@ IN: unicode.categories.tests [ "Lo" ] [ HEX: 3450 category ] unit-test [ "Lo" ] [ HEX: 4DB5 category ] unit-test [ "Cs" ] [ HEX: DD00 category ] unit-test +[ t ] [ CHAR: \t blank? ] unit-test +[ t ] [ CHAR: \s blank? ] unit-test +[ t ] [ CHAR: \r blank? ] unit-test +[ t ] [ CHAR: \n blank? ] unit-test +[ f ] [ CHAR: a blank? ] unit-test diff --git a/basis/unicode/categories/categories.factor b/basis/unicode/categories/categories.factor index 126c03c869..4ca5c9a90e 100644 --- a/basis/unicode/categories/categories.factor +++ b/basis/unicode/categories/categories.factor @@ -3,7 +3,7 @@ USING: unicode.categories.syntax sequences unicode.data ; IN: unicode.categories -CATEGORY: blank Zs Zl Zp | "\r\n" member? ; +CATEGORY: blank Zs Zl Zp | "\r\n\t" member? ; CATEGORY: letter Ll | "Other_Lowercase" property? ; CATEGORY: LETTER Lu | "Other_Uppercase" property? ; CATEGORY: Letter Lu Ll Lt Lm Lo Nl ; From 2325710a4ff61ddbf3624e458e7dff391065622f Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 2 Apr 2009 01:17:36 -0500 Subject: [PATCH 13/14] beginnings of a c preprocessor -- needs #if, #elif, #else --- extra/c/preprocessor/authors.txt | 1 + .../c/preprocessor/preprocessor-tests.factor | 16 ++ extra/c/preprocessor/preprocessor.factor | 155 ++++++++++++++++++ extra/c/tests/test1/README | 1 + extra/c/tests/test1/hi.h | 1 + extra/c/tests/test1/lo.h | 1 + extra/c/tests/test1/test1.c | 1 + extra/c/tests/test2/README | 1 + extra/c/tests/test2/test2.c | 17 ++ extra/c/tests/test3/README | 1 + extra/c/tests/test3/test3.c | 1 + extra/c/tests/test4/test4.c | 2 + 12 files changed, 198 insertions(+) create mode 100644 extra/c/preprocessor/authors.txt create mode 100644 extra/c/preprocessor/preprocessor-tests.factor create mode 100644 extra/c/preprocessor/preprocessor.factor create mode 100644 extra/c/tests/test1/README create mode 100644 extra/c/tests/test1/hi.h create mode 100644 extra/c/tests/test1/lo.h create mode 100644 extra/c/tests/test1/test1.c create mode 100644 extra/c/tests/test2/README create mode 100644 extra/c/tests/test2/test2.c create mode 100644 extra/c/tests/test3/README create mode 100644 extra/c/tests/test3/test3.c create mode 100644 extra/c/tests/test4/test4.c diff --git a/extra/c/preprocessor/authors.txt b/extra/c/preprocessor/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/extra/c/preprocessor/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/extra/c/preprocessor/preprocessor-tests.factor b/extra/c/preprocessor/preprocessor-tests.factor new file mode 100644 index 0000000000..d86b85a1b1 --- /dev/null +++ b/extra/c/preprocessor/preprocessor-tests.factor @@ -0,0 +1,16 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test c.preprocessor kernel accessors ; +IN: c.preprocessor.tests + +[ "vocab:c/tests/test1/test1.c" start-preprocess-file ] +[ include-nested-too-deeply? ] must-fail-with + +[ "yo\n\n\n\nyo4\n" ] +[ "vocab:c/tests/test2/test2.c" start-preprocess-file nip ] unit-test + +[ "vocab:c/tests/test3/test3.c" start-preprocess-file ] +[ "\"BOO\"" = ] must-fail-with + +[ V{ "\"omg\"" "\"lol\"" } ] +[ "vocab:c/tests/test4/test4.c" start-preprocess-file drop warnings>> ] unit-test diff --git a/extra/c/preprocessor/preprocessor.factor b/extra/c/preprocessor/preprocessor.factor new file mode 100644 index 0000000000..89292eb74b --- /dev/null +++ b/extra/c/preprocessor/preprocessor.factor @@ -0,0 +1,155 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: html.parser.state io io.encodings.utf8 io.files +io.streams.string kernel combinators accessors io.pathnames +fry sequences arrays locals namespaces io.directories +assocs math splitting make ; +IN: c.preprocessor + +: initial-library-paths ( -- seq ) + V{ "/usr/include" } clone ; + +TUPLE: preprocessor-state library-paths symbol-table +include-nesting include-nesting-max processing-disabled? +ifdef-nesting warnings ; + +: ( -- preprocessor-state ) + preprocessor-state new + initial-library-paths >>library-paths + H{ } clone >>symbol-table + 0 >>include-nesting + 200 >>include-nesting-max + 0 >>ifdef-nesting + V{ } clone >>warnings ; + +DEFER: preprocess-file + +ERROR: unknown-c-preprocessor state-parser name ; + +ERROR: bad-include-line line ; + +ERROR: header-file-missing path ; + +:: read-standard-include ( preprocessor-state path -- ) + preprocessor-state dup library-paths>> + [ path append-path exists? ] find nip + [ + dup [ + path append-path + preprocess-file + ] with-directory + ] [ + ! path header-file-missing + drop + ] if* ; + +:: read-local-include ( preprocessor-state path -- ) + current-directory get path append-path dup :> full-path + dup exists? [ + [ preprocessor-state ] dip preprocess-file + ] [ + ! full-path header-file-missing + drop + ] if ; + +: handle-include ( preprocessor-state state-parser -- ) + skip-whitespace advance dup previous { + { CHAR: < [ CHAR: > take-until-object read-standard-include ] } + { CHAR: " [ CHAR: " take-until-object read-local-include ] } + [ bad-include-line ] + } case ; + +: (readlns) ( -- ) + readln "\\" ?tail [ , ] dip [ (readlns) ] when ; + +: readlns ( -- string ) [ (readlns) ] { } make concat ; + +: handle-define ( preprocessor-state state-parser -- ) + [ take-token ] [ take-rest ] bi + "\\" ?tail [ readlns append ] when + spin symbol-table>> set-at ; + +: handle-undef ( preprocessor-state state-parser -- ) + take-token swap symbol-table>> delete-at ; + +: handle-ifdef ( preprocessor-state state-parser -- ) + [ [ 1 + ] change-ifdef-nesting ] dip + take-token over symbol-table>> key? + [ drop ] [ t >>processing-disabled? drop ] if ; + +: handle-ifndef ( preprocessor-state state-parser -- ) + [ [ 1 + ] change-ifdef-nesting ] dip + take-token over symbol-table>> key? + [ t >>processing-disabled? drop ] + [ drop ] if ; + +: handle-endif ( preprocessor-state state-parser -- ) + drop [ 1 - ] change-ifdef-nesting drop ; + +: handle-error ( preprocessor-state state-parser -- ) + skip-whitespace + nip take-rest throw ; + +: handle-warning ( preprocessor-state state-parser -- ) + skip-whitespace + take-rest swap warnings>> push ; + +: parse-directive ( preprocessor-state state-parser string -- ) + { + { "warning" [ handle-warning ] } + { "error" [ handle-error ] } + { "include" [ handle-include ] } + { "define" [ handle-define ] } + { "undef" [ handle-undef ] } + { "ifdef" [ handle-ifdef ] } + { "ifndef" [ handle-ifndef ] } + { "endif" [ handle-endif ] } + { "if" [ 2drop ] } + { "elif" [ 2drop ] } + { "else" [ 2drop ] } + { "pragma" [ 2drop ] } + { "include_next" [ 2drop ] } + [ unknown-c-preprocessor ] + } case ; + +: parse-directive-line ( preprocessor-state state-parser -- ) + advance dup take-token + pick processing-disabled?>> [ + "endif" = [ + drop f >>processing-disabled? + [ 1 - ] change-ifdef-nesting + drop + ] [ 2drop ] if + ] [ + parse-directive + ] if ; + +: preprocess-line ( preprocessor-state state-parser -- ) + skip-whitespace dup current CHAR: # = + [ parse-directive-line ] + [ swap processing-disabled?>> [ drop ] [ write-full nl ] if ] if ; + +: preprocess-lines ( preprocessor-state -- ) + readln + [ [ preprocess-line ] [ drop preprocess-lines ] 2bi ] + [ drop ] if* ; + +ERROR: include-nested-too-deeply ; + +: check-nesting ( preprocessor-state -- preprocessor-state ) + [ 1 + ] change-include-nesting + dup [ include-nesting>> ] [ include-nesting-max>> ] bi > [ + include-nested-too-deeply + ] when ; + +: preprocess-file ( preprocessor-state path -- ) + [ check-nesting ] dip + [ utf8 [ preprocess-lines ] with-file-reader ] + [ drop [ 1 - ] change-include-nesting drop ] 2bi ; + +: start-preprocess-file ( path -- preprocessor-state string ) + dup parent-directory [ + [ + [ dup ] dip preprocess-file + ] with-string-writer + ] with-directory ; diff --git a/extra/c/tests/test1/README b/extra/c/tests/test1/README new file mode 100644 index 0000000000..99873133b2 --- /dev/null +++ b/extra/c/tests/test1/README @@ -0,0 +1 @@ +Tests if the preprocessor bails on an infinite loop caused by mutually recursive #include lines. diff --git a/extra/c/tests/test1/hi.h b/extra/c/tests/test1/hi.h new file mode 100644 index 0000000000..c9f337c47a --- /dev/null +++ b/extra/c/tests/test1/hi.h @@ -0,0 +1 @@ +#include "lo.h" diff --git a/extra/c/tests/test1/lo.h b/extra/c/tests/test1/lo.h new file mode 100644 index 0000000000..d59fdd272e --- /dev/null +++ b/extra/c/tests/test1/lo.h @@ -0,0 +1 @@ +#include "hi.h" diff --git a/extra/c/tests/test1/test1.c b/extra/c/tests/test1/test1.c new file mode 100644 index 0000000000..d59fdd272e --- /dev/null +++ b/extra/c/tests/test1/test1.c @@ -0,0 +1 @@ +#include "hi.h" diff --git a/extra/c/tests/test2/README b/extra/c/tests/test2/README new file mode 100644 index 0000000000..4244828197 --- /dev/null +++ b/extra/c/tests/test2/README @@ -0,0 +1 @@ +Tests whether #define and #ifdef/#endif work in the positive case. diff --git a/extra/c/tests/test2/test2.c b/extra/c/tests/test2/test2.c new file mode 100644 index 0000000000..4cc4191db1 --- /dev/null +++ b/extra/c/tests/test2/test2.c @@ -0,0 +1,17 @@ +#define YO +#ifdef YO +yo +#endif + +#define YO2 +#ifndef YO2 +yo2 +#endif + +#ifdef YO3 +yo3 +#endif + +#ifndef YO4 +yo4 +#endif diff --git a/extra/c/tests/test3/README b/extra/c/tests/test3/README new file mode 100644 index 0000000000..4244828197 --- /dev/null +++ b/extra/c/tests/test3/README @@ -0,0 +1 @@ +Tests whether #define and #ifdef/#endif work in the positive case. diff --git a/extra/c/tests/test3/test3.c b/extra/c/tests/test3/test3.c new file mode 100644 index 0000000000..8d08e836b2 --- /dev/null +++ b/extra/c/tests/test3/test3.c @@ -0,0 +1 @@ +#error "BOO" diff --git a/extra/c/tests/test4/test4.c b/extra/c/tests/test4/test4.c new file mode 100644 index 0000000000..5acd20da67 --- /dev/null +++ b/extra/c/tests/test4/test4.c @@ -0,0 +1,2 @@ +#warning "omg" +#warning "lol" From 7c7742cafa7089c2f05837207597e0e0a9bee5b1 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 2 Apr 2009 01:18:53 -0500 Subject: [PATCH 14/14] use unicode instead of ascii again --- extra/html/parser/state/state.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/html/parser/state/state.factor b/extra/html/parser/state/state.factor index b7936f6005..5f845ce810 100644 --- a/extra/html/parser/state/state.factor +++ b/extra/html/parser/state/state.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2009 Daniel Ehrenberg ! See http://factorcode.org/license.txt for BSD license. USING: namespaces math kernel sequences accessors fry circular -unicode.case ascii locals combinators.short-circuit +unicode.case unicode.categories locals combinators.short-circuit make combinators io splitting ; IN: html.parser.state