FAQ  •  Register  •  Login

Declaring arrays with constants (*solved*)

<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Mon Jul 21, 2014 7:19 pm

Declaring arrays with constants (*solved*)

Hi guys, it's been a little while. :)

I finally got around to upgrading to 1.4.0-s1881 and set about recompiling a bunch of old stuff to see how it turned out. One thing I'm having a problem with is that some of my code uses consts in the declaration of arrays, which was fine in 1.3 but doesn't seem to like compiling in 1.4.

e.g.
  Code:
'constants
const DGMAXX as ubyte = 10
const DGMAXY as ubyte = 10

'dungeon data
dim dgConnected(DGMAXY, DGMAXX) as ubyte


This fails to compile with an error telling me that I must use a constant (which I thought I did). :)

  Code:
DunGen.bas:6: Array bound must be a constant expression.
DunGen.bas:6: Array bound must be a constant expression.
Traceback (most recent call last):
  File "zxb.py", line 348, in <module>
  File "zxb.py", line 262, in main
  File "ply\yacc.pyc", line 263, in parse
  File "ply\yacc.pyc", line 710, in parseopt
  File "zxbparser.pyc", line 600, in p_bound_list_bound
  File "zxbparser.pyc", line 324, in make_bound_list
  File "symbols\boundlist.pyc", line 45, in make_node
  File "ast_\tree.pyc", line 147, in appendChild
  File "ast_\tree.pyc", line 52, in append
AssertionError


Apologies if this has already been covered in here, I didn't have much luck with the search!
Last edited by LTee on Wed Jul 23, 2014 5:40 pm, edited 1 time in total.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Jul 21, 2014 7:24 pm

Re: Declaring arrays with constants

LTee wrote:Hi guys, it's been a little while. :)

I finally got around to upgrading to 1.4.0-s1881 and set about recompiling a bunch of old stuff to see how it turned out. One thing I'm having a problem with is that some of my code uses consts in the declaration of arrays, which was fine in 1.3 but doesn't seem to like compiling in 1.4.

e.g.
  Code:
'constants
const DGMAXX as ubyte = 10
const DGMAXY as ubyte = 10

'dungeon data
dim dgConnected(DGMAXY, DGMAXX) as ubyte


This fails to compile with an error telling me that I must use a constant (which I thought I did). :)

  Code:
DunGen.bas:6: Array bound must be a constant expression.
DunGen.bas:6: Array bound must be a constant expression.
Traceback (most recent call last):
  File "zxb.py", line 348, in <module>
  File "zxb.py", line 262, in main
  File "ply\yacc.pyc", line 263, in parse
  File "ply\yacc.pyc", line 710, in parseopt
  File "zxbparser.pyc", line 600, in p_bound_list_bound
  File "zxbparser.pyc", line 324, in make_bound_list
  File "symbols\boundlist.pyc", line 45, in make_node
  File "ast_\tree.pyc", line 147, in appendChild
  File "ast_\tree.pyc", line 52, in append
AssertionError


Apologies if this has already been covered in here, I didn't have much luck with the search!


No, it's ok. 1881 was released 48h ago, if I recall correctly. :)
Thanks!

Will fix it ASAP!
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Mon Jul 21, 2014 7:33 pm

Re: Declaring arrays with constants

Brilliant, thanks Boriel! :D
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Mon Jul 21, 2014 11:24 pm

Re: Declaring arrays with constants

Please, download new version 1.4.0s1885 and tell me. :roll:
<<

LTee

Posts: 153

Joined: Tue Jul 07, 2009 2:54 pm

Post Tue Jul 22, 2014 7:54 pm

Re: Declaring arrays with constants

That seems to work perfectly - many thanks!

I do think I might have another problem, however.... but I need to investigate that first to make sure it's not me writing rubbish code. :)
<<

nitrofurano

Posts: 349

Joined: Thu Sep 29, 2011 12:44 pm

Location: Porto, Portugal

Post Tue Jul 22, 2014 8:23 pm

Re: Declaring arrays with constants

LTee wrote:...
  Code:
'constants
const DGMAXX as ubyte = 10
const DGMAXY as ubyte = 10

'dungeon data
dim dgConnected(DGMAXY, DGMAXX) as ubyte

...


well, i think what i’m really missing is this:
  Code:
dim dgConnected(DGMAXY, DGMAXX) as ubyte at $E000

(just like as we do for allocating variables to different memory addresses)

so that would take around 121 bytes (11*11 (i guess it’s 11, because it is an array from 0 to 10?) ) starting from $E000 - i’m needing this a lot, because when we patch ZX-Basic resulting binaries to rom files (such as on cartridge roms for Sega 8-bit consoles, ColecoVision, MSX, etc.), we really need to use peeks and pokes instead of arrays, since we can’t allocate arrays outside the rom area

i really have no idea how difficult would be implementing it
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Thu Jul 24, 2014 11:51 am

Re: Declaring arrays with constants

nitrofurano wrote:
LTee wrote:...
  Code:
'constants
const DGMAXX as ubyte = 10
const DGMAXY as ubyte = 10

'dungeon data
dim dgConnected(DGMAXY, DGMAXX) as ubyte

...


well, i think what i’m really missing is this:
  Code:
dim dgConnected(DGMAXY, DGMAXX) as ubyte at $E000

(just like as we do for allocating variables to different memory addresses)

so that would take around 121 bytes (11*11 (i guess it’s 11, because it is an array from 0 to 10?) ) starting from $E000 - i’m needing this a lot, because when we patch ZX-Basic resulting binaries to rom files (such as on cartridge roms for Sega 8-bit consoles, ColecoVision, MSX, etc.), we really need to use peeks and pokes instead of arrays, since we can’t allocate arrays outside the rom area

i really have no idea how difficult would be implementing it


I'm working on this. Basically, using Dynamic arrays. The problem is arrays also use a dimension table to calculate offset. And it always precedes the data.
For dynamic arrays I think the best way is to put the dimension table at the end. Dynamic arrays are created on runtime (just like in basic) and can change the dimension during the execution.

Return to Bug Reports

Who is online

Users browsing this forum: No registered users and 0 guests

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

phpBB SEO