Skip to content

Commit

Permalink
Remove constant expressions (such as multiline comments)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Apr 15, 2023
1 parent 999690f commit f410aa3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions opshin/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from logging import getLogger
from ast import fix_missing_locations

from .optimize.optimize_remove_comments import OptimizeRemoveDeadconstants
from .rewrite.rewrite_augassign import RewriteAugAssign
from .rewrite.rewrite_forbidden_overwrites import RewriteForbiddenOverwrites
from .rewrite.rewrite_import import RewriteImport
Expand Down Expand Up @@ -945,6 +946,7 @@ def compile(
# Apply optimizations
OptimizeRemoveDeadvars(),
OptimizeVarlen(),
OptimizeRemoveDeadconstants(),
OptimizeRemovePass(),
# the compiler runs last
UPLCCompiler(
Expand Down
16 changes: 16 additions & 0 deletions opshin/optimize/optimize_remove_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from ast import *

from ..util import CompilingNodeTransformer

"""
Removes expressions that return constants in sequences of statements (i.e. string comments)
"""


class OptimizeRemoveDeadconstants(CompilingNodeTransformer):
step = "Removing constants (i.e. string comments)"

def visit_Expr(self, node: Expr):
if isinstance(node.value, Constant):
return None
return node

0 comments on commit f410aa3

Please sign in to comment.