baby steps

This commit is contained in:
Nathan Braswell
2017-02-17 01:22:27 -05:00
parent 425d75675e
commit cb8124afc0
3 changed files with 34 additions and 8 deletions

View File

@@ -203,7 +203,7 @@ obj ast_transformation (Object) {
}
fun second_pass_function(node: *tree<symbol>, scope: *ast_node, template_replacements: map<string, *type>, do_raw_template: bool): *ast_node {
var func_identifier_node = get_node("func_identifier", node)
var function_name = string("lambda")
var function_name = string("__compiler_lambda__")
if (func_identifier_node)
function_name = concat_symbol_tree(func_identifier_node)
var template_dec = get_node("template_dec", node)
@@ -799,9 +799,12 @@ obj ast_transformation (Object) {
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
var func = transform(get_node("unarad", node), scope, search_type::function(parameter_types), template_replacements)
// may return an identifier of type object if doing operator() - but the () have been stripped out by importer
if (get_ast_type(func)->is_object()) {
var func_type = get_ast_type(func)
if (func_type->is_object() && func_type->indirection == 0) {
return make_method_call(func, "operator", parameters)
}
if (!(func_type->is_function() && func_type->indirection == 0))
error(node, "trying to call not a function")
var f = ast_function_call_ptr(func, parameters)
return f
}
@@ -965,7 +968,7 @@ obj ast_transformation (Object) {
if (!first_param_type)
error(node, "Cannot get type from left side of access operation")
if (!first_param_type->is_object())
error(node, "Type from left side of access operation isn't object")
error(node, "Type from left side of access operation (" + func_name + ") isn't object, is: " + first_param_type->to_string())
second_param = transform(node->children[2], first_param_type->type_def, searching_for, template_replacements)
// template member functions
// XXX add in template inst if it exists

View File

@@ -75,16 +75,39 @@ fun function_value_lower(name_ast_map: *map<string, pair<*tree<symbol>,*ast_node
println(string("there are ") + function_value_creation_points.size + " function value creation points in the program.")
println(string("there are ") + function_types_needed_wo_lambdas.size() + " function types needed wo lambdas in the program.")
println(string("there are ") + function_types_needed_for_lambdas.size() + " function types needed for lambdas in the program.")
println(string("there are ") + (function_types_needed_wo_lambdas + function_types_needed_for_lambdas).size() + " total (set union, not addition) in the program."); // darn vexing parse
println(string("there are ") + (function_types_needed_wo_lambdas + function_types_needed_for_lambdas).size() + " total (set union, not addition) in the program.")
var void_ptr = type_ptr(base_type::void_return(), 1); // this most vexing parse actually causes a compiler segfault as it tries to call the result of type_ptr as a function....
// AND IT STILL DOES EVEN WITH ALL MY CHEKCS
(function_types_needed_wo_lambdas + function_types_needed_for_lambdas).for_each(fun(t: type) {
var cleaned = t.clone()
cleaned->is_raw = true
var new_type_def_name = t.to_string() + "_function_value_struct"
var new_type_def = ast_type_def_ptr(new_type_def_name)
new_type_def->type_def.variables.add(ast_declaration_statement_ptr(ast_identifier_ptr("func", t.clone(), new_type_def), null<ast_node>()))
new_type_def->type_def.variables.add(ast_declaration_statement_ptr(ast_identifier_ptr("func", cleaned, new_type_def), null<ast_node>()))
new_type_def->type_def.variables.add(ast_declaration_statement_ptr(ast_identifier_ptr("data", void_ptr, new_type_def), null<ast_node>()))
add_to_scope("~enclosing_scope", name_ast_map->values.first().second, new_type_def)
add_to_scope(new_type_def_name, new_type_def, name_ast_map->values.first().second)
name_ast_map->values.first().second->translation_unit.children.add(new_type_def)
})
// create the closure type for each lambda
var closure_id = 0
lambdas.for_each(fun(l: *ast_node) {
if (l->function.closed_variables.size()) {
var new_type_def_name = string("closure_struct_") + closure_id++
var new_type_def = ast_type_def_ptr(new_type_def_name)
l->function.closed_variables.for_each(fun(v: *ast_node) {
// TODO: need to clean this type if it's a lambda type or contains it
new_type_def->type_def.variables.add(ast_declaration_statement_ptr(ast_identifier_ptr(v->identifier.name, v->identifier.type->clone_with_ref(), new_type_def), null<ast_node>()))
})
add_to_scope("~enclosing_scope", name_ast_map->values.first().second, new_type_def)
add_to_scope(new_type_def_name, new_type_def, name_ast_map->values.first().second)
name_ast_map->values.first().second->translation_unit.children.add(new_type_def)
}
})
function_value_creation_points.for_each(fun(p: function_parent_block) {
})
}

View File

@@ -20,9 +20,9 @@ fun get_first_terminal(source: *tree<symbol>): *tree<symbol> {
}
fun error(source: *tree<symbol>, message: *char) error(source, string(message));
fun error(source: *tree<symbol>, message: string) {
source = get_first_terminal(source)
if (source)
error("***error |" + concat_symbol_tree(source) + "| *** " + source->data.source + ": " + source->data.position + " " + message)
var first = get_first_terminal(source)
if (first)
error("***error |" + concat_symbol_tree(source) + "| *** " + first->data.source + ": " + first->data.position + " " + message)
error(message)
}
fun method_in_object(method: *ast_node, enclosing_object: *ast_node): bool {