Object *knh_getClassConstNULL(Ctx *ctx, knh_class_t cid, knh_bytes_t name) { DBG_ASSERT_cid(cid); if(ClassTBL(cid).constDictCaseMapNULL == NULL) return NULL; knh_DictCaseMap_t *cmap = ClassTBL(cid).constDictCaseMapNULL; Object *value = NULL; OLD_LOCK(ctx, LOCK_SYSTBL, NULL); int res = knh_DictCaseMap_index(cmap, name); if(res != -1) { value = knh_DictCaseMap_valueAt(cmap, res); } OLD_UNLOCK(ctx, LOCK_SYSTBL, NULL); return value; }
//<=============================================================== static const char *knh_Actor_getOriginalScript(CTX ctx, knh_Array_t *a, const char *actor_name) { int i = 0; int asize = a->size; const char *script = (const char *)malloc(MAX_SCRIPT_SIZE); memset((char *)script, 0, MAX_SCRIPT_SIZE); char *scr = (char *)script; char src_buf[MAX_SCRIPT_SIZE] = {0}; const char* pkg_name = "using konoha.actor.*;\n"; snprintf(scr, MAX_SCRIPT_SIZE, "%s", pkg_name); scr += strlen(pkg_name); for (i = 0; i < asize; i++) { knh_Func_t *fo = (knh_Func_t *)a->list[i]; knh_Method_t *mtd = fo->mtd; const char *mtd_name = knh_getmnname(ctx, mtd->mn); const char *type_name = S_tochar(ClassTBL(DP(mtd)->mp->p0.type)->sname); const char *arg_name = S_tochar(knh_getFieldName(ctx, DP(mtd)->mp->p0.fn)); const char *src = S_tochar(fo->mtd->b->tsource->text); knh_Actor_addIndent(src_buf, src); int wcount = snprintf(scr, MAX_SCRIPT_SIZE - strlen(scr), "\nvoid %s(%s %s)\n{\n%s}\n", mtd_name, type_name, arg_name, src_buf); if (wcount < 0) { fprintf(stderr, "ERROR: too large script size"); } scr += wcount; memset(src_buf, '\0', MAX_SCRIPT_SIZE); } snprintf(scr, MAX_SCRIPT_SIZE - strlen(scr), "Actor.act(\"%s\");", actor_name); return script; }
/* added by Wakamori */ static kbool_t method_isPermissionAllowed(CTX ctx, kMethod *mtd) { kDictMap *dmap = ctx->share->securityDictMap; CWB_t cwbbuf, *cwb = CWB_open0(ctx, &cwbbuf); CWB_write(ctx, cwb, S_tobytes(ClassTBL(mtd->cid)->sname)); CWB_putc(ctx, cwb, '.'); CWB_write(ctx, cwb, B(MN__(mtd->mn))); DBG_P("[methodname] : %s", CWB_tobytes(cwb).text); const char *idx, *p = role; while (p[0] != '\0') { idx = strchr((const char *)p, ','); kArray *a = NULL; if (idx != NULL) { a = (kArray *)knh_DictMap_getNULL(ctx, dmap, new_bytes2(p, idx - p)); p = idx + 1; } else { a = (kArray *)knh_DictMap_getNULL(ctx, dmap, B(p)); p += knh_strlen(p); } if (a != NULL) { int i; for (i = 0; i < knh_Array_size(a); i++) { const char *s = S_totext((kString*)knh_Array_n(a, i)); if (strstr(s, CWB_tobytes(cwb).text) != NULL || strstr(s, "all") != NULL) { // this method is allowed to be executed by this role CWB_close0(ctx, cwb); return 1; } } } } CWB_close0(ctx, cwb); return 0; }
kArray* new_ArrayG(CTX ctx, kclass_t cid, size_t capacity) { kArray *a = (kArray*)new_Object_init2(ctx, ClassTBL(cid)); if(capacity > 0) { knh_Array_grow(ctx, a, capacity, 8); } return a; }
KNHAPI2(kArray*) new_Array(CTX ctx, kclass_t p1, size_t capacity) { kclass_t cid = knh_class_P1(ctx, CLASS_Array, p1); kArray *a = (kArray*)new_Object_init2(ctx, ClassTBL(cid)); if(capacity > 0) { knh_Array_grow(ctx, a, capacity, 8); } return a; }
void KTexture::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { //fprintf(stderr, "KTexture::mouseReleaseEvent\n"); isDrag = false; if (ctx != NULL && sfp != NULL && mouse_release_func != NULL) { const knh_ClassTBL_t *ct1 = ClassTBL(cid); const knh_ClassTBL_t *ct2 = ClassTBL(mouse_event_cid); if (ct1 == NULL || ct2 == NULL) return; knh_RawPtr_t *p1 = (knh_RawPtr_t*)new_hObject_(ctx, ct1); p1->rawptr = this; KNH_SETv(ctx, sfp[5].o, UPCAST(p1)); knh_RawPtr_t *p2 = (knh_RawPtr_t*)new_hObject_(ctx, ct2); p2->rawptr = event; KNH_SETv(ctx, sfp[6].o, UPCAST(p2)); if (mouse_release_func->baseNULL != NULL) { KNH_SETv(ctx, sfp[K_CALLDELTA].o, mouse_release_func->baseNULL); } KNH_SCALL(ctx, sfp, 0, mouse_release_func->mtd, 3); } }
int knh_Object_compareTo(Ctx *ctx, Object *o1, Object *o2) { knh_class_t bcid1 = o1->h.bcid; knh_class_t bcid2 = o2->h.bcid; int res; if(bcid1 == bcid2) { res = ClassTBL(bcid1).cspi->compareTo(ctx, o1, o2); } else { res = (int)(o1 - o2); DBG_P("compared %s %s res=%d", O__(o1), O__(o2), res); } return res; }
static void knh_Actor_mainLoop(CTX ctx, knh_sfp_t *sfp, knh_Actor_t *a) { const char *name = DP(a)->actor_name; const char *path = DP(a)->path; int port = DP(a)->port; fprintf(stderr, "======== <<< Actor Information >>> ========\n"); fprintf(stderr, "name : %s\n", name); fprintf(stderr, "path : %s\n", path); fprintf(stderr, "port : %d\n", port); fprintf(stderr, "===========================================\n"); //int prev_pid = 0; int status; knh_io_t fd = knh_ServerSocket_open(ctx, sfp, port, 3); while (true) { knh_io_t sd = knh_ServerSocket_accept(ctx, sfp, fd); int pid = fork(); //fprintf(stderr, "==================\n"); //fprintf(stderr, "pid = [%d]\n", pid); if (pid == 0) { //child //fprintf(stderr, "child\n"); knh_InputStream_t *ins = knh_Socket_getInputStream(ctx, sd); knh_class_t cid = knh_getcid(ctx, new_bytes("ConnectionObject")); const knh_ClassTBL_t *ct = ClassTBL(cid); knh_Object_t *o = (knh_Object_t *)knh_InputStream_readObject(ctx, ins, ct); //fprintf(stderr, "mtd_name = %s\n", c->mtd_name); //knh_Object_t *msg = c->msg; knh_Actor_readMessage(ctx, a, o); knh_InputStream_close(ctx, ins); exit(0); } else if (pid < 0) { fprintf(stderr, "fork error\n"); } else { //fprintf(stderr, "PARENT: pid = [%d]\n", pid); waitpid(pid, &status, 0); //prev_pid = pid; } close(sd); } }
int knh_addClassConst(Ctx *ctx, knh_class_t cid, knh_String_t* name, Object *value) { int ret; knh_DictCaseMap_t *cmap = ClassTBL(cid).constDictCaseMapNULL; DBG_ASSERT_cid(cid); if(cmap == NULL) { knh_ClassTBL_t *t = pClassTBL(ctx, cid); cmap = new_DictCaseMap0(ctx, 0); KNH_INITv(t->constDictCaseMapNULL, cmap); } DBG_ASSERT(IS_Map(cmap)); OLD_LOCK(ctx, LOCK_SYSTBL, NULL); int idx = knh_DictCaseMap_index(cmap, S_tobytes(name)); if(idx != -1) { ret = 0; goto L_UNLOCK; } knh_DictCaseMap_set(ctx, cmap, name, value); ret = 1; L_UNLOCK: OLD_UNLOCK(ctx, LOCK_SYSTBL, NULL); return ret; }
int knh_addClassConst(CTX, kcid_t cid, kString* name, Object *value) { int ret; kDictMap *cmap = ClassTBL(cid)->constDictCaseMapNULL; DBG_ASSERT_cid(cid); if(cmap == NULL) { kclass_t *t = varClassTBL(cid); cmap = new_DictMap0(_ctx, 0, 1/*isCaseMap*/, "ClassTBL.constDictMap"); KINITv(t->constDictCaseMapNULL, cmap); } DBG_ASSERT(IS_Map(cmap)); OLD_LOCK(_ctx, LOCK_SYSTBL, NULL); int idx = knh_DictMap_index(cmap, S_tobytes(name)); if(idx != -1) { ret = 0; goto L_UNLOCK; } knh_DictMap_set(_ctx, cmap, name, value); ret = 1; L_UNLOCK: OLD_UNLOCK(_ctx, LOCK_SYSTBL, NULL); return ret; }
KNHAPI2(knh_Int_t*) new_Int(CTX ctx, knh_class_t cid, knh_int_t value) { knh_Int_t *b = (knh_Int_t*)new_hObject_(ctx, ClassTBL(cid)); b->n.ivalue = value; return b; }
KNHAPI2(knh_Float_t*) new_Float(CTX ctx, knh_class_t cid, knh_float_t value) { knh_Float_t *b = (knh_Float_t*)new_hObject_(ctx, ClassTBL(cid)); b->n.fvalue = value; return b; }
knh_write_cid(ctx, w, SP(mpr)->tcid); knh_write_EOL(ctx, w); } if(hasCaption == 1) { knh_write_EOL(ctx, w); } } //## @Static method void System.man(Object c, NameSpace ns); METHOD System_man(CTX ctx, knh_sfp_t *sfp _RIX) { knh_OutputStream_t *w = KNH_STDOUT; const knh_ClassTBL_t *ct = O_cTBL(sfp[1].o); knh_NameSpace_t *ns = sfp[2].ns; if(IS_Class(sfp[1].o)) { ct = ClassTBL(((knh_Class_t*)sfp[1].o)->cid); } ClassNAME_man(ctx, w, ct); if(!class_isPrivate(ct->cid)) { if(ct->constDictCaseMapNULL != NULL) { ClassCONST_man(ctx, w, ct, ns); } ClassOP_man(ctx, w, ct, ns); ClassMETHOD_man(ctx, w, ct, ns); ClassFMT_man(ctx, w, ct, ns); ClassTYPEMAP_man(ctx, w, ct, ns); } } /* ------------------------------------------------------------------------ */
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; }
static METHOD Object_getKey(Ctx *ctx, knh_sfp_t *sfp, long rix) { knh_String_t *s = ClassTBL(knh_Object_bcid(sfp[0].o)).cspi->getkey(ctx, sfp); KNH_ASSERT(IS_String(s)); RETURN_(s); }
static METHOD Object_hashCode(Ctx *ctx, knh_sfp_t *sfp, long rix) { knh_hashcode_t h = ClassTBL(knh_Object_bcid(sfp[0].o)).cspi->hashCode(ctx, sfp); RETURNi_(h); }