33 static void finalizer(
void *ptr) {
34 std::unique_ptr<std::any> _ptr(
static_cast<std::any *
>(ptr));
47 void *ptr = std::make_unique<std::any>(std::move(val)).release();
50 fprintf(stderr,
"failed to allocate a new externref");
200 Val(std::optional<Func> func);
204 Val(std::optional<ExternRef> ptr) : val{} {
213 Val(std::optional<AnyRef> ptr) : val{} {
218 wasmtime_anyref_set_null(&val.
of.
anyref);
240 return ValKind::FuncRef;
242 return ValKind::ExternRef;
244 return ValKind::AnyRef;
246 return ValKind::V128;
305 if (wasmtime_externref_is_null(&val.
of.
externref)) {
322 if (wasmtime_anyref_is_null(&val.
of.
anyref)) {
335 std::optional<Func>
funcref()
const;
Representation of a WebAssembly anyref value.
Definition: val.hh:82
const wasmtime_anyref_t * raw() const
Definition: val.hh:115
static AnyRef i31(Store::Context cx, uint32_t value)
Definition: val.hh:93
void unroot(Store::Context cx)
Definition: val.hh:108
AnyRef clone(Store::Context cx)
Creates a new AnyRef which is separately rooted from this one.
Definition: val.hh:100
std::optional< int32_t > i31(Store::Context cx) const
If this is an i31, get the value sign-extended.
Definition: val.hh:126
std::optional< uint32_t > u31(Store::Context cx) const
If this is an i31, get the value zero-extended.
Definition: val.hh:118
AnyRef(wasmtime_anyref_t val)
Creates a new AnyRef directly from its C-API representation.
Definition: val.hh:89
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
const wasmtime_externref_t * raw() const
Definition: val.hh:76
ExternRef clone(Store::Context cx)
Creates a new ExternRef which is separately rooted from this one.
Definition: val.hh:56
void unroot(Store::Context cx)
Definition: val.hh:69
ExternRef(Store::Context cx, T val)
Definition: val.hh:46
std::any & data(Store::Context cx)
Returns the underlying host data associated with this ExternRef.
Definition: val.hh:63
Representation of a WebAssembly function.
Definition: wasmtime.hh:347
A WebAssembly global.
Definition: wasmtime.hh:707
An interior pointer into a Store.
Definition: store.hh:60
A WebAssembly table.
Definition: wasmtime.hh:766
Representation of a generic WebAssembly value.
Definition: val.hh:160
Val(int32_t i32)
Creates a new i32 WebAssembly value.
Definition: val.hh:175
Val(float f32)
Creates a new f32 WebAssembly value.
Definition: val.hh:185
float f32() const
Definition: val.hh:271
std::optional< AnyRef > anyref(Store::Context cx) const
Definition: val.hh:318
int32_t i32() const
Definition: val.hh:253
double f64() const
Definition: val.hh:280
int64_t i64() const
Definition: val.hh:262
void unroot(Store::Context cx)
Unroots any GC references this Val points to within the cx provided.
Definition: val.hh:338
V128 v128() const
Definition: val.hh:289
ValKind kind() const
Returns the kind of value that this value has.
Definition: val.hh:229
Val(int64_t i64)
Creates a new i64 WebAssembly value.
Definition: val.hh:180
std::optional< ExternRef > externref(Store::Context cx) const
Definition: val.hh:301
Val(const V128 &v128)
Creates a new v128 WebAssembly value.
Definition: val.hh:195
Val(std::optional< ExternRef > ptr)
Creates a new externref value.
Definition: val.hh:204
Val(double f64)
Creates a new f64 WebAssembly value.
Definition: val.hh:190
Val(std::optional< AnyRef > ptr)
Creates a new anyref value.
Definition: val.hh:213
std::optional< Func > funcref() const
Definition: wasmtime.hh:659
Container for the v128 WebAssembly type.
Definition: val.hh:135
V128()
Creates a new zero-value v128.
Definition: val.hh:140
wasmtime_v128 v128
The little-endian bytes of the v128 value.
Definition: val.hh:137
V128(const wasmtime_v128 &v)
Creates a new V128 from its C API representation.
Definition: val.hh:143
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:39
A host-defined un-forgeable reference to pass into WebAssembly.
Definition: val.h:174
Container for different kinds of wasm values.
Definition: val.h:441
wasmtime_valkind_t kind
Discriminant of which field of of is valid.
Definition: val.h:443
wasmtime_valunion_t of
Container for the extern item's value.
Definition: val.h:445
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:321
wasmtime_v128 v128
Field used if wasmtime_val_t::kind is WASMTIME_V128.
Definition: val.h:338
float32_t f32
Field used if wasmtime_val_t::kind is WASMTIME_F32.
Definition: val.h:325
int64_t i64
Field used if wasmtime_val_t::kind is WASMTIME_I64.
Definition: val.h:323
float64_t f64
Field used if wasmtime_val_t::kind is WASMTIME_F64.
Definition: val.h:327
wasmtime_anyref_t anyref
Field used if wasmtime_val_t::kind is WASMTIME_ANYREF.
Definition: val.h:329
wasmtime_externref_t externref
Field used if wasmtime_val_t::kind is WASMTIME_EXTERNREF.
Definition: val.h:331
#define WASMTIME_EXTERNREF
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an externref.
Definition: val.h:300
void wasmtime_anyref_unroot(wasmtime_context_t *context, wasmtime_anyref_t *ref)
Unroots the ref provided within the context.
#define WASMTIME_ANYREF
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an anyref.
Definition: val.h:303
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.
#define WASMTIME_I32
Value of wasmtime_valkind_t meaning that wasmtime_val_t is an i32.
Definition: val.h:286
void wasmtime_anyref_clone(wasmtime_context_t *context, 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 ...
uint8_t wasmtime_v128[16]
A 128-bit value representing the WebAssembly v128 type. Bytes are stored in little-endian order.
Definition: val.h:307
#define WASMTIME_F32
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f32.
Definition: val.h:290
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:297
#define WASMTIME_F64
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a f64.
Definition: val.h:292
void wasmtime_externref_unroot(wasmtime_context_t *context, wasmtime_externref_t *ref)
Unroots the pointer ref from the context provided.
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_val_unroot(wasmtime_context_t *context, wasmtime_val_t *val)
Unroot the value contained by val.
void wasmtime_externref_clone(wasmtime_context_t *context, 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:288
#define WASMTIME_V128
Value of wasmtime_valkind_t meaning that wasmtime_val_t is a v128.
Definition: val.h:294