| 2751 | } |
| 2752 | |
| 2753 | WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext * |
| 2754 | WasmEdge_TableInstanceCreateWithInit(const WasmEdge_TableTypeContext *TabType, |
| 2755 | const WasmEdge_Value Value) noexcept { |
| 2756 | try { |
| 2757 | if (TabType) { |
| 2758 | // Comparison of the value types needs the module instance to retrieve the |
| 2759 | // function type index after applying the typed function reference |
| 2760 | // proposal. It's impossible to do this without refactoring. Therefore |
| 2761 | // simply match the FuncRef and ExternRef here. |
| 2762 | const AST::TableType &TType = *fromTabTypeCxt(TabType); |
| 2763 | WasmEdge::ValType GotType = genValType(Value.Type); |
| 2764 | if (TType.getRefType().isFuncRefType() != GotType.isFuncRefType()) { |
| 2765 | spdlog::error(WasmEdge::ErrCode::Value::RefTypeMismatch); |
| 2766 | spdlog::error( |
| 2767 | WasmEdge::ErrInfo::InfoMismatch(TType.getRefType(), GotType)); |
| 2768 | return nullptr; |
| 2769 | } |
| 2770 | auto Val = WasmEdge::ValVariant( |
| 2771 | to_WasmEdge_128_t<WasmEdge::uint128_t>(Value.Value)) |
| 2772 | .get<WasmEdge::RefVariant>(); |
| 2773 | if (!TType.getRefType().isNullableRefType() && Val.isNull()) { |
| 2774 | spdlog::error(WasmEdge::ErrCode::Value::NonNullRequired); |
| 2775 | return nullptr; |
| 2776 | } |
| 2777 | return toTabCxt( |
| 2778 | new WasmEdge::Runtime::Instance::TableInstance(TType, Val)); |
| 2779 | } |
| 2780 | } catch (...) { |
| 2781 | handleCAPIError(); |
| 2782 | } |
| 2783 | return nullptr; |
| 2784 | } |
| 2785 | |
| 2786 | WASMEDGE_CAPI_EXPORT const WasmEdge_TableTypeContext * |
| 2787 | WasmEdge_TableInstanceGetTableType( |