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> effect-in length tail*
40 "/-- Entering: " write dup .
45 "/-- Leaving: " write dup .
47 >r datastack r> effect-out length tail* stack.
50 ] if* "\\--" print flush ;
52 : (watch) ( word def -- def )
53 over [ entering ] curry
58 dup [ (watch) ] annotate ;
60 : (watch-vars) ( quot word vars -- newquot )
62 "--- Entering: " write swap .
63 "--- Variable values:" print
64 [ dup get ] H{ } map>assoc describe
67 : watch-vars ( word vars -- )
68 dupd [ (watch-vars) ] 2curry annotate ;
70 GENERIC# annotate-methods 1 ( word quot -- )
72 M: generic annotate-methods
73 >r "methods" word-prop values r> [ annotate ] curry each ;
75 M: word annotate-methods
78 : breakpoint ( word -- )
79 [ add-breakpoint ] annotate-methods ;
81 : breakpoint-if ( word quot -- )
82 [ [ [ break ] when ] rot 3append ] curry annotate-methods ;