fix: 修复字节码函数调用跳过扩展字执行异常问题

This commit is contained in:
爱特每羊队
2026-06-07 22:26:44 +08:00
parent f95841b3a1
commit 788a898b01
3 changed files with 11 additions and 11 deletions
+1 -3
View File
@@ -1029,9 +1029,7 @@ impl Compiler {
_ => OpCode::CALL, _ => OpCode::CALL,
}; };
ctx.emit(opcode::encode(op, callee_reg, this_reg, first_arg_reg)); ctx.emit(opcode::encode(op, callee_reg, this_reg, first_arg_reg));
if matches!(op, OpCode::CALL_NATIVE) { ctx.emit(arg_regs.len() as u32);
ctx.emit(arg_regs.len() as u32);
}
// Copy result from regs[0] into a dedicated register so multiple // Copy result from regs[0] into a dedicated register so multiple
// call expressions don't overwrite each other. // call expressions don't overwrite each other.
let result_reg = ctx.alloc_reg(); let result_reg = ctx.alloc_reg();
+6 -5
View File
@@ -1191,12 +1191,13 @@ impl Vm {
if !obj_ptr.is_null() { if !obj_ptr.is_null() {
let obj = unsafe { &*obj_ptr }; let obj = unsafe { &*obj_ptr };
if obj.is_function() { if obj.is_function() {
if obj.native_fn().is_some() { // Always consume extension word for arg_count
// Native call - use extension word for arg_count let ext = self.bytecode[self.pc];
let ext = self.bytecode[self.pc]; self.pc += 1;
self.pc += 1; let arg_count = (ext & 0xFF) as usize;
let arg_count = (ext & 0xFF) as usize;
if obj.native_fn().is_some() {
// Native call
let mut args_buf = [0u8; 257]; let mut args_buf = [0u8; 257];
args_buf[0] = this_reg; args_buf[0] = this_reg;
for i in 0..arg_count.min(256) { for i in 0..arg_count.min(256) {
+4 -3
View File
@@ -59,9 +59,10 @@ fn regression_recursion_depth_limit() {
#[test] #[test]
fn regression_throw_statement_errors() { fn regression_throw_statement_errors() {
assert_eq!( let result = eval("throw 'error'");
eval("throw 'error'"), assert!(
"vm error: opcode THROW not yet implemented" result.contains("uncaught"),
"expected uncaught, got: {result}"
); );
} }