Wasmtime
component/val.h
Go to the documentation of this file.
1
2
3#ifndef WASMTIME_COMPONENT_VAL_H
4#define WASMTIME_COMPONENT_VAL_H
5
6#include <wasmtime/conf.h>
7
8#ifdef WASMTIME_FEATURE_COMPONENT_MODEL
9
10#include <stdint.h>
11#include <wasm.h>
12#include <wasmtime/store.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
23typedef struct wasmtime_component_resource_type
25
37WASM_API_EXTERN
40
47WASM_API_EXTERN
50
55WASM_API_EXTERN
59
64WASM_API_EXTERN
67
89typedef struct wasmtime_component_resource_any
91
99WASM_API_EXTERN
101 const wasmtime_component_resource_any_t *resource);
102
115WASM_API_EXTERN
117 const wasmtime_component_resource_any_t *resource);
118
121WASM_API_EXTERN
123 const wasmtime_component_resource_any_t *resource);
124
137WASM_API_EXTERN
140
146WASM_API_EXTERN
149
165typedef struct wasmtime_component_resource_host
167
178WASM_API_EXTERN
180wasmtime_component_resource_host_new(bool owned, uint32_t rep, uint32_t ty);
181
190WASM_API_EXTERN
192 const wasmtime_component_resource_host_t *resource);
193
198WASM_API_EXTERN
200 const wasmtime_component_resource_host_t *resource);
201
206WASM_API_EXTERN
208 const wasmtime_component_resource_host_t *resource);
209
212WASM_API_EXTERN
214 const wasmtime_component_resource_host_t *resource);
215
220WASM_API_EXTERN
223
235WASM_API_EXTERN
239
244WASM_API_EXTERN
248
251
254#define WASMTIME_COMPONENT_BOOL 0
257#define WASMTIME_COMPONENT_S8 1
260#define WASMTIME_COMPONENT_U8 2
263#define WASMTIME_COMPONENT_S16 3
266#define WASMTIME_COMPONENT_U16 4
269#define WASMTIME_COMPONENT_S32 5
272#define WASMTIME_COMPONENT_U32 6
275#define WASMTIME_COMPONENT_S64 7
278#define WASMTIME_COMPONENT_U64 8
281#define WASMTIME_COMPONENT_F32 9
284#define WASMTIME_COMPONENT_F64 10
287#define WASMTIME_COMPONENT_CHAR 11
290#define WASMTIME_COMPONENT_STRING 12
293#define WASMTIME_COMPONENT_LIST 13
296#define WASMTIME_COMPONENT_RECORD 14
299#define WASMTIME_COMPONENT_TUPLE 15
302#define WASMTIME_COMPONENT_VARIANT 16
305#define WASMTIME_COMPONENT_ENUM 17
308#define WASMTIME_COMPONENT_OPTION 18
311#define WASMTIME_COMPONENT_RESULT 19
314#define WASMTIME_COMPONENT_FLAGS 20
317#define WASMTIME_COMPONENT_RESOURCE 21
318
321
322#define DECLARE_VEC(name, type) \
323 \
324 typedef struct name { \
325 \
326 size_t size; \
327 \
328 type *data; \
329 } name##_t; \
330 \
331 \
332 WASM_API_EXTERN void name##_new(name##_t *out, size_t size, \
333 const type *ptr); \
334 \
335 WASM_API_EXTERN void name##_new_empty(name##_t *out); \
336 \
337 WASM_API_EXTERN void name##_new_uninit(name##_t *out, size_t size); \
338 \
339 WASM_API_EXTERN void name##_copy(name##_t *dst, const name##_t *src); \
340 \
341 WASM_API_EXTERN void name##_delete(name##_t *value);
342
348
349#undef DECLARE_VEC
350
352typedef struct {
358
360typedef struct {
362 bool is_ok;
367
370typedef union {
374 int8_t s8;
376 uint8_t u8;
378 int16_t s16;
380 uint16_t u16;
382 int32_t s32;
384 uint32_t u32;
386 int64_t s64;
388 uint64_t u64;
394 uint32_t character;
422
431
440
455WASM_API_EXTERN wasmtime_component_val_t *
457
465
471WASM_API_EXTERN void
474
486WASM_API_EXTERN void
488
489#ifdef __cplusplus
490} // extern "C"
491#endif
492
493#endif // WASMTIME_FEATURE_COMPONENT_MODEL
494
495#endif // WASMTIME_COMPONENT_VAL_H
wasmtime_component_resource_any_t * wasmtime_component_resource_any_clone(const wasmtime_component_resource_any_t *resource)
Clones a component resource.
wasmtime_component_resource_type_t * wasmtime_component_resource_type_clone(const wasmtime_component_resource_type_t *ty)
Clones a resource type.
wasmtime_component_resource_host_t * wasmtime_component_resource_host_new(bool owned, uint32_t rep, uint32_t ty)
Creates a new host-defined component resource.
wasmtime_component_val_t * wasmtime_component_val_new(wasmtime_component_val_t *val)
Allocates a new wasmtime_component_val_t on the heap, initializing it with the contents of val.
uint32_t wasmtime_component_resource_host_type(const wasmtime_component_resource_host_t *resource)
Gets the "type" of a host-defined component resource.
wasmtime_component_resource_host_t * wasmtime_component_resource_host_clone(const wasmtime_component_resource_host_t *resource)
Clones a host-defined component resource.
struct wasmtime_component_resource_host wasmtime_component_resource_host_t
Represents a host-defined component resource.
Definition: component/val.h:165
void wasmtime_component_val_clone(const wasmtime_component_val_t *src, wasmtime_component_val_t *dst)
Performs a deep copy of the provided src, storing the results into dst.
void wasmtime_component_resource_host_delete(wasmtime_component_resource_host_t *resource)
Deallocates a host-defined component resource.
struct wasmtime_component_valrecord_entry wasmtime_component_valrecord_entry_t
A pair of a name and a value that represents one entry in a value with kind WASMTIME_COMPONENT_RECORD...
bool wasmtime_component_resource_type_equal(const wasmtime_component_resource_type_t *a, const wasmtime_component_resource_type_t *b)
Compares two resource types for equality.
struct wasmtime_component_resource_type wasmtime_component_resource_type_t
Represents the type of a component resource.
Definition: component/val.h:23
wasmtime_error_t * wasmtime_component_resource_host_to_any(wasmtime_context_t *ctx, const wasmtime_component_resource_host_t *resource, wasmtime_component_resource_any_t **ret)
Same as wasmtime_component_resource_any_to_host except for converting the other way around.
bool wasmtime_component_resource_any_owned(const wasmtime_component_resource_any_t *resource)
Returns whether this resource is an own, or a borrow in the component model.
void wasmtime_component_resource_type_delete(wasmtime_component_resource_type_t *resource)
Deallocates a resource type.
wasmtime_error_t * wasmtime_component_resource_any_drop(wasmtime_context_t *ctx, const wasmtime_component_resource_any_t *resource)
Drops a component resource.
bool wasmtime_component_resource_host_owned(const wasmtime_component_resource_host_t *resource)
Returns whether this host-defined resource is an own or a borrow in the component model.
struct wasmtime_component_resource_any wasmtime_component_resource_any_t
Represents a component resource which can be either guest-owned or host-owned.
Definition: component/val.h:89
uint8_t wasmtime_component_valkind_t
Discriminant used in wasmtime_component_val_t::kind.
Definition: component/val.h:250
void wasmtime_component_val_free(wasmtime_component_val_t *ptr)
Deallocates the heap-allocated value at ptr.
void wasmtime_component_resource_any_delete(wasmtime_component_resource_any_t *resource)
Deallocates a component resource.
void wasmtime_component_val_delete(wasmtime_component_val_t *value)
Deallocates any memory owned by value.
wasmtime_component_resource_type_t * wasmtime_component_resource_type_new_host(uint32_t ty)
Creates a new resource type representing a host-defined resource.
struct wasmtime_component_val wasmtime_component_val_t
Represents possible runtime values which a component function can either consume or produce.
uint32_t wasmtime_component_resource_host_rep(const wasmtime_component_resource_host_t *resource)
Gets the "rep" of a host-defined component resource.
wasmtime_error_t * wasmtime_component_resource_any_to_host(wasmtime_context_t *ctx, const wasmtime_component_resource_any_t *resource, wasmtime_component_resource_host_t **ret)
Attempts to convert a wasmtime_component_resource_any_t into a wasmtime_component_resource_host_t.
wasmtime_component_resource_type_t * wasmtime_component_resource_any_type(const wasmtime_component_resource_any_t *resource)
Gets the type of a component resource.
Build-time defines for how the C API was built.
A list of bytes.
Definition: wasm.h:102
Represents possible runtime values which a component function can either consume or produce.
Definition: component/val.h:425
wasmtime_component_valunion_t of
Value of type kind.
Definition: component/val.h:429
wasmtime_component_valkind_t kind
The type discriminant.
Definition: component/val.h:427
A vec of a wasm_name_t
Definition: component/val.h:347
A vec of a struct wasmtime_component_val
Definition: component/val.h:343
A pair of a name and a value that represents one entry in a value with kind WASMTIME_COMPONENT_RECORD...
Definition: component/val.h:434
wasmtime_component_val_t val
The value of this entry.
Definition: component/val.h:438
wasm_name_t name
The name of this entry.
Definition: component/val.h:436
A vec of a struct wasmtime_component_valrecord_entry
Definition: component/val.h:345
Represents a result type.
Definition: component/val.h:360
bool is_ok
The discriminant of the result.
Definition: component/val.h:362
struct wasmtime_component_val * val
Definition: component/val.h:365
A vec of a struct wasmtime_component_val
Definition: component/val.h:346
Represents a variant type.
Definition: component/val.h:352
struct wasmtime_component_val * val
The payload of the variant.
Definition: component/val.h:356
wasm_name_t discriminant
The discriminant of the variant.
Definition: component/val.h:354
An interior pointer into a wasmtime_store_t which is used as "context" for many functions.
Errors generated by Wasmtime.
Represents possible runtime values which a component function can either consume or produce.
Definition: component/val.h:370
uint16_t u16
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U16.
Definition: component/val.h:380
wasm_name_t string
Definition: component/val.h:397
int64_t s64
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S64.
Definition: component/val.h:386
bool boolean
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_BOOL.
Definition: component/val.h:372
wasmtime_component_resource_any_t * resource
Definition: component/val.h:420
wasmtime_component_valvariant_t variant
Definition: component/val.h:407
uint32_t u32
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U32.
Definition: component/val.h:384
wasmtime_component_vallist_t list
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_LIST.
Definition: component/val.h:399
int32_t s32
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S32.
Definition: component/val.h:382
float32_t f32
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_F32.
Definition: component/val.h:390
float64_t f64
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_F64.
Definition: component/val.h:392
struct wasmtime_component_val * option
Definition: component/val.h:412
int16_t s16
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S16.
Definition: component/val.h:378
uint8_t u8
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U8.
Definition: component/val.h:376
wasmtime_component_valrecord_t record
Definition: component/val.h:402
uint64_t u64
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U64.
Definition: component/val.h:388
wasmtime_component_valresult_t result
Definition: component/val.h:415
uint32_t character
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_CHAR.
Definition: component/val.h:394
wasmtime_component_valflags_t flags
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_FLAGS.
Definition: component/val.h:417
wasmtime_component_valtuple_t tuple
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_TUPLE.
Definition: component/val.h:404
int8_t s8
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S8.
Definition: component/val.h:374
wasm_name_t enumeration
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_ENUM.
Definition: component/val.h:409
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