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
43typedef struct wasmtime_anyref {
46 uint64_t store_id;
48 uint32_t __private1;
50 uint32_t __private2;
54
57static inline void wasmtime_anyref_set_null(wasmtime_anyref_t *ref) {
58 ref->store_id = 0;
59}
60
66static inline bool wasmtime_anyref_is_null(const wasmtime_anyref_t *ref) {
67 return ref->store_id == 0;
68}
69
77WASM_API_EXTERN void wasmtime_anyref_clone(wasmtime_context_t *context,
78 const wasmtime_anyref_t *anyref,
80
94WASM_API_EXTERN void wasmtime_anyref_unroot(wasmtime_context_t *context,
96
104WASM_API_EXTERN void wasmtime_anyref_from_raw(wasmtime_context_t *context,
105 uint32_t raw,
106 wasmtime_anyref_t *out);
107
118WASM_API_EXTERN uint32_t wasmtime_anyref_to_raw(wasmtime_context_t *context,
119 const wasmtime_anyref_t *ref);
120
129WASM_API_EXTERN void wasmtime_anyref_from_i31(wasmtime_context_t *context,
130 uint32_t i31val,
131 wasmtime_anyref_t *out);
132
142WASM_API_EXTERN bool wasmtime_anyref_i31_get_u(wasmtime_context_t *context,
143 const wasmtime_anyref_t *anyref,
144 uint32_t *dst);
145
155WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
156 const wasmtime_anyref_t *anyref,
157 int32_t *dst);
158
180typedef struct wasmtime_externref {
183 uint64_t store_id;
185 uint32_t __private1;
187 uint32_t __private2;
191
194static inline void wasmtime_externref_set_null(wasmtime_externref_t *ref) {
195 ref->store_id = 0;
196}
197
203static inline bool wasmtime_externref_is_null(const wasmtime_externref_t *ref) {
204 return ref->store_id == 0;
205}
206
230WASM_API_EXTERN bool wasmtime_externref_new(wasmtime_context_t *context,
231 void *data,
232 void (*finalizer)(void *),
234
241WASM_API_EXTERN void *wasmtime_externref_data(wasmtime_context_t *context,
242 const wasmtime_externref_t *data);
243
253WASM_API_EXTERN void wasmtime_externref_clone(wasmtime_context_t *context,
254 const wasmtime_externref_t *ref,
256
268WASM_API_EXTERN void wasmtime_externref_unroot(wasmtime_context_t *context,
270
279 uint32_t raw,
281
292WASM_API_EXTERN uint32_t wasmtime_externref_to_raw(
293 wasmtime_context_t *context, const wasmtime_externref_t *ref);
294
296typedef uint8_t wasmtime_valkind_t;
298#define WASMTIME_I32 0
300#define WASMTIME_I64 1
302#define WASMTIME_F32 2
304#define WASMTIME_F64 3
306#define WASMTIME_V128 4
309#define WASMTIME_FUNCREF 5
312#define WASMTIME_EXTERNREF 6
315#define WASMTIME_ANYREF 7
316
319typedef uint8_t wasmtime_v128[16];
320
331typedef union wasmtime_valunion {
333 int32_t i32;
335 int64_t i64;
352
358static inline void wasmtime_funcref_set_null(wasmtime_func_t *func) {
359 func->store_id = 0;
360}
361
367static inline bool wasmtime_funcref_is_null(const wasmtime_func_t *func) {
368 return func->store_id == 0;
369}
370
384typedef union wasmtime_val_raw {
388 int32_t i32;
392 int64_t i64;
412 uint32_t anyref;
420 uint32_t externref;
427 void *funcref;
429
430// Assert that the shape of this type is as expected since it needs to match
431// Rust.
432static inline void __wasmtime_val_assertions() {
433 static_assert(sizeof(wasmtime_valunion_t) >= 16 &&
434 sizeof(wasmtime_valunion_t) <= 24,
435 "should be 16 bytes plus a pointer large (plus alignment on "
436 "some platforms)");
437 static_assert(__alignof(wasmtime_valunion_t) == 8,
438 "should be 8-byte aligned");
439 static_assert(sizeof(wasmtime_val_raw_t) == 16, "should be 16 bytes large");
440 static_assert(__alignof(wasmtime_val_raw_t) == 8, "should be 8-byte aligned");
441}
442
460typedef struct wasmtime_val {
466
478WASM_API_EXTERN void wasmtime_val_unroot(wasmtime_context_t *context,
479 wasmtime_val_t *val);
480
488WASM_API_EXTERN void wasmtime_val_clone(wasmtime_context_t *context,
489 const wasmtime_val_t *src,
490 wasmtime_val_t *dst);
491
492#ifdef __cplusplus
493} // extern "C"
494#endif
495
496#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:43
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:48
void * __private3
Internal to Wasmtime.
Definition: val.h:52
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:50
uint64_t store_id
Definition: val.h:46
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:180
uint64_t store_id
Definition: val.h:183
uint32_t __private2
Internal to Wasmtime.
Definition: val.h:187
void * __private3
Internal to Wasmtime.
Definition: val.h:189
uint32_t __private1
Internal to Wasmtime.
Definition: val.h:185
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:460
wasmtime_valkind_t kind
Discriminant of which field of of is valid.
Definition: val.h:462
wasmtime_valunion_t of
Container for the extern item's value.
Definition: val.h:464
Container for possible wasm values.
Definition: val.h:384
uint32_t anyref
Definition: val.h:412
uint32_t externref
Definition: val.h:420
float32_t f32
Definition: val.h:396
float64_t f64
Definition: val.h:400
int32_t i32
Definition: val.h:388
wasmtime_v128 v128
Definition: val.h:404
int64_t i64
Definition: val.h:392
void * funcref
Definition: val.h:427
Container for different kinds of wasm values.
Definition: val.h:331
wasmtime_func_t funcref
Definition: val.h:348
int32_t i32
Field used if wasmtime_val_t::kind is WASMTIME_I32.
Definition: val.h:333
wasmtime_v128 v128
Field used if wasmtime_val_t::kind is WASMTIME_V128.
Definition: val.h:350
float32_t f32
Field used if wasmtime_val_t::kind is WASMTIME_F32.
Definition: val.h:337
int64_t i64
Field used if wasmtime_val_t::kind is WASMTIME_I64.
Definition: val.h:335
float64_t f64
Field used if wasmtime_val_t::kind is WASMTIME_F64.
Definition: val.h:339
wasmtime_anyref_t anyref
Field used if wasmtime_val_t::kind is WASMTIME_ANYREF.
Definition: val.h:341
wasmtime_externref_t externref
Field used if wasmtime_val_t::kind is WASMTIME_EXTERNREF.
Definition: val.h:343
uint8_t wasmtime_valkind_t
Discriminant stored in wasmtime_val::kind.
Definition: val.h:296
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:319
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