forward/backward constructors instead of auto-constructors
parent
4d9af7317e
commit
74fbe979bb
|
@ -69,11 +69,18 @@ CONSTRUCTOR: inherit2 ( a -- obj ) ;
|
||||||
|
|
||||||
TUPLE: inherit3 hp max-hp ;
|
TUPLE: inherit3 hp max-hp ;
|
||||||
TUPLE: inherit4 < inherit3 ;
|
TUPLE: inherit4 < inherit3 ;
|
||||||
|
TUPLE: inherit5 < inherit3 ;
|
||||||
|
|
||||||
CONSTRUCTOR: inherit3 ( -- obj )
|
CONSTRUCTOR: inherit3 ( -- obj )
|
||||||
dup max-hp>> >>hp ;
|
dup max-hp>> >>hp ;
|
||||||
|
|
||||||
AUTO-CONSTRUCTOR: inherit4 ( -- obj )
|
BACKWARD-CONSTRUCTOR: inherit4 ( -- obj )
|
||||||
10 >>max-hp ;
|
10 >>max-hp ;
|
||||||
|
|
||||||
[ 10 ] [ <inherit4> hp>> ] unit-test
|
[ 10 ] [ <inherit4> hp>> ] unit-test
|
||||||
|
|
||||||
|
FORWARD-CONSTRUCTOR: inherit5 ( -- obj )
|
||||||
|
5 >>hp
|
||||||
|
10 >>max-hp ;
|
||||||
|
|
||||||
|
[ 5 ] [ <inherit5> hp>> ] unit-test
|
||||||
|
|
|
@ -48,9 +48,10 @@ MACRO:: slots>constructor ( class slots -- quot )
|
||||||
class lookup-initializer
|
class lookup-initializer
|
||||||
'[ @ _ execute( obj -- obj ) ] effect define-declared ;
|
'[ @ _ execute( obj -- obj ) ] effect define-declared ;
|
||||||
|
|
||||||
:: define-auto-constructor ( constructor-word class effect def -- )
|
:: define-auto-constructor ( constructor-word class effect def reverse? -- )
|
||||||
constructor-word class effect def (define-constructor)
|
constructor-word class effect def (define-constructor)
|
||||||
class superclasses [ lookup-initializer ] map sift reverse
|
class superclasses [ lookup-initializer ] map sift
|
||||||
|
reverse? [ reverse ] when
|
||||||
'[ @ _ [ execute( obj -- obj ) ] each ] effect define-declared ;
|
'[ @ _ [ execute( obj -- obj ) ] each ] effect define-declared ;
|
||||||
|
|
||||||
: scan-constructor ( -- class word )
|
: scan-constructor ( -- class word )
|
||||||
|
@ -60,7 +61,7 @@ MACRO:: slots>constructor ( class slots -- quot )
|
||||||
scan-constructor complete-effect parse-definition ;
|
scan-constructor complete-effect parse-definition ;
|
||||||
|
|
||||||
SYNTAX: CONSTRUCTOR: parse-constructor define-constructor ;
|
SYNTAX: CONSTRUCTOR: parse-constructor define-constructor ;
|
||||||
|
SYNTAX: FORWARD-CONSTRUCTOR: parse-constructor f define-auto-constructor ;
|
||||||
SYNTAX: AUTO-CONSTRUCTOR: parse-constructor define-auto-constructor ;
|
SYNTAX: BACKWARD-CONSTRUCTOR: parse-constructor t define-auto-constructor ;
|
||||||
|
|
||||||
"initializers" create-vocab drop
|
"initializers" create-vocab drop
|
||||||
|
|
Loading…
Reference in New Issue