From a03973653262fbbfed7ce42dfa39646d16bdc98f Mon Sep 17 00:00:00 2001 From: ubq323 Date: Fri, 21 Jun 2024 00:25:55 +0100 Subject: while loops, comparisons, modulo, fizzbuzz --- dis.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'dis.c') diff --git a/dis.c b/dis.c index 9033bff..5c22cc2 100644 --- a/dis.c +++ b/dis.c @@ -2,6 +2,7 @@ #include #include +#include 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); + } } } -- cgit v1.2.3