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>
13#include <wasmtime/store.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
40typedef struct wasmtime_component_resource_any
42
50WASM_API_EXTERN
52 const wasmtime_component_resource_any_t *resource);
53
66WASM_API_EXTERN
68 const wasmtime_component_resource_any_t *resource);
69
72WASM_API_EXTERN
74 const wasmtime_component_resource_any_t *resource);
75
88WASM_API_EXTERN
91
97WASM_API_EXTERN
100
116typedef struct wasmtime_component_resource_host
118
129WASM_API_EXTERN
131wasmtime_component_resource_host_new(bool owned, uint32_t rep, uint32_t ty);
132
141WASM_API_EXTERN
143 const wasmtime_component_resource_host_t *resource);
144
149WASM_API_EXTERN
151 const wasmtime_component_resource_host_t *resource);
152
157WASM_API_EXTERN
159 const wasmtime_component_resource_host_t *resource);
160
163WASM_API_EXTERN
165 const wasmtime_component_resource_host_t *resource);
166
171WASM_API_EXTERN
174
186WASM_API_EXTERN
190
195WASM_API_EXTERN
199
202
205#define WASMTIME_COMPONENT_BOOL 0
208#define WASMTIME_COMPONENT_S8 1
211#define WASMTIME_COMPONENT_U8 2
214#define WASMTIME_COMPONENT_S16 3
217#define WASMTIME_COMPONENT_U16 4
220#define WASMTIME_COMPONENT_S32 5
223#define WASMTIME_COMPONENT_U32 6
226#define WASMTIME_COMPONENT_S64 7
229#define WASMTIME_COMPONENT_U64 8
232#define WASMTIME_COMPONENT_F32 9
235#define WASMTIME_COMPONENT_F64 10
238#define WASMTIME_COMPONENT_CHAR 11
241#define WASMTIME_COMPONENT_STRING 12
244#define WASMTIME_COMPONENT_LIST 13
247#define WASMTIME_COMPONENT_RECORD 14
250#define WASMTIME_COMPONENT_TUPLE 15
253#define WASMTIME_COMPONENT_VARIANT 16
256#define WASMTIME_COMPONENT_ENUM 17
259#define WASMTIME_COMPONENT_OPTION 18
262#define WASMTIME_COMPONENT_RESULT 19
265#define WASMTIME_COMPONENT_FLAGS 20
268#define WASMTIME_COMPONENT_RESOURCE 21
269
272
273#define DECLARE_VEC(name, type) \
274 \
275 typedef struct name { \
276 \
277 size_t size; \
278 \
279 type *data; \
280 } name##_t; \
281 \
282 \
283 WASM_API_EXTERN void name##_new(name##_t *out, size_t size, \
284 const type *ptr); \
285 \
286 WASM_API_EXTERN void name##_new_empty(name##_t *out); \
287 \
288 WASM_API_EXTERN void name##_new_uninit(name##_t *out, size_t size); \
289 \
290 WASM_API_EXTERN void name##_copy(name##_t *dst, const name##_t *src); \
291 \
292 WASM_API_EXTERN void name##_delete(name##_t *value);
293
299
300#undef DECLARE_VEC
301
303typedef struct {
309
311typedef struct {
313 bool is_ok;
318
321typedef union {
325 int8_t s8;
327 uint8_t u8;
329 int16_t s16;
331 uint16_t u16;
333 int32_t s32;
335 uint32_t u32;
337 int64_t s64;
339 uint64_t u64;
345 uint32_t character;
373
382
391
406WASM_API_EXTERN wasmtime_component_val_t *
408
416
422WASM_API_EXTERN void
425
437WASM_API_EXTERN void
439
440#ifdef __cplusplus
441} // extern "C"
442#endif
443
444#endif // WASMTIME_FEATURE_COMPONENT_MODEL
445
446#endif // WASMTIME_COMPONENT_VAL_H
WASM_API_EXTERN void wasmtime_component_resource_host_delete(wasmtime_component_resource_host_t *resource)
Deallocates 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:116
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...
WASM_API_EXTERN 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.
WASM_API_EXTERN void wasmtime_component_resource_any_delete(wasmtime_component_resource_any_t *resource)
Deallocates a component resource.
WASM_API_EXTERN 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.
WASM_API_EXTERN 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:40
uint8_t wasmtime_component_valkind_t
Discriminant used in wasmtime_component_val_t::kind.
Definition: component/val.h:201
WASM_API_EXTERN wasmtime_component_resource_type_t * wasmtime_component_resource_any_type(const wasmtime_component_resource_any_t *resource)
Gets the type of a component resource.
WASM_API_EXTERN wasmtime_component_resource_host_t * wasmtime_component_resource_host_clone(const wasmtime_component_resource_host_t *resource)
Clones a host-defined component resource.
WASM_API_EXTERN 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.
WASM_API_EXTERN 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.
WASM_API_EXTERN void wasmtime_component_val_free(wasmtime_component_val_t *ptr)
Deallocates the heap-allocated value at ptr.
WASM_API_EXTERN wasmtime_error_t * wasmtime_component_resource_any_drop(wasmtime_context_t *ctx, const wasmtime_component_resource_any_t *resource)
Drops a component resource.
struct wasmtime_component_val wasmtime_component_val_t
Represents possible runtime values which a component function can either consume or produce.
WASM_API_EXTERN 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.
WASM_API_EXTERN uint32_t wasmtime_component_resource_host_type(const wasmtime_component_resource_host_t *resource)
Gets the "type" of a host-defined component resource.
WASM_API_EXTERN uint32_t wasmtime_component_resource_host_rep(const wasmtime_component_resource_host_t *resource)
Gets the "rep" of a host-defined component resource.
WASM_API_EXTERN wasmtime_component_resource_any_t * wasmtime_component_resource_any_clone(const wasmtime_component_resource_any_t *resource)
Clones a component resource.
WASM_API_EXTERN void wasmtime_component_val_delete(wasmtime_component_val_t *value)
Deallocates any memory owned by value.
WASM_API_EXTERN 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.
Build-time defines for how the C API was built.
struct wasmtime_component_resource_type wasmtime_component_resource_type_t
Represents the type of a component resource.
Definition: resource.h:21
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:376
wasmtime_component_valunion_t of
Value of type kind.
Definition: component/val.h:380
wasmtime_component_valkind_t kind
The type discriminant.
Definition: component/val.h:378
A vec of a wasm_name_t
Definition: component/val.h:298
A vec of a struct wasmtime_component_val
Definition: component/val.h:294
A pair of a name and a value that represents one entry in a value with kind WASMTIME_COMPONENT_RECORD...
Definition: component/val.h:385
wasmtime_component_val_t val
The value of this entry.
Definition: component/val.h:389
wasm_name_t name
The name of this entry.
Definition: component/val.h:387
A vec of a struct wasmtime_component_valrecord_entry
Definition: component/val.h:296
Represents a result type.
Definition: component/val.h:311
bool is_ok
The discriminant of the result.
Definition: component/val.h:313
struct wasmtime_component_val * val
Definition: component/val.h:316
A vec of a struct wasmtime_component_val
Definition: component/val.h:297
Represents a variant type.
Definition: component/val.h:303
struct wasmtime_component_val * val
The payload of the variant.
Definition: component/val.h:307
wasm_name_t discriminant
The discriminant of the variant.
Definition: component/val.h:305
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:321
uint16_t u16
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U16.
Definition: component/val.h:331
wasm_name_t string
Definition: component/val.h:348
int64_t s64
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S64.
Definition: component/val.h:337
bool boolean
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_BOOL.
Definition: component/val.h:323
wasmtime_component_resource_any_t * resource
Definition: component/val.h:371
wasmtime_component_valvariant_t variant
Definition: component/val.h:358
uint32_t u32
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U32.
Definition: component/val.h:335
wasmtime_component_vallist_t list
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_LIST.
Definition: component/val.h:350
int32_t s32
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S32.
Definition: component/val.h:333
float32_t f32
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_F32.
Definition: component/val.h:341
float64_t f64
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_F64.
Definition: component/val.h:343
struct wasmtime_component_val * option
Definition: component/val.h:363
int16_t s16
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S16.
Definition: component/val.h:329
uint8_t u8
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U8.
Definition: component/val.h:327
wasmtime_component_valrecord_t record
Definition: component/val.h:353
uint64_t u64
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_U64.
Definition: component/val.h:339
wasmtime_component_valresult_t result
Definition: component/val.h:366
uint32_t character
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_CHAR.
Definition: component/val.h:345
wasmtime_component_valflags_t flags
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_FLAGS.
Definition: component/val.h:368
wasmtime_component_valtuple_t tuple
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_TUPLE.
Definition: component/val.h:355
int8_t s8
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_S8.
Definition: component/val.h:325
wasm_name_t enumeration
Field used if wasmtime_component_val_t::kind is WASMTIME_COMPONENT_ENUM.
Definition: component/val.h:360
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