RefType variant definition.
| 366 | |
| 367 | /// RefType variant definition. |
| 368 | struct RefVariant { |
| 369 | // Constructors. |
| 370 | RefVariant() noexcept { setData<void>(TypeCode::ExternRef); } |
| 371 | RefVariant(const ValType &VT) noexcept { setData<void>(VT); } |
| 372 | RefVariant(const ValType &VT, const RefVariant &Val) noexcept { |
| 373 | setData(VT, Val.getPtr<void>()); |
| 374 | } |
| 375 | |
| 376 | template <typename T> RefVariant(const T *P) noexcept { |
| 377 | setData(TypeCode::ExternRef, reinterpret_cast<const void *>(P)); |
| 378 | } |
| 379 | template <typename T> RefVariant(const ValType &VT, const T *P) noexcept { |
| 380 | setData(VT, reinterpret_cast<const void *>(P)); |
| 381 | } |
| 382 | RefVariant(const Runtime::Instance::FunctionInstance *P) noexcept { |
| 383 | setData(TypeCode::FuncRef, reinterpret_cast<const void *>(P)); |
| 384 | } |
| 385 | RefVariant(const Runtime::Instance::StructInstance *P) noexcept { |
| 386 | setData(TypeCode::StructRef, reinterpret_cast<const void *>(P)); |
| 387 | } |
| 388 | RefVariant(const Runtime::Instance::ArrayInstance *P) noexcept { |
| 389 | setData(TypeCode::ArrayRef, reinterpret_cast<const void *>(P)); |
| 390 | } |
| 391 | |
| 392 | // Getter for type. |
| 393 | const ValType &getType() const noexcept { |
| 394 | return reinterpret_cast<const ValType &>(toArray()[0]); |
| 395 | } |
| 396 | ValType &getType() noexcept { |
| 397 | return reinterpret_cast<ValType &>(toArray()[0]); |
| 398 | } |
| 399 | |
| 400 | // Getter for pointer. |
| 401 | template <typename T> T *getPtr() const noexcept { |
| 402 | return reinterpret_cast<T *>(toArray()[1]); |
| 403 | } |
| 404 | |
| 405 | // Check whether it is null. |
| 406 | bool isNull() const { return getPtr<void>() == nullptr; } |
| 407 | |
| 408 | // Getter for the raw data. |
| 409 | uint64x2_t getRawData() const noexcept { return Data; } |
| 410 | |
| 411 | private: |
| 412 | // Helper function for converting data to array. |
| 413 | const std::array<uint64_t, 2> &toArray() const noexcept { |
| 414 | return reinterpret_cast<const std::array<uint64_t, 2> &>(Data); |
| 415 | } |
| 416 | std::array<uint64_t, 2> &toArray() noexcept { |
| 417 | return reinterpret_cast<std::array<uint64_t, 2> &>(Data); |
| 418 | } |
| 419 | |
| 420 | // Helper function to set the content. |
| 421 | template <typename T> |
| 422 | void setData(const ValType &VT, const T *Ptr = nullptr) noexcept { |
| 423 | getType() = VT; |
| 424 | toArray()[1] = reinterpret_cast<uintptr_t>(Ptr); |
| 425 | } |
no outgoing calls