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
9ced6e74
Commit
9ced6e74
authored
Aug 18, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move constants
parent
6740254c
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
103 additions
and
99 deletions
+103
-99
trans/tests/a_a_errtest.py
trans/tests/a_a_errtest.py
+1
-1
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+1
-1
trans/transpiler/consts.py
trans/transpiler/consts.py
+76
-76
trans/transpiler/phases/desugar_compare/__init__.py
trans/transpiler/phases/desugar_compare/__init__.py
+1
-19
trans/transpiler/phases/emit_cpp/consts.py
trans/transpiler/phases/emit_cpp/consts.py
+22
-0
trans/transpiler/phases/emit_cpp/expr.py
trans/transpiler/phases/emit_cpp/expr.py
+1
-1
trans/transpiler/phases/emit_cpp/function.py
trans/transpiler/phases/emit_cpp/function.py
+1
-1
No files found.
trans/tests/a_a_errtest.py
View file @
9ced6e74
...
@@ -6,4 +6,4 @@ def gàé():
...
@@ -6,4 +6,4 @@ def gàé():
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
if
True
:
if
True
:
a
,
b
=
g
àé
()
# abc
a
,
b
,
c
=
g
àé
()
# abc
\ No newline at end of file
\ No newline at end of file
trans/transpiler/__init__.py
View file @
9ced6e74
...
@@ -15,7 +15,7 @@ from transpiler.phases.desugar_op import DesugarOp
...
@@ -15,7 +15,7 @@ from transpiler.phases.desugar_op import DesugarOp
colorama
.
init
()
colorama
.
init
()
from
transpiler.consts
import
MAPPINGS
from
transpiler.
phases.emit_cpp.
consts
import
MAPPINGS
from
transpiler.exceptions
import
CompileError
from
transpiler.exceptions
import
CompileError
from
transpiler.phases.desugar_with
import
DesugarWith
from
transpiler.phases.desugar_with
import
DesugarWith
from
transpiler.phases.emit_cpp.file
import
FileVisitor
from
transpiler.phases.emit_cpp.file
import
FileVisitor
...
...
trans/transpiler/consts.py
View file @
9ced6e74
# coding: utf-8
# coding: utf-8
import
ast
import
ast
SYMBOLS
=
{
#
SYMBOLS = {
ast
.
Eq
:
"=="
,
#
ast.Eq: "==",
ast
.
NotEq
:
'!='
,
#
ast.NotEq: '!=',
ast
.
Pass
:
'/* pass */'
,
#
ast.Pass: '/* pass */',
ast
.
Mult
:
'*'
,
#
ast.Mult: '*',
ast
.
Add
:
'+'
,
#
ast.Add: '+',
ast
.
Sub
:
'-'
,
#
ast.Sub: '-',
ast
.
Div
:
'/'
,
#
ast.Div: '/',
ast
.
FloorDiv
:
'/'
,
# TODO
#
ast.FloorDiv: '/', # TODO
ast
.
Mod
:
'%'
,
#
ast.Mod: '%',
ast
.
Lt
:
'<'
,
#
ast.Lt: '<',
ast
.
Gt
:
'>'
,
#
ast.Gt: '>',
ast
.
GtE
:
'>='
,
#
ast.GtE: '>=',
ast
.
LtE
:
'<='
,
#
ast.LtE: '<=',
ast
.
LShift
:
'<<'
,
#
ast.LShift: '<<',
ast
.
RShift
:
'>>'
,
#
ast.RShift: '>>',
ast
.
BitXor
:
'^'
,
#
ast.BitXor: '^',
ast
.
BitOr
:
'|'
,
#
ast.BitOr: '|',
ast
.
BitAnd
:
'&'
,
#
ast.BitAnd: '&',
ast
.
Not
:
'!'
,
#
ast.Not: '!',
ast
.
IsNot
:
'!='
,
#
ast.IsNot: '!=',
ast
.
USub
:
'-'
,
#
ast.USub: '-',
ast
.
And
:
'&&'
,
#
ast.And: '&&',
ast
.
Or
:
'||'
#
ast.Or: '||'
}
#
}
"""Mapping of Python AST nodes to C++ symbols."""
#
"""Mapping of Python AST nodes to C++ symbols."""
#
DUNDER_SYMBOLS
=
{
#
DUNDER_SYMBOLS = {
"__eq__"
:
"=="
,
#
"__eq__": "==",
"__ne__"
:
"!="
,
#
"__ne__": "!=",
"__lt__"
:
"<"
,
#
"__lt__": "<",
"__gt__"
:
">"
,
#
"__gt__": ">",
"__ge__"
:
">="
,
#
"__ge__": ">=",
"__le__"
:
"<="
,
#
"__le__": "<=",
"__add__"
:
"+"
,
#
"__add__": "+",
"__sub__"
:
"-"
,
#
"__sub__": "-",
"__mul__"
:
"*"
,
#
"__mul__": "*",
"__div__"
:
"/"
,
#
"__div__": "/",
"__mod__"
:
"%"
,
#
"__mod__": "%",
"__lshift__"
:
"<<"
,
#
"__lshift__": "<<",
"__rshift__"
:
">>"
,
#
"__rshift__": ">>",
"__xor__"
:
"^"
,
#
"__xor__": "^",
"__or__"
:
"|"
,
#
"__or__": "|",
"__and__"
:
"&"
,
#
"__and__": "&",
"__invert__"
:
"~"
,
#
"__invert__": "~",
"__neg__"
:
"-"
,
#
"__neg__": "-",
"__pos__"
:
"+"
,
#
"__pos__": "+",
}
#
}
#
PRECEDENCE
=
[
#
PRECEDENCE = [
(
"()"
,
"[]"
,
"."
,),
#
("()", "[]", ".",),
(
"unary"
,
"co_await"
),
#
("unary", "co_await"),
(
"*"
,
"/"
,
"%"
,),
#
("*", "/", "%",),
(
"+"
,
"-"
),
#
("+", "-"),
(
"<<"
,
">>"
),
#
("<<", ">>"),
(
"<"
,
"<="
,
">"
,
">="
),
#
("<", "<=", ">", ">="),
(
"=="
,
"!="
),
#
("==", "!="),
(
"&"
,),
#
("&",),
(
"^"
,),
#
("^",),
(
"|"
,),
#
("|",),
(
"&&"
,),
#
("&&",),
(
"||"
,),
#
("||",),
(
"?:"
,
"co_yield"
),
#
("?:", "co_yield"),
(
","
,)
#
(",",)
]
#
]
"""Precedence of C++ operators."""
#
"""Precedence of C++ operators."""
#
PRECEDENCE_LEVELS
=
{
op
:
i
for
i
,
ops
in
enumerate
(
PRECEDENCE
)
for
op
in
ops
}
#
PRECEDENCE_LEVELS = {op: i for i, ops in enumerate(PRECEDENCE) for op in ops}
"""Mapping of C++ operators to their precedence level."""
#
"""Mapping of C++ operators to their precedence level."""
#
MAPPINGS
=
{
#
MAPPINGS = {
"True"
:
"true"
,
#
"True": "true",
"False"
:
"false"
,
#
"False": "false",
"None"
:
"nullptr"
#
"None": "nullptr"
}
#
}
"""Mapping of Python builtin constants to C++ equivalents."""
#
"""Mapping of Python builtin constants to C++ equivalents."""
trans/transpiler/phases/desugar_compare/__init__.py
View file @
9ced6e74
...
@@ -35,21 +35,3 @@ class DesugarCompare(ast.NodeTransformer):
...
@@ -35,21 +35,3 @@ class DesugarCompare(ast.NodeTransformer):
if
len
(
res
.
values
)
==
1
:
if
len
(
res
.
values
)
==
1
:
return
res
.
values
[
0
]
return
res
.
values
[
0
]
return
res
return
res
# def visit_Compare(self, node: ast.Compare):
# res = ast.BoolOp(ast.And(), [], **linenodata(node))
# operands = list(map(self.visit, [node.left, *node.comparators]))
# for left, op, right in zip(operands, node.ops, operands[1:]):
# lnd = make_lnd(left, right)
# call = ast.Compare(
# left,
# [op],
# [right],
# **lnd
# )
# if type(op) == ast.NotIn:
# call = ast.UnaryOp(ast.Not(), call, **lnd)
# res.values.append(call)
# if len(res.values) == 1:
# return res.values[0]
# return res
trans/transpiler/phases/emit_cpp/consts.py
View file @
9ced6e74
...
@@ -28,6 +28,28 @@ SYMBOLS = {
...
@@ -28,6 +28,28 @@ SYMBOLS = {
}
}
"""Mapping of Python AST nodes to C++ symbols."""
"""Mapping of Python AST nodes to C++ symbols."""
DUNDER_SYMBOLS
=
{
"__eq__"
:
"=="
,
"__ne__"
:
"!="
,
"__lt__"
:
"<"
,
"__gt__"
:
">"
,
"__ge__"
:
">="
,
"__le__"
:
"<="
,
"__add__"
:
"+"
,
"__sub__"
:
"-"
,
"__mul__"
:
"*"
,
"__div__"
:
"/"
,
"__mod__"
:
"%"
,
"__lshift__"
:
"<<"
,
"__rshift__"
:
">>"
,
"__xor__"
:
"^"
,
"__or__"
:
"|"
,
"__and__"
:
"&"
,
"__invert__"
:
"~"
,
"__neg__"
:
"-"
,
"__pos__"
:
"+"
,
}
PRECEDENCE
=
[
PRECEDENCE
=
[
(
"()"
,
"[]"
,
"."
,),
(
"()"
,
"[]"
,
"."
,),
(
"unary"
,
"co_await"
),
(
"unary"
,
"co_await"
),
...
...
trans/transpiler/phases/emit_cpp/expr.py
View file @
9ced6e74
...
@@ -6,7 +6,7 @@ from typing import List, Iterable
...
@@ -6,7 +6,7 @@ from typing import List, Iterable
from
transpiler.phases.typing.types
import
UserType
,
FunctionType
,
Promise
from
transpiler.phases.typing.types
import
UserType
,
FunctionType
,
Promise
from
transpiler.phases.utils
import
make_lnd
from
transpiler.phases.utils
import
make_lnd
from
transpiler.utils
import
compare_ast
,
linenodata
from
transpiler.utils
import
compare_ast
,
linenodata
from
transpiler.consts
import
SYMBOLS
,
PRECEDENCE_LEVELS
,
DUNDER_SYMBOLS
from
transpiler.
phases.emit_cpp.
consts
import
SYMBOLS
,
PRECEDENCE_LEVELS
,
DUNDER_SYMBOLS
from
transpiler.phases.emit_cpp
import
CoroutineMode
,
join
,
NodeVisitor
from
transpiler.phases.emit_cpp
import
CoroutineMode
,
join
,
NodeVisitor
from
transpiler.phases.typing.scope
import
Scope
,
VarKind
from
transpiler.phases.typing.scope
import
Scope
,
VarKind
...
...
trans/transpiler/phases/emit_cpp/function.py
View file @
9ced6e74
...
@@ -3,7 +3,7 @@ import ast
...
@@ -3,7 +3,7 @@ import ast
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
from
typing
import
Iterable
from
typing
import
Iterable
from
transpiler.consts
import
SYMBOLS
from
transpiler.
phases.emit_cpp.
consts
import
SYMBOLS
from
transpiler.phases.emit_cpp
import
CoroutineMode
from
transpiler.phases.emit_cpp
import
CoroutineMode
from
transpiler.phases.emit_cpp.block
import
BlockVisitor
from
transpiler.phases.emit_cpp.block
import
BlockVisitor
from
transpiler.phases.typing.scope
import
Scope
from
transpiler.phases.typing.scope
import
Scope
...
...
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