#ifndef WASMTIME_ANYREF_CLASS_HH
#define WASMTIME_ANYREF_CLASS_HH
#include <wasmtime/conf.h>
#ifdef WASMTIME_FEATURE_GC
#include <assert.h>
#include <wasmtime/_store_class.hh>
#include <wasmtime/anyref.h>
#include <wasmtime/helpers.hh>
#include <wasmtime/types/val.hh>
namespace wasmtime {
class ArrayRef;
class EqRef;
class StructRef;
class AnyRef {
WASMTIME_TOP_REF_WRAPPER(AnyRef, wasmtime_anyref);
static AnyRef i31(Store::Context cx, uint32_t value) {
wasmtime_anyref_t other;
wasmtime_anyref_from_i31(cx.capi(), value, &other);
return AnyRef(other);
}
std::optional<uint32_t> u31(Store::Context cx) const {
uint32_t ret = 0;
if (wasmtime_anyref_i31_get_u(cx.capi(), &raw, &ret))
return ret;
return std::nullopt;
}
std::optional<int32_t> i31(Store::Context cx) const {
int32_t ret = 0;
if (wasmtime_anyref_i31_get_s(cx.capi(), &raw, &ret))
return ret;
return std::nullopt;
}
bool is_i31(Store::Context cx) const {
return wasmtime_anyref_is_i31(cx.capi(), &raw);
}
bool is_eqref(Store::Context cx) const;
bool is_struct(Store::Context cx) const;
bool is_array(Store::Context cx) const;
std::optional<EqRef> as_eqref(Store::Context cx) const;
std::optional<StructRef> as_struct(Store::Context cx) const;
std::optional<ArrayRef> as_array(Store::Context cx) const;
HeapType ty(Store::Context cx) const {
wasmtime_heaptype_t out;
bool ok = wasmtime_anyref_type(cx.capi(), &raw, &out);
assert(ok);
return HeapType(out);
}
};
}
#endif
#endif