Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

[Feature] Implement support for built-in type identifiers such as `str`, `num`, `bool` etc.

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 support for type identifiers, which should be usable during runtime to compare types.

This includes the following types:

  • bool
  • str
  • num

But importantly excludes the following types, as they are constants and therefore have as the type themselves. This also means doing typeof(<value of type undefined>) will simply return undefined and therefore should be rather replaced with <value of type undefined> == undefined (Same as with null and void, which is effectively a synonym for undefined.

This extends proposal #369, which proposes support for the built-in typeof() function allowing dynamic type checking.

Exact behaviour / changes you want

  • [ ] Implement runtime type objects for the Kipper base primitive types str, num and bool.
  • [ ] Add support for comparisons using typeof(EXP) and the constant type identifiers.
  • [ ] Allow the identifiers to be assigned to variables using the type type, for example:
    var reflectedType: type = num;
    if (typeof(someVariable) == reflectedType) {
      // It is of type 'num'
      ...
    }
    
    This also serves as the foundation for future custom types using custom type definitions with interfaces or unions.

Additional Notes

  • #373 (Detailed implementation reference)
  • #332 (Proof of concept for the runtime types)

Luna-Klatzer avatar Jul 27 '23 13:07 Luna-Klatzer