Fix bugs with new instruction features
This commit is contained in:
parent
ef01499e38
commit
77cb82b9fe
@ -1491,14 +1491,17 @@ impl<'src> Compiler<'src> {
|
||||
|
||||
self.advance()?;
|
||||
|
||||
let mut argument_count = 0;
|
||||
|
||||
while !self.allow(Token::RightParenthesis)? {
|
||||
let expected_register = self.next_register();
|
||||
|
||||
self.parse_expression()?;
|
||||
|
||||
let actual_register = self.next_register() - 1;
|
||||
let registers_to_close = actual_register - expected_register;
|
||||
|
||||
if expected_register < actual_register {
|
||||
if registers_to_close > 0 {
|
||||
let close = Instruction::from(Close {
|
||||
from: expected_register,
|
||||
to: actual_register,
|
||||
@ -1507,12 +1510,13 @@ impl<'src> Compiler<'src> {
|
||||
self.emit_instruction(close, Type::None, self.current_position);
|
||||
}
|
||||
|
||||
argument_count += registers_to_close + 1;
|
||||
|
||||
self.allow(Token::Comma)?;
|
||||
}
|
||||
|
||||
let end = self.current_position.1;
|
||||
let register = self.next_register();
|
||||
let argument_count = self.next_register() - function.index() - 1;
|
||||
let call = Instruction::from(Call {
|
||||
destination: Destination::Register(register),
|
||||
function,
|
||||
|
@ -286,7 +286,7 @@ impl Display for ConcreteValue {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
ConcreteValue::Function(function) => write!(f, "{function}"),
|
||||
ConcreteValue::Function(chunk) => write!(f, "{}", chunk.r#type()),
|
||||
ConcreteValue::Integer(integer) => write!(f, "{integer}"),
|
||||
ConcreteValue::List(list) => {
|
||||
write!(f, "[")?;
|
||||
|
@ -285,6 +285,14 @@ impl<'a> Vm<'a> {
|
||||
|
||||
if boolean == test_value {
|
||||
self.jump(1, true);
|
||||
} else {
|
||||
let jump = self.read()?;
|
||||
let Jump {
|
||||
offset,
|
||||
is_positive,
|
||||
} = Jump::from(&jump);
|
||||
|
||||
self.jump(offset as usize, is_positive);
|
||||
}
|
||||
}
|
||||
Operation::TestSet => {
|
||||
@ -451,11 +459,10 @@ impl<'a> Vm<'a> {
|
||||
self.set_register(register_index, register)?;
|
||||
}
|
||||
Operation::Jump => {
|
||||
let jump = self.read()?;
|
||||
let Jump {
|
||||
offset,
|
||||
is_positive,
|
||||
} = Jump::from(&jump);
|
||||
} = Jump::from(&instruction);
|
||||
|
||||
self.jump(offset as usize, is_positive);
|
||||
}
|
||||
@ -479,7 +486,7 @@ impl<'a> Vm<'a> {
|
||||
});
|
||||
};
|
||||
let mut function_vm = Vm::new(chunk, Some(self));
|
||||
let first_argument_index = register_index - argument_count - 1;
|
||||
let first_argument_index = register_index - argument_count;
|
||||
|
||||
for (argument_index, argument_register_index) in
|
||||
(first_argument_index..register_index).enumerate()
|
||||
@ -489,9 +496,7 @@ impl<'a> Vm<'a> {
|
||||
Register::Pointer(Pointer::ParentStack(argument_register_index)),
|
||||
)?;
|
||||
|
||||
function_vm
|
||||
.local_definitions
|
||||
.push(Some(argument_index as u16));
|
||||
function_vm.local_definitions[argument_index] = Some(argument_index as u16);
|
||||
}
|
||||
|
||||
let return_value = function_vm.run()?;
|
||||
@ -627,7 +632,7 @@ impl<'a> Vm<'a> {
|
||||
if is_positive {
|
||||
format!("+{}", offset)
|
||||
} else {
|
||||
format!("-{}", offset + 1)
|
||||
format!("-{}", offset)
|
||||
}
|
||||
);
|
||||
|
||||
@ -749,7 +754,7 @@ impl<'a> Vm<'a> {
|
||||
position: self.current_position,
|
||||
})?;
|
||||
|
||||
self.jump(1, true);
|
||||
self.ip += 1;
|
||||
self.current_position = *position;
|
||||
|
||||
Ok(*instruction)
|
||||
|
Loading…
Reference in New Issue
Block a user