call initializers in reverse order to allow base classes to set state after slots are set in a subclass
parent
3cabf3aeca
commit
39047be85d
|
@ -65,3 +65,15 @@ TUPLE: inherit2 < inherit1 a ;
|
||||||
CONSTRUCTOR: inherit2 ( a -- obj ) ;
|
CONSTRUCTOR: inherit2 ( a -- obj ) ;
|
||||||
|
|
||||||
[ T{ inherit2 f f 100 } ] [ 100 <inherit2> ] unit-test
|
[ T{ inherit2 f f 100 } ] [ 100 <inherit2> ] unit-test
|
||||||
|
|
||||||
|
|
||||||
|
TUPLE: inherit3 hp max-hp ;
|
||||||
|
TUPLE: inherit4 < inherit3 ;
|
||||||
|
|
||||||
|
CONSTRUCTOR: inherit3 ( -- obj )
|
||||||
|
dup max-hp>> >>hp ;
|
||||||
|
|
||||||
|
AUTO-CONSTRUCTOR: inherit4 ( -- obj )
|
||||||
|
10 >>max-hp ;
|
||||||
|
|
||||||
|
[ 10 ] [ <inherit4> hp>> ] unit-test
|
||||||
|
|
|
@ -50,7 +50,7 @@ MACRO:: slots>constructor ( class slots -- quot )
|
||||||
|
|
||||||
:: define-auto-constructor ( constructor-word class effect def -- )
|
:: define-auto-constructor ( constructor-word class effect def -- )
|
||||||
constructor-word class effect def (define-constructor)
|
constructor-word class effect def (define-constructor)
|
||||||
class superclasses [ lookup-initializer ] map sift
|
class superclasses [ lookup-initializer ] map sift reverse
|
||||||
'[ @ _ [ execute( obj -- obj ) ] each ] effect define-declared ;
|
'[ @ _ [ execute( obj -- obj ) ] each ] effect define-declared ;
|
||||||
|
|
||||||
: scan-constructor ( -- class word )
|
: scan-constructor ( -- class word )
|
||||||
|
|
Loading…
Reference in New Issue