stage1 重构代码
This commit is contained in:
@@ -54,7 +54,7 @@ int main(int argc, const char **argv) {
|
||||
spl_ins_t *ins = &vec_at(prog.insns, i);
|
||||
printf("%4zd: %s", i, spl_opcode_name((spl_opcode_t)ins->opcode));
|
||||
if (ins->type != SPL_VOID)
|
||||
printf(" %s", spl_type_name((spl_type_t)ins->type));
|
||||
printf(" %s", spl_type_tag_name((spl_type_t)ins->type));
|
||||
printf(" %zd", ins->imm);
|
||||
|
||||
/* annotate jumps / calls */
|
||||
|
||||
@@ -443,7 +443,7 @@ const char *opcode_name[] = {
|
||||
#undef X
|
||||
};
|
||||
const char *spl_opcode_name(spl_opcode_t opcode) { return opcode_name[opcode]; }
|
||||
const char *spl_type_name(spl_type_t type) {
|
||||
const char *spl_type_tag_name(spl_type_t type) {
|
||||
switch (type) {
|
||||
case SPL_VOID:
|
||||
return "void";
|
||||
@@ -481,7 +481,7 @@ const char *spl_type_name(spl_type_t type) {
|
||||
void spl_ins_dump(spl_ins_t *ins, spl_val_t addr) {
|
||||
printf("%4zu: %s", addr, spl_opcode_name((spl_opcode_t)ins->opcode));
|
||||
if (ins->type != SPL_VOID)
|
||||
printf(" %s", spl_type_name((spl_type_t)ins->type));
|
||||
printf(" %s", spl_type_tag_name((spl_type_t)ins->type));
|
||||
printf(" %zd:%zx", ins->imm, ins->imm);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ int spl_prog_add_str(spl_prog_t *prog, const char *str);
|
||||
|
||||
/* Opcode name lookup for debugging/dumping */
|
||||
const char *spl_opcode_name(spl_opcode_t opcode);
|
||||
const char *spl_type_name(spl_type_t type);
|
||||
const char *spl_type_tag_name(spl_type_t type);
|
||||
|
||||
void spl_ins_dump(spl_ins_t *ins, spl_val_t addr);
|
||||
|
||||
|
||||
@@ -665,7 +665,7 @@ int spl_vm_run_once(spl_vm_t *vm) {
|
||||
|
||||
if (vm->trace) {
|
||||
fprintf(stderr, "vm: ip=%zd op=%s type=%s imm=%zu sp=%zd fp=%zd\n", vm->ip - 1,
|
||||
spl_opcode_name(ins->opcode), spl_type_name(ins->type), ins->imm, vm->sp, vm->fp);
|
||||
spl_opcode_name(ins->opcode), spl_type_tag_name(ins->type), ins->imm, vm->sp, vm->fp);
|
||||
}
|
||||
|
||||
switch (ins->opcode) {
|
||||
@@ -1084,7 +1084,7 @@ void spl_vm_dump_instr(spl_vm_t *vm, spl_val_t ip) {
|
||||
return;
|
||||
spl_ins_t *ins = &vec_at(vm->prog->insns, ip);
|
||||
fprintf(stderr, " instr at ip=%zd: op=%s type=%s imm=%zu\n", ip, spl_opcode_name(ins->opcode),
|
||||
spl_type_name(ins->type), ins->imm);
|
||||
spl_type_tag_name(ins->type), ins->imm);
|
||||
}
|
||||
|
||||
void spl_vm_stackdump(spl_vm_t *vm, spl_val_t sp) {
|
||||
|
||||
Reference in New Issue
Block a user