Some cleanups to start 0.84

slava 2006-07-28 07:54:46 +00:00
parent 08e81025be
commit 03f625cea1
19 changed files with 50 additions and 74 deletions

View File

@ -3,8 +3,8 @@ CC = gcc
BINARY = f BINARY = f
IMAGE = factor.image IMAGE = factor.image
BUNDLE = Factor.app BUNDLE = Factor.app
DISK_IMAGE_DIR = Factor-0.83 DISK_IMAGE_DIR = Factor-0.84
DISK_IMAGE = Factor-0.83.dmg DISK_IMAGE = Factor-0.84.dmg
ifdef DEBUG ifdef DEBUG
CFLAGS = -g CFLAGS = -g

View File

@ -9,6 +9,7 @@
+ ui: + ui:
- gadgets/fields unit test fails if UI not running
- "benchmark/help" runs out of memory - "benchmark/help" runs out of memory
- shortcuts: - shortcuts:
- find a listener - find a listener
@ -113,7 +114,7 @@
+ misc: + misc:
- consider: swap tail --> tail, swap head --> head - consider: swap tail --> tail, swap head --> head, swap group --> group
- mach_signal: fault address reporting is not reliable - mach_signal: fault address reporting is not reliable
- slice: if sequence or seq start is changed, abstraction violation - slice: if sequence or seq start is changed, abstraction violation
- hashed generic method dispatch - hashed generic method dispatch

View File

@ -85,8 +85,6 @@ ARTICLE: "debugger" "The debugger"
{ $subsection :r } { $subsection :r }
{ $subsection :c } { $subsection :c }
{ $subsection :get } { $subsection :get }
{ $subsection :error }
{ $subsection :cc }
"If the error is recoverable, a list of restarts is also printed, and a numbered restart can be invoked:" "If the error is recoverable, a list of restarts is also printed, and a numbered restart can be invoked:"
{ $subsection :res } { $subsection :res }
"You can read more about error handling in " { $link "errors" } "." ; "You can read more about error handling in " { $link "errors" } "." ;

View File

@ -9,8 +9,8 @@ vectors ;
[ rot >r [ swap call ] keep r> set-array-nth ] 3keep [ rot >r [ swap call ] keep r> set-array-nth ] 3keep
] repeat drop ; inline ] repeat drop ; inline
: (map) ( quot seq i -- quot seq value ) : (map) ( seq quot i -- quot seq value )
pick pick >r >r swap nth-unsafe swap call r> r> rot ; inline -rot [ >r nth-unsafe r> call ] 2keep rot ; inline
: (2each) ( quot seq seq i -- quot seq seq i ) : (2each) ( quot seq seq i -- quot seq seq i )
[ 2nth-unsafe rot dup slip ] 3keep ; inline [ 2nth-unsafe rot dup slip ] 3keep ; inline
@ -30,13 +30,6 @@ vectors ;
t <array> f 0 pick set-nth-unsafe t <array> f 0 pick set-nth-unsafe
] if ; ] if ;
: select ( seq quot quot -- seq )
pick >r >r V{ } clone rot [
-rot [
>r over >r call [ r> r> push ] [ r> r> 2drop ] if
] 2keep
] r> call r> like nip ; inline
IN: sequences IN: sequences
: each ( seq quot -- | quot: elt -- ) : each ( seq quot -- | quot: elt -- )
@ -51,22 +44,21 @@ IN: sequences
swapd each ; inline swapd each ; inline
: map ( seq quot -- seq | quot: elt -- elt ) : map ( seq quot -- seq | quot: elt -- elt )
swap [ dup length [ (map) ] collect ] keep like 2nip ; over >r over length [ (map) ] collect r> like 2nip ;
inline inline
: map-with ( obj list quot -- list | quot: obj elt -- elt ) : map-with ( obj list quot -- list | quot: obj elt -- elt )
swap [ with rot ] map 2nip ; inline swap [ with rot ] map 2nip ; inline
: accumulate ( list identity quot -- values | quot: x y -- z ) : accumulate ( seq identity quot -- values | quot: x y -- z )
rot [ pick >r swap call r> ] map-with nip ; inline rot [ pick >r swap call r> ] map-with nip ; inline
: change-nth ( seq i quot -- ) : change-nth ( i seq quot -- )
pick pick >r >r >r swap nth -rot [ nth swap call ] 2keep set-nth ; inline
r> call r> r> swap set-nth ; inline
: inject ( seq quot -- | quot: elt -- elt ) : inject ( seq quot -- | quot: elt -- elt )
over length over length
[ [ swap change-nth ] 3keep ] repeat 2drop ; [ [ -rot change-nth ] 3keep ] repeat 2drop ;
inline inline
: inject-with ( obj seq quot -- | quot: obj elt -- elt ) : inject-with ( obj seq quot -- | quot: obj elt -- elt )
@ -141,7 +133,11 @@ IN: sequences
swap [ with rot ] all? 2nip ; inline swap [ with rot ] all? 2nip ; inline
: subset ( seq quot -- seq | quot: elt -- ? ) : subset ( seq quot -- seq | quot: elt -- ? )
[ each ] select ; inline over >r over length <vector> rot [
-rot [
>r over >r call [ r> r> push ] [ r> r> 2drop ] if
] 2keep
] each r> like nip ; inline
: subset-with ( obj seq quot -- seq | quot: obj elt -- ? ) : subset-with ( obj seq quot -- seq | quot: obj elt -- ? )
swap [ with rot ] subset 2nip ; inline swap [ with rot ] subset 2nip ; inline
@ -178,5 +174,5 @@ IN: sequences
pick rot call [ pick rot call [
drop clone drop clone
] [ ] [
over >r >r length r> call dup 0 swap r> copy-into over >r >r length r> call 0 over r> copy-into
] if ; inline ] if ; inline

