Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#586 from boriel/bugfix/preproc_asm_er…
Browse files Browse the repository at this point in the history
…ror_missing

Bugfix/preproc asm error missing
  • Loading branch information
boriel committed Nov 14, 2021
2 parents 450da44 + 2572f5a commit 286b577
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/zxbc/zxbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def main(args=None, emitter=None):

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

asm_output = asm_output.split("\n")
for i in range(len(asm_output)):
Expand Down
2 changes: 2 additions & 0 deletions src/zxbpp/zxbasmpplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
"line": "LINE",
"require": "REQUIRE",
"pragma": "PRAGMA",
"error": "ERROR",
"warning": "WARNING",
}

# List of token names.
Expand Down
27 changes: 20 additions & 7 deletions src/zxbpp/zxbpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import re

from dataclasses import dataclass
from enum import Enum, unique

from typing import Any
from typing import Dict
Expand Down Expand Up @@ -45,6 +46,12 @@
from src import arch


@unique
class PreprocMode(str, Enum):
BASIC = "BASIC"
ASM = "ASM"


# Generated output
OUTPUT = ""

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


def setMode(mode: str) -> None:
def setMode(mode: PreprocMode) -> None:
global LEXER

mode = mode.upper()
if mode not in ("ASM", "BASIC"):
if mode not in list(PreprocMode):
raise PreprocError('Invalid mode "%s"' % mode, lineno=LEXER.lineno)

if mode == "ASM":
LEXER = zxbasmpplex.Lexer(defines_table=ID_TABLE)
else:
LEXER = zxbpplex.Lexer(defines_table=ID_TABLE)
lexers = {
PreprocMode.ASM: zxbasmpplex.Lexer(defines_table=ID_TABLE),
PreprocMode.BASIC: zxbpplex.Lexer(defines_table=ID_TABLE),
}

LEXER = lexers[PreprocMode(mode)]


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

config.init()
init()
setMode("BASIC")
setMode(PreprocMode.BASIC)

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

_, ext = os.path.splitext(options.input_file)
if ext.lower() == "asm":
setMode(PreprocMode.ASM)

result = main([options.input_file] if options.input_file else [])
if not global_.has_errors: # ok?
if options.output_file:
Expand Down
4 changes: 4 additions & 0 deletions tests/functional/error_macro.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#warning "this is a warning"
#error "this is an error"
nop

4 changes: 4 additions & 0 deletions tests/functional/test_errmsg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,7 @@ ND.Controls.bas:4: error: Invalid argument 'dirData'
ND.Controls.bas:2: warning: [W150] Variable 'dirData' is never used
>>> process_file('zx48k/bad_fname_err4.bas', ['-S', '-q'])
ND.Controls.bas:2: error: sub 'Controls_LABEL' declared but not implemented

>>> process_file('error_macro.asm')
error_macro.asm:1: warning: this is a warning
error_macro.asm:2: error: this is an error

0 comments on commit 286b577

Please sign in to comment.