2005-01-14 12:01:48 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
2005-02-18 20:37:01 -05:00
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-12-13 00:13:54 -05:00
|
|
|
IN: generic
|
2005-02-18 20:37:01 -05:00
|
|
|
USING: errors hashtables kernel lists namespaces parser strings
|
|
|
|
words vectors ;
|
2004-12-13 00:13:54 -05:00
|
|
|
|
|
|
|
! Predicate metaclass for generalized predicate dispatch.
|
|
|
|
SYMBOL: predicate
|
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
: predicate-dispatch ( existing definition class -- dispatch )
|
2004-12-13 00:13:54 -05:00
|
|
|
[
|
2005-03-05 14:45:23 -05:00
|
|
|
\ dup , "predicate" word-prop append, , , \ ifte ,
|
2004-12-13 00:13:54 -05:00
|
|
|
] make-list ;
|
|
|
|
|
2004-12-19 03:04:03 -05:00
|
|
|
: predicate-method ( vtable definition class type# -- )
|
2004-12-18 23:18:32 -05:00
|
|
|
>r rot r> swap [
|
|
|
|
vector-nth
|
|
|
|
( vtable definition class existing )
|
|
|
|
-rot predicate-dispatch
|
|
|
|
] 2keep set-vector-nth ;
|
2004-12-13 00:13:54 -05:00
|
|
|
|
|
|
|
predicate [
|
2005-03-05 14:45:23 -05:00
|
|
|
"superclass" word-prop builtin-supertypes
|
|
|
|
] "builtin-supertypes" set-word-prop
|
2004-12-13 00:13:54 -05:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
predicate [
|
2004-12-23 23:55:22 -05:00
|
|
|
( generic vtable definition class -- )
|
2004-12-18 23:18:32 -05:00
|
|
|
dup builtin-supertypes [
|
|
|
|
( vtable definition class type# )
|
2004-12-19 03:04:03 -05:00
|
|
|
>r 3dup r> predicate-method
|
2004-12-23 23:55:22 -05:00
|
|
|
] each 2drop 2drop
|
2005-03-05 14:45:23 -05:00
|
|
|
] "add-method" set-word-prop
|
2004-12-18 23:18:32 -05:00
|
|
|
|
2005-03-05 14:45:23 -05:00
|
|
|
predicate 25 "priority" set-word-prop
|
2004-12-18 23:18:32 -05:00
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
predicate [
|
|
|
|
2dup = [
|
|
|
|
2drop t
|
|
|
|
] [
|
2005-03-05 14:45:23 -05:00
|
|
|
>r "superclass" word-prop r> class<
|
2004-12-29 18:01:23 -05:00
|
|
|
] ifte
|
2005-03-05 14:45:23 -05:00
|
|
|
] "class<" set-word-prop
|
2004-12-29 18:01:23 -05:00
|
|
|
|
2004-12-13 00:13:54 -05:00
|
|
|
: define-predicate ( class predicate definition -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
pick "superclass" word-prop "predicate" word-prop
|
2004-12-23 01:14:07 -05:00
|
|
|
[ \ dup , append, , [ drop f ] , \ ifte , ] make-list
|
2005-01-14 12:01:48 -05:00
|
|
|
define-compound
|
2005-03-05 14:45:23 -05:00
|
|
|
predicate "metaclass" set-word-prop ;
|