factor/library/generic/builtin.factor

49 lines
1.4 KiB
Factor
Raw Normal View History

2005-02-18 20:37:01 -05:00
! Copyright (C) 2004, 2005 Slava Pestov.
! See http://factor.sf.net/license.txt for BSD license.
IN: generic
2005-02-18 20:37:01 -05:00
USING: errors hashtables kernel lists namespaces parser strings
words vectors ;
! Builtin metaclass for builtin types: fixnum, word, cons, etc.
SYMBOL: builtin
builtin [
"builtin-type" word-property unit
] "builtin-supertypes" set-word-property
builtin [
( generic vtable definition class -- )
rot set-vtable drop
] "add-method" set-word-property
builtin 50 "priority" set-word-property
2004-12-29 18:01:23 -05:00
! All builtin types are equivalent in ordering
builtin [ 2drop t ] "class<" set-word-property
2004-12-20 15:29:55 -05:00
: builtin-predicate ( type# symbol -- )
#! 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 = [
2004-12-23 01:14:07 -05:00
nip [ not ] "predicate" set-word-property
] [
dup "t" [ "syntax" ] search = [
2004-12-23 18:26:04 -05:00
nip [ ] "predicate" set-word-property
] [
dup predicate-word
[ rot [ swap type eq? ] cons define-compound ] keep
unit "predicate" set-word-property
] ifte
2004-12-23 01:14:07 -05:00
] ifte ;
: builtin-class ( symbol type# slotspec -- )
>r swap
dup intern-symbol
2dup builtin-predicate
[ swap "builtin-type" set-word-property ] keep
dup builtin define-class r> define-slots ;
2004-12-20 15:29:55 -05:00
: builtin-type ( n -- symbol )
unit classes get hash ;