Wasmtime
_eqref_class.hh
1#ifndef WASMTIME_EQREF_CLASS_HH
2#define WASMTIME_EQREF_CLASS_HH
3
4#include <optional>
5#include <wasmtime/conf.h>
6
7#ifdef WASMTIME_FEATURE_GC
8
9#include <wasmtime/_store_class.hh>
10#include <wasmtime/eqref.h>
11#include <wasmtime/helpers.hh>
12#include <wasmtime/types/val.hh>
13
14namespace wasmtime {
15
16class AnyRef;
17class StructRef;
18class ArrayRef;
19
29class EqRef {
30 WASMTIME_REF_WRAPPER(EqRef, wasmtime_eqref);
31
32public:
34 static EqRef from_i31(Store::Context cx, uint32_t val) {
36 wasmtime_eqref_from_i31(cx.capi(), val, &out);
37 return EqRef(out);
38 }
39
41 bool is_i31(Store::Context cx) const {
42 return wasmtime_eqref_is_i31(cx.capi(), &raw);
43 }
44
47 std::optional<uint32_t> i31_get_u(Store::Context cx) const {
48 uint32_t dst;
49 if (wasmtime_eqref_i31_get_u(cx.capi(), &raw, &dst))
50 return dst;
51 return std::nullopt;
52 }
53
56 std::optional<int32_t> i31_get_s(Store::Context cx) const {
57 int32_t dst;
58 if (wasmtime_eqref_i31_get_s(cx.capi(), &raw, &dst))
59 return dst;
60 return std::nullopt;
61 }
62
64 bool is_struct(Store::Context cx) const {
65 return wasmtime_eqref_is_struct(cx.capi(), &raw);
66 }
67
69 bool is_array(Store::Context cx) const {
70 return wasmtime_eqref_is_array(cx.capi(), &raw);
71 }
72
75
77 //
78 // as_struct() defined after StructRef below.
79 std::optional<StructRef> as_struct(Store::Context cx) const;
80
82 //
83 // as_array() defined after ArrayRef below.
84 std::optional<ArrayRef> as_array(Store::Context cx) const;
85
89 bool ok = wasmtime_eqref_type(cx.capi(), &raw, &out);
90 assert(ok);
91 return HeapType(out);
92 }
93};
94
95} // namespace wasmtime
96
97#endif // WASMTIME_FEATURE_GC
98
99#endif // WASMTIME_EQREF_CLASS_HH
Representation of a WebAssembly anyref value.
Definition: _anyref_class.hh:23
Representation of a WebAssembly eqref value.
Definition: _eqref_class.hh:29
std::optional< ArrayRef > as_array(Store::Context cx) const
Downcast this eqref into an arrayref.
std::optional< uint32_t > i31_get_u(Store::Context cx) const
Definition: _eqref_class.hh:47
std::optional< StructRef > as_struct(Store::Context cx) const
Downcast this eqref into a structref.
bool is_i31(Store::Context cx) const
Returns true if this eqref is an i31ref.
Definition: _eqref_class.hh:41
static EqRef from_i31(Store::Context cx, uint32_t val)
Create an eqref from an i31 value.
Definition: _eqref_class.hh:34
HeapType ty(Store::Context cx) const
Returns the type of this EqRef.
Definition: _eqref_class.hh:87
AnyRef to_anyref() const
Upcast this eqref to an anyref.
bool is_array(Store::Context cx) const
Returns true if this eqref is an arrayref.
Definition: _eqref_class.hh:69
bool is_struct(Store::Context cx) const
Returns true if this eqref is a structref.
Definition: _eqref_class.hh:64
std::optional< int32_t > i31_get_s(Store::Context cx) const
Definition: _eqref_class.hh:56
Representation of a heap type in WebAssembly.
Definition: types/val.hh:22
An interior pointer into a Store.
Definition: _store_class.hh:65
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: _store_class.hh:183
Build-time defines for how the C API was built.
WASM_API_EXTERN bool wasmtime_eqref_is_struct(wasmtime_context_t *context, const wasmtime_eqref_t *eqref)
Test whether an eqref is a structref.
WASM_API_EXTERN bool wasmtime_eqref_is_array(wasmtime_context_t *context, const wasmtime_eqref_t *eqref)
Test whether an eqref is an arrayref.
WASM_API_EXTERN bool wasmtime_eqref_type(wasmtime_context_t *context, const wasmtime_eqref_t *eqref, wasmtime_heaptype_t *out)
Returns the type of the specified eqref.
WASM_API_EXTERN bool wasmtime_eqref_i31_get_u(wasmtime_context_t *context, const wasmtime_eqref_t *eqref, uint32_t *dst)
Get the eqref's underlying i31ref value, zero extended.
WASM_API_EXTERN bool wasmtime_eqref_i31_get_s(wasmtime_context_t *context, const wasmtime_eqref_t *eqref, int32_t *dst)
Get the eqref's underlying i31ref value, sign extended.
WASM_API_EXTERN bool wasmtime_eqref_is_i31(wasmtime_context_t *context, const wasmtime_eqref_t *eqref)
Test whether this eqref is an i31ref.
WASM_API_EXTERN void wasmtime_eqref_from_i31(wasmtime_context_t *context, uint32_t i31val, wasmtime_eqref_t *out)
Create a new i31ref value.
A WebAssembly eqref value.
Definition: val.h:163
A WebAssembly heap type.
Definition: types/val.h:76