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

(many) Add implicitly typed int arrays #494

Merged
merged 1 commit into from
Jun 18, 2024

Conversation

perlun
Copy link
Collaborator

@perlun perlun commented Jun 12, 2024

This is an important step towards completing #487, but a few more things are needed for this:

  • Being able to specify int[] as an explicit type specifier. Right now, only implicitly typed int arrays are supported.
  • Being able to use this for other data types like long[], double[] and string[].

As for the underlying perlang::IntArray class, what I am aiming for here is something a bit more high-level than traditional C-style int[] arrays. They are nice in the sense of being "low overhead" but are also prone to all kinds of C-style memory issues (heap overflow, most notably). Perlang arrays will be more akin to Java or C#-style arrays, which are inherently "safe by design". It should be more or less impossible to use a Perlang array in such a way as to cause the program to crash. Because we don't have a JVM or MSIL interpreter to help us with this, we have to implement the boundary checks on our own.

At the moment, those boundary checks throw (C++) exceptions. We could consider adding more "try"-oriented methods too, like try_get(index, default_value) or even try_get(index, () -> default_value) if we want to be more fancy. Either way, the point is to avoid exceptions and let the caller (by returning a bool) check if the operation was successful or not by different, sometimes more appropriate means than exceptions.

@perlun perlun added stdlib Things related to the Perlang API/stdlib language Language features (or bugs) experimental compilation Issues which are relevant when using experimental compilation labels Jun 12, 2024
@perlun perlun added this to the 0.5.0 milestone Jun 12, 2024
@perlun perlun force-pushed the feature/support-implicitly-typed-int-arrays branch from de082f7 to a2eb814 Compare June 12, 2024 20:57
@perlun perlun merged commit c264442 into master Jun 18, 2024
11 checks passed
@perlun perlun deleted the feature/support-implicitly-typed-int-arrays branch June 18, 2024 19:07
);
}

// TODO: Add test for indexing before and after array size, ensuring that we get the expected exceptions
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, would have been nice to take in the same PR I guess. 🙈 Will have to come in a followup PR.

Copy link
Collaborator Author

@perlun perlun Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental compilation Issues which are relevant when using experimental compilation language Language features (or bugs) stdlib Things related to the Perlang API/stdlib
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant