From 055f0a4100a0641bb697901ad892a3fb7de7115e Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 13 Oct 2024 02:47:12 -0400 Subject: [PATCH] Continue working on function calls --- dust-lang/src/instruction.rs | 7 ++----- dust-lang/src/parser.rs | 4 +++- dust-lang/src/vm.rs | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/dust-lang/src/instruction.rs b/dust-lang/src/instruction.rs index 5d2e3d6..371f4dc 100644 --- a/dust-lang/src/instruction.rs +++ b/dust-lang/src/instruction.rs @@ -573,15 +573,12 @@ impl Instruction { Operation::Call => { let function_index = self.a(); let argument_count = self.b(); + let first_argument = function_index + 1; let last_argument = function_index + argument_count; let mut output = format!("R{function_index}("); - for register in function_index..last_argument { - if register != last_argument - 1 { - output.push_str(", "); - } - + for register in first_argument..=last_argument { output.push_str(&format!("R{}", register)); } diff --git a/dust-lang/src/parser.rs b/dust-lang/src/parser.rs index bbbf828..8c8d29e 100644 --- a/dust-lang/src/parser.rs +++ b/dust-lang/src/parser.rs @@ -1159,9 +1159,11 @@ impl<'src> Parser<'src> { self.advance()?; - let function_register = self.current_register - 1; + let function_register = self.current_register; let mut argument_count = 0; + self.increment_register()?; + while !self.allow(Token::RightParenthesis)? { if argument_count > 0 { self.expect(Token::Comma)?; diff --git a/dust-lang/src/vm.rs b/dust-lang/src/vm.rs index be14c53..df528f6 100644 --- a/dust-lang/src/vm.rs +++ b/dust-lang/src/vm.rs @@ -382,9 +382,9 @@ impl Vm { }; let mut function_vm = Vm::new(function.take_chunk()); 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)?; function_vm.stack.push(Register::Value(argument));