Continue working on function calls
This commit is contained in:
parent
d5fc68e466
commit
055f0a4100
@ -573,15 +573,12 @@ impl Instruction {
|
|||||||
Operation::Call => {
|
Operation::Call => {
|
||||||
let function_index = self.a();
|
let function_index = self.a();
|
||||||
let argument_count = self.b();
|
let argument_count = self.b();
|
||||||
|
let first_argument = function_index + 1;
|
||||||
let last_argument = function_index + argument_count;
|
let last_argument = function_index + argument_count;
|
||||||
|
|
||||||
let mut output = format!("R{function_index}(");
|
let mut output = format!("R{function_index}(");
|
||||||
|
|
||||||
for register in function_index..last_argument {
|
for register in first_argument..=last_argument {
|
||||||
if register != last_argument - 1 {
|
|
||||||
output.push_str(", ");
|
|
||||||
}
|
|
||||||
|
|
||||||
output.push_str(&format!("R{}", register));
|
output.push_str(&format!("R{}", register));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1159,9 +1159,11 @@ impl<'src> Parser<'src> {
|
|||||||
|
|
||||||
self.advance()?;
|
self.advance()?;
|
||||||
|
|
||||||
let function_register = self.current_register - 1;
|
let function_register = self.current_register;
|
||||||
let mut argument_count = 0;
|
let mut argument_count = 0;
|
||||||
|
|
||||||
|
self.increment_register()?;
|
||||||
|
|
||||||
while !self.allow(Token::RightParenthesis)? {
|
while !self.allow(Token::RightParenthesis)? {
|
||||||
if argument_count > 0 {
|
if argument_count > 0 {
|
||||||
self.expect(Token::Comma)?;
|
self.expect(Token::Comma)?;
|
||||||
|
@ -382,9 +382,9 @@ impl Vm {
|
|||||||
};
|
};
|
||||||
let mut function_vm = Vm::new(function.take_chunk());
|
let mut function_vm = Vm::new(function.take_chunk());
|
||||||
let first_argument_index = function_index + 1;
|
let first_argument_index = function_index + 1;
|
||||||
let last_argument_index = first_argument_index + argument_count;
|
let last_argument_index = first_argument_index + argument_count - 1;
|
||||||
|
|
||||||
for argument_index in first_argument_index..last_argument_index {
|
for argument_index in first_argument_index..=last_argument_index {
|
||||||
let argument = self.empty(argument_index, position)?;
|
let argument = self.empty(argument_index, position)?;
|
||||||
|
|
||||||
function_vm.stack.push(Register::Value(argument));
|
function_vm.stack.push(Register::Value(argument));
|
||||||
|
Loading…
Reference in New Issue
Block a user