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-03-05 14:45:23 -05:00
|
|
|
builtin [ 2drop t ] "class<" set-word-prop
|
2004-12-29 18:01:23 -05:00
|
|
|
|
2004-12-20 15:29:55 -05:00
|
|
|
: builtin-predicate ( type# symbol -- )
|
2005-01-16 17:58:28 -05:00
|
|
|
#! We call search here because we have to know if the symbol
|
|
|
|
#! is t or f, and cannot compare type numbers or symbol
|
|
|
|
#! identity during bootstrapping.
|
|
|
|
dup "f" [ "syntax" ] search = [
|
2005-03-05 14:45:23 -05:00
|
|
|
nip [ not ] "predicate" set-word-prop
|
2004-12-23 01:14:07 -05:00
|
|
|
] [
|
2005-01-16 17:58:28 -05:00
|
|
|
dup "t" [ "syntax" ] search = [
|
2005-03-05 14:45:23 -05:00
|
|
|
nip [ ] "predicate" set-word-prop
|
2004-12-23 18:26:04 -05:00
|
|
|
] [
|
|
|
|
dup predicate-word
|
|
|
|
[ rot [ swap type eq? ] cons define-compound ] keep
|
2005-03-05 14:45:23 -05:00
|
|
|
unit "predicate" set-word-prop
|
2004-12-23 18:26:04 -05:00
|
|
|
] ifte
|
2004-12-23 01:14:07 -05:00
|
|
|
] ifte ;
|
2004-12-13 00:13:54 -05:00
|
|
|
|
2005-02-20 19:03:37 -05:00
|
|
|
: builtin-class ( symbol type# slotspec -- )
|
2005-04-27 01:40:09 -04:00
|
|
|
>r 2dup builtins get set-nth r>
|
2005-02-20 19:03:37 -05:00
|
|
|
>r swap
|
2004-12-23 02:14:40 -05:00
|
|
|
dup intern-symbol
|
2004-12-13 00:13:54 -05:00
|
|
|
2dup builtin-predicate
|
2005-03-05 14:45:23 -05:00
|
|
|
[ swap "builtin-type" set-word-prop ] keep
|
2005-02-20 19:03:37 -05:00
|
|
|
dup builtin define-class r> define-slots ;
|
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 ;
|