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

[Feature] Implement Array<T> type and constant array initialisation expression syntax #499

Open
2 of 8 tasks
Luna-Klatzer opened this issue Aug 7, 2023 · 0 comments
Open
2 of 8 tasks
Assignees
Labels
feature New feature or enhancement
Milestone

Comments

@Luna-Klatzer
Copy link
Member

Is there an existing proposal for this?

  • I have searched the existing issues

This feature does not exist in the latest version

  • I am using the latest version

Proposal

Implement the Array<T> type based on the given Array type from the target languages JavaScript and TypeScript (Ref: Array on MDN), which should allow the dynamic storing of data based on a generic type T specififying the type constraint of an Array.

This issue also includes implementing the following array syntax:

[elem1, elem2, elem3, ...] // -> implies Array<typeof elem1 | typeof elem2 | typeof elem3 | ...> 

This also includes providing the basic functionality from the prototype Array, which includes for now these functions:

  • Array<T>.concat(otherArray: Array<T>) -> Array<T>: Joins together the existing array and the otherArray (in that order), and creates a new shallow copy of both arrays.
  • Array<T>.join(seperator: str) -> str: Joins together all values of the array by adding the seperator in-between all of them.
  • Array<T>.flat() -> FlatArray<Array<T>>: Flats the map and resolves all values of any nested arrays and inserts them at the top level of the array.
  • Array<T>.shift() -> T: Returns the first element of the array and removes it from the object.
  • Array<T>.pop() -> T: Returns the last element of the array and removes it from the object.
  • Array<T>.reverse() -> Array<T>: Reverses the original array and returns a reference to it.
  • Array<T>.push(elem: T) -> num: Pushes a new value to the end of the array and returns the number of elements now in the array.
  • Array<T>.slice(start?: num, start?: end) -> T: Returns a shallow copy from the given range, start is inclusive, end is exclusive.

Exact behaviour / changes you want

  • Implement the syntax in the parser to allow for constant array expressions.
  • Implement the internal type Array<T> and proper handling for the generic typing. ([Feature] Implement basic generic type system for built-in types #494)
  • Implement automatic type inferrance of constant arrays.
  • Implement support for the Array constructor and allow it to be referenced in Kipper code, so type checks using typeof(val) == Array should be possible.
  • Implement support for the Array prototype and all given functions.
  • Implement translation to JavaScript and TypeScript.
@Luna-Klatzer Luna-Klatzer added the feature New feature or enhancement label Aug 7, 2023
@Luna-Klatzer Luna-Klatzer self-assigned this Aug 7, 2023
@Luna-Klatzer Luna-Klatzer added this to the v0.11.0 milestone Aug 7, 2023
@Luna-Klatzer Luna-Klatzer changed the title [Feature] Implement Array<T> type and list-syntax [Feature] Implement Array<T> type and constant array initialisation expression syntax Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
Development

No branches or pull requests

1 participant