2005-02-20 19:03:37 -05:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
|
|
|
|
IN: generic
|
2006-05-15 01:01:47 -04:00
|
|
|
USING: arrays kernel kernel-internals math namespaces
|
2005-09-11 20:46:55 -04:00
|
|
|
parser sequences strings words ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: define-typecheck ( class generic quot -- )
|
2005-09-16 02:39:33 -04:00
|
|
|
over define-generic -rot define-method ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: define-slot-word ( class slot word quot -- )
|
2006-08-15 03:01:24 -04:00
|
|
|
rot >fixnum add* define-typecheck ;
|
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: reader-effect ( -- effect ) 1 1 <effect> ; inline
|
2006-08-15 03:01:24 -04:00
|
|
|
|
|
|
|
: define-reader ( class slot decl reader -- )
|
|
|
|
dup [
|
|
|
|
dup reader-effect "declared-effect" set-word-prop
|
|
|
|
[ slot ] rot dup object eq?
|
|
|
|
[ drop ] [ 1array [ declare ] swap add* append ] if
|
|
|
|
define-slot-word
|
2005-02-20 19:03:37 -05:00
|
|
|
] [
|
|
|
|
2drop 2drop
|
2005-09-24 15:21:17 -04:00
|
|
|
] if ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
2006-08-16 21:55:53 -04:00
|
|
|
: writer-effect ( -- effect ) 2 0 <effect> ; inline
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: define-writer ( class slot writer -- )
|
2006-08-15 03:01:24 -04:00
|
|
|
dup [
|
|
|
|
dup writer-effect "declared-effect" set-word-prop
|
|
|
|
[ set-slot ] define-slot-word
|
|
|
|
] [
|
|
|
|
3drop
|
|
|
|
] if ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
2006-05-02 01:49:52 -04:00
|
|
|
: define-slot ( class slot decl reader writer -- )
|
|
|
|
>r >r >r 2dup r> r> define-reader r> define-writer ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: intern-slots ( spec -- spec )
|
2006-05-02 01:49:52 -04:00
|
|
|
[ [ dup array? [ first2 create ] when ] map ] map ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: define-slots ( class spec -- )
|
2006-05-02 01:49:52 -04:00
|
|
|
[ first4 define-slot ] each-with ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: reader-word ( class name -- word )
|
2005-12-17 09:55:00 -05:00
|
|
|
>r word-name "-" r> append3 in get 2array ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: writer-word ( class name -- word )
|
2005-12-17 09:55:00 -05:00
|
|
|
[ swap "set-" % word-name % "-" % % ] "" make in get 2array ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
2006-05-02 01:49:52 -04:00
|
|
|
: simple-slot ( class name -- )
|
|
|
|
2dup reader-word , writer-word , ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
2005-07-25 17:13:35 -04:00
|
|
|
: simple-slots ( class slots base -- spec )
|
|
|
|
over length [ + ] map-with
|
2006-05-02 01:49:52 -04:00
|
|
|
[ [ , object , dupd simple-slot ] { } make ] 2map nip intern-slots ;
|