Increment pc register before doing function call, not after return

This commit is contained in:
Konstantin Nazarov 2024-09-16 22:27:24 +01:00
parent 1733b0e433
commit 6ff2084d09
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 3 additions and 10 deletions

View file

@ -43,7 +43,6 @@ Result<StackFrame> stdlib_print(const StackFrame& stack) {
auto res = TRY(stack.set(0, nil));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -73,7 +72,6 @@ Result<StackFrame> stdlib_assert(const StackFrame& stack) {
auto res = TRY(stack.set(0, nil));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -86,7 +84,6 @@ Result<StackFrame> stdlib_dict(const StackFrame& stack) {
auto res = TRY(stack.set(0, d));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -99,7 +96,6 @@ Result<StackFrame> stdlib_list(const StackFrame& stack) {
auto res = TRY(stack.set(0, d));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -110,7 +106,6 @@ Result<StackFrame> stdlib_array(const StackFrame& stack) {
auto res = TRY(stack.set(0, params));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -128,7 +123,6 @@ Result<StackFrame> stdlib_get(const StackFrame& stack) {
auto res = TRY(stack.set(0, val));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -172,7 +166,6 @@ Result<StackFrame> stdlib_srcloc(const StackFrame& stack) {
auto res = TRY(stack.set(0, val));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -191,7 +184,6 @@ Result<StackFrame> stdlib_size(const StackFrame& stack) {
auto res = TRY(stack.set(0, val));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}
@ -245,7 +237,6 @@ Result<StackFrame> stdlib_map(const StackFrame& stack_param) {
auto res = TRY(stack.set(0, accumulator));
res = TRY(res.ret(0));
res = TRY(res.incpc());
return res;
}

View file

@ -104,6 +104,7 @@ Result<void> VM::vm_call_lisp(Opcode& oc, Function& fun) {
uint64_t reg_start = (uint64_t)oc.arg1().arg;
uint64_t reg_end = (uint64_t)oc.arg2().arg;
_stack = TRY(_stack.incpc());
_stack = TRY(_stack.call(TRY(fun.copy_value()), reg_start, reg_end));
return Result<void>();
@ -116,6 +117,7 @@ Result<void> VM::vm_call_stdlib(Opcode& oc, StdlibFunction& fun) {
auto params = TRY(_stack.slice(reg_start + 1, reg_end));
_stack = TRY(_stack.set(reg_start + 1, TRY(params.copy_value())));
_stack = TRY(_stack.settop(reg_start + 2));
_stack = TRY(_stack.incpc());
_stack = TRY(_stack.call(TRY(fun.copy_value()), reg_start, reg_start + 2));
return Result<void>();
@ -144,6 +146,7 @@ Result<void> VM::vm_selfcall(Opcode& oc) {
uint64_t reg_start = (uint64_t)oc.arg1().arg;
uint64_t reg_end = (uint64_t)oc.arg2().arg;
_stack = TRY(_stack.incpc());
_stack = TRY(_stack.call(fun, reg_start, reg_end));
return Result<void>();
@ -159,7 +162,6 @@ Result<void> VM::vm_ret(Opcode& oc) {
auto regnum = (uint64_t)oc.arg1().arg;
_stack = TRY(_stack.ret(regnum));
_stack = TRY(_stack.incpc());
return Result<void>();
}