Skip to content

Commit 9ba3dcd

Browse files
committed
Allow array at label expressions
1 parent 65f6dbd commit 9ba3dcd

5 files changed

Lines changed: 111 additions & 4 deletions

File tree

libzxbc/zxbparser.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ def p_var_decl_at(p):
682682
entry.make_alias(tmp.operand)
683683
entry.offset = tmp.operand.offset
684684
else:
685-
error(p.lineno(4), 'Only address of identifiers are allowed')
685+
error(p.lineno(4), 'Only addresses of identifiers are allowed')
686686
return
687687
else:
688688
entry.addr = tmp
@@ -765,9 +765,18 @@ def p_arr_decl_attr(p):
765765
p[0] = None
766766
return
767767

768-
if not is_number(expr):
769-
api.errmsg.syntax_error_address_must_be_constant(p.lineno(2))
770-
p[0] = None
768+
if expr.token == 'CONST':
769+
expr = expr.expr
770+
if expr.token == 'UNARY' and expr.operator == 'ADDRESS': # Must be an ID
771+
if expr.operand.token == 'ARRAYACCESS':
772+
if expr.operand.offset is None:
773+
error(p.lineno(4), 'Address is not constant. Only constant subscripts are allowed')
774+
return
775+
elif expr.operand.token not in ('VAR', 'LABEL'):
776+
error(p.lineno(3), 'Only addresses of identifiers are allowed')
777+
return
778+
elif not is_number(expr):
779+
api.errmsg.syntax_error_address_must_be_constant(p.lineno(3))
771780
return
772781

773782
arr_entry = SYMBOL_TABLE.access_array(arr_decl[0], arr_decl[1])
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
__LABEL__c:
14+
ld hl, 0
15+
ld b, h
16+
ld c, l
17+
__END_PROGRAM:
18+
di
19+
ld hl, (__CALL_BACK__)
20+
ld sp, hl
21+
exx
22+
pop hl
23+
exx
24+
pop iy
25+
pop ix
26+
ei
27+
ret
28+
__CALL_BACK__:
29+
DEFW 0
30+
ZXBASIC_USER_DATA:
31+
_a.__DATA__ EQU ADDRESS(c)
32+
_a:
33+
DEFW __LABEL0
34+
_a.__DATA__.__PTR__:
35+
DEFW __LABEL__c
36+
__LABEL0:
37+
DEFW 0000h
38+
DEFB 01h
39+
; Defines DATA END --> HEAP size is 0
40+
ZXBASIC_USER_DATA_END:
41+
; Defines USER DATA Length in bytes
42+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
43+
END
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
REM arrat at label
2+
DIM a(5) as Ubyte AT @c
3+
4+
c:
5+
6+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
__LABEL__c:
14+
ld hl, 0
15+
ld b, h
16+
ld c, l
17+
__END_PROGRAM:
18+
di
19+
ld hl, (__CALL_BACK__)
20+
ld sp, hl
21+
exx
22+
pop hl
23+
exx
24+
pop iy
25+
pop ix
26+
ei
27+
ret
28+
__CALL_BACK__:
29+
DEFW 0
30+
ZXBASIC_USER_DATA:
31+
_a.__DATA__ EQU ADDRESS(c) PLUS 1
32+
_a:
33+
DEFW __LABEL0
34+
_a.__DATA__.__PTR__:
35+
DEFW (__LABEL__c) + (1)
36+
__LABEL0:
37+
DEFW 0000h
38+
DEFB 01h
39+
; Defines DATA END --> HEAP size is 0
40+
ZXBASIC_USER_DATA_END:
41+
; Defines USER DATA Length in bytes
42+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
43+
END
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
REM Array elements at label c + 1
2+
DIM a(5) as Ubyte AT @c + 1
3+
4+
c:
5+
6+

0 commit comments

Comments
 (0)