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 <assert.h>
9
#include <wasmtime/_store_class.hh>
10
#include <
wasmtime/anyref.h
>
11
#include <wasmtime/helpers.hh>
12
#include <
wasmtime/types/val.hh
>
13
14
namespace
wasmtime {
15
16
class
ArrayRef;
17
class
EqRef;
18
class
StructRef;
19
23
class
AnyRef
{
24
WASMTIME_TOP_REF_WRAPPER(
AnyRef
,
wasmtime_anyref
);
25
28
static
AnyRef
i31(
Store::Context
cx, uint32_t value) {
29
wasmtime_anyref_t
other;
30
wasmtime_anyref_from_i31(cx.
capi
(), value, &other);
31
return
AnyRef
(other);
32
}
33
35
std::optional<uint32_t> u31(
Store::Context
cx)
const
{
36
uint32_t ret = 0;
37
if
(wasmtime_anyref_i31_get_u(cx.
capi
(), &raw, &ret))
38
return
ret;
39
return
std::nullopt;
40
}
41
43
std::optional<int32_t> i31(
Store::Context
cx)
const
{
44
int32_t ret = 0;
45
if
(wasmtime_anyref_i31_get_s(cx.
capi
(), &raw, &ret))
46
return
ret;
47
return
std::nullopt;
48
}
49
51
bool
is_i31(
Store::Context
cx)
const
{
52
return
wasmtime_anyref_is_i31(cx.
capi
(), &raw);
53
}
54
56
bool
is_eqref(
Store::Context
cx)
const
;
57
59
bool
is_struct(
Store::Context
cx)
const
;
60
62
bool
is_array(
Store::Context
cx)
const
;
63
65
std::optional<EqRef> as_eqref(
Store::Context
cx)
const
;
66
68
std::optional<StructRef> as_struct(
Store::Context
cx)
const
;
69
71
std::optional<ArrayRef> as_array(
Store::Context
cx)
const
;
72
74
HeapType
ty(
Store::Context
cx)
const
{
75
wasmtime_heaptype_t
out;
76
bool
ok = wasmtime_anyref_type(cx.
capi
(), &raw, &out);
77
assert(ok);
78
return
HeapType
(out);
79
}
80
};
81
82
}
// namespace wasmtime
83
84
#endif
// WASMTIME_FEATURE_GC
85
86
#endif
// WASMTIME_ANYREF_CLASS_HH
anyref.h
wasmtime::AnyRef
Representation of a WebAssembly anyref value.
Definition:
_anyref_class.hh:23
wasmtime::HeapType
Representation of a heap type in WebAssembly.
Definition:
types/val.hh:22
wasmtime::Store::Context
An interior pointer into a Store.
Definition:
_store_class.hh:65
wasmtime::Store::Context::capi
const wasmtime_context_t * capi() const
Returns the underlying C API pointer.
Definition:
_store_class.hh:183
conf.h
Build-time defines for how the C API was built.
wasmtime_anyref
A WebAssembly value in the any hierarchy of GC types.
Definition:
val.h:77
wasmtime_heaptype
A WebAssembly heap type.
Definition:
types/val.h:76
val.hh
include
wasmtime
_anyref_class.hh
Generated by
1.9.3