 ! (c)2010 Joe Groff bsd license
-USING: accessors definitions fry kernel locals.types namespaces parser
-see sequences words ;
+USING: accessors arrays combinators definitions fry kernel
+locals.types namespaces parser quotations see sequences slots
+words ;
+FROM: kernel.private => declare ;
 FROM: help.markup.private => link-effect? ;
 IN: variables
 

M: variable link-effect? drop f ;
M: variable print-stack-effect? drop f ;

TUPLE: global-box value ;

PREDICATE: global-variable < variable
    "variable-setter" word-prop def>> first global-box? ;

: [global-getter] ( box -- quot )
    '[ _ value>> ] ;


M: global-variable definer drop \ GLOBAL: f ;

INTERSECTION: typed-global-variable
    global-variable typed-variable ;

: define-typed-global ( word type -- )
    2dup "variable-type" set-word-prop
    dup initial-value global-box boa swap
    [ [ [global-getter] ] dip [typed-getter] ]
    [ [ [global-setter] ] dip [typed-setter] ] 2bi (define-variable) ;

SYNTAX: TYPED-GLOBAL:
    CREATE-WORD scan-object define-typed-global ;

M: typed-global-variable definer drop \ TYPED-GLOBAL: f ;

