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
|
2005-09-25 21:54:25 -04:00
|
|
|
USING: errors inspector kernel listener lists math namespaces
|
|
|
|
prettyprint sequences io strings vectors words ;
|
2005-03-07 22:11:36 -05:00
|
|
|
|
2005-03-26 20:12:14 -05:00
|
|
|
! The single-stepper simulates Factor in Factor to allow
|
|
|
|
! single-stepping through the execution of a quotation. It can
|
|
|
|
! transfer the continuation to and from the primary interpreter.
|
|
|
|
|
2005-03-07 22:11:36 -05:00
|
|
|
: &s
|
|
|
|
#! Print stepper data stack.
|
2005-08-22 20:54:01 -04:00
|
|
|
meta-d get stack. ;
|
2005-03-07 22:11:36 -05:00
|
|
|
|
2005-08-26 18:18:07 -04:00
|
|
|
: meta-r*
|
|
|
|
#! Stepper call stack, as well as the currently
|
|
|
|
#! executing quotation.
|
|
|
|
[ meta-r get % meta-executing get , meta-cf get , ] { } make ;
|
|
|
|
|
2005-03-07 22:11:36 -05:00
|
|
|
: &r
|
2005-03-20 19:05:57 -05:00
|
|
|
#! Print stepper call stack, as well as the currently
|
|
|
|
#! executing quotation.
|
2005-08-26 18:18:07 -04:00
|
|
|
meta-r* stack. ;
|
2005-03-07 22:11:36 -05:00
|
|
|
|
|
|
|
: &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) ;
|
|
|
|
|
2005-03-20 19:05:57 -05:00
|
|
|
: 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.
|
2005-03-20 19:05:57 -05:00
|
|
|
next do-1 report ;
|
2005-03-07 22:11:36 -05:00
|
|
|
|
|
|
|
: into
|
|
|
|
#! Step into current word.
|
2005-03-20 19:05:57 -05:00
|
|
|
next do report ;
|
|
|
|
|
2005-09-24 23:21:09 -04:00
|
|
|
: end-walk
|
2005-03-20 19:05:57 -05:00
|
|
|
#! Continue executing the single-stepped continuation in the
|
|
|
|
#! primary interpreter.
|
2005-09-24 23:21:09 -04:00
|
|
|
\ call push-r meta-cf get push-r meta-interp continue ;
|
2005-03-07 22:11:36 -05:00
|
|
|
|
|
|
|
: walk-banner ( -- )
|
2005-08-23 22:27:05 -04:00
|
|
|
"&s &r show stepper stacks" print
|
|
|
|
"&get ( var -- value ) get stepper variable value" print
|
2005-08-21 01:17:37 -04:00
|
|
|
"step -- single step over" print
|
|
|
|
"into -- single step into" print
|
2005-09-24 23:21:09 -04:00
|
|
|
"bye -- continue execution" print
|
2005-03-07 22:11:36 -05:00
|
|
|
report ;
|
|
|
|
|
2005-06-27 03:54:43 -04:00
|
|
|
: walk-listener walk-banner "walk " listener-prompt set listener ;
|
2005-03-10 17:57:22 -05:00
|
|
|
|
2005-03-20 19:05:57 -05:00
|
|
|
: init-walk ( quot callstack namestack -- )
|
2005-08-26 18:18:07 -04:00
|
|
|
[ meta-d get "Stepper data stack:" ] datastack-hook set
|
|
|
|
[ meta-r* "Stepper return stack:" ] callstack-hook set
|
2005-03-20 19:05:57 -05:00
|
|
|
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.
|
2005-03-20 19:05:57 -05:00
|
|
|
callstack namestack [
|
|
|
|
init-walk
|
2005-03-10 17:57:22 -05:00
|
|
|
walk-listener
|
2005-09-24 23:21:09 -04:00
|
|
|
end-walk
|
2005-03-20 19:05:57 -05:00
|
|
|
] with-scope ;
|