From 0d43b38c70255f1bdb69ceede2b67ef4b293468b Mon Sep 17 00:00:00 2001 From: David Kerkeslager Date: Wed, 9 Aug 2017 08:50:43 -0400 Subject: [PATCH] Get called functions from the environment --- generation.py | 2 +- templates/program.c | 5 +++++ transformation.py | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/generation.py b/generation.py index 86abe96..6bc2384 100644 --- a/generation.py +++ b/generation.py @@ -65,7 +65,7 @@ def generate_negation_expression(c_negation_expression): ) def generate_function_call(function_call): - return '{}({}, {})'.format( + return 'Environment_get(environment, "{}").instance.closure({}, {})'.format( function_call.name, function_call.argument_count, # TODO This is just a single item containing a reference to the items list--make that clearer diff --git a/templates/program.c b/templates/program.c index f23640a..0d6d947 100644 --- a/templates/program.c +++ b/templates/program.c @@ -330,6 +330,11 @@ int main(int argc, char** argv) { Environment* environment = Environment_construct(); + // TODO Use the symbol from SYMBOL_LIST + {% for builtin in builtins %} + Environment_set(environment, "{{ builtin }}", builtin${{ builtin }}); + {% endfor %} + {% for statement in statements %} {{ statement }} {% endfor %} diff --git a/transformation.py b/transformation.py index 9784c15..b636286 100644 --- a/transformation.py +++ b/transformation.py @@ -270,8 +270,9 @@ def transform_function_call_expression(accumulators, function_call): # 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='builtin${}.instance.closure'.format(function_call.function.value), + name=function_call.function.value, argument_count=function_call.argument_count, argument_items=transform_expression(accumulators, function_call.argument_items), ) -- 2.20.1