GC Array
array.new
Section titled “array.new”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 0array.new_default
Section titled “array.new_default”Create a new array with default values.
Signature: (param i32) (result arrayref)
Example:
(array.new_default $my_array (i32.const 10))array.new_fixed
Section titled “array.new_fixed”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))array.new_data
Section titled “array.new_data”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))array.new_elem
Section titled “array.new_elem”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))array.get
Section titled “array.get”Get an element from an array.
Signature: (param arrayref i32) (result field_type)
Example:
(array.get $my_array (local.get $arr) (i32.const 5))array.get_s
Section titled “array.get_s”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))array.get_u
Section titled “array.get_u”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))array.set
Section titled “array.set”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))array.len
Section titled “array.len”Get the length of an array.
Signature: (param arrayref) (result i32)
Example:
(array.len (local.get $arr))array.fill
Section titled “array.fill”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))array.copy
Section titled “array.copy”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))array.init_data
Section titled “array.init_data”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 copyarray.init_elem
Section titled “array.init_elem”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