diff --git a/bytecode-vm-compiler/Makefile b/bytecode-vm-compiler/Makefile index b6dd7eb..c91f532 100644 --- a/bytecode-vm-compiler/Makefile +++ b/bytecode-vm-compiler/Makefile @@ -24,6 +24,9 @@ test/test-scanner: test/test-scanner.c src/scanner.h src/scanner.c src/lox_asser test/test-compiler: test/test-compiler.c src/compiler.h src/compiler.c src/scanner.h src/scanner.c src/chunk.h src/chunk.c src/value.h src/value.c $(CC) -DDEBUG_TRACE_EXECUTION -fsanitize=address $(CFLAGS) -Wno-error test/test-compiler.c $(SRC_FILES) -o test/test-compiler test/test-compiler || mv -v test/test-compiler test/test-compiler.failed +test/test-table: test/test-table.c test/test-vm + $(CC) -fsanitize=address $(CFLAGS) -Wno-error test/test-table.c $(SRC_FILES) -o test/test-table + test/test-table || mv test/test-table test/test-table.failed # NOTE: if you're seeing a bunch of errors about unknown clang flags, make diff --git a/bytecode-vm-compiler/src/vm.c b/bytecode-vm-compiler/src/vm.c index ccf4cee..25e22a5 100644 --- a/bytecode-vm-compiler/src/vm.c +++ b/bytecode-vm-compiler/src/vm.c @@ -11,7 +11,7 @@ #include "vm.h" LoxString* newEmptyLoxString(VM* vm, int length); -// TODO: make this a parameter +// TODO: don't use a global variable for the VM static VM vm; // NOLINT static void resetStack(void) { vm.stack.top = vm.stack.bottom; } @@ -43,6 +43,7 @@ static bool isTruthy(Value value) { } } +// TODO: add VM as a parameter void initVM(void) { new_stack(&vm.stack); resetStack(); @@ -57,6 +58,8 @@ void freeVM(void) { /** * hack: only used for tests + * q: does this copy the VM? Looking through the properties of the VM, the only + * property that might actually be copied is `vm.stack.cap` */ VM getVM_(void) { return vm; } diff --git a/bytecode-vm-compiler/test/test-table.c b/bytecode-vm-compiler/test/test-table.c new file mode 100644 index 0000000..90b01ff --- /dev/null +++ b/bytecode-vm-compiler/test/test-table.c @@ -0,0 +1,14 @@ +#include "../src/vm.h" +#include +LoxString* allocateString(VM* vm, char const* cString, int length); +int main(void) { + // basic + initVM(); + VM vm = getVM_(); + LoxTable table; + tableInit(&table); + char const* k = "key"; + LoxString* key = allocateString(&vm, "key", strlen(k)); + tableSet(&table, key, NUMBER_VAL(42.0)); + +}