Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-compiler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-compiler
Commits
d0c84863
Commit
d0c84863
authored
Aug 11, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract method for better traceback
parent
fc4a6b28
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
11 deletions
+19
-11
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+3
-1
trans/transpiler/phases/typing/common.py
trans/transpiler/phases/typing/common.py
+13
-8
trans/transpiler/phases/typing/types.py
trans/transpiler/phases/typing/types.py
+3
-2
No files found.
trans/transpiler/__init__.py
View file @
d0c84863
...
...
@@ -97,7 +97,9 @@ def exception_hook(exc_type, exc_value, tb):
for
i
,
line
in
enumerate
(
hg
[
start
:
last_node
.
end_lineno
+
CONTEXT_SIZE
]):
erroneous
=
last_node
.
lineno
<=
offset
+
i
<=
last_node
.
end_lineno
indicator
=
cf
.
white
(
" →"
)
if
erroneous
else
" "
disp
=
f"
\
x1b
[24m
{
indicator
}{
cf
.
white
}{
(
offset
+
i
):
>
4
}{
cf
.
red
if
erroneous
else
cf
.
reset
}
▎
{
cf
.
reset
}
{
line
}\
x1b
[24m"
bar
=
" ▎"
# bar = "│" if erroneous else "┊"
disp
=
f"
\
x1b
[24m
{
indicator
}{
cf
.
white
}{
(
offset
+
i
):
>
4
}{
cf
.
red
if
erroneous
else
cf
.
reset
}{
bar
}{
cf
.
reset
}
{
line
}\
x1b
[24m"
print
(
disp
)
# print(repr(disp))
print
()
...
...
trans/transpiler/phases/typing/common.py
View file @
d0c84863
...
...
@@ -28,7 +28,6 @@ class ScoperVisitor(NodeVisitorSeq):
if
not
block
:
return
TB
=
f"running type analysis on block starting with
{
highlight
(
block
[
0
])
}
"
from
transpiler.phases.typing.block
import
ScoperBlockVisitor
self
.
fdecls
=
[]
for
b
in
block
:
self
.
visit
(
b
)
...
...
@@ -40,13 +39,7 @@ class ScoperVisitor(NodeVisitorSeq):
for
node
,
rtype
in
old_list
:
from
transpiler.exceptions
import
CompileError
try
:
for
b
in
node
.
body
:
decls
=
{}
visitor
=
ScoperBlockVisitor
(
node
.
inner_scope
,
decls
)
visitor
.
visit
(
b
)
b
.
decls
=
decls
if
not
node
.
inner_scope
.
has_return
:
rtype
.
unify
(
TY_NONE
)
# todo: properly indicate missing return
self
.
visit_function_definition
(
node
,
rtype
)
except
CompileError
as
e
:
new_list
.
append
((
node
,
rtype
))
if
not
exc
:
...
...
@@ -58,3 +51,15 @@ class ScoperVisitor(NodeVisitorSeq):
old_list
=
new_list
exc
=
None
def
visit_function_definition
(
self
,
node
,
rtype
):
TB
=
f"running type analysis on the body of
{
highlight
(
node
)
}
"
TB_NODE
=
node
from
transpiler.phases.typing.block
import
ScoperBlockVisitor
for
b
in
node
.
body
:
decls
=
{}
visitor
=
ScoperBlockVisitor
(
node
.
inner_scope
,
decls
)
visitor
.
visit
(
b
)
b
.
decls
=
decls
if
not
node
.
inner_scope
.
has_return
:
rtype
.
unify
(
TY_NONE
)
# todo: properly indicate missing return
trans/transpiler/phases/typing/types.py
View file @
d0c84863
...
...
@@ -174,8 +174,9 @@ class TypeOperator(BaseType, ABC):
def
unify_internal
(
self
,
other
:
BaseType
):
from
transpiler.phases.typing.exceptions
import
TypeMismatchError
,
TypeMismatchKind
if
from_node
:
=
next
(
filter
(
None
,
(
getattr
(
x
,
"from_node"
,
None
)
for
x
in
(
other
,
self
))),
None
):
TB_NODE
=
from_node
# TODO(zdimension): this is really broken... but it would be nice
# if from_node := next(filter(None, (getattr(x, "from_node", None) for x in (other, self))), None):
# TB_NODE = from_node
if
not
isinstance
(
other
,
TypeOperator
):
raise
TypeMismatchError
(
self
,
other
,
TypeMismatchKind
.
DIFFERENT_TYPE
)
if
other
.
is_protocol
and
not
self
.
is_protocol
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment