Merge git://factorcode.org/git/factor

release
Doug Coleman 2007-10-19 19:52:25 -05:00
commit ac002af5fa
22 changed files with 71 additions and 81 deletions

View File

@ -153,17 +153,11 @@ GENERIC: ' ( obj -- ptr )
: bignum-radix bignum-bits 2^ 1- ; : bignum-radix bignum-bits 2^ 1- ;
: (bignum>seq) ( n -- )
dup zero? [
drop
] [
dup bignum-radix bitand ,
bignum-bits neg shift (bignum>seq)
] if ;
: bignum>seq ( n -- seq ) : bignum>seq ( n -- seq )
#! n is positive or zero. #! n is positive or zero.
[ (bignum>seq) ] { } make ; [ dup 0 > ]
[ dup bignum-bits neg shift swap bignum-radix bitand ]
{ } unfold ;
: emit-bignum ( n -- ) : emit-bignum ( n -- )
[ 0 < 1 0 ? ] keep abs bignum>seq [ 0 < 1 0 ? ] keep abs bignum>seq

View File

@ -127,15 +127,13 @@ DEFER: (class<)
curry* subset empty? curry* subset empty?
] curry find [ "Topological sort failed" throw ] unless* ; ] curry find [ "Topological sort failed" throw ] unless* ;
: (sort-classes) ( vec -- )
dup empty?
[ drop ]
[ dup largest-class , over delete-nth (sort-classes) ] if ;
PRIVATE> PRIVATE>
: sort-classes ( seq -- newseq ) : sort-classes ( seq -- newseq )
[ >vector (sort-classes) ] { } make ; >vector
[ dup empty? not ]
[ dup largest-class >r over delete-nth r> ]
{ } unfold ;
: class-or ( class1 class2 -- class ) : class-or ( class1 class2 -- class )
{ {

View File

@ -85,10 +85,8 @@ SYMBOL: stdio
: write-object ( str obj -- ) : write-object ( str obj -- )
presented associate format ; presented associate format ;
: lines-loop ( -- ) readln [ , lines-loop ] when* ;
: lines ( stream -- seq ) : lines ( stream -- seq )
[ [ lines-loop ] { } make ] with-stream ; [ [ readln dup ] [ ] { } unfold ] with-stream ;
: contents ( stream -- str ) : contents ( stream -- str )
2048 <sbuf> [ stream-copy ] keep >string ; 2048 <sbuf> [ stream-copy ] keep >string ;

View File

@ -60,6 +60,11 @@ DEFER: if
: 2apply ( x y quot -- ) tuck 2slip call ; inline : 2apply ( x y quot -- ) tuck 2slip call ; inline
: while ( pred body tail -- )
>r >r dup slip r> r> roll
[ >r tuck 2slip r> while ]
[ 2nip call ] if ; inline
! Quotation building ! Quotation building
: 2curry ( obj1 obj2 quot -- curry ) : 2curry ( obj1 obj2 quot -- curry )

View File

@ -44,10 +44,10 @@ M: word pprint*
dup parsing? [ dup parsing? [
\ POSTPONE: [ pprint-word ] pprint-prefix \ POSTPONE: [ pprint-word ] pprint-prefix
] [ ] [
dup "break-before" word-prop break dup "break-before" word-prop line-break
dup pprint-word dup pprint-word
dup ?start-group dup ?end-group dup ?start-group dup ?end-group
"break-after" word-prop break "break-after" word-prop line-break
] if ; ] if ;
M: real pprint* number>string text ; M: real pprint* number>string text ;

View File

@ -72,7 +72,7 @@ $nl
"Once the output sections have been generated, the tree of sections is traversed and intelligent decisions are made about indentation and line breaks. Finally, text is output." "Once the output sections have been generated, the tree of sections is traversed and intelligent decisions are made about indentation and line breaks. Finally, text is output."
{ $subsection section } { $subsection section }
"Adding leaf sections:" "Adding leaf sections:"
{ $subsection break } { $subsection line-break }
{ $subsection text } { $subsection text }
{ $subsection styled-text } { $subsection styled-text }
"Nesting and denesting sections:" "Nesting and denesting sections:"

View File

@ -227,7 +227,7 @@ M: mixin-class see-class*
\ MIXIN: pprint-word \ MIXIN: pprint-word
dup pprint-word <block dup pprint-word <block
dup members [ dup members [
hard break hard line-break
\ INSTANCE: pprint-word pprint-word pprint-word \ INSTANCE: pprint-word pprint-word pprint-word
] curry* each block> ; ] curry* each block> ;

View File

@ -30,10 +30,10 @@ HELP: fresh-line
{ $description "Advances the prettyprinter by one line unless the current line is empty. If the line limit is exceeded, escapes the prettyprinter by restoring a continuation captured in " { $link do-pprint } "." } ; { $description "Advances the prettyprinter by one line unless the current line is empty. If the line limit is exceeded, escapes the prettyprinter by restoring a continuation captured in " { $link do-pprint } "." } ;
HELP: soft HELP: soft
{ $description "Possible input parameter to " { $link break } "." } ; { $description "Possible input parameter to " { $link line-break } "." } ;
HELP: hard HELP: hard
{ $description "Possible input parameter to " { $link break } "." } ; { $description "Possible input parameter to " { $link line-break } "." } ;
{ soft hard } related-words { soft hard } related-words
@ -70,7 +70,7 @@ HELP: section
{ $class-description "A piece of prettyprinter output. Instances of this class are not used directly, instead one instantiates various classes which delegate to this class:" { $class-description "A piece of prettyprinter output. Instances of this class are not used directly, instead one instantiates various classes which delegate to this class:"
{ $list { $list
{ $link text } { $link text }
{ $link break } { $link line-break }
{ $link block } { $link block }
{ $link inset } { $link inset }
{ $link flow } { $link flow }
@ -123,7 +123,7 @@ HELP: pprint-section
{ $contract "Prints a section, performing wrapping and indentation using available formatting information." } { $contract "Prints a section, performing wrapping and indentation using available formatting information." }
$prettyprinting-note ; $prettyprinting-note ;
HELP: break HELP: line-break
{ $values { "type" { $link soft } " or " { $link hard } } } { $values { "type" { $link soft } " or " { $link hard } } }
{ $description "Adds a section introducing a line break to the current block. If the block is output as a " { $link short-section } ", all breaks are ignored. Otherwise, hard breaks introduce unconditional newlines, and soft breaks introduce a newline if the position is more than half of the " { $link margin } "." } { $description "Adds a section introducing a line break to the current block. If the block is output as a " { $link short-section } ", all breaks are ignored. Otherwise, hard breaks introduce unconditional newlines, and soft breaks introduce a newline if the position is more than half of the " { $link margin } "." }
$prettyprinting-note ; $prettyprinting-note ;
@ -158,11 +158,11 @@ HELP: save-end-position
HELP: pprint-sections HELP: pprint-sections
{ $values { "block" block } { "advancer" "a quotation with stack effect " { $snippet "( block -- )" } } } { $values { "block" block } { "advancer" "a quotation with stack effect " { $snippet "( block -- )" } } }
{ $description "Prints child sections of a block, ignoring any " { $link break } " sections. The " { $snippet "advancer" } " quotation is called between every pair of sections." } ; { $description "Prints child sections of a block, ignoring any " { $link line-break } " sections. The " { $snippet "advancer" } " quotation is called between every pair of sections." } ;
HELP: do-break HELP: do-break
{ $values { "break" break } } { $values { "break" line-break } }
{ $description "Prints a break section as per the policy outlined in " { $link break } "." } ; { $description "Prints a break section as per the policy outlined in " { $link line-break } "." } ;
HELP: empty-block? HELP: empty-block?
{ $values { "block" block } { "?" "a boolean" } } { $values { "block" block } { "?" "a boolean" } }

View File

@ -124,15 +124,16 @@ M: object short-section? section-fits? ;
] if ; ] if ;
! Break section ! Break section
TUPLE: break type ; TUPLE: line-break type ;
: <break> ( type -- section ) : <line-break> ( type -- section )
H{ } 0 <section> H{ } 0 <section>
{ set-break-type set-delegate } \ break construct ; { set-line-break-type set-delegate }
\ line-break construct ;
M: break short-section drop ; M: line-break short-section drop ;
M: break long-section drop ; M: line-break long-section drop ;
! Block sections ! Block sections
TUPLE: block sections ; TUPLE: block sections ;
@ -149,7 +150,8 @@ TUPLE: block sections ;
pprinter-block block-sections push ; pprinter-block block-sections push ;
: last-section ( -- section ) : last-section ( -- section )
pprinter-block block-sections [ break? not ] find-last nip ; pprinter-block block-sections
[ line-break? not ] find-last nip ;
: start-group ( -- ) : start-group ( -- )
t last-section set-section-start-group? ; t last-section set-section-start-group? ;
@ -162,13 +164,13 @@ TUPLE: block sections ;
swap short-section? and swap short-section? and
[ bl ] when ; [ bl ] when ;
: break ( type -- ) [ <break> add-section ] when* ; : line-break ( type -- ) [ <line-break> add-section ] when* ;
M: block section-fits? ( section -- ? ) M: block section-fits? ( section -- ? )
line-limit? [ drop t ] [ delegate section-fits? ] if ; line-limit? [ drop t ] [ delegate section-fits? ] if ;
: pprint-sections ( block advancer -- ) : pprint-sections ( block advancer -- )
swap block-sections [ break? not ] subset swap block-sections [ line-break? not ] subset
unclip pprint-section [ unclip pprint-section [
dup rot call pprint-section dup rot call pprint-section
] curry* each ; inline ] curry* each ; inline
@ -177,7 +179,7 @@ M: block short-section ( block -- )
[ advance ] pprint-sections ; [ advance ] pprint-sections ;
: do-break ( break -- ) : do-break ( break -- )
dup break-type hard eq? dup line-break-type hard eq?
over section-end last-newline get - margin get 2/ > or over section-end last-newline get - margin get 2/ > or
[ <fresh-line ] [ drop ] if ; [ <fresh-line ] [ drop ] if ;
@ -284,7 +286,7 @@ M: colon unindent-first-line? drop t ;
! Long section layout algorithm ! Long section layout algorithm
: chop-break ( seq -- seq ) : chop-break ( seq -- seq )
dup peek break? [ 1 head-slice* chop-break ] when ; dup peek line-break? [ 1 head-slice* chop-break ] when ;
SYMBOL: prev SYMBOL: prev
SYMBOL: next SYMBOL: next
@ -322,7 +324,7 @@ M: block long-section ( block -- )
[ [
block-sections chop-break group-flow [ block-sections chop-break group-flow [
dup ?break-group [ dup ?break-group [
dup break? [ dup line-break? [
do-break do-break
] [ ] [
dup advance pprint-section dup advance pprint-section

View File

@ -655,3 +655,10 @@ PRIVATE>
: trim ( seq quot -- newseq ) : trim ( seq quot -- newseq )
[ ltrim ] keep rtrim ; inline [ ltrim ] keep rtrim ; inline
: unfold ( obj pred quot exemplar -- seq )
[
10 swap new-resizable [
[ push ] curry compose [ drop ] while
] keep
] keep like ; inline

View File

@ -106,7 +106,8 @@ M: tuple equal?
: (delegates) ( obj -- ) : (delegates) ( obj -- )
[ dup , delegate (delegates) ] when* ; [ dup , delegate (delegates) ] when* ;
: delegates ( obj -- seq ) [ (delegates) ] { } make ; : delegates ( obj -- seq )
[ dup ] [ [ delegate ] keep ] { } unfold ;
: is? ( obj quot -- ? ) >r delegates r> contains? ; inline : is? ( obj quot -- ? ) >r delegates r> contains? ; inline

View File

@ -33,7 +33,7 @@ PRIVATE>
: >base64 ( seq -- base64 ) : >base64 ( seq -- base64 )
#! cut string into two pieces, convert 3 bytes at a time #! cut string into two pieces, convert 3 bytes at a time
#! pad string with = when not enough bits #! pad string with = when not enough bits
dup length dup 3 mod - swap dup length dup 3 mod - cut swap
[ [
3 group [ encode3 % ] each 3 group [ encode3 % ] each
dup empty? [ drop ] [ >base64-rem % ] if dup empty? [ drop ] [ >base64-rem % ] if

View File

@ -40,17 +40,11 @@ PRIVATE>
(mailbox-block-if-empty) (mailbox-block-if-empty)
mailbox-data dlist-pop-front ; mailbox-data dlist-pop-front ;
<PRIVATE
: (mailbox-get-all) ( mailbox -- )
dup mailbox-empty? [
drop
] [
dup mailbox-data dlist-pop-front , (mailbox-get-all)
] if ;
PRIVATE>
: mailbox-get-all ( mailbox -- array ) : mailbox-get-all ( mailbox -- array )
(mailbox-block-if-empty) (mailbox-block-if-empty)
[ (mailbox-get-all) ] { } make ; [ dup mailbox-empty? ]
[ dup mailbox-data dlist-pop-front ]
{ } unfold ;
: while-mailbox-empty ( mailbox quot -- ) : while-mailbox-empty ( mailbox quot -- )
over mailbox-empty? [ over mailbox-empty? [

View File

@ -13,11 +13,8 @@ M: link uses
{ $subsection $link $see-also } { $subsection $link $see-also }
collect-elements [ \ f or ] map ; collect-elements [ \ f or ] map ;
: (help-path) ( topic -- )
article-parent [ dup , (help-path) ] when* ;
: help-path ( topic -- seq ) : help-path ( topic -- seq )
[ (help-path) ] { } make ; [ dup ] [ [ article-parent ] keep ] { } unfold 1 tail ;
: set-article-parents ( parent article -- ) : set-article-parents ( parent article -- )
article-children [ set-article-parent ] curry* each ; article-children [ set-article-parent ] curry* each ;

View File

@ -94,11 +94,10 @@ M: f parse-sockaddr nip ;
swap addrinfo-family addrspec-of-family swap addrinfo-family addrspec-of-family
parse-sockaddr ; parse-sockaddr ;
: addrspec, ( addrinfo -- )
[ dup addrinfo>addrspec , addrinfo-next addrspec, ] when* ;
: parse-addrinfo-list ( addrinfo -- seq ) : parse-addrinfo-list ( addrinfo -- seq )
[ addrspec, ] { } make [ ] subset ; [ dup ]
[ dup addrinfo-next swap addrinfo>addrspec ]
{ } unfold [ ] subset ;
M: object resolve-host ( host serv passive? -- seq ) M: object resolve-host ( host serv passive? -- seq )
>r dup integer? [ number>string ] when >r dup integer? [ number>string ] when

View File

@ -59,3 +59,13 @@ C: <serialize-test> serialize-test
[ t ] [ objects [ check-serialize-2 ] all? ] unit-test [ t ] [ objects [ check-serialize-2 ] all? ] unit-test
[ t ] [ pi check-serialize-1 ] unit-test [ t ] [ pi check-serialize-1 ] unit-test
[ t ] [
{ 1 2 3 } [
[
dup (serialize) (serialize)
] with-serialized
] string-out [
deserialize-sequence all-eq?
] string-in
] unit-test

View File

@ -260,11 +260,8 @@ DEFER: (deserialize) ( -- obj )
: with-serialized ( quot -- ) : with-serialized ( quot -- )
V{ } clone serialized rot with-variable ; inline V{ } clone serialized rot with-variable ; inline
: (deserialize-sequence)
deserialize* [ , (deserialize-sequence) ] [ drop ] if ;
: deserialize-sequence ( -- seq ) : deserialize-sequence ( -- seq )
[ (deserialize-sequence) ] { } make ; [ [ deserialize* ] [ ] { } unfold ] with-serialized ;
: deserialize ( -- obj ) : deserialize ( -- obj )
[ (deserialize) ] with-serialized ; [ (deserialize) ] with-serialized ;

View File

@ -11,7 +11,7 @@ IN: store.blob
: (load-blob) ( path -- seq/f ) : (load-blob) ( path -- seq/f )
dup exists? [ dup exists? [
<file-reader> [ <file-reader> [
[ deserialize-sequence ] with-serialized deserialize-sequence
] with-stream ] with-stream
] [ ] [
drop f drop f

View File

@ -285,11 +285,8 @@ M: gadget ungraft* drop ;
: add-gadgets ( seq parent -- ) : add-gadgets ( seq parent -- )
swap [ over (add-gadget) ] each relayout ; swap [ over (add-gadget) ] each relayout ;
: (parents) ( gadget -- )
[ dup , gadget-parent (parents) ] when* ;
: parents ( gadget -- seq ) : parents ( gadget -- seq )
[ (parents) ] { } make ; [ dup ] [ [ gadget-parent ] keep ] { } unfold ;
: each-parent ( gadget quot -- ? ) : each-parent ( gadget quot -- ? )
>r parents r> all? ; inline >r parents r> all? ; inline
@ -335,11 +332,8 @@ M: f request-focus-on 2drop ;
: request-focus ( gadget -- ) : request-focus ( gadget -- )
dup focusable-child swap request-focus-on ; dup focusable-child swap request-focus-on ;
: (focus-path) ( gadget -- )
[ dup , gadget-focus (focus-path) ] when* ;
: focus-path ( world -- seq ) : focus-path ( world -- seq )
[ (focus-path) ] { } make ; [ dup ] [ [ gadget-focus ] keep ] { } unfold ;
: make-gadget ( quot gadget -- gadget ) : make-gadget ( quot gadget -- gadget )
[ \ make-gadget rot with-variable ] keep ; inline [ \ make-gadget rot with-variable ] keep ; inline

View File

@ -1,6 +1,7 @@
USING: sequences rss arrays concurrency kernel sorting USING: sequences rss arrays concurrency kernel sorting
html.elements io assocs namespaces math threads vocabs html html.elements io assocs namespaces math threads vocabs html
furnace http.server.templating calendar math.parser splitting ; furnace http.server.templating calendar math.parser splitting
continuations debugger ;
IN: webapps.planet IN: webapps.planet
TUPLE: posting author title date link body ; TUPLE: posting author title date link body ;

View File

@ -16,13 +16,6 @@ IN: windows.kernel32
: GENERIC_EXECUTE HEX: 20000000 ; inline : GENERIC_EXECUTE HEX: 20000000 ; inline
: GENERIC_ALL HEX: 10000000 ; inline : GENERIC_ALL HEX: 10000000 ; inline
: DELETE HEX: 00010000 ; inline
: READ_CONTROL HEX: 00020000 ; inline
: WRITE_DAC HEX: 00040000 ; inline
: WRITE_OWNER HEX: 00080000 ; inline
: SYNCHRONIZE HEX: 00100000 ; inline
: STANDARD_RIGHTS_REQUIRED HEX: 000f0000 ; inline
: CREATE_NEW 1 ; inline : CREATE_NEW 1 ; inline
: CREATE_ALWAYS 2 ; inline : CREATE_ALWAYS 2 ; inline
: OPEN_EXISTING 3 ; inline : OPEN_EXISTING 3 ; inline

View File

@ -35,7 +35,7 @@ M: string item>xml ! This should change < and &
2array "member" build-tag* ; 2array "member" build-tag* ;
M: hashtable item>xml M: hashtable item>xml
[ [ struct-member , ] assoc-each ] { } make [ struct-member ] { } assoc>map
"struct" build-tag* ; "struct" build-tag* ;
M: array item>xml M: array item>xml