Add globals to the store, returning their addresses in the store
(
&mut self,
out: &mut Vec<Addr>,
new_globals: &[Global],
func_addrs: &[FuncAddr],
)
| 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 { |
no test coverage detected