summaryrefslogtreecommitdiff
path: root/dis.c
diff options
context:
space:
mode:
Diffstat (limited to 'dis.c')
-rw-r--r--dis.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/dis.c b/dis.c
index 9033bff..5c22cc2 100644
--- a/dis.c
+++ b/dis.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdlib.h>
static void print_const(Chunk *ch, uint8_t ix) {
Val k = ch->consts.d[ix];
@@ -10,6 +11,13 @@ static void print_const(Chunk *ch, uint8_t ix) {
}
void disasm_chunk(Chunk *ch) {
+ puts("constants:");
+ for (uint8_t cix = 0; cix < ch->consts.len; cix++) {
+ printf("%hd\t",cix);
+ print_const(ch, cix);
+ }
+
+ puts("bytecode:");
for (size_t ip = 0; ip < ch->bc.len; ) {
uint8_t instr = ch->bc.d[ip];
printf("%04zd\t",ip);
@@ -49,7 +57,7 @@ void disasm_chunk(Chunk *ch) {
case OP_REDO: {
ip += 2;
uint16_t offset = RSHORT();
- printf("0branch -%5hu\t; -> %04zd\n", offset, ip - offset);
+ printf("redo -%5hu\t; -> %04zd\n", offset, ip - offset);
break;
}
#undef RSHORT
@@ -64,11 +72,18 @@ void disasm_chunk(Chunk *ch) {
SIMPLE_INSTR(OP_SUB, "sub")
SIMPLE_INSTR(OP_MUL, "mul")
SIMPLE_INSTR(OP_DIV, "div")
+ SIMPLE_INSTR(OP_MOD, "mod")
SIMPLE_INSTR(OP_NIL, "nil")
SIMPLE_INSTR(OP_TRUE, "true")
SIMPLE_INSTR(OP_FALSE, "false")
+ SIMPLE_INSTR(OP_CMP, "cmp")
+ SIMPLE_INSTR(OP_EQU, "equ")
#undef SIMPLE_INSTR
+ default:
+ printf("unknown opcode %d\n", instr);
+ exit(2);
+
}
}
}