Normalize literal expressions
[fur] / transformation.py
index 41cd712..cc24304 100644 (file)
@@ -153,8 +153,8 @@ BUILTINS = {
 def transform_variable_expression(accumulators, expression):
     return CVariableExpression(variable=expression.variable)
 
-def transform_string_literal(accumulators, expression):
-    value = expression.value
+def transform_string_literal_expression(accumulators, expression):
+    value = expression.string
 
     try:
         index = accumulators.string_literal_list.index(value)
@@ -252,11 +252,7 @@ def transform_infix_expression(accumulators, expression):
     )
 
 def transform_integer_literal_expression(accumulators, expression):
-    return CIntegerLiteral(value=expression.value)
-
-def transform_parenthesized_expression(accumulators, expression):
-    # Parentheses can be removed because everything in the C output is explicitly parenthesized
-    return transform_expression(accumulators, expression.internal)
+    return CIntegerLiteral(value=expression.integer)
 
 def transform_negation_expression(accumulators, expression):
     return CNegationExpression(
@@ -270,12 +266,13 @@ def transform_expression(accumulators, expression):
         parsing.FurInfixExpression: transform_infix_expression,
         parsing.FurIntegerLiteralExpression: transform_integer_literal_expression,
         parsing.FurNegationExpression: transform_negation_expression,
-        parsing.FurParenthesizedExpression: transform_parenthesized_expression,
-        parsing.FurStringLiteralExpression: transform_string_literal,
+        parsing.FurStringLiteralExpression: transform_string_literal_expression,
         parsing.FurSymbolExpression: transform_symbol_expression,
         normalization.NormalFunctionCallExpression: transform_function_call_expression,
         normalization.NormalInfixExpression: transform_infix_expression,
+        normalization.NormalIntegerLiteralExpression: transform_integer_literal_expression,
         normalization.NormalNegationExpression: transform_negation_expression,
+        normalization.NormalStringLiteralExpression: transform_string_literal_expression,
         normalization.NormalVariableExpression: transform_variable_expression,
     }[type(expression)](accumulators, expression)
 
@@ -297,13 +294,15 @@ def transform_symbol_assignment_statement(accumulators, assignment_statement):
     )
 
 def transform_function_call_expression(accumulators, function_call):
-    if function_call.function.value in BUILTINS.keys():
-        # TODO Check that the builtin is actually callable
-        accumulators.builtin_set.add(function_call.function.value)
+    if isinstance(function_call.function, parsing.FurSymbolExpression):
+        # TODO Move this check to transformation of symbol expressions so we can have builtins that aren't functions
+        if function_call.function.value in BUILTINS.keys():
+            # TODO Check that the builtin is actually callable
+            accumulators.builtin_set.add(function_call.function.value)
 
     # TODO Use the symbol from SYMBOL LIST
     return CFunctionCallExpression(
-        name=function_call.function.value,
+        name=transform_expression(accumulators, function_call.function),
         argument_count=function_call.argument_count,
         argument_items=transform_expression(accumulators, function_call.argument_items),
     )