MCPcopy Index your code
hub / github.com/endbasic/endbasic / resolve_array_index

Method resolve_array_index

core/src/vm/context.rs:301–329  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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 ///

Callers 2

do_load_arrayMethod · 0.80
do_store_arrayMethod · 0.80

Calls 8

get_regMethod · 0.80
heap_indexMethod · 0.80
to_partsMethod · 0.80
pushMethod · 0.80
flat_indexMethod · 0.80
set_exceptionMethod · 0.80
getMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected