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
13namespace wasmtime {
14
15class AnyRef;
16class StructRef;
17class ArrayRef;
18
28class EqRef {
29 WASMTIME_REF_WRAPPER(EqRef, wasmtime_eqref);
30
31public:
33 static EqRef from_i31(Store::Context cx, uint32_t val) {
35 wasmtime_eqref_from_i31(cx.capi(), val, &out);
36 return EqRef(out);
37 }
38
40 bool is_i31(Store::Context cx) const {
41 return wasmtime_eqref_is_i31(cx.capi(), &raw);
42 }
43
46 std::optional<uint32_t> i31_get_u(Store::Context cx) const {
47 uint32_t dst;
48 if (wasmtime_eqref_i31_get_u(cx.capi(), &raw, &dst))
49 return dst;
50 return std::nullopt;
51 }
52
55 std::optional<int32_t> i31_get_s(Store::Context cx) const {
56 int32_t dst;
57 if (wasmtime_eqref_i31_get_s(cx.capi(), &raw, &dst))
58 return dst;
59 return std::nullopt;
60 }
61
63 bool is_struct(Store::Context cx) const {
64 return wasmtime_eqref_is_struct(cx.capi(), &raw);
65 }
66
68 bool is_array(Store::Context cx) const {
69 return wasmtime_eqref_is_array(cx.capi(), &raw);
70 }
71
74
76 //
77 // as_struct() defined after StructRef below.
78 std::optional<StructRef> as_struct(Store::Context cx) const;
79
81 //
82 // as_array() defined after ArrayRef below.
83 std::optional<ArrayRef> as_array(Store::Context cx) const;
84};
85
86} // namespace wasmtime
87
88#endif // WASMTIME_FEATURE_GC
89
90#endif // WASMTIME_EQREF_CLASS_HH
Representation of a WebAssembly anyref value.
Definition: _anyref_class.hh:21
Representation of a WebAssembly eqref value.
Definition: _eqref_class.hh:28
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:46
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:40
static EqRef from_i31(Store::Context cx, uint32_t val)
Create an eqref from an i31 value.
Definition: _eqref_class.hh:33
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:68
bool is_struct(Store::Context cx) const
Returns true if this eqref is a structref.
Definition: _eqref_class.hh:63
std::optional< int32_t > i31_get_s(Store::Context cx) const
Definition: _eqref_class.hh:55
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_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