#pragma once #include #include #include #include __attribute__((format(printf, 1, 2))) static inline char *malp(const char *fmt, ...) { va_list v1, v2; va_start(v1, fmt); va_copy(v2, v1); size_t len = vsnprintf(NULL, 0, fmt, v1); va_end(v1); va_start(v2, fmt); char *str = malloc(len + 1); vsnprintf(str, len + 1, fmt, v2); str[len] = 0; va_end(v2); return str; } static const char *LINST_NAMES[] = { [L_GETGLOBAL] = "getglobal", [L_SETGLOBAL] = "setglobal", [L_SETINT16] = "setint16", [L_SETINT32] = "setint32", [L_SETFLOAT] = "setfloat", [L_SETSTR] = "setstr", [L_SETTABLE] = "settable", [L_SETBOOL] = "setbool", [L_SETNIL] = "setnil", [L_SETFUNC] = "setfunc", [L_ADD] = "add", [L_SUB] = "sub", [L_MUL] = "mul", [L_DIV] = "div", [L_IDIV] = "idiv", [L_MOD] = "mod", [L_RET] = "ret", [L_JNOTCOND] = "jnotcond", [L_MOVE] = "move", [L_CALL] = "call", [L_JUMP] = "jump", [L_ADVANCETEST] = "advancetest", [L_COND_EQ] = "cond_eq", [L_COND_NEQ] = "cond_neq", [L_SETFIELD] = "setfield", [L_GETFIELD] = "getfield", }; static void dump(LInst* i) { while(1) { printf("%s %02X %02X %02X\n", LINST_NAMES[i->opcode], i->a, i->b, i->c); if(i->opcode == L_RET) { break; } i++; } }