Skip to content

Commit

Permalink
rename decompose_to_symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Oct 16, 2023
1 parent d7d7d3e commit dc80c2d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion qlasskit/ast2logic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .utils import flatten # noqa: F401, E402
from .typing import Args, BoolExpList # noqa: F401, E402
from .t_arguments import translate_argument, translate_arguments # noqa: F401, E402
from .t_expression import translate_expression, type_of_exp # noqa: F401, E402
from .t_expression import translate_expression, decompose_to_symbols # noqa: F401, E402
from .t_statement import translate_statement # noqa: F401, E402
from .t_ast import translate_ast # noqa: F401, E402
from . import exceptions # noqa: F401, E402
6 changes: 3 additions & 3 deletions qlasskit/ast2logic/t_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
from . import Env, exceptions


def type_of_exp(vlist, base, res=[]) -> List[Symbol]:
"""Type inference for expressions: iterate over val, and decompose to bool"""
def decompose_to_symbols(vlist, base, res=[]) -> List[Symbol]:
"""Decompose exp to symbols"""
if isinstance(vlist, list):
i = 0
res = []
for in_val in vlist:
r_new = type_of_exp(in_val, f"{base}.{i}", res)
r_new = decompose_to_symbols(in_val, f"{base}.{i}", res)
if isinstance(r_new, list):
res.extend(r_new)
else:
Expand Down
6 changes: 3 additions & 3 deletions qlasskit/ast2logic/t_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from sympy import Symbol
from sympy.logic.boolalg import Boolean

from . import Binding, Env, exceptions, translate_expression, type_of_exp
from . import Binding, Env, decompose_to_symbols, exceptions, translate_expression


def translate_statement( # noqa: C901
Expand Down Expand Up @@ -58,14 +58,14 @@ def translate_statement( # noqa: C901
raise exceptions.SymbolReassignedException(target)

tval, val = translate_expression(stmt.value, env) # TODO: typecheck
res = type_of_exp(val, f"{target}")
res = decompose_to_symbols(val, f"{target}")
env.bind(Binding(target, tval, [x[0] for x in res]))
res = list(map(lambda x: (Symbol(x[0]), x[1]), res))
return res, env

elif isinstance(stmt, ast.Return):
texp, vexp = translate_expression(stmt.value, env) # TODO: typecheck
res = type_of_exp(vexp, "_ret")
res = decompose_to_symbols(vexp, "_ret")
env.bind(Binding("_ret", texp, [x[0] for x in res]))
res = list(map(lambda x: (Symbol(x[0]), x[1]), res))
return res, env
Expand Down

0 comments on commit dc80c2d

Please sign in to comment.