Forum
Array initialization bug (*solved*) - Printable Version

+- Forum (https://www.boriel.com/forum)
+-- Forum: Compilers and Computer Languages (https://www.boriel.com/forum/forumdisplay.php?fid=12)
+--- Forum: ZX Basic Compiler (https://www.boriel.com/forum/forumdisplay.php?fid=11)
+---- Forum: Bug Reports (https://www.boriel.com/forum/forumdisplay.php?fid=15)
+---- Thread: Array initialization bug (*solved*) (/showthread.php?tid=636)



Array initialization bug (*solved*) - einar - 12-23-2014

My next ZX BASIC game requires a lookup table for variable sized data.

The simplest solution would be something like this:

Code:
data1:
    asm
        defb 0,1,2,3,4,5
    end asm
data2:
    asm
        defb 6,7,8
    end asm
data3:
    asm
        defb 9,10,11,12
    end asm

DIM array(1 TO 3) AS UINTEGER = { @data1, @data2, @data3 }

But compiling this program using latest version of ZX BASIC (incorrectly) produces the following error messages:

Code:
prog.bas:14: Initializer expression is not constant.
prog.bas:14: Initializer expression is not constant.
prog.bas:14: Initializer expression is not constant.

Another alternative would be declaring the lookup table directly in ASM, but ZX BASIC doesn't support mapping arrays to memory addresses either:

Code:
DIM array(1 TO 3) AS UINTEGER AT @data

For now, I'm implementing everything "manually" instead of using ZX BASIC arrays. But it would be nice if this problem could be fixed in future releases! Smile


Re: Array initialization bug - boriel - 12-23-2014

Definitely this is a bug! :oops:
Thanks for reporting.
These days I'm (finally) fixing this and other bugs reported here.


Re: Array initialization bug - einar - 12-23-2014

Thank you!!!


Re: Array initialization bug - einar - 02-22-2015

Just wondering if there has been any progress on this bug?

I'm asking because other bugs I reported recently have easy (efficient) workarounds, this one doesn't...


Re: Array initialization bug - boriel - 07-11-2015

einar Wrote:Just wondering if there has been any progress on this bug?

I'm asking because other bugs I reported recently have easy (efficient) workarounds, this one doesn't...
OMG I forgot about it completely :!:

This one was hard one to fix... And I'm thinking of make another compiler revamp (been QUITE busy since last year).
I need to write the roadmap on the zxbasic.net (wiki) site.


Re: Array initialization bug - einar - 07-11-2015

Thanks for the feedback!


Re: Array initialization bug - emook - 05-21-2017

This still looks like its an issue, any chance it can be fixed?

Or is there a way around this?

Thanks


Re: Array initialization bug - boriel - 05-21-2017

Just released ZX Basic 1.5.1 (had an almost sabbatic year in 2016, really needed it)

Will try to address this in ZXBasic 1.5.3 but it's a tough one.
Also, which ZX Basic version are you using? on which platform? (Windows, Linux, etc?)


Re: Array initialization bug - boriel - 09-05-2017

Okay, after *a lot* of work, it's finally done.
Please, download version 1.6.10 and try to do it.

Also you can now use ON (expression) GOTO label1, label2, ... (up to 255 labels). Also ON ... GOSUB.
example:
Code:
ON RND * 4 GOTO label0, label1, label2

PRINT "3 or higher!"
END

label0:
   PRINT "it was a 0"
   END

label1:
   PRINT "it was a 1"
   END

label2:
   PRINT "it was a 2"

(expression) can be any numerical expression (it will be converted to byte). If the result is 0, it will jump to the 1st label, 1, for the 2nd, etc...
If the result pass beyond the last label, no action is taken (the program continues normally).