Skip to content

Commit b48bef5

Browse files
committed
bugfix: crash upon constant array access
Defining a var like DIM p = @A(3, 4) being var a an array crashed the compiler. Fixed.
1 parent 6ecb579 commit b48bef5

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

arch/zx48k/translator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ def traverse_const(node):
285285
if node.token == 'CONST':
286286
return Translator.traverse_const(node.expr)
287287

288+
if node.token == 'ARRAYACCESS':
289+
return '({} + {})'.format(node.entry.mangled, node.offset)
290+
288291
raise InvalidCONSTexpr(node)
289292

290293
@staticmethod

tests/functional/arrconst.asm

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
ld hl, (_p)
14+
ld (_p), hl
15+
ld hl, 0
16+
ld b, h
17+
ld c, l
18+
__END_PROGRAM:
19+
di
20+
ld hl, (__CALL_BACK__)
21+
ld sp, hl
22+
exx
23+
pop hl
24+
exx
25+
pop iy
26+
pop ix
27+
ei
28+
ret
29+
__CALL_BACK__:
30+
DEFW 0
31+
32+
ZXBASIC_USER_DATA:
33+
_p:
34+
DEFW (_a + 5)
35+
_a:
36+
DEFW 0001h
37+
DEFW 0003h
38+
DEFB 02h
39+
DEFB 00h
40+
DEFB 00h
41+
DEFB 00h
42+
DEFB 00h
43+
DEFB 00h
44+
DEFB 00h
45+
DEFB 00h
46+
DEFB 00h
47+
DEFB 00h
48+
DEFB 00h
49+
DEFB 00h
50+
DEFB 00h
51+
DEFB 00h
52+
DEFB 00h
53+
DEFB 00h
54+
DEFB 00h
55+
DEFB 00h
56+
DEFB 00h
57+
; Defines DATA END --> HEAP size is 0
58+
ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP
59+
; Defines USER DATA Length in bytes
60+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
61+
END

tests/functional/arrconst.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
DIM a(2, 2) as UInteger
3+
DIM p = @a(0, 0)
4+
p = p
5+

0 commit comments

Comments
 (0)