2005-02-18 20:37:01 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-12-13 00:13:54 -05:00
|
|
|
IN: generic
|
2005-05-06 19:49:07 -04:00
|
|
|
USING: errors hashtables kernel lists math namespaces parser
|
|
|
|
sequences strings vectors words ;
|
2004-12-13 00:13:54 -05:00
|
|
|
|
|
|
|
! Builtin metaclass for builtin types: fixnum, word, cons, etc.
|
|
|
|
SYMBOL: builtin
|
|
|
|
|
2005-03-28 23:45:13 -05:00
|
|
|
! Global vector mapping type numbers to builtin class objects.
|
|
|
|
SYMBOL: builtins
|
|
|
|
|
2004-12-13 00:13:54 -05:00
|
|
|
builtin [
|
2005-03-05 14:45:23 -05:00
|
|
|
"builtin-type" word-prop unit
|
|
|
|
] "builtin-supertypes" set-word-prop
|
2004-12-13 00:13:54 -05:00
|
|
|
|
2004-12-18 23:18:32 -05:00
|
|
|
builtin [
|
2004-12-23 23:55:22 -05:00
|
|
|
( generic vtable definition class -- )
|
|
|
|
rot set-vtable drop
|
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
|
|
|
builtin 50 "priority" set-word-prop
|
2004-12-18 23:18:32 -05:00
|
|
|
|
2004-12-29 18:01:23 -05:00
|
|
|
! All builtin types are equivalent in ordering
|
2005-07-31 23:38:33 -04:00
|
|
|
builtin [ (class<) ] "class<" set-word-prop
|
2004-12-29 18:01:23 -05:00
|
|
|
|
2005-07-28 18:20:31 -04:00
|
|
|
: builtin-predicate ( class predicate -- )
|
|
|
|
2dup register-predicate
|
|
|
|
[ \ type , swap "builtin-type" word-prop , \ eq? , ] make-list
|
2005-05-14 17:18:45 -04:00
|
|
|
define-compound ;
|
|
|
|
|
|
|
|
: register-builtin ( class -- )
|
|
|
|
dup "builtin-type" word-prop builtins get set-nth ;
|
|
|
|
|
|
|
|
: define-builtin ( symbol type# predicate slotspec -- )
|
|
|
|
>r >r >r
|
2004-12-23 02:14:40 -05:00
|
|
|
dup intern-symbol
|
2005-05-14 17:18:45 -04:00
|
|
|
dup r> "builtin-type" set-word-prop
|
|
|
|
dup builtin define-class
|
2005-07-28 18:20:31 -04:00
|
|
|
dup r> builtin-predicate
|
2005-07-25 17:13:35 -04:00
|
|
|
dup r> intern-slots 2dup "slots" set-word-prop
|
|
|
|
define-slots
|
2005-05-14 17:18:45 -04:00
|
|
|
register-builtin ;
|
2004-12-13 00:13:54 -05:00
|
|
|
|
2005-04-26 00:35:55 -04:00
|
|
|
: builtin-type ( n -- symbol ) builtins get nth ;
|
2005-03-26 20:12:14 -05:00
|
|
|
|
|
|
|
PREDICATE: word builtin metaclass builtin = ;
|
2005-05-06 19:49:07 -04:00
|
|
|
|
|
|
|
: type-tag ( type -- tag )
|
|
|
|
#! Given a type number, return the tag number.
|
|
|
|
dup 6 > [ drop 3 ] when ;
|