Esempio n. 1
0
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);
}
Esempio n. 2
0
// @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);
}
Esempio n. 3
0
//## @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);
	}
}
Esempio n. 4
0
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);
	}
}
Esempio n. 5
0
static void kResultSet_format(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	kResultSet *rs = (kResultSet *) v[0].asObject;
	KLIB KBuffer_printf(kctx, wb, "{");
	size_t i;
	for(i = 0; i < (rs)->column_size; i++) {
		if(i > 0) {
			KLIB KBuffer_printf(kctx, wb, ",");
		}
		KLIB KBuffer_printf(kctx, wb, "(%d): ", i);
		ktypeattr_t type = rs->column[i].type;
		krbp_t *val = &rs->column[i].val;
		if(KType_Is(UnboxType, type)) {
			KonohaValue sp[1];
			KStackSetUnboxValue(sp[0].unboxValue, val[0].unboxValue);
			KClass_(type)->format(kctx, sp, 0, wb);
		} else {
			KLIB kObject_WriteToBuffer(kctx, val[0].asObject, false/*delim*/, wb, NULL, 0);
		}
	}
	KLIB KBuffer_printf(kctx, wb, "}");
}