Ejemplo n.º 1
0
//## String ResultSet.getString(String n);
static KMETHOD ResultSet_getString(KonohaContext *kctx, KonohaStack *sfp)
{
	kResultSet *rs = (kResultSet *)sfp[0].asObject;
	kString *res = TS_EMPTY;
	int idx = ResultSet_FindColumn(kctx, rs, sfp[1].asString);
	if(idx >= 0) {
		ktypeattr_t type = rs->column[idx].type;
		krbp_t *val = &rs->column[idx].val;
		if(type == KType_String) {
			res = val[0].asString;
		} else if(type == KType_Int) {
			KBuffer wb;
			KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
			KLIB KBuffer_printf(kctx, &wb, KFLOAT_FMT, val[0].floatValue);
			const char *text = KLIB KBuffer_text(kctx, &wb, 0);
			res = KLIB new_kString(kctx, OnStack, text, KBuffer_bytesize(&wb), 0);
			KLIB KBuffer_Free(&wb);
		} else if(KDefinedKonohaCommonModule() && type == KType_float) {
			KBuffer wb;
			KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
			KLIB KBuffer_printf(kctx, &wb, KFLOAT_FMT, val[0].floatValue);
			KLIB KBuffer_Free(&wb);
			const char *text = KLIB KBuffer_text(kctx, &wb, 0);
			res = KLIB new_kString(kctx, OnStack, text, KBuffer_bytesize(&wb), 0);
			KLIB KBuffer_Free(&wb);
		}
	}
	KReturn(res);
}
Ejemplo n.º 2
0
static void WriteVirtualCode1(KonohaContext *kctx, KBuffer *wb, KVirtualCode *c, KVirtualCode *vcode_start)
{
	KLIB KBuffer_printf(kctx, wb, "[L%d:%d] %s(%d)", (int)(c - vcode_start), c->line, OPDATA[c->opcode].name, (int)c->opcode);
	DumpOpArgument(kctx, wb, OPDATA[c->opcode].arg1, c, 0, vcode_start);
	DumpOpArgument(kctx, wb, OPDATA[c->opcode].arg2, c, 1, vcode_start);
	DumpOpArgument(kctx, wb, OPDATA[c->opcode].arg3, c, 2, vcode_start);
	DumpOpArgument(kctx, wb, OPDATA[c->opcode].arg4, c, 3, vcode_start);
	KLIB KBuffer_printf(kctx, wb, "\n");
}
Ejemplo n.º 3
0
static void kPyObject_p(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	PyObject *pyo =  ((kPyObject *)v[pos].asObject)->self;
	PyObject *str = pyo->ob_type->tp_str(pyo);
	Py_INCREF(str);
	KLIB KBuffer_printf(kctx, wb, "%s", PyString_AsString(str));
	Py_DECREF(str);
}
Ejemplo n.º 4
0
static void Person_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	/* This function is called when serializing the object. */
	struct Person *p = (struct Person *) v[pos].asObject;
	KLIB KBuffer_Write(kctx, wb, S_text(p->name), S_size(p->name));
	KLIB KBuffer_Write(kctx, wb, ",", 1);
	KLIB KBuffer_printf(kctx, wb, KINT_FMT, p->age);
}
Ejemplo n.º 5
0
static void kBytes_format(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	kBytes *ba = v[pos].asBytes;
	size_t i, j, n;
	for(j = 0; j * 16 < ba->bytesize; j++) {
		KLIB KBuffer_printf(kctx, wb, "%08x", (int)(j*16));
		for(i = 0; i < 16; i++) {
			n = j * 16 + i;
			if(n < ba->bytesize) {
				KLIB KBuffer_printf(kctx, wb, " %2x", (int)ba->utext[n]);
			}
			else {
				KLIB KBuffer_printf(kctx, wb, "%s", "   ");
			}
		}
		KLIB KBuffer_printf(kctx, wb, "%s", "    ");
		for(i = 0; i < 16; i++) {
			n = j * 16 + i;
			if(n < ba->bytesize && isprint(ba->utext[n])) {
				KLIB KBuffer_printf(kctx, wb, "%c", (int)ba->utext[n]);
			}
			else {
				KLIB KBuffer_printf(kctx, wb, "%s", " ");
			}
		}
		KLIB KBuffer_printf(kctx, wb, "\n");
	}
}
Ejemplo n.º 6
0
static void kFile_format(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	kFile *file = (kFile *)v[pos].asObject;
	if(file->PathInfoNULL != NULL) {
		KLIB KBuffer_Write(kctx, wb, kString_text(file->PathInfoNULL), kString_size(file->PathInfoNULL));
	}
	else {
		KLIB KBuffer_printf(kctx, wb, "FILE:%p", file->fp);
	}
}
Ejemplo n.º 7
0
static void Method_WriteAttributeToBuffer(KonohaContext *kctx, kMethod *mtd, KBuffer *wb)
{
	size_t i;
	for(i = 0; i < sizeof(MethodFlagData)/sizeof(const char *); i++) {
		uintptr_t flagmask = 1 << i;
		if((mtd->flag & flagmask) == flagmask) {
			KLIB KBuffer_printf(kctx, wb, "@%s ", MethodFlagData[i]);
		}
	}
}
Ejemplo n.º 8
0
static void DumpOpArgument(KonohaContext *kctx, KBuffer *wb, KVirtualCodeType type, KVirtualCode *c, size_t i, KVirtualCode *vcode_start)
{
	switch(type) {
	case VMT_VOID: break;
	case VMT_ADDR:
		KLIB KBuffer_printf(kctx, wb, " L%d", (int)((KVirtualCode *)c->p[i] - vcode_start));
		break;
	case VMT_UL: {
		kfileline_t uline = (kfileline_t)c->data[i];
		KLIB KBuffer_printf(kctx, wb, " (%s:%d)", PLATAPI shortFilePath(KFileLine_textFileName(uline)), (khalfword_t)uline);
		break;
	}
	case VMT_R: {
		KLIB KBuffer_printf(kctx, wb, " sfp[%d,r=%d]", (int)c->data[i]/2, (int)c->data[i]);
		break;
	}
	case VMT_FX: {
		khalfword_t index  = (khalfword_t)c->data[i];
		khalfword_t xindex = (khalfword_t)(c->data[i] >> (sizeof(khalfword_t)*8));
		KLIB KBuffer_printf(kctx, wb, " sfp[%d,r=%d][%d]", (int)index/2, (int)index, (int)xindex);
		break;
	}
	case VMT_U:
		KLIB KBuffer_printf(kctx, wb, " i%ld", (long)c->data[i]); break;
	case VMT_C:
	case VMT_TY:
		KLIB KBuffer_printf(kctx, wb, "(%s)", KClass_text(c->ct[i])); break;
	case VMT_F:
		KLIB KBuffer_printf(kctx, wb, " function(%p)", c->p[i]); break;
	case VMT_Object: {
		kObject *o = c->o[i];
		if(IS_Method(o)) {
			kMethod *mtd = (kMethod *)o;
			KLIB KBuffer_printf(kctx, wb, " %s.%s%s", KType_text(mtd->typeId), KMethodName_Fmt2(mtd->mn));
		}
		else {
			KLIB KBuffer_printf(kctx, wb, " (%s)", KClass_text(kObject_class(o)));
			KLIB kObject_WriteToBuffer(kctx, o, 0, wb, NULL, 0);
		}
		break;
	}
	case VMT_HCACHE:
		break;
	}/*switch*/
}
Ejemplo n.º 9
0
static void kFileStatus_format(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	kFileStatus *stat = (kFileStatus *)v[pos].asObject;
	KLIB KBuffer_printf(kctx, wb, "{dev: %d, ", stat->stat->st_dev);
	KLIB KBuffer_printf(kctx, wb, "ino: %d, ",  stat->stat->st_ino);
	KLIB KBuffer_printf(kctx, wb, "mode: %d, ", stat->stat->st_mode);
	KLIB KBuffer_printf(kctx, wb, "nlink: %d, ", stat->stat->st_nlink);
	KLIB KBuffer_printf(kctx, wb, "uid: %d, ", stat->stat->st_uid);
	KLIB KBuffer_printf(kctx, wb, "uid: %d, ", stat->stat->st_gid);
	KLIB KBuffer_printf(kctx, wb, "size: %d}", stat->stat->st_size);
}
Ejemplo n.º 10
0
static void kResultSet_format(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	kResultSet *rs = (kResultSet *) v[0].asObject;
	KLIB KBuffer_printf(kctx, wb, "{");
	size_t i;
	for(i = 0; i < (rs)->column_size; i++) {
		if(i > 0) {
			KLIB KBuffer_printf(kctx, wb, ",");
		}
		KLIB KBuffer_printf(kctx, wb, "(%d): ", i);
		ktypeattr_t type = rs->column[i].type;
		krbp_t *val = &rs->column[i].val;
		if(KType_Is(UnboxType, type)) {
			KonohaValue sp[1];
			KStackSetUnboxValue(sp[0].unboxValue, val[0].unboxValue);
			KClass_(type)->format(kctx, sp, 0, wb);
		} else {
			KLIB kObject_WriteToBuffer(kctx, val[0].asObject, false/*delim*/, wb, NULL, 0);
		}
	}
	KLIB KBuffer_printf(kctx, wb, "}");
}
Ejemplo n.º 11
0
static void kMethod_WriteToBuffer(KonohaContext *kctx, kMethod *mtd, KBuffer *wb)
{
	kParam *pa = kMethod_GetParam(mtd);
	Method_WriteAttributeToBuffer(kctx, mtd, wb);
	KLIB KBuffer_printf(kctx, wb, "%s %s.%s%s", KType_text(pa->rtype), KType_text(mtd->typeId), KMethodName_Fmt2(mtd->mn));
	{
		size_t i;
		KLIB KBuffer_Write(kctx, wb, "(", 1);
		for(i = 0; i < pa->psize; i++) {
			if(i > 0) {
				KLIB KBuffer_Write(kctx, wb, ", ", 2);
			}
			if(KTypeAttr_Is(ReadOnly, pa->paramtypeItems[i].attrTypeId)) {
				KLIB KBuffer_printf(kctx, wb, "@ReadOnly ");
			}
			if(KTypeAttr_Is(Coercion, pa->paramtypeItems[i].attrTypeId)) {
				KLIB KBuffer_printf(kctx, wb, "@Coercion ");
			}
			KLIB KBuffer_printf(kctx, wb, "%s %s", KType_text(pa->paramtypeItems[i].attrTypeId), KSymbol_text(pa->paramtypeItems[i].name));
		}
		KLIB KBuffer_Write(kctx, wb, ")", 1);
	}
}
Ejemplo n.º 12
0
static void kException_AddStackTrace(KonohaContext *kctx, KonohaStack *sfp, kException *e)
{
	kMethod *mtd = sfp[K_MTDIDX].calledMethod;
	KBuffer wb;
	KLIB KBuffer_Init(&kctx->stack->cwb, &wb);
	kfileline_t uline = sfp[K_RTNIDX].calledFileLine;
	if(uline > 0) {
		const char *file = KFileLine_textFileName(uline);
		KLIB KBuffer_printf(kctx, &wb, "(%s:%d) %s.%s%s" , PLATAPI shortFilePath(file), (kushort_t)uline, kMethod_Fmt3(mtd));
	}
//	int i = 0, psize = kMethod_ParamSize(mtd);
//	kParam *pa = kMethod_GetParam(mtd);
//	KClass *thisClass = O_cid(sfp[0]);
//	for(i = 0; i < psize; i++) {
//		pa->paramtypeItems[0].attrTypeId;
//		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 KBuffer_text(kctx, &wb, EnsureZero);
	KLIB new_kString(kctx, e->StackTraceList, 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));
//	}
}
Ejemplo n.º 13
0
static void kFloat_p(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	KLIB KBuffer_printf(kctx, wb, KFLOAT_FMT, v[pos].floatValue);
}
Ejemplo n.º 14
0
static void kDir_format(KonohaContext *kctx, KonohaValue *v, int pos, KBuffer *wb)
{
	kDir *dir = (kDir *)v[pos].asObject;
	KLIB KBuffer_printf(kctx, wb, "DIR: %s", kString_text(dir->PathInfoNULL));
}