Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

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

Open Luna-Klatzer opened this issue 1 year ago • 0 comments

Is there an existing proposal for this?

  • [X] I have searched the existing issues

This feature does not exist in the latest version

  • [X] 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. (#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 avatar Aug 07 '23 12:08 Luna-Klatzer