MCPcopy Create free account
hub / github.com/explodingcamera/tinywasm / init_globals

Method init_globals

crates/tinywasm/src/store/mod.rs:370–394  ·  view source on GitHub ↗

Add globals to the store, returning their addresses in the store

(
        &mut self,
        out: &mut Vec<Addr>,
        new_globals: &[Global],
        func_addrs: &[FuncAddr],
    )

Source from the content-addressed store, hash-verified

368
369 /// Add globals to the store, returning their addresses in the store
370 pub(crate) fn init_globals(
371 &mut self,
372 out: &mut Vec<Addr>,
373 new_globals: &[Global],
374 func_addrs: &[FuncAddr],
375 ) -> Result<()> {
376 let start = self.state.globals.len() as Addr;
377 out.reserve_exact(new_globals.len());
378 self.state.globals.reserve_exact(new_globals.len());
379
380 for (i, global) in new_globals.iter().enumerate() {
381 let value = match self.eval_const(&global.init, out, func_addrs) {
382 Ok(val) => val,
383 Err(e) => {
384 cold_path();
385 return Err(e);
386 }
387 };
388
389 self.state.globals.push(GlobalInstance::new(global.ty, value));
390 out.push(start + i as Addr);
391 }
392
393 Ok(())
394 }
395
396 fn elem_addr(&self, item: &ElementItem, globals: &[Addr], funcs: &[FuncAddr]) -> Result<Option<u32>> {
397 let res = match item {

Callers 1

instantiate_no_startMethod · 0.80

Calls 3

eval_constMethod · 0.80
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected