added moo_iskindof().
changed isKindOf: to utilize a new primitive _is_kind_of. marked BlockContext and MethodContext to be #final and #limited
This commit is contained in:
@ -2098,6 +2098,27 @@ static moo_pfrc_t pf_hash (moo_t* moo, moo_ooi_t nargs)
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_is_kind_of (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t rcv, _class;
|
||||
|
||||
rcv = MOO_STACK_GETRCV(moo, nargs);
|
||||
_class = MOO_STACK_GETARG(moo, nargs, 0);
|
||||
|
||||
MOO_PF_CHECK_ARGS (moo, nargs, MOO_CLASSOF(moo, _class) == moo->_class);
|
||||
|
||||
if (moo_iskindof(moo, rcv, (moo_oop_class_t)_class))
|
||||
{
|
||||
MOO_STACK_SETRET (moo, nargs, moo->_true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MOO_STACK_SETRET (moo, nargs, moo->_false);
|
||||
}
|
||||
|
||||
return MOO_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static moo_pfrc_t pf_responds_to (moo_t* moo, moo_ooi_t nargs)
|
||||
{
|
||||
moo_oop_t rcv, selector;
|
||||
@ -4135,6 +4156,7 @@ static pf_t pftab[] =
|
||||
|
||||
{ "_hash", { pf_hash, 0, 0 } },
|
||||
|
||||
{ "_is_kind_of", { pf_is_kind_of, 1, 1, } },
|
||||
{ "_responds_to", { pf_responds_to, 1, 1 } },
|
||||
{ "_perform", { pf_perform, 1, MA } },
|
||||
|
||||
|
@ -224,7 +224,7 @@ static kernel_class_info_t kernel_classes[] =
|
||||
|
||||
{ 13,
|
||||
{ 'M','e','t','h','o','d','C','o','n','t','e','x','t' },
|
||||
0,
|
||||
MOO_CLASS_SELFSPEC_FLAG_FINAL | MOO_CLASS_SELFSPEC_FLAG_LIMITED,
|
||||
MOO_CONTEXT_NAMED_INSTVARS,
|
||||
MOO_CLASS_SPEC_FLAG_INDEXED,
|
||||
MOO_OBJ_TYPE_OOP,
|
||||
@ -232,7 +232,7 @@ static kernel_class_info_t kernel_classes[] =
|
||||
|
||||
{ 12,
|
||||
{ 'B','l','o','c','k','C','o','n','t','e','x','t' },
|
||||
0,
|
||||
MOO_CLASS_SELFSPEC_FLAG_FINAL | MOO_CLASS_SELFSPEC_FLAG_LIMITED,
|
||||
MOO_CONTEXT_NAMED_INSTVARS,
|
||||
MOO_CLASS_SPEC_FLAG_INDEXED,
|
||||
MOO_OBJ_TYPE_OOP,
|
||||
|
@ -973,3 +973,27 @@ moo_oop_t moo_findclass (moo_t* moo, moo_oop_nsdic_t nsdic, const moo_ooch_t* na
|
||||
|
||||
return ass->value;
|
||||
}
|
||||
|
||||
int moo_iskindof (moo_t* moo, moo_oop_t obj, moo_oop_class_t _class)
|
||||
{
|
||||
moo_oop_class_t c;
|
||||
|
||||
c = MOO_CLASSOF(moo,obj); /* c := self class */
|
||||
if (c == moo->_class)
|
||||
{
|
||||
/* object is a class */
|
||||
if (_class == moo->_class) return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c == _class) return 1;
|
||||
}
|
||||
|
||||
c = (moo_oop_class_t)c->superclass;
|
||||
while ((moo_oop_t)c != moo->_nil)
|
||||
{
|
||||
if (c == _class) return 1;
|
||||
c = (moo_oop_class_t)c->superclass;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1729,6 +1729,12 @@ MOO_EXPORT moo_oop_t moo_findclass (
|
||||
const moo_ooch_t* name
|
||||
);
|
||||
|
||||
MOO_EXPORT int moo_iskindof (
|
||||
moo_t* moo,
|
||||
moo_oop_t obj,
|
||||
moo_oop_class_t _class
|
||||
);
|
||||
|
||||
/* =========================================================================
|
||||
* TRAILER MANAGEMENT
|
||||
* ========================================================================= */
|
||||
|
Reference in New Issue
Block a user