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 [
|
2005-08-02 00:25:05 -04:00
|
|
|
>r swap >fixnum r> cons 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
|
|
|
|
|
|
|
: define-reader ( class slot reader -- )
|
|
|
|
[ slot ] define-slot-word ;
|
|
|
|
|
|
|
|
: define-writer ( class slot writer -- )
|
|
|
|
[ set-slot ] define-slot-word ;
|
|
|
|
|
|
|
|
: define-slot ( class slot reader writer -- )
|
|
|
|
>r >r 2dup r> define-reader r> define-writer ;
|
|
|
|
|
|
|
|
: intern-slots ( spec -- spec )
|
2005-12-10 01:02:13 -05:00
|
|
|
[ first3 [ dup [ first2 create ] when ] 2apply 3array ] map ;
|
2005-02-20 19:03:37 -05:00
|
|
|
|
|
|
|
: define-slots ( class spec -- )
|
2005-09-02 23:44:23 -04:00
|
|
|
[ first3 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
|
|
|
|
2005-07-25 17:13:35 -04:00
|
|
|
: simple-slot ( class name -- reader writer )
|
|
|
|
[ reader-word ] 2keep 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
|
2005-09-11 20:46:55 -04:00
|
|
|
[ >r dupd simple-slot r> -rot 3array ] 2map nip
|
2005-08-19 21:46:12 -04:00
|
|
|
intern-slots ;
|