View File

@ -35,8 +35,8 @@ HELP: map-with "( obj seq quot -- newseq )"
{ $values { "obj" "an object" } { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( obj elt -- new )" } } } { $values { "obj" "an object" } { "seq" "a sequence" } { "quot" "a quotation with stack effect " { $snippet "( obj elt -- new )" } } }
{ $description "Variant of " { $link map } " which pushes a retained object on each invocation of the quotation." } ; { $description "Variant of " { $link map } " which pushes a retained object on each invocation of the quotation." } ;
HELP: change-nth "( seq i quot -- )" HELP: change-nth "( i seq quot -- )"
{ $values { "seq" "a mutable sequence" } { "i" "a non-negative integer" } { "quot" "a quotation with stack effect " { $snippet "( elt -- newelt )" } } } { $values { "i" "a non-negative integer" } { "seq" "a mutable sequence" } { "quot" "a quotation with stack effect " { $snippet "( elt -- newelt )" } } }
{ $description "Applies the quotation to the " { $snippet "i" } "th element of the sequence, storing the result back into the sequence." } { $description "Applies the quotation to the " { $snippet "i" } "th element of the sequence, storing the result back into the sequence." }
{ $errors "Throws an error if the sequence is immutable, if the index is out of bounds, or the sequence cannot hold elements of the type output by " { $snippet "quot" } "." } { $errors "Throws an error if the sequence is immutable, if the index is out of bounds, or the sequence cannot hold elements of the type output by " { $snippet "quot" } "." }
{ $side-effects "seq" } ; { $side-effects "seq" } ;

View File

@ -50,7 +50,7 @@ M: object like drop ;
: (delete) ( elt store scan seq -- ) : (delete) ( elt store scan seq -- )
2dup length < [ 2dup length < [
3dup move 3dup move
>r pick over r> dup >r nth = r> swap [ nth pick = ] 2keep rot
[ >r >r 1+ r> r> ] unless >r 1+ r> (delete) [ >r >r 1+ r> r> ] unless >r 1+ r> (delete)
] when ; ] when ;
@ -100,10 +100,11 @@ M: object like drop ;
: all-eq? ( seq -- ? ) [ eq? ] monotonic? ; : all-eq? ( seq -- ? ) [ eq? ] monotonic? ;
: (mismatch) ( seq1 seq2 n -- i )
[ >r 2dup r> 2nth-unsafe = not ] find drop 2nip ; inline
: mismatch ( seq1 seq2 -- i ) : mismatch ( seq1 seq2 -- i )
2dup min-length 2dup min-length (mismatch) ;
[ >r 2dup r> 2nth-unsafe = not ] find
swap >r 3drop r> ;
: flip ( seq -- seq ) : flip ( seq -- seq )
dup empty? [ dup empty? [
@ -127,11 +128,8 @@ M: object like drop ;
: last/first ( seq -- pair ) dup peek swap first 2array ; : last/first ( seq -- pair ) dup peek swap first 2array ;
: sequence= ( seq seq -- ? ) : sequence= ( seq seq -- ? )
2dup [ length ] 2apply number= [ 2dup [ length ] 2apply tuck number=
dup length [ >r 2dup r> 2nth-unsafe = ] all? 2nip [ (mismatch) -1 number= ] [ 3drop f ] if ;
] [
2drop f
] if ;
UNION: sequence array string sbuf vector quotation ; UNION: sequence array string sbuf vector quotation ;

View File

@ -26,9 +26,6 @@ GENERIC: like ( seq seq -- seq )
: bounds-check? ( n seq -- ? ) : bounds-check? ( n seq -- ? )
over 0 >= [ length < ] [ 2drop f ] if ; inline over 0 >= [ length < ] [ 2drop f ] if ; inline
: ?nth ( n seq/f -- elt/f )
2dup bounds-check? [ nth ] [ 2drop f ] if ;
IN: sequences-internals IN: sequences-internals
GENERIC: resize ( n seq -- seq ) GENERIC: resize ( n seq -- seq )
@ -61,3 +58,8 @@ M: integer nth-unsafe drop ;
: exchange-unsafe ( n n seq -- ) : exchange-unsafe ( n n seq -- )
[ tuck nth-unsafe >r nth-unsafe r> ] 3keep tuck [ tuck nth-unsafe >r nth-unsafe r> ] 3keep tuck
>r >r set-nth-unsafe r> r> set-nth-unsafe ; inline >r >r set-nth-unsafe r> r> set-nth-unsafe ; inline
IN: sequences
: ?nth ( n seq/f -- elt/f )
2dup bounds-check? [ nth-unsafe ] [ 2drop f ] if ;

View File

@ -48,7 +48,7 @@ strings vectors ;
tuck >r >r head-slice r> r> tail-slice swapd append3 ; tuck >r >r head-slice r> r> tail-slice swapd append3 ;
: remove-nth ( n seq -- seq ) : remove-nth ( n seq -- seq )
[ head-slice ] 2keep >r 1+ r> tail-slice append ; f -rot dupd replace-slice ;
: (cut) ( n seq -- before after ) : (cut) ( n seq -- before after )
[ head ] 2keep tail-slice ; [ head ] 2keep tail-slice ;

View File

@ -17,7 +17,7 @@ M: string hashcode
dup rehash-string string-hashcode dup rehash-string string-hashcode
] ?if ; ] ?if ;
M: string nth bounds-check char-slot ; M: string nth bounds-check nth-unsafe ;
M: string nth-unsafe >r >fixnum r> char-slot ; M: string nth-unsafe >r >fixnum r> char-slot ;
@ -45,8 +45,6 @@ PREDICATE: integer control "\0\e\r\n\t\u0008\u007f" member? ;
: >upper ( str -- str ) [ ch>upper ] map ; : >upper ( str -- str ) [ ch>upper ] map ;
: quotable? ( ch -- ? ) : quotable? ( ch -- ? )
#! In a string literal, can this character be used without
#! escaping?
dup printable? swap "\"\\" member? not and ; foldable dup printable? swap "\"\\" member? not and ; foldable
: padding ( string count char -- string ) : padding ( string count char -- string )

View File

@ -8,6 +8,8 @@ USE: test
USE: sequences USE: sequences
USE: vectors USE: vectors
[ CHAR: b ] [ 1 >bignum "abc" nth ] unit-test
[ ] [ 10 [ [ -1000000 <sbuf> ] catch drop ] times ] unit-test [ ] [ 10 [ [ -1000000 <sbuf> ] catch drop ] times ] unit-test
[ "abc" ] [ [ "a" "b" "c" ] [ [ % ] each ] "" make ] unit-test [ "abc" ] [ [ "a" "b" "c" ] [ [ % ] each ] "" make ] unit-test

View File

@ -148,9 +148,6 @@ M: object error. ( error -- ) . ;
dup length [ restart. ] 2each dup length [ restart. ] 2each
] if ; ] if ;
DEFER: :error
DEFER: :cc
: debug-help ( -- ) : debug-help ( -- )
terpri terpri
"Debugger commands:" print "Debugger commands:" print
@ -158,8 +155,6 @@ DEFER: :cc
":s data stack at exception time" [ :s ] (debug-help) ":s data stack at exception time" [ :s ] (debug-help)
":r retain stack at exception time" [ :r ] (debug-help) ":r retain stack at exception time" [ :r ] (debug-help)
":c call stack at exception time" [ :c ] (debug-help) ":c call stack at exception time" [ :c ] (debug-help)
":error starts the inspector with the error" [ :error ] (debug-help)
":cc starts the inspector with the error continuation" [ :cc ] (debug-help)
":get ( var -- value ) accesses variables at time of error" print ":get ( var -- value ) accesses variables at time of error" print
flush ; flush ;

