call initializers in reverse order to allow base classes to set state after slots are set in a subclass

db4
Doug Coleman 2009-06-11 13:19:54 -05:00
parent 3cabf3aeca
commit 39047be85d
2 changed files with 13 additions and 1 deletions

View File

@ -65,3 +65,15 @@ TUPLE: inherit2 < inherit1 a ;
CONSTRUCTOR: inherit2 ( a -- obj ) ;
[ 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

View File

@ -50,7 +50,7 @@ MACRO:: slots>constructor ( class slots -- quot )
:: define-auto-constructor ( constructor-word class effect def -- )
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 ;
: scan-constructor ( -- class word )