neilsf / XC-BASIC

A compiling BASIC dialect for the Commodore-64
https://xc-basic.net/
MIT License
74 stars 15 forks source link

User defined types #102

Closed neilsf closed 3 years ago

neilsf commented 4 years ago

User defined types (or structs in other languages) can hold more than one variable type of a fixed byte length. I suggest implementing the TYPE directive similarly to the QB style:

TYPE typename
  DIM variable1 AS <type>
  DIM variable2 AS <type>
ENDTYPE

Variables may then be defined as the new type:

DIM my_var AS typename

Preferably, arrays should be supported both within type definitions and variable definitions, i. e. a type can hold arrays as well as an array can be of a user defined type:

TYPE typename
  DIM variable[10] AS byte
ENDTYPE

DIM my_var[10] AS typename

The above example would create an array of 10 elements each of these elements holding an array of 10 bytes.

Using types will only be possible in explicit mode (see #100).

mrg-75 commented 4 years ago

This would be a great addition to the language, it makes organising data so much easier.

neilsf commented 3 years ago

Implemented in V3.