UI debugger, first cut

slava 2006-11-30 07:15:42 +00:00
parent 18e0be59e0
commit 3ac7498862
14 changed files with 131 additions and 64 deletions

View File

@ -1,22 +1,24 @@
+ 0.87: + 0.87:
- parse errors should be shown in a popup - parse errors should be shown in a popup
- growable data heap - menu Command: quots look dumb
- no need for modify-listener-operation!
- command buttons: indicate shortcuts
- http://paste.lisp.org/display/30426
- update ui docs
+ 0.88:
- growable data heap
- variable width word wrap - variable width word wrap
- graphical crossref tool - graphical crossref tool
- http://paste.lisp.org/display/30426
- compiled call traces: - compiled call traces:
- should be independent of whenever the runtime was built with - should be independent of whenever the runtime was built with
-fomit-frame-pointer or not -fomit-frame-pointer or not
- doesn't show #labels - doesn't show #labels
- we don't know if signal handlers run with the same stack or not - we don't know if signal handlers run with the same stack or not
+ 0.88:
- use crc32 instead of modification date in reload-modules - use crc32 instead of modification date in reload-modules
- models: don't do redundant work - models: don't do redundant work
- menu Command: quots look dumb
- top level window positioning on ms windows - top level window positioning on ms windows
- crashes: - crashes:
- callback scheduling issue - callback scheduling issue
@ -31,6 +33,7 @@
- available-modules - available-modules
- :trace - :trace
- string-lines - string-lines
- md5, crc32
- auto-update browser and help when sources reload - auto-update browser and help when sources reload
- mac intel: struct returns from objc methods - mac intel: struct returns from objc methods
- new windows don't always have focus, eg focus follows mouse - new windows don't always have focus, eg focus follows mouse

View File

@ -30,16 +30,21 @@ SYMBOL: restarts
[ >c drop call c> drop ] [ >c drop call c> drop ]
[ rot drop swap call ] ifcc ; inline [ rot drop swap call ] ifcc ; inline
TUPLE: condition restarts cc ; TUPLE: condition restarts continuation ;
C: condition ( error restarts cc -- condition ) C: condition ( error restarts cc -- condition )
[ set-condition-cc ] keep [ set-condition-continuation ] keep
[ set-condition-restarts ] keep [ set-condition-restarts ] keep
[ set-delegate ] keep ; [ set-delegate ] keep ;
: condition ( error restarts -- restart ) : condition ( error restarts -- restart )
[ <condition> throw ] callcc1 2nip ; [ <condition> throw ] callcc1 2nip ;
TUPLE: restart name obj continuation ;
: restart ( restart -- )
dup restart-obj swap restart-continuation continue-with ;
GENERIC: compute-restarts ( error -- seq ) GENERIC: compute-restarts ( error -- seq )
M: object compute-restarts drop { } ; M: object compute-restarts drop { } ;
@ -48,8 +53,9 @@ M: tuple compute-restarts delegate compute-restarts ;
M: condition compute-restarts M: condition compute-restarts
[ delegate compute-restarts ] keep [ delegate compute-restarts ] keep
[ condition-cc ] keep [ condition-continuation ] keep
condition-restarts [ swap add ] map-with append ; condition-restarts [ first2 rot <restart> ] map-with
append ;
PREDICATE: array kernel-error ( obj -- ? ) PREDICATE: array kernel-error ( obj -- ? )
dup first \ kernel-error eq? swap second 0 18 between? and ; dup first \ kernel-error eq? swap second 0 18 between? and ;

View File

@ -46,12 +46,7 @@ SYMBOL: stdio
: write-outliner ( str obj content -- ) : write-outliner ( str obj content -- )
outline associate [ write-object ] with-nesting ; outline associate [ write-object ] with-nesting ;
: (print-input/quot)
associate [ H{ { font-style bold } } format ] with-nesting
terpri ;
: print-input ( string input -- ) : print-input ( string input -- )
<input> presented (print-input/quot) ; <input> presented associate
[ H{ { font-style bold } } format ] with-nesting
: print-quot ( string quot -- ) terpri ;
quotation (print-input/quot) ;

View File

