Skip to content

Commit a1c22a9

Browse files
authored
Merge pull request #446 from boriel/bugfix/missing_include_filename
Bugfix/missing include filename
2 parents f23728d + ff291e5 commit a1c22a9

7 files changed

Lines changed: 29 additions & 27 deletions

File tree

src/arch/zx48k/backend/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,9 +1803,7 @@ def _inline(ins):
18031803

18041804
ASMLABEL = new_ASMID()
18051805
ASMS[ASMLABEL] = tmp
1806-
output.append('#line %s' % ins.quad[2])
18071806
output.append(ASMLABEL)
1808-
output.append('#line %i' % (int(ins.quad[2]) + len(tmp)))
18091807

18101808
return output
18111809

@@ -2095,7 +2093,7 @@ def __str__(self):
20952093
'out': [2, _out], # Defines a OUT instruction OUT x, y
20962094
'in': [1, _in], # Defines an IN instruction IN x, y
20972095

2098-
'inline': [2, _inline], # Defines an inline asm instruction
2096+
'inline': [1, _inline], # Defines an inline asm instruction
20992097

21002098
'cast': [4, _cast],
21012099
# TYPECAST: X = cast(from Type1, to Type2, Y) Ej. Converts Y 16bit to X 8bit: (cast, x, u16, u8, y)

src/arch/zx48k/translator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ def visit_ON_GOSUB(self, node):
626626

627627
def visit_CHKBREAK(self, node):
628628
if self.PREV_TOKEN != node.token:
629-
self.ic_inline('push hl', node.children[0].t)
629+
self.ic_inline('push hl')
630630
self.ic_fparam(gl.PTR_TYPE, node.children[0].t)
631631
self.ic_call('CHECK_BREAK', 0)
632632
backend.REQUIRES.add('break.asm')
@@ -906,7 +906,10 @@ def visit_ITALIC(self, node):
906906
# Other Sentences, like ASM, etc..
907907
# -----------------------------------------------------------------------------------------------------
908908
def visit_ASM(self, node):
909-
self.ic_inline(node.asm, node.lineno)
909+
EOL = '\n'
910+
self.ic_inline(f'#line {node.lineno} "{node.filename}"')
911+
self.ic_inline(node.asm)
912+
self.ic_inline(f'#line {node.lineno + 1 + len(node.asm.split(EOL))} "{node.filename}"')
910913

911914
# endregion
912915

src/arch/zx48k/translatorinstvisitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ def ic_gt(self, type_, t, t1, t2):
109109
def ic_in(self, t):
110110
return self.emit('in', t)
111111

112-
def ic_inline(self, asm_code: str, t):
113-
return self.emit('inline', asm_code, t)
112+
def ic_inline(self, asm_code: str):
113+
return self.emit('inline', asm_code)
114114

115115
def ic_jgezero(self, type_, t, label: str):
116116
return self.emit('jgezero' + self.TSUFFIX(type_), t, label)

src/arch/zx48k/translatorvisitor.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,20 @@ def traverse_const(node):
199199
return result
200200

201201
if node.token == 'BINARY':
202-
mid = node.operator
203-
if mid == 'PLUS':
204-
mid = '+'
205-
elif mid == 'MINUS':
206-
mid = '-'
207-
elif mid == 'MUL':
208-
mid = '*'
209-
elif mid == 'DIV':
210-
mid = '/'
211-
elif mid == 'MOD':
212-
mid = '%'
213-
elif mid == 'POW':
214-
mid = '^'
215-
elif mid == 'SHL':
216-
mid = '>>'
217-
elif mid == 'SHR':
218-
mid = '<<'
219-
else:
220-
raise InvalidOperatorError(mid)
202+
operator = {
203+
'PLUS': '+',
204+
'MINUS': '-',
205+
'MUL': '*',
206+
'DIV': '/',
207+
'MOD': '%',
208+
'POW': '^',
209+
'SHL': '>>',
210+
'SHR': '<<'
211+
}
212+
213+
mid = operator.get(node.operator)
214+
if mid is None:
215+
raise InvalidOperatorError(node.operator)
221216

222217
return '(%s) %s (%s)' % (TranslatorVisitor.traverse_const(node.left), mid,
223218
TranslatorVisitor.traverse_const(node.right))

src/libzxbc/zxbc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def main(args=None, emitter=None):
252252
# Emits jump tables
253253
translator.emit_jump_tables()
254254
# Signals end of user code
255-
translator.ic_inline(';; --- end of user code ---', zxblex.lexer.lineno)
255+
translator.ic_inline(';; --- end of user code ---')
256256

257257
if OPTIONS.emitBackend:
258258
with open_file(OPTIONS.outputFileName, 'wt', 'utf-8') as output_file:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "extra_chars.bas"
2+

tests/functional/test_cmdline.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ no_zxnext.asm:29: error: Syntax error. Unexpected token 'C' [C]
3636
>>> process_file('define_val.bas', ['-q', '-S', '-O -D MACRO'])
3737
define_val.bas:4: error: "MACRO should be VALUE"
3838

39+
>>> process_file('tap_include_asm_error.bas', ['-q', '-S'])
40+
extra_chars.bas:1: error: illegal character '`'
41+
extra_chars.bas:2: error: illegal character '#'
42+

0 commit comments

Comments
 (0)