2011-08-26 15:32:41 -04:00
|
|
|
! Copyright (C) 2011 Doug Coleman.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
USING: accessors assocs fry kernel quotations sequences strings
|
2011-08-27 01:56:02 -04:00
|
|
|
tools.annotations vocabs words prettyprint io splitting ;
|
2011-08-26 15:32:41 -04:00
|
|
|
IN: tools.coverage
|
|
|
|
|
|
|
|
TUPLE: coverage < identity-tuple executed? ;
|
|
|
|
|
|
|
|
C: <coverage> coverage
|
|
|
|
|
|
|
|
GENERIC: coverage-on ( object -- )
|
|
|
|
|
|
|
|
GENERIC: coverage-off ( object -- )
|
|
|
|
|
2011-08-27 02:04:02 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
|
|
|
: private-vocab-name ( string -- string' )
|
|
|
|
".private" ?tail drop ".private" append ;
|
|
|
|
|
|
|
|
: change-vocabulary-coverage ( string quot -- )
|
2011-08-27 01:56:02 -04:00
|
|
|
over ".private" tail? [
|
|
|
|
[ words ] dip each
|
|
|
|
] [
|
|
|
|
[ [ private-vocab-name words ] dip each ]
|
|
|
|
[ [ words ] dip each ] 2bi
|
|
|
|
] if ; inline
|
|
|
|
|
2011-08-27 02:04:02 -04:00
|
|
|
PRIVATE>
|
|
|
|
|
2011-08-26 15:32:41 -04:00
|
|
|
M: string coverage-on
|
2011-08-27 02:04:02 -04:00
|
|
|
[ coverage-on ] change-vocabulary-coverage ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
|
|
|
M: string coverage-off ( vocabulary -- )
|
2011-08-27 02:04:02 -04:00
|
|
|
[ coverage-off ] change-vocabulary-coverage ;
|
2011-08-26 15:32:41 -04:00
|
|
|
|
|
|
|
M: word coverage-on ( word -- )
|
|
|
|
H{ } clone [ "coverage" set-word-prop ] 2keep
|
|
|
|
'[
|
|
|
|
\ coverage new [ _ set-at ] 2keep
|
|
|
|
'[ _ t >>executed? drop ] [ ] surround
|
|
|
|
] deep-annotate ;
|
|
|
|
|
|
|
|
M: word coverage-off ( word -- )
|
|
|
|
[ reset ] [ f "coverage" set-word-prop ] bi ;
|
|
|
|
|
2011-08-27 01:56:02 -04:00
|
|
|
GENERIC: toggle-coverage ( object -- )
|
|
|
|
|
|
|
|
M: string toggle-coverage
|
2011-08-27 02:04:02 -04:00
|
|
|
[ toggle-coverage ] change-vocabulary-coverage ;
|
2011-08-27 01:56:02 -04:00
|
|
|
|
|
|
|
M: word toggle-coverage
|
|
|
|
dup "coverage" word-prop [
|
|
|
|
coverage-off
|
|
|
|
] [
|
|
|
|
coverage-on
|
|
|
|
] if ;
|
|
|
|
|
2011-08-26 15:32:41 -04:00
|
|
|
GENERIC: coverage ( object -- seq )
|
|
|
|
|
|
|
|
M: string coverage
|
|
|
|
words [ dup coverage ] { } map>assoc ;
|
|
|
|
|
|
|
|
M: word coverage ( word -- seq )
|
|
|
|
"coverage" word-prop >alist
|
|
|
|
[ drop executed?>> not ] assoc-filter values ;
|
|
|
|
|
|
|
|
GENERIC: coverage. ( object -- )
|
|
|
|
|
|
|
|
M: string coverage.
|
|
|
|
words [ coverage. ] each ;
|
|
|
|
|
|
|
|
M: word coverage.
|
|
|
|
dup coverage [
|
|
|
|
drop
|
|
|
|
] [
|
|
|
|
[ name>> ":" append print ]
|
|
|
|
[ [ bl bl bl bl . ] each ] bi*
|
|
|
|
] if-empty ;
|