Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array Support #29

Open
Hawkbat opened this issue Apr 6, 2019 · 0 comments
Open

Array Support #29

Hawkbat opened this issue Apr 6, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@Hawkbat
Copy link
Owner

Hawkbat commented Apr 6, 2019

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, 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]
@Hawkbat Hawkbat added the enhancement New feature or request label Apr 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant