Skip to content

GC Struct

Create a new structure on the heap.

Signature: (param field_types...) (result structref)

Example:

(struct.new $my_struct (i32.const 1) (f32.const 2.0))

Create a new structure with default values.

Signature: (result structref)

Example:

(struct.new_default $my_struct)

Get a field from a structure.

Signature: (param structref) (result field_type)

Example:

(struct.get $my_struct $field_name (local.get $s))

Get a signed field from a structure (sign-extending).

Signature: (param structref) (result field_type)

Example:

(struct.get_s $my_struct $field_index (local.get $s))

Get an unsigned field from a structure (zero-extending).

Signature: (param structref) (result field_type)

Example:

(struct.get_u $my_struct $field_index (local.get $s))

Set a field in a structure.

Signature: (param structref field_type)

Example:

(struct.set $my_struct $field_index (local.get $s) (i32.const 42))