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
7e04915c
Commit
7e04915c
authored
Aug 18, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move constants
parent
ac78d6fd
Changes
7
Hide 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 @
7e04915c
...
...
@@ -6,4 +6,4 @@ def gàé():
if
__name__
==
"__main__"
:
if
True
:
a
,
b
=
g
àé
()
# abc
\ No newline at end of file
a
,
b
,
c
=
g
àé
()
# abc
\ No newline at end of file
trans/transpiler/__init__.py
View file @
7e04915c
...
...
@@ -15,7 +15,7 @@ from transpiler.phases.desugar_op import DesugarOp
colorama
.
init
()
from
transpiler.consts
import
MAPPINGS
from
transpiler.
phases.emit_cpp.
consts
import
MAPPINGS
from
transpiler.exceptions
import
CompileError
from
transpiler.phases.desugar_with
import
DesugarWith
from
transpiler.phases.emit_cpp.file
import
FileVisitor
...
...
trans/transpiler/consts.py
View file @
7e04915c
# coding: utf-8
import
ast
SYMBOLS
=
{
ast
.
Eq
:
"=="
,
ast
.
NotEq
:
'!='
,
ast
.
Pass
:
'/* pass */'
,
ast
.
Mult
:
'*'
,
ast
.
Add
:
'+'
,
ast
.
Sub
:
'-'
,
ast
.
Div
:
'/'
,
ast
.
FloorDiv
:
'/'
,
# TODO
ast
.
Mod
:
'%'
,
ast
.
Lt
:
'<'
,
ast
.
Gt
:
'>'
,
ast
.
GtE
:
'>='
,
ast
.
LtE
:
'<='
,
ast
.
LShift
:
'<<'
,
ast
.
RShift
:
'>>'
,
ast
.
BitXor
:
'^'
,
ast
.
BitOr
:
'|'
,
ast
.
BitAnd
:
'&'
,
ast
.
Not
:
'!'
,
ast
.
IsNot
:
'!='
,
ast
.
USub
:
'-'
,
ast
.
And
:
'&&'
,
ast
.
Or
:
'||'
}
"""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
=
[
(
"()"
,
"[]"
,
"."
,),
(
"unary"
,
"co_await"
),
(
"*"
,
"/"
,
"%"
,),
(
"+"
,
"-"
),
(
"<<"
,
">>"
),
(
"<"
,
"<="
,
">"
,
">="
),
(
"=="
,
"!="
),
(
"&"
,),
(
"^"
,),
(
"|"
,),
(
"&&"
,),
(
"||"
,),
(
"?:"
,
"co_yield"
),
(
","
,)
]
"""Precedence of C++ operators."""
PRECEDENCE_LEVELS
=
{
op
:
i
for
i
,
ops
in
enumerate
(
PRECEDENCE
)
for
op
in
ops
}
"""Mapping of C++ operators to their precedence level."""
MAPPINGS
=
{
"True"
:
"true"
,
"False"
:
"false"
,
"None"
:
"nullptr"
}
"""Mapping of Python builtin constants to C++ equivalents."""
#
SYMBOLS = {
#
ast.Eq: "==",
#
ast.NotEq: '!=',
#
ast.Pass: '/* pass */',
#
ast.Mult: '*',
#
ast.Add: '+',
#
ast.Sub: '-',
#
ast.Div: '/',
#
ast.FloorDiv: '/', # TODO
#
ast.Mod: '%',
#
ast.Lt: '<',
#
ast.Gt: '>',
#
ast.GtE: '>=',
#
ast.LtE: '<=',
#
ast.LShift: '<<',
#
ast.RShift: '>>',
#
ast.BitXor: '^',
#
ast.BitOr: '|',
#
ast.BitAnd: '&',
#
ast.Not: '!',
#
ast.IsNot: '!=',
#
ast.USub: '-',
#
ast.And: '&&',
#
ast.Or: '||'
#
}
#
"""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 = [
#
("()", "[]", ".",),
#
("unary", "co_await"),
#
("*", "/", "%",),
#
("+", "-"),
#
("<<", ">>"),
#
("<", "<=", ">", ">="),
#
("==", "!="),
#
("&",),
#
("^",),
#
("|",),
#
("&&",),
#
("||",),
#
("?:", "co_yield"),
#
(",",)
#
]
#
"""Precedence of C++ operators."""
#
#
PRECEDENCE_LEVELS = {op: i for i, ops in enumerate(PRECEDENCE) for op in ops}
#
"""Mapping of C++ operators to their precedence level."""
#
#
MAPPINGS = {
#
"True": "true",
#
"False": "false",
#
"None": "nullptr"
#
}
#
"""Mapping of Python builtin constants to C++ equivalents."""
trans/transpiler/phases/desugar_compare/__init__.py
View file @
7e04915c
...
...
@@ -34,22 +34,4 @@ class DesugarCompare(ast.NodeTransformer):
res
.
values
.
append
(
call
)
if
len
(
res
.
values
)
==
1
:
return
res
.
values
[
0
]
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
return
res
\ No newline at end of file
trans/transpiler/phases/emit_cpp/consts.py
View file @
7e04915c
...
...
@@ -28,6 +28,28 @@ 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
=
[
(
"()"
,
"[]"
,
"."
,),
(
"unary"
,
"co_await"
),
...
...
trans/transpiler/phases/emit_cpp/expr.py
View file @
7e04915c
...
...
@@ -6,7 +6,7 @@ from typing import List, Iterable
from
transpiler.phases.typing.types
import
UserType
,
FunctionType
,
Promise
from
transpiler.phases.utils
import
make_lnd
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.typing.scope
import
Scope
,
VarKind
...
...
trans/transpiler/phases/emit_cpp/function.py
View file @
7e04915c
...
...
@@ -3,7 +3,7 @@ import ast
from
dataclasses
import
dataclass
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.block
import
BlockVisitor
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