Wasmtime
gc.h
Go to the documentation of this file.
1
11#ifndef WASMTIME_GC_H
12#define WASMTIME_GC_H
13
14#include <wasmtime/val.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
35typedef struct wasmtime_eqref {
38 uint64_t store_id;
40 uint32_t __private1;
42 uint32_t __private2;
46
48static inline void wasmtime_eqref_set_null(wasmtime_eqref_t *ref) {
49 ref->store_id = 0;
50}
51
53static inline bool wasmtime_eqref_is_null(const wasmtime_eqref_t *ref) {
54 return ref->store_id == 0;
55}
56
62WASM_API_EXTERN void wasmtime_eqref_clone(const wasmtime_eqref_t *eqref,
63 wasmtime_eqref_t *out);
64
71WASM_API_EXTERN void wasmtime_eqref_unroot(wasmtime_eqref_t *ref);
72
79WASM_API_EXTERN void wasmtime_eqref_to_anyref(const wasmtime_eqref_t *eqref,
81
90WASM_API_EXTERN void wasmtime_eqref_from_i31(wasmtime_context_t *context,
91 uint32_t i31val,
92 wasmtime_eqref_t *out);
93
100WASM_API_EXTERN bool wasmtime_eqref_is_i31(wasmtime_context_t *context,
101 const wasmtime_eqref_t *eqref);
102
112WASM_API_EXTERN bool wasmtime_eqref_i31_get_u(wasmtime_context_t *context,
113 const wasmtime_eqref_t *eqref,
114 uint32_t *dst);
115
125WASM_API_EXTERN bool wasmtime_eqref_i31_get_s(wasmtime_context_t *context,
126 const wasmtime_eqref_t *eqref,
127 int32_t *dst);
128
129// ============================================================================
130// StructRef
131// ============================================================================
132
140
142#define WASMTIME_STORAGE_KIND_I8 9
144#define WASMTIME_STORAGE_KIND_I16 10
145
153typedef struct wasmtime_field_type {
162
171typedef struct wasmtime_struct_type wasmtime_struct_type_t;
172
183WASM_API_EXTERN wasmtime_struct_type_t *
185 const wasmtime_field_type_t *fields, size_t nfields);
186
191
201typedef struct wasmtime_struct_ref_pre wasmtime_struct_ref_pre_t;
202
211WASM_API_EXTERN wasmtime_struct_ref_pre_t *
213 const wasmtime_struct_type_t *ty);
214
218WASM_API_EXTERN void
220
233typedef struct wasmtime_structref {
235 uint64_t store_id;
237 uint32_t __private1;
239 uint32_t __private2;
243
245static inline void wasmtime_structref_set_null(wasmtime_structref_t *ref) {
246 ref->store_id = 0;
247}
248
250static inline bool wasmtime_structref_is_null(const wasmtime_structref_t *ref) {
251 return ref->store_id == 0;
252}
253
267 const wasmtime_val_t *fields, size_t nfields, wasmtime_structref_t *out);
268
272WASM_API_EXTERN void
275
280
284WASM_API_EXTERN void
286 wasmtime_anyref_t *out);
287
291WASM_API_EXTERN void
293 wasmtime_eqref_t *out);
294
305WASM_API_EXTERN wasmtime_error_t *
307 const wasmtime_structref_t *structref, size_t index,
308 wasmtime_val_t *out);
309
321WASM_API_EXTERN wasmtime_error_t *
323 const wasmtime_structref_t *structref,
324 size_t index, const wasmtime_val_t *val);
325
331WASM_API_EXTERN bool wasmtime_eqref_is_struct(wasmtime_context_t *context,
332 const wasmtime_eqref_t *eqref);
333
341WASM_API_EXTERN bool wasmtime_eqref_as_struct(wasmtime_context_t *context,
342 const wasmtime_eqref_t *eqref,
344
345#ifdef __cplusplus
346} // extern "C"
347#endif
348
349#endif // WASMTIME_GC_H
WASM_API_EXTERN wasmtime_error_t * wasmtime_structref_set_field(wasmtime_context_t *context, const wasmtime_structref_t *structref, size_t index, const wasmtime_val_t *val)
Set a field of a struct.
WASM_API_EXTERN void wasmtime_struct_type_delete(wasmtime_struct_type_t *ty)
Delete a struct type.
struct wasmtime_field_type wasmtime_field_type_t
Convenience alias for wasmtime_field_type.
struct wasmtime_struct_type wasmtime_struct_type_t
An opaque handle to a WebAssembly struct type definition.
Definition: gc.h:171
WASM_API_EXTERN wasmtime_struct_type_t * wasmtime_struct_type_new(const wasm_engine_t *engine, const wasmtime_field_type_t *fields, size_t nfields)
Create a new struct type.
WASM_API_EXTERN void wasmtime_structref_clone(const wasmtime_structref_t *structref, wasmtime_structref_t *out)
Clone a structref, creating a new root.
WASM_API_EXTERN bool wasmtime_eqref_is_struct(wasmtime_context_t *context, const wasmtime_eqref_t *eqref)
Test whether an eqref is a structref.
WASM_API_EXTERN void wasmtime_structref_unroot(wasmtime_structref_t *ref)
Unroot a structref to allow garbage collection.
WASM_API_EXTERN void wasmtime_structref_to_eqref(const wasmtime_structref_t *structref, wasmtime_eqref_t *out)
Upcast a structref to an eqref.
WASM_API_EXTERN void wasmtime_eqref_to_anyref(const wasmtime_eqref_t *eqref, wasmtime_anyref_t *out)
Upcast an eqref to an anyref.
WASM_API_EXTERN void wasmtime_eqref_unroot(wasmtime_eqref_t *ref)
Unroot an eqref to allow garbage collection.
struct wasmtime_eqref wasmtime_eqref_t
Convenience alias for wasmtime_eqref.
struct wasmtime_struct_ref_pre wasmtime_struct_ref_pre_t
An opaque, pre-allocated, and registered struct layout for faster allocation.
Definition: gc.h:201
uint8_t wasmtime_storage_kind_t
Discriminant for storage types in struct/array field types.
Definition: gc.h:139
WASM_API_EXTERN bool wasmtime_eqref_as_struct(wasmtime_context_t *context, const wasmtime_eqref_t *eqref, wasmtime_structref_t *out)
Downcast an eqref to a structref.
WASM_API_EXTERN bool wasmtime_eqref_i31_get_u(wasmtime_context_t *context, const wasmtime_eqref_t *eqref, uint32_t *dst)
Get the eqref's underlying i31ref value, zero extended.
WASM_API_EXTERN void wasmtime_eqref_clone(const wasmtime_eqref_t *eqref, wasmtime_eqref_t *out)
Clone an eqref, creating a new root.
WASM_API_EXTERN wasmtime_error_t * wasmtime_structref_field(wasmtime_context_t *context, const wasmtime_structref_t *structref, size_t index, wasmtime_val_t *out)
Read a field from a struct.
WASM_API_EXTERN bool wasmtime_eqref_i31_get_s(wasmtime_context_t *context, const wasmtime_eqref_t *eqref, int32_t *dst)
Get the eqref's underlying i31ref value, sign extended.
WASM_API_EXTERN void wasmtime_struct_ref_pre_delete(wasmtime_struct_ref_pre_t *pre)
Delete a struct pre-allocator.
WASM_API_EXTERN wasmtime_error_t * wasmtime_structref_new(wasmtime_context_t *context, const wasmtime_struct_ref_pre_t *pre, const wasmtime_val_t *fields, size_t nfields, wasmtime_structref_t *out)
Allocate a new struct instance.
WASM_API_EXTERN void wasmtime_structref_to_anyref(const wasmtime_structref_t *structref, wasmtime_anyref_t *out)
Upcast a structref to an anyref.
WASM_API_EXTERN wasmtime_struct_ref_pre_t * wasmtime_struct_ref_pre_new(wasmtime_context_t *context, const wasmtime_struct_type_t *ty)
Create a new struct pre-allocator.
WASM_API_EXTERN bool wasmtime_eqref_is_i31(wasmtime_context_t *context, const wasmtime_eqref_t *eqref)
Test whether this eqref is an i31ref.
WASM_API_EXTERN void wasmtime_eqref_from_i31(wasmtime_context_t *context, uint32_t i31val, wasmtime_eqref_t *out)
Create a new i31ref value.
struct wasmtime_structref wasmtime_structref_t
Convenience alias for wasmtime_structref.
Compilation environment and configuration.
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:47
An interior pointer into a wasmtime_store_t which is used as "context" for many functions.
A WebAssembly eqref value.
Definition: gc.h:35
void * __private3
Internal to Wasmtime.
Definition: gc.h:44
uint32_t __private2
Internal to Wasmtime.
Definition: gc.h:42
uint64_t store_id
Definition: gc.h:38
uint32_t __private1
Internal to Wasmtime.
Definition: gc.h:40
Errors generated by Wasmtime.
Describes the type and mutability of a struct field or array element.
Definition: gc.h:153
wasmtime_storage_kind_t kind
Definition: gc.h:157
bool mutable_
Definition: gc.h:160
A WebAssembly structref value.
Definition: gc.h:233
uint32_t __private2
Internal to Wasmtime.
Definition: gc.h:239
void * __private3
Internal to Wasmtime.
Definition: gc.h:241
uint32_t __private1
Internal to Wasmtime.
Definition: gc.h:237
uint64_t store_id
Internal metadata.
Definition: gc.h:235
Container for different kinds of wasm values.
Definition: val.h:541