Fix this handling, other bytecode fixes
This commit is contained in:
@@ -188,12 +188,24 @@ obj ast_transformation (Object) {
|
||||
var copy_construct_param = ast_identifier_ptr(string("in"), node->adt_def.self_type->clone_with_indirection(1,false), node)
|
||||
var assign_param = ast_identifier_ptr(string("in"), node->adt_def.self_type->clone_with_indirection(0,true), node)
|
||||
vector(
|
||||
make_pair("operator==", ast_function_ptr(string("operator=="), type_ptr(vector(equals_param->identifier.type), type_ptr(base_type::boolean()), 0, false, false, true), vector(equals_param), false)),
|
||||
make_pair("operator!=", ast_function_ptr(string("operator!="), type_ptr(vector(nequals_param->identifier.type), type_ptr(base_type::boolean()), 0, false, false, true), vector(nequals_param), false)),
|
||||
make_pair("construct", ast_function_ptr(string("construct"), type_ptr(vector<*type>(), node->adt_def.self_type->clone_with_increased_indirection(), 0, false, false, true), vector<*ast_node>(), false)),
|
||||
make_pair("copy_construct", ast_function_ptr(string("copy_construct"), type_ptr(vector(copy_construct_param->identifier.type), type_ptr(base_type::void_return()), 0, false, false, true), vector(copy_construct_param), false)),
|
||||
make_pair("operator=", ast_function_ptr(string("operator="), type_ptr(vector(assign_param->identifier.type), type_ptr(base_type::void_return()), 0, false, false, true), vector(assign_param), false)),
|
||||
make_pair("destruct", ast_function_ptr(string("destruct"), type_ptr(vector<*type>(), type_ptr(base_type::void_return()), 0, false, false, true), vector<*ast_node>(), false))
|
||||
make_pair("operator==", ast_function_ptr(string("operator=="),
|
||||
type_ptr(vector(equals_param->identifier.type), type_ptr(base_type::boolean()), 0, false, false, true),
|
||||
vector(equals_param), ast_identifier_ptr("this", node->adt_def.self_type->clone_with_indirection(1), node), false, false)),
|
||||
make_pair("operator!=", ast_function_ptr(string("operator!="),
|
||||
type_ptr(vector(nequals_param->identifier.type), type_ptr(base_type::boolean()), 0, false, false, true),
|
||||
vector(nequals_param), ast_identifier_ptr("this", node->adt_def.self_type->clone_with_indirection(1), node), false, false)),
|
||||
make_pair("construct", ast_function_ptr(string("construct"),
|
||||
type_ptr(vector<*type>(), node->adt_def.self_type->clone_with_increased_indirection(), 0, false, false, true),
|
||||
vector<*ast_node>(), ast_identifier_ptr("this", node->adt_def.self_type->clone_with_indirection(1), node), false, false)),
|
||||
make_pair("copy_construct", ast_function_ptr(string("copy_construct"),
|
||||
type_ptr(vector(copy_construct_param->identifier.type), type_ptr(base_type::void_return()), 0, false, false, true),
|
||||
vector(copy_construct_param), ast_identifier_ptr("this", node->adt_def.self_type->clone_with_indirection(1), node), false, false)),
|
||||
make_pair("operator=", ast_function_ptr(string("operator="),
|
||||
type_ptr(vector(assign_param->identifier.type), type_ptr(base_type::void_return()), 0, false, false, true),
|
||||
vector(assign_param), ast_identifier_ptr("this", node->adt_def.self_type->clone_with_indirection(1), node), false, false)),
|
||||
make_pair("destruct", ast_function_ptr(string("destruct"),
|
||||
type_ptr(vector<*type>(), type_ptr(base_type::void_return()), 0, false, false, true),
|
||||
vector<*ast_node>(), ast_identifier_ptr("this", node->adt_def.self_type->clone_with_indirection(1), node), false, false))
|
||||
).for_each(fun(func_pair: pair<*char, *ast_node>) {
|
||||
node->adt_def.regular_funcs.add(func_pair.second)
|
||||
add_to_scope(string(func_pair.first), func_pair.second, node)
|
||||
@@ -238,10 +250,19 @@ obj ast_transformation (Object) {
|
||||
})
|
||||
var is_variadic = get_node("\"...\"", node) != null<tree<symbol>>()
|
||||
var is_raw = function_name != "__compiler_lambda__"
|
||||
var this_param = null<ast_node>()
|
||||
if (is_type_def(scope)) {
|
||||
this_param = ast_identifier_ptr("this", scope->type_def.self_type->clone_with_indirection(1), scope)
|
||||
} else if (is_template(scope)) {
|
||||
var parent_scope = get_ast_scope(scope)->get(string("~enclosing_scope"))[0]
|
||||
if (is_type_def(parent_scope)) {
|
||||
this_param = ast_identifier_ptr("this", parent_scope->type_def.self_type->clone_with_indirection(1), parent_scope)
|
||||
}
|
||||
}
|
||||
// figure out function type and make function_node
|
||||
var function_node = ast_function_ptr(function_name,
|
||||
type_ptr(parameters.map(fun(parameter: *ast_node): *type return parameter->identifier.type;),
|
||||
return_type, 0, false, is_variadic, is_raw), parameters, get_node("\"ext\"", node) != null<tree<symbol>>(), is_variadic)
|
||||
return_type, 0, false, is_variadic, is_raw), parameters, this_param, get_node("\"ext\"", node) != null<tree<symbol>>(), is_variadic)
|
||||
// fix up the enclosing_scope's
|
||||
parameters.for_each(fun(n: *ast_node) n->identifier.enclosing_scope = function_node;)
|
||||
// add to scope
|
||||
@@ -470,17 +491,15 @@ obj ast_transformation (Object) {
|
||||
fun transform_all(nodes: vector<*tree<symbol>>, scope: *ast_node, template_replacements: map<string, *type>): vector<*ast_node> {
|
||||
return nodes.map(fun(node: *tree<symbol>): *ast_node return transform(node, scope, template_replacements);)
|
||||
}
|
||||
fun make_this(object: *ast_node): *ast_node {
|
||||
if (!type_def_to_this.contains_key(object))
|
||||
type_def_to_this[object] = ast_identifier_ptr("this", object->type_def.self_type->clone_with_indirection(1), object)
|
||||
return type_def_to_this[object]
|
||||
}
|
||||
fun transform_identifier(node: *tree<symbol>, scope: *ast_node, searching_for: search_type): *ast_node {
|
||||
// first, we check for and generate this
|
||||
var name = concat_symbol_tree(node)
|
||||
if (name == "this") {
|
||||
while (!is_type_def(scope)) scope = get_ast_scope(scope)->get(string("~enclosing_scope"))[0]
|
||||
return make_this(scope)
|
||||
while (!is_function(scope) || scope->function.this_param == null<ast_node>())
|
||||
scope = get_ast_scope(scope)->get(string("~enclosing_scope"))[0]
|
||||
if (!is_function(scope))
|
||||
error(node, "Couldn't find this")
|
||||
return scope->function.this_param
|
||||
}
|
||||
match (searching_for) {
|
||||
search_type::none() return identifier_lookup(name, scope)
|
||||
|
||||
Reference in New Issue
Block a user