Skip to content

Commit 6119697

Browse files
committed
Fix crash upon bad let expr
If the expr type is None, the program crashed. Also add more typing hints. Test case included
1 parent 6cc7b33 commit 6119697

5 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/libzxbc/zxbparser.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@
1313
# PI Constant
1414
# PI = 3.1415927 is ZX Spectrum PI representation
1515
# But a better one is 3.141592654, so take it from math
16+
1617
import math
1718
from math import pi as PI
1819
import collections
1920

2021
# typings
2122
from typing import NamedTuple
23+
from typing import Optional
2224

2325
# Compiler API
2426
from src.api.debug import __DEBUG__ # analysis:ignore
@@ -181,15 +183,18 @@ def make_nop():
181183
return symbols.NOP()
182184

183185

184-
def make_number(value, lineno, type_=None):
186+
def make_number(value, lineno: int, type_=None):
185187
""" Wrapper: creates a constant number node.
186188
"""
187189
return symbols.NUMBER(value, type_=type_, lineno=lineno)
188190

189191

190-
def make_typecast(type_, node, lineno):
192+
def make_typecast(type_: symbols.TYPE, node: Optional[symbols.SYMBOL], lineno: int):
191193
""" Wrapper: returns a Typecast node
192194
"""
195+
if node is None or node.type_ is None:
196+
return # syntax / semantic error
197+
193198
assert isinstance(type_, symbols.TYPE)
194199
return symbols.TYPECAST.make_node(type_, node, lineno)
195200

src/parsetab/tabs.dbm.bak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'zxbpp', (0, 72571)
22
'asmparse', (72704, 254311)
33
'zxnext_asmparse', (327168, 285299)
4-
'zxbparser', (612864, 712099)
4+
'zxbparser', (612864, 715296)

src/parsetab/tabs.dbm.dat

3.12 KB
Binary file not shown.

src/parsetab/tabs.dbm.dir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
'zxbpp', (0, 72571)
22
'asmparse', (72704, 254311)
33
'zxnext_asmparse', (327168, 285299)
4-
'zxbparser', (612864, 712099)
4+
'zxbparser', (612864, 715296)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DIM a as Ubyte
2+
3+
FUNCTION editStringFN(ByREF s AS Byte) as s
4+
s = s + 1
5+
RETURN s
6+
END FUNCTION
7+
8+
a = editStringFN(a, 1, "i")
9+

0 commit comments

Comments
 (0)