Esempio n. 1
0
// ## Array[AprTableEntry] AprTable.getElts()
static KMETHOD AprTable_getElts(KonohaContext *kctx, KonohaStack *sfp)
{
    kAprTable *self = (kAprTable *) sfp[0].asObject;
    kArray *arr = (kArray *)KLIB new_kObject(kctx, OnStack, KClass_Array, 0);
    const apr_array_header_t *apr_arr = apr_table_elts(self->tbl);
    const apr_table_entry_t *entries = (apr_table_entry_t *)apr_arr->elts;
    int i=0;
    for (i=0; i<apr_arr->nelts; i++) {
        KLIB kArray_Add(kctx, arr, (kAprTableEntry *)KLIB new_kObject(kctx, OnStack, KClass_AprTableEntry, (uintptr_t)entries));
        entries++;
    }
    KReturn(arr);
}
Esempio n. 2
0
//## @Native @Static Thread Thread.self();
static KMETHOD Thread_self(KonohaContext *kctx, KonohaStack *sfp)
{
	kThread *t = (kThread *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	t->kctx = kctx;//FIXME
	t->thread = pthread_self();
	KReturn(t);
}
Esempio n. 3
0
// @SmartReturn Object Prototype.get(Symbol symbol)
static KMETHOD Prototype_get(KonohaContext *kctx, KonohaStack *sfp)
{
	KClass *targetClass = KGetReturnType(sfp);
	DBG_P("requesting type=%s", KClass_text(targetClass));
	ksymbol_t symbol = sfp[1].intValue;
	KKeyValue *kvs = KLIB kObjectProto_GetKeyValue(kctx, sfp[0].asObject, symbol);
	if(kvs != NULL) {
		KClass *c = KClass_(kvs->attrTypeId);
		if(targetClass == c) {
			if(KClass_Is(UnboxType, targetClass)) {
				KReturnUnboxValue(kvs->unboxValue);
			}
			else {
				KReturnField(kvs->ObjectValue);
			}
		}
		DBG_P("requesting type=%s instanceof %s ? %d", KClass_text(c), KClass_text(targetClass), c->isSubType(kctx, c, targetClass));
		if(c->isSubType(kctx, c, targetClass)) {
			if(KClass_Is(UnboxType, c)) {
				if(KClass_Is(UnboxType, targetClass)) {
					KReturnUnboxValue(kvs->unboxValue);
				}
				else {
					DBG_P("boxing type=%s instanceof %s ? %d", KClass_text(c), KClass_text(targetClass), c->isSubType(kctx, c, targetClass));
					KReturn(KLIB new_kObject(kctx, OnStack, c, kvs->unboxValue));
				}
			}
			KReturnField(kvs->ObjectValue);
		}
	}
	KReturnUnboxValue(0);  // return default value
}
Esempio n. 4
0
static void MPIData_extend(KonohaContext *kctx, kMPIData *p, int size) {
	size_t newSize = p->offset + size;
	if(p->size < newSize) {
		switch(p->typeId) {
		case KMPI_BYTES: {
			kBytes *b = (kBytes *)KLIB new_kObject(kctx, OnField, KClass_Bytes, (uintptr_t)newSize);
			memcpy(b->buf, p->b->buf, p->size);
			p->b = b;
			p->size = newSize;
			break;
		}
		case KMPI_FARRAY: {
			kfloat_t *fa = KCalloc_UNTRACE(sizeof(kfloat_t), newSize);
			memcpy(fa, p->fa, p->size * sizeof(kfloat_t));
			KFree(p->fa, p->size * sizeof(kfloat_t));
			p->fa = fa;
			p->size = newSize;
			break;
		}
		case KMPI_IARRAY: {
			kint_t *ia = KCalloc_UNTRACE(sizeof(kint_t), newSize);
			memcpy(ia, p->ia, p->size * sizeof(kint_t));
			KFree(p->ia, p->size * sizeof(kint_t));
			p->ia = ia;
			p->size = newSize;
			break;
		}
		default:
			abort();
		}
	}
}
Esempio n. 5
0
//## @Const method String[] String.split(RegExp regex);
static KMETHOD String_split(KonohaContext *kctx, KonohaStack *sfp)
{
	INIT_GCSTACK();
	kArray *resultArray = (kArray *)KLIB new_kObject(kctx, _GcStack, KGetReturnType(sfp), 0);
	kArray_split(kctx, resultArray, sfp[0].asString, sfp[1].asRegExp, S_size(sfp[0].asString));
	KReturnWith(resultArray, RESET_GCSTACK());
}
Esempio n. 6
0
// 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);
}
Esempio n. 7
0
// 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);
}
Esempio n. 8
0
// 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);
}
Esempio n. 9
0
//## @Const method String[] String.split(RegExp regex, Int limit);
static KMETHOD String_splitWithLimit(KonohaContext *kctx, KonohaStack *sfp)
{
	INIT_GCSTACK();
	size_t limit = sfp[2].intValue < 0 ? S_size(sfp[0].asString) : (size_t) sfp[2].intValue;
	kArray *resultArray = (kArray *)KLIB new_kObject(kctx, _GcStack, KGetReturnType(sfp), 0);
	kArray_split(kctx, resultArray, sfp[0].asString, sfp[1].asRegExp, limit);
	KReturnWith(resultArray, RESET_GCSTACK());
}
Esempio n. 10
0
static KMETHOD String_toIterator(KonohaContext *kctx, KonohaStack *sfp)
{
	kIterator *itr = (kIterator *)KLIB new_kObject(kctx, OnStack, CT_StringIterator, 0);
	KFieldSet(itr, itr->source, sfp[0].asObject);
	itr->hasNext = String_hasNext;
	itr->setNextResult = String_setNextResult;
	KReturn(itr);
}
Esempio n. 11
0
// MecabNode Tagger.ParseToNode(String input)
static KMETHOD Tagger_ParseToNode(KonohaContext *kctx, KonohaStack *sfp)
{
	struct _kTagger *mecab = (struct _kTagger *)sfp[0].asObject;
	const char *input = kString_text(sfp[1].asString);
	const mecab_node_t* node = mecab_sparse_tonode(mecab->mecab, input);
	struct _kMecabNode* ret = (struct _kMecabNode *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	ret->node = node;
	KReturn(ret);
}
Esempio n. 12
0
//## Complex Complex.conjl();
static KMETHOD Complex_conjl(KonohaContext *kctx, KonohaStack *sfp)
{
	kComplex *kc = (kComplex *) sfp[0].asObject;
	long double _Complex zl = (long double _Complex)kc->z;
	long double answer = conj(zl);
	kComplex *ret = (kComplex *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	ret->z = answer;
	KReturn(ret);
}
Esempio n. 13
0
//## Complex Complex.conjf();
static KMETHOD Complex_conjf(KonohaContext *kctx, KonohaStack *sfp)
{
	kComplex *kc = (kComplex *) sfp[0].asObject;
	float _Complex zf = (float _Complex)kc->z;
	float _Complex answer = conj(zf);
	kComplex *ret = (kComplex *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	ret->z = answer;
	KReturn(ret);
}
Esempio n. 14
0
// 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);
}
Esempio n. 15
0
// 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);
}
Esempio n. 16
0
static KMETHOD Array_toIterator(KonohaContext *kctx, KonohaStack *sfp)
{
	kArray *a = sfp[0].asArray;
	KClass *cIterator = KClass_p0(kctx, KClass_Iterator, kObject_class(a)->p0);
	kIterator *itr = (kIterator *)KLIB new_kObject(kctx, OnStack, cIterator, 0);
	KFieldSet(itr, itr->arrayList, a);
	itr->hasNext = Array_hasNext;
	itr->setNextResult = KType_Is(UnboxType, kObject_class(a)->p0) ? Array_SetNextResultUnbox : Array_SetNextResult;
	KReturn(itr);
}
Esempio n. 17
0
static KMETHOD Array_toIterator(KonohaContext *kctx, KonohaStack *sfp)
{
	kArray *a = sfp[0].asArray;
	KonohaClass *cIterator = CT_p0(kctx, CT_Iterator, O_ct(a)->p0);
	kIterator *itr = (kIterator *)KLIB new_kObject(kctx, OnStack, cIterator, 0);
	KFieldSet(itr, itr->arrayList, a);
	itr->hasNext = Array_hasNext;
	itr->setNextResult = TY_isUnbox(O_ct(a)->p0) ? Array_setNextResultUnbox : Array_setNextResult;
	KReturn(itr);
}
Esempio n. 18
0
static kBytes* new_kBytes(KonohaContext *kctx, kArray *gcstack, KClass *c, const char *buf, size_t bufsiz)
{
	kBytes* ba = (kBytes *) KLIB new_kObject(kctx, gcstack, c, bufsiz);
	if(bufsiz > 0) {
		((struct kBytesVar *)ba)->byteptr  = (const char *)KCalloc(bufsiz, 1, NULL);
		((struct kBytesVar *)ba)->bytesize = bufsiz;
		memcpy(ba->buf, buf, bufsiz);
	}
	return ba;
}
Esempio n. 19
0
// MecabNode MecabNode.bnext()
static KMETHOD MecabNode_bnext(KonohaContext *kctx, KonohaStack *sfp)
{
	struct _kMecabNode *node = (struct _kMecabNode *)sfp[0].asObject;
	mecab_node_t* bnext = node->node->bnext;
	struct _kMecabNode* ret = NULL;
	if(node != NULL) {
		ret = (struct _kMecabNode *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
		ret->node = bnext;
	}
	KReturn(ret);
}
Esempio n. 20
0
//## Stat System.fstat(int fd)
static KMETHOD System_fstat(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	int fd = (int)sfp[1].intValue;
	struct stat buf = {}; /* zero */
	int ret = fstat(fd, &buf);
	if(ret == -1) {
		KTraceErrorPoint(trace, SystemFault|SoftwareFault, "fstat", LogInt("fildes", fd), LogErrno);
	}
	KReturn(KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)&buf));
}
Esempio n. 21
0
//## @Native XmlReader XmlReader.new(String path);
static KMETHOD XmlReader_new(KonohaContext *kctx, KonohaStack *sfp)
{
	const char *path = kString_text(sfp[1].asString);
	xmlTextReaderPtr r = xmlNewTextReaderFilename(path);
	struct kXmlReaderVar *xml = (struct kXmlReaderVar *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	if(r == NULL) {
		//kreportf(ErrTag, sfp[K_RTNIDX].uline, "could not create XmlReader Object from %s", path);
	}
	xml->reader = (xmlTextReaderPtr)r;
	KReturn(xml);
}
Esempio n. 22
0
static void KReturnPyObject_(KonohaContext *kctx, KonohaStack *sfp, PyObject *pyo)
{
	if(pyo != NULL) {
		KReturn(KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)pyo));
	}
	else {
		// ERROR if python object is NULL
		// add ktrace.
		// looks stupid
		PyErr_Print();
	}
}
Esempio n. 23
0
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();
	}
}
Esempio n. 24
0
//## @Native XmlReader String.convertToXml();
static KMETHOD String_convertToXml(KonohaContext *kctx, KonohaStack *sfp)
{
	xmlChar* input = (xmlChar *)kString_text(sfp[0].asString);
	xmlTextReaderPtr r = xmlReaderForDoc(input, NULL, NULL, 1);
	//xmlTextReaderPtr r = xmlReaderForDoc(input, NULL, "UTF-8", 1);
	struct kXmlReaderVar *xml = (struct kXmlReaderVar *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
	if(r == NULL) {
		//kreportf(ErrTag, sfp[K_RTNIDX].uline, "could not create XmlReader Object from String");
	}
	xml->reader = (xmlTextReaderPtr)r;
	KReturn(xml);
}
Esempio n. 25
0
//## @Native Thread Thread.create(Func f)
static KMETHOD Thread_create(KonohaContext *kctx, KonohaStack *sfp)
{
	INIT_GCSTACK();
	kFunc *f = sfp[1].asFunc;
	KLIB kMethod_DoLazyCompilation(kctx, (f)->mtd, NULL, HatedLazyCompile);
	kThread *thread = (kThread *)KLIB new_kObject(kctx, _GcStack, KGetReturnType(sfp), 0);
	thread->rootCtx = kctx; //TODO getRootContext
	thread->kctx = KLIB KonohaContext_Init(kctx, kctx->platApi);
	KFieldSet(thread, thread->func, f);
	pthread_create(&(thread->thread), NULL, spawn_start, thread);
	RESET_GCSTACK(); // FIXME?? Not sure this is okay??
	KReturn(thread);
}
Esempio n. 26
0
//## 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);
}
Esempio n. 27
0
//## Stat System.stat(String path)
static KMETHOD System_stat(KonohaContext *kctx, KonohaStack *sfp)
{
	KMakeTrace(trace, sfp);
	char buffer[K_PATHMAX];
	kString *path = sfp[1].asString;
	const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
	struct stat buf = {}; /* zero */
	int ret = stat(systemPath, &buf);
	if(ret == -1) {
		int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|SystemError, trace);
		KTraceErrorPoint(trace, fault, "stat", LogText("path", kString_text(path)), LogErrno);
	}
	KReturn(KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)&buf));
}
Esempio n. 28
0
//## ResultSet Connection.query(String query);
static KMETHOD Connection_query(KonohaContext *kctx, KonohaStack *sfp)
{
	INIT_GCSTACK();
	KMakeTrace(trace, sfp);
	kConnection *conn = (kConnection *)sfp[0].asObject;
	const char *query = kString_text(sfp[1].asString);
	kResultSet *rs = (kResultSet *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)conn);
	KCursor *qcur = conn->driver->qexec(kctx, conn->db, query, rs, trace);
	if(qcur != NULL) {
		rs->qcur   = qcur;
		rs->driver = conn->driver;
	}
	KReturnWith(rs, RESET_GCSTACK());
}
Esempio n. 29
0
// MecabNode MecabNode.enext()
static KMETHOD MecabNode_enext(KonohaContext *kctx, KonohaStack *sfp)
{
	struct _kMecabNode *node = (struct _kMecabNode *)sfp[0].asObject;
	mecab_node_t* enext = node->node->enext;
	struct _kMecabNode* ret;
	if(node != NULL) {
		ret = (struct _kMecabNode *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
		ret->node = enext;
		KReturn(ret);
	}
	else {
		KReturnDefaultValue();
	}
}
Esempio n. 30
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);
}