Wasmtime
_arrayref_class.hh
1#ifndef WASMTIME_ARRAYREF_CLASS_HH
2#define WASMTIME_ARRAYREF_CLASS_HH
3
4#include <wasmtime/conf.h>
5
6#ifdef WASMTIME_FEATURE_GC
7
8#include <wasmtime/_store_class.hh>
9#include <wasmtime/arrayref.h>
11
12namespace wasmtime {
13
14class Val;
15class AnyRef;
16class EqRef;
17
25 friend class ArrayRef;
26 WASMTIME_OWN_WRAPPER(ArrayRefPre, wasmtime_array_ref_pre)
27
28public:
31 auto *raw = wasmtime_array_ref_pre_new(cx.capi(), ty.capi());
32 ArrayRefPre pre(raw);
33 return pre;
34 }
35};
36
43class ArrayRef {
44 WASMTIME_REF_WRAPPER(ArrayRef, wasmtime_arrayref)
45
46public:
49 const Val &elem, uint32_t len);
50
53 uint32_t out;
54 auto *err = wasmtime_arrayref_len(cx.capi(), &raw, &out);
55 if (err)
56 return Result<uint32_t>(Error(err));
57 return Result<uint32_t>(out);
58 }
59
61 Result<Val> get(Store::Context cx, uint32_t index) const;
62
65 const Val &value) const;
66
69
71 EqRef to_eqref() const;
72};
73
74} // namespace wasmtime
75
76#endif // WASMTIME_FEATURE_GC
77
78#endif // WASMTIME_ARRAYREF_CLASS_HH
WASM_API_EXTERN wasmtime_array_ref_pre_t * wasmtime_array_ref_pre_new(wasmtime_context_t *context, const wasmtime_array_type_t *ty)
Create a new array pre-allocator.
WASM_API_EXTERN wasmtime_error_t * wasmtime_arrayref_len(wasmtime_context_t *context, const wasmtime_arrayref_t *arrayref, uint32_t *out)
Get the length of an array.
Representation of a WebAssembly anyref value.
Definition: _anyref_class.hh:21
Pre-allocated array layout for fast allocation of array instances.
Definition: _arrayref_class.hh:24
static ArrayRefPre create(Store::Context cx, const ArrayType &ty)
Create a new array pre-allocator.
Definition: _arrayref_class.hh:30
Representation of a WebAssembly arrayref value.
Definition: _arrayref_class.hh:43
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.
Owned handle to a WebAssembly array type definition.
Definition: types/arrayref.hh:18
Representation of a WebAssembly eqref value.
Definition: _eqref_class.hh:28
Errors coming from Wasmtime.
Definition: error.hh:26
Fallible result type used for Wasmtime.
Definition: error.hh:70
An interior pointer into a Store.
Definition: _store_class.hh:65
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition: _store_class.hh:183
Representation of a generic WebAssembly value.
Definition: _val_class.hh:53
Build-time defines for how the C API was built.
A WebAssembly arrayref value.
Definition: val.h:210