Example #1
0
static int konoha_handler(request_rec *r)
{
	//konoha_config_t *conf = ap_get_module_config(
	//		r->server->module_config, &konoha_module);
	if(strcmp(r->handler, "konoha-script")) {
		return DECLINED;
	}
	// if(r->method_number != M_GET) {
	// 	 TODO 
	// 	return HTTP_METHOD_NOT_ALLOWED;
	// }
	KonohaClass *cRequest;
	verbose_debug = 1;
	KonohaContext* konoha = konoha_create(&cRequest);
	//assert(cRequest != NULL);
	r->content_encoding = "utf-8";
	ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "filename=%s", r->filename);
	if(Konoha_LoadScript(konoha, r->filename)) {
		return DECLINED;
	}

	KonohaContext *kctx = konoha;
	kNameSpace *ns = KNULL(NameSpace);
	kMethod *mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, TY_System, MN_("handler"), -1);  // fixme
	if(mtd == NULL) {
		ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "System.handler() not found");
		return -1;
	}

	/* XXX: We assume Request Object may not be freed by GC */
	kObject *req_obj = KLIB new_kObject(kctx, OnStack, cRequest, (uintptr_t)r);
	BEGIN_LOCAL(lsfp, K_CALLDELTA + 1);
	KUnsafeFieldSet(lsfp[K_CALLDELTA+0].asObject, K_NULL);
	KUnsafeFieldSet(lsfp[K_CALLDELTA+1].asObject, req_obj);
	{
		KonohaStack *sfp = lsfp + K_CALLDELTA;
		KSetMethodCallStack(sfp, 0/*UL*/, mtd, 1, KLIB Knull(kctx, CT_Int));
		KonohaRuntime_callMethod(kctx, sfp);
	}
	END_LOCAL();
	int ret = lsfp[0].intValue;
	Konoha_Destroy(konoha);
	return ret;
}
Example #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);
}