Skip to content

Commit d8a8e10

Browse files
committed
Feature: syntax for creating recurring arrays
1 parent 03705d2 commit d8a8e10

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

nml/expression/binop.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA."""
1515

1616
from nml import generic, nmlop
17+
from . import Array
1718

1819
from .base_expression import ConstantFloat, ConstantNumeric, Expression
1920
from .boolean import Boolean
@@ -71,6 +72,7 @@ def reduce(self, id_dicts=None, unknown_id_fatal=True):
7172
# - If both subexpressions are constant, compute the result and return it.
7273
# - If the operator allows it and the second expression is more complex than
7374
# the first one swap them.
75+
# - If first subexpression is an array, compute the result and return it.
7476
# - If the operation is a no-op, delete it.
7577
# - Variables (as used in action2var) can have some computations attached to
7678
# them, do that if possible.
@@ -116,6 +118,13 @@ def reduce(self, id_dicts=None, unknown_id_fatal=True):
116118
elif op == nmlop.CMP_GT:
117119
op = nmlop.CMP_LT
118120

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+
119128
# - If the operation is a no-op, delete it.
120129
if op == nmlop.AND and isinstance(expr2, ConstantNumeric) and (expr2.value == -1 or expr2.value == 0xFFFFFFFF):
121130
return expr1

0 commit comments

Comments
 (0)