|
28 | 28 | ) |
29 | 29 |
|
30 | 30 | from .. import mlog |
| 31 | +from . import operator |
31 | 32 | from .decorators import FeatureNew |
32 | 33 | from .disabler import Disabler, is_disabled |
33 | 34 | from .helpers import default_resolve_key, flatten, resolve_second_level_holders, stringifyUserArguments |
@@ -344,24 +345,14 @@ def evaluate_comparison(self, node: mparser.ComparisonNode) -> InterpreterObject |
344 | 345 | if isinstance(val2, Disabler): |
345 | 346 | return val2 |
346 | 347 |
|
347 | | - # New code based on InterpreterObjects |
348 | | - operator = { |
349 | | - 'in': MesonOperator.IN, |
350 | | - 'not in': MesonOperator.NOT_IN, |
351 | | - '==': MesonOperator.EQUALS, |
352 | | - '!=': MesonOperator.NOT_EQUALS, |
353 | | - '>': MesonOperator.GREATER, |
354 | | - '<': MesonOperator.LESS, |
355 | | - '>=': MesonOperator.GREATER_EQUALS, |
356 | | - '<=': MesonOperator.LESS_EQUALS, |
357 | | - }[node.ctype] |
| 348 | + op = operator.MAPPING[node.ctype] |
358 | 349 |
|
359 | 350 | # Check if the arguments should be reversed for simplicity (this essentially converts `in` to `contains`) |
360 | | - if operator in (MesonOperator.IN, MesonOperator.NOT_IN): |
| 351 | + if op in (MesonOperator.IN, MesonOperator.NOT_IN): |
361 | 352 | val1, val2 = val2, val1 |
362 | 353 |
|
363 | 354 | val1.current_node = node |
364 | | - return self._holderify(val1.operator_call(operator, _unholder(val2))) |
| 355 | + return self._holderify(val1.operator_call(op, _unholder(val2))) |
365 | 356 |
|
366 | 357 | def evaluate_andstatement(self, cur: mparser.AndNode) -> InterpreterObject: |
367 | 358 | l = self.evaluate_statement(cur.left) |
@@ -414,15 +405,8 @@ def evaluate_arithmeticstatement(self, cur: mparser.ArithmeticNode) -> Interpret |
414 | 405 | if l is None or r is None: |
415 | 406 | raise InvalidCodeOnVoid(cur.operation) |
416 | 407 |
|
417 | | - mapping: T.Dict[str, MesonOperator] = { |
418 | | - 'add': MesonOperator.PLUS, |
419 | | - 'sub': MesonOperator.MINUS, |
420 | | - 'mul': MesonOperator.TIMES, |
421 | | - 'div': MesonOperator.DIV, |
422 | | - 'mod': MesonOperator.MOD, |
423 | | - } |
424 | 408 | l.current_node = cur |
425 | | - res = l.operator_call(mapping[cur.operation], _unholder(r)) |
| 409 | + res = l.operator_call(operator.MAPPING[cur.operation], _unholder(r)) |
426 | 410 | return self._holderify(res) |
427 | 411 |
|
428 | 412 | def evaluate_ternary(self, node: mparser.TernaryNode) -> T.Optional[InterpreterObject]: |
|
0 commit comments