Add bytecode VM backend (compile AST to bytecodes + stack-based VM)

New execution mode: ./run vm <file.j> compiles AST to bytecodes and
runs them in a while/switch loop. Ints/floats live on the stack (no
heap allocation), ~7.7x faster than the tree-walking interpreter.

Implements: opcodes, compiler with backpatching (if/while), stack VM
with arithmetic, comparisons, variables, strings, and print/println.
Reorganizes backend into src/backend/eval/ and src/backend/bytecode/.
This commit is contained in:
Jose Luis Montañes Ojados
2026-02-18 01:01:22 +01:00
parent 2c91cbb561
commit 4442886afa
11 changed files with 776 additions and 58 deletions

View File

@@ -94,7 +94,7 @@ void obj_free(void *allocator, size_t offset) {
JLANG_free(allocator, offset);
}
void obj_print(void *allocator, size_t offset, const char *preffix) {
void obj_print(void *allocator, size_t offset, const char *preffix, const char *suffix) {
Object *obj = (Object *)JLANG_RESOLVE(allocator, offset);
switch (obj->type) {
@@ -117,7 +117,7 @@ void obj_print(void *allocator, size_t offset, const char *preffix) {
if (items[i] == offset) {
printf("<self:0x%zu>", offset);
} else {
obj_print(allocator, items[i], "\"");
obj_print(allocator, items[i], "\"", "\"");
}
if (i < obj->data.list_val.capacity - 1) {
@@ -133,8 +133,8 @@ void obj_print(void *allocator, size_t offset, const char *preffix) {
}
printf("%s", (char *)JLANG_RESOLVE(allocator, obj->data.string_val.chars));
if (strcmp(preffix, "") != 0) {
printf("%s", preffix);
if (strcmp(suffix, "") != 0) {
printf("%s", suffix);
}
break;
default: