33 static void finalizer(
void *ptr) {
34 std::unique_ptr<std::any> _ptr(
static_cast<std::any *
>(ptr));
56 wasmtime_externref_set_null(&other.val);
63 wasmtime_externref_set_null(&other.val);
75 void *ptr = std::make_unique<std::any>(val).release();
78 fprintf(stderr,
"failed to allocate a new externref");
92 wasmtime_externref_set_null(&val);
127 wasmtime_anyref_set_null(&other.val);
134 wasmtime_anyref_set_null(&other.val);
152 wasmtime_anyref_set_null(&val);
244 Val(std::optional<Func> func);
248 Val(std::optional<ExternRef> ptr) : val{} {
252 wasmtime_externref_set_null(&ptr->val);
258 Val(std::optional<AnyRef> ptr) : val{} {
262 wasmtime_anyref_set_null(&ptr->val);
264 wasmtime_anyref_set_null(&val.
of.
anyref);
288 other.val.of.i32 = 0;
296 other.val.of.i32 = 0;
315 return ValKind::FuncRef;
317 return ValKind::ExternRef;
319 return ValKind::AnyRef;
321 return ValKind::V128;
380 if (wasmtime_externref_is_null(&val.
of.
externref)) {
397 if (wasmtime_anyref_is_null(&val.
of.
anyref)) {
410 std::optional<Func>
funcref()
const;
Representation of a WebAssembly anyref value.
Definition: val.hh:105
AnyRef(AnyRef &&other)
Move constructor to move the contents of other.
Definition: val.hh:125
static AnyRef i31(Store::Context cx, uint32_t value)
Definition: val.hh:142
AnyRef & operator=(AnyRef &&other)
Move assignment to move the contents of other.
Definition: val.hh:131
AnyRef & operator=(const AnyRef &other)
Copy assignment to clone from other.
Definition: val.hh:118
std::optional< int32_t > i31(Store::Context cx) const
If this is an i31, get the value sign-extended.
Definition: val.hh:170
uint32_t borrow_raw(Store::Context cx) const
Returns wasmtime_anyref_to_raw.
Definition: val.hh:157
AnyRef(const AnyRef &other)
Copy constructor to clone other.
Definition: val.hh:115
std::optional< uint32_t > u31(Store::Context cx) const
If this is an i31, get the value zero-extended.
Definition: val.hh:162
uint32_t take_raw(Store::Context cx)
Definition: val.hh:150
AnyRef(wasmtime_anyref_t val)
Creates a new AnyRef directly from its C-API representation.
Definition: val.hh:112
Representation of a WebAssembly externref value.
Definition: val.hh:28
ExternRef(wasmtime_externref_t val)
Creates a new ExternRef directly from its C-API representation.
Definition: val.hh:39
ExternRef & operator=(const ExternRef &other)
Copy assignment to clone from other.
Definition: val.hh:47
ExternRef(Store::Context cx, std::any val)
Definition: val.hh:74
ExternRef & operator=(ExternRef &&other)
Move assignment to move the contents of other.
Definition: val.hh:60
ExternRef(ExternRef &&other)
Move constructor to move the contents of other.
Definition: val.hh:54
uint32_t borrow_raw(Store::Context cx) const
Returns wasmtime_externref_to_raw.
Definition: val.hh:97
ExternRef(const ExternRef &other)
Copy constructor to clone other.
Definition: val.hh:42
uint32_t take_raw(Store::Context cx)
Definition: val.hh:90
std::any & data(Store::Context cx)
Returns the underlying host data associated with this ExternRef.
Definition: val.hh:84
Representation of a WebAssembly function.
Definition: func.hh:336
A WebAssembly global.
Definition: global.hh:28
An interior pointer into a Store.
Definition: store.hh:60
wasmtime_context_t * raw_context()
Returns the raw context pointer for the C API.
Definition: store.hh:153
A WebAssembly table.
Definition: table.hh:31
Representation of a generic WebAssembly value.
Definition: val.hh:204
Val(const Val &other)
Copy constructor to clone other.
Definition: val.hh:275
Val(int32_t i32)
Creates a new i32 WebAssembly value.
Definition: val.hh:219
Val(float f32)
Creates a new f32 WebAssembly value.
Definition: val.hh:229
float f32() const
Definition: val.hh:346
int32_t i32() const
Definition: val.hh:328
double f64() const
Definition: val.hh:355
std::optional< AnyRef > anyref() const
Definition: val.hh:393
int64_t i64() const
Definition: val.hh:337
V128 v128() const
Definition: val.hh:364
ValKind kind() const
Returns the kind of value that this value has.
Definition: val.hh:304
Val(int64_t i64)
Creates a new i64 WebAssembly value.
Definition: val.hh:224
Val(const V128 &v128)
Creates a new v128 WebAssembly value.
Definition: val.hh:239
Val(std::optional< ExternRef > ptr)
Creates a new externref value.
Definition: val.hh:248
~Val()
Unroots the values in val, if any.
Definition: val.hh:301
Val(double f64)
Creates a new f64 WebAssembly value.
Definition: val.hh:234
Val & operator=(const Val &other)
Copy assignment to clone from other.
Definition: val.hh:278
Val(std::optional< AnyRef > ptr)
Creates a new anyref value.
Definition: val.hh:258
Val & operator=(Val &&other)
Move assignment to move the contents of other.
Definition: val.hh:292
std::optional< ExternRef > externref() const
Definition: val.hh:376
std::optional< Func > funcref() const
Definition: func.hh:649
Val(Val &&other)
Move constructor to move the contents of other.
Definition: val.hh:285
Container for the v128 WebAssembly type.
Definition: val.hh:179
V128()
Creates a new zero-value v128.
Definition: val.hh:184
wasmtime_v128 v128
The little-endian bytes of the v128 value.
Definition: val.hh:181
V128(const wasmtime_v128 &v)
Creates a new V128 from its C API representation.
Definition: val.hh:187
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:43
A host-defined un-forgeable reference to pass into WebAssembly.
Definition: val.h:178
Container for different kinds of wasm values.
Definition: val.h:456
wasmtime_valkind_t kind
Discriminant of which field of of is valid.
Definition: val.h:458
wasmtime_valunion_t of
Container for the extern item's value.
Definition: val.h:460
ValKind
Different kinds of types accepted by Wasmtime.
Definition: types/val.hh:16
int32_t i32
Field used if wasmtime_val_t::kind is WASMTIME_I32.
Definition: val.h:329
wasmtime_v128 v128
Field used if wasmtime_val_t::kind is WASMTIME_V128.
Definition: val.h:346
float32_t f32
Field used if wasmtime_val_t::kind is WASMTIME_F32.
Definition: val.h:333
int64_t i64
Field used if wasmtime_val_t::kind is WASMTIME_I64.
Definition: val.h:331
float64_t f64
Field used if wasmtime_val_t::kind is WASMTIME_F64.
Definition: val.h:335
wasmtime_anyref_t anyref
Field used if wasmtime_val_t::kind is WASMTIME_ANYREF.
Definition: val.h:337
wasmtime_externref_t externref
Field used if wasmtime_val_t::kind is WASMTIME_EXTERNREF.
Definition: val.h:339
#define WASMTIME_EXTERNREF
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an externref.
Definition: val.h:308
uint32_t wasmtime_externref_to_raw(wasmtime_context_t *context, const wasmtime_externref_t *ref)
Converts a wasmtime_externref_t to a raw value suitable for storing into a wasmtime_val_raw_t.
#define WASMTIME_ANYREF
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an anyref.
Definition: val.h:311
void wasmtime_val_unroot(wasmtime_val_t *val)
Unroot the value contained by val.
void wasmtime_val_clone(const wasmtime_val_t *src, wasmtime_val_t *dst)
Clones the value pointed to by src into the dst provided.
void * wasmtime_externref_data(wasmtime_context_t *context, const wasmtime_externref_t *data)
Get an externref's wrapped data.
void wasmtime_anyref_from_i31(wasmtime_context_t *context, uint32_t i31val, wasmtime_anyref_t *out)
Create a new i31ref value.
void wasmtime_anyref_unroot(wasmtime_anyref_t *ref)
Unroots the ref provided within the context.
#define WASMTIME_I32
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i32.
Definition: val.h:294
uint8_t wasmtime_v128[16]
A 128-bit value representing the WebAssembly v128 type. Bytes are stored in little-endian order.
Definition: val.h:315
#define WASMTIME_F32
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f32.
Definition: val.h:298
bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context, const wasmtime_anyref_t *anyref, int32_t *dst)
Get the anyref's underlying i31ref value, sign extended, if any.
#define WASMTIME_FUNCREF
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a funcref.
Definition: val.h:305
#define WASMTIME_F64
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f64.
Definition: val.h:300
void wasmtime_anyref_clone(const wasmtime_anyref_t *anyref, wasmtime_anyref_t *out)
Creates a new reference pointing to the same data that anyref points to (depending on the configured ...
bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context, const wasmtime_anyref_t *anyref, uint32_t *dst)
Get the anyref's underlying i31ref value, zero extended, if any.
bool wasmtime_externref_new(wasmtime_context_t *context, void *data, void(*finalizer)(void *), wasmtime_externref_t *out)
Create a new externref value.
void wasmtime_externref_unroot(wasmtime_externref_t *ref)
Unroots the pointer ref from the context provided.
uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context, const wasmtime_anyref_t *ref)
Converts a wasmtime_anyref_t to a raw value suitable for storing into a wasmtime_val_raw_t.
void wasmtime_externref_clone(const wasmtime_externref_t *ref, wasmtime_externref_t *out)
Creates a new reference pointing to the same data that ref points to (depending on the configured col...
#define WASMTIME_I64
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i64.
Definition: val.h:296
#define WASMTIME_V128
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a v128.
Definition: val.h:302