You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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, number defines 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, StructIdentifier defines 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, number defines a padded label for each element of an array with a length of length and a byte size of number.
DARRAY length, StructIdentifier defines 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 number starts 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.
ARRAY SW number starts 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.
ARRAY SL number starts 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.
ARRAY StructIdentifier starts 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.
ENDA ends 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]
The text was updated successfully, but these errors were encountered:
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 likestruct.array.element_5.field
.Initial syntax proposal (extending the existing structs proposal):
fieldIdentifier SARRAY length, number
defines 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, StructIdentifier
defines 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, number
defines a padded label for each element of an array with a length of length and a byte size of number.DARRAY length, StructIdentifier
defines 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 number
starts an instantiation of an array of indeterminate length with an element byte size of number; number is 1 if omitted.DB
.ARRAY SW number
starts an instantiation of an array of indeterminate length with an element byte size of number * 2; number is 1 if omitted.DW
.ARRAY SL number
starts an instantiation of an array of indeterminate length with an element byte size of number * 4; number is 1 if omitted.DL
.ARRAY StructIdentifier
starts an instantiation of an array of indeterminate length with an element type of StructIdentifier.NEW
.ENDA
ends the current array instantiation.Example:
The text was updated successfully, but these errors were encountered: