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
9a209460
Commit
9a209460
authored
Aug 02, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make inference run in multiple passes
parent
06f91a66
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
25 deletions
+33
-25
trans/__main__.py
trans/__main__.py
+2
-2
trans/tests/a_a_a_errtest.py
trans/tests/a_a_a_errtest.py
+0
-10
trans/tests/webserver.py
trans/tests/webserver.py
+2
-2
trans/transpiler/phases/emit_cpp/block.py
trans/transpiler/phases/emit_cpp/block.py
+2
-2
trans/transpiler/phases/if_main/__init__.py
trans/transpiler/phases/if_main/__init__.py
+1
-0
trans/transpiler/phases/typing/common.py
trans/transpiler/phases/typing/common.py
+25
-8
trans/transpiler/phases/typing/expr.py
trans/transpiler/phases/typing/expr.py
+1
-1
No files found.
trans/__main__.py
View file @
9a209460
...
...
@@ -57,8 +57,8 @@ path = Path(args.input[0])
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
code
=
f
.
read
()
from
.
transpiler
import
transpile
from
.
transpiler.format
import
format_code
from
transpiler
import
transpile
from
transpiler.format
import
format_code
raw_cpp
=
transpile
(
code
,
path
.
name
,
path
)
formatted
=
format_code
(
raw_cpp
)
...
...
trans/tests/a_a_a_errtest.py
View file @
9a209460
import
sys
import
math
x
=
[
6
]
x
=
5
u
=
(
math
.
abcd
)
# abcd
a
=
5
if
True
else
3
def
c
(
x
:
int
):
return
x
for
v
in
6
:
g
=
6
h
=
7
i
=
8
pass
if
__name__
==
"__main__"
:
pass
\ No newline at end of file
trans/tests/webserver.py
View file @
9a209460
...
...
@@ -29,7 +29,7 @@ def read_file(path):
fd
.
close
()
return
content
def
handle_connection
(
connfd
:
socket
,
filepath
):
def
handle_connection
(
connfd
,
filepath
):
buf
=
connfd
.
recv
(
1024
).
decode
(
"utf-8"
)
length
=
buf
.
find
(
"
\
r
\
n
\
r
\
n
"
)
content
=
read_file
(
filepath
)
...
...
@@ -37,7 +37,7 @@ def handle_connection(connfd: socket, filepath):
connfd
.
send
(
response
.
encode
(
"utf-8"
))
connfd
.
close
()
def
server_loop
(
sockfd
:
socket
,
filepath
):
def
server_loop
(
sockfd
,
filepath
):
while
True
:
connfd
,
_
=
sockfd
.
accept
()
...
...
trans/transpiler/phases/emit_cpp/block.py
View file @
9a209460
...
...
@@ -25,8 +25,8 @@ class BlockVisitor(NodeVisitor):
def
visit_Pass
(
self
,
node
:
ast
.
Pass
)
->
Iterable
[
str
]:
yield
";"
def
visit_FunctionDef
(
self
,
node
:
ast
.
FunctionDef
)
->
Iterable
[
str
]:
yield
from
self
.
visit_free_func
(
node
)
#
def visit_FunctionDef(self, node: ast.FunctionDef) -> Iterable[str]:
#
yield from self.visit_free_func(node)
def
visit_free_func
(
self
,
node
:
ast
.
FunctionDef
,
emission
:
FunctionEmissionKind
)
->
Iterable
[
str
]:
if
getattr
(
node
,
"is_main"
,
False
):
...
...
trans/transpiler/phases/if_main/__init__.py
View file @
9a209460
...
...
@@ -12,5 +12,6 @@ class IfMainVisitor(ast.NodeVisitor):
new_node
=
ast
.
parse
(
"def main(): pass"
).
body
[
0
]
new_node
.
body
=
stmt
.
body
new_node
.
is_main
=
True
node
.
main_if
=
new_node
node
.
body
[
i
]
=
new_node
return
\ No newline at end of file
trans/transpiler/phases/typing/common.py
View file @
9a209460
...
...
@@ -28,7 +28,14 @@ class ScoperVisitor(NodeVisitorSeq):
self
.
fdecls
=
[]
for
b
in
block
:
self
.
visit
(
b
)
for
node
,
rtype
in
self
.
fdecls
:
if
self
.
fdecls
:
old_list
=
self
.
fdecls
exc
=
None
while
True
:
new_list
=
[]
for
node
,
rtype
in
old_list
:
from
transpiler.exceptions
import
CompileError
try
:
for
b
in
node
.
body
:
decls
=
{}
visitor
=
ScoperBlockVisitor
(
node
.
inner_scope
,
decls
)
...
...
@@ -36,4 +43,14 @@ class ScoperVisitor(NodeVisitorSeq):
b
.
decls
=
decls
if
not
node
.
inner_scope
.
has_return
:
rtype
.
unify
(
TY_NONE
)
# todo: properly indicate missing return
except
CompileError
as
e
:
new_list
.
append
((
node
,
rtype
))
if
not
exc
:
exc
=
e
if
len
(
new_list
)
==
len
(
old_list
):
raise
exc
if
not
new_list
:
break
old_list
=
new_list
exc
=
None
trans/transpiler/phases/typing/expr.py
View file @
9a209460
...
...
@@ -34,7 +34,7 @@ DUNDER = {
class
ScoperExprVisitor
(
ScoperVisitor
):
def
visit
(
self
,
node
)
->
BaseType
:
if
existing
:
=
getattr
(
node
,
"type"
,
None
):
return
existing
return
existing
.
resolve
()
res
=
super
().
visit
(
node
)
if
not
res
:
raise
NotImplementedError
(
f"`
{
ast
.
unparse
(
node
)
}
`
{
type
(
node
)
}
"
)
...
...
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