Normalize all the arguments to functions
authorDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 8 Aug 2017 07:24:45 +0000 (03:24 -0400)
committerDavid Kerkeslager <kerkeslager@gmail.com>
Tue, 8 Aug 2017 07:24:45 +0000 (03:24 -0400)
normalization.py
transformation.py

index c51c973..c48c3e9 100644 (file)
@@ -43,14 +43,21 @@ def fake_normalization(counter, thing):
     return (counter, (), thing)
 
 def normalize_function_call_expression(counter, expression):
+    assert isinstance(expression, parsing.FurFunctionCallExpression)
+
     prestatements = []
     arguments = []
 
     for argument in expression.arguments:
+        counter, argument_prestatements, normalized_argument = normalize_expression(counter, argument)
+
+        for s in argument_prestatements:
+            prestatements.append(s)
+
         variable = '${}'.format(counter)
         prestatements.append(NormalVariableAssignmentStatement(
             variable=variable,
-            expression=argument, # TODO Normalize each argument
+            expression=normalized_argument,
         ))
         arguments.append(NormalVariableExpression(
             variable=variable,
@@ -66,6 +73,16 @@ def normalize_function_call_expression(counter, expression):
         ),
     )
 
+def normalize_expression(counter, expression):
+    return {
+        parsing.FurFunctionCallExpression: normalize_function_call_expression,
+        parsing.FurInfixExpression: fake_normalization, # TODO This should not be faked
+        parsing.FurIntegerLiteralExpression: fake_normalization,
+        parsing.FurNegationExpression: fake_normalization,
+        parsing.FurStringLiteralExpression: fake_normalization,
+        parsing.FurSymbolExpression: fake_normalization,
+    }[type(expression)](counter, expression)
+
 def normalize_expression_statement(counter, statement):
     counter, prestatements, normalized = {
         parsing.FurFunctionCallExpression: normalize_function_call_expression,
index c3ced00..3309b9c 100644 (file)
@@ -214,6 +214,7 @@ def transform_expression(accumulators, expression):
     # TODO Handle all possible types in this form
     return {
         normalization.NormalVariableExpression: transform_variable_expression,
+        normalization.NormalFunctionCallExpression: transform_function_call_expression,
     }[type(expression)](accumulators, expression)
 
 def transform_symbol_assignment_statement(accumulators, assignment_statement):
@@ -236,6 +237,7 @@ def transform_negation_expression(accumulators, negation_expression):
     )
 
 def transform_function_call_expression(accumulators, function_call):
+    # TODO Function should be a full expression
     if function_call.function.value in BUILTINS.keys():
         # TODO Check that the builtin is actually callable
         accumulators.builtin_set.add(function_call.function.value)