Skip to content

Commit 7ee5f55

Browse files
committed
Fix bug with -O2 and optimization
1 parent 1a3c045 commit 7ee5f55

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

src/api/optimize.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,17 @@ def visit_BLOCK(self, node):
159159
class FunctionGraphVisitor(UniqueVisitor):
160160
""" Mark FUNCALLS
161161
"""
162+
def _get_calls_from_children(self, node):
163+
return [
164+
symbol
165+
for symbol in self.filter_inorder(node, lambda x: isinstance(x, (symbols.FUNCCALL, symbols.CALL)))
166+
if not isinstance(symbol, symbols.ARRAYACCESS)
167+
]
168+
162169
def _set_children_as_accessed(self, node: symbols.SYMBOL):
163170
parent = node.get_parent(symbols.FUNCDECL)
164171
if parent is None: # Global scope?
165-
for symbol in self.filter_inorder(node, lambda x: isinstance(x, (symbols.FUNCCALL, symbols.CALL))):
172+
for symbol in self._get_calls_from_children(node):
166173
symbol.entry.accessed = True
167174

168175
def visit_FUNCCALL(self, node: symbols.SYMBOL):
@@ -175,7 +182,7 @@ def visit_CALL(self, node: symbols.SYMBOL):
175182

176183
def visit_FUNCDECL(self, node: symbols.SYMBOL):
177184
if node.entry.accessed:
178-
for symbol in self.filter_inorder(node, lambda x: isinstance(x, (symbols.FUNCCALL, symbols.CALL))):
185+
for symbol in self._get_calls_from_children(node):
179186
symbol.entry.accessed = True
180187

181188
yield node
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
jp __MAIN_PROGRAM__
14+
__CALL_BACK__:
15+
DEFW 0
16+
ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
19+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
20+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
21+
ZXBASIC_USER_DATA_END:
22+
__MAIN_PROGRAM__:
23+
call _Init
24+
ld hl, 0
25+
ld b, h
26+
ld c, l
27+
__END_PROGRAM:
28+
di
29+
ld hl, (__CALL_BACK__)
30+
ld sp, hl
31+
exx
32+
pop hl
33+
pop iy
34+
pop ix
35+
exx
36+
ei
37+
ret
38+
_Init:
39+
push ix
40+
ld ix, 0
41+
add ix, sp
42+
ld hl, 0
43+
push hl
44+
inc sp
45+
_Init__leave:
46+
ld sp, ix
47+
pop ix
48+
ret
49+
;; --- end of user code ---
50+
END
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
DIM myArray(1 to 6) as ubyte
2+
3+
SUB Init()
4+
DIM i as ubyte
5+
myArray(i) = 0
6+
END SUB
7+
8+
Init()

0 commit comments

Comments
 (0)