| 617 | } |
| 618 | |
| 619 | Expect<void> |
| 620 | Executor::arrayInitElem(Runtime::StackManager &StackMgr, const RefVariant &Ref, |
| 621 | const uint32_t TypeIdx, const uint32_t ElemIdx, |
| 622 | const uint32_t DstIdx, const uint32_t SrcIdx, |
| 623 | const uint32_t Cnt) const noexcept { |
| 624 | auto *Inst = Ref.getPtr<Runtime::Instance::ArrayInstance>(); |
| 625 | if (Inst == nullptr) { |
| 626 | return Unexpect(ErrCode::Value::AccessNullArray); |
| 627 | } |
| 628 | if (static_cast<uint64_t>(DstIdx) + static_cast<uint64_t>(Cnt) > |
| 629 | Inst->getLength()) { |
| 630 | return Unexpect(ErrCode::Value::ArrayOutOfBounds); |
| 631 | } |
| 632 | const auto &VType = getArrayStorageTypeByIdx(StackMgr, TypeIdx); |
| 633 | auto *ElemInst = getElemInstByIdx(StackMgr, ElemIdx); |
| 634 | assuming(ElemInst); |
| 635 | auto ElemSrc = ElemInst->getRefs(); |
| 636 | if (static_cast<uint64_t>(SrcIdx) + static_cast<uint64_t>(Cnt) > |
| 637 | ElemSrc.size()) { |
| 638 | return Unexpect(ErrCode::Value::TableOutOfBounds); |
| 639 | } |
| 640 | |
| 641 | auto Arr = Inst->getArray(); |
| 642 | // The value has been packed. |
| 643 | std::transform(ElemSrc.begin() + SrcIdx, ElemSrc.begin() + SrcIdx + Cnt, |
| 644 | Arr.begin() + DstIdx, |
| 645 | [&](const RefVariant &V) { return packVal(VType, V); }); |
| 646 | return {}; |
| 647 | } |
| 648 | |
| 649 | Expect<void> |
| 650 | Executor::arrayCopy(Runtime::StackManager &StackMgr, const RefVariant &DstRef, |