MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / structNew

Method structNew

lib/executor/engine/refInstr.cpp:412–436  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

410}
411
412Expect<RefVariant>
413Executor::structNew(Runtime::StackManager &StackMgr, const uint32_t TypeIdx,
414 Span<const ValVariant> Args) const noexcept {
415 /// TODO: The array and struct instances are currently owned by the module
416 /// instance because they refer to the defined types of the module instances.
417 /// This may be changed after applying the garbage collection mechanism.
418 const auto &CompType = getCompositeTypeByIdx(StackMgr, TypeIdx);
419 uint32_t N = static_cast<uint32_t>(CompType.getFieldTypes().size());
420 Runtime::Instance::ModuleInstance *ModInst =
421 const_cast<Runtime::Instance::ModuleInstance *>(StackMgr.getModule());
422 std::vector<ValVariant> Vals(N);
423 for (uint32_t I = 0; I < N; I++) {
424 const auto &VType = CompType.getFieldTypes()[I].getStorageType();
425 if (Args.size() > 0) {
426 Vals[I] = packVal(VType, Args[I]);
427 } else {
428 Vals[I] = VType.isRefType()
429 ? ValVariant(RefVariant(toBottomType(StackMgr, VType)))
430 : ValVariant(static_cast<uint128_t>(0U));
431 }
432 }
433 WasmEdge::Runtime::Instance::StructInstance *Inst =
434 ModInst->newStruct(TypeIdx, std::move(Vals));
435 return RefVariant(Inst->getDefType(), Inst);
436}
437
438Expect<ValVariant> Executor::structGet(Runtime::StackManager &StackMgr,
439 const RefVariant Ref,

Callers

nothing calls this directly

Calls 6

RefVariantClass · 0.85
isRefTypeMethod · 0.80
newStructMethod · 0.80
sizeMethod · 0.45
getModuleMethod · 0.45
getDefTypeMethod · 0.45

Tested by

no test coverage detected