@ -78,12 +78,10 @@ M: string error. print ;
error-continuation get continuation-name hash-stack ; error-continuation get continuation-name hash-stack ;
: :res ( n -- ) : :res ( n -- )
restarts get-global nth restarts get-global nth f restarts set-global restart ;
f restarts set-global
first3 continue-with ;
: :edit ( -- ) : :edit ( -- )
error get delegates [ parse-error-file ] find nip [ error get delegates [ parse-error? ] find-last nip [
dup parse-error-file ?resource-path dup parse-error-file ?resource-path
swap parse-error-line edit-location swap parse-error-line edit-location
] when* ; ] when* ;
@ -104,8 +102,7 @@ M: string error. print ;
} cond ; } cond ;
: restart. ( restart n -- ) : restart. ( restart n -- )
[ [ # " :res " % first % ] "" make ] keep [ # " :res " % restart-name % ] "" make print ;
[ :res ] curry print-quot ;
: restarts. ( -- ) : restarts. ( -- )
restarts get dup empty? [ restarts get dup empty? [
@ -121,13 +118,13 @@ M: string error. print ;
terpri terpri
"Debugger commands:" print "Debugger commands:" print
terpri terpri
":help - documentation for this error" [ :help ] print-quot ":help - documentation for this error" print
":s - data stack at exception time" [ :s ] print-quot ":s - data stack at exception time" print
":r - retain stack at exception time" [ :r ] print-quot ":r - retain stack at exception time" print
":c - call stack at exception time" [ :c ] print-quot ":c - call stack at exception time" print
error get [ parse-error? ] is? [ error get [ parse-error? ] is? [
":edit - jump to source location" [ :edit ] print-quot ":edit - jump to source location" print
] when ] when
":get ( var -- value ) accesses variables at time of the error" print ":get ( var -- value ) accesses variables at time of the error" print
@ -142,4 +139,7 @@ M: string error. print ;
"Error in print-error!" print "Error in print-error!" print
] recover drop ; ] recover drop ;
: try ( quot -- ) [ print-error ] recover ; SYMBOL: error-hook
: try ( quot -- )
[ error-hook get [ call ] [ print-error ] ?if ] recover ;

View File

@ -25,8 +25,8 @@ SYMBOL: inspector-stack
: inspector-help ( -- ) : inspector-help ( -- )
"Object inspector." print "Object inspector." print
"up -- return to previous object" [ up ] print-quot "up -- return to previous object" print
"me ( -- obj ) push this object" [ me ] print-quot "me ( -- obj ) push this object" print
"go ( n -- ) inspect nth slot" print "go ( n -- ) inspect nth slot" print
terpri ; terpri ;

View File

@ -81,9 +81,6 @@ presentation H{
[ presentation-object summary ] [ "" ] if* [ presentation-object summary ] [ "" ] if*
] <filter> <label-control> dup reverse-video-theme ; ] <filter> <label-control> dup reverse-video-theme ;
: <listener-button> ( gadget quot -- button )
[ call-listener drop ] curry <roll-button> ;
! Character styles ! Character styles
: apply-style ( style gadget key quot -- style gadget ) : apply-style ( style gadget key quot -- style gadget )
@ -106,16 +103,12 @@ presentation H{
: apply-presentation-style ( style gadget -- style gadget ) : apply-presentation-style ( style gadget -- style gadget )
presented [ <presentation> ] apply-style ; presented [ <presentation> ] apply-style ;
: apply-quotation-style ( style gadget -- style gadget )
quotation [ <listener-button> ] apply-style ;
: <styled-label> ( style text -- gadget ) : <styled-label> ( style text -- gadget )
<label> <label>
apply-foreground-style apply-foreground-style
apply-background-style apply-background-style
apply-font-style apply-font-style
apply-presentation-style apply-presentation-style
apply-quotation-style
nip ; nip ;
! Paragraph styles ! Paragraph styles
@ -148,7 +141,6 @@ presentation H{
apply-border-color-style apply-border-color-style
apply-page-color-style apply-page-color-style
apply-presentation-style apply-presentation-style
apply-quotation-style
apply-outliner-style apply-outliner-style
nip ; nip ;

View File

@ -40,6 +40,7 @@ PROVIDE: core/ui
"text/interactor.factor" "text/interactor.factor"
"ui.factor" "ui.factor"
"tools/tools.factor" "tools/tools.factor"
"tools/debugger.factor"
"tools/messages.factor" "tools/messages.factor"
"tools/listener.factor" "tools/listener.factor"
"tools/walker.factor" "tools/walker.factor"

View File

@ -9,7 +9,7 @@ math listener models errors ;
TUPLE: interactor TUPLE: interactor
history output history output
continuation quot busy? continuation quot busy?
use in ; use in error-hook ;
C: interactor ( output -- gadget ) C: interactor ( output -- gadget )
[ set-interactor-output ] keep [ set-interactor-output ] keep
@ -66,19 +66,21 @@ M: interactor stream-read
: save-in/use ( interactor -- ) : save-in/use ( interactor -- )
use get over set-interactor-use use get over set-interactor-use
in get swap set-interactor-in ; in get over set-interactor-in
error-hook get swap set-interactor-error-hook ;
: restore-in/use ( interactor -- ) : restore-in/use ( interactor -- )
dup interactor-use use set dup interactor-use use set
interactor-in in set ; dup interactor-in in set
interactor-error-hook error-hook set ;
: go-to-error ( interactor error -- ) : go-to-error ( interactor error -- )
dup parse-error-line 1- swap parse-error-col 2array dup parse-error-line 1- swap parse-error-col 2array
over editor-caret set-model mark>caret ; over editor-caret set-model mark>caret ;
: handle-parse-error ( interactor error -- ) : handle-parse-error ( interactor error -- )
dup parse-error? [ 2dup go-to-error delegate ] when dup parse-error? [ dupd go-to-error ] when
swap interactor-output [ print-error ] with-stream* ; interactor-error-hook call ;
: try-parse ( str interactor -- quot/error/f ) : try-parse ( str interactor -- quot/error/f )
[ [

View File

@ -0,0 +1,46 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: gadgets-debugger
USING: errors sequences gadgets gadgets-buttons gadgets-listener
gadgets-panes gadgets-lists gadgets-scrolling gadgets-theme
kernel models arrays namespaces ;
: <debugger-button>
[ call-listener drop ] curry <bevel-button> ;
: <restart-list> ( seq -- gadget )
[ drop ] [ restart-name ] rot <model> <list> ;
TUPLE: debugger restarts ;
: <debugger-display> ( error restart-list -- gadget )
>r [ error. ] make-pane r>
2array make-pile
1 over set-pack-fill ;
C: debugger ( error restarts -- gadget )
{
{
[ gadget get { debugger } <toolbar> ]
f f @top
}
{
[ <restart-list> ]
set-debugger-restarts
[ <debugger-display> <scroller> ]
@center
}
} make-frame* dup popup-theme ;
M: debugger focusable-child*
debugger-restarts ;
debugger "toolbar" {
{ "Data stack" T{ key-down f f "s" } [ :s ] }
{ "Retain stack" T{ key-down f f "r" } [ :r ] }
{ "Call stack" T{ key-down f f "c" } [ :c ] }
{ "Help" T{ key-down f f "h" } [ :help ] }
{ "Edit" T{ key-down f f "e" } [ :edit ] }
} [
first3 [ call-listener drop ] curry 3array
] map define-commands

View File

@ -6,7 +6,7 @@ gadgets-panes gadgets-scrolling gadgets-text
gadgets-theme gadgets-tracks gadgets-workspace gadgets-theme gadgets-tracks gadgets-workspace
generic hashtables tools io kernel listener math models generic hashtables tools io kernel listener math models
namespaces parser prettyprint sequences shells strings styles namespaces parser prettyprint sequences shells strings styles
threads words definitions help ; threads words definitions help errors ;
TUPLE: listener-gadget input output stack use ; TUPLE: listener-gadget input output stack use ;
@ -14,6 +14,9 @@ TUPLE: listener-gadget input output stack use ;
use get over set-listener-gadget-use use get over set-listener-gadget-use
>r datastack r> listener-gadget-stack set-model ; >r datastack r> listener-gadget-stack set-model ;
: ui-error-hook ( listener -- )
find-workspace dup workspace-error-hook call ;
: listener-stream ( listener -- stream ) : listener-stream ( listener -- stream )
dup listener-gadget-input dup listener-gadget-input
swap listener-gadget-output <pane-stream> swap listener-gadget-output <pane-stream>
@ -37,7 +40,9 @@ TUPLE: listener-gadget input output stack use ;
: listener-thread ( listener -- ) : listener-thread ( listener -- )
dup listener-stream [ dup listener-stream [
dup
[ ui-listener-hook ] curry listener-hook set [ ui-listener-hook ] curry listener-hook set
[ ui-error-hook ] curry error-hook set
find-messages batch-errors set find-messages batch-errors set
welcome. welcome.
listener listener

View File

@ -5,7 +5,7 @@ USING: definitions gadgets gadgets-browser gadgets-dataflow
gadgets-help gadgets-listener gadgets-search gadgets-text gadgets-help gadgets-listener gadgets-search gadgets-text
gadgets-workspace hashtables help inference kernel namespaces gadgets-workspace hashtables help inference kernel namespaces
parser prettyprint scratchpad sequences strings styles syntax parser prettyprint scratchpad sequences strings styles syntax
test tools words generic models io modules ; test tools words generic models io modules errors ;
V{ } clone operations set-global V{ } clone operations set-global
@ -51,6 +51,15 @@ M: operation invoke-command ( target operation -- )
{ +quot+ [ listener-gadget call-tool ] } { +quot+ [ listener-gadget call-tool ] }
} define-operation } define-operation
! Restart
[ restart? ] H{
{ +primary+ t }
{ +secondary+ t }
{ +name+ "Restart" }
{ +quot+ [ restart ] }
{ +listener+ t }
} define-operation
! Pathnames ! Pathnames
[ pathname? ] H{ [ pathname? ] H{
{ +primary+ t } { +primary+ t }

View File

@ -109,11 +109,6 @@ M: live-search focusable-child* live-search-field ;
[ input-string ] [ input-string ]
<live-search> ; <live-search> ;
: show-titled-popup ( workspace gadget title -- )
[ find-workspace hide-popup ] <closable-gadget>
[ popup-theme ] keep
swap show-popup ;
: workspace-listener ( workspace -- listener ) : workspace-listener ( workspace -- listener )
listener-gadget swap find-tool tool-gadget nip ; listener-gadget swap find-tool tool-gadget nip ;

View File

@ -20,7 +20,7 @@ GENERIC: tool-help ( tool -- topic )
M: gadget tool-help drop f ; M: gadget tool-help drop f ;
TUPLE: workspace book popup ; TUPLE: workspace book popup error-hook ;
: find-workspace [ workspace? ] find-parent ; : find-workspace [ workspace? ] find-parent ;

View File

@ -4,9 +4,10 @@ IN: gadgets-workspace
USING: help arrays compiler gadgets gadgets-books USING: help arrays compiler gadgets gadgets-books
gadgets-browser gadgets-buttons gadgets-dataflow gadgets-help gadgets-browser gadgets-buttons gadgets-dataflow gadgets-help
gadgets-listener gadgets-presentations gadgets-walker gadgets-listener gadgets-presentations gadgets-walker
gadgets-workspace generic kernel math modules scratchpad gadgets-debugger generic kernel math modules scratchpad
sequences syntax words io namespaces hashtables sequences syntax words io namespaces hashtables
gadgets-scrolling gadgets-panes gadgets-messages ; gadgets-scrolling gadgets-panes gadgets-messages gadgets-theme
errors ;
C: tool ( gadget -- tool ) C: tool ( gadget -- tool )
{ {
@ -61,13 +62,6 @@ tool "toolbar" {
: <workspace-book> ( -- gadget ) : <workspace-book> ( -- gadget )
workspace-tabs 1 <column> [ execute <tool> ] map <book> ; workspace-tabs 1 <column> [ execute <tool> ] map <book> ;
C: workspace ( -- workspace )
{
{ [ <workspace-book> ] set-workspace-book f @center }
{ [ gadget get <workspace-tabs> ] f f @top }
{ [ gadget get { workspace } <toolbar> ] f f @bottom }
} make-frame* ;
M: workspace pref-dim* delegate pref-dim* { 550 650 } vmax ; M: workspace pref-dim* delegate pref-dim* { 550 650 } vmax ;
: init-status ( world -- ) : init-status ( world -- )
@ -79,9 +73,16 @@ M: workspace pref-dim* delegate pref-dim* { 550 650 } vmax ;
request-focus ; request-focus ;
: show-popup ( gadget workspace -- ) : show-popup ( gadget workspace -- )
dup hide-popup 2dup set-workspace-popup dupd add-gadget dup hide-popup
2dup set-workspace-popup
dupd add-gadget
dup popup-theme
request-focus ; request-focus ;
: show-titled-popup ( workspace gadget title -- )
[ find-workspace hide-popup ] <closable-gadget>
swap show-popup ;
: popup-dim ( workspace -- dim ) : popup-dim ( workspace -- dim )
rect-dim first2 4 /i 2array ; rect-dim first2 4 /i 2array ;
@ -94,6 +95,18 @@ M: workspace pref-dim* delegate pref-dim* { 550 650 } vmax ;
over popup-dim over set-gadget-dim over popup-dim over set-gadget-dim
swap popup-loc swap set-rect-loc ; swap popup-loc swap set-rect-loc ;
: debugger-popup ( workspace -- )
error get restarts get <debugger>
"Error" show-titled-popup ;
C: workspace ( -- workspace )
[ debugger-popup ] over set-workspace-error-hook
{
{ [ <workspace-book> ] set-workspace-book f @center }
{ [ gadget get <workspace-tabs> ] f f @top }
{ [ gadget get { workspace } <toolbar> ] f f @bottom }
} make-frame* ;
M: workspace layout* M: workspace layout*
dup delegate layout* dup delegate layout*
dup workspace-book swap workspace-popup dup dup workspace-book swap workspace-popup dup