From: David Kerkeslager Date: Wed, 9 Aug 2017 12:50:43 +0000 (-0400) Subject: Get called functions from the environment X-Git-Url: https://code.kerkeslager.com/?p=fur;a=commitdiff_plain;h=0d43b38c70255f1bdb69ceede2b67ef4b293468b Get called functions from the environment --- 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), )