return CONSTANT_EXPRESSION_MAPPING[c_constant_expression.value]
def generate_symbol_expression(c_symbol_expression):
- return 'Environment_get(&environment, SYMBOL_LIST[{}] /* symbol: {} */)'.format(
+ return 'Environment_get(environment, SYMBOL_LIST[{}] /* symbol: {} */)'.format(
c_symbol_expression.symbol_list_index,
c_symbol_expression.symbol,
)
)
def generate_function_call(function_call):
- return 'Environment_get(&environment, "{}").instance.closure(&environment, {}, {})'.format(
+ return 'Environment_get(environment, "{}").instance.closure(environment, {}, {})'.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
return '{};'.format(generate_expression(statement.expression))
def generate_symbol_assignment_statement(c_assignment_statement):
- return 'Environment_set(&environment, SYMBOL_LIST[{}] /* symbol: {} */, {});'.format(
+ return 'Environment_set(environment, SYMBOL_LIST[{}] /* symbol: {} */, {});'.format(
c_assignment_statement.target_symbol_list_index,
c_assignment_statement.target,
generate_expression(c_assignment_statement.expression),
return generated_if_clause + generated_if_statements + generated_else_statements
def generate_function_declaration(statement):
- return 'Environment_set(&environment, "{}", user${});'.format(statement.name, statement.name)
+ return 'Environment_set(environment, "{}", user${});'.format(statement.name, statement.name)
def generate_statement(statement):
return {
{% for function_definition in function_definition_list %}
Object user${{function_definition.name}}$implementation(Environment* parent, size_t argc, Object* args)
{
- Environment environment;
- Environment_initialize(&environment, parent);
+ Environment* environment = malloc(sizeof(Environment));;
+ Environment_initialize(environment, parent);
{% for statement in function_definition.statement_list[:-1] %}
{{ generate_statement(statement) }}
{% endfor %}
Object result = {{ generate_statement(function_definition.statement_list[-1]) }}
- Environment_deinitialize(&environment);
+ Environment_deinitialize(environment);
return result;
}
int main(int argc, char** argv)
{
- Environment environment;
- Environment_initialize(&environment, NULL);
+ Environment* environment = malloc(sizeof(Environment));
+ Environment_initialize(environment, NULL);
// TODO Use the symbol from SYMBOL_LIST
{% for builtin in builtins %}
- Environment_set(&environment, "{{ builtin }}", builtin${{ builtin }});
+ Environment_set(environment, "{{ builtin }}", builtin${{ builtin }});
{% endfor %}
{% for statement in statements %}
{{ generate_statement(statement) }}
{% endfor %}
- Environment_deinitialize(&environment);
+ Environment_deinitialize(environment);
+ free(environment);
return 0;
}