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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/**
* \file wasmtime/arrayref.h
*
* APIs for interacting with WebAssembly `arrayref` type in Wasmtime.
*/
#ifndef WASMTIME_ARRAYREF_H
#define WASMTIME_ARRAYREF_H
#include <wasmtime/conf.h>
#ifdef WASMTIME_FEATURE_GC
#include <wasmtime/types/arrayref.h>
#include <wasmtime/val.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* \brief An opaque pre-allocated array layout for fast allocation.
*
* Created from a #wasmtime_array_type_t and a store context. Reusable for
* allocating many array instances of the same type.
*
* Owned. Must be deleted with #wasmtime_array_ref_pre_delete.
*/
typedef struct wasmtime_array_ref_pre wasmtime_array_ref_pre_t;
/**
* \brief Create a new array pre-allocator.
*
* \param context The store context.
* \param ty The array type (not consumed; caller retains ownership).
*
* \return Returns a new array ref pre-allocator.
*/
WASM_API_EXTERN wasmtime_array_ref_pre_t *
wasmtime_array_ref_pre_new(wasmtime_context_t *context,
const wasmtime_array_type_t *ty);
/**
* \brief Delete an array pre-allocator.
*/
WASM_API_EXTERN void
wasmtime_array_ref_pre_delete(wasmtime_array_ref_pre_t *pre);
/// \brief Initialize the `ref` to a null `arrayref` value.
static inline void wasmtime_arrayref_set_null(wasmtime_arrayref_t *ref) {
ref->store_id = 0;
}
/// \brief Returns whether the provided `ref` is a null `arrayref` value.
static inline bool wasmtime_arrayref_is_null(const wasmtime_arrayref_t *ref) {
return ref->store_id == 0;
}
/**
* \brief Allocate a new array instance.
*
* All elements are initialized to the same value.
*
* \param context The store context.
* \param pre The array pre-allocator.
* \param elem The initial element value.
* \param len The number of elements.
* \param out Receives the new arrayref on success.
*
* \return NULL on success, or a #wasmtime_error_t on failure.
*/
WASM_API_EXTERN wasmtime_error_t *wasmtime_arrayref_new(
wasmtime_context_t *context, const wasmtime_array_ref_pre_t *pre,
const wasmtime_val_t *elem, uint32_t len, wasmtime_arrayref_t *out);
/**
* \brief Clone an `arrayref`, creating a new root.
*/
WASM_API_EXTERN void
wasmtime_arrayref_clone(const wasmtime_arrayref_t *arrayref,
wasmtime_arrayref_t *out);
/**
* \brief Unroot an `arrayref` to allow garbage collection.
*/
WASM_API_EXTERN void wasmtime_arrayref_unroot(wasmtime_arrayref_t *ref);
/**
* \brief Upcast an `arrayref` to an `anyref`.
*/
WASM_API_EXTERN void
wasmtime_arrayref_to_anyref(const wasmtime_arrayref_t *arrayref,
wasmtime_anyref_t *out);
/**
* \brief Upcast an `arrayref` to an `eqref`.
*/
WASM_API_EXTERN void
wasmtime_arrayref_to_eqref(const wasmtime_arrayref_t *arrayref,
wasmtime_eqref_t *out);
/**
* \brief Get the length of an array.
*
* \param context The store context.
* \param arrayref The array (not consumed).
* \param out Receives the length on success.
*
* \return NULL on success, or a #wasmtime_error_t on failure.
*/
WASM_API_EXTERN wasmtime_error_t *
wasmtime_arrayref_len(wasmtime_context_t *context,
const wasmtime_arrayref_t *arrayref, uint32_t *out);
/**
* \brief Read an element from an array.
*
* \param context The store context.
* \param arrayref The array (not consumed).
* \param index The element index.
* \param out Receives the element value on success.
*
* \return NULL on success, or a #wasmtime_error_t on failure.
*/
WASM_API_EXTERN wasmtime_error_t *
wasmtime_arrayref_get(wasmtime_context_t *context,
const wasmtime_arrayref_t *arrayref, uint32_t index,
wasmtime_val_t *out);
/**
* \brief Set an element of an array.
*
* \param context The store context.
* \param arrayref The array (not consumed).
* \param index The element index.
* \param val The value to write.
*
* \return NULL on success, or a #wasmtime_error_t on failure.
*/
WASM_API_EXTERN wasmtime_error_t *
wasmtime_arrayref_set(wasmtime_context_t *context,
const wasmtime_arrayref_t *arrayref, uint32_t index,
const wasmtime_val_t *val);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // WASMTIME_FEATURE_GC
#endif // WASMTIME_ARRAYREF_H