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

Allow array literals to include an element index #446

Open
mneumann opened this issue Feb 15, 2023 · 1 comment
Open

Allow array literals to include an element index #446

mneumann opened this issue Feb 15, 2023 · 1 comment
Labels
complexity 2: significant This is non-trivial, but still not a major undertaking kind: feature: language Adding a new language feature

Comments

@mneumann
Copy link
Contributor

For example code like this:

:const _byte_class_table_data Array(U8)'val: [
    0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 00..0f
    0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 10..1f
    0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 20..2f
    0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // 30..3f
    ...
]

could be written as:

:const _byte_class_table_data Array(U8)'val: [
    0x00: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0x10: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0x20: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    0x30: 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    ...
]

Each item array element can be prefixed with the index in the array (e.g. 0x00), if none is given, the previous index is used and incremented by one. It's an error if indices are missing or are duplicate.

@jemc
Copy link
Contributor

jemc commented Feb 15, 2023

I wasn't a fan of this in your original suggestion in which it seemed like every element would need to be labelled with an index. But I like this suggestion a lot more - allowing some of them to be labelled for clarity and extrapolating the rest.

@jemc jemc added kind: feature: language Adding a new language feature complexity 2: significant This is non-trivial, but still not a major undertaking labels Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity 2: significant This is non-trivial, but still not a major undertaking kind: feature: language Adding a new language feature
Projects
None yet
Development

No branches or pull requests

2 participants