Exemplo n.º 1
0
static kBasicBlock* new_BasicBlockLABEL(KonohaContext *kctx)
{
	kBasicBlock *bb = new_(BasicBlock, 0);
	bb->id = kArray_size(ctxcode->codeList);
	KLIB kArray_add(kctx, ctxcode->codeList, bb);
	return bb;
}
Exemplo n.º 2
0
kcontext_t *new_ThreadContext(CTX)
{
	KNH_SYSLOCK(_ctx);
	kcontext_t *newCtx = new_hcontext(_ctx);
	newCtx->share = ctx->share;
	newCtx->stat = ctx->stat;
	newCtx->spi = ctx->spi;
	newCtx->script = ctx->script;
	newCtx->parent = WCTX(_ctx);
//	newCtx->freeObjectList = NULL;
//	newCtx->freeObjectTail = NULL;
	KINITv(newCtx->gma, new_(GammaBuilder));
	knh_GammaBuilder_init(newCtx);
	CommonContext_init(_ctx, newCtx);
	knh_stack_initexpand(newCtx, NULL, K_STACKSIZE);

	ctx->wshare->contextCounter++;
	ctx->wshare->threadCounter++;
	if(newCtx->ctxobjNC == NULL) {
		newCtx->ctxobjNC = knh_toContext(newCtx);
	}
	kArray_add(ctx->share->contextListNULL, newCtx->ctxobjNC);
	newCtx->safepoint = ctx->share->ctx0->safepoint;
	KNH_SYS_UNLOCK(_ctx);
	return newCtx;
}
Exemplo n.º 3
0
static void copyMethodList(CTX, kcid_t cid, kArray *s, kArray *d)
{
	size_t i;
	for(i = 0; i < kArray_size(s); i++) {
		kMethod *mtd = s->methods[i];
		if(mtd->cid != cid) continue;
		kArray_add(d, mtd);
	}
}
Exemplo n.º 4
0
ksymbol_t knh_addname(CTX, kString *s, knh_Fdictset f)
{
	size_t n = knh_Map_size(_ctx->share->symbolDictCaseSet);
	if(unlikely(!(n+1 < MN_SETTER))) {  /* Integer overflowed */
		KNH_DIE("too many names, last nameid(fn)=%d < %d", (int)(n+1), (int)MN_SETTER);
	}
	kArray_add(ctx->share->symbolList, s);
	f(_ctx, ctx->share->symbolDictCaseSet, s, n + 1);
	return (ksymbol_t)(n);
}
Exemplo n.º 5
0
//## String[] Json.getKeys();
static KMETHOD Json_getKeys(KonohaContext *kctx, KonohaStack *sfp)
{
	json_t* obj = ((struct _kJson *)sfp[0].asObject)->obj;
	kArray *a = (kArray *)KLIB new_kObjectDontUseThis(kctx, CT_StringArray0, 0);
	CHECK_JSON(obj, KReturn(KNULL(Array)));
	const char* key;
	void* iter = json_object_iter(obj);
	while(iter) {
		key = json_object_iter_key(iter);
		iter = json_object_iter_next(obj, iter);
		KLIB kArray_add(kctx, a, KLIB new_kString(kctx, key, strlen(key), StringPolicy_POOL|StringPolicy_ASCII));
	}
	KReturn(a);
}
Exemplo n.º 6
0
static void konoha_commandline(CTX, int argc, char** argv)
{
	kclass_t *CT_StringArray0 = CT_p0(_ctx, CT_Array, TY_String);
	kArray *a = (kArray*)new_kObject(CT_StringArray0, NULL);
	int i;
	for(i = 0; i < argc; i++) {
		DBG_P("argv=%d, '%s'", i, argv[i]);
		kArray_add(a, new_kString(argv[i], strlen(argv[i]), SPOL_TEXT));
	}
	KDEFINE_OBJECT_CONST ConstData[] = {
			{"SCRIPT_ARGV", CT_StringArray0->cid, (kObject*)a},
			{}
	};
	kNameSpace_loadConstData(KNULL(NameSpace), ConstData, 0);
}
Exemplo n.º 7
0
kfileid_t knh_getURI(CTX, kbytes_t t)
{
	OLD_LOCK(_ctx, LOCK_SYSTBL, NULL);
	kindex_t idx = knh_DictSet_index(_ctx->share->urnDictSet, t);
	if(idx == -1) {
		kString *s = new_kString(t.text, t.len, SPOL_POOL);
		idx = kArray_size(_ctx->share->urns);
		knh_DictSet_set(_ctx, ctx->share->urnDictSet, s, idx);
		kArray_add(ctx->share->urns, s);
		KNH_NTRACE2(_ctx, "konoha:newfileid", K_OK, KNH_LDATA(LOG_s("urn", S_text(s)), LOG_i("fileid", idx)));
	}
	else {
		idx = knh_DictSet_valueAt(_ctx->share->urnDictSet, idx);
	}
	OLD_UNLOCK(_ctx, LOCK_SYSTBL, NULL);
	return (kfileid_t)idx;
}
Exemplo n.º 8
0
static void kException_addStackTrace(KonohaContext *kctx, KonohaStack *sfp, kException *e)
{
	kMethod *mtd = sfp[K_MTDIDX].mtdNC;
	KUtilsWriteBuffer wb;
	KLIB Kwb_init(&kctx->stack->cwb, &wb);
	kfileline_t uline = sfp[K_RTNIDX].uline;
	if(uline > 0) {
		const char *file = FileId_t(uline);
		KLIB Kwb_printf(kctx, &wb, "(%s:%d) %s.%s%s" , PLATAPI shortFilePath(file), (kushort_t)uline, Method_t(mtd));
	}
//	int i = 0, psize = Method_paramsize(mtd);
//	kParam *pa = Method_param(mtd);
//	KonohaClass *thisClass = O_cid(sfp[0]);
//	for(i = 0; i < psize; i++) {
//		pa->paramtypeItems[0].ty;
//		if(i > 0) {
//			knh_putc(ctx, cwb->w, ',');
//		}
//		knh_write_fn(ctx, cwb->w, p->fn);
//		knh_putc(ctx, cwb->w, '=');
//		knh_write_sfp(ctx, cwb->w, type, &sfp[i+1], FMT_line);
//	}
	const char *msg = KLIB Kwb_top(kctx, &wb, 1);
	KLIB kArray_add(kctx, e->stackTraceList, KLIB new_kString(kctx, msg, strlen(msg), 0));
//	if((mtd)->mn != MN_LAMBDA) {
//		knh_uline_t uline = knh_stack_uline(ctx, sfp);
//		knh_write_uline(ctx, cwb->w, uline);
//		knh_write_type(ctx, cwb->w, (mtd)->cid);
//		knh_putc(ctx, cwb->w, '.');
//		knh_write_mn(ctx, cwb->w, (mtd)->mn);
//		knh_putc(ctx, cwb->w, '(');
//		knh_putc(ctx, cwb->w, ')');
//		if(DP(e)->tracesNULL == NULL) {
//			KNH_INITv(DP(e)->tracesNULL, new_Array(ctx, CLASS_String, 0));
//		}
//		knh_Array_add(ctx, DP(e)->tracesNULL, knh_cwb_newString(ctx, cwb));
//	}
}
Exemplo n.º 9
0
static kcontext_t* new_RootContext(void)
{
	kcontext_t *ctx = (kcontext_t*)new_hcontext(NULL);
	const knh_LoaderAPI_t *kapi = knh_getLoaderAPI();
	kshare_t *share = (kshare_t*)malloc(sizeof(kshare_t) + sizeof(kstatinfo_t) + sizeof(knh_ServiceSPI_t));
	ctx->share = share;
	knh_bzero(share, sizeof(kshare_t) + sizeof(kstatinfo_t) + sizeof(knh_ServiceSPI_t));
	share->syslock = knh_mutex_malloc(_ctx);
	ctx->stat = (kstatinfo_t*)((share+1));
	ctx->spi = (const knh_ServiceSPI_t*)(_ctx->stat + 1);
	initServiceSPI((knh_ServiceSPI_t*)ctx->spi);

	kmemshare_init(_ctx);
	share->ClassTBL = (kclass_t**)KMALLOC((CTX)ctx, sizeof(struct _kclass*)*(K_CLASSTABLE_INIT));
	knh_bzero(share->ClassTBL, sizeof(struct _kclass*)*(K_CLASSTABLE_INIT));
	share->sizeClassTBL = 0;
	share->capacityClassTBL  = K_CLASSTABLE_INIT;

	share->EventTBL = (knh_EventTBL_t*)KCALLOC(SIZEOF_TEXPT(K_EVENTTBL_INIT));
	knh_bzero((void*)share->EventTBL, SIZEOF_TEXPT(K_EVENTTBL_INIT));
	share->sizeEventTBL = 0;
	share->capacityEventTBL  = K_EVENTTBL_INIT;
	kshare_loadStructData(_ctx, kapi);

	KINITv(share->funcDictSet, new_DictSet0(_ctx, 0, 0, "funcDictSet"));
	KINITv(share->constPtrMap, new_PtrMap(_ctx, 0));
	KINITv(share->inferPtrMap, new_PtrMap(_ctx, 0));
	KINITv(share->xdataPtrMap, new_PtrMap(_ctx, 0));
	KINITv(share->constPools, new_Array0(_ctx, 0));
	knh_loadSystemTypeMapRule(_ctx);
	knh_ClassTBL_setConstPool(_ctx, ClassTBL(CLASS_Int));
	knh_ClassTBL_setConstPool(_ctx, ClassTBL(CLASS_Float));
#ifdef K_USING_STRINGPOOL
	knh_ClassTBL_setConstPool(_ctx, ClassTBL(CLASS_String));
#endif
	{
		kObject *p = (kObject*)new_hObject_(_ctx, ClassTBL(CLASS_Object));
		Object_setNullObject(p, 1);
		KINITv(share->constNull, p);
	}
	{
		kBoolean *o = new_H(Boolean);
		o->n.bvalue = 1;
		KINITv(share->constTrue, o);
		o = new_H(Boolean);
		o->n.bvalue = 0;
		KINITv(share->constFalse, o);
	}
	{
		static const kdim_t dimINIT = {};
		kArray *a = new_H(Array);
		(a)->size = 0;
		(a)->dim = &dimINIT;
		KINITv(share->emptyArray, a);
	}
	share->tString = (kString**)KCALLOC(SIZEOF_TSTRING);
	knh_bzero(share->tString, SIZEOF_TSTRING);
	knh_loadScriptSystemString(_ctx);
	KINITv(share->cwdPath, new_CurrentPath(_ctx));

	/* These are not shared, but needed to initialize System*/
	knh_stack_initexpand(_ctx, NULL, K_STACKSIZE);
	KINITv(share->packageDictMap, new_DictMap0(_ctx, 0, 1/*isCaseMap*/, "packageDictMap"));
	KINITv(share->secfileidtyDictMap, new_DictMap0(_ctx, 0, 1/*isCaseMap*/, "secfileidtyDictMap")); // added by Wakamori
	KINITv(share->classNameDictSet, new_DictSet0(_ctx, 128, 1/*isCaseMap*/, "classNameDictSet"));
	KINITv(share->eventDictSet, new_DictSet0(_ctx, 32, 1/*isCaseMap*/, "eventDictSet"));
	KINITv(share->streamDpiDictSet, new_DictSet0(_ctx, 0, 1/*isCaseMap*/, "streamDpiDictSet"));
	KINITv(share->mapDpiDictSet, new_DictSet0(_ctx, 0, 1/*isCaseMap*/, "mapDpiDictSet"));
	KINITv(share->convDpiDictSet, new_DictSet0(_ctx, 0, 1/*isCaseMap*/, "convDpiDictSet"));
	KINITv(share->rconvDpiDictSet, new_DictSet0(_ctx, 0, 1/*isCaseMap*/, "convDpiDictSet"));

	KINITv(share->enc,   new_T(knh_getSystemEncoding()));
	KINITv(share->in,    new_InputStreamStdIn(_ctx, share->enc));
	KINITv(share->out,   new_OutputStreamStdOut(_ctx, share->enc));
	KINITv(share->err,   new_OutputStreamStdErr(_ctx, share->enc));

	KINITv(share->props, new_DictMap0(_ctx, 20, 1/*isCaseMap*/, "System.props"));
	KINITv(share->symbolDictCaseSet, new_DictSet0(_ctx, K_TFIELD_SIZE + 10, 1/*isCaseMap*/, "System.symbolDictSet"));
	KINITv(share->symbolList, new_Array0(_ctx, K_TFIELD_SIZE + 10));
	KINITv(share->urnDictSet, new_DictSet0(_ctx, 0, 0/*isCaseMap*/, "System.urnDictSet"));
	KINITv(share->urns, new_Array0(_ctx, 1));
	KINITv(share->corelang, new_(Lang));
	knh_initSugarData(_ctx);
	KINITv(share->tokenDictSet, new_DictSet0(_ctx, (TT_MAX - STT_MAX), 0/*isCaseMap*/, "System.tokenDictSet"));
//	KINITv(share->URNAliasDictMap, new_DictMap0(_ctx, 0, 0/*isCaseMap*/, "System.URNAliasDictMap"));

	KINITv(share->rootks, new_(KonohaSpace));
	knh_loadScriptSystemData(_ctx, share->rootks, kapi);
	knh_System_initPath(_ctx);                 // require rootks
	KINITv(_ctx->script, new_(Script));     // require rootks
	KINITv(_ctx->gma, new_(GammaBuilder));         // require script
	knh_loadScriptSystemKonohaCode(_ctx);      // require gamma
	loadPolicy(_ctx); // added by Wakamori
	knh_loadScriptSystemMethod(_ctx, kapi);
	CommonContext_init(_ctx, ctx);
	knh_loadScriptTermData(_ctx);
	knh_loadScriptAliasTermData(_ctx);
	share->ctx0 = ctx;
	knh_GammaBuilder_init(_ctx);  // initalize gamma->gf, reported by uh
	knh_initBuiltInPackage(_ctx, knh_getLoaderAPI());

	/* CompilerAPI */
	KINITv(share->konoha_compiler, K_NULL);
	share->compilerAPI = NULL;

	share->contextCounter = 1;
	share->threadCounter = 1;
	share->stopCounter = 0;
	share->gcStopCounter = 0;
	KINITv(share->contextListNULL, new_Array0(_ctx, 4));
	kArray_add(ctx->share->contextListNULL, knh_toContext(_ctx));
#if defined(K_USING_THREAD)
	share->stop_cond = kthread_cond_init(_ctx);
	share->start_cond = kthread_cond_init(_ctx);
	share->close_cond = kthread_cond_init(_ctx);
#endif
	return ctx;
}
Exemplo n.º 10
0
static kObject* BUILD_addConstPool(KonohaContext *kctx, kObject *o)
{
	KLIB kArray_add(kctx, ctxcode->constPools, o);
	return o;
}