Skip to content

GC Array

Create a new array on the heap.

Signature: (param field_type i32) (result arrayref)

Example:

(array.new $my_array (i32.const 0) (i32.const 10)) ;; Create size 10 array filled with 0

Create a new array with default values.

Signature: (param i32) (result arrayref)

Example:

(array.new_default $my_array (i32.const 10))

Create a new array from a fixed set of arguments.

Signature: (param field_type...) (result arrayref)

Example:

(array.new_fixed $my_array 3 (i32.const 1) (i32.const 2) (i32.const 3))

Create a new array from a data segment.

Signature: (param i32 i32) (result arrayref)

Example:

(array.new_data $my_array $data_index (i32.const 0) (i32.const 10))

Create a new array from an element segment.

Signature: (param i32 i32) (result arrayref)

Example:

(array.new_elem $my_array $elem_index (i32.const 0) (i32.const 10))

Get an element from an array.

Signature: (param arrayref i32) (result field_type)

Example:

(array.get $my_array (local.get $arr) (i32.const 5))

Get a signed element from an array.

Signature: (param arrayref i32) (result field_type)

Example:

(array.get_s $my_array (local.get $arr) (i32.const 5))

Get an unsigned element from an array.

Signature: (param arrayref i32) (result field_type)

Example:

(array.get_u $my_array (local.get $arr) (i32.const 5))

Set an element in an array.

Signature: (param arrayref i32 field_type)

Example:

(array.set $my_array (local.get $arr) (i32.const 5) (i32.const 42))

Get the length of an array.

Signature: (param arrayref) (result i32)

Example:

(array.len (local.get $arr))

Fill a range of an array with a value.

Signature: (param arrayref i32 field_type i32)

Example:

(array.fill (local.get $arr) (i32.const 0) (i32.const 42) (i32.const 10))

Copy a range from one array to another.

Signature: (param arrayref i32 arrayref i32 i32)

Example:

(array.copy $dst_type $src_type (local.get $dst) (i32.const 0) (local.get $src) (i32.const 0) (i32.const 10))

Initialize a portion of an array from a passive data segment. Takes the array, destination offset in the array, source offset in the data segment, and length.

Signature: (param arrayref i32 i32 i32)

Example:

(array.init_data $byte_array $data_segment
(local.get $arr) ;; array reference
(i32.const 0) ;; destination offset in array
(i32.const 0) ;; source offset in data segment
(i32.const 100)) ;; number of elements to copy

Initialize a portion of an array from a passive element segment. Takes the array, destination offset in the array, source offset in the element segment, and length.

Signature: (param arrayref i32 i32 i32)

Example:

(array.init_elem $funcref_array $elem_segment
(local.get $arr) ;; array reference
(i32.const 0) ;; destination offset in array
(i32.const 0) ;; source offset in elem segment
(i32.const 10)) ;; number of elements to copy