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-05-18 16:26:22 -04:00
|
|
|
USING: interpreter kernel lists prettyprint sequences
|
|
|
|
stdio 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-04-01 12:42:14 -05:00
|
|
|
over >r >r dup word-def r> call r> swap (define-compound) ;
|
|
|
|
inline
|
2005-03-10 17:57:22 -05:00
|
|
|
|
2005-04-14 19:37:13 -04:00
|
|
|
: (watch) ( word def -- def )
|
2005-05-18 16:26:22 -04:00
|
|
|
>r "==> " swap word-name append \ print \ .s r>
|
2005-04-14 19:37:13 -04:00
|
|
|
cons cons cons ;
|
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 ;
|