Esempio n. 1
0
//## DIR System.opendir(String path)
static KMETHOD System_opendir(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI formatSystemPath(kctx, buffer, sizeof(buffer), S_text(path), S_size(path), trace);
	DIR *d = opendir(systemPath);
	if(d == NULL) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_guessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "opendir", LogText("dirname", S_text(path)), LogErrno);
		KLIB KonohaRuntime_raise(kctx, EXPT_("IO"), fault, NULL, sfp);
	}
	kDir *dir = (kDir *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)d);
	KFieldSet(dir, dir->PathInfoNULL, path);
	if(!PLATAPI isSystemCharsetUTF8(kctx)) {
		dir->readerIconv = PLATAPI iconvSystemCharsetToUTF8(kctx, trace);
	}
	KReturn(dir);
}
Esempio n. 2
0
//## Object Dynamic.(Object o);
static KMETHOD Dynamic_(KonohaContext *kctx, KonohaStack *sfp)
{
	kObject *obj = sfp[0].asObject;
	int argc = kctx->esp - sfp - 2;   // believe me
	ksymbol_t symbol = (ksymbol_t)(kctx->esp[-1].intValue);
//	kString  *symbolString = kctx->esp[-1].asString;
	kNameSpace *ns = sfp[K_NSIDX].asNameSpace;
	DBG_ASSERT(IS_NameSpace(ns));
	kMethod *mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, O_typeId(obj), symbol, argc);
	if(mtd != NULL) {
		if(kMethod_CheckMethodCallStack(kctx, sfp, mtd, argc)) {
			KonohaRuntime_setesp(kctx, kctx->esp - 1);
			sfp[K_MTDIDX].calledMethod = mtd;
			//kObject *returnValue = sfp[K_RTNIDX].asObject;
			KonohaRuntime_callMethod(kctx, sfp);
			return;
		}
	}
	KLIB KonohaRuntime_raise(kctx, EXPT_("NoSuchMethod"), SoftwareFault, NULL, sfp);
}
Esempio n. 3
0
static void THROW_ZeroDividedException(KonohaContext *kctx, KonohaStack *sfp)
{
	KLIB KonohaRuntime_raise(kctx, EXPT_("ZeroDivided"), SoftwareFault, NULL, sfp);
}