working on moving rest of obj stuff into obj_lower

This commit is contained in:
Nathan Braswell
2017-11-03 00:39:58 -04:00
parent 5b8ef4ce2e
commit cb720e5cd6
9 changed files with 295 additions and 144 deletions

View File

@@ -122,10 +122,10 @@ obj c_generator (Object) {
var parameter_types = string()
var parameters = string()
// lambdas can have the enclosing object too, if it's needed (lambda in a method)
if (enclosing_object && !is_lambda) {
parameter_types = type_to_c(enclosing_object->type_def.self_type) + "*"
parameters = type_to_c(enclosing_object->type_def.self_type) + "* this"
}
/*if (enclosing_object && !is_lambda) {*/
/*parameter_types = type_to_c(enclosing_object->type_def.self_type) + "*"*/
/*parameters = type_to_c(enclosing_object->type_def.self_type) + "* this"*/
/*}*/
var decorated_name = string()
if (backing.is_extern)
@@ -264,8 +264,7 @@ obj c_generator (Object) {
to_ret += get_name(identifier) + " = " + generate(node->declaration_statement.expression, enclosing_object, enclosing_func)
}
if (node->declaration_statement.init_method_call) {
to_ret += ";\n"
to_ret += generate(node->declaration_statement.init_method_call, enclosing_object, enclosing_func)
error("init_method_call remaining")
}
return to_ret
}
@@ -301,8 +300,8 @@ obj c_generator (Object) {
fun generate_identifier(node: *ast_node, enclosing_object: *ast_node, enclosing_func: *ast_node): string {
if (get_ast_type(node)->is_ref)
error("still existin ref in identifier")
if (enclosing_object && get_ast_scope(enclosing_object)->contains_key(node->identifier.name) && get_ast_scope(enclosing_object)->get(node->identifier.name).contains(node))
return "(this->" + get_name(node) + ")"
/*if (enclosing_object && get_ast_scope(enclosing_object)->contains_key(node->identifier.name) && get_ast_scope(enclosing_object)->get(node->identifier.name).contains(node))*/
/*return "(this->" + get_name(node) + ")"*/
return get_name(node)
}
fun generate_return_statement(node: *ast_node, enclosing_object: *ast_node, enclosing_func: *ast_node): string {
@@ -364,21 +363,21 @@ obj c_generator (Object) {
if (func_return_type->is_ref)
error("still ref in function calling")
if (is_dot_style_method_call(node)) {
func_name = generate_function(node->function_call.func->function_call.parameters[1])
// don't add & if it was ->
if (node->function_call.func->function_call.func->function.name == ".")
call_string += "&"
/*if (is_dot_style_method_call(node)) {*/
/*func_name = generate_function(node->function_call.func->function_call.parameters[1])*/
/*// don't add & if it was ->*/
/*if (node->function_call.func->function_call.func->function.name == ".")*/
/*call_string += "&"*/
call_string += generate(node->function_call.func->function_call.parameters[0], enclosing_object, enclosing_func)
} else {
/*call_string += generate(node->function_call.func->function_call.parameters[0], enclosing_object, enclosing_func)*/
/*} else {*/
func_name = generate(node->function_call.func, enclosing_object, enclosing_func)
// handle method call from inside method of same object
if (enclosing_object && method_in_object(node->function_call.func, enclosing_object)) {
call_string += "this";
}
}
/*if (enclosing_object && method_in_object(node->function_call.func, enclosing_object)) {*/
/*call_string += "this";*/
/*}*/
/*}*/
var parameters = node->function_call.parameters
if ( parameters.size == 2 && (func_name == "+" || func_name == "-" || func_name == "*" || func_name == "/"