'CPSStructureLiteralExpression',
(
'field_count',
- 'symbol_list_variable',
- 'value_list_variable',
),
)
),
)
+CPSSymbolLiteralExpression = collections.namedtuple(
+ 'CPSSymbolLiteralExpression',
+ (
+ 'symbol',
+ ),
+)
+
CPSVariableExpression = collections.namedtuple(
'CPSVariableExpression',
(
def convert_structure_literal_expression(expression):
return CPSStructureLiteralExpression(
field_count=expression.field_count,
- symbol_list_variable=expression.symbol_list_variable,
- value_list_variable=expression.value_list_variable,
)
def convert_symbol_expression(expression):
return CPSSymbolExpression(symbol=expression.symbol)
+def convert_symbol_literal_expression(expression):
+ return CPSSymbolLiteralExpression(symbol=expression.symbol)
+
def convert_variable_expression(expression):
return CPSVariableExpression(variable=expression.variable)
normalization.NormalStringLiteralExpression: convert_string_literal_expression,
normalization.NormalStructureLiteralExpression: convert_structure_literal_expression,
normalization.NormalSymbolExpression: convert_symbol_expression,
+ normalization.NormalSymbolLiteralExpression: convert_symbol_literal_expression,
normalization.NormalVariableExpression: convert_variable_expression,
}[type(expression)](expression)
-def convert_array_variable_initialization_statement(statement):
- return CPSArrayVariableInitializationStatement(
- variable=statement.variable,
- items=tuple(convert_expression(e) for e in statement.items),
- )
-
def convert_assignment_statement(statement):
return CPSAssignmentStatement(
target=statement.target,
expression=convert_expression(statement.expression),
)
-def convert_symbol_array_variable_initialization_statement(statement):
- return CPSSymbolArrayVariableInitializationStatement(
- variable=statement.variable,
- symbol_list=statement.symbol_list,
- )
-
def convert_statement(statement):
return {
- normalization.NormalArrayVariableInitializationStatement: convert_array_variable_initialization_statement,
normalization.NormalAssignmentStatement: convert_assignment_statement,
normalization.NormalExpressionStatement: convert_expression_statement,
normalization.NormalListAppendStatement: convert_list_append_statement,
normalization.NormalPushStatement: convert_push_statement,
normalization.NormalVariableInitializationStatement: convert_variable_initialization_statement,
- normalization.NormalSymbolArrayVariableInitializationStatement: convert_symbol_array_variable_initialization_statement,
}[type(statement)](statement)
def convert_statement_list(statement_list):
return referenced_entry_list, instruction_list
+def generate_structure_literal_expression(counters, expression):
+ referenced_entry_list = ()
+ instruction_list = (CIRInstruction(
+ instruction='structure',
+ argument=expression.field_count,
+ ),)
+
+ return referenced_entry_list, instruction_list
+
def generate_symbol_expression(counters, expression):
referenced_entry_list = ()
instruction_list = (CIRInstruction(
return referenced_entry_list, instruction_list
+def generate_symbol_literal_expression(counters, expression):
+ referenced_entry_list = ()
+ instruction_list = (CIRInstruction(
+ instruction='push_value',
+ argument=generate_symbol_literal(expression.symbol),
+ ),)
+
+ return referenced_entry_list, instruction_list
+
def generate_variable_expression(counters, expression):
referenced_entry_list = ()
instruction_list = (CIRInstruction(
conversion.CPSLambdaExpression: generate_lambda_expression,
conversion.CPSListConstructExpression: generate_list_construct_expression,
conversion.CPSStringLiteralExpression: generate_string_literal_expression,
+ conversion.CPSStructureLiteralExpression: generate_structure_literal_expression,
conversion.CPSSymbolExpression: generate_symbol_expression,
+ conversion.CPSSymbolLiteralExpression: generate_symbol_literal_expression,
conversion.CPSVariableExpression: generate_variable_expression,
}[type(expression)](counters, expression)
NormalSymbolExpression = collections.namedtuple(
'NormalSymbolExpression',
- [
+ (
'symbol',
- ],
+ ),
+)
+
+NormalSymbolLiteralExpression = collections.namedtuple(
+ 'NormalSymbolLiteralExpression',
+ (
+ 'symbol',
+ ),
)
NormalPushStatement = collections.namedtuple(
],
)
-NormalArrayVariableInitializationStatement = collections.namedtuple(
- 'NormalArrayVariableInitializationStatement',
- [
- 'variable',
- 'items',
- ],
-)
-
-NormalSymbolArrayVariableInitializationStatement = collections.namedtuple(
- 'NormalSymbolArrayVariableInitializationStatement',
- [
- 'variable',
- 'symbol_list',
- ],
-)
-
NormalVariableInitializationStatement = collections.namedtuple(
'NormalVariableInitializationStatement',
[
NormalStructureLiteralExpression = collections.namedtuple(
'NormalStructureLiteralExpression',
- [
+ (
'field_count',
- 'symbol_list_variable',
- 'value_list_variable',
- ],
+ ),
)
def normalize_structure_literal_expression(counter, expression):
prestatements = []
- field_symbol_array = []
- field_value_array = []
- for symbol_expression_pair in expression.fields:
- counter, field_prestatements, field_expression = normalize_expression(
+ for field in expression.fields:
+ counter, field_expression_prestatements, field_expression = normalize_expression(
counter,
- symbol_expression_pair.expression,
+ field.expression,
)
- for p in field_prestatements:
+ for p in field_expression_prestatements:
prestatements.append(p)
- field_symbol_array.append(symbol_expression_pair.symbol)
- field_value_array.append(field_expression)
+ prestatements.append(NormalPushStatement(
+ expression=field_expression,
+ ))
- symbol_array_variable = '${}'.format(counter)
- counter += 1
-
- prestatements.append(
- NormalSymbolArrayVariableInitializationStatement(
- variable=symbol_array_variable,
- symbol_list=tuple(field_symbol_array),
- )
- )
-
- value_array_variable = '${}'.format(counter)
- counter += 1
-
- prestatements.append(
- NormalArrayVariableInitializationStatement(
- variable=value_array_variable,
- items=tuple(field_value_array),
- )
- )
-
- variable = '${}'.format(counter)
-
- prestatements.append(
- NormalVariableInitializationStatement(
- variable=variable,
- expression=NormalStructureLiteralExpression(
- field_count=len(expression.fields),
- symbol_list_variable=symbol_array_variable,
- value_list_variable=value_array_variable,
+ prestatements.append(NormalPushStatement(
+ expression=NormalSymbolLiteralExpression(
+ symbol=field.symbol,
),
- )
- )
+ ))
return (
- counter + 1,
+ counter,
tuple(prestatements),
- NormalVariableExpression(variable=variable),
+ NormalStructureLiteralExpression(
+ field_count=len(expression.fields),
+ ),
)
-
def normalize_symbol_expression(counter, expression):
return (
counter,