Alloc Slice Expression
An alloc slice expression allocates storage for a specified number of values and yields a slice to them.
An alloc slice expression has the slice type whose element type is the initializer function's return type.
Process
At runtime:
- the first expression is evaluated to determine the number of values to allocate;
- enough space for that number of values of the initializer function's return type is allocated, see region allocation;
- the second expression (the initializer function) is evaluated once for each element of the allocation, in order;
- if the initializer function accepts a
u64parameter, the zero-based index of the element is provided as its argument; - each resulting value is stored in its corresponding element of the allocated space; and
- a slice to the allocated storage is returned.
Assertions
- The first expression has type
u64, and its expected type is that type. - The second expression has function type
function(): Torfunction(u64): Tfor some typeT. - The initializer function's return type is runtime representable.
Syntax
alloc_slice_expression = alloc, left_bracket, expression, right_bracket, unary_expression ;