Skip to content

Commit 03156e9

Browse files
committed
Merged in bugfix/const_arr_crash (pull request #180)
Bugfix/const arr crash Approved-by: Jose Rodriguez <boriel@gmail.com>
2 parents 6ecb579 + e569419 commit 03156e9

32 files changed

Lines changed: 593 additions & 178 deletions

arch/zx48k/backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
OPT32 = True
133133

134134
# Label RegExp
135-
RE_LABEL = re.compile('^[ \t]*[a-zA-Z_][_a-zA-Z\d]*:')
135+
RE_LABEL = re.compile(r'^[ \t]*[a-zA-Z_][_a-zA-Z\d]*:')
136136

137137
# (ix +/- ...) regexp
138138
RE_IX_IDX = re.compile(r'^\([ \t]*ix[ \t]*[-+][ \t]*.+\)$')

arch/zx48k/optimizer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
'bc', 'de', 'hl', 'sp', 'ix', 'iy', 'ixh', 'ixl', 'iyh', 'iyl',
4545
'af', "af'", 'i', 'r'}
4646

47-
RE_NUMBER = re.compile('^([-+]?[0-9]+|$[A-Fa-f0-9]+|[0-9][A-Fa-f0-9]*[Hh]|%[01]+|[01]+[bB])$')
47+
RE_NUMBER = re.compile(r'^([-+]?[0-9]+|$[A-Fa-f0-9]+|[0-9][A-Fa-f0-9]*[Hh]|%[01]+|[01]+[bB])$')
4848
RE_INDIR = re.compile(r'\([ \t]*[Ii][XxYy][ \t]*[-+][ \t]*[0-9]+[ \t]*\)')
4949
RE_IXIND = re.compile(r'[iI][xXyY]([-+][0-9]+)?')
5050
RE_LABEL = re.compile(r'^[ \t]*[_a-zA-Z][a-zA-Z\d]*:')
51-
RE_INDIR16 = re.compile('r[ \t]*\([ \t]*([dD][eE])|([hH][lL])[ \t]*\)[ \t]*')
52-
RE_OUTC = re.compile('[ \t]*\([ \t]*[cC]\)')
53-
RE_ID = re.compile('[.a-zA-Z_][.a-zA-Z_0-9]*')
54-
RE_PRAGMA = re.compile('^#[ \t]?pragma[ \t]opt[ \t]')
51+
RE_INDIR16 = re.compile(r'[ \t]*\([ \t]*([dD][eE])|([hH][lL])[ \t]*\)[ \t]*')
52+
RE_OUTC = re.compile(r'[ \t]*\([ \t]*[cC]\)')
53+
RE_ID = re.compile(r'[.a-zA-Z_][.a-zA-Z_0-9]*')
54+
RE_PRAGMA = re.compile(r'^#[ \t]?pragma[ \t]opt[ \t]')
5555

5656
# Enabled Optimizations (this is useful for debugging)
5757
OPT00 = True

arch/zx48k/translator.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,9 @@ def traverse_const(node):
285285
if node.token == 'CONST':
286286
return Translator.traverse_const(node.expr)
287287

288+
if node.token == 'ARRAYACCESS':
289+
return '({} + {})'.format(node.entry.mangled, node.offset)
290+
288291
raise InvalidCONSTexpr(node)
289292

290293
@staticmethod
@@ -457,6 +460,11 @@ def visit_ARGLIST(self, node):
457460
for i in range(len(node) - 1, -1, -1): # visit in reverse order
458461
yield node[i]
459462

463+
if isinstance(node.parent, symbols.ARRAYACCESS) and OPTIONS.arrayCheck.value:
464+
upper = node.parent.entry.bounds[i].upper
465+
lower = node.parent.entry.bounds[i].lower
466+
self.emit('paramu16', upper - lower)
467+
460468
def visit_ARGUMENT(self, node):
461469
if not node.byref:
462470
suffix = self.TSUFFIX(node.type_)
@@ -496,11 +504,6 @@ def visit_ARRAYLOAD(self, node):
496504
if node.offset is None:
497505
yield node.args
498506

