diff --git a/src/execution/gc_tests.rs b/src/execution/gc_tests.rs index 32144f8..f9790b3 100644 --- a/src/execution/gc_tests.rs +++ b/src/execution/gc_tests.rs @@ -46,7 +46,8 @@ fn compact_roots( frame.byte_len = reservation.byte_len; for register in 0..function.register_count { if let Some(Some(value)) = registers.get(frame_index * width + register) { - write_frame_value(&mut arena, *frame, function, register as u16, *value).unwrap(); + write_frame_value(&mut arena, frame.base, function, register as u16, *value) + .unwrap(); } } } diff --git a/src/execution/machine.rs b/src/execution/machine.rs index 8c189ab..c055df4 100644 --- a/src/execution/machine.rs +++ b/src/execution/machine.rs @@ -90,7 +90,7 @@ impl Frame { #[inline(always)] pub(super) fn read_frame_value( arena: &FrameArena, - frame: Frame, + frame_base: u32, function: &ResolvedFunction, register: u16, ) -> Result { @@ -99,13 +99,13 @@ pub(super) fn read_frame_value( .register_accesses .get(register) .ok_or(VmFault::InvalidStoragePlan)?; - arena.read_access(frame.base, access) + arena.read_access(frame_base, access) } #[inline(always)] pub(super) fn write_frame_value( arena: &mut FrameArena, - frame: Frame, + frame_base: u32, function: &ResolvedFunction, register: u16, value: RuntimeValue, @@ -115,7 +115,7 @@ pub(super) fn write_frame_value( .register_accesses .get(register) .ok_or(VmFault::InvalidStoragePlan)?; - arena.write_access(frame.base, access, value) + arena.write_access(frame_base, access, value) } pub(super) struct Machine { @@ -506,7 +506,7 @@ impl Machine { for (parameter, argument) in arguments.iter().enumerate() { if write_frame_value( &mut self.frame_arena, - self.frames[0], + self.frames[0].base, entry, parameter as u16, argument.value, @@ -602,7 +602,7 @@ impl Machine { if let Some((destination, value)) = result { write_frame_value( &mut self.frame_arena, - frame, + frame.base, function, destination, RuntimeValue::I32(value), @@ -1600,7 +1600,7 @@ impl Machine { }; if let Err(fault) = write_frame_value( &mut self.frame_arena, - callee, + callee.base, target_function, parameter as u16, value, @@ -2408,7 +2408,7 @@ impl Machine { }; if let Err(fault) = write_frame_value( &mut self.frame_arena, - child_frame, + child_frame.base, target_function, parameter as u16, value, @@ -2689,7 +2689,7 @@ impl Machine { return Ok(self.fault(VmFault::ReachedUnreachable)); } _ => { - let frame = self.frames[frame_index]; + let frame = &self.frames[frame_index]; let function = self .image .function(frame.function) @@ -2697,7 +2697,7 @@ impl Machine { match execute_scalar( instruction, &mut self.frame_arena, - frame, + frame.base, function, &self.image, &self.heap, @@ -3061,7 +3061,7 @@ impl Machine { .image .function(frame.function) .ok_or(VmFault::InvalidResolvedId)?; - read_frame_value(&self.frame_arena, frame, function, register) + read_frame_value(&self.frame_arena, frame.base, function, register) } fn write_register( @@ -3079,7 +3079,7 @@ impl Machine { .image .function(frame.function) .ok_or(VmFault::InvalidResolvedId)?; - write_frame_value(&mut self.frame_arena, frame, function, register, value) + write_frame_value(&mut self.frame_arena, frame.base, function, register, value) } fn ensure_type_initialized( @@ -4304,9 +4304,13 @@ impl Machine { continue; } } - let value = - read_frame_value(&self.frame_arena, frame, active_function, register as u16) - .map_err(|_| RunError::NotRunnable)?; + let value = read_frame_value( + &self.frame_arena, + frame.base, + active_function, + register as u16, + ) + .map_err(|_| RunError::NotRunnable)?; let reference_type = match value { RuntimeValue::Reference(reference) => Some( self.reference_type(reference) @@ -4440,7 +4444,7 @@ impl Machine { { return None; } - read_frame_value(&self.frame_arena, frame, function, local as u16).ok() + read_frame_value(&self.frame_arena, frame.base, function, local as u16).ok() } #[cfg(test)] @@ -4679,19 +4683,19 @@ enum InstructionFailure { fn execute_scalar( instruction: &ResolvedInstruction, arena: &mut FrameArena, - frame: Frame, + frame_base: u32, function: &ResolvedFunction, image: &ExecutionImage, heap: &Heap, ) -> Result<(), InstructionFailure> { macro_rules! binary { ($dst:expr, $lhs:expr, $rhs:expr, $body:expr) => {{ - let lhs = read_frame_value(arena, frame, function, *$lhs) + let lhs = read_frame_value(arena, frame_base, function, *$lhs) .map_err(InstructionFailure::Fault)?; - let rhs = read_frame_value(arena, frame, function, *$rhs) + let rhs = read_frame_value(arena, frame_base, function, *$rhs) .map_err(InstructionFailure::Fault)?; let value = ($body)(lhs, rhs)?; - write_frame_value(arena, frame, function, *$dst, value) + write_frame_value(arena, frame_base, function, *$dst, value) .map_err(InstructionFailure::Fault) }}; } @@ -4718,7 +4722,7 @@ fn execute_scalar( let mut values = [0.0; 16]; for (index, component) in layout.components.iter().enumerate() { let RuntimeValue::$variant(bits) = arena - .read_component_value(frame.base, *component) + .read_component_value(frame_base, *component) .map_err(InstructionFailure::Fault)? else { return Err(InstructionFailure::Fault(VmFault::InvalidValueType)); @@ -4745,7 +4749,7 @@ fn execute_scalar( { arena .$write( - frame.base, + frame_base, &function.frame_layout, *dst as usize, index, @@ -4779,7 +4783,7 @@ fn execute_scalar( .and_then(|layout| layout.components.first()) .ok_or(InstructionFailure::Fault(VmFault::InvalidValueType))?; arena - .copy_component(frame.base, source, frame.base, destination) + .copy_component(frame_base, source, frame_base, destination) .map_err(InstructionFailure::Fault)?; } Ok(()) @@ -4802,7 +4806,7 @@ fn execute_scalar( .and_then(|layout| layout.components.first()) .ok_or(InstructionFailure::Fault(VmFault::InvalidValueType))?; arena - .copy_component(frame.base, source, frame.base, destination) + .copy_component(frame_base, source, frame_base, destination) .map_err(InstructionFailure::Fault) } ResolvedInstruction::Nop => Ok(()), @@ -4812,9 +4816,9 @@ fn execute_scalar( .get(*src as usize) .is_some_and(|value| value.kind != 8) { - let value = read_frame_value(arena, frame, function, *src) + let value = read_frame_value(arena, frame_base, function, *src) .map_err(InstructionFailure::Fault)?; - return write_frame_value(arena, frame, function, *dst, value) + return write_frame_value(arena, frame_base, function, *dst, value) .map_err(InstructionFailure::Fault); } let source = function @@ -4828,12 +4832,12 @@ fn execute_scalar( .get(*dst as usize) .ok_or(InstructionFailure::Fault(VmFault::InvalidValueType))?; arena - .copy_value(frame.base, source, frame.base, destination) + .copy_value(frame_base, source, frame_base, destination) .map_err(InstructionFailure::Fault) } ResolvedInstruction::Const { dst, constant } => write_frame_value( arena, - frame, + frame_base, function, *dst, image @@ -4842,7 +4846,7 @@ fn execute_scalar( ) .map_err(InstructionFailure::Fault), ResolvedInstruction::Null { dst } => { - write_frame_value(arena, frame, function, *dst, RuntimeValue::Null) + write_frame_value(arena, frame_base, function, *dst, RuntimeValue::Null) .map_err(InstructionFailure::Fault) } ResolvedInstruction::MathUnary { @@ -4851,7 +4855,7 @@ fn execute_scalar( dst, src, } => { - let source = read_frame_value(arena, frame, function, *src) + let source = read_frame_value(arena, frame_base, function, *src) .map_err(InstructionFailure::Fault)?; let value = match (*form, source) { (3, RuntimeValue::F32(bits)) => RuntimeValue::F32( @@ -4862,7 +4866,7 @@ fn execute_scalar( ), _ => return Err(InstructionFailure::Fault(VmFault::InvalidValueType)), }; - write_frame_value(arena, frame, function, *dst, value) + write_frame_value(arena, frame_base, function, *dst, value) .map_err(InstructionFailure::Fault) } ResolvedInstruction::MathBinary { @@ -4890,10 +4894,10 @@ fn execute_scalar( .get(*dst as usize) .ok_or(InstructionFailure::Fault(VmFault::InvalidValueType))? .kind; - let source = read_frame_value(arena, frame, function, *src) + let source = read_frame_value(arena, frame_base, function, *src) .map_err(InstructionFailure::Fault)?; let value = convert_with_signedness(source, destination, *form)?; - write_frame_value(arena, frame, function, *dst, value) + write_frame_value(arena, frame_base, function, *dst, value) .map_err(InstructionFailure::Fault) } ResolvedInstruction::Add { @@ -4952,10 +4956,10 @@ fn execute_scalar( Arithmetic::Rem )), ResolvedInstruction::Neg { form, dst, src } => { - let source = read_frame_value(arena, frame, function, *src) + let source = read_frame_value(arena, frame_base, function, *src) .map_err(InstructionFailure::Fault)?; let value = negate(*form, source)?; - write_frame_value(arena, frame, function, *dst, value) + write_frame_value(arena, frame_base, function, *dst, value) .map_err(InstructionFailure::Fault) } ResolvedInstruction::BitAnd { @@ -5065,7 +5069,7 @@ fn execute_scalar( binary!(dst, lhs, rhs, |a, b| Ok(RuntimeValue::Bool(a != b))) } ResolvedInstruction::StringLength { dst, string } => { - let string = read_frame_value(arena, frame, function, *string) + let string = read_frame_value(arena, frame_base, function, *string) .map_err(InstructionFailure::Fault)?; let value = text::length(image, heap, string).map_err(|error| match error { text::TextError::Trap(trap) => InstructionFailure::Trap(trap), @@ -5074,16 +5078,16 @@ fn execute_scalar( InstructionFailure::Fault(VmFault::CorruptLifecycle) } })?; - write_frame_value(arena, frame, function, *dst, RuntimeValue::I32(value)) + write_frame_value(arena, frame_base, function, *dst, RuntimeValue::I32(value)) .map_err(InstructionFailure::Fault) } ResolvedInstruction::StringGet { dst, string, index } => { - let index_value = read_frame_value(arena, frame, function, *index) + let index_value = read_frame_value(arena, frame_base, function, *index) .map_err(InstructionFailure::Fault)?; let RuntimeValue::I32(index) = index_value else { return Err(InstructionFailure::Fault(VmFault::InvalidValueType)); }; - let string = read_frame_value(arena, frame, function, *string) + let string = read_frame_value(arena, frame_base, function, *string) .map_err(InstructionFailure::Fault)?; let value = text::get(image, heap, string, index).map_err(|error| match error { text::TextError::Trap(trap) => InstructionFailure::Trap(trap), @@ -5092,7 +5096,7 @@ fn execute_scalar( InstructionFailure::Fault(VmFault::CorruptLifecycle) } })?; - write_frame_value(arena, frame, function, *dst, RuntimeValue::Char(value)) + write_frame_value(arena, frame_base, function, *dst, RuntimeValue::Char(value)) .map_err(InstructionFailure::Fault) } _ => Err(InstructionFailure::Fault(VmFault::UnsupportedInstruction)),