From d3a2ea6f0859d7653f297ee3f59d157d78e36c76 Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Tue, 8 Aug 2017 03:24:45 -0400 Subject: [PATCH] Normalize all the arguments to functions --- normalization.py | 19 ++++++++++++++++++- transformation.py | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/normalization.py b/normalization.py index c51c973..c48c3e9 100644 --- a/normalization.py +++ b/normalization.py @@ -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, diff --git a/transformation.py b/transformation.py index c3ced00..3309b9c 100644 --- a/transformation.py +++ b/transformation.py @@ -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) -- 2.20.1