factor/basis/tools/annotations/annotations.factor

83 lines
2.0 KiB
Factor
Raw Normal View History

2008-02-21 00:13:31 -05:00
! Copyright (C) 2005, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-07-02 01:20:01 -04:00
USING: accessors kernel words parser io summary quotations
sequences prettyprint continuations effects definitions
2008-07-02 01:20:01 -04:00
compiler.units namespaces assocs tools.walker generic
inspector ;
2007-09-20 18:09:08 -04:00
IN: tools.annotations
2008-04-05 23:59:31 -04:00
GENERIC: reset ( word -- )
M: generic reset
[ call-next-method ]
[ subwords [ reset ] each ] bi ;
M: word reset
dup "unannotated-def" word-prop [
[
2008-02-07 18:07:43 -05:00
dup dup "unannotated-def" word-prop define
] with-compilation-unit
2008-02-07 18:07:43 -05:00
f "unannotated-def" set-word-prop
] [ drop ] if ;
2007-09-20 18:09:08 -04:00
: annotate ( word quot -- )
2008-02-07 18:07:43 -05:00
over "unannotated-def" word-prop [
"Cannot annotate a word twice" throw
] when
[
over dup def>> "unannotated-def" set-word-prop
>r dup def>> r> call define
] with-compilation-unit ; inline
2007-09-20 18:09:08 -04:00
2008-02-07 18:07:43 -05:00
: word-inputs ( word -- seq )
stack-effect [
2008-08-29 11:26:53 -04:00
>r datastack r> in>> length tail*
] [
2008-02-07 18:07:43 -05:00
datastack
] if* ;
: entering ( str -- )
"/-- Entering: " write dup .
word-inputs stack.
"\\--" print flush ;
2007-09-20 18:09:08 -04:00
: leaving ( str -- )
"/-- Leaving: " write dup .
stack-effect [
2008-08-29 11:26:53 -04:00
>r datastack r> out>> length tail* stack.
] [
.s
] if* "\\--" print flush ;
2007-09-20 18:09:08 -04:00
: (watch) ( word def -- def )
2007-09-20 18:09:08 -04:00
over [ entering ] curry
rot [ leaving ] curry
swapd 3append ;
: watch ( word -- )
dup [ (watch) ] annotate ;
2007-09-20 18:09:08 -04:00
2008-02-10 02:38:51 -05:00
: (watch-vars) ( quot word vars -- newquot )
[
"--- Entering: " write swap .
"--- Variable values:" print
[ dup get ] H{ } map>assoc describe
] 2curry prepose ;
2008-02-10 02:38:51 -05:00
: watch-vars ( word vars -- )
dupd [ (watch-vars) ] 2curry annotate ;
2008-04-05 23:59:31 -04:00
GENERIC# annotate-methods 1 ( word quot -- )
M: generic annotate-methods
>r "methods" word-prop values r> [ annotate ] curry each ;
M: word annotate-methods
annotate ;
2007-09-20 18:09:08 -04:00
: breakpoint ( word -- )
2008-04-05 23:59:31 -04:00
[ add-breakpoint ] annotate-methods ;
2007-09-20 18:09:08 -04:00
: breakpoint-if ( word quot -- )
2008-04-05 23:59:31 -04:00
[ [ [ break ] when ] rot 3append ] curry annotate-methods ;