499-
if OPTIONS.arrayCheck.value:
500-
upper = node.entry.bounds[0].upper
501-
lower = node.entry.bounds[0].lower
502-
self.emit('paramu16', upper - lower)
503-
504507
if scope == SCOPE.global_:
505508
self.emit('aload' + self.TSUFFIX(node.type_), node.entry.t, node.entry.mangled)
506509
elif scope == SCOPE.parameter:
@@ -644,9 +647,6 @@ def visit_LETARRAYSUBSTR(self, node):
644647
def visit_ARRAYACCESS(self, node):
645648
yield node.arglist
646649

647-
if OPTIONS.arrayCheck.value:
648-
self.emit('param' + self.TSUFFIX(gl.BOUND_TYPE), len(node.entry.bounds))
649-
650650
def visit_STRSLICE(self, node):
651651
yield node.string
652652
if node.string.token == 'STRING' or \

library-asm/array.asm

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ __ARRAY:
4242
4343
ld hl, 0 ; BC = Offset "accumulator"
4444

45+
LOOP:
4546
#ifdef __CHECK_ARRAY_BOUNDARY__
4647
pop de
4748
#endif
48-
49-
LOOP:
5049
pop bc ; Get next index (Ai) from the stack
5150

5251
#ifdef __CHECK_ARRAY_BOUNDARY__
@@ -74,15 +73,8 @@ LOOP:
7473
exx
7574
pop de ; DE = Max bound Number (i-th dimension)
7675

77-
#ifdef __CHECK_ARRAY_BOUNDARY__
78-
push de
79-
#endif
8076
;call __MUL16_FAST ; HL *= DE
8177
call __FNMUL
82-
#ifdef __CHECK_ARRAY_BOUNDARY__
83-
pop de
84-
dec de
85-
#endif
8678
jp LOOP
8779
8880
ARRAY_END:

tests/functional/46.asm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,11 @@ __ARRAY:
140140

141141
ld hl, 0 ; BC = Offset "accumulator"
142142

143-
#line 48 "/src/zxb/trunk/library-asm/array.asm"
144-
145143
LOOP:
144+
#line 49 "/src/zxb/trunk/library-asm/array.asm"
146145
pop bc ; Get next index (Ai) from the stack
147146

148-
#line 60 "/src/zxb/trunk/library-asm/array.asm"
147+
#line 59 "/src/zxb/trunk/library-asm/array.asm"
149148

150149
add hl, bc ; Adds current index
151150

@@ -163,10 +162,8 @@ LOOP:
163162
exx
164163
pop de ; DE = Max bound Number (i-th dimension)
165164

166-
#line 80 "/src/zxb/trunk/library-asm/array.asm"
167165
;call __MUL16_FAST ; HL *= DE
168166
call __FNMUL
169-
#line 86 "/src/zxb/trunk/library-asm/array.asm"
170167
jp LOOP
171168

172169
ARRAY_END:
@@ -177,7 +174,7 @@ ARRAY_END:
177174
push de
178175
exx
179176

180-
#line 100 "/src/zxb/trunk/library-asm/array.asm"
177+
#line 92 "/src/zxb/trunk/library-asm/array.asm"
181178
LOCAL ARRAY_SIZE_LOOP
182179

183180
ex de, hl
@@ -208,7 +205,7 @@ ARRAY_SIZE_LOOP:
208205

209206
;add hl, de
210207
;__ARRAY_FIN:
211-
#line 131 "/src/zxb/trunk/library-asm/array.asm"
208+
#line 123 "/src/zxb/trunk/library-asm/array.asm"
212209

213210
pop de
214211
add hl, de ; Adds element start

tests/functional/47.asm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,11 @@ __ARRAY:
167167

168168
ld hl, 0 ; BC = Offset "accumulator"
169169

170-
#line 48 "/src/zxb/trunk/library-asm/array.asm"
171-
172170
LOOP:
171+
#line 49 "/src/zxb/trunk/library-asm/array.asm"
173172
pop bc ; Get next index (Ai) from the stack
174173

175-
#line 60 "/src/zxb/trunk/library-asm/array.asm"
174+
#line 59 "/src/zxb/trunk/library-asm/array.asm"
176175

177176
add hl, bc ; Adds current index
178177

