def generate_list_construct_expression(expression):
return 'List_construct({})'.format(expression.allocate)
-def generate_list_get_expression(expression):
- return 'List_get(&{}, {})'.format(
- generate_expression(expression.list_expression),
- generate_expression(expression.index_expression),
- )
-
def generate_expression(expression):
return {
transformation.CFunctionCallExpression: generate_function_call,
transformation.CIntegerLiteral: generate_integer_literal,
transformation.CListConstructExpression: generate_list_construct_expression,
- transformation.CListGetExpression: generate_list_get_expression,
transformation.CStringLiteral: generate_string_literal,
transformation.CStructureLiteralExpression: generate_structure_literal_expression,
transformation.CSymbolExpression: generate_symbol_expression,
],
)
-NormalListGetExpression = collections.namedtuple(
- 'NormalListGetExpression',
- [
- 'list_expression',
- 'index_expression',
- ],
-)
-
def normalize_list_literal_expression(counter, expression):
list_variable = '${}'.format(counter)
counter += 1
list_expression,
)
-def normalize_list_item_expression(counter, expression):
- counter, list_prestatements, list_expression = normalize_expression(counter, expression.list_expression)
- counter, index_prestatements, index_expression = normalize_expression(counter, expression.index_expression)
-
- result_variable = '${}'.format(counter)
- result_prestatement = NormalVariableInitializationStatement(
- variable=result_variable,
- expression=NormalListGetExpression(
- list_expression=list_expression,
- index_expression=index_expression,
- ),
- )
-
- return (
- counter + 1,
- list_prestatements + index_prestatements + (result_prestatement,),
- NormalVariableExpression(variable=result_variable),
- )
-
def normalize_string_literal_expression(counter, expression):
variable = '${}'.format(counter)
return (
import collections
import conversion
-import normalization
CIntegerLiteral = collections.namedtuple(
'CIntegerLiteral',
],
)
-CListGetExpression = collections.namedtuple(
- 'CListGetExpression',
- [
- 'list_expression',
- 'index_expression',
- ],
-)
-
def transform_structure_literal_expression(accumulators, expression):
return CStructureLiteralExpression(
field_count=expression.field_count,
def transform_list_construct_expression(accumulators, expression):
return CListConstructExpression(allocate=expression.allocate)
-def transform_list_get_expression(accumulators, expression):
- return CListGetExpression(
- list_expression=transform_expression(accumulators, expression.list_expression),
- index_expression=transform_expression(accumulators, expression.index_expression),
- )
-
def transform_list_append_statement(accumulators, expression):
return CListAppendStatement(
list_expression=transform_expression(accumulators, expression.list_expression),
conversion.CPSFunctionCallExpression: transform_function_call_expression,
conversion.CPSIntegerLiteralExpression: transform_integer_literal_expression,
conversion.CPSListConstructExpression: transform_list_construct_expression,
- normalization.NormalListGetExpression: transform_list_get_expression,
conversion.CPSStructureLiteralExpression: transform_structure_literal_expression,
conversion.CPSStringLiteralExpression: transform_string_literal_expression,
conversion.CPSSymbolExpression: transform_symbol_expression,