1 ! (c)2010 Joe Groff bsd license
2 USING: accessors definitions fry kernel locals.types namespaces parser
4 FROM: help.markup.private => link-effect? ;
7 PREDICATE: variable < word
8 "variable-setter" word-prop ;
10 GENERIC: variable-setter ( word -- word' )
12 M: variable variable-setter "variable-setter" word-prop ;
13 M: local-reader variable-setter "local-writer" word-prop ;
16 scan-object variable-setter suffix! ;
18 : [variable-getter] ( variable -- quot )
20 : [variable-setter] ( variable -- quot )
23 : (define-variable) ( word getter setter -- )
24 [ (( -- value )) define-inline ]
27 [ name>> "set: " prepend <uninterned-word> ]
28 [ over "variable-setter" set-word-prop ] bi
29 ] dip (( value -- )) define-inline
32 : define-variable ( word -- )
33 dup [ [variable-getter] ] [ [variable-setter] ] bi (define-variable) ;
36 CREATE-WORD define-variable ;
38 M: variable definer drop \ VAR: f ;
39 M: variable definition drop f ;
40 M: variable link-effect? drop f ;
41 M: variable print-stack-effect? drop f ;
43 TUPLE: global-box value ;
45 PREDICATE: global-variable < variable
46 "variable-setter" word-prop def>> first global-box? ;
48 : [global-getter] ( box -- quot )
50 : [global-setter] ( box -- quot )
53 : define-global ( word -- )
54 global-box new [ [global-getter] ] [ [global-setter] ] bi (define-variable) ;
57 CREATE-WORD define-global ;
59 M: global-variable definer drop \ GLOBAL: f ;