1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel words parser io summary quotations
4 sequences prettyprint continuations effects definitions
5 compiler.units namespaces assocs tools.walker generic
9 GENERIC: reset ( word -- )
13 [ subwords [ reset ] each ] bi ;
16 dup "unannotated-def" word-prop [
18 dup dup "unannotated-def" word-prop define
19 ] with-compilation-unit
20 f "unannotated-def" set-word-prop
23 : annotate ( word quot -- )
24 over "unannotated-def" word-prop [
25 "Cannot annotate a word twice" throw
28 over dup def>> "unannotated-def" set-word-prop
29 >r dup def>> r> call define
30 ] with-compilation-unit ; inline
32 : word-inputs ( word -- seq )
34 >r datastack r> in>> length tail*
40 "/-- Entering: " write dup .
45 "/-- Leaving: " write dup .
47 >r datastack r> out>> length tail* stack.
50 ] if* "\\--" print flush ;
52 : (watch) ( word def -- def ) over '[ _ entering @ _ leaving ] ;
55 dup [ (watch) ] annotate ;
57 : (watch-vars) ( quot word vars -- newquot )
60 "--- Entering: " write _ .
61 "--- Variable values:" print _ [ dup get ] H{ } map>assoc describe
65 : watch-vars ( word vars -- )
66 dupd [ (watch-vars) ] 2curry annotate ;
68 GENERIC# annotate-methods 1 ( word quot -- )
70 M: generic annotate-methods
71 >r "methods" word-prop values r> [ annotate ] curry each ;
73 M: word annotate-methods
76 : breakpoint ( word -- )
77 [ add-breakpoint ] annotate-methods ;
79 : breakpoint-if ( word quot -- )
80 [ [ [ break ] when ] rot 3append ] curry annotate-methods ;