From 33372512fc32c26913c8385637d20f6d98c8376c Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 22 Oct 2021 10:34:25 +0200 Subject: Add constants operation --- src/bytecode/main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'src/bytecode/main.c') diff --git a/src/bytecode/main.c b/src/bytecode/main.c index 78fdfd3..ce196c8 100644 --- a/src/bytecode/main.c +++ b/src/bytecode/main.c @@ -5,6 +5,7 @@ #include #include "types.h" +#include "chunk.h" #include "darray.h" #include "ops.h" #include "debug.h" @@ -27,15 +28,24 @@ process_source(const StringView *source) { } // Test chunks and debugging utilities. - u8 *chunk = NULL; - array_init(chunk, 0); - array_push(chunk, OP_RETURN); - array_push(chunk, OP_RETURN); - array_push(chunk, OP_RETURN); - array_push(chunk, OP_RETURN); + // Initialize chunk. + Chunk chunk = {0}; + array_init(chunk.code, 0); + array_init(chunk.constants, 0); + + // Push some test instructions. + size_t const_idx = add_constant(chunk, 7); + array_push(chunk.code, OP_CONSTANT); + array_push(chunk.code, const_idx); + array_push(chunk.code, OP_RETURN); + + // Disassemble the chunk. disassemble_chunk(chunk, "test chunk"); - array_free(chunk); + // Free chunk. + array_free(chunk.code); + array_free(chunk.constants); + array_free(tokens); } -- cgit v1.2.1