1
0

Tweak example and native function logic

This commit is contained in:
Jeff 2024-11-29 18:10:03 -05:00
parent 36da1d0d7c
commit 1ef5ddc013
3 changed files with 8 additions and 14 deletions

View File

@ -778,6 +778,8 @@ impl<'src> Compiler<'src> {
}); });
} }
if let Some([Operation::Test, Operation::Jump]) = self.get_last_operations() {}
let (argument, push_back) = self.handle_binary_argument(&left_instruction)?; let (argument, push_back) = self.handle_binary_argument(&left_instruction)?;
if push_back { if push_back {

View File

@ -686,10 +686,10 @@ impl Instruction {
function, function,
argument_count, argument_count,
} = Call::from(self); } = Call::from(self);
let first_argument = destination.index().saturating_sub(argument_count); let arguments_start = destination.index().saturating_sub(argument_count);
let last_argument = destination.index() - 1; let arguments_end = arguments_start + argument_count;
format!("{destination} = {function}(R{first_argument}..=R{last_argument})") format!("{destination} = {function}(R{arguments_start}..R{arguments_end})")
} }
Operation::CallNative => { Operation::CallNative => {
let CallNative { let CallNative {
@ -697,10 +697,10 @@ impl Instruction {
function, function,
argument_count, argument_count,
} = CallNative::from(self); } = CallNative::from(self);
let first_argument = destination.index().saturating_sub(argument_count); let arguments_start = destination.index().saturating_sub(argument_count);
let last_argument = destination.index() - 1; let arguments_end = arguments_start + argument_count;
format!("{destination} = {function}(R{first_argument}..=R{last_argument})") format!("{destination} = {function}(R{arguments_start}..R{arguments_end})")
} }
Operation::Return => { Operation::Return => {
let Return { let Return {

View File

@ -104,10 +104,6 @@ pub fn write<'a>(vm: &'a Vm<'a>, instruction: Instruction) -> Result<Option<Valu
let first_argument = to_register.saturating_sub(argument_count); let first_argument = to_register.saturating_sub(argument_count);
for argument_index in first_argument..to_register { for argument_index in first_argument..to_register {
if argument_index != first_argument {
stdout.write(b" ").map_err(map_err)?;
}
let argument = if let Some(value) = vm.open_register_allow_empty(argument_index)? { let argument = if let Some(value) = vm.open_register_allow_empty(argument_index)? {
value value
} else { } else {
@ -137,10 +133,6 @@ pub fn write_line<'a>(vm: &'a Vm<'a>, instruction: Instruction) -> Result<Option
let first_argument = to_register.saturating_sub(argument_count); let first_argument = to_register.saturating_sub(argument_count);
for argument_index in first_argument..to_register { for argument_index in first_argument..to_register {
if argument_index != first_argument {
stdout.write(b" ").map_err(map_err)?;
}
let argument = if let Some(value) = vm.open_register_allow_empty(argument_index)? { let argument = if let Some(value) = vm.open_register_allow_empty(argument_index)? {
value value
} else { } else {