return expression.variable
def generate_function_call_for_fur_infix_operator(expression):
- return 'operator${}({}, {})'.format(
+ return 'operator${}(stack)'.format(
expression.name,
- generate_expression(expression.left),
- generate_expression(expression.right),
)
def generate_structure_literal_expression(expression):
[
'order',
'operator',
- 'left',
- 'right',
],
)
counter, left_prestatements, left_expression = normalize_expression(counter, expression.left)
counter, right_prestatements, right_expression = normalize_expression(counter, expression.right)
- left_variable = '${}'.format(counter)
- counter += 1
- right_variable = '${}'.format(counter)
- counter += 1
center_variable = '${}'.format(counter)
counter += 1
root_prestatements = (
- NormalVariableInitializationStatement(
- variable=left_variable,
- expression=left_expression,
- ),
- NormalVariableInitializationStatement(
- variable=right_variable,
- expression=right_expression,
- ),
+ NormalPushStatement(expression=left_expression),
+ NormalPushStatement(expression=right_expression),
NormalVariableInitializationStatement(
variable=center_variable,
expression=NormalInfixExpression(
order=expression.order,
operator=expression.operator,
- left=NormalVariableExpression(variable=left_variable),
- right=NormalVariableExpression(variable=right_variable),
),
),
)
middle_variable = '${}'.format(counter)
counter += 1
+ # TODO Is there a memory leak if the middle expression throws an exception because the first expression result hasn't been added to the stack?
juncture_prestatements = (
NormalVariableInitializationStatement(
variable=left_variable,
}
// TODO Make this conditionally added
-Object operator$concatenate(Object left, Object right)
+Object operator$concatenate(Stack* stack)
{
+ Object right = Stack_pop(stack);
+ Object left = Stack_pop(stack);
+
switch(left.type) {
case STRING_CONCATENATION:
case STRING_LITERAL:
}
{% for id in infix_declarations %}
-Object operator${{ id.name }}(Object left, Object right)
+Object operator${{ id.name }}(Stack* stack)
{
+ Object right = Stack_pop(stack);
+ Object left = Stack_pop(stack);
+
assert(left.type == {{ id.in_type.upper() }});
assert(right.type == {{ id.in_type.upper() }});
'CFunctionCallForFurInfixOperator',
[
'name',
- 'left',
- 'right',
],
)
'>': CInfixDeclaration(name='greaterThan', in_type='integer', out_type='boolean', operator='>'),
}
-def transform_comparison_level_expression(accumulators, expression):
- accumulators.operator_set.add(FUR_INFIX_OPERATOR_TO_C_INFIX_OPERATOR[expression.operator])
-
- return CFunctionCallForFurInfixOperator(
- name=FUR_INFIX_OPERATOR_TO_C_INFIX_OPERATOR[expression.operator].name,
- left=transform_expression(accumulators, expression.left),
- right=transform_expression(accumulators, expression.right),
- )
-
def transform_infix_operator_without_c_equivalent(accumulators, expression):
return CFunctionCallForFurInfixOperator(
name='concatenate',
- left=transform_expression(accumulators, expression.left),
- right=transform_expression(accumulators, expression.right),
)
+
def transform_infix_expression(accumulators, expression):
if expression.operator in FUR_INFIX_OPERATOR_TO_C_FUNCTION:
return transform_infix_operator_without_c_equivalent(accumulators, expression)
- if expression.order == 'comparison_level':
- return transform_comparison_level_expression(accumulators, expression)
-
accumulators.operator_set.add(FUR_INFIX_OPERATOR_TO_C_INFIX_OPERATOR[expression.operator])
return CFunctionCallForFurInfixOperator(
name=FUR_INFIX_OPERATOR_TO_C_INFIX_OPERATOR[expression.operator].name,
- left=transform_expression(accumulators, expression.left),
- right=transform_expression(accumulators, expression.right),
)
def transform_integer_literal_expression(accumulators, expression):