Type

Entities for represent values or objects used within WasmVM

Types out of WebAssembly specification (extended) are denoted as [ext]

Fundamental types

Represent basic values or date references

using WasmVM::i32_t = int32_t

32-bit signed integer

using WasmVM::i64_t = int64_t

64-bit signed integer

using WasmVM::f32_t = float

32-bit (single precision) floating-point number

using WasmVM::f64_t = double

64-bit (double precision) floating-point number

using WasmVM::funcref_t = std::optional<index_t>

Nullable reference of function

using WasmVM::externref_t = void*

Nullable reference of external objects

using WasmVM::i8_t = int8_t

[ext] 8-bit signed integer

using WasmVM::u8_t = uint8_t

[ext] 8-bit unsigned integer

using WasmVM::i16_t = int16_t

[ext] 16-bit signed integer

using WasmVM::u16_t = uint16_t

[ext] 16-bit unsigned integer

using WasmVM::u32_t = uint32_t

[ext] 32-bit unsigned integer

using WasmVM::u64_t = uint64_t

[ext] 64-bit unsigned integer

using WasmVM::byte_t = std::byte

[ext] Single byte

using WasmVM::index_t = u32_t

[ext] Index of objects

using WasmVM::offset_t = u64_t

[ext] Offset of objects

using WasmVM::align_t = uint8_t

[ext] Memory alignment

Constants

constexpr u64_t WasmVM::page_size = 65536

Memory page size

constexpr index_t WasmVM::index_npos = -1

[ext] Undefined (non-existing) index

Enumerations

struct WasmVM::ValueType

A number type, or a reference type (ref null? heaptype). The heap type is abstract or names a type index; the legacy spellings are the nullable abstract forms, so funcref is (ref null func).

Kind kind

Which number type, or which abstract heap type, or ref for a concrete one.

bool nullable

Meaningful for the reference kinds.

index_t typeidx

Meaningful when kind is ref.

static ValueType concrete(index_t typeidx, bool nullable)

(ref $t) / (ref null $t)

bool is_num() const
bool is_ref() const
bool is_concrete() const
bool is_bottom() const
enum WasmVM::ValueType::Kind
enumerator i32

Denote i32_t value

enumerator i64

Denote i64_t value

enumerator f32

Denote f32_t value

enumerator f64

Denote f64_t value

enumerator funcref

Denote funcref_t value

enumerator externref

Denote externref_t value

enumerator i31ref

Denote i31ref_t value (GC proposal)

enumerator exnref

Denote exnref_t value (exception-handling proposal)

enumerator structref

Any struct (GC proposal)

enumerator arrayref

Any array (GC proposal)

enumerator anyref

Anything in the internal hierarchy (GC proposal)

enumerator eqref

Anything comparable with ref.eq (GC proposal)

enumerator nullref

The bottom of the internal hierarchy: only null

enumerator nullfuncref

The bottom of the function hierarchy: only null

enumerator nullexternref

The bottom of the external hierarchy: only null

enumerator ref

A concrete reference, whose typeidx names the type

struct WasmVM::GcObject

Base of everything a guest allocates on the garbage-collected heap: a struct, an array, an exception payload. Reference counted, with a cycle collector on top so that a cycle through a mutable reference field is reclaimed as well.

template<typename T>
class WasmVM::GcPtr

A counted handle on a WasmVM::GcObject, null when it holds nothing. Shaped like the std::shared_ptr it replaces.

std::size_t WasmVM::gc_collect()

Collect now, and return how many objects were freed. Collection also happens on its own as candidates gather, so an embedder need not call this.

std::size_t WasmVM::gc_live_count()

How many objects the guest has allocated and not yet had reclaimed.

using WasmVM::structref_t = GcPtr<StructObj>

A reference to a struct on the heap; null when the handle is

using WasmVM::arrayref_t = GcPtr<ArrayObj>

A reference to an array on the heap; null when the handle is

struct WasmVM::StructObj
index_t typeidx

The type this struct was allocated from

std::vector<Value> fields

One per field, in declaration order. A packed field is held as an i32 already truncated to its width.

struct WasmVM::ArrayObj
index_t typeidx
std::vector<Value> elems
enum WasmVM::RefType
enumerator funcref

Denote function reference value

enumerator externref

Denote external object reference value

Object types

using WasmVM::Value = std::variant<i32_t, i64_t, f32_t, f64_t, funcref_t, externref_t, i31ref_t, exnref_t, structref_t, arrayref_t>

General type of value

using WasmVM::Ref = std::variant<funcref_t, externref_t>

Reference type

struct WasmVM::Limits

Limits of ranged objects or values

offset_t min

Minimum value

std::optional<offset_t> max

[Optional] Maximum value

bool is64 = false

[ext] When true, the memory or table uses a 64-bit address space (memory64 proposal). Defaults to false (32-bit).

struct WasmVM::FuncType

Declarational type (signature) of function

std::vector<ValueType> params

Value types of function parameters

std::vector<ValueType> results

Value types of function results (return values)

enum class WasmVM::PackedType

Packed storage of a struct field or array element (GC proposal). Never a value type: a packed field is read and written through i32.

enumerator i8
enumerator i16
using WasmVM::StorageType = std::variant<ValueType, PackedType>

Storage type of a struct field or array element

struct WasmVM::FieldType

Type of a struct field or of an array’s elements

StorageType storage
bool mut = false

Whether struct.set / array.set may write it

struct WasmVM::StructType
std::vector<FieldType> fields
struct WasmVM::ArrayType
FieldType field
using WasmVM::CompType = std::variant<FuncType, StructType, ArrayType>

Composite type: what a type section entry defines

struct WasmVM::SubType

One entry of the type section: a composite type that may name a supertype and may sit inside a recursion group. A plain function type is a SubType that is final with no supers.

bool final = true
std::vector<index_t> supers

Supertype indices, as written. The spec allows at most one; the validator rejects more.

CompType comp
bool is_func() const
bool is_struct() const
bool is_array() const
const FuncType &func() const

The function type, for the places a type index can only ever name a function’s. Throws WasmVM::Exception::Exception when the entry is a struct or array type.

struct WasmVM::RecGroup

An explicit (rec ...) group: count consecutive entries of WasmVM::WasmModule::types starting at first.

index_t first
index_t count
using WasmVM::MemType = Limits

Declarational type (signature) of memory

struct WasmVM::TableType

Declarational type (signature) of table

Limits limits

Limits of table

RefType reftype

Specify the reference type of table elements

struct WasmVM::GlobalType

Declarational type (signature) of global

enum Mut

Declarational type for denoting mutability of the global

enumerator constant

The global value is immutable

enumerator variable

The global value is variable

Mut mut

Specify the mutability

ValueType type

Specify the type of global value

struct WasmVM::ExternVal

Declarational type (signature) of external values or objects

enum ExternType
enumerator Func

Indicate the external value is function

enumerator Mem

Indicate the external value is memory

enumerator Table

Indicate the external value is table

enumerator Global

Indicate the external value is global

ExternType type
index_t addr

Specify the type of global value