tools.annotations: redo 'watch' so that it doesn't call 'datastack' anymore, instead use macros to capture stack values. This works better with compiler optimizations

db4
Slava Pestov 2009-07-03 22:32:30 -05:00
parent a3c3445643
commit f53efa88c6
2 changed files with 25 additions and 10 deletions

View File

@ -49,3 +49,14 @@ M: string blah-generic ;
[ ] [ M\ string blah-generic watch ] unit-test
[ "hi" ] [ "hi" blah-generic ] unit-test
! See how well watch interacts with optimizations.
GENERIC: my-generic ( a -- b )
M: object my-generic ;
\ my-generic watch
: some-code ( -- )
f my-generic drop ;
[ ] [ some-code ] unit-test

View File

@ -3,7 +3,8 @@
USING: accessors kernel math sorting words parser io summary
quotations sequences prettyprint continuations effects
definitions compiler.units namespaces assocs tools.walker
tools.time generic inspector fry tools.continuations ;
tools.time generic inspector fry tools.continuations
locals generalizations macros ;
IN: tools.annotations
GENERIC: reset ( word -- )
@ -46,17 +47,20 @@ M: word annotate
<PRIVATE
: stack-values ( names -- alist )
[ datastack ] dip [ nip ] [ length tail* ] 2bi zip ;
:: trace-quot ( word effect quot str -- quot' )
effect quot call :> values
values length :> n
[
"--- " write str write bl word .
n ndup n narray values swap zip simple-table.
flush
] ; inline
: trace-message ( word quot str -- )
"--- " write write bl over .
[ stack-effect ] dip '[ @ stack-values ] [ f ] if*
[ simple-table. ] unless-empty flush ; inline
MACRO: entering ( word -- quot )
dup stack-effect [ in>> ] "Entering" trace-quot ;
: entering ( str -- ) [ in>> ] "Entering" trace-message ;
: leaving ( str -- ) [ out>> ] "Leaving" trace-message ;
MACRO: leaving ( word -- quot )
dup stack-effect [ out>> ] "Leaving" trace-quot ;
: (watch) ( word def -- def )
over '[ _ entering @ _ leaving ] ;