Skip to content

Commit 286b577

Browse files
authored
Merge pull request #586 from boriel/bugfix/preproc_asm_error_missing
Bugfix/preproc asm error missing
2 parents 450da44 + 2572f5a commit 286b577

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

src/zxbc/zxbc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def main(args=None, emitter=None):
153153

154154
# Join all lines into a single string and ensures an INTRO at end of file
155155
asm_output = backend.emit(backend.MEMORY, optimize=OPTIONS.optimization_level > 0)
156-
asm_output = arch.target.optimizer.optimize(asm_output) + "\n" # invoke the -O3
156+
asm_output = arch.target.optimizer.optimize(asm_output) + "\n" # invoke the peephole optimizer
157157

158158
asm_output = asm_output.split("\n")
159159
for i in range(len(asm_output)):

src/zxbpp/zxbasmpplex.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
"line": "LINE",
7575
"require": "REQUIRE",
7676
"pragma": "PRAGMA",
77+
"error": "ERROR",
78+
"warning": "WARNING",
7779
}
7880

7981
# List of token names.

src/zxbpp/zxbpp.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import re
1818

1919
from dataclasses import dataclass
20+
from enum import Enum, unique
2021

2122
from typing import Any
2223
from typing import Dict
@@ -45,6 +46,12 @@
4546
from src import arch
4647

4748

49+
@unique
50+
class PreprocMode(str, Enum):
51+
BASIC = "BASIC"
52+
ASM = "ASM"
53+
54+
4855
# Generated output
4956
OUTPUT = ""
5057

@@ -143,17 +150,19 @@ def set_include_path():
143150
INCLUDEPATH = [os.path.join(pwd, "library"), os.path.join(pwd, "library-asm")]
144151

145152

146-
def setMode(mode: str) -> None:
153+
def setMode(mode: PreprocMode) -> None:
147154
global LEXER
148155

149156
mode = mode.upper()
150-
if mode not in ("ASM", "BASIC"):
157+
if mode not in list(PreprocMode):
151158
raise PreprocError('Invalid mode "%s"' % mode, lineno=LEXER.lineno)
152159

153-
if mode == "ASM":
154-
LEXER = zxbasmpplex.Lexer(defines_table=ID_TABLE)
155-
else:
156-
LEXER = zxbpplex.Lexer(defines_table=ID_TABLE)
160+
lexers = {
161+
PreprocMode.ASM: zxbasmpplex.Lexer(defines_table=ID_TABLE),
162+
PreprocMode.BASIC: zxbpplex.Lexer(defines_table=ID_TABLE),
163+
}
164+
165+
LEXER = lexers[PreprocMode(mode)]
157166

158167

159168
def search_filename(fname: str, lineno: int, local_first: bool) -> str:
@@ -862,7 +871,7 @@ def entry_point(args=None):
862871

863872
config.init()
864873
init()
865-
setMode("BASIC")
874+
setMode(PreprocMode.BASIC)
866875

867876
parser = argparse.ArgumentParser()
868877
parser.add_argument(
@@ -924,6 +933,10 @@ def entry_point(args=None):
924933
config.OPTIONS.stderr_filename = options.stderr
925934
config.OPTIONS.stderr = utils.open_file(config.OPTIONS.stderr_filename, "wt", "utf-8")
926935

936+
_, ext = os.path.splitext(options.input_file)
937+
if ext.lower() == "asm":
938+
setMode(PreprocMode.ASM)
939+
927940
result = main([options.input_file] if options.input_file else [])
928941
if not global_.has_errors: # ok?
929942
if options.output_file:

tests/functional/error_macro.asm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#warning "this is a warning"
2+
#error "this is an error"
3+
nop
4+

tests/functional/test_errmsg.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,7 @@ ND.Controls.bas:4: error: Invalid argument 'dirData'
252252
ND.Controls.bas:2: warning: [W150] Variable 'dirData' is never used
253253
>>> process_file('zx48k/bad_fname_err4.bas', ['-S', '-q'])
254254
ND.Controls.bas:2: error: sub 'Controls_LABEL' declared but not implemented
255+
256+
>>> process_file('error_macro.asm')
257+
error_macro.asm:1: warning: this is a warning
258+
error_macro.asm:2: error: this is an error

0 commit comments

Comments
 (0)