aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/main.c
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-22 10:34:25 +0200
committerBad Diode <bd@badd10de.dev>2021-10-22 10:34:25 +0200
commit33372512fc32c26913c8385637d20f6d98c8376c (patch)
tree9aa30e3e376d4769e858c37c912866dfdb4b4a62 /src/bytecode/main.c
parenteeff5e273f22aa28e81ab080e9ffdce85ac394b8 (diff)
downloadbdl-33372512fc32c26913c8385637d20f6d98c8376c.tar.gz
bdl-33372512fc32c26913c8385637d20f6d98c8376c.zip
Add constants operation
Diffstat (limited to 'src/bytecode/main.c')
-rw-r--r--src/bytecode/main.c24
1 files changed, 17 insertions, 7 deletions
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 @@
5#include <string.h> 5#include <string.h>
6 6
7#include "types.h" 7#include "types.h"
8#include "chunk.h"
8#include "darray.h" 9#include "darray.h"
9#include "ops.h" 10#include "ops.h"
10#include "debug.h" 11#include "debug.h"
@@ -27,15 +28,24 @@ process_source(const StringView *source) {
27 } 28 }
28 29
29 // Test chunks and debugging utilities. 30 // Test chunks and debugging utilities.
30 u8 *chunk = NULL; 31 // Initialize chunk.
31 array_init(chunk, 0); 32 Chunk chunk = {0};
32 array_push(chunk, OP_RETURN); 33 array_init(chunk.code, 0);
33 array_push(chunk, OP_RETURN); 34 array_init(chunk.constants, 0);
34 array_push(chunk, OP_RETURN); 35
35 array_push(chunk, OP_RETURN); 36 // Push some test instructions.
37 size_t const_idx = add_constant(chunk, 7);
38 array_push(chunk.code, OP_CONSTANT);
39 array_push(chunk.code, const_idx);
40 array_push(chunk.code, OP_RETURN);
41
42 // Disassemble the chunk.
36 disassemble_chunk(chunk, "test chunk"); 43 disassemble_chunk(chunk, "test chunk");
37 44
38 array_free(chunk); 45 // Free chunk.
46 array_free(chunk.code);
47 array_free(chunk.constants);
48
39 array_free(tokens); 49 array_free(tokens);
40} 50}
41 51