1 ! Copyright (C) 2005, 2008 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors kernel words parser io inspector quotations
4 sequences prettyprint continuations effects definitions
5 compiler.units namespaces assocs tools.walker generic ;
8 GENERIC: reset ( word -- )
12 [ subwords [ reset ] each ] bi ;
15 dup "unannotated-def" word-prop [
17 dup dup "unannotated-def" word-prop define
18 ] with-compilation-unit
19 f "unannotated-def" set-word-prop
22 : annotate ( word quot -- )
23 over "unannotated-def" word-prop [
24 "Cannot annotate a word twice" throw
27 over dup def>> "unannotated-def" set-word-prop
28 >r dup def>> r> call define
29 ] with-compilation-unit ; inline
31 : word-inputs ( word -- seq )
33 >r datastack r> effect-in length tail*
39 "/-- Entering: " write dup .
44 "/-- Leaving: " write dup .
46 >r datastack r> effect-out length tail* stack.
49 ] if* "\\--" print flush ;
51 : (watch) ( word def -- def )
52 over [ entering ] curry
57 dup [ (watch) ] annotate ;
59 : (watch-vars) ( quot word vars -- newquot )
61 "--- Entering: " write swap .
62 "--- Variable values:" print
63 [ dup get ] H{ } map>assoc describe
66 : watch-vars ( word vars -- )
67 dupd [ (watch-vars) ] 2curry annotate ;
69 GENERIC# annotate-methods 1 ( word quot -- )
71 M: generic annotate-methods
72 >r "methods" word-prop values r> [ annotate ] curry each ;
74 M: word annotate-methods
77 : breakpoint ( word -- )
78 [ add-breakpoint ] annotate-methods ;
80 : breakpoint-if ( word quot -- )
81 [ [ [ break ] when ] rot 3append ] curry annotate-methods ;