spotlessmind1975 / ugbasic

An isomorphic BASIC language compiler for retrocomputers
Apache License 2.0
92 stars 16 forks source link

Add REDIM command #712

Open trs-eric opened 11 months ago

trs-eric commented 11 months ago

It would be nice to be able to REDIM an array.

In most languages, REDIM allows you to either shrink or expand an array but not change it's type. If there is not enough contiguous memory, the function should move the entire array such that it can be resize while maintaining the data. When shrinking the array, it should just cut off the end of the array.

Some languages like QB64 offer further options like allowing you to remove the front or back of the array or preserving / removing the existing data.

spotlessmind1975 commented 11 months ago

Hi @trs-eric and thank you so much for suggesting this feature!

To implement the REDIM command we need to have a "dynamic heap", and ugBASIC currently does not use this structure for variables other than dynamic strings, for performance reasons.. Dynamic strings, however, are managed separately from the rest of the variables. As soon as this data structure is introduced, it will be possible to implement REDIM as well as data allocation on this structure.

Thank you again and have a nice retrocoding!