|
14 | 14 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.""" |
15 | 15 |
|
16 | 16 | from nml import generic, nmlop |
| 17 | +from . import Array |
17 | 18 |
|
18 | 19 | from .base_expression import ConstantFloat, ConstantNumeric, Expression |
19 | 20 | from .boolean import Boolean |
@@ -71,6 +72,7 @@ def reduce(self, id_dicts=None, unknown_id_fatal=True): |
71 | 72 | # - If both subexpressions are constant, compute the result and return it. |
72 | 73 | # - If the operator allows it and the second expression is more complex than |
73 | 74 | # the first one swap them. |
| 75 | + # - If first subexpression is an array, compute the result and return it. |
74 | 76 | # - If the operation is a no-op, delete it. |
75 | 77 | # - Variables (as used in action2var) can have some computations attached to |
76 | 78 | # them, do that if possible. |
@@ -116,6 +118,13 @@ def reduce(self, id_dicts=None, unknown_id_fatal=True): |
116 | 118 | elif op == nmlop.CMP_GT: |
117 | 119 | op = nmlop.CMP_LT |
118 | 120 |
|
| 121 | + if ( |
| 122 | + isinstance(expr1, Array) |
| 123 | + and isinstance(expr2, ConstantNumeric) |
| 124 | + and self.op == nmlop.MUL |
| 125 | + ): |
| 126 | + return Array(self.op.compiletime_func(expr1.values, expr2.value), self.pos) |
| 127 | + |
119 | 128 | # - If the operation is a no-op, delete it. |
120 | 129 | if op == nmlop.AND and isinstance(expr2, ConstantNumeric) and (expr2.value == -1 or expr2.value == 0xFFFFFFFF): |
121 | 130 | return expr1 |
|
0 commit comments