Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
7d69d7e2
Commit
7d69d7e2
authored
Aug 11, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract method for better traceback
parent
a93954c6
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 @
7d69d7e2
...
@@ -97,7 +97,9 @@ def exception_hook(exc_type, exc_value, tb):
...
@@ -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
]):
for
i
,
line
in
enumerate
(
hg
[
start
:
last_node
.
end_lineno
+
CONTEXT_SIZE
]):
erroneous
=
last_node
.
lineno
<=
offset
+
i
<=
last_node
.
end_lineno
erroneous
=
last_node
.
lineno
<=
offset
+
i
<=
last_node
.
end_lineno
indicator
=
cf
.
white
(
" →"
)
if
erroneous
else
" "
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
(
disp
)
# print(repr(disp))
# print(repr(disp))
print
()
print
()
...
...
trans/transpiler/phases/typing/common.py
View file @
7d69d7e2
...
@@ -28,7 +28,6 @@ class ScoperVisitor(NodeVisitorSeq):
...
@@ -28,7 +28,6 @@ class ScoperVisitor(NodeVisitorSeq):
if
not
block
:
if
not
block
:
return
return
TB
=
f"running type analysis on block starting with
{
highlight
(
block
[
0
])
}
"
TB
=
f"running type analysis on block starting with
{
highlight
(
block
[
0
])
}
"
from
transpiler.phases.typing.block
import
ScoperBlockVisitor
self
.
fdecls
=
[]
self
.
fdecls
=
[]
for
b
in
block
:
for
b
in
block
:
self
.
visit
(
b
)
self
.
visit
(
b
)
...
@@ -40,13 +39,7 @@ class ScoperVisitor(NodeVisitorSeq):
...
@@ -40,13 +39,7 @@ class ScoperVisitor(NodeVisitorSeq):
for
node
,
rtype
in
old_list
:
for
node
,
rtype
in
old_list
:
from
transpiler.exceptions
import
CompileError
from
transpiler.exceptions
import
CompileError
try
:
try
:
for
b
in
node
.
body
:
self
.
visit_function_definition
(
node
,
rtype
)
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
except
CompileError
as
e
:
except
CompileError
as
e
:
new_list
.
append
((
node
,
rtype
))
new_list
.
append
((
node
,
rtype
))
if
not
exc
:
if
not
exc
:
...
@@ -58,3 +51,15 @@ class ScoperVisitor(NodeVisitorSeq):
...
@@ -58,3 +51,15 @@ class ScoperVisitor(NodeVisitorSeq):
old_list
=
new_list
old_list
=
new_list
exc
=
None
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 @
7d69d7e2
...
@@ -174,8 +174,9 @@ class TypeOperator(BaseType, ABC):
...
@@ -174,8 +174,9 @@ class TypeOperator(BaseType, ABC):
def
unify_internal
(
self
,
other
:
BaseType
):
def
unify_internal
(
self
,
other
:
BaseType
):
from
transpiler.phases.typing.exceptions
import
TypeMismatchError
,
TypeMismatchKind
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
):
# TODO(zdimension): this is really broken... but it would be nice
TB_NODE
=
from_node
# 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
):
if
not
isinstance
(
other
,
TypeOperator
):
raise
TypeMismatchError
(
self
,
other
,
TypeMismatchKind
.
DIFFERENT_TYPE
)
raise
TypeMismatchError
(
self
,
other
,
TypeMismatchKind
.
DIFFERENT_TYPE
)
if
other
.
is_protocol
and
not
self
.
is_protocol
:
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