@@ -190,10 +189,8 @@ LOOP:
190189
exx
191190
pop de ; DE = Max bound Number (i-th dimension)
192191

193-
#line 80 "/src/zxb/trunk/library-asm/array.asm"
194192
;call __MUL16_FAST ; HL *= DE
195193
call __FNMUL
196-
#line 86 "/src/zxb/trunk/library-asm/array.asm"
197194
jp LOOP
198195

199196
ARRAY_END:
@@ -204,7 +201,7 @@ ARRAY_END:
204201
push de
205202
exx
206203

207-
#line 100 "/src/zxb/trunk/library-asm/array.asm"
204+
#line 92 "/src/zxb/trunk/library-asm/array.asm"
208205
LOCAL ARRAY_SIZE_LOOP
209206

210207
ex de, hl
@@ -235,7 +232,7 @@ ARRAY_SIZE_LOOP:
235232

236233
;add hl, de
237234
;__ARRAY_FIN:
238-
#line 131 "/src/zxb/trunk/library-asm/array.asm"
235+
#line 123 "/src/zxb/trunk/library-asm/array.asm"
239236

240237
pop de
241238
add hl, de ; Adds element start

tests/functional/55.asm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,11 @@ __ARRAY:
135135

136136
ld hl, 0 ; BC = Offset "accumulator"
137137

138-
#line 48 "/src/zxb/trunk/library-asm/array.asm"
139-
140138
LOOP:
139+
#line 49 "/src/zxb/trunk/library-asm/array.asm"
141140
pop bc ; Get next index (Ai) from the stack
142141

143-
#line 60 "/src/zxb/trunk/library-asm/array.asm"
142+
#line 59 "/src/zxb/trunk/library-asm/array.asm"
144143

145144
add hl, bc ; Adds current index
146145

@@ -158,10 +157,8 @@ LOOP:
158157
exx
159158
pop de ; DE = Max bound Number (i-th dimension)
160159

161-
#line 80 "/src/zxb/trunk/library-asm/array.asm"
162160
;call __MUL16_FAST ; HL *= DE
163161
call __FNMUL
164-
#line 86 "/src/zxb/trunk/library-asm/array.asm"
165162
jp LOOP
166163

167164
ARRAY_END:
@@ -172,7 +169,7 @@ ARRAY_END:
172169
push de
173170
exx
174171

175-
#line 100 "/src/zxb/trunk/library-asm/array.asm"
172+
#line 92 "/src/zxb/trunk/library-asm/array.asm"
176173
LOCAL ARRAY_SIZE_LOOP
177174

178175
ex de, hl
@@ -203,7 +200,7 @@ ARRAY_SIZE_LOOP:
203200

204201
;add hl, de
205202
;__ARRAY_FIN:
206-
#line 131 "/src/zxb/trunk/library-asm/array.asm"
203+
#line 123 "/src/zxb/trunk/library-asm/array.asm"
207204

208205
pop de
209206
add hl, de ; Adds element start

tests/functional/aloadstr1.asm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,11 @@ __ARRAY:
138138

139139
ld hl, 0 ; BC = Offset "accumulator"
140140

141-
#line 48 "/src/zxb/trunk/library-asm/array.asm"
142-
143141
LOOP:
142+
#line 49 "/src/zxb/trunk/library-asm/array.asm"
144143
pop bc ; Get next index (Ai) from the stack
145144

146-
#line 60 "/src/zxb/trunk/library-asm/array.asm"
145+
#line 59 "/src/zxb/trunk/library-asm/array.asm"
147146

148147
add hl, bc ; Adds current index
149148

@@ -161,10 +160,8 @@ LOOP:
161160
exx
162161
pop de ; DE = Max bound Number (i-th dimension)
163162

164-
#line 80 "/src/zxb/trunk/library-asm/array.asm"
165163
;call __MUL16_FAST ; HL *= DE
166164
call __FNMUL
167-
#line 86 "/src/zxb/trunk/library-asm/array.asm"
168165
jp LOOP
169166

170167
ARRAY_END:
@@ -175,7 +172,7 @@ ARRAY_END:
175172
push de
176173
exx
177174

