factor/library/tools/walker.factor

74 lines
1.8 KiB
Factor
Raw Normal View History

2005-03-07 22:11:36 -05:00
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: interpreter
USING: errors kernel listener lists math namespaces prettyprint
stdio strings vectors words ;
: &s
#! Print stepper data stack.
meta-d get {.} ;
: &r
#! Print stepper call stack, as well as the currently
#! executing quotation.
meta-cf get . meta-executing get . meta-r get {.} ;
2005-03-07 22:11:36 -05:00
: &n
#! Print stepper name stack.
meta-n get [.] ;
: &c
#! Print stepper catch stack.
meta-c get [.] ;
: &get ( var -- value )
2005-03-10 17:57:22 -05:00
#! Get stepper variable value.
2005-03-07 22:11:36 -05:00
meta-n get (get) ;
: report ( -- ) meta-cf get . ;
2005-03-07 22:11:36 -05:00
: step
2005-03-10 17:57:22 -05:00
#! Step over current word.
next do-1 report ;
2005-03-07 22:11:36 -05:00
: into
#! Step into current word.
next do report ;
: continue
#! Continue executing the single-stepped continuation in the
#! primary interpreter.
meta-d get set-datastack
meta-c get set-catchstack
meta-cf get
meta-r get
meta-n get set-namestack
set-callstack call ;
2005-03-07 22:11:36 -05:00
: walk-banner ( -- )
[ &s &r &n &c ] [ prettyprint-word " " write ] each
"show stepper stacks." print
\ &get prettyprint-word
" ( var -- value ) inspects the stepper namestack." print
\ step prettyprint-word " -- single step over" print
\ into prettyprint-word " -- single step into" print
\ continue prettyprint-word " -- continue execution" print
\ bye prettyprint-word " -- exit single-stepper" print
2005-03-07 22:11:36 -05:00
report ;
2005-03-10 17:57:22 -05:00
: walk-listener walk-banner "walk" listener-prompt set listener ;
: init-walk ( quot callstack namestack -- )
init-interpreter
meta-n set
meta-r set
meta-cf set
datastack meta-d set ;
2005-03-07 22:11:36 -05:00
: walk ( quot -- )
#! Single-step through execution of a quotation.
callstack namestack [
init-walk
2005-03-10 17:57:22 -05:00
walk-listener
] with-scope ;