1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* \file wasmtime/types/structref.h
*
* APIs for interacting with WebAssembly GC `structref` type in Wasmtime.
*/
#ifndef WASMTIME_TYPES_STRUCTREF_H
#define WASMTIME_TYPES_STRUCTREF_H
#include <wasm.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief Discriminant for storage types in struct/array field types.
*/
typedef uint8_t wasmtime_storage_type_kind_t;
/// \brief An 8-bit packed integer
#define WASMTIME_STORAGE_TYPE_KIND_I8 0
/// \brief A 16-bit packed integer
#define WASMTIME_STORAGE_TYPE_KIND_I16 1
/// \brief A regular value type (i32, f64, funcref, etc).
#define WASMTIME_STORAGE_TYPE_KIND_VALTYPE 2
/// \brief A storage type descriptor for struct/array fields.
typedef struct wasmtime_storage_type {
/// The kind of storage type this is.
wasmtime_storage_type_kind_t kind;
/// if `kind` is `WASMTIME_STORAGE_TYPE_KIND_VALTYPE`, then this is
/// set.
wasm_valtype_t *valtype;
} wasmtime_storage_type_t;
/// \brief Clone a storage type into `out`.
WASM_API_EXTERN void
wasmtime_storage_type_clone(const wasmtime_storage_type_t *storage,
wasmtime_storage_type_t *out);
/// \brief Delete a storage type.
///
/// Only necessary for `WASMTIME_STORAGE_TYPE_KIND_VALTYPE` when the value
/// type is a concrete reference type.
WASM_API_EXTERN void
wasmtime_storage_type_delete(wasmtime_storage_type_t *storage);
/**
* \typedef wasmtime_field_type_t
* \brief Convenience alias for #wasmtime_field_type
*
* \struct wasmtime_field_type
* \brief Describes the type and mutability of a struct field or array element.
*/
typedef struct wasmtime_field_type {
/// Whether this field is mutable. `true` for mutable, `false` for
/// immutable.
bool mutable_;
/// The type stored in this field.
wasmtime_storage_type_t storage;
} wasmtime_field_type_t;
/// \brief Clone a field type into `out`.
WASM_API_EXTERN void
wasmtime_field_type_clone(const wasmtime_field_type_t *field,
wasmtime_field_type_t *out);
/// \brief Delete a field type.
WASM_API_EXTERN void wasmtime_field_type_delete(wasmtime_field_type_t *field);
/**
* \brief An opaque handle to a WebAssembly struct type definition.
*
* A struct type describes the fields of a struct. It is used to create a
* #wasmtime_struct_ref_pre_t, which can then allocate struct instances.
*
* Owned. Must be deleted with #wasmtime_struct_type_delete.
*/
typedef struct wasmtime_struct_type wasmtime_struct_type_t;
/**
* \brief Create a new struct type.
*
* \param engine The engine to register the type with.
* \param fields Pointer to an array of field type descriptors.
* \param nfields Number of fields.
*
* \return Returns a new struct type, or NULL on error (e.g. invalid field
* types).
*/
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);
/**
* \brief Clone a struct type.
*/
WASM_API_EXTERN wasmtime_struct_type_t *
wasmtime_struct_type_copy(const wasmtime_struct_type_t *ty);
/**
* \brief Delete a struct type.
*/
WASM_API_EXTERN void wasmtime_struct_type_delete(wasmtime_struct_type_t *ty);
/// \brief Get the number of fields in a struct type.
WASM_API_EXTERN size_t
wasmtime_struct_type_num_fields(const wasmtime_struct_type_t *ty);
/// \brief Get the field type of a struct type's field by index.
///
/// Returns `true` if `index` is in-bounds and `out` is filled in. Returns
/// `false` if `index` is out-of-bounds and `out` is not modified.
WASM_API_EXTERN bool
wasmtime_struct_type_field(const wasmtime_struct_type_t *ty, size_t index,
wasmtime_field_type_t *out);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // WASMTIME_TYPES_STRUCTREF_H