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
e65a0e3f
Commit
e65a0e3f
authored
Jul 27, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance error display
parent
b761813b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
5 deletions
+9
-5
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+5
-2
trans/transpiler/phases/emit_cpp/module.py
trans/transpiler/phases/emit_cpp/module.py
+3
-2
trans/transpiler/phases/typing/exceptions.py
trans/transpiler/phases/typing/exceptions.py
+1
-1
No files found.
trans/transpiler/__init__.py
View file @
e65a0e3f
...
...
@@ -4,6 +4,7 @@ import builtins
import
inspect
from
transpiler.consts
import
MAPPINGS
from
transpiler.exceptions
import
CompileError
from
transpiler.phases.desugar_with
import
DesugarWith
#from transpiler.phases import initial_pytype
from
transpiler.phases.emit_cpp.file
import
FileVisitor
...
...
@@ -51,9 +52,11 @@ def exception_hook(exc_type, exc_value, tb):
if
last_node
is
not
None
:
print
(
f"In file
\
"
{
Fore
.
RESET
}{
last_file
}{
Fore
.
RED
}\
"
, line
{
last_node
.
lineno
}
"
)
print
(
"
\
t
"
+
highlight
(
ast
.
unparse
(
last_node
)))
print
()
print
(
f"
{
Fore
.
RED
}
Error:
{
Fore
.
RESET
}
{
exc_value
}
"
)
print
(
inspect
.
cleandoc
(
exc_value
.
detail
(
last_node
)))
if
isinstance
(
exc_value
,
CompileError
):
print
(
inspect
.
cleandoc
(
exc_value
.
detail
(
last_node
)))
print
()
sys
.
excepthook
=
exception_hook
...
...
trans/transpiler/phases/emit_cpp/module.py
View file @
e65a0e3f
...
...
@@ -46,7 +46,8 @@ class ModuleVisitor(BlockVisitor):
def
emit_python_func
(
self
,
mod
:
str
,
name
:
str
,
alias
:
str
,
fty
:
FunctionType
)
->
Iterable
[
str
]:
TB
=
f"emitting C++ code for Python function
{
highlight
(
f'
{
mod
}
.
{
name
}
')
}
"
yield
f"auto
{
alias
}
("
yield
"struct {"
yield
f"auto operator()("
for
i
,
argty
in
enumerate
(
fty
.
parameters
):
if
i
!=
0
:
...
...
@@ -66,6 +67,7 @@ class ModuleVisitor(BlockVisitor):
yield
from
self
.
visit
(
fty
.
return_type
)
yield
">();"
yield
"}"
yield
f"}}
{
alias
}
;"
def
visit_ImportFrom
(
self
,
node
:
ast
.
ImportFrom
)
->
Iterable
[
str
]:
if
node
.
module_obj
.
is_python
:
...
...
@@ -74,7 +76,6 @@ class ModuleVisitor(BlockVisitor):
assert
isinstance
(
fty
,
FunctionType
)
yield
from
self
.
emit_python_func
(
node
.
module
,
alias
.
name
,
alias
.
asname
or
alias
.
name
,
fty
)
yield
"// python"
elif
node
.
module
in
{
"typon"
,
"typing"
,
"__future__"
}:
yield
""
else
:
...
...
trans/transpiler/phases/typing/exceptions.py
View file @
e65a0e3f
...
...
@@ -23,7 +23,7 @@ class UnresolvedTypeVariableError(CompileError):
As such, you need to give enough information to the compiler to infer the type of the function.
For example:
vvv
this tells the compiler that
{
highlight
(
'math.factorial'
)
}
returns an
{
highlight
(
'int'
)
}
↓↓↓
this tells the compiler that
{
highlight
(
'math.factorial'
)
}
returns an
{
highlight
(
'int'
)
}
{
highlight
(
'res: int = math.factorial(5)'
)
}
"""
return
"""
This generally indicates the compiler was unable to infer the type of a variable or expression.
...
...
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