if type(c_argument) in LITERAL_TYPE_MAPPING:
return LITERAL_TYPE_MAPPING[type(c_argument)](c_argument)
- INFIX_TYPE_MAPPING = {
- transformation.CAdditionExpression: 'add',
- transformation.CSubtractionExpression: 'subtract',
- transformation.CMultiplicationExpression: 'multiply',
- transformation.CIntegerDivisionExpression: 'integerDivide',
- transformation.CModularDivisionExpression: 'modularDivide',
- transformation.CEqualityExpression: 'equals',
- transformation.CInequalityExpression: 'notEquals',
- transformation.CGreaterThanExpression: 'greaterThan',
- transformation.CLessThanExpression: 'lessThan',
- transformation.CGreaterThanOrEqualExpression: 'greaterThanOrEqual',
- transformation.CLessThanOrEqualExpression: 'lessThanOrEqual',
- transformation.CAndExpression: 'and',
- }
-
- return 'builtin${}({}, {})'.format(
- INFIX_TYPE_MAPPING[type(c_argument)],
- generate_expression(c_argument.left),
- generate_expression(c_argument.right),
- )
+ if isinstance(c_argument, transformation.CFunctionCallForFurInfixOperator):
+ return 'builtin${}({}, {})'.format(
+ c_argument.name,
+ generate_expression(c_argument.left),
+ generate_expression(c_argument.right),
+ )
+
+ raise Exception('Could not handle expresssion "{}"'.format(c_argument))
def generate_negation_expression(c_negation_expression):
return 'builtin$negate({})'.format(
],
)
-CAdditionExpression = collections.namedtuple(
- 'CAdditionExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CSubtractionExpression = collections.namedtuple(
- 'CSubtractionExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CMultiplicationExpression = collections.namedtuple(
- 'CMultiplicationExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CIntegerDivisionExpression = collections.namedtuple(
- 'CIntegerDivisionExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CEqualityExpression = collections.namedtuple(
- 'CEqualityExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CInequalityExpression = collections.namedtuple(
- 'CInequalityExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CGreaterThanOrEqualExpression = collections.namedtuple(
- 'CGreaterThanOrEqualExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CLessThanOrEqualExpression = collections.namedtuple(
- 'CLessThanOrEqualExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CGreaterThanExpression = collections.namedtuple(
- 'CGreaterThanExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CLessThanExpression = collections.namedtuple(
- 'CLessThanExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CAndExpression = collections.namedtuple(
- 'CAndExpression',
- [
- 'left',
- 'right',
- ],
-)
-
-CModularDivisionExpression = collections.namedtuple(
- 'CModularDivisionExpression',
+CFunctionCallForFurInfixOperator = collections.namedtuple(
+ 'CFunctionCallForFurInfixOperator',
[
+ 'name',
'left',
'right',
],
],
)
-EQUALITY_LEVEL_OPERATOR_MAPPING = {
- '==': CEqualityExpression,
- '!=': CInequalityExpression,
- '<=': CLessThanOrEqualExpression,
- '>=': CGreaterThanOrEqualExpression,
- '<': CLessThanExpression,
- '>': CGreaterThanExpression,
+EQUALITY_LEVEL_OPERATOR_TO_FUNCTION_NAME_MAPPING = {
+ '==': 'equals',
+ '!=': 'notEquals',
+ '<=': 'lessThanOrEqual',
+ '>=': 'greaterThanOrEqual',
+ '<': 'lessThan',
+ '>': 'greaterThan',
}
def transform_equality_level_expression(builtin_dependencies, symbol_list, expression):
)
# TODO Don't evaluate the middle expression twice
- return CAndExpression(
+ return CFunctionCallForFurInfixOperator(
+ name='and',
left=left,
- right=EQUALITY_LEVEL_OPERATOR_MAPPING[expression.operator](
+ right=CFunctionCallForFurInfixOperator(
+ name=EQUALITY_LEVEL_OPERATOR_TO_FUNCTION_NAME_MAPPING[expression.operator],
left=middle,
right=right,
),
)
- return EQUALITY_LEVEL_OPERATOR_MAPPING[expression.operator](
+ return CFunctionCallForFurInfixOperator(
+ name=EQUALITY_LEVEL_OPERATOR_TO_FUNCTION_NAME_MAPPING[expression.operator],
left=transform_expression(builtin_dependencies, symbol_list, expression.left),
right=transform_expression(builtin_dependencies, symbol_list, expression.right),
)
if isinstance(expression, parsing.FurEqualityLevelExpression):
return transform_equality_level_expression(builtin_dependencies, symbol_list, expression)
- INFIX_OPERATOR_TO_TYPE_MAPPING = {
- '+': CAdditionExpression,
- '-': CSubtractionExpression,
- '*': CMultiplicationExpression,
- '//': CIntegerDivisionExpression,
- '%': CModularDivisionExpression,
+ INFIX_OPERATOR_TO_FUNCTION_NAME = {
+ '+': 'add',
+ '-': 'subtract',
+ '*': 'multiply',
+ '//': 'integerDivide',
+ '%': 'modularDivide',
}
- return INFIX_OPERATOR_TO_TYPE_MAPPING[expression.operator](
+ return CFunctionCallForFurInfixOperator(
+ name=INFIX_OPERATOR_TO_FUNCTION_NAME[expression.operator],
left=transform_expression(builtin_dependencies, symbol_list, expression.left),
right=transform_expression(builtin_dependencies, symbol_list, expression.right),
)