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

feat: Allow structs and arrays as globals #1054

Merged
merged 4 commits into from
Mar 28, 2023
Merged

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Mar 28, 2023

Related issue(s)

Resolves #439

Description

Summary of changes

Allows non-integers such as structs and arrays to be used as globals, as long as they're initialized as constants. There is nothing verifying the sub-expressions for these are also constants currently though, so it is possible to have unexpected behavior (calling a function which tries to use the uninitialized global internally).

Attempting to use these in an array-length context will not crash the compiler, but will issue a somewhat confusing error that can be improved later.

Dependency additions / changes

Test additions / changes

Checklist

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt with default settings.
  • I have linked this PR to the issue(s) that it resolves.
  • I have reviewed the changes on GitHub, line by line.
  • I have ensured all changes are covered in the description.

Documentation needs

  • This PR requires documentation updates when merged.

We'll need to document that, in addition to integers, arbitrary structs and arrays can also be defined as globals. They must be initialized to struct or array literals however.

We should likely mention the sub-expressions within these struct/array literals should also be literals themselves even though this is not enforced yet.

Additional context

@jfecher jfecher changed the title Allow structs and arrays as globals feat: Allow structs and arrays as globals Mar 28, 2023
@kevaundray kevaundray enabled auto-merge March 28, 2023 17:25
@kevaundray kevaundray added this pull request to the merge queue Mar 28, 2023
Merged via the queue into master with commit dadbd3c Mar 28, 2023
@kevaundray kevaundray deleted the jf/flexible-globals branch March 28, 2023 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Global arrays
2 participants