From e17b9119293783728e193b29856d81ba5862c8eb Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 4 Oct 2019 18:15:19 -0700 Subject: [PATCH 01/10] sequences.generalizations: fix finish-nfind use of times. (that didn't work in optimizing compiler). --- basis/sequences/generalizations/generalizations.factor | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/basis/sequences/generalizations/generalizations.factor b/basis/sequences/generalizations/generalizations.factor index 207d7e8393..5290e60777 100644 --- a/basis/sequences/generalizations/generalizations.factor +++ b/basis/sequences/generalizations/generalizations.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2009 Joe Groff. ! See http://factorcode.org/license.txt for BSD license. -USING: combinators fry generalizations kernel macros math -math.order memoize.private sequences sequences.private ; +USING: arrays combinators fry generalizations kernel macros math +math.order memoize.private quotations sequences +sequences.private ; IN: sequences.generalizations MACRO: (nsequence) ( n -- quot ) @@ -128,10 +129,10 @@ MACRO: nmap-reduce ( map-quot reduce-quot n -- quot ) (neach) all-integers? ; inline MACRO: finish-nfind ( n -- quot ) - [ 1 + ] keep dup dup dup '[ + [ 1 + ] keep dup dup dup f >quotation '[ _ npick [ [ dup ] _ ndip _ nnth-unsafe ] - [ _ ndrop _ [ f ] times ] + [ _ ndrop @ ] if ] ; From fcfe24f98b07025caf2c29745dee4551a393ad4f Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 4 Oct 2019 18:15:59 -0700 Subject: [PATCH 02/10] fry: improve syntax for _ and @ to throw when not used in a fry quotation. --- basis/fry/fry.factor | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/basis/fry/fry.factor b/basis/fry/fry.factor index 27292e7012..9e6fc75e77 100644 --- a/basis/fry/fry.factor +++ b/basis/fry/fry.factor @@ -1,11 +1,16 @@ ! Copyright (C) 2009 Slava Pestov, Eduardo Cavazos, Joe Groff. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors combinators kernel locals.backend math parser -quotations sequences sets splitting words ; +USING: accessors combinators kernel locals.backend math +namespaces parser quotations sequences sets splitting words ; IN: fry -: _ ( -- * ) "Only valid inside a fry" throw ; -: @ ( -- * ) "Only valid inside a fry" throw ; +ERROR: not-in-a-fry ; + +SYMBOL: in-fry? + +SYNTAX: _ in-fry? get [ \ _ suffix! ] [ not-in-a-fry ] if ; + +SYNTAX: @ in-fry? get [ \ @ suffix! ] [ not-in-a-fry ] if ; ERROR: >r/r>-in-fry-error ; @@ -17,7 +22,7 @@ GENERIC: fry ( quot -- quot' ) dup { load-local load-locals get-local drop-locals } intersect [ >r/r>-in-fry-error ] unless-empty ; -PREDICATE: fry-specifier < word { _ @ } member-eq? ; +PREDICATE: fry-specifier < word { POSTPONE: _ POSTPONE: @ } member-eq? ; GENERIC: count-inputs ( quot -- n ) @@ -89,11 +94,11 @@ INSTANCE: fried-callable fried [ >quotation 1quotation prefix ] if-empty ; : mark-composes ( quot -- quot' ) - [ dup \ @ = [ drop [ _ @ ] ] [ 1quotation ] if ] map concat ; inline + [ dup \ @ = [ drop [ POSTPONE: _ POSTPONE: @ ] ] [ 1quotation ] if ] map concat ; inline : shallow-fry ( quot -- quot' ) check-fry mark-composes - { _ } split convert-curries + { POSTPONE: _ } split convert-curries [ [ [ ] ] [ [ ] (make-curry) but-last ] if-zero ] [ shallow-spread>quot swap [ [ ] (make-curry) compose ] unless-zero ] if-empty ; @@ -145,4 +150,4 @@ M: callable fry ( quot -- quot' ) ] bi ] if-empty ; -SYNTAX: '[ parse-quotation fry append! ; +SYNTAX: '[ t in-fry? [ parse-quotation ] with-variable fry append! ; From 0a64678c2d64200e25d57652b919f435a3b5b09c Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 4 Oct 2019 18:31:04 -0700 Subject: [PATCH 03/10] stack-checker.values: fix for fry change. --- basis/stack-checker/values/values.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/stack-checker/values/values.factor b/basis/stack-checker/values/values.factor index 72a79a3f71..e25212abe3 100644 --- a/basis/stack-checker/values/values.factor +++ b/basis/stack-checker/values/values.factor @@ -122,7 +122,7 @@ M: f (literal) current-word get bad-macro-input ; GENERIC: known>callable ( known -- quot ) : ?@ ( x -- y ) - dup callable? [ drop _ ] unless ; + dup callable? [ drop \ _ ] unless ; M: object known>callable drop \ _ ; From 0e958ca21ca69c207d1187d30b857a91e9c0a7e1 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Fri, 4 Oct 2019 18:55:30 -0700 Subject: [PATCH 04/10] fry: update docs for syntax change. --- basis/fry/fry-docs.factor | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/basis/fry/fry-docs.factor b/basis/fry/fry-docs.factor index db1681dae0..f0fa6a633a 100644 --- a/basis/fry/fry-docs.factor +++ b/basis/fry/fry-docs.factor @@ -19,7 +19,7 @@ HELP: fry HELP: '[ { $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 @ } "." } +{ $description "Literal fried quotation. Expands into code which takes values from the stack and substitutes them in place of the fry specifiers " { $link POSTPONE: _ } " and " { $link POSTPONE: @ } "." } { $examples "See " { $link "fry.examples" } "." } ; HELP: >r/r>-in-fry-error @@ -30,26 +30,26 @@ ARTICLE: "fry.examples" "Examples of fried quotations" $nl "If a quotation does not contain any fry specifiers, then " { $link POSTPONE: '[ } " behaves just like " { $link POSTPONE: [ } ":" { $code "{ 10 20 30 } '[ . ] each" } -"Occurrences of " { $link _ } " on the left map directly to " { $link curry } ". That is, the following three lines are equivalent:" +"Occurrences of " { $link POSTPONE: _ } " on the left map directly to " { $link curry } ". That is, the following three lines are equivalent:" { $code "{ 10 20 30 } 5 '[ _ + ] map" "{ 10 20 30 } 5 [ + ] curry map" "{ 10 20 30 } [ 5 + ] map" } -"Occurrences of " { $link _ } " in the middle of a quotation map to more complex quotation composition patterns. The following three lines are equivalent:" +"Occurrences of " { $link POSTPONE: _ } " in the middle of a quotation map to more complex quotation composition patterns. The following three lines are equivalent:" { $code "{ 10 20 30 } 5 '[ 3 _ / ] map" "{ 10 20 30 } 5 [ 3 ] swap [ / ] curry compose map" "{ 10 20 30 } [ 3 5 / ] map" } -"Occurrences of " { $link @ } " are simply syntax sugar for " { $snippet "_ call" } ". The following four lines are equivalent:" +"Occurrences of " { $link POSTPONE: @ } " are simply syntax sugar for " { $snippet "_ call" } ". The following four lines are equivalent:" { $code "{ 10 20 30 } [ sq ] '[ @ . ] each" "{ 10 20 30 } [ sq ] [ call . ] curry each" "{ 10 20 30 } [ sq ] [ . ] compose each" "{ 10 20 30 } [ sq . ] each" } -"The " { $link _ } " and " { $link @ } " specifiers may be freely mixed, and the result is considerably more concise and readable than the version using " { $link curry } " and " { $link compose } " directly:" +"The " { $link POSTPONE: _ } " and " { $link POSTPONE: @ } " specifiers may be freely mixed, and the result is considerably more concise and readable than the version using " { $link curry } " and " { $link compose } " directly:" { $code "{ 8 13 14 27 } [ even? ] 5 '[ @ dup _ ? ] map" "{ 8 13 14 27 } [ even? ] 5 [ dup ] swap [ ? ] curry compose compose map" @@ -83,15 +83,15 @@ $nl { $subsections POSTPONE: '[ } "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:" { $subsections - _ - @ + POSTPONE: _ + POSTPONE: @ } "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." { $subsections "fry.examples" "fry.philosophy" } -"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)." +"Fry is implemented as a parsing word which reads a quotation and scans for occurrences of " { $link POSTPONE: _ } " and " { $link POSTPONE: @ } "; 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:" { $subsections fry } From c19d6517a91ee5c366c4d54b3865b3827a3a4e64 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 5 Oct 2019 16:03:22 +0000 Subject: [PATCH 05/10] furnace.redirection: Fix for unloaded vocabularies in lint. --- basis/furnace/redirection/redirection-docs.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/furnace/redirection/redirection-docs.factor b/basis/furnace/redirection/redirection-docs.factor index cc19e421c8..66d61fd7ec 100644 --- a/basis/furnace/redirection/redirection-docs.factor +++ b/basis/furnace/redirection/redirection-docs.factor @@ -50,7 +50,7 @@ $nl } ; ARTICLE: "furnace.redirection" "Furnace redirection support" -"The " { $vocab-link "furnace.redirection" } " vocabulary builds additional functionality on top of " { $vocab-link "http.server.redirection" } ", and integrates with various Furnace features such as " { $link "furnace.asides" } " and " { $link "furnace.conversations" } "." +"The " { $vocab-link "furnace.redirection" } " vocabulary builds additional functionality on top of " { $vocab-link "http.server.redirection" } ", and integrates with various Furnace features such as " { $vocab-link "furnace.asides" } " and " { $vocab-link "furnace.conversations" } "." $nl "A redirection response which takes asides and conversations into account:" { $subsections } From abf36e89aefefbb6afd3276bb2ec3107571f85e5 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 5 Oct 2019 12:02:30 -0500 Subject: [PATCH 06/10] furnace.utilities: Allow for unloaded vocab to pass help-lint. --- basis/furnace/utilities/utilities-docs.factor | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/basis/furnace/utilities/utilities-docs.factor b/basis/furnace/utilities/utilities-docs.factor index 74b01ce75f..40d5d8ea49 100644 --- a/basis/furnace/utilities/utilities-docs.factor +++ b/basis/furnace/utilities/utilities-docs.factor @@ -34,19 +34,19 @@ HELP: hidden-form-field HELP: link-attr { $values { "tag" tag } { "responder" "a responder" } } { $contract "Modifies an XHTML " { $snippet "a" } " tag." } -{ $notes "This word is called by " { $link "html.templates.chloe.tags.form" } "." } +{ $notes "This word is called by " { $vocab-link "html.templates.chloe" } "." } { $examples "Conversation scope adds attributes to link tags." } ; HELP: modify-form { $values { "responder" "a responder" } { "xml/f" "an XML chunk or f" } } { $contract "Emits hidden form fields using " { $link hidden-form-field } "." } -{ $notes "This word is called by " { $link "html.templates.chloe.tags.form" } "." } +{ $notes "This word is called by " { $vocab-link "html.templates.chloe" } "." } { $examples "Session management, conversation scope and asides use hidden form fields to pass state." } ; HELP: modify-query { $values { "query" assoc } { "responder" "a responder" } { "query'" assoc } } { $contract "Modifies the query parameters of a URL destined to be displayed as a link." } -{ $notes "This word is called by " { $link "html.templates.chloe.tags.form" } "." } +{ $notes "This word is called by " { $vocab-link "html.templates.chloe" } "." } { $examples "Asides add query parameters to URLs." } ; HELP: modify-redirect-query From 78c3a99a31d02fc93fb41bc021cc4464f462aace Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 5 Oct 2019 12:04:14 -0500 Subject: [PATCH 07/10] zealot.help-lint: Add a help-lint for travisci that ignores a lot of flaky resource leaks. Some work needs to be done with ensuring that resources are cleaned up before reporting resource leaks and exiting. In the meantime, we want TravisCI to be useful enough to catch help-lint errors, so ignore a bunch of errors that it might find. These leaks are still tested for in the more thorough mason CI. --- .travis.yml | 2 +- extra/zealot/help-lint/authors.txt | 1 + extra/zealot/help-lint/help-lint.factor | 30 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 extra/zealot/help-lint/authors.txt create mode 100644 extra/zealot/help-lint/help-lint.factor diff --git a/.travis.yml b/.travis.yml index 72c09be6c8..791416095e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,5 +72,5 @@ script: - "./factor -e='USING: memory vocabs.hierarchy ; \"zealot\" load save'" - './factor -run=zealot.cli-changed-vocabs' - './factor -run=tools.test `./factor -run=zealot.cli-changed-vocabs | paste -s -d " " -`' - - './factor -run=help.lint `./factor -run=zealot.cli-changed-vocabs | paste -s -d " " -`' + - './factor -run=zealot.help-lint `./factor -run=zealot.cli-changed-vocabs | paste -s -d " " -`' - "./factor -e='USING: modern.paths tools.test sequences system kernel math random ; core-vocabs os macosx? [ dup length 3 /i sample ] when [ test ] each'" diff --git a/extra/zealot/help-lint/authors.txt b/extra/zealot/help-lint/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/zealot/help-lint/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/zealot/help-lint/help-lint.factor b/extra/zealot/help-lint/help-lint.factor new file mode 100644 index 0000000000..76b6f5a67f --- /dev/null +++ b/extra/zealot/help-lint/help-lint.factor @@ -0,0 +1,30 @@ +! Copyright (C) 2019 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: assocs cache command-line help.lint io io.monitors kernel +namespaces prettyprint sequences system vocabs.hierarchy ; +IN: zealot.help-lint + +! FIXME: help-lint sometimes lists monitors and event-streams as leaked. +! event-stream is macosx-only so hack it into a string +CONSTANT: ignored-resources { + "linux-monitor" "macosx-monitor" "malloc-ptr" + "epoll-mx" "server-port" "openssl-context" + "cache-assoc" "input-port" "fd" "output-port" "stdin" + "event-stream" +} + +: filter-flaky-resources ( seq -- seq' ) + [ drop unparse ignored-resources member? ] assoc-reject ; + +! Allow testing without calling exit +: zealot-help-lint ( exit? -- ) + command-line get [ load ] each + help-lint-all + lint-failures get filter-flaky-resources + [ nip assoc-empty? [ "==== FAILING LINT" print :lint-failures flush ] unless ] + [ swap [ 0 1 ? (exit) ] [ drop ] if ] 2bi ; + +: zealot-help-lint-main ( -- ) + t zealot-help-lint ; + +MAIN: zealot-help-lint-main \ No newline at end of file From 28f0f471d373fda5cbaf623c3fa4c55ab9b3f218 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 5 Oct 2019 14:32:35 -0700 Subject: [PATCH 08/10] alien.data.map: fix use of _ for fry change. --- extra/alien/data/map/map.factor | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extra/alien/data/map/map.factor b/extra/alien/data/map/map.factor index 994eb3272b..4b871ce5ae 100644 --- a/extra/alien/data/map/map.factor +++ b/extra/alien/data/map/map.factor @@ -85,7 +85,8 @@ MACRO: unpack-params ( ins -- quot ) [ c-type-count nip '[ _ firstn-unsafe ] ] map '[ _ spread ] ; MACRO: pack-params ( outs -- quot ) - [ ] [ c-type-count nip dup [ [ ndip _ ] dip set-firstn ] 3curry ] reduce + [ ] [ c-type-count nip dup + [ [ ndip POSTPONE: _ ] dip set-firstn ] 3curry ] reduce fry [ call ] compose ; :: [data-map] ( ins outs param-quot -- quot ) From 85d7fc9d307b8edd109942a2d4cc66b1ec42c3b6 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sat, 5 Oct 2019 16:40:57 -0700 Subject: [PATCH 09/10] talks.olug-talk: fix link to new syntax _. --- extra/talks/otug-talk/otug-talk.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/talks/otug-talk/otug-talk.factor b/extra/talks/otug-talk/otug-talk.factor index 89beedf7cd..8bdde809c6 100644 --- a/extra/talks/otug-talk/otug-talk.factor +++ b/extra/talks/otug-talk/otug-talk.factor @@ -54,7 +54,7 @@ CONSTANT: otug-slides { "Suppose we want a " { $snippet "remove-comments*" } " word" } { $code ": remove-comments* ( lines string -- lines' )" " [ ??? head? ] reject ;" } { "We use " { $link POSTPONE: '[ } " instead of " { $link POSTPONE: [ } } - { "Create “holes” with " { $link _ } } + { "Create “holes” with " { $link POSTPONE: _ } } "Holes filled in left to right when quotation pushed on the stack" } { $slide "Constructing quotations" From 840ecce776af6fa15d05926b4c31d60a9e4a5a1b Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Sun, 6 Oct 2019 03:41:10 -0700 Subject: [PATCH 10/10] talks.otug-talk: forgot a second $link. --- extra/talks/otug-talk/otug-talk.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/talks/otug-talk/otug-talk.factor b/extra/talks/otug-talk/otug-talk.factor index 8bdde809c6..bb18d724de 100644 --- a/extra/talks/otug-talk/otug-talk.factor +++ b/extra/talks/otug-talk/otug-talk.factor @@ -59,7 +59,7 @@ CONSTANT: otug-slides } { $slide "Constructing quotations" { $code ": remove-comments* ( lines string -- lines' )" " '[ _ head? ] reject ;" "" ": remove-comments ( lines -- lines' )" " \"#\" remove-comments* ;" } - { { $link @ } " inserts a quotation" } + { { $link POSTPONE: @ } " inserts a quotation" } { $code ": replicate ( n quot -- seq )" " '[ drop @ ] map ;" } { $code "10 [ 1 10 [a,b] random ] replicate ." } }