debug: update runtime opcode printing

This commit is contained in:
2026-05-24 20:24:44 +01:00
parent d7443d7810
commit 862028f5a8
+32 -18
View File
@@ -70,10 +70,10 @@ extern void print_lex_token(struct lex_token *tok)
printf("(%s)", token_keyword_to_string(tok->tok_keyword)); printf("(%s)", token_keyword_to_string(tok->tok_keyword));
break; break;
case TOK_INT: case TOK_INT:
printf("(%lld)", tok->tok_int);
break;
case TOK_DOUBLE: case TOK_DOUBLE:
printf("(%lf)", tok->tok_double); printf("(");
fx_value_to_string(&tok->tok_number, fx_stdout, NULL);
printf(")");
break; break;
default: default:
break; break;
@@ -180,6 +180,9 @@ void print_instruction(
enum bshell_opcode opcode = 0; enum bshell_opcode opcode = 0;
uint32_t arg = 0; uint32_t arg = 0;
fx_value *pool_value = NULL; fx_value *pool_value = NULL;
fx_object *obj;
double d;
const char *s = NULL;
bshell_instruction_decode(instr, &opcode, &arg); bshell_instruction_decode(instr, &opcode, &arg);
@@ -187,6 +190,20 @@ void print_instruction(
switch (opcode) { switch (opcode) {
case OPCODE_LDC_INT: case OPCODE_LDC_INT:
fx_printf("ldc.int [yellow]#0x%02x", arg); fx_printf("ldc.int [yellow]#0x%02x", arg);
break;
case OPCODE_LDC_FP:
pool_value = bshell_scriptblock_get_pool_value(
container,
arg,
FX_TYPE_DOUBLE);
fx_printf("ldc.fp [cyan]@0x%02x ", arg);
if (pool_value) {
fx_value_get_double(pool_value, &d);
fx_printf("[reset][[[yellow]%g[reset]]", d);
} else {
fx_printf("[red]<INVALID>[reset]");
}
break; break;
case OPCODE_LDC_STR: case OPCODE_LDC_STR:
pool_value = bshell_scriptblock_get_pool_value( pool_value = bshell_scriptblock_get_pool_value(
@@ -201,9 +218,8 @@ void print_instruction(
} }
fx_printf("ldc.str [cyan]@0x%02x ", arg); fx_printf("ldc.str [cyan]@0x%02x ", arg);
if (pool_value) { if (pool_value) {
fx_printf( fx_value_get_cstr(pool_value, &s);
"[reset][[[green]%s[reset]]", fx_printf("[reset][[[green]%s[reset]]", s);
fx_value_get_cstr(pool_value));
} else { } else {
fx_printf("[red]<INVALID>[reset]"); fx_printf("[red]<INVALID>[reset]");
} }
@@ -220,9 +236,8 @@ void print_instruction(
fx_printf("ldblock [cyan]@0x%02x ", arg); fx_printf("ldblock [cyan]@0x%02x ", arg);
if (pool_value) { if (pool_value) {
fx_printf("[reset][[[magenta]vvv[reset]]\n"); fx_printf("[reset][[[magenta]vvv[reset]]\n");
print_scriptblock( fx_value_get_object(pool_value, &obj);
fx_value_get_object(pool_value), print_scriptblock(obj, depth + 1);
depth + 1);
} else { } else {
fx_printf("[red]<INVALID>[reset]"); fx_printf("[red]<INVALID>[reset]");
} }
@@ -241,9 +256,8 @@ void print_instruction(
} }
fx_printf("ldlocal [cyan]@0x%02x ", arg); fx_printf("ldlocal [cyan]@0x%02x ", arg);
if (pool_value) { if (pool_value) {
fx_printf( fx_value_get_cstr(pool_value, &s);
"[reset][[[green]%s[reset]]", fx_printf("[reset][[[green]%s[reset]]", s);
fx_value_get_cstr(pool_value));
} else { } else {
fx_printf("[red]<INVALID>"); fx_printf("[red]<INVALID>");
} }
@@ -259,7 +273,7 @@ void print_instruction(
fx_printf("ldarg [cyan]@0x%02x", arg); fx_printf("ldarg [cyan]@0x%02x", arg);
break; break;
case OPCODE_LDPROP: case OPCODE_LDPROP:
fx_printf("ldprop [cyan]@0x%02x", arg); fx_printf("ldprop");
break; break;
case OPCODE_LDELEM: case OPCODE_LDELEM:
fx_printf("ldelem [cyan]@0x%02x", arg); fx_printf("ldelem [cyan]@0x%02x", arg);
@@ -280,10 +294,8 @@ void print_instruction(
} }
fx_printf("stlocal [cyan]@0x%02x ", arg); fx_printf("stlocal [cyan]@0x%02x ", arg);
if (pool_value) { if (pool_value) {
fx_printf("[%s]", fx_value_get_cstr(pool_value)); fx_value_get_cstr(pool_value, &s);
fx_printf( fx_printf("[reset][[[green]%s[reset]]", s);
"[reset][[[green]%s[reset]]",
fx_value_get_cstr(pool_value));
} else { } else {
fx_printf("<INVALID>"); fx_printf("<INVALID>");
} }
@@ -446,5 +458,7 @@ void print_instruction(
void print_value(fx_value *val) void print_value(fx_value *val)
{ {
fx_printf("[yellow]%d[reset]\n", val->v_int); fx_printf("[yellow]");
fx_value_to_string(val, fx_stdout, NULL);
fx_printf("[reset]\n");
} }