aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bytecode/main.c')
-rw-r--r--src/bytecode/main.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/bytecode/main.c b/src/bytecode/main.c
index c994e08..ca1f441 100644
--- a/src/bytecode/main.c
+++ b/src/bytecode/main.c
@@ -4,9 +4,8 @@
4#include <stdlib.h> 4#include <stdlib.h>
5#include <string.h> 5#include <string.h>
6 6
7#include "types.h" 7#include "vm.h"
8#include "chunk.h" 8
9#include "darray.h"
10#include "ops.h" 9#include "ops.h"
11#include "debug.h" 10#include "debug.h"
12#include "errors.c" 11#include "errors.c"
@@ -14,9 +13,16 @@
14#include "read_line.c" 13#include "read_line.c"
15#include "string_view.c" 14#include "string_view.c"
16 15
16static VM vm;
17
17void 18void
18init(void) { 19init(void) {
19 // STUB 20 vm = vm_init();
21}
22
23void
24halt(void) {
25 vm_free(vm);
20} 26}
21 27
22void 28void
@@ -27,26 +33,14 @@ process_source(const StringView *source) {
27 return; 33 return;
28 } 34 }
29 35
30 // Test chunks and debugging utilities.
31 // Initialize chunk.
32 Chunk chunk = {0};
33 array_init(chunk.code, 0);
34 array_init(chunk.constants, 0);
35 array_init(chunk.lines, 0);
36
37 // Push some test instructions. 36 // Push some test instructions.
38 size_t const_idx = add_constant(chunk, 7); 37 size_t const_idx = add_constant(vm.chunk, 7);
39 add_code(chunk, OP_CONSTANT, 1, 1); 38 add_code(vm.chunk, OP_CONSTANT, 1, 1);
40 add_code(chunk, const_idx, 1, 1); 39 add_code(vm.chunk, const_idx, 1, 1);
41 add_code(chunk, OP_RETURN, 1, 1); 40 add_code(vm.chunk, OP_RETURN, 1, 1);
42 41
43 // Disassemble the chunk. 42 // Disassemble the chunk.
44 disassemble_chunk(chunk, "test chunk"); 43 disassemble_chunk(vm.chunk, "test chunk");
45
46 // Free chunk.
47 array_free(chunk.code);
48 array_free(chunk.constants);
49 array_free(chunk.lines);
50 44
51 array_free(tokens); 45 array_free(tokens);
52} 46}
@@ -183,6 +177,7 @@ main(int argc, char *argv[]) {
183 case 'i': { 177 case 'i': {
184 // Interactive mode. 178 // Interactive mode.
185 run_repl(); 179 run_repl();
180 halt();
186 return EXIT_SUCCESS; 181 return EXIT_SUCCESS;
187 } break; 182 } break;
188 default: { 183 default: {
@@ -195,6 +190,7 @@ main(int argc, char *argv[]) {
195 // Run from stdin. 190 // Run from stdin.
196 if (optind == argc) { 191 if (optind == argc) {
197 run_stdin(); 192 run_stdin();
193 halt();
198 return EXIT_SUCCESS; 194 return EXIT_SUCCESS;
199 } 195 }
200 196
@@ -205,5 +201,6 @@ main(int argc, char *argv[]) {
205 optind++; 201 optind++;
206 } 202 }
207 203
204 halt();
208 return EXIT_SUCCESS; 205 return EXIT_SUCCESS;
209} 206}