-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Also requested by Sanqui.
Note that this proposal only includes "real" arrays that exist in RAM or ROM. Array support for macros will follow in an additional feature request.
Arrays should mirror structs in that they are a compile-time construct with empty label expansions for RAM (DS-like) and inline instantiations for ROM (DB-like). Arrays-of-structs and structs-of-arrays should both be possible, with new struct syntax if necessary.
Will have to see if standard array indexing syntax ([index]) conflicts with the existing parsing; I don't think it should. Using it for initialization is definitely not RGBDS-like, though.
Internally, we can probably just treat arrays as creating a new identifier for each element prefixed by its index, so struct.array[5].field is equivalent to something like struct.array.element_5.field.
Initial syntax proposal (extending the existing structs proposal):
fieldIdentifier SARRAY length, numberdefines a struct field that will be treated like an array with a length of length and an element byte size of number; number is 1 if omitted.fieldIdentifier SARRAY length, StructIdentifierdefines a struct field that will be treated like an array with a length of length and an element with a byte size of sizeof(StructIdentifier).DARRAY length, numberdefines a padded label for each element of an array with a length of length and a byte size of number.DARRAY length, StructIdentifierdefines a padded label for each field of each struct element of an array with a length of length and an element with a byte size of sizeof(StructIdentifier).ARRAY SB numberstarts an instantiation of an array of indeterminate length with an element byte size of number; number is 1 if omitted.- Each line of an array instantiation that starts with any amount of whitespace is treated as an array element instantiation and evaluated as if it were passed to
DB.
- Each line of an array instantiation that starts with any amount of whitespace is treated as an array element instantiation and evaluated as if it were passed to
ARRAY SW numberstarts an instantiation of an array of indeterminate length with an element byte size of number * 2; number is 1 if omitted.- Each line of an array instantiation that starts with any amount of whitespace is treated as an array element instantiation and evaluated as if it were passed to
DW.
- Each line of an array instantiation that starts with any amount of whitespace is treated as an array element instantiation and evaluated as if it were passed to
ARRAY SL numberstarts an instantiation of an array of indeterminate length with an element byte size of number * 4; number is 1 if omitted.- Each line of an array instantiation that starts with any amount of whitespace is treated as an array element instantiation and evaluated as if it were passed to
DL.
- Each line of an array instantiation that starts with any amount of whitespace is treated as an array element instantiation and evaluated as if it were passed to
ARRAY StructIdentifierstarts an instantiation of an array of indeterminate length with an element type of StructIdentifier.- Each line of an array instantiation that starts with an amount of whitespace must be a struct instantiation using
NEW.
- Each line of an array instantiation that starts with an amount of whitespace must be a struct instantiation using
ENDAends the current array instantiation.
Example:
Point: STRUCT
x SB
y SB
ENDS
Sprite: STRUCT
gfxPtrs SARRAY 4, 2
point SSTRUCT Point
ENDS
Section "RAM", wram0
wordBuffer: DARRAY 128, 2
sprites: DARRAY 16, Sprite
Section "ROM", rom0
initialSprites: ARRAY Sprite
NEW
gfxPtr SARRAY
$12F4
$3C12
ENDA
x SB $F0
y SB $2E
ENDN
NEW
gfxPtr SARRAY
$6543
$42EA
ENDA
x SB $13
y SB $64
ENDN
ENDA
secondSpriteAddress: DW initialSprites[1]