From ec186a23dc654ca8fae3c4ad783b132d7cb87777 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Fri, 6 Mar 2009 13:32:07 -0600 Subject: [PATCH] Make watch and other annotations work on method-specs. { world graft* } watch --- .../annotations/annotations-tests.factor | 8 +++ basis/tools/annotations/annotations.factor | 49 +++++++++++++++---- core/generic/generic.factor | 3 ++ 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/basis/tools/annotations/annotations-tests.factor b/basis/tools/annotations/annotations-tests.factor index 1e766e3dec..2a65ea5236 100644 --- a/basis/tools/annotations/annotations-tests.factor +++ b/basis/tools/annotations/annotations-tests.factor @@ -38,3 +38,11 @@ M: object another-generic ; [ ] [ \ another-generic reset ] unit-test [ "" ] [ [ 3 another-generic drop ] with-string-writer ] unit-test + +GENERIC: blah-generic ( a -- b ) + +M: string blah-generic ; + +{ string blah-generic } watch + +[ ] [ "hi" blah-generic ] unit-test \ No newline at end of file diff --git a/basis/tools/annotations/annotations.factor b/basis/tools/annotations/annotations.factor index b436be5163..7bb4711b90 100644 --- a/basis/tools/annotations/annotations.factor +++ b/basis/tools/annotations/annotations.factor @@ -1,4 +1,4 @@ -! Copyright (C) 2005, 2008 Slava Pestov. +! Copyright (C) 2005, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel math sorting words parser io summary quotations sequences prettyprint continuations effects @@ -20,16 +20,34 @@ M: word reset f "unannotated-def" set-word-prop ] [ drop ] if ; +M: method-spec reset + first2 method reset ; + ERROR: cannot-annotate-twice word ; +word ( obj -- word ) + dup method-spec? [ first2 method ] when ; + +: save-unannotated-def ( word -- ) + dup def>> "unannotated-def" set-word-prop ; + +: (annotate) ( word quot -- ) + [ dup def>> ] dip call define ; inline + +PRIVATE> + : annotate ( word quot -- ) - over "unannotated-def" word-prop [ - over cannot-annotate-twice - ] when - [ - over dup def>> "unannotated-def" set-word-prop - [ dup def>> ] dip call define - ] with-compilation-unit ; inline + [ method-spec>word check-annotate-twice ] dip + [ over save-unannotated-def (annotate) ] with-compilation-unit ; inline + + + : watch ( word -- ) - dup [ (watch) ] annotate ; + dup '[ [ _ ] dip (watch) ] annotate ; + + + GENERIC# annotate-methods 1 ( word quot -- ) M: generic annotate-methods @@ -79,6 +103,9 @@ M: generic annotate-methods M: word annotate-methods annotate ; +M: method-spec annotate-methods + annotate ; + : breakpoint ( word -- ) [ add-breakpoint ] annotate-methods ; @@ -92,9 +119,13 @@ word-timing [ H{ } clone ] initialize : reset-word-timing ( -- ) word-timing get clear-assoc ; + + : add-timing ( word -- ) dup '[ _ (add-timing) ] annotate ; diff --git a/core/generic/generic.factor b/core/generic/generic.factor index c16b6a52a1..c520b4aaac 100644 --- a/core/generic/generic.factor +++ b/core/generic/generic.factor @@ -83,6 +83,9 @@ TUPLE: check-method class generic ; PREDICATE: method-body < word "method-generic" word-prop >boolean ; +M: method-spec stack-effect + first2 method stack-effect ; + M: method-body stack-effect "method-generic" word-prop stack-effect ;