Starting work on advice vocab
parent
f5db48e3b7
commit
f8da0cd23f
|
@ -0,0 +1,5 @@
|
||||||
|
! Copyright (C) 2008 James Cash
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: kernel sequences tools.tests advice ;
|
||||||
|
IN: advice.tests
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
! Copyright (C) 2008 James Cash
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: kernel sequences symbols fry words assocs tools.annotations ;
|
||||||
|
IN: advice
|
||||||
|
|
||||||
|
SYMBOLS: before after around ;
|
||||||
|
|
||||||
|
: get-advice ( word type -- seq )
|
||||||
|
word-prop values ;
|
||||||
|
|
||||||
|
: call-before ( word -- )
|
||||||
|
before get-advice [ call ] each ;
|
||||||
|
|
||||||
|
: call-after ( word -- )
|
||||||
|
after get-advice [ call ] each ;
|
||||||
|
|
||||||
|
: advise-before ( quot name word -- )
|
||||||
|
before word-prop set-at ;
|
||||||
|
|
||||||
|
: advise-after ( quot name word -- )
|
||||||
|
after word-prop set-at ;
|
||||||
|
|
||||||
|
: remove-advice ( name word loc -- )
|
||||||
|
word-prop delete-at ;
|
||||||
|
|
||||||
|
: make-advised ( word -- )
|
||||||
|
[ dup [ over '[ _ call-before @ _ call-after ] ] annotate ]
|
||||||
|
[ { before after around } [ H{ } clone swap set-word-prop ] with each ] bi ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
James Cash
|
|
@ -0,0 +1,3 @@
|
||||||
|
advice
|
||||||
|
aspect
|
||||||
|
annotations
|
Loading…
Reference in New Issue