Commit aec0e5c2 authored by Tom Niget's avatar Tom Niget

Add proper display for ICEs

parent 13764aba
...@@ -5,8 +5,13 @@ import importlib ...@@ -5,8 +5,13 @@ import importlib
import inspect import inspect
import os import os
import traceback
#os.environ["TERM"] = "xterm-256" #os.environ["TERM"] = "xterm-256"
import colorama import colorama
from transpiler.phases.desugar_compare import DesugarCompare
colorama.init() colorama.init()
from transpiler.consts import MAPPINGS from transpiler.consts import MAPPINGS
...@@ -32,6 +37,8 @@ def exception_hook(exc_type, exc_value, tb): ...@@ -32,6 +37,8 @@ def exception_hook(exc_type, exc_value, tb):
last_node = None last_node = None
last_file = None last_file = None
orig_tb = tb
while tb: while tb:
local_vars = tb.tb_frame.f_locals local_vars = tb.tb_frame.f_locals
name = tb.tb_frame.f_code.co_name name = tb.tb_frame.f_code.co_name
...@@ -103,12 +110,17 @@ def exception_hook(exc_type, exc_value, tb): ...@@ -103,12 +110,17 @@ def exception_hook(exc_type, exc_value, tb):
print(disp) print(disp)
# print(repr(disp)) # print(repr(disp))
print() print()
print(cf.red("Error:"), exc_value)
if isinstance(exc_value, CompileError): if isinstance(exc_value, CompileError):
print(cf.red("Error:"), exc_value)
detail = inspect.cleandoc(exc_value.detail(last_node)) detail = inspect.cleandoc(exc_value.detail(last_node))
if detail: if detail:
print() print()
print(detail) print(detail)
else:
print(cf.red("Internal Compiler Error:"), exc_value)
print()
print("Please report this error to the Typon maintainers.")
traceback.print_tb(orig_tb, limit=-1)
print() print()
def find_indices(s, indices: list[int]) -> list[int]: def find_indices(s, indices: list[int]) -> list[int]:
...@@ -162,8 +174,9 @@ def transpile(source, name="<module>", path=None): ...@@ -162,8 +174,9 @@ def transpile(source, name="<module>", path=None):
res = ast.parse(source, type_comments=True) res = ast.parse(source, type_comments=True)
# res = initial_pytype.run(source, res) # res = initial_pytype.run(source, res)
res = DesugarWith().visit(res)
IfMainVisitor().visit(res) IfMainVisitor().visit(res)
res = DesugarWith().visit(res)
res = DesugarCompare().visit(res)
ScoperBlockVisitor().visit(res) ScoperBlockVisitor().visit(res)
# print(res.scope) # print(res.scope)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment