fixed an issue in isKindOf:

This commit is contained in:
hyunghwan.chung 2017-09-30 04:49:54 +00:00
parent a240b0be7d
commit cb2b93d01c
4 changed files with 24 additions and 8 deletions

View File

@ -239,7 +239,7 @@ extend Apex
method(#class) isKindOf: aClass
{
<primitive: #_is_kind_of>
^(self isMemberOf: aClass) or: [self inheritsFrom: aClass].
^(self isMemberOf: aClass) or: [self class inheritsFrom: aClass].
}
method isMemberOf: aClass

View File

@ -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.

View File

@ -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

View File

@ -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
{