--- /dev/null
+def make_incrementer(increment_amount) do
+ def result(i) do
+ increment_amount + i
+ end
+
+ result
+end
+
+print((make_incrementer(1))(41), '\n')
+print((make_incrementer(2))(40), '\n')
def generate_function_call(function_call):
# TODO This gets called twice, which is really inefficient--normalization would also allow other clauses besides a variable reference
- get_closure_clause = 'Environment_get(environment, "{}").instance.closure'.format(
- function_call.name,
- )
- return '{}.call(environmentPool, {}.closed, {}, {})'.format(
+ # TODO This should no longer be called "name", as it can be an expression of a few types
+ # TODO Check the type of the things being called
+ get_closure_clause = generate_expression(function_call.name)
+ return '{}.instance.closure.call(environmentPool, {}.instance.closure.closed, {}, {})'.format(
get_closure_clause,
get_closure_clause,
function_call.argument_count,
items=tuple(arguments),
))
+ counter, function_prestatements, function_expression = normalize_expression(
+ counter,
+ expression.function,
+ )
+
+ for ps in function_prestatements:
+ prestatements.append(ps)
+
return (
counter,
tuple(prestatements),
NormalFunctionCallExpression(
- function=expression.function, # TODO Normalize the function
+ function=function_expression,
argument_count=len(arguments),
argument_items=NormalVariableExpression(variable=arguments_variable),
),
)
def _function_call_expression_parser(index, tokens):
- # TODO Use a FurSymbolExpression for the name
+ # TODO Allow function calls as the source of the function. This requires a
+ # left-recursive parser, however.
failure = (False, index, None)
- success, index, function = _symbol_expression_parser(index, tokens)
+ # We have to be careful what expressions we add here. Otherwise expressions
+ # like "a + b()" become ambiguous to the parser.
+ success, index, function = _or_parser(
+ _symbol_expression_parser,
+ _parenthesized_expression_parser,
+ )(index, tokens)
if not success:
return failure
)
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),
)