added DISPOSABLE-CENTRAL: to extra/central
parent
16ba9fbd80
commit
56cb3c6f59
|
@ -1,4 +1,4 @@
|
||||||
USING: central help.markup help.syntax ;
|
USING: central destructors help.markup help.syntax ;
|
||||||
|
|
||||||
HELP: CENTRAL:
|
HELP: CENTRAL:
|
||||||
{ $description
|
{ $description
|
||||||
|
@ -8,3 +8,9 @@ HELP: CENTRAL:
|
||||||
"stack manipulation and full-out locals, meant to solve the case where "
|
"stack manipulation and full-out locals, meant to solve the case where "
|
||||||
"one object is operated on by several related words."
|
"one object is operated on by several related words."
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
HELP: DISPOSABLE-CENTRAL:
|
||||||
|
{ $description
|
||||||
|
"Like " { $link POSTPONE: CENTRAL: } ", but generates " { $snippet "with-" }
|
||||||
|
" words that are wrapped in a " { $link with-disposal } "."
|
||||||
|
} ;
|
|
@ -1,7 +1,19 @@
|
||||||
USING: central tools.test ;
|
USING: accessors central destructors kernel math tools.test ;
|
||||||
|
|
||||||
IN: scratchpad
|
IN: scratchpad
|
||||||
|
|
||||||
CENTRAL: test-central
|
CENTRAL: test-central
|
||||||
|
|
||||||
[ 3 ] [ 3 [ test-central ] with-test-central ] unit-test
|
[ 3 ] [ 3 [ test-central ] with-test-central ] unit-test
|
||||||
|
|
||||||
|
TUPLE: test-disp-cent value disposed ;
|
||||||
|
|
||||||
|
! A phony destructor that adds 1 to the value so we can make sure it got called.
|
||||||
|
M: test-disp-cent dispose* dup value>> 1+ >>value drop ;
|
||||||
|
|
||||||
|
DISPOSABLE-CENTRAL: t-d-c
|
||||||
|
|
||||||
|
: test-t-d-c ( -- n )
|
||||||
|
test-disp-cent new 3 >>value [ t-d-c ] with-t-d-c value>> ;
|
||||||
|
|
||||||
|
[ 4 ] [ test-t-d-c ] unit-test
|
|
@ -1,16 +1,28 @@
|
||||||
USING: kernel lexer namespaces parser sequences words ;
|
USING: destructors kernel lexer namespaces parser sequences words ;
|
||||||
|
|
||||||
IN: central
|
IN: central
|
||||||
|
|
||||||
: define-central-getter ( word -- )
|
: define-central-getter ( word -- )
|
||||||
dup [ get ] curry (( -- obj )) define-declared ;
|
dup [ get ] curry (( -- obj )) define-declared ;
|
||||||
|
|
||||||
: define-central-setter ( word with-word -- )
|
: define-centrals ( str -- getter setter )
|
||||||
[ with-variable ] with (( object quot -- )) define-declared ;
|
[ create-in dup define-central-getter ]
|
||||||
|
[ "with-" prepend create-in dup make-inline ] bi ;
|
||||||
|
|
||||||
|
: central-setter-def ( word with-word -- with-word quot )
|
||||||
|
[ with-variable ] with ;
|
||||||
|
|
||||||
|
: disposable-setter-def ( word with-word -- with-word quot )
|
||||||
|
[ pick [ drop with-variable ] with-disposal ] with ;
|
||||||
|
|
||||||
|
: declare-central ( with-word quot -- ) (( object quot -- )) define-declared ;
|
||||||
|
|
||||||
: define-central ( word-name -- )
|
: define-central ( word-name -- )
|
||||||
[ create-in dup define-central-getter ] keep
|
define-centrals central-setter-def declare-central ;
|
||||||
"with-" prepend create-in [ define-central-setter ] keep
|
|
||||||
make-inline ;
|
: define-disposable-central ( word-name -- )
|
||||||
|
define-centrals disposable-setter-def declare-central ;
|
||||||
|
|
||||||
SYNTAX: CENTRAL: ( -- ) scan define-central ;
|
SYNTAX: CENTRAL: ( -- ) scan define-central ;
|
||||||
|
|
||||||
|
SYNTAX: DISPOSABLE-CENTRAL: ( -- ) scan define-disposable-central ;
|
Loading…
Reference in New Issue