Methods now remember their file/line

slava 2006-08-02 07:49:13 +00:00
parent f9b8f32e67
commit 8a6cd181c4
8 changed files with 42 additions and 30 deletions

View File

@ -29,8 +29,6 @@
- offer to remove generic words which are not called and have no
methods
- forgetting a tuple class should forget the constructor
- methods: remember their file/line
- { class generic } jedit, reload DTRT
- T{ link f "foo" "bar" } see
- T{ link f "foo" "bar" } jedit
- T{ link f "foo" "bar" } reload

View File

@ -3,12 +3,27 @@
IN: generic
USING: words hashtables sequences arrays errors kernel ;
PREDICATE: array method-spec
dup length 2 = [
first2 generic? >r class? r> and
] [
drop f
] if ;
TUPLE: method def loc ;
M: f method-def ;
M: f method-loc ;
M: quotation method-def ;
M: quotation method-loc drop f ;
: method ( class generic -- quot )
"methods" word-prop hash ;
"methods" word-prop hash method-def ;
: methods ( generic -- alist )
"methods" word-prop hash>alist
[ [ first ] 2apply class-compare ] sort ;
[ [ first ] 2apply class-compare ] sort
[ first2 method-def 2array ] map ;
: order ( generic -- list )
"methods" word-prop hash-keys [ class-compare ] sort ;
@ -23,7 +38,7 @@ TUPLE: check-method class generic ;
swap [ "methods" word-prop swap call ] keep ?make-generic ;
inline
: define-method ( definition class generic -- )
: define-method ( method class generic -- )
>r bootstrap-word r> check-method
[ set-hash ] with-methods ;

View File

@ -32,10 +32,10 @@ TUPLE: check-vocab name ;
: parsing? ( word -- ? )
dup word? [ "parsing" word-prop ] [ drop f ] if ;
: location ( -- loc ) file get line-number get 2array ;
: save-location ( word -- )
dup set-word
dup line-number get "line" set-word-prop
file get "file" set-word-prop ;
dup set-word location "loc" set-word-prop ;
: create-in in get create dup save-location ;

View File

@ -1,8 +1,8 @@
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: parser
USING: errors generic io kernel math namespaces sequences
words ;
USING: errors generic hashtables io kernel math namespaces
sequences words ;
: file-vocabs ( -- )
"scratchpad" set-in { "syntax" "scratchpad" } set-use ;
@ -41,8 +41,16 @@ words ;
: run-resource ( file -- ) parse-resource call ;
: word-file ( word -- file )
"file" word-prop dup
[ "resource:/" ?head [ resource-path ] when ] when ;
GENERIC: where ( spec -- loc )
: reload ( word -- ) word-file run-file ;
M: word where "loc" word-prop ;
M: method-spec where
dup first2 "methods" word-prop hash method-loc
[ ] [ second where ] ?if ;
: ?resource-path ( path -- path )
"resource:/" ?head [ resource-path ] when ;
: reload ( spec -- )
where first [ ?resource-path run-file ] when* ;

View File

@ -57,10 +57,6 @@ HELP: run-resource "( path -- )"
{ $description "Parses and runs a library resource." }
{ $errors "Throws an I/O error if there was an error reading the resource. Throws a parse error if the input is malformed." } ;
HELP: word-file "( word -- file )"
{ $values { "word" "a word" } { "file" "a path name string" } }
{ $description "Outputs the file name containing the most recent redefinition of the word, or " { $link f } " if the word was not defined in a file." } ;
HELP: reload "( word -- )"
{ $values { "word" "a word" } }
{ $description "Reloads the source file containing the most recent redefinition of the word." }

View File

@ -52,7 +52,9 @@ DEFER: !PRIMITIVE: parsing
: !: CREATE dup reset-generic [ define-compound ] f ; parsing
: !GENERIC: CREATE dup reset-word define-generic ; parsing
: !G: CREATE dup reset-word [ define-generic* ] f ; parsing
: !M: scan-word scan-word [ -rot define-method ] f ; parsing
: !M:
scan-word scan-word
[ location <method> -rot define-method ] f ; parsing
: !UNION: ( -- class predicate definition )
CREATE dup intern-symbol dup predicate-word

View File

@ -4,13 +4,6 @@ IN: prettyprint
USING: arrays generic hashtables io kernel math namespaces
sequences styles words ;
PREDICATE: array method-spec
dup length 2 = [
first2 generic? >r class? r> and
] [
drop f
] if ;
GENERIC: (synopsis) ( spec -- )
: write-vocab ( vocab -- )

View File

@ -1,5 +1,5 @@
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
! Copyright (C) 2004, 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: jedit
USING: arrays errors io kernel listener math namespaces
parser prettyprint sequences strings words shells ;
@ -36,9 +36,9 @@ parser prettyprint sequences strings words shells ;
: jedit-file ( file -- )
1array make-jedit-request send-jedit-request ;
: jedit ( word -- )
: jedit ( spec -- )
#! Note that line numbers here start from 1
dup word-file swap "line" word-prop jedit-line/file ;
where first2 >r ?resource-path r> jedit-line/file ;
! Wire protocol for jEdit to evaluate Factor code.
! Packets are of the form: