Commit 7e04915c authored by Tom Niget's avatar Tom Niget

Move constants

parent ac78d6fd
......@@ -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
......@@ -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
......
# 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."""
......@@ -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
......@@ -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"),
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment