Skip to content

Commit 69b6ed8

Browse files
authored
Merge pull request #572 from boriel/bugfix/crash_on_forward_reference_to_sub
fix: fix crash on forward reference to sub
2 parents 58608ca + 3832d06 commit 69b6ed8

4 files changed

Lines changed: 76 additions & 4 deletions

File tree

src/api/symboltable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -796,8 +796,8 @@ def declare_func(self, id_: str, lineno: int, type_=None, class_=CLASS.function)
796796
if id_[-1] in DEPRECATED_SUFFIXES and entry.type_ != self.basic_types[SUFFIX_TYPE[id_[-1]]]:
797797
syntax_error_func_type_mismatch(lineno, entry)
798798

799-
if entry.token == "VAR": # This was a function used in advance
800-
symbols.VAR.to_function(entry, lineno=lineno)
799+
if entry.token == "VAR": # This was a function or sub used in advance
800+
symbols.VAR.to_function(entry, lineno=lineno, class_=class_)
801801
entry.mangled = "%s_%s" % (self.current_namespace, entry.name) # HINT: mangle for nexted scopes
802802
entry.class_ = class_
803803
else:

src/symbols/var.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ def to_label(var_instance):
146146
return var_instance
147147

148148
@staticmethod
149-
def to_function(var_instance, lineno=None):
149+
def to_function(var_instance, lineno=None, class_=CLASS.function):
150150
"""Converts a var_instance to a function one"""
151151
assert isinstance(var_instance, SymbolVAR)
152152
from src.symbols import FUNCTION
153153

154154
var_instance.__class__ = FUNCTION
155-
var_instance.class_ = CLASS.function
155+
var_instance.class_ = class_
156156
var_instance.reset(lineno=lineno)
157157
return var_instance
158158

tests/functional/zx48k/dim_at0.asm

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
org 32768
2+
.core.__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 (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
.core.ZXBASIC_USER_DATA_END:
22+
.core.__MAIN_PROGRAM__:
23+
ld hl, 0
24+
ld b, h
25+
ld c, l
26+
.core.__END_PROGRAM:
27+
di
28+
ld hl, (.core.__CALL_BACK__)
29+
ld sp, hl
30+
exx
31+
pop hl
32+
exx
33+
pop iy
34+
pop ix
35+
ei
36+
ret
37+
_test1:
38+
push ix
39+
ld ix, 0
40+
add ix, sp
41+
ld hl, 0
42+
push hl
43+
push ix
44+
pop hl
45+
ld bc, -2
46+
add hl, bc
47+
ex de, hl
48+
ld hl, .LABEL.__LABEL0
49+
ld bc, 2
50+
ldir
51+
_test1__leave:
52+
ld sp, ix
53+
pop ix
54+
ret
55+
_test2:
56+
push ix
57+
ld ix, 0
58+
add ix, sp
59+
_test2__leave:
60+
ld sp, ix
61+
pop ix
62+
ret
63+
;; --- end of user code ---
64+
.LABEL.__LABEL0:
65+
DEFW _test2
66+
END

tests/functional/zx48k/dim_at0.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sub test1()
2+
DIM dummy as Uinteger = @test2
3+
end sub
4+
5+
sub test2
6+
end sub

0 commit comments

Comments
 (0)