// @SmartReturn void Object.set(Symbol symbol, Object value) static KMETHOD Prototype_SetObject(KonohaContext *kctx, KonohaStack *sfp) { ksymbol_t symbol = (ksymbol_t)sfp[1].intValue; KClass *c = kObject_class(sfp[2].asObject); if(KClass_Is(UnboxType, c)) { KLIB kObjectProto_SetUnboxValue(kctx, sfp[0].asObject, symbol, c->typeId, kObject_Unbox(sfp[2].asObject)); } else { KLIB kObjectProto_SetObject(kctx, sfp[0].asObject, symbol, c->typeId, sfp[2].asObject); } }
static void kNameSpace_LookupMethodWithInlineCache(KonohaContext *kctx, KonohaStack *sfp, kNameSpace *ns, kMethod **cache) { ktypeattr_t typeId = kObject_typeId(sfp[0].asObject); kMethod *mtd = cache[0]; if(mtd->typeId != typeId) { KClass *ct = kObject_class(sfp[0].asObject); mtd = KLIB kNameSpace_GetMethodBySignatureNULL(kctx, ns, ct, mtd->mn, mtd->paramdom, 0, NULL); cache[0] = mtd; } KStackSetUnboxValue(sfp[0].unboxValue, kObject_Unbox(sfp[0].asObject)); KStackSetUnboxValue(sfp[K_MTDIDX].calledMethod, mtd); }
// @SmartReturn Object Object.as(Object target) static KMETHOD Object_as(KonohaContext *kctx, KonohaStack *sfp) { KClass *selfClass = kObject_class(sfp[0].asObject), *targetClass = KGetReturnType(sfp); kObject *returnValue; if(selfClass == targetClass || selfClass->isSubType(kctx, selfClass, targetClass)) { returnValue = sfp[0].asObject; } else { returnValue = KLIB Knull(kctx, targetClass); } KStackSetUnboxValue(sfp[K_RTNIDX].unboxValue, kObject_Unbox(returnValue)); KReturn(returnValue); }
//## @SmartReturn Object ResultSet.get(String n); static KMETHOD ResultSet_get(KonohaContext *kctx, KonohaStack *sfp) { KClass *retClass = KGetReturnType(sfp); if(retClass->typeId == KType_Int) { ResultSet_getInt(kctx, sfp); } else if(retClass->typeId == KType_String) { ResultSet_getString(kctx, sfp); } else if(KDefinedKonohaCommonModule() && retClass->typeId == KType_float) { ResultSet_getFloat(kctx, sfp); } else { kObject *returnValue = KLIB Knull(kctx, retClass); KStackSetUnboxValue(sfp[K_RTNIDX].unboxValue, kObject_Unbox(returnValue)); KReturn(returnValue); } }
static void KStackDynamicTypeCheck(KonohaContext *kctx, KonohaStack *sfp, kMethod *mtd, KClass *thisClass) { kushort_t i; kParam *pa = kMethod_GetParam(mtd); for(i = 0; i < pa->psize; i++) { KClass *objectType = kObject_class(sfp[i+1].asObject); KClass *paramType = KClass_(pa->paramtypeItems[i].attrTypeId); paramType = paramType->realtype(kctx, paramType, thisClass); if(objectType == paramType || objectType->isSubType(kctx, objectType, paramType)) { if(KClass_Is(UnboxType, paramType)) { KStackSetUnboxValue(sfp[i+1].unboxValue, kObject_Unbox(sfp[i+1].asObject)); } continue; // OK } ThrowTypeError(kctx, sfp, i + 1); } }