Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#572 from boriel/bugfix/crash_on_forwa…
Browse files Browse the repository at this point in the history
…rd_reference_to_sub

fix: fix crash on forward reference to sub
  • Loading branch information
boriel committed Oct 6, 2021
2 parents 58608ca + 3832d06 commit 69b6ed8
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/api/symboltable.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,8 @@ def declare_func(self, id_: str, lineno: int, type_=None, class_=CLASS.function)
if id_[-1] in DEPRECATED_SUFFIXES and entry.type_ != self.basic_types[SUFFIX_TYPE[id_[-1]]]:
syntax_error_func_type_mismatch(lineno, entry)

if entry.token == "VAR": # This was a function used in advance
symbols.VAR.to_function(entry, lineno=lineno)
if entry.token == "VAR": # This was a function or sub used in advance
symbols.VAR.to_function(entry, lineno=lineno, class_=class_)
entry.mangled = "%s_%s" % (self.current_namespace, entry.name) # HINT: mangle for nexted scopes
entry.class_ = class_
else:
Expand Down
4 changes: 2 additions & 2 deletions src/symbols/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ def to_label(var_instance):
return var_instance

@staticmethod
def to_function(var_instance, lineno=None):
def to_function(var_instance, lineno=None, class_=CLASS.function):
"""Converts a var_instance to a function one"""
assert isinstance(var_instance, SymbolVAR)
from src.symbols import FUNCTION

var_instance.__class__ = FUNCTION
var_instance.class_ = CLASS.function
var_instance.class_ = class_
var_instance.reset(lineno=lineno)
return var_instance

Expand Down
66 changes: 66 additions & 0 deletions tests/functional/zx48k/dim_at0.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
org 32768
.core.__START_PROGRAM:
di
push ix
push iy
exx
push hl
exx
ld hl, 0
add hl, sp
ld (.core.__CALL_BACK__), hl
ei
jp .core.__MAIN_PROGRAM__
.core.__CALL_BACK__:
DEFW 0
.core.ZXBASIC_USER_DATA:
; Defines USER DATA Length in bytes
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld hl, 0
ld b, h
ld c, l
.core.__END_PROGRAM:
di
ld hl, (.core.__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
_test1:
push ix
ld ix, 0
add ix, sp
ld hl, 0
push hl
push ix
pop hl
ld bc, -2
add hl, bc
ex de, hl
ld hl, .LABEL.__LABEL0
ld bc, 2
ldir
_test1__leave:
ld sp, ix
pop ix
ret
_test2:
push ix
ld ix, 0
add ix, sp
_test2__leave:
ld sp, ix
pop ix
ret
;; --- end of user code ---
.LABEL.__LABEL0:
DEFW _test2
END
6 changes: 6 additions & 0 deletions tests/functional/zx48k/dim_at0.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sub test1()
DIM dummy as Uinteger = @test2
end sub

sub test2
end sub

0 comments on commit 69b6ed8

Please sign in to comment.