Put stdlib calls onto the stack as well as normal function calls
This commit is contained in:
parent
e9b9ef6d61
commit
6126c7b8eb
1 changed files with 21 additions and 5 deletions
26
src/vm.cpp
26
src/vm.cpp
|
@ -114,11 +114,10 @@ Result<void> VM::vm_call_stdlib(Opcode& oc, StdlibFunction& fun) {
|
|||
uint64_t reg_end = (uint64_t)oc.arg2().arg;
|
||||
|
||||
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.call(TRY(fun.copy_value()), reg_start, reg_start + 2));
|
||||
|
||||
auto res = TRY(call_stdlib_function(fun.fun_id(), params));
|
||||
_stack = TRY(setreg(oc.arg1().arg, res));
|
||||
|
||||
_stack = TRY(_stack.incpc());
|
||||
return Result<void>();
|
||||
}
|
||||
|
||||
|
@ -278,7 +277,24 @@ Result<void> VM::step_bytecode() {
|
|||
return Result<void>();
|
||||
}
|
||||
|
||||
Result<void> VM::step_native() { return ERROR(NotImplemented); }
|
||||
Result<void> VM::step_native() {
|
||||
// foo
|
||||
auto fun = TRY(_stack.fun());
|
||||
if (!fun.is<StdlibFunction>()) return ERROR(TypeMismatch);
|
||||
auto fun_id = fun.to<StdlibFunction>()->fun_id();
|
||||
|
||||
auto params = TRY(_stack.get(0));
|
||||
if (!params.is<Array>()) return ERROR(TypeMismatch);
|
||||
|
||||
auto res = TRY(call_stdlib_function(fun_id, *params.to<Array>()));
|
||||
|
||||
auto top = TRY(_stack.size());
|
||||
_stack = TRY(_stack.set(top, res));
|
||||
_stack = TRY(_stack.ret(top));
|
||||
|
||||
_stack = TRY(_stack.incpc());
|
||||
return Result<void>();
|
||||
}
|
||||
|
||||
Result<void> VM::step() {
|
||||
auto fun = TRY(_stack.fun());
|
||||
|
|
Loading…
Reference in a new issue