Merge branch 'master' of git://factorcode.org/git/factor

db4
Doug Coleman 2008-02-27 19:30:47 -06:00
commit 5caf407517
34 changed files with 307 additions and 180 deletions

View File

@ -367,7 +367,7 @@ TUPLE: callback-context ;
] if ; ] if ;
: do-callback ( quot token -- ) : do-callback ( quot token -- )
init-error-handler init-catchstack
dup 2 setenv dup 2 setenv
slip slip
wait-to-return ; inline wait-to-return ; inline

View File

@ -1,11 +1,11 @@
! Copyright (C) 2004, 2007 Slava Pestov. ! Copyright (C) 2004, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
IN: bootstrap.stage1 IN: bootstrap.stage1
USING: arrays debugger generic hashtables io assocs USING: arrays debugger generic hashtables io assocs
kernel.private kernel math memory namespaces parser kernel.private kernel math memory namespaces parser
prettyprint sequences vectors words system splitting prettyprint sequences vectors words system splitting
init io.files bootstrap.image bootstrap.image.private vocabs init io.files bootstrap.image bootstrap.image.private vocabs
vocabs.loader system ; vocabs.loader system debugger continuations ;
{ "resource:core" } vocab-roots set { "resource:core" } vocab-roots set
@ -40,7 +40,14 @@ vocabs.loader system ;
[ [
"resource:core/bootstrap/stage2.factor" "resource:core/bootstrap/stage2.factor"
dup resource-exists? [ dup resource-exists? [
run-file [ run-file ]
[
:c
dup print-error flush
"listener" vocab
[ restarts. vocab-main execute ]
[ die ] if*
] recover
] [ ] [
"Cannot find " write write "." print "Cannot find " write write "." print
"Please move " write image write " to the same directory as the Factor sources," print "Please move " write image write " to the same directory as the Factor sources," print

View File

@ -51,66 +51,60 @@ SYMBOL: bootstrap-time
! Wrap everything in a catch which starts a listener so ! Wrap everything in a catch which starts a listener so
! you can see what went wrong, instead of dealing with a ! you can see what went wrong, instead of dealing with a
! fep ! fep
[
! We time bootstrap
millis >r
default-image-name "output-image" set-global ! We time bootstrap
millis >r
"math help handbook compiler tools ui ui.tools io" "include" set-global default-image-name "output-image" set-global
"" "exclude" set-global
parse-command-line "math help handbook compiler tools ui ui.tools io" "include" set-global
"" "exclude" set-global
"-no-crossref" cli-args member? [ do-crossref ] unless parse-command-line
! Set dll paths "-no-crossref" cli-args member? [ do-crossref ] unless
wince? [ "windows.ce" require ] when
winnt? [ "windows.nt" require ] when
"deploy-vocab" get [ ! Set dll paths
"stage2: deployment mode" print wince? [ "windows.ce" require ] when
] [ winnt? [ "windows.nt" require ] when
"listener" require
"none" require
] if
[ "deploy-vocab" get [
load-components "stage2: deployment mode" print
run-bootstrap-init
"bootstrap.compiler" vocab [
compile-remaining
] when
] with-compiler-errors
:errors
f error set-global
f error-continuation set-global
"deploy-vocab" get [
"tools.deploy.shaker" run
] [
[
boot
do-init-hooks
[
parse-command-line
run-user-init
"run" get run
stdio get [ stream-flush ] when*
] [ print-error 1 exit ] recover
] set-boot-quot
millis r> - dup bootstrap-time set-global
print-report
"output-image" get resource-path save-image-and-exit
] if
] [ ] [
:c "listener" require
print-error restarts. "none" require
"listener" vocab-main execute ] if
1 exit
] recover [
load-components
run-bootstrap-init
"bootstrap.compiler" vocab [
compile-remaining
] when
] with-compiler-errors
:errors
f error set-global
f error-continuation set-global
"deploy-vocab" get [
"tools.deploy.shaker" run
] [
[
boot
do-init-hooks
[
parse-command-line
run-user-init
"run" get run
stdio get [ stream-flush ] when*
] [ print-error 1 exit ] recover
] set-boot-quot
millis r> - dup bootstrap-time set-global
print-report
"output-image" get resource-path save-image-and-exit
] if

View File

@ -193,6 +193,3 @@ HELP: save-error
{ $values { "error" "an error" } } { $values { "error" "an error" } }
{ $description "Called by the error handler to set the " { $link error } " and " { $link restarts } " global variables after an error was thrown." } { $description "Called by the error handler to set the " { $link error } " and " { $link restarts } " global variables after an error was thrown." }
$low-level-note ; $low-level-note ;
HELP: init-error-handler
{ $description "Called on startup to initialize the catch stack and set a pair of hooks which allow the Factor VM to signal errors to library code." } ;

View File

@ -6,6 +6,7 @@ IN: continuations
SYMBOL: error SYMBOL: error
SYMBOL: error-continuation SYMBOL: error-continuation
SYMBOL: error-thread
SYMBOL: restarts SYMBOL: restarts
<PRIVATE <PRIVATE
@ -24,6 +25,8 @@ SYMBOL: restarts
#! with a declaration. #! with a declaration.
f { object } declare ; f { object } declare ;
: init-catchstack V{ } clone 1 setenv ;
PRIVATE> PRIVATE>
: catchstack ( -- catchstack ) catchstack* clone ; inline : catchstack ( -- catchstack ) catchstack* clone ; inline
@ -169,17 +172,3 @@ M: condition compute-restarts
condition-continuation condition-continuation
[ <restart> ] curry { } assoc>map [ <restart> ] curry { } assoc>map
append ; append ;
<PRIVATE
: init-error-handler ( -- )
V{ } clone set-catchstack
! VM calls on error
[
continuation error-continuation set-global rethrow
] 5 setenv
! VM adds this to kernel errors, so that user-space
! can identify them
"kernel-error" 6 setenv ;
PRIVATE>

View File

@ -1,6 +1,6 @@
USING: alien arrays generic generic.math help.markup help.syntax USING: alien arrays generic generic.math help.markup help.syntax
kernel math memory strings sbufs vectors io io.files classes kernel math memory strings sbufs vectors io io.files classes
help generic.standard continuations system ; help generic.standard continuations system debugger.private ;
IN: debugger IN: debugger
ARTICLE: "errors-assert" "Assertions" ARTICLE: "errors-assert" "Assertions"
@ -80,9 +80,6 @@ HELP: print-error
HELP: restarts. HELP: restarts.
{ $description "Print a list of restarts for the most recently thrown error to the " { $link stdio } " stream." } ; { $description "Print a list of restarts for the most recently thrown error to the " { $link stdio } " stream." } ;
HELP: debug-help
{ $description "Print a synopsis of useful debugger words." } ;
HELP: error-hook HELP: error-hook
{ $var-description "A quotation with stack effect " { $snippet "( error -- )" } " which is used by " { $link try } " to report the error to the user." } { $var-description "A quotation with stack effect " { $snippet "( error -- )" } " which is used by " { $link try } " to report the error to the user." }
{ $examples "The default value prints the error with " { $link print-error } ", followed by a list of restarts and a help message. The graphical listener sets this variable to display a popup instead." } ; { $examples "The default value prints the error with " { $link print-error } ", followed by a list of restarts and a help message. The graphical listener sets this variable to display a popup instead." } ;
@ -169,3 +166,6 @@ HELP: depth
HELP: assert-depth HELP: assert-depth
{ $values { "quot" "a quotation" } } { $values { "quot" "a quotation" } }
{ $description "Runs a quotation. Throws an error if the total number of elements on the stack is not the same before and after the quotation runs." } ; { $description "Runs a quotation. Throws an error if the total number of elements on the stack is not the same before and after the quotation runs." } ;
HELP: init-debugger
{ $description "Called on startup to set a pair of hooks which allow the " { $link throw } " word to function." } ;

View File

@ -5,7 +5,8 @@ math namespaces prettyprint sequences assocs sequences.private
strings io.styles vectors words system splitting math.parser strings io.styles vectors words system splitting math.parser
tuples continuations continuations.private combinators tuples continuations continuations.private combinators
generic.math io.streams.duplex classes compiler.units generic.math io.streams.duplex classes compiler.units
generic.standard vocabs ; generic.standard vocabs threads threads.private init
kernel.private ;
IN: debugger IN: debugger
GENERIC: error. ( error -- ) GENERIC: error. ( error -- )
@ -57,27 +58,30 @@ M: string error. print ;
dup length [ restart. ] 2each dup length [ restart. ] 2each
] if ; ] if ;
: debug-help ( -- )
nl
"Debugger commands:" print
nl
":help - documentation for this error" print
":s - data stack at exception time" print
":r - retain stack at exception time" print
":c - call stack at exception time" print
":edit - jump to source location (parse errors only)" print
":get ( var -- value ) accesses variables at time of the error" print
flush ;
: print-error ( error -- ) : print-error ( error -- )
[ error. flush ] curry [ error. flush ] curry
[ global [ "Error in print-error!" print drop ] bind ] [ global [ "Error in print-error!" print drop ] bind ]
recover ; recover ;
: error-in-thread. ( -- )
error-thread get-global
"Error in thread " write
[
dup thread-id #
" (" % dup thread-name %
", " % dup thread-quot unparse-short % ")" %
] "" make
swap write-object ":" print nl ;
SYMBOL: error-hook SYMBOL: error-hook
[ print-error restarts. debug-help ] error-hook set-global [
error-in-thread.
print-error
restarts.
nl
"Type :help for debugging help." print flush
] error-hook set-global
: try ( quot -- ) : try ( quot -- )
[ error-hook get call ] recover ; [ error-hook get call ] recover ;
@ -260,3 +264,31 @@ M: no-compilation-unit error.
M: no-vocab summary M: no-vocab summary
drop "Vocabulary does not exist" ; drop "Vocabulary does not exist" ;
! Hooks
M: thread error-in-thread ( error thread -- )
initial-thread get-global eq? [
die drop
] [
global [
error-in-thread. print-error flush
] bind
] if ;
<PRIVATE
: init-debugger ( -- )
V{ } clone set-catchstack
! VM calls on error
[
self error-thread set-global
continuation error-continuation set-global
rethrow
] 5 setenv
! VM adds this to kernel errors, so that user-space
! can identify them
"kernel-error" 6 setenv ;
PRIVATE>
[ init-debugger ] "debugger" add-init-hook

View File

@ -0,0 +1,7 @@
IN: temporary
USING: init namespaces sequences math tools.test kernel ;
[ t ] [
init-hooks get [ first "libc" = ] find drop
init-hooks get [ first "io.backend" = ] find drop <
] unit-test

View File

@ -15,7 +15,7 @@ init-hooks global [ drop V{ } clone ] cache drop
dup init-hooks get at [ over call ] unless dup init-hooks get at [ over call ] unless
init-hooks get set-at ; init-hooks get set-at ;
: boot ( -- ) init-namespaces init-error-handler ; : boot ( -- ) init-namespaces init-catchstack ;
: boot-quot ( -- quot ) 20 getenv ; : boot-quot ( -- quot ) 20 getenv ;

View File

@ -46,7 +46,7 @@ M: realloc-error summary drop "Memory reallocation failed" ;
<PRIVATE <PRIVATE
[ H{ } clone mallocs set-global ] "mallocs" add-init-hook [ H{ } clone mallocs set-global ] "libc" add-init-hook
: add-malloc ( alien -- ) : add-malloc ( alien -- )
dup mallocs get-global set-at ; dup mallocs get-global set-at ;

View File

@ -429,7 +429,7 @@ HELP: collect
HELP: each HELP: each
{ $values { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } } { $values { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( elt -- )" } } }
{ $description "Applies the quotation to each element of the sequence in turn." } ; { $description "Applies the quotation to each element of the sequence in order." } ;
HELP: reduce HELP: reduce
{ $values { "seq" sequence } { "identity" object } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "result" "the final result" } } { $values { "seq" sequence } { "identity" object } { "quot" "a quotation with stack effect " { $snippet "( prev elt -- next )" } } { "result" "the final result" } }
@ -447,7 +447,7 @@ HELP: accumulate
HELP: map HELP: map
{ $values { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( old -- new )" } } { "newseq" "a new sequence" } } { $values { "seq" sequence } { "quot" "a quotation with stack effect " { $snippet "( old -- new )" } } { "newseq" "a new sequence" } }
{ $description "Applies the quotation to each element yielding a new element. The new elements are collected into a sequence of the same class as the input sequence." } ; { $description "Applies the quotation to each element of the sequence in order. The new elements are collected into a sequence of the same class as the input sequence." } ;
HELP: change-nth HELP: change-nth
{ $values { "i" "a non-negative integer" } { "seq" "a mutable sequence" } { "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 )" } } }

View File

@ -4,13 +4,12 @@
IN: threads IN: threads
USING: arrays hashtables heaps kernel kernel.private math USING: arrays hashtables heaps kernel kernel.private math
namespaces sequences vectors continuations continuations.private namespaces sequences vectors continuations continuations.private
dlists assocs system combinators debugger prettyprint io init dlists assocs system combinators init boxes ;
boxes ;
SYMBOL: initial-thread SYMBOL: initial-thread
TUPLE: thread TUPLE: thread
name quot error-handler exit-handler name quot exit-handler
id id
continuation state continuation state
mailbox variables sleep-entry ; mailbox variables sleep-entry ;
@ -60,11 +59,10 @@ threads global [ H{ } assoc-like ] change-at
PRIVATE> PRIVATE>
: <thread> ( quot name error-handler -- thread ) : <thread> ( quot name -- thread )
\ thread counter <box> [ ] { \ thread counter <box> [ ] {
set-thread-quot set-thread-quot
set-thread-name set-thread-name
set-thread-error-handler
set-thread-id set-thread-id
set-thread-continuation set-thread-continuation
set-thread-exit-handler set-thread-exit-handler
@ -179,20 +177,8 @@ M: real sleep
] 1 (throw) ] 1 (throw)
] "spawn" suspend 2drop ; ] "spawn" suspend 2drop ;
: default-thread-error-handler ( error thread -- )
global [
"Error in thread " write
dup thread-id pprint
" (" write
dup thread-name pprint ")" print
"spawned to call " write
thread-quot short.
nl
print-error flush
] bind ;
: spawn ( quot name -- thread ) : spawn ( quot name -- thread )
[ default-thread-error-handler ] <thread> [ (spawn) ] keep ; <thread> [ (spawn) ] keep ;
: spawn-server ( quot name -- thread ) : spawn-server ( quot name -- thread )
>r [ [ ] [ ] while ] curry r> spawn ; >r [ [ ] [ ] while ] curry r> spawn ;
@ -202,6 +188,8 @@ M: real sleep
[ >r set-namestack set-datastack r> call ] 3curry [ >r set-namestack set-datastack r> call ] 3curry
"Thread" spawn drop ; "Thread" spawn drop ;
GENERIC: error-in-thread ( error thread -- )
<PRIVATE <PRIVATE
: init-threads ( -- ) : init-threads ( -- )
@ -209,13 +197,13 @@ M: real sleep
<dlist> 42 setenv <dlist> 42 setenv
<min-heap> 43 setenv <min-heap> 43 setenv
initial-thread global initial-thread global
[ drop f "Initial" [ die ] <thread> ] cache [ drop f "Initial" <thread> ] cache
<box> over set-thread-continuation <box> over set-thread-continuation
f over set-thread-state f over set-thread-state
dup register-thread dup register-thread
set-self ; set-self ;
[ self dup thread-error-handler call stop ] [ self error-in-thread stop ]
thread-error-hook set-global thread-error-hook set-global
PRIVATE> PRIVATE>

View File

@ -0,0 +1,10 @@
USING: io.crc32 io.files kernel math ;
IN: benchmark.crc32
: crc32-primes-list ( -- )
10 [
"extra/math/primes/list/list.factor" resource-path
file-contents crc32 drop
] times ;
MAIN: crc32-primes-list

View File

@ -0,0 +1,7 @@
USING: crypto.md5 io.files kernel ;
IN: benchmark.md5
: md5-primes-list ( -- )
"extra/math/primes/list/list.factor" resource-path file>md5 drop ;
MAIN: md5-primes-list

View File

@ -0,0 +1,14 @@
USING: io.files random math.parser io math ;
IN: benchmark.random
: random-numbers-path "random-numbers.txt" temp-file ;
: write-random-numbers ( n -- )
random-numbers-path [
[ 200 random 100 - number>string print ] times
] with-file-writer ;
: random-main ( -- )
1000000 write-random-numbers ;
MAIN: random-main

View File

@ -1,7 +1,8 @@
USING: kernel sequences sorting random ; USING: kernel sequences sorting benchmark.random math.parser
io.files ;
IN: benchmark.sort IN: benchmark.sort
: sort-benchmark : sort-benchmark
100000 [ drop 100000 random ] map natural-sort drop ; random-numbers-path file-lines [ string>number ] map natural-sort drop ;
MAIN: sort-benchmark MAIN: sort-benchmark

View File

@ -1,4 +1,5 @@
USING: io io.files math math.parser kernel prettyprint ; USING: io io.files math math.parser kernel prettyprint
benchmark.random ;
IN: benchmark.sum-file IN: benchmark.sum-file
: sum-file-loop ( n -- n' ) : sum-file-loop ( n -- n' )
@ -8,6 +9,6 @@ IN: benchmark.sum-file
[ 0 sum-file-loop ] with-file-reader . ; [ 0 sum-file-loop ] with-file-reader . ;
: sum-file-main ( -- ) : sum-file-main ( -- )
home "sum-file-in.txt" path+ sum-file ; random-numbers-path sum-file ;
MAIN: sum-file-main MAIN: sum-file-main

View File

@ -11,7 +11,7 @@ concurrency.mailboxes threads sequences ;
[ { 1 4 9 } ] [ { 1 2 3 } [ 1000 random sleep sq ] parallel-map ] unit-test [ { 1 4 9 } ] [ { 1 2 3 } [ 1000 random sleep sq ] parallel-map ] unit-test
[ { 1 2 3 } [ dup 2 mod 0 = [ "Even" throw ] when ] parallel-map ] [ { 1 2 3 } [ dup 2 mod 0 = [ "Even" throw ] when ] parallel-map ]
[ linked-error "Even" = ] must-fail-with [ delegate "Even" = ] must-fail-with
[ V{ 0 3 6 9 } ] [ V{ 0 3 6 9 } ]
[ 10 [ 3 mod zero? ] parallel-subset ] unit-test [ 10 [ 3 mod zero? ] parallel-subset ] unit-test

View File

@ -14,6 +14,10 @@ HELP: raise-flag
{ $values { "flag" flag } } { $values { "flag" flag } }
{ $description "Raises a flag, notifying any threads waiting on it. Does nothing if the flag has already been raised." } ; { $description "Raises a flag, notifying any threads waiting on it. Does nothing if the flag has already been raised." } ;
HELP: wait-for-flag
{ $values { "flag" flag } }
{ $description "Waits for a flag to be raised. If the flag has already been raised, returns immediately." } ;
HELP: lower-flag HELP: lower-flag
{ $values { "flag" flag } } { $values { "flag" flag } }
{ $description "Attempts to lower a flag. If the flag has been raised previously, returns immediately, otherwise waits for it to be raised first." } ; { $description "Attempts to lower a flag. If the flag has been raised previously, returns immediately, otherwise waits for it to be raised first." } ;
@ -26,8 +30,9 @@ $nl
"Essentially, a flag can be thought of as a counting semaphore where the count never goes above one." "Essentially, a flag can be thought of as a counting semaphore where the count never goes above one."
{ $subsection flag } { $subsection flag }
{ $subsection flag? } { $subsection flag? }
"Raising and lowering flags:" "Waiting for a flag to be raised:"
{ $subsection raise-flag } { $subsection raise-flag }
{ $subsection wait-for-flag }
{ $subsection lower-flag } ; { $subsection lower-flag } ;
ABOUT: "concurrency.flags" ABOUT: "concurrency.flags"

View File

@ -13,9 +13,14 @@ TUPLE: flag value? thread ;
[ resume ] [ drop t over set-flag-value? ] if [ resume ] [ drop t over set-flag-value? ] if
] unless drop ; ] unless drop ;
: wait-for-flag ( flag -- )
dup flag-value? [ drop ] [
[ flag-thread >box ] curry "flag" suspend drop
] if ;
: lower-flag ( flag -- ) : lower-flag ( flag -- )
dup flag-value? [ dup flag-value? [
f swap set-flag-value? f swap set-flag-value?
] [ ] [
[ flag-thread >box ] curry "flag" suspend drop wait-for-flag
] if ; ] if ;

View File

@ -174,5 +174,5 @@ threads sequences calendar ;
] ; ] ;
[ lock-timeout-test ] [ [ lock-timeout-test ] [
linked-thread thread-name "Lock timeout-er" = linked-error-thread thread-name "Lock timeout-er" =
] must-fail-with ] must-fail-with

View File

@ -65,12 +65,23 @@ TUPLE: mailbox threads data ;
: mailbox-get? ( pred mailbox -- obj ) : mailbox-get? ( pred mailbox -- obj )
f mailbox-get-timeout? ; inline f mailbox-get-timeout? ; inline
TUPLE: linked error thread ; TUPLE: linked-error thread ;
C: <linked> linked : <linked-error> ( error thread -- linked )
{ set-delegate set-linked-error-thread }
linked-error construct ;
: ?linked dup linked? [ rethrow ] when ; : ?linked dup linked-error? [ rethrow ] when ;
TUPLE: linked-thread supervisor ;
M: linked-thread error-in-thread
[ <linked-error> ] keep
linked-thread-supervisor mailbox-put ;
: <linked-thread> ( quot name mailbox -- thread' )
>r <thread> linked-thread construct-delegate r>
over set-linked-thread-supervisor ;
: spawn-linked-to ( quot name mailbox -- thread ) : spawn-linked-to ( quot name mailbox -- thread )
[ >r <linked> r> mailbox-put ] curry <thread> <linked-thread> [ (spawn) ] keep ;
[ (spawn) ] keep ;

View File

@ -29,7 +29,7 @@ IN: temporary
"crash" throw "crash" throw
] "Linked test" spawn-linked drop ] "Linked test" spawn-linked drop
receive receive
] [ linked-error "crash" = ] must-fail-with ] [ delegate "crash" = ] must-fail-with
MATCH-VARS: ?from ?to ?value ; MATCH-VARS: ?from ?to ?value ;
SYMBOL: increment SYMBOL: increment

