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