2007-11-28 10:49:43 -05:00
|
|
|
! Copyright (C) 2007 Daniel Ehrenberg
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-04-03 20:17:58 -04:00
|
|
|
USING: parser generic kernel classes words slots assocs sequences arrays
|
2008-04-05 00:14:40 -04:00
|
|
|
vectors definitions prettyprint ;
|
2007-11-28 10:49:43 -05:00
|
|
|
IN: delegate
|
|
|
|
|
2008-04-05 00:14:40 -04:00
|
|
|
! Protocols
|
|
|
|
|
|
|
|
: cross-2each ( seq1 seq2 quot -- )
|
|
|
|
[ with each ] 2curry each ; inline
|
|
|
|
|
|
|
|
: forget-all-methods ( classes words -- )
|
|
|
|
[ 2array forget ] cross-2each ;
|
|
|
|
|
|
|
|
: protocol-words ( protocol -- words )
|
|
|
|
"protocol-words" word-prop ;
|
|
|
|
|
|
|
|
: protocol-users ( protocol -- users )
|
|
|
|
"protocol-users" word-prop ;
|
|
|
|
|
|
|
|
: users-and-words ( protocol -- users words )
|
|
|
|
[ protocol-users ] [ protocol-words ] bi ;
|
|
|
|
|
|
|
|
: forget-old-definitions ( protocol new-wordlist -- )
|
|
|
|
>r users-and-words r>
|
|
|
|
seq-diff forget-all-methods ;
|
|
|
|
|
|
|
|
: define-protocol ( protocol wordlist -- )
|
|
|
|
2dup forget-old-definitions
|
|
|
|
{ } like "protocol-words" set-word-prop ;
|
2007-11-28 10:49:43 -05:00
|
|
|
|
|
|
|
: PROTOCOL:
|
2008-04-05 00:14:40 -04:00
|
|
|
CREATE-WORD
|
|
|
|
dup define-symbol
|
|
|
|
dup f "inline" set-word-prop
|
|
|
|
parse-definition define-protocol ; parsing
|
2007-11-28 10:49:43 -05:00
|
|
|
|
2008-04-05 00:14:40 -04:00
|
|
|
PREDICATE: protocol < word protocol-words ; ! Subclass of symbol?
|
|
|
|
|
|
|
|
M: protocol forget*
|
|
|
|
[ users-and-words forget-all-methods ] [ call-next-method ] bi ;
|
|
|
|
|
|
|
|
M: protocol definition protocol-words ;
|
|
|
|
|
|
|
|
M: protocol definer drop \ PROTOCOL: \ ; ;
|
|
|
|
|
|
|
|
M: protocol synopsis* word-synopsis ; ! Necessary?
|
2007-11-28 10:49:43 -05:00
|
|
|
|
|
|
|
GENERIC: group-words ( group -- words )
|
|
|
|
|
|
|
|
M: protocol group-words
|
|
|
|
"protocol-words" word-prop ;
|
|
|
|
|
|
|
|
M: generic group-words
|
2008-04-03 20:17:58 -04:00
|
|
|
1array ;
|
2007-11-28 10:49:43 -05:00
|
|
|
|
|
|
|
M: tuple-class group-words
|
2008-04-05 00:14:40 -04:00
|
|
|
"slots" word-prop
|
|
|
|
[ [ slot-spec-reader ] map ]
|
|
|
|
[ [ slot-spec-writer ] map ] bi append ;
|
|
|
|
|
|
|
|
! Consultation
|
2007-11-28 10:49:43 -05:00
|
|
|
|
|
|
|
: define-consult-method ( word class quot -- )
|
2008-03-31 20:18:05 -04:00
|
|
|
pick suffix >r swap create-method r> define ;
|
2008-04-03 20:17:58 -04:00
|
|
|
|
|
|
|
: change-word-prop ( word prop quot -- )
|
|
|
|
>r swap word-props r> change-at ; inline
|
|
|
|
|
2008-04-05 00:14:40 -04:00
|
|
|
: add ( item vector/f -- vector )
|
|
|
|
2dup member? [ nip ] [ ?push ] if ;
|
|
|
|
|
2008-04-03 20:17:58 -04:00
|
|
|
: declare-consult ( class group -- )
|
2008-04-05 00:14:40 -04:00
|
|
|
"protocol-users" [ add ] change-word-prop ;
|
2007-11-28 10:49:43 -05:00
|
|
|
|
|
|
|
: define-consult ( class group quot -- )
|
2008-04-03 20:17:58 -04:00
|
|
|
>r 2dup declare-consult group-words swap r>
|
2008-03-17 04:27:41 -04:00
|
|
|
[ define-consult-method ] 2curry each ;
|
2007-11-28 10:49:43 -05:00
|
|
|
|
|
|
|
: CONSULT:
|
|
|
|
scan-word scan-word parse-definition swapd define-consult ; parsing
|
|
|
|
|
2008-04-05 00:14:40 -04:00
|
|
|
! Mimic still needs to be updated
|
|
|
|
|
2007-11-28 10:49:43 -05:00
|
|
|
: define-mimic ( group mimicker mimicked -- )
|
2008-04-05 00:14:40 -04:00
|
|
|
rot group-words -rot [
|
2007-12-08 03:21:32 -05:00
|
|
|
pick "methods" word-prop at dup
|
2008-04-05 00:14:40 -04:00
|
|
|
[ >r swap create-method-in r> word-def define ]
|
2008-03-05 16:24:13 -05:00
|
|
|
[ 3drop ] if
|
2007-11-28 10:49:43 -05:00
|
|
|
] 2curry each ;
|
|
|
|
|
|
|
|
: MIMIC:
|
|
|
|
scan-word scan-word scan-word define-mimic ; parsing
|