FAQ  •  Register  •  Login

Array initialization bug

<<

einar

Posts: 84

Joined: Sun Apr 08, 2012 9:33 pm

Post Tue Dec 23, 2014 2:28 am

Array initialization bug

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! :)
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Dec 23, 2014 9:17 am

Re: Array initialization bug

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

einar

Posts: 84

Joined: Sun Apr 08, 2012 9:33 pm

Post Tue Dec 23, 2014 11:41 am

Re: Array initialization bug

Thank you!!!
<<

einar

Posts: 84

Joined: Sun Apr 08, 2012 9:33 pm

Post Sun Feb 22, 2015 1:38 pm

Re: Array initialization bug

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...
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat Jul 11, 2015 8:58 am

Re: Array initialization bug

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.
<<

einar

Posts: 84

Joined: Sun Apr 08, 2012 9:33 pm

Post Sat Jul 11, 2015 12:44 pm

Re: Array initialization bug

Thanks for the feedback!
<<

emook

Posts: 27

Joined: Tue Dec 06, 2016 1:23 am

Post Sun May 21, 2017 8:26 pm

Re: Array initialization bug

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

Or is there a way around this?

Thanks
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun May 21, 2017 10:59 pm

Re: Array initialization bug

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?)
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Sep 05, 2017 8:17 pm

Re: Array initialization bug

Okay, after *a lot* of work, it's finally done.
Please, download version 2.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).

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO