2005-03-10 17:57:22 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
IN: words
|
|
|
|
|
|
|
|
! The annotation words let you flag a word for either tracing
|
|
|
|
! or single-stepping. Note that currently, words referring to
|
|
|
|
! annotated words cannot be compiled; and annotating a word has
|
|
|
|
! no effect of compiled calls to that word.
|
2005-08-08 15:21:14 -04:00
|
|
|
USING: interpreter io kernel lists namespaces prettyprint
|
|
|
|
sequences strings test ;
|
2005-03-10 17:57:22 -05:00
|
|
|
|
2005-04-14 19:37:13 -04:00
|
|
|
: annotate ( word quot -- | quot: word def -- def )
|
2005-08-23 15:50:32 -04:00
|
|
|
over >r >r dup word-def r> call r> swap define-compound ;
|
2005-04-01 12:42:14 -05:00
|
|
|
inline
|
2005-03-10 17:57:22 -05:00
|
|
|
|
2005-04-14 19:37:13 -04:00
|
|
|
: (watch) ( word def -- def )
|
2005-08-08 15:21:14 -04:00
|
|
|
[
|
|
|
|
"===> Entering: " pick word-name append , \ print ,
|
|
|
|
\ .s ,
|
|
|
|
%
|
|
|
|
"===> Leaving: " swap word-name append , \ print ,
|
|
|
|
\ .s ,
|
|
|
|
] make-list ;
|
2005-03-10 17:57:22 -05:00
|
|
|
|
|
|
|
: watch ( word -- )
|
|
|
|
#! Cause a message to be printed out when the word is
|
2005-04-14 19:37:13 -04:00
|
|
|
#! executed.
|
2005-03-10 17:57:22 -05:00
|
|
|
[ (watch) ] annotate ;
|
|
|
|
|
|
|
|
: break ( word -- )
|
|
|
|
#! Cause the word to start the code walker when executed.
|
2005-03-28 23:45:13 -05:00
|
|
|
[ nip [ walk ] cons ] annotate ;
|
|
|
|
|
|
|
|
: timer ( word -- )
|
|
|
|
#! Print the time taken to execute the word when it's called.
|
|
|
|
[ nip [ time ] cons ] annotate ;
|