| 462 | } |
| 463 | |
| 464 | Expect<RefVariant> |
| 465 | Executor::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 | |
| 493 | Expect<RefVariant> |
| 494 | Executor::arrayNewData(Runtime::StackManager &StackMgr, const uint32_t TypeIdx, |
nothing calls this directly
no test coverage detected