View File

@ -199,6 +199,7 @@ ARTICLE: "tools" "Developer tools"
"Debugging tools:" "Debugging tools:"
{ $subsection "tools.annotations" } { $subsection "tools.annotations" }
{ $subsection "tools.test" } { $subsection "tools.test" }
{ $subsection "tools.threads" }
"Performance tools:" "Performance tools:"
{ $subsection "tools.memory" } { $subsection "tools.memory" }
{ $subsection "profiling" } { $subsection "profiling" }

View File

@ -122,18 +122,31 @@ M: word set-article-parent swap "help-parent" set-word-prop ;
: (:help-multi) : (:help-multi)
"This error has multiple delegates:" print "This error has multiple delegates:" print
($index) nl ; ($index) nl
"Use \\ ... help to get help about a specific delegate." print ;
: (:help-none) : (:help-none)
drop "No help for this error. " print ; drop "No help for this error. " print ;
: (:help-debugger)
nl
"Debugger commands:" print
nl
":help - documentation for this error" print
":s - data stack at exception time" print
":r - retain stack at exception time" print
":c - call stack at exception time" print
":edit - jump to source location (parse errors only)" print
":get ( var -- value ) accesses variables at time of the error" print ;
: :help ( -- ) : :help ( -- )
error get delegates [ error-help ] map [ ] subset error get delegates [ error-help ] map [ ] subset
{ {
{ [ dup empty? ] [ (:help-none) ] } { [ dup empty? ] [ (:help-none) ] }
{ [ dup length 1 = ] [ first help ] } { [ dup length 1 = ] [ first help ] }
{ [ t ] [ (:help-multi) ] } { [ t ] [ (:help-multi) ] }
} cond ; } cond (:help-debugger) ;
: remove-article ( name -- ) : remove-article ( name -- )
dup articles get key? [ dup articles get key? [

View File

@ -17,7 +17,7 @@ SYMBOL: +gl-function-pointers+
: reset-gl-function-pointers ( -- ) : reset-gl-function-pointers ( -- )
100 <hashtable> +gl-function-pointers+ set-global ; 100 <hashtable> +gl-function-pointers+ set-global ;
[ reset-gl-function-pointers ] "opengl.gl init hook" add-init-hook [ reset-gl-function-pointers ] "opengl.gl" add-init-hook
reset-gl-function-pointers reset-gl-function-pointers
reset-gl-function-number-counter reset-gl-function-number-counter

View File

@ -0,0 +1,17 @@
IN: tools.threads
USING: help.markup help.syntax threads ;
HELP: threads.
{ $description "Prints a list of running threads and their state. The ``Waiting on'' column displays one of the following:"
{ $list
"``running'' if the thread is the current thread"
"``yield'' if the thread is waiting to run"
{ "the string given to " { $link suspend } " if the thread is suspended" }
}
} ;
ARTICLE: "tools.threads" "Listing threads"
"Printing a list of running threads:"
{ $subsection threads. } ;
ABOUT: "tools.threads"

View File

@ -88,7 +88,6 @@ TUPLE: repeat-button ;
repeat-button H{ repeat-button H{
{ T{ drag } [ button-clicked ] } { T{ drag } [ button-clicked ] }
{ T{ button-down } [ button-clicked ] }
} set-gestures } set-gestures
: <repeat-button> ( label quot -- button ) : <repeat-button> ( label quot -- button )

View File

@ -1,18 +1,15 @@
! Copyright (C) 2006, 2008 Slava Pestov. ! Copyright (C) 2006, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs combinators continuations documents USING: arrays assocs combinators continuations documents
ui.tools.workspace hashtables io io.styles kernel math hashtables io io.styles kernel math
math.vectors models namespaces parser prettyprint quotations math.vectors models namespaces parser prettyprint quotations
sequences sequences.lib strings threads listener sequences sequences.lib strings threads listener
tuples ui.commands ui.gadgets ui.gadgets.editors tuples ui.commands ui.gadgets ui.gadgets.editors
ui.gadgets.presentations ui.gadgets.worlds ui.gestures ui.gadgets.presentations ui.gadgets.worlds ui.gestures
definitions boxes calendar ; definitions boxes calendar concurrency.flags ui.tools.workspace ;
IN: ui.tools.interactor IN: ui.tools.interactor
TUPLE: interactor TUPLE: interactor history output flag thread help ;
history output
thread quot
help ;
: interactor-continuation ( interactor -- continuation ) : interactor-continuation ( interactor -- continuation )
interactor-thread box-value interactor-thread box-value
@ -35,12 +32,16 @@ help ;
: init-interactor-history ( interactor -- ) : init-interactor-history ( interactor -- )
V{ } clone swap set-interactor-history ; V{ } clone swap set-interactor-history ;
: init-interactor-state ( interactor -- )
<flag> over set-interactor-flag
<box> swap set-interactor-thread ;
: <interactor> ( output -- gadget ) : <interactor> ( output -- gadget )
<source-editor> <source-editor>
interactor construct-editor interactor construct-editor
tuck set-interactor-output tuck set-interactor-output
<box> over set-interactor-thread
dup init-interactor-history dup init-interactor-history
dup init-interactor-state
dup init-caret-help ; dup init-caret-help ;
M: interactor graft* M: interactor graft*
@ -97,7 +98,10 @@ M: interactor model-changed
] unless drop ; ] unless drop ;
: interactor-yield ( interactor -- obj ) : interactor-yield ( interactor -- obj )
[ interactor-thread >box ] curry "input" suspend ; [
[ interactor-thread >box ] keep
interactor-flag raise-flag
] curry "input" suspend ;
M: interactor stream-readln M: interactor stream-readln
[ interactor-yield ] keep interactor-finish ?first ; [ interactor-yield ] keep interactor-finish ?first ;