178-
#line 100 "/src/zxb/trunk/library-asm/array.asm"
175+
#line 92 "/src/zxb/trunk/library-asm/array.asm"
179176
LOCAL ARRAY_SIZE_LOOP
180177

181178
ex de, hl
@@ -206,7 +203,7 @@ ARRAY_SIZE_LOOP:
206203

207204
;add hl, de
208205
;__ARRAY_FIN:
209-
#line 131 "/src/zxb/trunk/library-asm/array.asm"
206+
#line 123 "/src/zxb/trunk/library-asm/array.asm"
210207

211208
pop de
212209
add hl, de ; Adds element start

tests/functional/array03.asm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,11 @@ __ARRAY:
133133

134134
ld hl, 0 ; BC = Offset "accumulator"
135135

136-
#line 48 "/src/zxb/trunk/library-asm/array.asm"
137-
138136
LOOP:
137+
#line 49 "/src/zxb/trunk/library-asm/array.asm"
139138
pop bc ; Get next index (Ai) from the stack
140139

141-
#line 60 "/src/zxb/trunk/library-asm/array.asm"
140+
#line 59 "/src/zxb/trunk/library-asm/array.asm"
142141

143142
add hl, bc ; Adds current index
144143

@@ -156,10 +155,8 @@ LOOP:
156155
exx
157156
pop de ; DE = Max bound Number (i-th dimension)
158157

159-
#line 80 "/src/zxb/trunk/library-asm/array.asm"
160158
;call __MUL16_FAST ; HL *= DE
161159
call __FNMUL
162-
#line 86 "/src/zxb/trunk/library-asm/array.asm"
163160
jp LOOP
164161

165162
ARRAY_END:
@@ -170,7 +167,7 @@ ARRAY_END:
170167
push de
171168
exx
172169

173-
#line 100 "/src/zxb/trunk/library-asm/array.asm"
170+
#line 92 "/src/zxb/trunk/library-asm/array.asm"
174171
LOCAL ARRAY_SIZE_LOOP
175172

176173
ex de, hl
@@ -201,7 +198,7 @@ ARRAY_SIZE_LOOP:
201198

202199
;add hl, de
203200
;__ARRAY_FIN:
204-
#line 131 "/src/zxb/trunk/library-asm/array.asm"
201+
#line 123 "/src/zxb/trunk/library-asm/array.asm"
205202

206203
pop de
207204
add hl, de ; Adds element start

tests/functional/array06.asm

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,11 @@ __ARRAY:
133133

134134
ld hl, 0 ; BC = Offset "accumulator"
135135

136-
#line 48 "/src/zxb/trunk/library-asm/array.asm"
137-
138136
LOOP:
137+
#line 49 "/src/zxb/trunk/library-asm/array.asm"
139138
pop bc ; Get next index (Ai) from the stack
140139

141-
#line 60 "/src/zxb/trunk/library-asm/array.asm"
140+
#line 59 "/src/zxb/trunk/library-asm/array.asm"
142141

143142
add hl, bc ; Adds current index
144143

@@ -156,10 +155,8 @@ LOOP:
156155
exx
157156
pop de ; DE = Max bound Number (i-th dimension)
158157

159-
#line 80 "/src/zxb/trunk/library-asm/array.asm"
160158
;call __MUL16_FAST ; HL *= DE
161159
call __FNMUL
162-
#line 86 "/src/zxb/trunk/library-asm/array.asm"
163160
jp LOOP
164161

165162
ARRAY_END:
@@ -170,7 +167,7 @@ ARRAY_END:
170167
push de
171168
exx
172169

173-
#line 100 "/src/zxb/trunk/library-asm/array.asm"
170+
#line 92 "/src/zxb/trunk/library-asm/array.asm"
174171
LOCAL ARRAY_SIZE_LOOP
175172

176173
ex de, hl
@@ -201,7 +198,7 @@ ARRAY_SIZE_LOOP:
201198

202199
;add hl, de
203200
;__ARRAY_FIN:
204-
#line 131 "/src/zxb/trunk/library-asm/array.asm"
201+
#line 123 "/src/zxb/trunk/library-asm/array.asm"
205202

206203
pop de
207204
add hl, de ; Adds element start

0 commit comments

Comments
 (0)