Skip to content

Commit

Permalink
@@@ wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vegerot committed Nov 2, 2024
1 parent 8f2164d commit 1209b57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
3 changes: 3 additions & 0 deletions bytecode-vm-compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion bytecode-vm-compiler/src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -43,6 +43,7 @@ static bool isTruthy(Value value) {
}
}

// TODO: add VM as a parameter
void initVM(void) {
new_stack(&vm.stack);
resetStack();
Expand All @@ -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; }

Expand Down
14 changes: 14 additions & 0 deletions bytecode-vm-compiler/test/test-table.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "../src/vm.h"
#include <string.h>
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));

}

0 comments on commit 1209b57

Please sign in to comment.