main+ir: fix errors with REPL input (and wrong output in error messages)
This commit is contained in:
parent
103339d666
commit
37bfd831f4
2 changed files with 9 additions and 8 deletions
|
|
@ -65,8 +65,8 @@ def main():
|
|||
|
||||
context.check()
|
||||
|
||||
intermediate_representation = ir.IR(ast, source=data)
|
||||
intermediate_representation.update_location()
|
||||
intermediate_representation = ir.IR(ast)
|
||||
intermediate_representation.update_location(source=tokens.data)
|
||||
|
||||
print("\n---\n", repr(context))
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ def main():
|
|||
e.pretty_print()
|
||||
|
||||
finally:
|
||||
CompilationWarning.show_warnings(data, file=sys.stdout)
|
||||
CompilationWarning.show_warnings(tokens.data, file=sys.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -260,7 +260,7 @@ def _to_text(ir: list[IRItem]) -> list[str]:
|
|||
|
||||
class IR:
|
||||
|
||||
def __init__(self, ast: nodes.Node, source: str):
|
||||
def __init__(self, ast: nodes.Node):
|
||||
node_ir = ast.intermediate_representation()
|
||||
|
||||
assert all((isinstance(ir, IRAction) for ir in node_ir))
|
||||
|
|
@ -268,17 +268,15 @@ class IR:
|
|||
# noinspection PyTypeChecker
|
||||
self.intermediate_representation: list[IRAction] = node_ir
|
||||
|
||||
self.source = source
|
||||
|
||||
def code(self) -> list[str]:
|
||||
return [x.codegen() for x in self.intermediate_representation]
|
||||
|
||||
def update_location(self):
|
||||
def update_location(self, source: str):
|
||||
code = self.code()
|
||||
ir_item: IRAction
|
||||
for i, ir_item in enumerate(self.intermediate_representation):
|
||||
ir_item.ir_location = Location(line=i, ir=code)
|
||||
ir_item.location.source = self.source
|
||||
ir_item.location.source = source
|
||||
|
||||
def pretty_print(self):
|
||||
messages = []
|
||||
|
|
@ -286,6 +284,9 @@ class IR:
|
|||
for i, ir_item in enumerate(self.intermediate_representation):
|
||||
prefix = f"{str(ir_item.location) + ':':<30}"
|
||||
source_info = ir_item.location.source_substring.splitlines(keepends=False)
|
||||
logger.debug(f"source: {repr(ir_item.location.source)}")
|
||||
if len(source_info) == 0:
|
||||
source_info = ["<NO SOURCE>"]
|
||||
messages += [f"# {prefix} {source_info.pop(0)}"]
|
||||
while len(source_info) > 0:
|
||||
messages += [f"# {' ' * len(prefix)} {source_info.pop(0)}"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue