diff --git a/moo/kernel/Apex.moo b/moo/kernel/Apex.moo index 6dec859..8476fe8 100644 --- a/moo/kernel/Apex.moo +++ b/moo/kernel/Apex.moo @@ -239,7 +239,7 @@ extend Apex method(#class) isKindOf: aClass { - ^(self isMemberOf: aClass) or: [self inheritsFrom: aClass]. + ^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass]. } method isMemberOf: aClass diff --git a/moo/kernel/test-003.moo b/moo/kernel/test-003.moo index 435dfc2..2fe42fa 100644 --- a/moo/kernel/test-003.moo +++ b/moo/kernel/test-003.moo @@ -54,7 +54,7 @@ class MyObject(TestObject) method(#class) main { | tc limit | -(10 isKindOf: 20) dump. + tc := %( ## 0 - 4 [(Object isKindOf: Class) == true], @@ -65,12 +65,20 @@ class MyObject(TestObject) ## 5-9 [(Apex isKindOf: Class) == true], + [(Apex isKindOf: Apex) == true], [(SmallInteger isKindOf: Integer) == false], [(10 isKindOf: Integer) == true], [(10 isKindOf: 20) == false], - [(Apex isMemberOf: Class) == true], - [(Class isMemberOf: Class) == true] + ## 10-14 + [([] isKindOf: BlockContext) == true], + [([] isKindOf: MethodContext) == false], + [([] isKindOf: Context) == true], + [('string' isKindOf: String) == true], + [(#symbol isKindOf: String) == true], + + [('string' isKindOf: Symbol) == false], + [(#symbol isKindOf: Symbol) == true] ). limit := tc size. diff --git a/moo/lib/exec.c b/moo/lib/exec.c index 37c8a17..f1ab703 100644 --- a/moo/lib/exec.c +++ b/moo/lib/exec.c @@ -33,10 +33,18 @@ #define PROC_STATE_TERMINATED -1 +/* receiver check failure leads to hard failure. + * RATIONAL: the primitive handler should be used by relevant classes and + * objects only. if the receiver check fails, you must review + * your class library */ #define MOO_PF_CHECK_RCV(moo,cond) do { \ if (!(cond)) { moo_seterrnum((moo), MOO_EMSGRCV); return MOO_PF_HARD_FAILURE; } \ } while(0) +/* argument check failure causes the wrapping method to return an error. + * RATIONAL: Being a typeless language, it's hard to control the kinds of + * arguments. + */ #define MOO_PF_CHECK_ARGS(moo,nargs,cond) do { \ if (!(cond)) { MOO_STACK_SETRETTOERROR ((moo), (nargs), MOO_EINVAL); return MOO_PF_SUCCESS; } \ } while(0) @@ -2484,7 +2492,7 @@ static moo_pfrc_t pf_semaphore_signal (moo_t* moo, moo_ooi_t nargs) moo_oop_t rcv; rcv = MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo,rcv) == moo->_semaphore); /* TODO: use moo_iskindof(moo,rcv,moo->_semaphore); */ + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore)); /* signal_semaphore() may change the active process though the * implementation as of this writing makes runnable the process waiting @@ -2502,7 +2510,7 @@ static moo_pfrc_t pf_semaphore_wait (moo_t* moo, moo_ooi_t nargs) moo_oop_t rcv; rcv = MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo,rcv) == moo->_semaphore); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore)); /* i must set the return value before calling await_semaphore(). * await_semaphore() may switch the active process and the stack @@ -2529,7 +2537,7 @@ static moo_pfrc_t pf_semaphore_group_wait (moo_t* moo, moo_ooi_t nargs) moo_oop_t rcv, sem; rcv = MOO_STACK_GETRCV(moo, nargs); - MOO_PF_CHECK_RCV (moo, MOO_CLASSOF(moo,rcv) == moo->_semaphore_group); + MOO_PF_CHECK_RCV (moo, moo_iskindof(moo, rcv, moo->_semaphore_group)); /* i must set the return value before calling await_semaphore_group(). * MOO_STACK_SETRETTORCV() manipulates the stack of the currently active diff --git a/moo/lib/moo.c b/moo/lib/moo.c index aefcdc4..55da5a9 100644 --- a/moo/lib/moo.c +++ b/moo/lib/moo.c @@ -984,7 +984,7 @@ int moo_iskindof (moo_t* moo, moo_oop_t obj, moo_oop_class_t _class) if (c == moo->_class) { /* object is a class */ - if (_class == moo->_class) return 1; + if (_class == moo->_class) return 1; /* obj isKindOf: Class */ } else {