View File

@ -78,7 +78,7 @@ DEFER: describe
: sheet. ( sheet -- ) : sheet. ( sheet -- )
flip flip
H{ { table-gap { 10 0 0 } } } H{ { table-gap { 10 0 } } }
[ dup unparse-short swap write-object ] [ dup unparse-short swap write-object ]
tabular-output ; tabular-output ;

View File

@ -47,9 +47,3 @@ SYMBOL: inspector-stack
: go ( n -- ) inspector-slots get nth (inspect) ; : go ( n -- ) inspector-slots get nth (inspect) ;
: up ( -- ) inspector-stack get dup pop* pop (inspect) ; : up ( -- ) inspector-stack get dup pop* pop (inspect) ;
! Another feature.
IN: errors
: :error ( -- ) error get inspect ;
: :cc ( -- ) error-continuation get inspect ;

View File

@ -28,9 +28,3 @@ HELP: go "( n -- )"
HELP: up "( -- )" HELP: up "( -- )"
{ $description "Returns to the previously-inspected object." } ; { $description "Returns to the previously-inspected object." } ;
HELP: :error "( -- )"
{ $description "Opens an inspector with the most recently thrown error." } ;
HELP: :cc "( -- )"
{ $description "Opens an inspector with the continuation reified at the time of the most recently thrown error." } ;

