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

Dynamic arrays #234

Open
Akuli opened this issue Feb 24, 2023 · 3 comments
Open

Dynamic arrays #234

Akuli opened this issue Feb 24, 2023 · 3 comments
Labels

Comments

@Akuli
Copy link
Owner

Akuli commented Feb 24, 2023

The self-hosted compiler already has a few dynamic arrays, i.e. arrays whose size grows as needed. Many languages have something like this:

  • Python: list
  • C++: vector
  • C: does not come in standard library, but can be implemented (see List in the Jou compiler)

Jou doesn't support these very well. Currently my Jou code has a realloc() whenever another item is added to the list, which works but isn't very efficient.

To implement dynamic arrays in Jou, I think I want something similar to the solution in C, so some kind of combination of macros and anonymous structs, neither of which is currently supported in Jou.

@Moosems
Copy link

Moosems commented Dec 8, 2023

Will there also be an array that can contain multiple types?

@Akuli
Copy link
Owner Author

Akuli commented Dec 8, 2023

You can already use union and enum to wrap multiple types into a single container type. This is not documented anywhere though.

@Akuli
Copy link
Owner Author

Akuli commented Dec 12, 2024

Very much related to #527

@Akuli Akuli added the feature label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants