Wasmtime
val.h
Go to the documentation of this file.
1
7#ifndef WASMTIME_VAL_H
8#define WASMTIME_VAL_H
9
10#include <stdalign.h>
11#include <wasm.h>
12#include <wasmtime/extern.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
39typedef struct wasmtime_anyref {
42 uint64_t store_id;
44 uint32_t __private1;
46 uint32_t __private2;
48
51static inline void wasmtime_anyref_set_null(wasmtime_anyref_t *ref) {
52 ref->store_id = 0;
53}
54
60static inline bool wasmtime_anyref_is_null(const wasmtime_anyref_t *ref) {
61 return ref->store_id == 0;
62}
63
71WASM_API_EXTERN void wasmtime_anyref_clone(wasmtime_context_t *context,
72 const wasmtime_anyref_t *anyref,
74
88WASM_API_EXTERN void wasmtime_anyref_unroot(wasmtime_context_t *context,
90
98WASM_API_EXTERN void wasmtime_anyref_from_raw(wasmtime_context_t *context,
99 uint32_t raw,
100 wasmtime_anyref_t *out);
101
112WASM_API_EXTERN uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context,
113 const wasmtime_anyref_t *ref);
114
123WASM_API_EXTERN void wasmtime_anyref_from_i31(wasmtime_context_t *context,
124 uint32_t i31val,
125 wasmtime_anyref_t *out);
126
136WASM_API_EXTERN bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context,
137 const wasmtime_anyref_t *anyref,
138 uint32_t *dst);
139
149WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
150 const wasmtime_anyref_t *anyref,
151 int32_t *dst);
152
174typedef struct wasmtime_externref {
177 uint64_t store_id;
179 uint32_t __private1;
181 uint32_t __private2;
183
186static inline void wasmtime_externref_set_null(wasmtime_externref_t *ref) {
187 ref->store_id = 0;
188}
189
195static inline bool wasmtime_externref_is_null(const wasmtime_externref_t *ref) {
196 return ref->store_id == 0;
197}
198
218WASM_API_EXTERN bool wasmtime_externref_new(wasmtime_context_t *context,
219 void *data,
220 void (*finalizer)(void *),
222
229WASM_API_EXTERN void *wasmtime_externref_data(wasmtime_context_t *context,
230 const wasmtime_externref_t *data);
231
241WASM_API_EXTERN void wasmtime_externref_clone(wasmtime_context_t *context,
242 const wasmtime_externref_t *ref,
244
256WASM_API_EXTERN void wasmtime_externref_unroot(wasmtime_context_t *context,
258
267 uint32_t raw,
269
280WASM_API_EXTERN uint32_t wasmtime_externref_to_raw(
281 wasmtime_context_t *context, const wasmtime_externref_t *ref);
282
284typedef uint8_t wasmtime_valkind_t;
286#define WASMTIME_I32 0
288#define WASMTIME_I64 1
290#define WASMTIME_F32 2
292#define WASMTIME_F64 3
294#define WASMTIME_V128 4
297#define WASMTIME_FUNCREF 5
300#define WASMTIME_EXTERNREF 6
303#define WASMTIME_ANYREF 7
304
307typedef uint8_t wasmtime_v128[16];
308
319typedef union wasmtime_valunion {
321 int32_t i32;
323 int64_t i64;
340
346static inline void wasmtime_funcref_set_null(wasmtime_func_t *func) {
347 func->store_id = 0;
348}
349
355static inline bool wasmtime_funcref_is_null(const wasmtime_func_t *func) {
356 return func->store_id == 0;
357}
358
372typedef union wasmtime_val_raw {
376 int32_t i32;
380 int64_t i64;
400 uint32_t anyref;
408 uint32_t externref;
415 void *funcref;
417
418// Assert that the shape of this type is as expected since it needs to match
419// Rust.
420static inline void __wasmtime_val_assertions() {
421 static_assert(sizeof(wasmtime_valunion_t) == 16, "should be 16-bytes large");
422 static_assert(__alignof(wasmtime_valunion_t) == 8,
423 "should be 8-byte aligned");
424 static_assert(sizeof(wasmtime_val_raw_t) == 16, "should be 16 bytes large");
425 static_assert(__alignof(wasmtime_val_raw_t) == 8, "should be 8-byte aligned");
426}
427
441typedef struct wasmtime_val {
447
459WASM_API_EXTERN void wasmtime_val_unroot(wasmtime_context_t *context,
460 wasmtime_val_t *val);
461
469WASM_API_EXTERN void wasmtime_val_clone(wasmtime_context_t *context,
470 const wasmtime_val_t *src,
471 wasmtime_val_t *dst);
472
473#ifdef __cplusplus
474} // extern "C"
475#endif
476
477#endif // WASMTIME_VAL_H
Definition of wasmtime_extern_t and external items.
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:39
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:44
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:46
uint64_t store_id
Definition: val.h:42
An interior pointer into a wasmtime_store_t which is used as "context" for many functions.
A host-defined un-forgeable reference to pass into WebAssembly.
Definition: val.h:174
uint64_t store_id
Definition: val.h:177
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:181
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:179
Representation of a function in Wasmtime.
Definition: extern.h:25
uint64_t store_id
Definition: extern.h:31
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
Container for possible wasm values.
Definition: val.h:372
uint32_t anyref
Definition: val.h:400
uint32_t externref
Definition: val.h:408
float32_t f32
Definition: val.h:384
float64_t f64
Definition: val.h:388
int32_t i32
Definition: val.h:376
wasmtime_v128 v128
Definition: val.h:392
int64_t i64
Definition: val.h:380
void * funcref
Definition: val.h:415
Container for different kinds of wasm values.
Definition: val.h:319
wasmtime_func_t funcref
Definition: val.h:336
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
uint8_t wasmtime_valkind_t
Discriminant stored in wasmtime_val::kind.
Definition: val.h:284
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.
struct wasmtime_externref wasmtime_externref_t
Convenience alias for wasmtime_externref.
void wasmtime_anyref_unroot(wasmtime_context_t *context, wasmtime_anyref_t *ref)
Unroots the ref provided within the context.
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.
union wasmtime_valunion wasmtime_valunion_t
Convenience alias for wasmtime_valunion.
void wasmtime_val_clone(wasmtime_context_t *context, const wasmtime_val_t *src, wasmtime_val_t *dst)
Clones the value pointed to by src into the dst provided.
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 ...
union wasmtime_val_raw wasmtime_val_raw_t
Convenience alias for wasmtime_val_raw.
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
void wasmtime_externref_from_raw(wasmtime_context_t *context, uint32_t raw, wasmtime_externref_t *out)
Converts a raw externref value coming from wasmtime_val_raw_t into a wasmtime_externref_t.
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.
void wasmtime_externref_unroot(wasmtime_context_t *context, wasmtime_externref_t *ref)
Unroots the pointer ref from the context provided.
struct wasmtime_val wasmtime_val_t
Convenience alias for wasmtime_val_t.
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_anyref_from_raw(wasmtime_context_t *context, uint32_t raw, wasmtime_anyref_t *out)
Converts a raw anyref value coming from wasmtime_val_raw_t into a wasmtime_anyref_t.
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(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...
struct wasmtime_anyref wasmtime_anyref_t
Convenience alias for wasmtime_anyref.
float float32_t
A type definition for a 32-bit float.
Definition: wasm.h:44
double float64_t
A type definition for a 64-bit float.
Definition: wasm.h:45