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
|
|
|
|
vectors ;
|
2007-11-28 10:49:43 -05:00
|
|
|
IN: delegate
|
|
|
|
|
|
|
|
: define-protocol ( wordlist protocol -- )
|
|
|
|
swap { } like "protocol-words" set-word-prop ;
|
|
|
|
|
|
|
|
: PROTOCOL:
|
2008-03-16 03:43:00 -04:00
|
|
|
CREATE-WORD dup define-symbol
|
2007-11-28 10:49:43 -05:00
|
|
|
parse-definition swap define-protocol ; parsing
|
|
|
|
|
2008-03-26 19:23:19 -04:00
|
|
|
PREDICATE: protocol < word "protocol-words" word-prop ;
|
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
|
|
|
|
"slots" word-prop 1 tail ! The first slot is the delegate
|
|
|
|
! 1 tail should be removed when the delegate slot is removed
|
|
|
|
dup [ slot-spec-reader ] map
|
|
|
|
swap [ slot-spec-writer ] map append ;
|
|
|
|
|
|
|
|
: 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
|
|
|
|
|
|
|
: 3bi ( x y z p q -- p(x,y,z) q(x,y,z) )
|
|
|
|
>r 3keep r> call ; inline
|
|
|
|
|
|
|
|
: change-word-prop ( word prop quot -- )
|
|
|
|
>r swap word-props r> change-at ; inline
|
|
|
|
|
|
|
|
: declare-consult ( class group -- )
|
|
|
|
"protocol-users" [ ?push ] 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
|
|
|
|
|
|
|
|
: define-mimic ( group mimicker mimicked -- )
|
|
|
|
>r >r group-words r> r> [
|
2007-12-08 03:21:32 -05:00
|
|
|
pick "methods" word-prop at dup
|
2008-03-17 04:27:41 -04:00
|
|
|
[ >r swap create-method 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
|