diff --git a/basis/alien/c-types/c-types-tests.factor b/basis/alien/c-types/c-types-tests.factor index edda9e7fdb..5c4f022e93 100644 --- a/basis/alien/c-types/c-types-tests.factor +++ b/basis/alien/c-types/c-types-tests.factor @@ -56,3 +56,7 @@ TYPEDEF: uchar* MyLPBYTE ] must-fail [ t ] [ { t f t } >c-bool-array { 1 0 1 } >c-int-array = ] unit-test + +os windows? cpu x86.64? and [ + [ -2147467259 ] [ 2147500037 *long ] unit-test +] when diff --git a/basis/checksums/common/common.factor b/basis/checksums/common/common.factor index 1f25efef24..7d5f34777d 100644 --- a/basis/checksums/common/common.factor +++ b/basis/checksums/common/common.factor @@ -18,4 +18,4 @@ SYMBOL: bytes-read ] "" make 64 group ; : update-old-new ( old new -- ) - [ get >r get r> ] 2keep >r >r w+ dup r> set r> set ; inline + [ [ get ] bi@ w+ dup ] 2keep [ set ] bi@ ; inline diff --git a/basis/checksums/md5/md5.factor b/basis/checksums/md5/md5.factor index 6158254f84..257fd930c4 100644 --- a/basis/checksums/md5/md5.factor +++ b/basis/checksums/md5/md5.factor @@ -14,7 +14,7 @@ IN: checksums.md5 SYMBOLS: a b c d old-a old-b old-c old-d ; : T ( N -- Y ) - sin abs 4294967296 * >bignum ; foldable + sin abs 4294967296 * >integer ; foldable : initialize-md5 ( -- ) 0 bytes-read set diff --git a/basis/combinators/short-circuit/short-circuit.factor b/basis/combinators/short-circuit/short-circuit.factor index 2b4e522789..d8bab4dd34 100644 --- a/basis/combinators/short-circuit/short-circuit.factor +++ b/basis/combinators/short-circuit/short-circuit.factor @@ -3,9 +3,13 @@ locals generalizations macros fry ; IN: combinators.short-circuit MACRO:: n&& ( quots n -- quot ) - [ f ] - quots [| q | { [ drop n ndup q call dup not ] [ drop n ndrop f ] } ] map - [ n nnip ] suffix 1array + [ f ] quots [| q | + n + [ q '[ drop _ ndup @ dup not ] ] + [ '[ drop _ ndrop f ] ] + bi 2array + ] map + n '[ _ nnip ] suffix 1array [ cond ] 3append ; MACRO: 0&& ( quots -- quot ) '[ _ 0 n&& ] ; @@ -14,10 +18,13 @@ MACRO: 2&& ( quots -- quot ) '[ _ 2 n&& ] ; MACRO: 3&& ( quots -- quot ) '[ _ 3 n&& ] ; MACRO:: n|| ( quots n -- quot ) - [ f ] - quots - [| q | { [ drop n ndup q call dup ] [ n nnip ] } ] map - { [ drop n ndrop t ] [ f ] } suffix 1array + [ f ] quots [| q | + n + [ q '[ drop _ ndup @ dup ] ] + [ '[ _ nnip ] ] + bi 2array + ] map + n '[ drop _ ndrop t ] [ f ] 2array suffix 1array [ cond ] 3append ; MACRO: 0|| ( quots -- quot ) '[ _ 0 n|| ] ; diff --git a/basis/cpu/x86/64/winnt/winnt.factor b/basis/cpu/x86/64/winnt/winnt.factor index 9108c0e8f7..629ba23e06 100644 --- a/basis/cpu/x86/64/winnt/winnt.factor +++ b/basis/cpu/x86/64/winnt/winnt.factor @@ -23,6 +23,6 @@ M: x86.64 dummy-fp-params? t ; << "longlong" "ptrdiff_t" typedef "longlong" "intptr_t" typedef -"int" "long" typedef -"uint" "ulong" typedef +"int" c-type "long" define-primitive-type +"uint" c-type "ulong" define-primitive-type >> diff --git a/basis/delegate/delegate.factor b/basis/delegate/delegate.factor index 12860337ff..3a7cecb800 100644 --- a/basis/delegate/delegate.factor +++ b/basis/delegate/delegate.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors parser generic kernel classes classes.tuple words slots assocs sequences arrays vectors definitions -prettyprint math hashtables sets macros namespaces make ; +prettyprint math hashtables sets generalizations namespaces make ; IN: delegate : protocol-words ( protocol -- words ) @@ -25,15 +25,7 @@ M: tuple-class group-words : consult-method ( word class quot -- ) [ drop swap first create-method ] - [ - nip - [ - over second saver % - % - dup second restorer % - first , - ] [ ] make - ] 3bi + [ nip [ , dup second , \ ndip , first , ] [ ] make ] 3bi define ; : change-word-prop ( word prop quot -- ) diff --git a/basis/furnace/actions/actions.factor b/basis/furnace/actions/actions.factor index 6c56a8ad7b..72a7b76d23 100644 --- a/basis/furnace/actions/actions.factor +++ b/basis/furnace/actions/actions.factor @@ -6,7 +6,7 @@ io arrays math boxes splitting urls xml.entities http.server http.server.responses -furnace +furnace.utilities furnace.redirection furnace.conversations html.forms diff --git a/basis/furnace/asides/asides.factor b/basis/furnace/asides/asides.factor index 6d4196cf0b..7489d19f94 100644 --- a/basis/furnace/asides/asides.factor +++ b/basis/furnace/asides/asides.factor @@ -4,9 +4,9 @@ USING: namespaces assocs kernel sequences accessors hashtables urls db.types db.tuples math.parser fry logging combinators html.templates.chloe.syntax http http.server http.server.filters http.server.redirection -furnace furnace.cache furnace.sessions +furnace.utilities furnace.redirection ; IN: furnace.asides diff --git a/basis/furnace/auth/auth.factor b/basis/furnace/auth/auth.factor index 1b5c5f9e73..b9c961941c 100644 --- a/basis/furnace/auth/auth.factor +++ b/basis/furnace/auth/auth.factor @@ -8,8 +8,8 @@ html.forms http.server http.server.filters http.server.dispatchers -furnace furnace.actions +furnace.utilities furnace.redirection furnace.boilerplate furnace.auth.providers diff --git a/basis/furnace/auth/features/recover-password/recover-password.factor b/basis/furnace/auth/features/recover-password/recover-password.factor index 5885aaef61..77be30a2d1 100644 --- a/basis/furnace/auth/features/recover-password/recover-password.factor +++ b/basis/furnace/auth/features/recover-password/recover-password.factor @@ -1,11 +1,10 @@ ! Copyright (c) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: namespaces make accessors kernel assocs arrays io.sockets -threads fry urls smtp validators html.forms present -http http.server.responses http.server.redirection -http.server.dispatchers -furnace furnace.actions furnace.auth furnace.auth.providers -furnace.redirection ; +threads fry urls smtp validators html.forms present http +http.server.responses http.server.redirection +http.server.dispatchers furnace.actions furnace.auth +furnace.auth.providers furnace.redirection furnace.utilities ; IN: furnace.auth.features.recover-password SYMBOL: lost-password-from diff --git a/basis/furnace/auth/features/registration/registration.factor b/basis/furnace/auth/features/registration/registration.factor index 0484c11727..7f73f0c404 100644 --- a/basis/furnace/auth/features/registration/registration.factor +++ b/basis/furnace/auth/features/registration/registration.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors assocs kernel namespaces validators html.forms urls http.server.dispatchers -furnace furnace.auth furnace.auth.providers furnace.actions +furnace.auth furnace.auth.providers furnace.actions furnace.redirection ; IN: furnace.auth.features.registration diff --git a/basis/furnace/auth/login/login.factor b/basis/furnace/auth/login/login.factor index 4fc4e7e8be..fff301eb2f 100644 --- a/basis/furnace/auth/login/login.factor +++ b/basis/furnace/auth/login/login.factor @@ -3,7 +3,6 @@ USING: kernel accessors namespaces sequences math.parser calendar validators urls logging html.forms http http.server http.server.dispatchers -furnace furnace.auth furnace.asides furnace.actions diff --git a/basis/furnace/boilerplate/boilerplate.factor b/basis/furnace/boilerplate/boilerplate.factor index 946372e1f8..95e93f2ee8 100644 --- a/basis/furnace/boilerplate/boilerplate.factor +++ b/basis/furnace/boilerplate/boilerplate.factor @@ -1,12 +1,13 @@ ! Copyright (c) 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel math.order namespaces furnace combinators.short-circuit +USING: accessors kernel math.order namespaces combinators.short-circuit html.forms html.templates html.templates.chloe locals http.server -http.server.filters ; +http.server.filters +furnace.utilities ; IN: furnace.boilerplate TUPLE: boilerplate < filter-responder template init ; diff --git a/basis/furnace/chloe-tags/chloe-tags.factor b/basis/furnace/chloe-tags/chloe-tags.factor index 697c885a01..8ab70ded7b 100644 --- a/basis/furnace/chloe-tags/chloe-tags.factor +++ b/basis/furnace/chloe-tags/chloe-tags.factor @@ -19,7 +19,7 @@ http http.server http.server.redirection http.server.responses -furnace ; +furnace.utilities ; QUALIFIED-WITH: assocs a IN: furnace.chloe-tags diff --git a/basis/furnace/conversations/conversations.factor b/basis/furnace/conversations/conversations.factor index 671296ce57..266958c8a4 100644 --- a/basis/furnace/conversations/conversations.factor +++ b/basis/furnace/conversations/conversations.factor @@ -4,10 +4,10 @@ USING: namespaces assocs kernel sequences accessors hashtables urls db.types db.tuples math.parser fry logging combinators html.templates.chloe.syntax http http.server http.server.filters http.server.redirection -furnace furnace.cache furnace.scopes furnace.sessions +furnace.utilities furnace.redirection ; IN: furnace.conversations diff --git a/basis/furnace/furnace-docs.factor b/basis/furnace/furnace-docs.factor index 911433d100..c6191b295e 100644 --- a/basis/furnace/furnace-docs.factor +++ b/basis/furnace/furnace-docs.factor @@ -2,129 +2,6 @@ USING: assocs help.markup help.syntax kernel quotations sequences strings urls xml.data http ; IN: furnace -HELP: adjust-redirect-url -{ $values { "url" url } { "url'" url } } -{ $description "Adjusts a redirection URL by filtering the URL's query parameters through the " { $link modify-redirect-query } " generic word on every responder involved in handling the current request." } ; - -HELP: adjust-url -{ $values { "url" url } { "url'" url } } -{ $description "Adjusts a link URL by filtering the URL's query parameters through the " { $link modify-query } " generic word on every responder involved in handling the current request." } ; - -HELP: client-state -{ $values { "key" string } { "value/f" { $maybe string } } } -{ $description "Looks up a cookie (if the current request is a GET or HEAD request) or a POST parameter (if the current request is a POST request)." } -{ $notes "This word is used by session management, conversation scope and asides." } ; - -HELP: each-responder -{ $values { "quot" { $quotation "( responder -- )" } } } -{ $description "Applies the quotation to each responder involved in processing the current request." } ; - -HELP: hidden-form-field -{ $values { "value" string } { "name" string } } -{ $description "Renders an HTML hidden form field tag." } -{ $notes "This word is used by session management, conversation scope and asides." } -{ $examples - { $example - "USING: furnace io ;" - "\"bar\" \"foo\" hidden-form-field nl" - "" - } -} ; - -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" } "." } -{ $examples "Conversation scope adds attributes to link tags." } ; - -HELP: modify-form -{ $values { "responder" "a responder" } } -{ $contract "Emits hidden form fields using " { $link hidden-form-field } "." } -{ $notes "This word is called by " { $link "html.templates.chloe.tags.form" } "." } -{ $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" } "." } -{ $examples "Asides add query parameters to URLs." } ; - -HELP: modify-redirect-query -{ $values { "query" assoc } { "responder" "a responder" } { "query'" assoc } } -{ $contract "Modifies the query parameters of a URL destined to be used with a redirect." } -{ $notes "This word is called by " { $link "furnace.redirection" } "." } -{ $examples "Conversation scope and asides add query parameters to redirect URLs." } ; - -HELP: nested-responders -{ $values { "seq" "a sequence of responders" } } -{ $description "" } ; - -HELP: referrer -{ $values { "referrer/f" { $maybe string } } } -{ $description "Outputs the current request's referrer URL." } ; - -HELP: request-params -{ $values { "request" request } { "assoc" assoc } } -{ $description "Outputs the query parameters (if the current request is a GET or HEAD request) or the POST parameters (if the current request is a POST request)." } ; - -HELP: resolve-base-path -{ $values { "string" string } { "string'" string } } -{ $description "" } ; - -HELP: resolve-template-path -{ $values { "pair" "a pair with shape " { $snippet "{ class string }" } } { "path" "a pathname string" } } -{ $description "" } ; - -HELP: same-host? -{ $values { "url" url } { "?" "a boolean" } } -{ $description "Tests if the given URL is located on the same host as the URL of the current request." } ; - -HELP: user-agent -{ $values { "user-agent" { $maybe string } } } -{ $description "Outputs the user agent reported by the client for the current request." } ; - -HELP: vocab-path -{ $values { "vocab" "a vocabulary specifier" } { "path" "a pathname string" } } -{ $description "" } ; - -HELP: exit-with -{ $values { "value" object } } -{ $description "Exits from an outer " { $link with-exit-continuation } "." } ; - -HELP: with-exit-continuation -{ $values { "quot" { $quotation { "( -- value )" } } } { "value" "a value returned by the quotation or an " { $link exit-with } " invocation" } } -{ $description "Runs a quotation with the " { $link exit-continuation } " variable bound. Calling " { $link exit-with } " in the quotation will immediately return." } -{ $notes "Furnace actions and authentication realms wrap their execution in this combinator, allowing form validation failures and login requests, respectively, to immediately return an HTTP response to the client without running any more responder code." } ; - -ARTICLE: "furnace.extension-points" "Furnace extension points" -"Furnace features such as session management, conversation scope and asides need to modify URLs in links and redirects, and insert hidden form fields, to implement state on top of the stateless HTTP protocol. In order to decouple the server-side state management code from the HTML templating code, a series of hooks are used." -$nl -"Responders can implement methods on the following generic words:" -{ $subsection modify-query } -{ $subsection modify-redirect-query } -{ $subsection link-attr } -{ $subsection modify-form } -"Presentation-level code can call the following words:" -{ $subsection adjust-url } -{ $subsection adjust-redirect-url } ; - -ARTICLE: "furnace.misc" "Miscellaneous Furnace features" -"Inspecting the chain of responders handling the current request:" -{ $subsection nested-responders } -{ $subsection each-responder } -{ $subsection resolve-base-path } -"Vocabulary root-relative resources:" -{ $subsection vocab-path } -{ $subsection resolve-template-path } -"Early return from a responder:" -{ $subsection with-exit-continuation } -{ $subsection exit-with } -"Other useful words:" -{ $subsection hidden-form-field } -{ $subsection request-params } -{ $subsection client-state } -{ $subsection user-agent } ; - ARTICLE: "furnace.persistence" "Furnace persistence layer" { $subsection "furnace.db" } "Server-side state:" diff --git a/basis/furnace/furnace-tests.factor b/basis/furnace/furnace-tests.factor index 00e4f6f152..f6e5434997 100644 --- a/basis/furnace/furnace-tests.factor +++ b/basis/furnace/furnace-tests.factor @@ -1,7 +1,7 @@ IN: furnace.tests USING: http http.server.dispatchers http.server.responses -http.server furnace tools.test kernel namespaces accessors -io.streams.string urls ; +http.server furnace furnace.utilities tools.test kernel +namespaces accessors io.streams.string urls ; TUPLE: funny-dispatcher < dispatcher ; : funny-dispatcher new-dispatcher ; diff --git a/basis/furnace/furnace.factor b/basis/furnace/furnace.factor index 29eb00a8f4..adafb21524 100644 --- a/basis/furnace/furnace.factor +++ b/basis/furnace/furnace.factor @@ -1,133 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: namespaces make assocs sequences kernel classes splitting -vocabs.loader accessors strings combinators arrays -continuations present fry -urls html.elements -http http.server http.server.redirection http.server.remapping ; IN: furnace -: nested-responders ( -- seq ) - responder-nesting get values ; - -: each-responder ( quot -- ) - nested-responders swap each ; inline - -: base-path ( string -- pair ) - dup responder-nesting get - [ second class superclasses [ name>> = ] with contains? ] with find nip - [ first ] [ "No such responder: " swap append throw ] ?if ; - -: resolve-base-path ( string -- string' ) - "$" ?head [ - [ - "/" split1 [ base-path [ "/" % % ] each "/" % ] dip % - ] "" make - ] when ; - -: vocab-path ( vocab -- path ) - dup vocab-dir vocab-append-path ; - -: resolve-template-path ( pair -- path ) - [ - first2 [ vocabulary>> vocab-path % ] [ "/" % % ] bi* - ] "" make ; - -GENERIC: modify-query ( query responder -- query' ) - -M: object modify-query drop ; - -GENERIC: modify-redirect-query ( query responder -- query' ) - -M: object modify-redirect-query drop ; - -GENERIC: adjust-url ( url -- url' ) - -M: url adjust-url - clone - [ [ modify-query ] each-responder ] change-query - [ resolve-base-path ] change-path - relative-to-request ; - -M: string adjust-url ; - -GENERIC: adjust-redirect-url ( url -- url' ) - -M: url adjust-redirect-url - adjust-url - [ [ modify-redirect-query ] each-responder ] change-query ; - -M: string adjust-redirect-url ; - -GENERIC: link-attr ( tag responder -- ) - -M: object link-attr 2drop ; - -GENERIC: modify-form ( responder -- ) - -M: object modify-form drop ; - -: hidden-form-field ( value name -- ) - over [ - - ] [ 2drop ] if ; - -: nested-forms-key "__n" ; - -: request-params ( request -- assoc ) - dup method>> { - { "GET" [ url>> query>> ] } - { "HEAD" [ url>> query>> ] } - { "POST" [ - post-data>> - dup content-type>> "application/x-www-form-urlencoded" = - [ content>> ] [ drop f ] if - ] } - } case ; - -: referrer ( -- referrer/f ) - #! Typo is intentional, it's in the HTTP spec! - "referer" request get header>> at - dup [ >url ensure-port [ remap-port ] change-port ] when ; - -: user-agent ( -- user-agent ) - "user-agent" request get header>> at "" or ; - -: same-host? ( url -- ? ) - dup [ - url get [ - [ protocol>> ] - [ host>> ] - [ port>> remap-port ] - tri 3array - ] bi@ = - ] when ; - -: cookie-client-state ( key request -- value/f ) - swap get-cookie dup [ value>> ] when ; - -: post-client-state ( key request -- value/f ) - request-params at ; - -: client-state ( key -- value/f ) - request get dup method>> { - { "GET" [ cookie-client-state ] } - { "HEAD" [ cookie-client-state ] } - { "POST" [ post-client-state ] } - } case ; - -SYMBOL: exit-continuation - -: exit-with ( value -- ) - exit-continuation get continue-with ; - -: with-exit-continuation ( quot -- value ) - '[ exit-continuation set @ ] callcc1 exit-continuation off ; - USE: vocabs.loader "furnace.actions" require "furnace.alloy" require diff --git a/basis/furnace/redirection/redirection.factor b/basis/furnace/redirection/redirection.factor index c5a63a795c..01297288dc 100644 --- a/basis/furnace/redirection/redirection.factor +++ b/basis/furnace/redirection/redirection.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors combinators namespaces fry urls http http.server http.server.redirection http.server.responses -http.server.remapping http.server.filters furnace ; +http.server.remapping http.server.filters furnace.utilities ; IN: furnace.redirection : ( url -- response ) diff --git a/basis/furnace/referrer/referrer-docs.factor b/basis/furnace/referrer/referrer-docs.factor index 599461c37c..b57bcb262b 100644 --- a/basis/furnace/referrer/referrer-docs.factor +++ b/basis/furnace/referrer/referrer-docs.factor @@ -1,5 +1,5 @@ USING: help.markup help.syntax io.streams.string -furnace ; +furnace.utilities ; IN: furnace.referrer HELP: diff --git a/basis/furnace/referrer/referrer.factor b/basis/furnace/referrer/referrer.factor index 003028ab1e..e5666c2698 100644 --- a/basis/furnace/referrer/referrer.factor +++ b/basis/furnace/referrer/referrer.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel http.server http.server.filters -http.server.responses furnace ; +http.server.responses furnace.utilities ; IN: furnace.referrer TUPLE: referrer-check < filter-responder quot ; diff --git a/basis/furnace/sessions/sessions-tests.factor b/basis/furnace/sessions/sessions-tests.factor index 6bb3c1cd69..907e657125 100644 --- a/basis/furnace/sessions/sessions-tests.factor +++ b/basis/furnace/sessions/sessions-tests.factor @@ -3,7 +3,8 @@ USING: tools.test http furnace.sessions furnace.actions http.server http.server.responses math namespaces make kernel accessors io.sockets io.servers.connection prettyprint io.streams.string io.files splitting destructors sequences db -db.tuples db.sqlite continuations urls math.parser furnace ; +db.tuples db.sqlite continuations urls math.parser furnace +furnace.utilities ; : with-session [ diff --git a/basis/furnace/sessions/sessions.factor b/basis/furnace/sessions/sessions.factor index b7120aaf11..cde95f2831 100644 --- a/basis/furnace/sessions/sessions.factor +++ b/basis/furnace/sessions/sessions.factor @@ -1,13 +1,11 @@ ! Copyright (C) 2008 Doug Coleman, Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: assocs kernel math.intervals math.parser namespaces -strings random accessors quotations hashtables sequences continuations -fry calendar combinators combinators.short-circuit destructors alarms -io.servers.connection -db db.tuples db.types +strings random accessors quotations hashtables sequences +continuations fry calendar combinators combinators.short-circuit +destructors alarms io.servers.connection db db.tuples db.types http http.server http.server.dispatchers http.server.filters -html.elements -furnace furnace.cache furnace.scopes ; +html.elements furnace.cache furnace.scopes furnace.utilities ; IN: furnace.sessions TUPLE: session < scope user-agent client ; diff --git a/basis/furnace/syndication/syndication.factor b/basis/furnace/syndication/syndication.factor index a326e62f02..876aaf8c98 100644 --- a/basis/furnace/syndication/syndication.factor +++ b/basis/furnace/syndication/syndication.factor @@ -1,9 +1,8 @@ ! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors kernel sequences fry -combinators syndication -http.server.responses http.server.redirection -furnace furnace.actions ; +USING: accessors kernel sequences fry combinators syndication +http.server.responses http.server.redirection furnace.actions +furnace.utilities ; IN: furnace.syndication GENERIC: feed-entry-title ( object -- string ) diff --git a/basis/furnace/utilities/utilities-docs.factor b/basis/furnace/utilities/utilities-docs.factor new file mode 100644 index 0000000000..1402e9c0ca --- /dev/null +++ b/basis/furnace/utilities/utilities-docs.factor @@ -0,0 +1,126 @@ +USING: assocs help.markup help.syntax kernel +quotations sequences strings urls xml.data http ; +IN: furnace.utilities + +HELP: adjust-redirect-url +{ $values { "url" url } { "url'" url } } +{ $description "Adjusts a redirection URL by filtering the URL's query parameters through the " { $link modify-redirect-query } " generic word on every responder involved in handling the current request." } ; + +HELP: adjust-url +{ $values { "url" url } { "url'" url } } +{ $description "Adjusts a link URL by filtering the URL's query parameters through the " { $link modify-query } " generic word on every responder involved in handling the current request." } ; + +HELP: client-state +{ $values { "key" string } { "value/f" { $maybe string } } } +{ $description "Looks up a cookie (if the current request is a GET or HEAD request) or a POST parameter (if the current request is a POST request)." } +{ $notes "This word is used by session management, conversation scope and asides." } ; + +HELP: each-responder +{ $values { "quot" { $quotation "( responder -- )" } } } +{ $description "Applies the quotation to each responder involved in processing the current request." } ; + +HELP: hidden-form-field +{ $values { "value" string } { "name" string } } +{ $description "Renders an HTML hidden form field tag." } +{ $notes "This word is used by session management, conversation scope and asides." } +{ $examples + { $example + "USING: furnace.utilities io ;" + "\"bar\" \"foo\" hidden-form-field nl" + "" + } +} ; + +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" } "." } +{ $examples "Conversation scope adds attributes to link tags." } ; + +HELP: modify-form +{ $values { "responder" "a responder" } } +{ $contract "Emits hidden form fields using " { $link hidden-form-field } "." } +{ $notes "This word is called by " { $link "html.templates.chloe.tags.form" } "." } +{ $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" } "." } +{ $examples "Asides add query parameters to URLs." } ; + +HELP: modify-redirect-query +{ $values { "query" assoc } { "responder" "a responder" } { "query'" assoc } } +{ $contract "Modifies the query parameters of a URL destined to be used with a redirect." } +{ $notes "This word is called by " { $link "furnace.redirection" } "." } +{ $examples "Conversation scope and asides add query parameters to redirect URLs." } ; + +HELP: nested-responders +{ $values { "seq" "a sequence of responders" } } +{ $description "" } ; + +HELP: referrer +{ $values { "referrer/f" { $maybe string } } } +{ $description "Outputs the current request's referrer URL." } ; + +HELP: request-params +{ $values { "request" request } { "assoc" assoc } } +{ $description "Outputs the query parameters (if the current request is a GET or HEAD request) or the POST parameters (if the current request is a POST request)." } ; + +HELP: resolve-base-path +{ $values { "string" string } { "string'" string } } +{ $description "" } ; + +HELP: resolve-template-path +{ $values { "pair" "a pair with shape " { $snippet "{ class string }" } } { "path" "a pathname string" } } +{ $description "" } ; + +HELP: same-host? +{ $values { "url" url } { "?" "a boolean" } } +{ $description "Tests if the given URL is located on the same host as the URL of the current request." } ; + +HELP: user-agent +{ $values { "user-agent" { $maybe string } } } +{ $description "Outputs the user agent reported by the client for the current request." } ; + +HELP: vocab-path +{ $values { "vocab" "a vocabulary specifier" } { "path" "a pathname string" } } +{ $description "" } ; + +HELP: exit-with +{ $values { "value" object } } +{ $description "Exits from an outer " { $link with-exit-continuation } "." } ; + +HELP: with-exit-continuation +{ $values { "quot" { $quotation { "( -- value )" } } } { "value" "a value returned by the quotation or an " { $link exit-with } " invocation" } } +{ $description "Runs a quotation with the " { $link exit-continuation } " variable bound. Calling " { $link exit-with } " in the quotation will immediately return." } +{ $notes "Furnace actions and authentication realms wrap their execution in this combinator, allowing form validation failures and login requests, respectively, to immediately return an HTTP response to the client without running any more responder code." } ; + +ARTICLE: "furnace.extension-points" "Furnace extension points" +"Furnace features such as session management, conversation scope and asides need to modify URLs in links and redirects, and insert hidden form fields, to implement state on top of the stateless HTTP protocol. In order to decouple the server-side state management code from the HTML templating code, a series of hooks are used." +$nl +"Responders can implement methods on the following generic words:" +{ $subsection modify-query } +{ $subsection modify-redirect-query } +{ $subsection link-attr } +{ $subsection modify-form } +"Presentation-level code can call the following words:" +{ $subsection adjust-url } +{ $subsection adjust-redirect-url } ; + +ARTICLE: "furnace.misc" "Miscellaneous Furnace features" +"Inspecting the chain of responders handling the current request:" +{ $subsection nested-responders } +{ $subsection each-responder } +{ $subsection resolve-base-path } +"Vocabulary root-relative resources:" +{ $subsection vocab-path } +{ $subsection resolve-template-path } +"Early return from a responder:" +{ $subsection with-exit-continuation } +{ $subsection exit-with } +"Other useful words:" +{ $subsection hidden-form-field } +{ $subsection request-params } +{ $subsection client-state } +{ $subsection user-agent } ; diff --git a/basis/furnace/utilities/utilities.factor b/basis/furnace/utilities/utilities.factor index 4bfbdcd943..f2b71fb89f 100644 --- a/basis/furnace/utilities/utilities.factor +++ b/basis/furnace/utilities/utilities.factor @@ -1,6 +1,9 @@ -! Copyright (c) 2008 Slava Pestov +! Copyright (C) 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors words kernel sequences splitting ; +USING: namespaces make assocs sequences kernel classes splitting +words vocabs.loader accessors strings combinators arrays +continuations present fry urls html.elements http http.server +http.server.redirection http.server.remapping ; IN: furnace.utilities : word>string ( word -- string ) @@ -17,3 +20,124 @@ ERROR: no-such-word name vocab ; : strings>words ( seq -- seq' ) [ string>word ] map ; + +: nested-responders ( -- seq ) + responder-nesting get values ; + +: each-responder ( quot -- ) + nested-responders swap each ; inline + +: base-path ( string -- pair ) + dup responder-nesting get + [ second class superclasses [ name>> = ] with contains? ] with find nip + [ first ] [ "No such responder: " swap append throw ] ?if ; + +: resolve-base-path ( string -- string' ) + "$" ?head [ + [ + "/" split1 [ base-path [ "/" % % ] each "/" % ] dip % + ] "" make + ] when ; + +: vocab-path ( vocab -- path ) + dup vocab-dir vocab-append-path ; + +: resolve-template-path ( pair -- path ) + [ + first2 [ vocabulary>> vocab-path % ] [ "/" % % ] bi* + ] "" make ; + +GENERIC: modify-query ( query responder -- query' ) + +M: object modify-query drop ; + +GENERIC: modify-redirect-query ( query responder -- query' ) + +M: object modify-redirect-query drop ; + +GENERIC: adjust-url ( url -- url' ) + +M: url adjust-url + clone + [ [ modify-query ] each-responder ] change-query + [ resolve-base-path ] change-path + relative-to-request ; + +M: string adjust-url ; + +GENERIC: adjust-redirect-url ( url -- url' ) + +M: url adjust-redirect-url + adjust-url + [ [ modify-redirect-query ] each-responder ] change-query ; + +M: string adjust-redirect-url ; + +GENERIC: link-attr ( tag responder -- ) + +M: object link-attr 2drop ; + +GENERIC: modify-form ( responder -- ) + +M: object modify-form drop ; + +: hidden-form-field ( value name -- ) + over [ + + ] [ 2drop ] if ; + +: nested-forms-key "__n" ; + +: request-params ( request -- assoc ) + dup method>> { + { "GET" [ url>> query>> ] } + { "HEAD" [ url>> query>> ] } + { "POST" [ + post-data>> + dup content-type>> "application/x-www-form-urlencoded" = + [ content>> ] [ drop f ] if + ] } + } case ; + +: referrer ( -- referrer/f ) + #! Typo is intentional, it's in the HTTP spec! + "referer" request get header>> at + dup [ >url ensure-port [ remap-port ] change-port ] when ; + +: user-agent ( -- user-agent ) + "user-agent" request get header>> at "" or ; + +: same-host? ( url -- ? ) + dup [ + url get [ + [ protocol>> ] + [ host>> ] + [ port>> remap-port ] + tri 3array + ] bi@ = + ] when ; + +: cookie-client-state ( key request -- value/f ) + swap get-cookie dup [ value>> ] when ; + +: post-client-state ( key request -- value/f ) + request-params at ; + +: client-state ( key -- value/f ) + request get dup method>> { + { "GET" [ cookie-client-state ] } + { "HEAD" [ cookie-client-state ] } + { "POST" [ post-client-state ] } + } case ; + +SYMBOL: exit-continuation + +: exit-with ( value -- ) + exit-continuation get continue-with ; + +: with-exit-continuation ( quot -- value ) + '[ exit-continuation set @ ] callcc1 exit-continuation off ; diff --git a/basis/generalizations/generalizations.factor b/basis/generalizations/generalizations.factor index c63c2b66ca..490fa77204 100644 --- a/basis/generalizations/generalizations.factor +++ b/basis/generalizations/generalizations.factor @@ -1,68 +1,75 @@ -! Copyright (C) 2007, 2008 Chris Double, Doug Coleman, Eduardo -! Cavazos, Slava Pestov. -! See http://factorcode.org/license.txt for BSD license. -USING: kernel sequences sequences.private namespaces math -math.ranges combinators macros quotations fry arrays ; -IN: generalizations - -MACRO: nsequence ( n seq -- quot ) - [ - [ drop ] [ '[ _ _ new-sequence ] ] 2bi - [ '[ @ [ _ swap set-nth-unsafe ] keep ] ] reduce - ] keep - '[ @ _ like ] ; - -MACRO: narray ( n -- quot ) - '[ _ { } nsequence ] ; - -MACRO: firstn ( n -- ) - dup zero? [ drop [ drop ] ] [ - [ [ '[ [ _ ] dip nth-unsafe ] ] map ] - [ 1- '[ [ _ ] dip bounds-check 2drop ] ] - bi prefix '[ _ cleave ] - ] if ; - -MACRO: npick ( n -- ) - 1- dup saver [ dup ] rot [ r> swap ] n*quot 3append ; - -MACRO: ndup ( n -- ) - dup '[ _ npick ] n*quot ; - -MACRO: nrot ( n -- ) - 1- dup saver swap [ r> swap ] n*quot append ; - -MACRO: -nrot ( n -- ) - 1- dup [ swap >r ] n*quot swap restorer append ; - -MACRO: ndrop ( n -- ) - [ drop ] n*quot ; - -: nnip ( n -- ) - swap >r ndrop r> ; inline - -MACRO: ntuck ( n -- ) - 2 + [ dupd -nrot ] curry ; - -MACRO: nrev ( n -- quot ) - 1 [a,b] [ ] [ '[ @ _ -nrot ] ] reduce ; - -MACRO: ndip ( quot n -- ) - dup saver -rot restorer 3append ; - -MACRO: nslip ( n -- ) - dup saver [ call ] rot restorer 3append ; - -MACRO: nkeep ( n -- ) - [ ] [ 1+ ] [ ] tri - '[ [ _ ndup ] dip _ -nrot _ nslip ] ; - -MACRO: ncurry ( n -- ) - [ curry ] n*quot ; - -MACRO: nwith ( n -- ) - [ with ] n*quot ; - -MACRO: napply ( n -- ) - 2 [a,b] - [ [ 1- ] keep '[ _ ntuck _ nslip ] ] - map concat >quotation [ call ] append ; +! Copyright (C) 2007, 2008 Chris Double, Doug Coleman, Eduardo +! Cavazos, Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel sequences sequences.private math math.ranges +combinators macros quotations fry ; +IN: generalizations + +<< + +: n*quot ( n seq -- seq' ) concat >quotation ; + +: repeat ( n obj quot -- ) swapd times ; inline + +>> + +MACRO: nsequence ( n seq -- quot ) + [ + [ drop ] [ '[ _ _ new-sequence ] ] 2bi + [ '[ @ [ _ swap set-nth-unsafe ] keep ] ] reduce + ] keep + '[ @ _ like ] ; + +MACRO: narray ( n -- quot ) + '[ _ { } nsequence ] ; + +MACRO: firstn ( n -- ) + dup zero? [ drop [ drop ] ] [ + [ [ '[ [ _ ] dip nth-unsafe ] ] map ] + [ 1- '[ [ _ ] dip bounds-check 2drop ] ] + bi prefix '[ _ cleave ] + ] if ; + +MACRO: npick ( n -- quot ) + 1- [ dup ] [ '[ _ dip swap ] ] repeat ; + +MACRO: ndup ( n -- ) + dup '[ _ npick ] n*quot ; + +MACRO: nrot ( n -- ) + 1- [ ] [ '[ _ dip swap ] ] repeat ; + +MACRO: -nrot ( n -- ) + 1- [ ] [ '[ swap _ dip ] ] repeat ; + +MACRO: ndrop ( n -- ) + [ drop ] n*quot ; + +MACRO: nnip ( n -- ) + '[ [ _ ndrop ] dip ] ; + +MACRO: ntuck ( n -- ) + 2 + '[ dup _ -nrot ] ; + +MACRO: nrev ( n -- quot ) + 1 [a,b] [ ] [ '[ @ _ -nrot ] ] reduce ; + +MACRO: ndip ( quot n -- ) + [ '[ _ dip ] ] times ; + +MACRO: nslip ( n -- ) + '[ [ call ] _ ndip ] ; + +MACRO: nkeep ( quot n -- ) + tuck '[ _ ndup _ _ ndip ] ; + +MACRO: ncurry ( n -- ) + [ curry ] n*quot ; + +MACRO: nwith ( n -- ) + [ with ] n*quot ; + +MACRO: napply ( n -- ) + 2 [a,b] + [ [ 1- ] [ ] bi '[ _ ntuck _ nslip ] ] + map concat >quotation [ call ] append ; diff --git a/basis/http/http-tests.factor b/basis/http/http-tests.factor index 96320b7d12..6e93d5ee3a 100644 --- a/basis/http/http-tests.factor +++ b/basis/http/http-tests.factor @@ -2,7 +2,7 @@ USING: http http.server http.client tools.test multiline io.streams.string io.encodings.utf8 io.encodings.8-bit io.encodings.binary io.encodings.string kernel arrays splitting sequences assocs io.sockets db db.sqlite continuations urls -hashtables accessors ; +hashtables accessors namespaces ; IN: http.tests [ "text/plain" latin1 ] [ "text/plain" parse-content-type ] unit-test @@ -11,6 +11,12 @@ IN: http.tests [ "application/octet-stream" binary ] [ "application/octet-stream" parse-content-type ] unit-test +[ { } ] [ "" parse-cookie ] unit-test +[ { } ] [ "" parse-set-cookie ] unit-test + +! Make sure that totally invalid cookies don't confuse us +[ { } ] [ "hello world; how are you" parse-cookie ] unit-test + : lf>crlf "\n" split "\r\n" join ; STRING: read-request-test-1 @@ -126,6 +132,7 @@ content-type: text/html; charset=UTF-8 ; read-response-test-1' 1array [ + URL" http://localhost/" url set read-response-test-1 lf>crlf [ read-response ] with-string-reader [ write-response ] with-string-writer diff --git a/basis/http/parsers/parsers.factor b/basis/http/parsers/parsers.factor index 8e8e7358d1..d72147b381 100644 --- a/basis/http/parsers/parsers.factor +++ b/basis/http/parsers/parsers.factor @@ -142,16 +142,15 @@ PEG: parse-header-line ( string -- pair ) 'space' , 'attr' , 'space' , - [ "=" token , 'space' , 'value' , ] seq* [ peek ] action - epsilon [ drop f ] action - 2choice , + [ "=" token , 'space' , 'value' , ] seq* [ peek ] action optional , 'space' , ] seq* ; : 'av-pairs' ( -- parser ) 'av-pair' ";" token list-of optional ; -PEG: (parse-set-cookie) ( string -- alist ) 'av-pairs' just ; +PEG: (parse-set-cookie) ( string -- alist ) + 'av-pairs' just [ sift ] action ; : 'cookie-value' ( -- parser ) [ @@ -162,7 +161,10 @@ PEG: (parse-set-cookie) ( string -- alist ) 'av-pairs' just ; 'space' , 'value' , 'space' , - ] seq* ; + ] seq* + [ ";,=" member? not ] satisfy repeat1 [ drop f ] action + 2choice ; PEG: (parse-cookie) ( string -- alist ) - 'cookie-value' [ ";," member? ] satisfy list-of optional just ; + 'cookie-value' [ ";," member? ] satisfy list-of + optional just [ sift ] action ; diff --git a/basis/locals/locals-tests.factor b/basis/locals/locals-tests.factor index 44c04da1a1..8796721b1b 100644 --- a/basis/locals/locals-tests.factor +++ b/basis/locals/locals-tests.factor @@ -418,6 +418,19 @@ M:: integer lambda-method-forget-test ( a -- b ) ; [ "USE: locals [let | a" eval ] [ error>> unexpected-eof? ] must-fail-with [ "USE: locals [|" eval ] [ error>> unexpected-eof? ] must-fail-with +[ 25 ] [ 5 [| a | { [ a sq ] } cond ] call ] unit-test +[ 25 ] [ 5 [| | { [| a | a sq ] } ] call first call ] unit-test + +:: FAILdog-1 ( -- b ) { [| c | c ] } ; + +\ FAILdog-1 must-infer + +:: FAILdog-2 ( a -- b ) a { [| c | c ] } cond ; + +\ FAILdog-2 must-infer + +[ 3 ] [ 3 [| a | \ a ] call ] unit-test + ! :: wlet-&&-test ( a -- ? ) ! [wlet | is-integer? [ a integer? ] ! is-even? [ a even? ] diff --git a/basis/locals/locals.factor b/basis/locals/locals.factor index e66b1531d2..df713a50e7 100644 --- a/basis/locals/locals.factor +++ b/basis/locals/locals.factor @@ -206,6 +206,8 @@ M: array rewrite-literal? [ rewrite-literal? ] contains? ; M: quotation rewrite-literal? [ rewrite-literal? ] contains? ; +M: wrapper rewrite-literal? drop t ; + M: hashtable rewrite-literal? drop t ; M: vector rewrite-literal? drop t ; @@ -235,12 +237,17 @@ M: hashtable rewrite-element >alist rewrite-sequence \ >hashtable , ; M: tuple rewrite-element [ tuple-slots rewrite-elements ] [ class literalize , ] bi \ boa , ; +M: lambda rewrite-element local-rewrite* ; + M: local rewrite-element , ; M: local-reader rewrite-element , ; M: word rewrite-element literalize , ; +M: wrapper rewrite-element + dup rewrite-literal? [ wrapped>> rewrite-element ] [ , ] if ; + M: object rewrite-element , ; M: array local-rewrite* rewrite-element ; @@ -251,8 +258,10 @@ M: tuple local-rewrite* rewrite-element ; M: hashtable local-rewrite* rewrite-element ; +M: wrapper local-rewrite* rewrite-element ; + M: word local-rewrite* - dup { >r r> } memq? + dup { >r r> load-locals get-local drop-locals } memq? [ >r/r>-in-lambda-error ] [ call-next-method ] if ; M: object lambda-rewrite* , ; @@ -350,10 +359,15 @@ M: wlet local-rewrite* word [ over "declared-effect" set-word-prop ] when* in>> [ dup pair? [ first ] when ] map make-locals dup push-locals ; +ERROR: bad-lambda-rewrite output ; + +M: bad-lambda-rewrite summary + drop "You have found a bug in locals. Please report." ; + : parse-locals-definition ( word -- word quot ) "(" expect parse-locals \ ; (parse-lambda) 2dup "lambda" set-word-prop - lambda-rewrite first ; + lambda-rewrite dup length 1 = [ first ] [ bad-lambda-rewrite ] if ; : (::) ( -- word def ) CREATE-WORD parse-locals-definition ; diff --git a/basis/macros/macros.factor b/basis/macros/macros.factor index 794d523d00..1481e6eea5 100644 --- a/basis/macros/macros.factor +++ b/basis/macros/macros.factor @@ -22,9 +22,3 @@ M: macro definition "macro" word-prop ; M: macro reset-word [ call-next-method ] [ f "macro" set-word-prop ] bi ; - -: n*quot ( n seq -- seq' ) concat >quotation ; - -: saver ( n -- quot ) \ >r >quotation ; - -: restorer ( n -- quot ) \ r> >quotation ; diff --git a/basis/math/bitwise/bitwise.factor b/basis/math/bitwise/bitwise.factor index afd83d4458..71ada945cd 100644 --- a/basis/math/bitwise/bitwise.factor +++ b/basis/math/bitwise/bitwise.factor @@ -23,17 +23,12 @@ IN: math.bitwise : bitroll ( x s w -- y ) [ wrap ] keep - [ shift-mod ] - [ [ - ] keep shift-mod ] 3bi bitor ; inline + [ shift-mod ] [ [ - ] keep shift-mod ] 3bi bitor ; inline : bitroll-32 ( n s -- n' ) 32 bitroll ; inline -HINTS: bitroll-32 bignum fixnum ; - : bitroll-64 ( n s -- n' ) 64 bitroll ; inline -HINTS: bitroll-64 bignum fixnum ; - ! 32-bit arithmetic : w+ ( int int -- int ) + 32 bits ; inline : w- ( int int -- int ) - 32 bits ; inline diff --git a/basis/opengl/opengl.factor b/basis/opengl/opengl.factor index ecb4c4a08c..3b807bf8b6 100644 --- a/basis/opengl/opengl.factor +++ b/basis/opengl/opengl.factor @@ -71,18 +71,22 @@ MACRO: all-enabled-client-state ( seq quot -- ) line-vertices GL_LINES 0 2 glDrawArrays ; : (rect-vertices) ( dim -- vertices ) + #! We use GL_LINE_STRIP with a duplicated first vertex + #! instead of GL_LINE_LOOP to work around a bug in Apple's + #! X3100 driver. { [ drop 0.5 0.5 ] [ first 0.3 - 0.5 ] [ [ first 0.3 - ] [ second 0.3 - ] bi ] [ second 0.3 - 0.5 swap ] - } cleave 8 narray >c-float-array ; + [ drop 0.5 0.5 ] + } cleave 10 narray >c-float-array ; : rect-vertices ( dim -- ) (rect-vertices) gl-vertex-pointer ; : (gl-rect) ( -- ) - GL_LINE_LOOP 0 4 glDrawArrays ; + GL_LINE_STRIP 0 5 glDrawArrays ; : gl-rect ( dim -- ) rect-vertices (gl-rect) ; @@ -119,7 +123,16 @@ MACRO: all-enabled-client-state ( seq quot -- ) : circle-points ( loc dim steps -- points ) circle-steps unit-circle adjust-points scale-points ; +: close-path ( points -- points' ) + dup first suffix ; + : circle-vertices ( loc dim steps -- vertices ) + #! We use GL_LINE_STRIP with a duplicated first vertex + #! instead of GL_LINE_LOOP to work around a bug in Apple's + #! X3100 driver. + circle-points close-path concat >c-float-array ; + +: fill-circle-vertices ( loc dim steps -- vertices ) circle-points concat >c-float-array ; : (gen-gl-object) ( quot -- id ) diff --git a/basis/ui/gadgets/buttons/buttons.factor b/basis/ui/gadgets/buttons/buttons.factor index 88d957f8cc..0fae5103ec 100644 --- a/basis/ui/gadgets/buttons/buttons.factor +++ b/basis/ui/gadgets/buttons/buttons.factor @@ -177,7 +177,7 @@ PRIVATE> M: radio-paint recompute-pen swap dim>> - [ { 4 4 } swap { 9 9 } v- circle-steps circle-vertices >>interior-vertices ] + [ { 4 4 } swap { 9 9 } v- circle-steps fill-circle-vertices >>interior-vertices ] [ { 1 1 } swap { 3 3 } v- circle-steps circle-vertices >>boundary-vertices ] bi drop ; @@ -194,7 +194,7 @@ M: radio-paint draw-interior M: radio-paint draw-boundary [ (radio-paint) ] [ boundary-vertices>> gl-vertex-pointer ] bi - GL_LINE_LOOP 0 circle-steps glDrawArrays ; + GL_LINE_STRIP 0 circle-steps 1+ glDrawArrays ; :: radio-knob-theme ( gadget -- gadget ) [let | radio-paint [ black ] | diff --git a/basis/ui/gadgets/canvas/canvas.factor b/basis/ui/gadgets/canvas/canvas.factor index 4ff7519a85..0028b9b165 100644 --- a/basis/ui/gadgets/canvas/canvas.factor +++ b/basis/ui/gadgets/canvas/canvas.factor @@ -12,8 +12,7 @@ TUPLE: canvas < gadget dlist ; : delete-canvas-dlist ( canvas -- ) [ find-gl-context ] - [ dlist>> [ delete-dlist ] when* ] - [ f >>dlist drop ] tri ; + [ [ [ delete-dlist ] when* f ] change-dlist drop ] bi ; : make-canvas-dlist ( canvas quot -- dlist ) [ drop ] [ GL_COMPILE swap make-dlist ] 2bi diff --git a/basis/ui/gadgets/editors/editors.factor b/basis/ui/gadgets/editors/editors.factor index 856795e4ed..59461c173f 100644 --- a/basis/ui/gadgets/editors/editors.factor +++ b/basis/ui/gadgets/editors/editors.factor @@ -1,12 +1,12 @@ ! Copyright (C) 2006, 2008 Slava Pestov ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays documents io kernel math models -namespaces make opengl opengl.gl sequences strings io.styles -math.vectors sorting colors combinators assocs math.order fry -calendar alarms ui.clipboards ui.commands ui.gadgets -ui.gadgets.borders ui.gadgets.buttons ui.gadgets.labels -ui.gadgets.scrollers ui.gadgets.theme ui.gadgets.wrappers -ui.render ui.gestures math.geometry.rect ; +namespaces locals fry make opengl opengl.gl sequences strings +io.styles math.vectors sorting colors combinators assocs +math.order fry calendar alarms ui.clipboards ui.commands +ui.gadgets ui.gadgets.borders ui.gadgets.buttons +ui.gadgets.labels ui.gadgets.scrollers ui.gadgets.theme +ui.gadgets.wrappers ui.render ui.gestures math.geometry.rect ; IN: ui.gadgets.editors TUPLE: editor < gadget @@ -104,14 +104,20 @@ M: editor ungraft* editor-font* "" string-height ; : y>line ( y editor -- line# ) - [ line-height / >fixnum ] keep model>> validate-line ; + line-height / >fixnum ; -: point>loc ( point editor -- loc ) - [ - [ first2 ] dip tuck y>line dup , - [ dup editor-font* ] dip - rot editor-line x>offset , - ] { } make ; +:: point>loc ( point editor -- loc ) + point second editor y>line { + { [ dup 0 < ] [ drop { 0 0 } ] } + { [ dup editor model>> last-line# > ] [ drop editor model>> doc-end ] } + [| n | + n + point first + editor editor-font* + n editor editor-line + x>offset 2array + ] + } cond ; : clicked-loc ( editor -- loc ) [ hand-rel ] keep point>loc ; @@ -141,8 +147,8 @@ M: editor ungraft* line-height * ; : caret-loc ( editor -- loc ) - [ editor-caret* ] keep 2dup loc>x - rot first rot line>y 2array ; + [ editor-caret* ] keep + [ loc>x ] [ [ first ] dip line>y ] 2bi 2array ; : caret-dim ( editor -- dim ) line-height 0 swap 2array ; @@ -175,12 +181,16 @@ M: editor ungraft* [ font>> ] dip { 0 0 } draw-string ; : first-visible-line ( editor -- n ) - clip get rect-loc second origin get second - - swap y>line ; + [ + [ clip get rect-loc second origin get second - ] dip + y>line + ] keep model>> validate-line ; : last-visible-line ( editor -- n ) - clip get rect-extent nip second origin get second - - swap y>line 1+ ; + [ + [ clip get rect-extent nip second origin get second - ] dip + y>line + ] keep model>> validate-line 1+ ; : with-editor ( editor quot -- ) [ @@ -193,9 +203,8 @@ M: editor ungraft* ] with-scope ; inline : visible-lines ( editor -- seq ) - \ first-visible-line get - \ last-visible-line get - rot control-value ; + [ \ first-visible-line get \ last-visible-line get ] dip + control-value ; : with-editor-translation ( n quot -- ) [ line-translation origin get v+ ] dip with-translation ; @@ -313,9 +322,9 @@ M: editor gadget-text* editor-string % ; : editor-cut ( editor clipboard -- ) dupd gadget-copy remove-selection ; -: delete/backspace ( elt editor quot -- ) +: delete/backspace ( editor quot -- ) over gadget-selection? [ - drop nip remove-selection + drop remove-selection ] [ [ [ [ editor-caret* ] [ model>> ] bi ] dip call ] [ drop model>> ] @@ -323,19 +332,19 @@ M: editor gadget-text* editor-string % ; ] if ; inline : editor-delete ( editor elt -- ) - swap [ over [ rot next-elt ] dip swap ] delete/backspace ; + '[ dupd _ next-elt ] delete/backspace ; : editor-backspace ( editor elt -- ) - swap [ over [ rot prev-elt ] dip ] delete/backspace ; + '[ over [ _ prev-elt ] dip ] delete/backspace ; : editor-select-prev ( editor elt -- ) - swap [ rot prev-elt ] change-caret ; + '[ _ prev-elt ] change-caret ; : editor-prev ( editor elt -- ) dupd editor-select-prev mark>caret ; : editor-select-next ( editor elt -- ) - swap [ rot next-elt ] change-caret ; + '[ _ next-elt ] change-caret ; : editor-next ( editor elt -- ) dupd editor-select-next mark>caret ; diff --git a/basis/ui/gadgets/frames/frames-tests.factor b/basis/ui/gadgets/frames/frames-tests.factor index e38e97c76c..27d511e10a 100644 --- a/basis/ui/gadgets/frames/frames-tests.factor +++ b/basis/ui/gadgets/frames/frames-tests.factor @@ -1,4 +1,17 @@ +USING: accessors kernel namespaces tools.test ui.gadgets +ui.gadgets.frames ui.gadgets.grids ui.gadgets.labels ; IN: ui.gadgets.frames.tests -USING: ui.gadgets.frames ui.gadgets tools.test ; [ ] [ layout ] unit-test + +[ t ] [ + + "Hello world"