2004-12-18 23:18:32 -05:00
|
|
|
! :folding=indent:collapseFolds=1:
|
2004-07-16 02:26:21 -04:00
|
|
|
|
|
|
|
! $Id$
|
|
|
|
!
|
2004-12-18 23:18:32 -05:00
|
|
|
! Copyright (C) 2004 Slava Pestov.
|
2004-07-16 02:26:21 -04:00
|
|
|
!
|
|
|
|
! Redistribution and use in source and binary forms, with or without
|
|
|
|
! modification, are permitted provided that the following conditions are met:
|
|
|
|
!
|
|
|
|
! 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer.
|
|
|
|
!
|
|
|
|
! 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
! this list of conditions and the following disclaimer in the documentation
|
|
|
|
! and/or other materials provided with the distribution.
|
|
|
|
!
|
|
|
|
! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
IN: generic
|
|
|
|
USE: errors
|
|
|
|
USE: hashtables
|
2004-07-16 02:26:21 -04:00
|
|
|
USE: kernel
|
2004-12-18 23:18:32 -05:00
|
|
|
USE: lists
|
|
|
|
USE: namespaces
|
|
|
|
USE: parser
|
|
|
|
USE: strings
|
|
|
|
USE: words
|
|
|
|
USE: vectors
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
! Union metaclass for dispatch on multiple classes.
|
|
|
|
SYMBOL: union
|
2004-07-28 19:02:24 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
union [
|
|
|
|
[ ] swap "members" word-property [
|
|
|
|
builtin-supertypes append
|
|
|
|
] each
|
|
|
|
] "builtin-supertypes" set-word-property
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
union [
|
2004-12-23 23:55:22 -05:00
|
|
|
( generic vtable definition class -- )
|
|
|
|
"members" word-property [ >r 3dup r> add-method ] each 3drop
|
2004-12-18 23:18:32 -05:00
|
|
|
] "add-method" set-word-property
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
union 30 "priority" set-word-property
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
union [ 2drop t ] "class<" set-word-property
|
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
: union-predicate ( definition -- list )
|
|
|
|
[
|
|
|
|
[
|
|
|
|
\ dup ,
|
2004-12-23 01:14:07 -05:00
|
|
|
unswons "predicate" word-property append,
|
2004-12-18 23:18:32 -05:00
|
|
|
[ drop t ] ,
|
|
|
|
union-predicate ,
|
|
|
|
\ ifte ,
|
|
|
|
] make-list
|
|
|
|
] [
|
|
|
|
[ drop f ]
|
|
|
|
] ifte* ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
: define-union ( class predicate definition -- )
|
2004-12-23 18:26:04 -05:00
|
|
|
#! We have to turn the f object into the f word, same for t.
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[
|
|
|
|
[ f | POSTPONE: f ]
|
|
|
|
[ t | POSTPONE: t ]
|
|
|
|
] assoc dup
|
|
|
|
] keep ?
|
|
|
|
] map
|
2004-12-18 23:18:32 -05:00
|
|
|
[ union-predicate define-compound ] keep
|
|
|
|
"members" set-word-property ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
: UNION: ( -- class predicate definition )
|
|
|
|
#! Followed by a class name, then a list of union members.
|
|
|
|
CREATE
|
2004-12-23 02:14:40 -05:00
|
|
|
dup intern-symbol
|
|
|
|
dup union define-class
|
2004-12-18 23:18:32 -05:00
|
|
|
dup predicate-word
|
2004-12-23 01:14:07 -05:00
|
|
|
[ dupd unit "predicate" set-word-property ] keep
|
2004-12-18 23:18:32 -05:00
|
|
|
[ define-union ] [ ] ; parsing
|