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

Method arrayNew

lib/executor/engine/refInstr.cpp:464–491  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462}
463
464Expect<RefVariant>
465Executor::arrayNew(Runtime::StackManager &StackMgr, const uint32_t TypeIdx,
466 const uint32_t Length,
467 Span<const ValVariant> Args) const noexcept {
468 /// TODO: The array and struct instances are currently owned by the module
469 /// instance because they refer to the defined types of the module instances.
470 /// This may be changed after applying the garbage collection mechanism.
471 const auto &VType = getArrayStorageTypeByIdx(StackMgr, TypeIdx);
472 WasmEdge::Runtime::Instance::ArrayInstance *Inst = nullptr;
473 Runtime::Instance::ModuleInstance *ModInst =
474 const_cast<Runtime::Instance::ModuleInstance *>(StackMgr.getModule());
475 if (Args.size() == 0) {
476 // New and fill with default values.
477 auto InitVal = VType.isRefType()
478 ? ValVariant(RefVariant(toBottomType(StackMgr, VType)))
479 : ValVariant(static_cast<uint128_t>(0U));
480 Inst = ModInst->newArray(TypeIdx, Length, InitVal);
481 } else if (Args.size() == 1) {
482 // Create and fill with the argument value.
483 Inst = ModInst->newArray(TypeIdx, Length, packVal(VType, Args[0]));
484 } else {
485 // Create with arguments.
486 Inst = ModInst->newArray(
487 TypeIdx,
488 packVals(VType, std::vector<ValVariant>(Args.begin(), Args.end())));
489 }
490 return RefVariant(Inst->getDefType(), Inst);
491}
492
493Expect<RefVariant>
494Executor::arrayNewData(Runtime::StackManager &StackMgr, const uint32_t TypeIdx,

Callers

nothing calls this directly

Calls 8

RefVariantClass · 0.85
isRefTypeMethod · 0.80
newArrayMethod · 0.80
getModuleMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getDefTypeMethod · 0.45

Tested by

no test coverage detected