diff --git a/extra/advice/advice-docs.factor b/extra/advice/advice-docs.factor new file mode 100644 index 0000000000..e69de29bb2 diff --git a/extra/advice/advice-tests.factor b/extra/advice/advice-tests.factor new file mode 100644 index 0000000000..0d71ef2220 --- /dev/null +++ b/extra/advice/advice-tests.factor @@ -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 + diff --git a/extra/advice/advice.factor b/extra/advice/advice.factor new file mode 100644 index 0000000000..12874be1f1 --- /dev/null +++ b/extra/advice/advice.factor @@ -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 ; + \ No newline at end of file diff --git a/extra/advice/authors.txt b/extra/advice/authors.txt new file mode 100644 index 0000000000..4b7af4aac0 --- /dev/null +++ b/extra/advice/authors.txt @@ -0,0 +1 @@ +James Cash diff --git a/extra/advice/tags.txt b/extra/advice/tags.txt new file mode 100644 index 0000000000..a87b65d938 --- /dev/null +++ b/extra/advice/tags.txt @@ -0,0 +1,3 @@ +advice +aspect +annotations