2005-01-29 14:18:28 -05:00
|
|
|
! Copyright (C) 2004, 2005 Slava Pestov.
|
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
2004-07-16 02:26:21 -04:00
|
|
|
IN: words
|
2005-01-29 14:18:28 -05:00
|
|
|
USING: generic hashtables kernel kernel-internals lists math
|
|
|
|
|
namespaces strings ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2005-01-14 19:51:38 -05:00
|
|
|
BUILTIN: word 17
|
2005-02-20 19:03:37 -05:00
|
|
|
[ 1 hashcode f ]
|
2005-03-05 14:45:23 -05:00
|
|
|
[ 4 "word-def" "set-word-def" ]
|
2005-02-20 19:03:37 -05:00
|
|
|
[ 5 "word-props" "set-word-props" ] ;
|
|
|
|
|
|
|
|
|
|
GENERIC: word-xt
|
|
|
|
|
M: word word-xt ( w -- xt ) 2 integer-slot ;
|
|
|
|
|
GENERIC: set-word-xt
|
|
|
|
|
M: word set-word-xt ( xt w -- ) 2 set-integer-slot ;
|
|
|
|
|
|
|
|
|
|
GENERIC: word-primitive
|
|
|
|
|
M: word word-primitive ( w -- n ) 3 integer-slot ;
|
|
|
|
|
GENERIC: set-word-primitive
|
|
|
|
|
M: word set-word-primitive ( n w -- )
|
|
|
|
|
[ 3 set-integer-slot ] keep update-xt ;
|
|
|
|
|
|
|
|
|
|
GENERIC: call-count
|
|
|
|
|
M: word call-count ( w -- n ) 6 integer-slot ;
|
|
|
|
|
GENERIC: set-call-count
|
|
|
|
|
M: word set-call-count ( n w -- ) 6 set-integer-slot ;
|
|
|
|
|
|
|
|
|
|
GENERIC: allot-count
|
|
|
|
|
M: word allot-count ( w -- n ) 7 integer-slot ;
|
|
|
|
|
GENERIC: set-allot-count
|
|
|
|
|
M: word set-allot-count ( n w -- ) 7 set-integer-slot ;
|
2004-12-18 23:18:32 -05:00
|
|
|
|
2004-12-15 16:57:29 -05:00
|
|
|
SYMBOL: vocabularies
|
|
|
|
|
|
2005-03-05 14:45:23 -05:00
|
|
|
: word-prop ( word name -- value ) swap word-props hash ;
|
|
|
|
|
: set-word-prop ( word value name -- ) rot word-props set-hash ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2004-12-12 23:49:44 -05:00
|
|
|
PREDICATE: word compound ( obj -- ? ) word-primitive 1 = ;
|
|
|
|
|
PREDICATE: word primitive ( obj -- ? ) word-primitive 2 > ;
|
|
|
|
|
PREDICATE: word symbol ( obj -- ? ) word-primitive 2 = ;
|
|
|
|
|
PREDICATE: word undefined ( obj -- ? ) word-primitive 0 = ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2004-12-15 16:57:29 -05:00
|
|
|
: define ( word primitive parameter -- )
|
2005-03-05 14:45:23 -05:00
|
|
|
pick set-word-def
|
2004-11-28 19:07:24 -05:00
|
|
|
over set-word-primitive
|
2005-03-05 14:45:23 -05:00
|
|
|
f "parsing" set-word-prop ;
|
|
|
|
|
|
|
|
|
|
: (define-compound) ( word def -- ) 1 swap define ;
|
2004-11-25 21:51:47 -05:00
|
|
|
|
2005-03-05 14:45:23 -05:00
|
|
|
: define-compound ( word def -- )
|
|
|
|
|
#! If the word is a generic word, clear the properties
|
|
|
|
|
#! involved so that 'see' can work properly.
|
|
|
|
|
over f "definer" set-word-prop
|
|
|
|
|
over f "methods" set-word-prop
|
|
|
|
|
over f "combination" set-word-prop
|
|
|
|
|
(define-compound) ;
|
|
|
|
|
|
|
|
|
|
: define-symbol ( word -- ) 2 over define ;
|
2004-07-16 02:26:21 -04:00
|
|
|
|
2004-12-23 02:14:40 -05:00
|
|
|
: intern-symbol ( word -- )
|
|
|
|
|
dup undefined? [ define-symbol ] [ drop ] ifte ;
|
|
|
|
|
|
2005-03-05 14:45:23 -05:00
|
|
|
: word-name ( word -- str ) "name" word-prop ;
|
|
|
|
|
: word-vocabulary ( word -- str ) "vocabulary" word-prop ;
|