Exemplo n.º 1
0
static void kJSON_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	kJSON *json = (kJSON *)v[pos].asObject;
	char *data = JSON_toString(json->json);
	KLIB Kwb_printf(kctx, wb, "%s", data);
	free(data);
}
Exemplo n.º 2
0
static void Jansson_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	struct _kJson *json = (struct _kJson *)v[pos].asObject;
	char* data = json_dumps(json->obj, JSON_ENSURE_ASCII);
	KLIB Kwb_printf(kctx, wb, "%s", data);
	free(data);
}
Exemplo n.º 3
0
static void RegExp_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	kRegExp *re = v[pos].asRegExp;
	KLIB Kwb_printf(kctx, wb, "/%s/%s%s%s", S_text(re->pattern),
			RegExp_isGlobal(re) ? "g" : "",
			RegExp_isIgnoreCase(re) ? "i" : "",
			RegExp_isMultiline(re) ? "m" : "");
}
Exemplo n.º 4
0
static void DumpVisitor_init(KonohaContext *kctx, struct IRBuilder *builder, kMethod *mtd)
{
	unsigned i;
	KGrowingBuffer wb;
	KLIB Kwb_init(&(kctx->stack->cwb), &wb);
	kParam *pa = Method_param(mtd);
	KLIB Kwb_printf(kctx, &wb, "METHOD %s%s(", T_mn(mtd->mn));
	for (i = 0; i < pa->psize; i++) {
		if(i != 0) {
			KLIB Kwb_write(kctx, &wb, ", ", 2);
		}
		KLIB Kwb_printf(kctx, &wb, "%s %s", TY_t(pa->paramtypeItems[i].ty), SYM_t(pa->paramtypeItems[i].fn));
	}
	emit_string(KLIB Kwb_top(kctx, &wb, 1), "", ") {", 0);
	builder->local_fields = (void *) KMalloc_UNTRACE(sizeof(int));
	DUMPER(builder)->indent = 0;
}
Exemplo n.º 5
0
static void PyObject_p(KonohaContext *kctx, KonohaStack *sfp, int pos, KUtilsWriteBuffer *wb, int level)
{
	// Now, level value has no effect.
	PyObject *pyo =  ((kPyObject*)sfp[pos].o)->self;
	PyObject* str = pyo->ob_type->tp_str(pyo);
	Py_INCREF(str);
	KLIB Kwb_printf(kctx, wb, "%s", PyString_AsString(str));
	Py_DECREF(str);
}
Exemplo n.º 6
0
static void Method_WriteAttributeToBuffer(KonohaContext *kctx, kMethod *mtd, KGrowingBuffer *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 Kwb_printf(kctx, wb, "@%s ", MethodFlagData[i]);
        }
    }
}
Exemplo n.º 7
0
static void kMethod_WriteToBuffer(KonohaContext *kctx, kMethod *mtd, KGrowingBuffer *wb)
{
    kParam *pa = Method_param(mtd);
    Method_WriteAttributeToBuffer(kctx, mtd, wb);
    KLIB Kwb_printf(kctx, wb, "%s %s.%s%s", TY_t(pa->rtype), TY_t(mtd->typeId), MethodName_t(mtd->mn));
    {
        size_t i;
        KLIB Kwb_Write(kctx, wb, "(", 1);
        for(i = 0; i < pa->psize; i++) {
            if(i > 0) {
                KLIB Kwb_Write(kctx, wb, ", ", 2);
            }
            if(FN_isCOERCION(pa->paramtypeItems[i].fn)) {
                KLIB Kwb_printf(kctx, wb, "@Coercion ");
            }
            KLIB Kwb_printf(kctx, wb, "%s %s", TY_t(pa->paramtypeItems[i].ty), SYM_t(pa->paramtypeItems[i].fn));
        }
        KLIB Kwb_Write(kctx, wb, ")", 1);
    }
}
Exemplo n.º 8
0
static void Log_p(KonohaContext *kctx, KonohaStack *sfp, int pos, KUtilsWriteBuffer *wb, int level)
{
	kRawPtr *self = (kRawPtr *) sfp[0].asObject;
	struct Log *log = (struct Log *) self->rawptr;
	int i;
	char *data = log_get_data(log);
	uint16_t klen, vlen;
	KLIB Kwb_printf(kctx, wb, "{");
	for (i = 0; i < log->logsize; ++i) {
		char kbuf[64] = {};
		char vbuf[64] = {};
		char *next = log_iterator(log, data, i);
		klen = log_get_length(log, i*2+0);
		vlen = log_get_length(log, i*2+1);
		memcpy(kbuf, data,klen);
		memcpy(vbuf, data+klen, vlen);
		KLIB Kwb_printf(kctx, wb, "'%s': '%s' ", kbuf, vbuf);
		data = next;
	}
	KLIB Kwb_printf(kctx, wb, "}");
}
Exemplo n.º 9
0
static void DumpVisitor_visitCallExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	KGrowingBuffer wb;
	KLIB Kwb_init(&(kctx->stack->cwb), &wb);
	kMethod *mtd = CallExpr_getMethod(expr);
	KLIB Kwb_printf(kctx, &wb, "CALL: '%s%s'", T_mn(mtd->mn));
	DUMPER(self)->indent++;
	emit_string(KLIB Kwb_top(kctx, &wb, 1), "(", "", DUMPER(self)->indent);
	DUMPER(self)->indent++;
	unsigned i;
	for (i = 1; i < kArray_size(expr->cons); ++i) {
		handleExpr(kctx, self, kExpr_at(expr, i));
	}
	DUMPER(self)->indent--;
	emit_string(")", "", "", DUMPER(self)->indent);
	DUMPER(self)->indent--;
	KLIB Kwb_free(&wb);
}
Exemplo n.º 10
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.º 11
0
static void kSymbol_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	ksymbol_t symbol = (ksymbol_t)v[pos].unboxValue;
	KLIB Kwb_printf(kctx, wb, "%s%s", PSYM_t(symbol));
}
Exemplo n.º 12
0
static void kcid_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	ktype_t cid = (ktype_t)v[pos].intValue;
	DBG_P(">>> Class=%s, cid=%d", SYM_t(CT_(cid)->classNameSymbol), cid);
	KLIB Kwb_printf(kctx, wb, "%s%s", PSYM_t(CT_(cid)->classNameSymbol));
}
Exemplo n.º 13
0
static void Float_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	KLIB Kwb_printf(kctx, wb, KFLOAT_FMT, v[pos].floatValue);
}
Exemplo n.º 14
0
static void Exception_p(KonohaContext *kctx, KonohaStack *sfp, int pos, KUtilsWriteBuffer *wb, int level)
{
	KLIB Kwb_printf(kctx, wb, "%s", S_text(sfp[pos].asException));
}
Exemplo n.º 15
0
static void kDir_p(KonohaContext *kctx, KonohaValue *v, int pos, KGrowingBuffer *wb)
{
	kDir *dir = (kDir *)v[pos].asObject;
	KLIB Kwb_printf(kctx, wb, "DIR: %s", S_text(dir->PathInfoNULL));
}
Exemplo n.º 16
0
static void Float_p(KonohaContext *kctx, KonohaStack *sfp, int pos, KUtilsWriteBuffer *wb, int level)
{
	KLIB Kwb_printf(kctx, wb, KFLOAT_FMT, sfp[pos].floatValue);
}