diff --git a/dust-lang/benches/addictive_addition.rs b/dust-lang/benches/addictive_addition.rs index ffb5264..f6b121e 100644 --- a/dust-lang/benches/addictive_addition.rs +++ b/dust-lang/benches/addictive_addition.rs @@ -1,7 +1,7 @@ use std::time::Duration; use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use dust_lang::{run, DustString}; +use dust_lang::run; const SOURCE: &str = r" let mut i = 0 @@ -12,7 +12,7 @@ const SOURCE: &str = r" "; fn addictive_addition(source: &str) { - run(Some(DustString::from("addictive_addition")), source).unwrap(); + run(source).unwrap(); } fn criterion_benchmark(c: &mut Criterion) { diff --git a/dust-lang/benches/fibonacci.rs b/dust-lang/benches/fibonacci.rs index da88346..cd83319 100644 --- a/dust-lang/benches/fibonacci.rs +++ b/dust-lang/benches/fibonacci.rs @@ -1,7 +1,7 @@ use std::time::Duration; use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use dust_lang::{run, DustString}; +use dust_lang::run; const SOURCE: &str = r" fn fib (n: int) -> int { @@ -15,7 +15,7 @@ const SOURCE: &str = r" "; fn addictive_addition(source: &str) { - run(Some(DustString::from("fibonacci")), source).unwrap(); + run(source).unwrap(); } fn criterion_benchmark(c: &mut Criterion) { diff --git a/dust-lang/src/compiler/mod.rs b/dust-lang/src/compiler/mod.rs index d9f88f1..4358839 100644 --- a/dust-lang/src/compiler/mod.rs +++ b/dust-lang/src/compiler/mod.rs @@ -49,10 +49,10 @@ use crate::{ /// /// assert_eq!(chunk.instructions().len(), 3); /// ``` -pub fn compile(program_name: Option, source: &str) -> Result { +pub fn compile(source: &str) -> Result { let lexer = Lexer::new(source); - let mut compiler = Compiler::new(lexer, program_name, true) - .map_err(|error| DustError::compile(error, source))?; + let mut compiler = + Compiler::new(lexer, None, true).map_err(|error| DustError::compile(error, source))?; compiler .compile() diff --git a/dust-lang/src/instruction/mod.rs b/dust-lang/src/instruction/mod.rs index e0a32e7..8cb0234 100644 --- a/dust-lang/src/instruction/mod.rs +++ b/dust-lang/src/instruction/mod.rs @@ -768,7 +768,7 @@ impl Debug for Instruction { impl Display for Instruction { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{} {}", self.operation(), self.disassembly_info()) + write!(f, "{} | {}", self.operation(), self.disassembly_info()) } } diff --git a/dust-lang/src/vm/mod.rs b/dust-lang/src/vm/mod.rs index cb5336f..fec393c 100644 --- a/dust-lang/src/vm/mod.rs +++ b/dust-lang/src/vm/mod.rs @@ -18,10 +18,10 @@ pub use thread::{Thread, ThreadData}; use tracing::{span, Level}; -use crate::{compile, Chunk, DustError, DustString, Value}; +use crate::{compile, Chunk, DustError, Value}; -pub fn run(program_name: Option, source: &str) -> Result, DustError> { - let chunk = compile(program_name, source)?; +pub fn run(source: &str) -> Result, DustError> { + let chunk = compile(source)?; let vm = Vm::new(chunk); Ok(vm.run()) @@ -92,8 +92,8 @@ pub enum Pointer { impl Display for Pointer { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - Self::Stack(index) => write!(f, "R{}", index), - Self::Constant(index) => write!(f, "C{}", index), + Self::Stack(index) => write!(f, "PR{}", index), + Self::Constant(index) => write!(f, "PC{}", index), } } } diff --git a/dust-lang/src/vm/run_action.rs b/dust-lang/src/vm/run_action.rs index 6cf5234..be1ae38 100644 --- a/dust-lang/src/vm/run_action.rs +++ b/dust-lang/src/vm/run_action.rs @@ -544,11 +544,17 @@ pub fn call(instruction: Instruction, data: &mut ThreadData) -> bool { ip: current_call.ip, record: Record::new(prototype), }; + let mut argument_index = 0; - for (argument_index, register_index) in (first_argument_register..return_register).enumerate() { - let argument = current_call + for register_index in first_argument_register..return_register { + let value_option = current_call .record - .clone_register_value_or_constant_unchecked(register_index); + .open_register_allow_empty_unchecked(register_index); + let argument = if let Some(value) = value_option { + value.clone() + } else { + continue; + }; trace!( "Passing argument \"{argument}\" to {}", @@ -560,7 +566,9 @@ pub fn call(instruction: Instruction, data: &mut ThreadData) -> bool { next_call .record - .set_register(argument_index as u8, Register::Value(argument)); + .set_register(argument_index, Register::Value(argument)); + + argument_index += 1; } data.next_action = get_next_action(&mut next_call.record); @@ -601,12 +609,12 @@ pub fn r#return(instruction: Instruction, data: &mut ThreadData) -> bool { }; let outer_call = data.call_stack.last_mut_unchecked(); - let destination = current_call.return_register; if should_return_value { let return_value = current_call .record .empty_register_or_clone_constant_unchecked(return_register); + let destination = current_call.return_register; outer_call .record