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

Method get_array_var

core/src/vm/mod.rs:207–230  ·  view source on GitHub ↗

Returns the array element named `key` from `vars`, decoding values from `read_raw`.

(
        &self,
        image: &Image,
        key: &SymbolKey,
        vars: &HashMap<SymbolKey, GlobalVarInfo>,
        subscripts: &[i32],
        read_raw: fn(&Context, u8) -> u64,
    )

Source from the content-addressed store, hash-verified

205
206 /// Returns the array element named `key` from `vars`, decoding values from `read_raw`.
207 fn get_array_var(
208 &self,
209 image: &Image,
210 key: &SymbolKey,
211 vars: &HashMap<SymbolKey, GlobalVarInfo>,
212 subscripts: &[i32],
213 read_raw: fn(&Context, u8) -> u64,
214 ) -> GetGlobalResult<Option<ConstantDatum>> {
215 let Some(info) = vars.get(key) else {
216 return Ok(None);
217 };
218 if info.ndims == 0 {
219 return Err(GetGlobalError::IsScalar(key.to_string()));
220 }
221 let raw = read_raw(&self.context, info.reg);
222 let ptr = DatumPtr::from(raw);
223 let heap_idx = ptr.heap_index();
224 let HeapDatum::Array(a) = self.heap.get(heap_idx) else {
225 panic!("Array variable does not point to an array on the heap");
226 };
227 let flat_idx = a.flat_index(subscripts).map_err(GetGlobalError::SubscriptOutOfBounds)?;
228 let v = a.values[flat_idx];
229 Ok(Some(ConstantDatum::from_raw(v, info.subtype, &image.constants, &self.heap)))
230 }
231
232 /// Creates a new VM with the given `upcalls_by_name` as the available built-in callables.
233 pub fn new(upcalls_by_name: HashMap<SymbolKey, Rc<dyn Callable>>) -> Self {

Callers 2

get_global_arrayMethod · 0.80
get_program_arrayMethod · 0.80

Calls 3

heap_indexMethod · 0.80
flat_indexMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected