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/conf.h>
13#include <wasmtime/extern.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
20typedef uint8_t wasmtime_valkind_t;
22#define WASMTIME_I32 0
24#define WASMTIME_I64 1
26#define WASMTIME_F32 2
28#define WASMTIME_F64 3
30#define WASMTIME_V128 4
33#define WASMTIME_FUNCREF 5
34
35#ifdef WASMTIME_FEATURE_GC
38#define WASMTIME_EXTERNREF 6
41#define WASMTIME_ANYREF 7
44#define WASMTIME_EXNREF 8
45#endif // WASMTIME_FEATURE_GC
46
49typedef uint8_t wasmtime_v128[16];
50
51#ifdef WASMTIME_FEATURE_GC
77typedef struct wasmtime_anyref {
80 uint64_t store_id;
82 uint32_t __private1;
84 uint32_t __private2;
88
103typedef struct wasmtime_exnref {
106 uint64_t store_id;
108 uint32_t __private1;
110 uint32_t __private2;
114
136typedef struct wasmtime_externref {
139 uint64_t store_id;
141 uint32_t __private1;
143 uint32_t __private2;
147
163typedef struct wasmtime_eqref {
166 uint64_t store_id;
168 uint32_t __private1;
170 uint32_t __private2;
174
187typedef struct wasmtime_structref {
189 uint64_t store_id;
191 uint32_t __private1;
193 uint32_t __private2;
197
210typedef struct wasmtime_arrayref {
212 uint64_t store_id;
214 uint32_t __private1;
216 uint32_t __private2;
220
221#endif // WASMTIME_FEATURE_GC
222
233typedef union wasmtime_valunion {
235 int32_t i32;
237 int64_t i64;
242#ifdef WASMTIME_FEATURE_GC
249#endif // WASMTIME_FEATURE_GC
254 wasmtime_func_t funcref;
258
264static inline void wasmtime_funcref_set_null(wasmtime_func_t *func) {
265 func->store_id = 0;
266}
267
273static inline bool wasmtime_funcref_is_null(const wasmtime_func_t *func) {
274 return func->store_id == 0;
275}
276
290typedef union wasmtime_val_raw {
294 int32_t i32;
298 int64_t i64;
311#ifdef WASMTIME_FEATURE_GC
319 uint32_t anyref;
327 uint32_t externref;
335 uint32_t exnref;
336#endif // WASMTIME_FEATURE_GC
343 void *funcref;
345
346// Assert that the shape of this type is as expected since it needs to match
347// Rust.
348static inline void __wasmtime_val_assertions() {
349 static_assert(sizeof(wasmtime_valunion_t) >= 16 &&
350 sizeof(wasmtime_valunion_t) <= 24,
351 "should be 16 bytes plus a pointer large (plus alignment on "
352 "some platforms)");
353 static_assert(__alignof(wasmtime_valunion_t) == 8,
354 "should be 8-byte aligned");
355 static_assert(sizeof(wasmtime_val_raw_t) == 16, "should be 16 bytes large");
356 static_assert(__alignof(wasmtime_val_raw_t) == 8, "should be 8-byte aligned");
357}
358
376typedef struct wasmtime_val {
382
395WASM_API_EXTERN void wasmtime_val_unroot(wasmtime_val_t *val);
396
404WASM_API_EXTERN void wasmtime_val_clone(const wasmtime_val_t *src,
405 wasmtime_val_t *dst);
406
407#ifdef __cplusplus
408} // extern "C"
409#endif
410
411#endif // WASMTIME_VAL_H
Build-time defines for how the C API was built.
Definition of wasmtime_extern_t and external items.
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:77
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:82
void * __private3
Internal to Wasmtime.
Definition: val.h:86
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:84
uint64_t store_id
Definition: val.h:80
A WebAssembly arrayref value.
Definition: val.h:210
uint64_t store_id
Internal metadata.
Definition: val.h:212
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:216
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:214
void * __private3
Internal to Wasmtime.
Definition: val.h:218
A WebAssembly eqref value.
Definition: val.h:163
void * __private3
Internal to Wasmtime.
Definition: val.h:172
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:170
uint64_t store_id
Definition: val.h:166
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:168
A WebAssembly exception reference value.
Definition: val.h:103
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:110
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:108
void * __private3
Internal to Wasmtime.
Definition: val.h:112
uint64_t store_id
Definition: val.h:106
A host-defined un-forgeable reference to pass into WebAssembly.
Definition: val.h:136
uint64_t store_id
Definition: val.h:139
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:143
void * __private3
Internal to Wasmtime.
Definition: val.h:145
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:141
Representation of a function in Wasmtime.
Definition: extern.h:26
uint64_t store_id
Definition: extern.h:32
A WebAssembly structref value.
Definition: val.h:187
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:193
void * __private3
Internal to Wasmtime.
Definition: val.h:195
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:191
uint64_t store_id
Internal metadata.
Definition: val.h:189
Container for different kinds of wasm values.
Definition: val.h:376
wasmtime_valkind_t kind
Discriminant of which field of of is valid.
Definition: val.h:378
wasmtime_valunion_t of
Container for the extern item's value.
Definition: val.h:380
Container for possible wasm values.
Definition: val.h:290
uint32_t anyref
Definition: val.h:319
uint32_t externref
Definition: val.h:327
float32_t f32
Definition: val.h:302
float64_t f64
Definition: val.h:306
int32_t i32
Definition: val.h:294
wasmtime_v128 v128
Definition: val.h:310
int64_t i64
Definition: val.h:298
uint32_t exnref
Definition: val.h:335
Container for different kinds of wasm values.
Definition: val.h:233
int32_t i32
Field used if wasmtime_val_t::kind is WASMTIME_I32.
Definition: val.h:235
wasmtime_v128 v128
Field used if wasmtime_val_t::kind is WASMTIME_V128.
Definition: val.h:256
float32_t f32
Field used if wasmtime_val_t::kind is WASMTIME_F32.
Definition: val.h:239
int64_t i64
Field used if wasmtime_val_t::kind is WASMTIME_I64.
Definition: val.h:237
wasmtime_exnref_t exnref
Field used if wasmtime_val_t::kind is WASMTIME_EXNREF.
Definition: val.h:248
float64_t f64
Field used if wasmtime_val_t::kind is WASMTIME_F64.
Definition: val.h:241
wasmtime_anyref_t anyref
Field used if wasmtime_val_t::kind is WASMTIME_ANYREF.
Definition: val.h:244
wasmtime_externref_t externref
Field used if wasmtime_val_t::kind is WASMTIME_EXTERNREF.
Definition: val.h:246
uint8_t wasmtime_valkind_t
Discriminant stored in wasmtime_val::kind.
Definition: val.h:20
struct wasmtime_externref wasmtime_externref_t
Convenience alias for wasmtime_externref.
union wasmtime_valunion wasmtime_valunion_t
Convenience alias for wasmtime_valunion.
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:49
struct wasmtime_arrayref wasmtime_arrayref_t
Convenience alias for wasmtime_arrayref.
WASM_API_EXTERN void wasmtime_val_unroot(wasmtime_val_t *val)
Unroot the value contained by val.
struct wasmtime_eqref wasmtime_eqref_t
Convenience alias for wasmtime_eqref.
WASM_API_EXTERN void wasmtime_val_clone(const wasmtime_val_t *src, wasmtime_val_t *dst)
Clones the value pointed to by src into the dst provided.
struct wasmtime_val wasmtime_val_t
Convenience alias for wasmtime_val_t.
struct wasmtime_exnref wasmtime_exnref_t
Convenience alias for wasmtime_exnref.
struct wasmtime_anyref wasmtime_anyref_t
Convenience alias for wasmtime_anyref.
struct wasmtime_structref wasmtime_structref_t
Convenience alias for wasmtime_structref.
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