Skip to content

Commit ff12277

Browse files
authored
Merge pull request #377 from boriel/bugfix/dim_at_const
Fix bug with DIM at @Label
2 parents cc9bf5e + 039aa07 commit ff12277

10 files changed

Lines changed: 176 additions & 2 deletions

File tree

arch/zx48k/translator.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,8 @@ def visit_VARDECL(self, node):
10721072
return
10731073

10741074
if entry.addr is not None:
1075-
self.ic_deflabel(entry.mangled, entry.addr)
1075+
addr = self.traverse_const(entry.addr) if isinstance(entry.addr, symbols.SYMBOL) else entry.addr
1076+
self.ic_deflabel(entry.mangled, addr)
10761077
for entry in entry.aliased_by:
10771078
self.ic_deflabel(entry.mangled, entry.addr)
10781079
elif entry.alias is None:

libzxbc/zxbparser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ def p_var_decl_at(p):
672672
if p[5].token == 'CONST':
673673
tmp = p[5].expr
674674
if tmp.token == 'UNARY' and tmp.operator == 'ADDRESS': # Must be an ID
675-
if tmp.operand.token == 'VAR':
675+
if tmp.operand.token in ('VAR', 'LABEL'):
676676
entry.make_alias(tmp.operand)
677677
elif tmp.operand.token == 'ARRAYACCESS':
678678
if tmp.operand.offset is None:
@@ -684,6 +684,8 @@ def p_var_decl_at(p):
684684
else:
685685
error(p.lineno(4), 'Only address of identifiers are allowed')
686686
return
687+
else:
688+
entry.addr = tmp
687689

688690
elif not is_number(p[5]):
689691
api.errmsg.syntax_error_address_must_be_constant(p.lineno(4))

tests/functional/dim_at_label0.asm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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__somelabel:
14+
_x:
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+
ZXBASIC_USER_DATA:
32+
; Defines DATA END --> HEAP size is 0
33+
ZXBASIC_USER_DATA_END:
34+
; Defines USER DATA Length in bytes
35+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
36+
END

tests/functional/dim_at_label0.bas

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
3+
somelabel:
4+
5+
DIM x as UInteger at @somelabel

tests/functional/dim_at_label1.asm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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__somelabel:
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+
_x EQU (__LABEL__somelabel) + (1)
32+
; Defines DATA END --> HEAP size is 0
33+
ZXBASIC_USER_DATA_END:
34+
; Defines USER DATA Length in bytes
35+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
36+
END

tests/functional/dim_at_label1.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
3+
somelabel:
4+
5+
DIM x as UInteger at @somelabel + 1
6+

tests/functional/dim_at_label2.asm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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__somelabel:
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+
_x EQU (__LABEL__somelabel) + (1)
32+
; Defines DATA END --> HEAP size is 0
33+
ZXBASIC_USER_DATA_END:
34+
; Defines USER DATA Length in bytes
35+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
36+
END

tests/functional/dim_at_label2.bas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
4+
5+
DIM x as UInteger at @somelabel + 1
6+
7+
somelabel:
8+

tests/functional/dim_at_label3.asm

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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__somelabel:
14+
_x:
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+
ZXBASIC_USER_DATA:
32+
; Defines DATA END --> HEAP size is 0
33+
ZXBASIC_USER_DATA_END:
34+
; Defines USER DATA Length in bytes
35+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
36+
END

tests/functional/dim_at_label3.bas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
3+
4+
5+
DIM x as UInteger at @somelabel
6+
7+
somelabel:
8+

0 commit comments

Comments
 (0)