Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Array expressions

ArrayExpression     = "[" , ArrayExprItems , "]"
                    ;
ArrayExprItems      = ExpressionWithoutBlock , { ",",  ExpressionWithoutBlock } , [ "," ]
                    | ExpressionWithoutBlock , ";" , NumberLiteral
                    ;

Bulk fill

Assigning a repeat expression ([value; N]) directly to a global variable whose array type is larger than 16 bits lowers to a runtime fill loop instead of materializing the array in a local:

global OAM: [u8; 160];

fn main() {
    OAM = [0; 160]; // runtime fill loop
}

This is restricted to:

  • array item types u8/i8 (other item types are not yet supported)
  • a value that is a compile-time-constant literal integer (optionally negated for i8) - a runtime-computed value, or a reference to a const item, is not yet supported

See bulk copy in operator expressions for copying an oversized array/struct from another global or const.