Resolves array subscripts and computes the flat index for `arr_reg` with subscripts read from registers starting at `first_sub_reg`. Returns `Some((heap_idx, flat_idx))` on success, or `None` if an exception was set.
(
&mut self,
arr_reg: Register,
first_sub_reg: Register,
heap: &Heap,
)
| 299 | /// |
| 300 | /// Returns `Some((heap_idx, flat_idx))` on success, or `None` if an exception was set. |
| 301 | fn resolve_array_index( |
| 302 | &mut self, |
| 303 | arr_reg: Register, |
| 304 | first_sub_reg: Register, |
| 305 | heap: &Heap, |
| 306 | ) -> Option<(usize, usize)> { |
| 307 | let arr_ptr = DatumPtr::from(self.get_reg(arr_reg)); |
| 308 | let heap_idx = arr_ptr.heap_index(); |
| 309 | let array = match heap.get(heap_idx) { |
| 310 | HeapDatum::Array(a) => a, |
| 311 | _ => unreachable!("Register must point to an array"), |
| 312 | }; |
| 313 | |
| 314 | let ndims = array.dimensions.len(); |
| 315 | let (_, first_idx) = first_sub_reg.to_parts(); |
| 316 | let mut subscripts = Vec::with_capacity(ndims); |
| 317 | for i in 0..unchecked_usize_as_u8(ndims) { |
| 318 | let sub_reg = Register::local(first_idx + i).unwrap(); |
| 319 | subscripts.push(self.get_reg(sub_reg) as i32); |
| 320 | } |
| 321 | |
| 322 | match array.flat_index(&subscripts) { |
| 323 | Ok(flat_idx) => Some((heap_idx, flat_idx)), |
| 324 | Err(e) => { |
| 325 | self.set_exception(e); |
| 326 | None |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | /// Registers that the instruction being processed threw an exception `message`. |
| 332 | /// |
no test coverage detected