Wasmtime
_anyref_class.hh
1#ifndef WASMTIME_ANYREF_CLASS_HH
2#define WASMTIME_ANYREF_CLASS_HH
3
4#include <wasmtime/conf.h>
5
6#ifdef WASMTIME_FEATURE_GC
7
8#include <wasmtime/_store_class.hh>
9#include <wasmtime/anyref.h>
10#include <wasmtime/helpers.hh>
11
12namespace wasmtime {
13
14class ArrayRef;
15class EqRef;
16class StructRef;
17
21class AnyRef {
22 WASMTIME_TOP_REF_WRAPPER(AnyRef, wasmtime_anyref);
23
26 static AnyRef i31(Store::Context cx, uint32_t value) {
28 wasmtime_anyref_from_i31(cx.capi(), value, &other);
29 return AnyRef(other);
30 }
31
33 std::optional<uint32_t> u31(Store::Context cx) const {
34 uint32_t ret = 0;
35 if (wasmtime_anyref_i31_get_u(cx.capi(), &raw, &ret))
36 return ret;
37 return std::nullopt;
38 }
39
41 std::optional<int32_t> i31(Store::Context cx) const {
42 int32_t ret = 0;
43 if (wasmtime_anyref_i31_get_s(cx.capi(), &raw, &ret))
44 return ret;
45 return std::nullopt;
46 }
47
49 bool is_i31(Store::Context cx) const {
50 return wasmtime_anyref_is_i31(cx.capi(), &raw);
51 }
52
54 inline bool is_eqref(Store::Context cx) const;
55
57 inline bool is_struct(Store::Context cx) const;
58
60 inline bool is_array(Store::Context cx) const;
61
63 inline std::optional<EqRef> as_eqref(Store::Context cx) const;
64
66 inline std::optional<StructRef> as_struct(Store::Context cx) const;
67
69 inline std::optional<ArrayRef> as_array(Store::Context cx) const;
70};
71
72} // namespace wasmtime
73
74#endif // WASMTIME_FEATURE_GC
75
76#endif // WASMTIME_ANYREF_CLASS_HH
Representation of a WebAssembly anyref value.
Definition: _anyref_class.hh:21
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
Build-time defines for how the C API was built.
A WebAssembly value in the any hierarchy of GC types.
Definition: val.h:77