View File

@ -6,7 +6,7 @@ kernel models namespaces parser quotations sequences ui.commands
ui.gadgets ui.gadgets.editors ui.gadgets.labelled ui.gadgets ui.gadgets.editors ui.gadgets.labelled
ui.gadgets.panes ui.gadgets.buttons ui.gadgets.scrollers ui.gadgets.panes ui.gadgets.buttons ui.gadgets.scrollers
ui.gadgets.tracks ui.gestures ui.operations vocabs words ui.gadgets.tracks ui.gestures ui.operations vocabs words
prettyprint listener debugger threads boxes ; prettyprint listener debugger threads boxes concurrency.flags ;
IN: ui.tools.listener IN: ui.tools.listener
TUPLE: listener-gadget input output stack ; TUPLE: listener-gadget input output stack ;
@ -40,9 +40,14 @@ M: listener-gadget call-tool* ( input listener -- )
M: listener-gadget tool-scroller M: listener-gadget tool-scroller
listener-gadget-output find-scroller ; listener-gadget-output find-scroller ;
: wait-for-listener ( listener -- )
#! Wait for the listener to start.
listener-gadget-input interactor-flag wait-for-flag ;
: workspace-busy? ( workspace -- ? ) : workspace-busy? ( workspace -- ? )
workspace-listener listener-gadget-input workspace-listener
interactor-busy? ; dup wait-for-listener
listener-gadget-input interactor-busy? ;
: get-listener ( -- listener ) : get-listener ( -- listener )
[ workspace-busy? not ] get-workspace* workspace-listener ; [ workspace-busy? not ] get-workspace* workspace-listener ;
@ -131,10 +136,14 @@ M: stack-display tool-scroller
listener listener
] with-stream* ; ] with-stream* ;
: start-listener-thread ( listener -- )
[ listener-thread ] curry "Listener" spawn drop ;
: restart-listener ( listener -- ) : restart-listener ( listener -- )
#! Returns when listener is ready to receive input.
dup com-end dup clear-output dup com-end dup clear-output
[ listener-thread ] curry dup start-listener-thread
"Listener" spawn drop ; wait-for-listener ;
: init-listener ( listener -- ) : init-listener ( listener -- )
f <model> swap set-listener-gadget-stack ; f <model> swap set-listener-gadget-stack ;

