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
9bd19dba
Commit
9bd19dba
authored
Nov 14, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use __ for traceback info
parent
775f5b0b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
22 additions
and
22 deletions
+22
-22
typon/trans/transpiler/__init__.py
typon/trans/transpiler/__init__.py
+4
-4
typon/trans/transpiler/phases/emit_cpp/__init__.py
typon/trans/transpiler/phases/emit_cpp/__init__.py
+2
-2
typon/trans/transpiler/phases/emit_cpp/file.py
typon/trans/transpiler/phases/emit_cpp/file.py
+1
-1
typon/trans/transpiler/phases/emit_cpp/module.py
typon/trans/transpiler/phases/emit_cpp/module.py
+2
-2
typon/trans/transpiler/phases/typing/block.py
typon/trans/transpiler/phases/typing/block.py
+4
-4
typon/trans/transpiler/phases/typing/common.py
typon/trans/transpiler/phases/typing/common.py
+3
-3
typon/trans/transpiler/phases/typing/expr.py
typon/trans/transpiler/phases/typing/expr.py
+2
-2
typon/trans/transpiler/phases/typing/types.py
typon/trans/transpiler/phases/typing/types.py
+2
-2
typon/trans/transpiler/phases/utils.py
typon/trans/transpiler/phases/utils.py
+1
-1
typon/trans/transpiler/utils.py
typon/trans/transpiler/utils.py
+1
-1
No files found.
typon/trans/transpiler/__init__.py
View file @
9bd19dba
...
...
@@ -50,10 +50,10 @@ def exception_hook(exc_type, exc_value, tb):
if
name
==
"visit"
and
(
node
:
=
local_vars
[
"node"
])
and
isinstance
(
node
,
ast
.
AST
):
last_node
=
node
if
node
:
=
local_vars
.
get
(
"
TB_NODE
"
,
None
):
if
node
:
=
local_vars
.
get
(
"
__TB_NODE__
"
,
None
):
last_node
=
node
if
local_vars
.
get
(
"
TB_SKIP
"
,
None
)
and
tb
.
tb_next
:
if
local_vars
.
get
(
"
__TB_SKIP__
"
,
None
)
and
tb
.
tb_next
:
tb
=
tb
.
tb_next
continue
...
...
@@ -61,7 +61,7 @@ def exception_hook(exc_type, exc_value, tb):
line_no
=
tb
.
tb_lineno
print
(
cf
.
red
(
f"File
{
filename
}
:
{
line_no
}
, in
{
cf
.
green
(
name
)
}
"
),
end
=
""
)
if
info
:
=
local_vars
.
get
(
"
TB
"
,
None
):
if
info
:
=
local_vars
.
get
(
"
__TB__
"
,
None
):
print
(
f":
{
cf
.
magenta
(
info
)
}\
x1b
[24m"
)
else
:
print
()
...
...
@@ -177,7 +177,7 @@ else:
def
transpile
(
source
,
name
:
str
,
path
=
None
):
TB
=
f"transpiling module
{
cf
.
white
(
name
)
}
"
__TB__
=
f"transpiling module
{
cf
.
white
(
name
)
}
"
res
=
ast
.
parse
(
source
,
type_comments
=
True
)
IfMainVisitor
().
visit
(
res
)
...
...
typon/trans/transpiler/phases/emit_cpp/__init__.py
View file @
9bd19dba
...
...
@@ -16,8 +16,8 @@ from transpiler.utils import UnsupportedNodeError, highlight
class
UniversalVisitor
:
def
visit
(
self
,
node
):
"""Visit a node."""
TB
=
f"emitting C++ code for
{
highlight
(
node
)
}
"
#
TB_SKIP
= True
__TB__
=
f"emitting C++ code for
{
highlight
(
node
)
}
"
#
__TB_SKIP__
= True
if
type
(
node
)
==
list
:
for
n
in
node
:
...
...
typon/trans/transpiler/phases/emit_cpp/file.py
View file @
9bd19dba
...
...
@@ -13,7 +13,7 @@ class FileVisitor(BlockVisitor):
module_name
:
str
def
visit_Module
(
self
,
node
:
ast
.
Module
)
->
Iterable
[
str
]:
TB
=
"emitting C++ code for Python module"
__TB__
=
"emitting C++ code for Python module"
stmt
:
ast
.
AST
yield
"#include <python/builtins.hpp>"
...
...
typon/trans/transpiler/phases/emit_cpp/module.py
View file @
9bd19dba
...
...
@@ -19,7 +19,7 @@ IGNORED_IMPORTS = {"typon", "typing", "__future__", "dataclasses", "enum"}
class
ModuleVisitor
(
BlockVisitor
):
includes
:
list
[
str
]
=
field
(
default_factory
=
list
)
def
visit_Import
(
self
,
node
:
ast
.
Import
)
->
Iterable
[
str
]:
TB
=
f"emitting C++ code for
{
highlight
(
node
)
}
"
__TB__
=
f"emitting C++ code for
{
highlight
(
node
)
}
"
for
alias
in
node
.
names
:
concrete
=
self
.
fix_name
(
alias
.
asname
or
alias
.
name
)
if
alias
.
module_obj
.
is_python
:
...
...
@@ -46,7 +46,7 @@ class ModuleVisitor(BlockVisitor):
yield
""
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
}
')
}
"
__TB__
=
f"emitting C++ code for Python function
{
highlight
(
f'
{
mod
}
.
{
name
}
')
}
"
yield
"struct {"
yield
f"auto operator()("
...
...
typon/trans/transpiler/phases/typing/block.py
View file @
9bd19dba
...
...
@@ -98,17 +98,17 @@ class ScoperBlockVisitor(ScoperVisitor):
node
.
is_declare
=
decl
if
node
.
value
is
not
None
:
ty_val
=
self
.
get_type
(
node
.
value
)
TB
=
f"unifying annotation
{
highlight
(
node
.
annotation
)
}
with value
{
highlight
(
node
.
value
)
}
of type
{
highlight
(
ty_val
)
}
"
__TB__
=
f"unifying annotation
{
highlight
(
node
.
annotation
)
}
with value
{
highlight
(
node
.
value
)
}
of type
{
highlight
(
ty_val
)
}
"
ty
.
unify
(
ty_val
)
def
visit_assign_target
(
self
,
target
,
decl_val
:
BaseType
)
->
bool
:
TB
=
f"analyzing assignment target
{
highlight
(
target
)
}
with value
{
highlight
(
decl_val
)
}
"
__TB__
=
f"analyzing assignment target
{
highlight
(
target
)
}
with value
{
highlight
(
decl_val
)
}
"
if
isinstance
(
target
,
ast
.
Name
):
if
target
.
id
==
"_"
:
return
False
target
.
type
=
decl_val
if
vdecl
:
=
self
.
scope
.
get
(
target
.
id
,
{
VarKind
.
LOCAL
,
VarKind
.
GLOBAL
,
VarKind
.
NONLOCAL
},
restrict_function
=
True
):
TB
=
f"unifying existing variable
{
highlight
(
target
.
id
)
}
of type
{
highlight
(
vdecl
.
type
)
}
with assigned value
{
highlight
(
decl_val
)
}
"
__TB__
=
f"unifying existing variable
{
highlight
(
target
.
id
)
}
of type
{
highlight
(
vdecl
.
type
)
}
with assigned value
{
highlight
(
decl_val
)
}
"
vdecl
.
type
.
unify
(
decl_val
)
return
False
else
:
...
...
@@ -333,7 +333,7 @@ class ScoperBlockVisitor(ScoperVisitor):
def
visit
(
self
,
node
:
ast
.
AST
):
if
isinstance
(
node
,
ast
.
AST
):
TB_SKIP
=
True
__TB_SKIP__
=
True
super
().
visit
(
node
)
node
.
scope
=
self
.
scope
else
:
...
...
typon/trans/transpiler/phases/typing/common.py
View file @
9bd19dba
...
...
@@ -57,7 +57,7 @@ class ScoperVisitor(NodeVisitorSeq):
def
visit_block
(
self
,
block
:
list
[
ast
.
AST
]):
if
not
block
:
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
])
}
"
self
.
fdecls
=
[]
for
b
in
block
:
self
.
visit
(
b
)
...
...
@@ -82,8 +82,8 @@ class ScoperVisitor(NodeVisitorSeq):
exc
=
None
def
visit_function_definition
(
self
,
node
,
rtype
):
TB
=
f"running type analysis on the body of
{
highlight
(
node
)
}
"
TB_NODE
=
node
__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
=
{}
...
...
typon/trans/transpiler/phases/typing/expr.py
View file @
9bd19dba
...
...
@@ -38,10 +38,10 @@ class ScoperExprVisitor(ScoperVisitor):
def
visit
(
self
,
node
)
->
BaseType
:
if
existing
:
=
getattr
(
node
,
"type"
,
None
):
return
existing
.
resolve
()
TB_SKIP
=
True
__TB_SKIP__
=
True
res
=
super
().
visit
(
node
)
if
not
res
:
TB_SKIP
=
False
__TB_SKIP__
=
False
raise
NotImplementedError
(
f"`
{
ast
.
unparse
(
node
)
}
`
{
type
(
node
)
}
"
)
res
=
res
.
resolve
()
if
True
or
not
hasattr
(
res
,
"from_node"
):
...
...
typon/trans/transpiler/phases/typing/types.py
View file @
9bd19dba
...
...
@@ -84,7 +84,7 @@ class BaseType(ABC):
def
unify
(
self
,
other
:
"BaseType"
,
mode
=
UnifyMode
.
NORMAL
):
a
,
b
=
self
.
resolve
(),
other
.
resolve
()
TB
=
f"unifying
{
highlight
(
a
)
}
and
{
highlight
(
b
)
}
"
__TB__
=
f"unifying
{
highlight
(
a
)
}
and
{
highlight
(
b
)
}
"
if
isinstance
(
b
,
TypeVariable
):
a
,
b
=
b
,
a
a
.
unify_internal
(
b
,
mode
)
...
...
@@ -261,7 +261,7 @@ class TypeOperator(BaseType, ABC):
from
transpiler.phases.typing.exceptions
import
TypeMismatchError
,
TypeMismatchKind
# 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
#
__TB_NODE__
= from_node
if
not
isinstance
(
other
,
TypeOperator
):
raise
TypeMismatchError
(
self
,
other
,
TypeMismatchKind
.
DIFFERENT_TYPE
)
if
mode
.
match_protocol
:
...
...
typon/trans/transpiler/phases/utils.py
View file @
9bd19dba
...
...
@@ -7,7 +7,7 @@ from transpiler.utils import UnsupportedNodeError, highlight
class
NodeVisitorSeq
:
def
visit
(
self
,
node
):
TB
=
f"running type analysis on
{
highlight
(
node
)
}
"
__TB__
=
f"running type analysis on
{
highlight
(
node
)
}
"
"""Visit a node."""
if
type
(
node
)
==
list
:
for
n
in
node
:
...
...
typon/trans/transpiler/utils.py
View file @
9bd19dba
...
...
@@ -61,7 +61,7 @@ def highlight(code, full=False):
"""
Syntax highlights code as Python using colorama
"""
TB
=
f"syntax highlighting
{
code
}
"
__TB__
=
f"syntax highlighting
{
code
}
"
if
code
is
None
:
return
cf
.
yellow
(
"<None>"
)
if
type
(
code
)
==
list
:
...
...
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