Skip to content

Commit dab0c19

Browse files
committed
feat: Implement core VM with stack-based execution and add micro and macro benchmarks.
1 parent ddef48b commit dab0c19

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

benchmarks/macro/json_bench.prox

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ func main() {
108108

109109
let start = clock();
110110

111-
print("JsonParser is: " + to_string(JsonParser));
112111
let parser = JsonParser(json_str);
113112
let res = parser.parse();
114113

benchmarks/micro/fib.prox

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
func fib(n) {
3-
if (n < 4) print("fib of " + to_string(n));
43
if (n < 2) return n;
54
return fib(n - 1) + fib(n - 2);
65
}

src/runtime/vm.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,24 @@ static InterpretResult run(VM* vm) {
10411041
vm->stackTop -= argCount + 1;
10421042
push(vm, result);
10431043
break;
1044+
} else if (IS_CLASS(callee)) {
1045+
if (!callValue(callee, argCount, vm)) {
1046+
return INTERPRET_RUNTIME_ERROR;
1047+
}
1048+
frame = &vm->frames[vm->frameCount - 1];
1049+
break;
1050+
} else if (IS_BOUND_METHOD(callee)) {
1051+
ObjBoundMethod* bound = AS_BOUND_METHOD(callee);
1052+
vm->stackTop[-argCount - 1] = bound->receiver;
1053+
if (vm->frameCount == FRAMES_MAX) {
1054+
runtimeError(vm, "Stack overflow.");
1055+
return INTERPRET_RUNTIME_ERROR;
1056+
}
1057+
frame = &vm->frames[vm->frameCount++];
1058+
frame->closure = bound->method;
1059+
frame->ip = bound->method->function->chunk.code;
1060+
frame->slots = vm->stackTop - argCount - 1;
1061+
break;
10441062
} else {
10451063
runtimeError(vm, "Can only call functions, classes, and foreign functions.");
10461064
return INTERPRET_RUNTIME_ERROR;

0 commit comments

Comments
 (0)