View File

@ -1,15 +1,14 @@
! Copyright (C) 2006, 2007 Slava Pestov. ! Copyright (C) 2006, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs debugger ui.tools.workspace USING: arrays assocs debugger ui.tools.workspace
ui.tools.operations ui.tools.browser ui.tools.inspector ui.tools.operations ui.tools.traceback ui.tools.browser
ui.tools.listener ui.tools.profiler ui.tools.inspector ui.tools.listener ui.tools.profiler
ui.tools.operations inspector io kernel math models namespaces ui.tools.operations inspector io kernel math models namespaces
prettyprint quotations sequences ui ui.commands ui.gadgets prettyprint quotations sequences ui ui.commands ui.gadgets
ui.gadgets.books ui.gadgets.buttons ui.gadgets.books ui.gadgets.buttons ui.gadgets.labelled
ui.gadgets.labelled ui.gadgets.scrollers ui.gadgets.tracks ui.gadgets.scrollers ui.gadgets.tracks ui.gadgets.worlds
ui.gadgets.worlds ui.gadgets.presentations ui.gestures words ui.gadgets.presentations ui.gestures words vocabs.loader
vocabs.loader tools.test ui.gadgets.buttons tools.test ui.gadgets.buttons ui.gadgets.status-bar mirrors ;
ui.gadgets.status-bar mirrors ;
IN: ui.tools IN: ui.tools
: <workspace-tabs> ( -- tabs ) : <workspace-tabs> ( -- tabs )
@ -85,3 +84,11 @@ workspace "workflow" f {
[ [
<workspace> "Factor workspace" open-status-window <workspace> "Factor workspace" open-status-window
] workspace-window-hook set-global ] workspace-window-hook set-global
: inspect-continuation ( traceback -- )
control-value [ inspect ] curry call-listener ;
traceback-gadget "toolbar" f {
{ T{ key-down f f "v" } variables }
{ T{ key-down f f "n" } inspect-continuation }
} define-command-map

View File

@ -1,8 +1,10 @@
! Copyright (C) 2006, 2007 Slava Pestov. ! Copyright (C) 2006, 2008 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: continuations kernel models namespaces prettyprint ui USING: continuations kernel models namespaces prettyprint ui
ui.commands ui.gadgets ui.gadgets.labelled assocs ui.commands ui.gadgets ui.gadgets.labelled assocs
ui.gadgets.tracks ui.gestures sequences hashtables inspector ; ui.gadgets.tracks ui.gadgets.buttons ui.gadgets.panes
ui.gadgets.status-bar ui.gadgets.scrollers
ui.gestures sequences hashtables inspector ;
IN: ui.tools.traceback IN: ui.tools.traceback
: <callstack-display> ( model -- gadget ) : <callstack-display> ( model -- gadget )
@ -17,10 +19,6 @@ IN: ui.tools.traceback
[ [ continuation-retain stack. ] when* ] [ [ continuation-retain stack. ] when* ]
t "Retain stack" <labelled-pane> ; t "Retain stack" <labelled-pane> ;
: <namestack-display> ( model -- gadget )
[ [ continuation-name namestack. ] when* ]
f "Dynamic variables" <labelled-pane> ;
TUPLE: traceback-gadget ; TUPLE: traceback-gadget ;
M: traceback-gadget pref-dim* drop { 550 600 } ; M: traceback-gadget pref-dim* drop { 550 600 } ;
@ -31,11 +29,28 @@ M: traceback-gadget pref-dim* drop { 550 600 } ;
[ [
g gadget-model <datastack-display> 1/2 track, g gadget-model <datastack-display> 1/2 track,
g gadget-model <retainstack-display> 1/2 track, g gadget-model <retainstack-display> 1/2 track,
] { 1 0 } make-track 1/5 track, ] { 1 0 } make-track 1/3 track,
g gadget-model <callstack-display> 2/5 track, g gadget-model <callstack-display> 2/3 track,
g gadget-model <namestack-display> 2/5 track, toolbar,
] with-gadget ] with-gadget
] keep ; ] keep ;
: <namestack-display> ( model -- gadget )
[ [ continuation-name namestack. ] when* ]
<pane-control> ;
TUPLE: variables-gadget ;
: <variables-gadget> ( model -- gadget )
<namestack-display> <scroller>
variables-gadget construct-empty
[ set-gadget-delegate ] keep ;
M: variables-gadget pref-dim* drop { 400 400 } ;
: variables ( traceback -- )
gadget-model <variables-gadget>
"Dynamic variables" open-status-window ;
: traceback-window ( continuation -- ) : traceback-window ( continuation -- )
<model> <traceback-gadget> "Traceback" open-window ; <model> <traceback-gadget> "Traceback" open-window ;

View File

@ -7,5 +7,4 @@ ARTICLE: "ui-walker" "UI walker"
$nl $nl
"The walker can travel backwards through time, and restore stacks. This does not undo side effects and therefore can only be used reliably on referentially transparent code." "The walker can travel backwards through time, and restore stacks. This does not undo side effects and therefore can only be used reliably on referentially transparent code."
{ $command-map walker-gadget "toolbar" } { $command-map walker-gadget "toolbar" }
{ $command-map walker-gadget "other" }
"Walkers are instances of " { $link walker-gadget } "." ; "Walkers are instances of " { $link walker-gadget } "." ;

View File

@ -7,7 +7,7 @@ ui.tools.workspace ui.gestures ui.gadgets.labels ui threads
namespaces tools.walker assocs ; namespaces tools.walker assocs ;
IN: ui.tools.walker IN: ui.tools.walker
TUPLE: walker-gadget status continuation thread ; TUPLE: walker-gadget status continuation thread traceback ;
: walker-command ( walker msg -- ) : walker-command ( walker msg -- )
over walker-gadget-thread thread-registered? over walker-gadget-thread thread-registered?
@ -26,13 +26,12 @@ TUPLE: walker-gadget status continuation thread ;
: com-abandon ( walker -- ) abandon walker-command ; : com-abandon ( walker -- ) abandon walker-command ;
: com-inspect ( walker -- )
walker-continuation model-value
[ inspect ] curry call-listener ;
M: walker-gadget ungraft* M: walker-gadget ungraft*
dup delegate ungraft* detach walker-command ; dup delegate ungraft* detach walker-command ;
M: walker-gadget focusable-child*
walker-gadget-traceback ;
: walker-state-string ( status thread -- string ) : walker-state-string ( status thread -- string )
[ [
"Thread: " % "Thread: " %
@ -52,10 +51,10 @@ M: walker-gadget ungraft*
[ walker-state-string ] curry <filter> <label-control> ; [ walker-state-string ] curry <filter> <label-control> ;
: <walker-gadget> ( status continuation thread -- gadget ) : <walker-gadget> ( status continuation thread -- gadget )
walker-gadget construct-boa [ over <traceback-gadget> walker-gadget construct-boa [
toolbar, toolbar,
g walker-gadget-status self <thread-status> f track, g walker-gadget-status self <thread-status> f track,
g walker-gadget-continuation <traceback-gadget> 1 track, g walker-gadget-traceback 1 track,
] { 0 1 } build-track ; ] { 0 1 } build-track ;
: walker-help "ui-walker" help-window ; : walker-help "ui-walker" help-window ;
@ -69,12 +68,8 @@ walker-gadget "toolbar" f {
{ T{ key-down f f "b" } com-back } { T{ key-down f f "b" } com-back }
{ T{ key-down f f "c" } com-continue } { T{ key-down f f "c" } com-continue }
{ T{ key-down f f "a" } com-abandon } { T{ key-down f f "a" } com-abandon }
{ T{ key-down f f "F1" } walker-help }
} define-command-map
walker-gadget "other" f {
{ T{ key-down f f "n" } com-inspect }
{ T{ key-down f f "d" } close-window } { T{ key-down f f "d" } close-window }
{ T{ key-down f f "F1" } walker-help }
} define-command-map } define-command-map
: walker-window ( -- ) : walker-window ( -- )