static KMETHOD ExprTyCheck_Float(KonohaContext *kctx, KonohaStack *sfp) { VAR_ExprTyCheck(stmt, expr, gma, reqty); kToken *tk = expr->termToken; sfp[4].floatValue = strtod(S_text(tk->text), NULL); // just using tramsformation float RETURN_(SUGAR kExpr_setUnboxConstValue(kctx, expr, TY_Float, sfp[4].unboxValue)); }
static METHOD Method_getName(Ctx *ctx, knh_sfp_t *sfp, long rix) { knh_cwb_t cwbbuf, *cwb = knh_cwb_open(ctx, &cwbbuf); knh_write_mn(ctx, cwb->w, DP(sfp[0].mtdOBJ)->mn); RETURN_(knh_cwb_newString(ctx, cwb)); }
// PoolPlugin KeyFilter.create(String key); static KMETHOD KeyFilter_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_key_filter *p = POOL_PLUGIN_CLONE(pool_plugin_key_filter); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); p->klen = S_size(sfp[1].asString); p->key = copy_string(kctx, sfp[2].s); RETURN_(ret); }
// PoolPlugin Response.create(Event ev); static KMETHOD Response_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_response *p = POOL_PLUGIN_CLONE(pool_plugin_response); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); kRawPtr *ev = (kRawPtr *) sfp[1].asObject; p->bev = ev->rawptr; RETURN_(ret); }
//## LogPool LogPool.new(String host, int port) static KMETHOD LogPool_new(KonohaContext *kctx, KonohaStack *sfp) { kRawPtr *ret = (kRawPtr *) sfp[0].asObject; char *host = (char *) S_text(sfp[1].asString); int port = sfp[2].intValue; RawPtr_init(kctx, sfp[0].asObject, logpool_open_client(NULL, host, port)); RETURN_(ret); }
// PoolPlugin React.create(String traceName, String key); static KMETHOD React_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_react *p = POOL_PLUGIN_CLONE(pool_plugin_react); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); p->conf.traceName = copy_string(kctx, sfp[1].asString); p->conf.key = copy_string(kctx, sfp[2].s); RETURN_(ret); }
// PoolPlugin Statics.create(Func initFo, Func exitFo, Func func); static KMETHOD Statics_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_statics *p = POOL_PLUGIN_CLONE(pool_plugin_statics); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); p->context = (uintptr_t)statics_init(kctx, sfp[1].asFunc, sfp[2].asFunc, sfp[3].asFunc); p->finit = p_init; p->fexit = p_exit; p->function = p_func; RETURN_(ret); }
// PoolPlugin Timer.create(int timer, int startFlat, int contFlat, int finFlag); static KMETHOD Timer_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_timer *p = POOL_PLUGIN_CLONE(pool_plugin_timer); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); p->timer = sfp[1].intValue; p->flag_start = sfp[2].intValue; p->flag_cont = sfp[3].intValue; p->flag_finish = sfp[4].intValue; RETURN_(ret); }
//## String Log.get(String key) static KMETHOD Log_get_(KonohaContext *kctx, KonohaStack *sfp) { kRawPtr *self = (kRawPtr *) sfp[0].asObject; struct Log *log = (struct Log *) self->rawptr; char *key = (char *) S_text(sfp[1].asString); int klen = S_size(sfp[1].asString); int vlen; char *data = Log_get(log, key, klen, &vlen); RETURN_(KLIB new_kString(kctx, data, vlen, SPOL_ASCII|SPOL_POOL)); }
static void RETURN_PyObject_(KonohaContext *kctx, KonohaStack *sfp, PyObject *pyo) { if(pyo != NULL) { RETURN_(KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)pyo)); } else { // ERROR if python object is NULL // add ktrace. // looks stupid PyErr_Print(); } }
//## Log LogPool.get() static KMETHOD LogPool_get(KonohaContext *kctx, KonohaStack *sfp) { logpool_t *lp = (logpool_t *) ((kRawPtr *) sfp[0].asObject)->rawptr; char *buf = malloc(256); char *ret = logpool_client_get(lp, buf, 256); kObject *log = KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), 0); if (ret == NULL) { kObject_setNullObject(log, 1); free(buf); } RawPtr_init(kctx, log, buf); RETURN_(log); }
// PoolPlugin ValFilter.create(String key, String val, String op); static KMETHOD ValFilter_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_val_filter *p = POOL_PLUGIN_CLONE(pool_plugin_val_filter); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); p->klen = S_size(sfp[1].asString); p->key = copy_string(kctx, sfp[1].asString); p->vlen = S_size(sfp[2].s); p->val = copy_string(kctx, sfp[2].s); if (strncmp(S_text(sfp[3].s), "eq", 2) == 0) { p->val_cmp = val_eq; } else { assert(0 && "TODO"); } RETURN_(ret); }
static KMETHOD PyObject_toString(KonohaContext *kctx, KonohaStack *sfp) { kPyObject *po = (kPyObject*)sfp[0].asObject; KUtilsWriteBuffer wb; // assert DBG_ASSERT(po->self != NULL); KLIB Kwb_init(&(kctx->stack->cwb), &wb); O_ct(sfp[0].asObject)->p(kctx, sfp, 0, &wb, 0); kString* s = KLIB new_kString(kctx, KLIB Kwb_top(kctx, &wb, 1), Kwb_bytesize(&wb), 0); KLIB Kwb_free(&wb); RETURN_(s); //if (PyString_Check(po->self)) { // //dec // t = PyString_AsString(po->self); // RETURN_(KLIB new_kString(kctx, t, strlen(t), 0)); //} //else if (PyUnicode_Check(po->self)) { // //dec // PyObject* s = PyUnicode_AsUTF8String(po->self); // // [TODO] there is no t's NULL check. Is it OK? // t = PyString_AsString(s); // RETURN_(KLIB new_kString(kctx, t, strlen(t), 0)); //} //else if (PyByteArray_Check(po->self)) { // //dec // t = PyByteArray_AsString(po->self); // RETURN_(KLIB new_kString(kctx, t, strlen(t), 0)); //} //else { // KUtilsWriteBuffer wb; // KLIB Kwb_init(&(kctx->stack->cwb), &wb); // O_ct(sfp[0].asObject)->p(kctx, sfp, 0, &wb, 0); // kString* s = KLIB new_kString(kctx, KLIB Kwb_top(kctx, &wb, 1), Kwb_bytesize(&wb), 0); // KLIB Kwb_free(&wb); // RETURN_(s); //} }
// PoolPlugin Copy.create(); static KMETHOD Copy_create(KonohaContext *kctx, KonohaStack *sfp) { struct pool_plugin_copy *p = POOL_PLUGIN_CLONE(pool_plugin_copy); kRawPtr *ret = (kRawPtr *) KLIB new_kObject(kctx, O_ct(sfp[K_RTNIDX].o), (uintptr_t)p); RETURN_(ret); }
/* float to String */ static KMETHOD Float_toString(KonohaContext *kctx, KonohaStack *sfp) { char buf[40]; PLATAPI snprintf_i(buf, sizeof(buf), KFLOAT_FMT, sfp[0].floatValue); RETURN_(KLIB new_kString(kctx, buf, strlen(buf), SPOL_ASCII)); }
static METHOD Object_getClass(Ctx *ctx, knh_sfp_t *sfp, long rix) { RETURN_(new_Type(ctx, (sfp[0].o)->h.cid)); }
//## Exception System.getThrownException(); static KMETHOD System_getThrownException(KonohaContext *kctx, KonohaStack *sfp) { KonohaExceptionContext *ctx = KonohaContext_getExceptionContext(kctx); RETURN_(ctx->thrownException); }
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 void Farray_fastgetO(CTX ctx, ksfp_t *sfp, size_t n2 _RIX) { kArray *a = sfp[0].a; RETURN_(a->list[n2]); }