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
|
2005-09-11 20:46:55 -04:00
|
|
|
USING: arrays kernel kernel-internals lists math namespaces
|
|
|
|
parser sequences strings words ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
2005-08-02 00:25:05 -04:00
|
|
|
: define-typecheck ( class generic def -- )
|
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 -- )
|
|
|
|
over [
|
2006-05-10 20:32:04 -04:00
|
|
|
rot >fixnum add* define-typecheck
|
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-05-02 01:49:52 -04:00
|
|
|
: define-reader ( class slot decl reader -- )
|
|
|
|
[ slot ] rot dup object eq? [
|
|
|
|
drop
|
|
|
|
] [
|
2006-05-10 20:32:04 -04:00
|
|
|
1array [ declare ] swap add* append
|
2006-05-02 01:49:52 -04:00
|
|
|
] if define-slot-word ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: define-writer ( class slot writer -- )
|
|
|
|
[ set-slot ] define-slot-word ;
|
|
|
|
|
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 ;
|