View File

@ -8,7 +8,7 @@ parser prettyprint sequences strings words ;
! edit files and position the cursor on a specific line number. ! edit files and position the cursor on a specific line number.
: jedit-server-info ( -- port auth ) : jedit-server-info ( -- port auth )
"~" get "/.jedit/server" append <file-reader> [ "~" get "/.jedit/server" path+ <file-reader> [
readln drop readln drop
readln string>number readln string>number
readln string>number readln string>number
@ -90,4 +90,4 @@ IN: shells
"telnetd-port" get string>number telnetd ; "telnetd-port" get string>number telnetd ;
! This is a string since we string>number it above. ! This is a string since we string>number it above.
global [ "9999" "telnetd-port" set ] bind "9999" "telnetd-port" set-global

View File

@ -20,7 +20,12 @@ strings styles vectors words ;
: total, ( n str -- ) : total, ( n str -- )
[ , number>string , "" , "" , ] { } make , ; [ , number>string , "" , "" , ] { } make , ;
: room-table ( -- table ) : simple-table ( table -- )
H{ { table-gap { 10 0 } } }
[ dup string? [ write ] [ pprint ] if ]
tabular-output ;
: room. ( -- )
room [ room [
{ "" "Total" "Used" "Free" } , { "" "Total" "Used" "Free" } ,
0 [ 0 [
@ -30,11 +35,7 @@ strings styles vectors words ;
"Semi-space" total, "Semi-space" total,
"Cards" total, "Cards" total,
"Code space" total/used/free, "Code space" total/used/free,
] [ ] make ; ] { } make simple-table ;
: room. ( -- )
room-table H{ { table-gap { 10 0 0 } } }
[ write ] tabular-output ;
! Some words for iterating through the heap. ! Some words for iterating through the heap.
@ -70,7 +71,4 @@ strings styles vectors words ;
( hash hash key -- ) ( hash hash key -- )
[ dup , dup pick hash , pick hash , ] { } make , [ dup , dup pick hash , pick hash , ] { } make ,
] each 2drop ] each 2drop
] { } make ] { } make simple-table ;
H{ { table-gap { 10 0 0 } } }
[ dup string? [ write ] [ pprint ] if ]
tabular-output ;

View File

@ -59,7 +59,7 @@ M: track pref-dim* ( track -- dim )
: set-nth-0 ( n seq -- old ) 2dup nth >r 0 -rot set-nth r> ; : set-nth-0 ( n seq -- old ) 2dup nth >r 0 -rot set-nth r> ;
: +nth ( delta n seq -- ) swap [ + ] change-nth ; : +nth ( delta n seq -- ) [ + ] change-nth ;
: clamp-nth ( i j sizes -- ) [ set-nth-0 swap ] keep +nth ; : clamp-nth ( i j sizes -- ) [ set-nth-0 swap ] keep +nth ;

View File

@ -71,10 +71,10 @@ C: document ( -- document )
] if r> peek length + 2array ; ] if r> peek length + 2array ;
: prepend-first ( str seq -- seq ) : prepend-first ( str seq -- seq )
0 [ append ] change-nth ; 0 swap [ append ] change-nth ;
: append-last ( str seq -- seq ) : append-last ( str seq -- seq )
dup length 1- [ swap append ] change-nth ; [ length 1- ] keep [ swap append ] change-nth ;
: loc-col/str ( loc document -- col str ) : loc-col/str ( loc document -- col str )
>r first2 swap r> nth ; >r first2 swap r> nth ;

View File

@ -1,2 +1,2 @@
IN: kernel IN: kernel
: version "0.83" ; : version "0.84" ;