Wasmtime
arrayref.hh
Go to the documentation of this file.
1
5#ifndef WASMTIME_ARRAYREF_HH
6#define WASMTIME_ARRAYREF_HH
7
8#include <wasmtime/_arrayref_class.hh>
9
10#ifdef WASMTIME_FEATURE_GC
11
12#include <wasmtime/_anyref_class.hh>
13#include <wasmtime/_eqref_class.hh>
14#include <wasmtime/_val_class.hh>
15
16namespace wasmtime {
17
18inline Result<ArrayRef> ArrayRef::create(Store::Context cx,
19 const ArrayRefPre &pre,
20 const Val &elem, uint32_t len) {
22 auto *err =
23 wasmtime_arrayref_new(cx.capi(), pre.capi(), elem.capi(), len, &out);
24 if (err)
25 return Result<ArrayRef>(Error(err));
26 return Result<ArrayRef>(ArrayRef(out));
27}
28
29inline Result<Val> ArrayRef::get(Store::Context cx, uint32_t index) const {
31 auto *err = wasmtime_arrayref_get(cx.capi(), &raw, index, &out);
32 if (err)
33 return Result<Val>(Error(err));
34 return Result<Val>(Val(out));
35}
36
37inline Result<std::monostate> ArrayRef::set(Store::Context cx, uint32_t index,
38 const Val &value) const {
39 auto *err = wasmtime_arrayref_set(cx.capi(), &raw, index, value.capi());
40 if (err)
41 return Result<std::monostate>(Error(err));
42 return Result<std::monostate>(std::monostate{});
43}
44
46inline AnyRef ArrayRef::to_anyref() const {
49 return AnyRef(out);
50}
51
53inline EqRef ArrayRef::to_eqref() const {
56 return EqRef(out);
57}
58
59} // namespace wasmtime
60
61#endif // WASMTIME_FEATURE_GC
62
63#endif // WASMTIME_ARRAYREF_HH
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)
Allocate a new array instance.
WASM_API_EXTERN void wasmtime_arrayref_to_anyref(const wasmtime_arrayref_t *arrayref, wasmtime_anyref_t *out)
Upcast an arrayref to an anyref.
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)
Set an element of an array.
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)
Read an element from an array.
WASM_API_EXTERN void wasmtime_arrayref_to_eqref(const wasmtime_arrayref_t *arrayref, wasmtime_eqref_t *out)
Upcast an arrayref to an eqref.
static Result< ArrayRef > create(Store::Context cx, const ArrayRefPre &pre, const Val &elem, uint32_t len)
Allocate a new array with all elements set to the same value.
Result< Val > get(Store::Context cx, uint32_t index) const
Read an element from the array.
Result< std::monostate > set(Store::Context cx, uint32_t index, const Val &value) const
Set an element of the array.
AnyRef to_anyref() const
Upcast to anyref.
Result< uint32_t > len(Store::Context cx) const
Get the length of the array.
Definition: _arrayref_class.hh:52
EqRef to_eqref() const
Upcast to eqref.
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:77
A WebAssembly arrayref value.
Definition: val.h:210
A WebAssembly eqref value.
Definition: val.h:163
Container for different kinds of wasm values.
Definition: val.h:376