Added in function call operator

This commit is contained in:
Nathan Braswell
2016-03-07 15:54:09 -05:00
parent 22feae1a58
commit 5ed310df8b
4 changed files with 24 additions and 4 deletions

View File

@@ -406,7 +406,19 @@ obj ast_transformation (Object) {
match (searching_for) { match (searching_for) {
search_type::none() return identifier_lookup(name, scope) search_type::none() return identifier_lookup(name, scope)
search_type::function(type_vec) { search_type::function(type_vec) {
return function_lookup(name, scope, type_vec) var possible_func = function_lookup(name, scope, type_vec)
if (possible_func)
return possible_func
var possible_obj = identifier_lookup(name, scope)
// sometimes identifier lookup doesn't return identfiers, i.e. function values, etc
if (possible_obj && is_identifier(possible_obj)) {
var possible_obj_type = get_ast_type(possible_obj)
// note operator() has had it's () stripped out...
if (possible_obj_type->is_object() && has_method(possible_obj_type->type_def, "operator", type_vec)) {
println("Has the operator()!")
return possible_obj
}
}
} }
} }
println("FAILED SEARCH FOR") println("FAILED SEARCH FOR")
@@ -585,7 +597,13 @@ obj ast_transformation (Object) {
// don't bother with a full transform for parameters with their own function, just get the boolean expression and transform it // don't bother with a full transform for parameters with their own function, just get the boolean expression and transform it
var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope, template_replacements);) var parameters = get_nodes("parameter", node).map(fun(child: *tree<symbol>): *ast_node return transform(get_node("boolean_expression", child), scope, template_replacements);)
var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);) var parameter_types = parameters.map(fun(param: *ast_node): *type return get_ast_type(param);)
var f = ast_function_call_ptr(transform(get_node("unarad", node), scope, search_type::function(parameter_types), template_replacements), parameters) 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()) {
println("Making an operator() method call!")
return make_method_call(func, "operator", parameters)
}
var f = ast_function_call_ptr(func, parameters)
print("function call function ") print("function call function ")
println(f->function_call.func) println(f->function_call.func)
print("function call parameters ") print("function call parameters ")

2
tests/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
tester
test_compiler

View File

@@ -1,4 +1,4 @@
import io:* import simple_print:*
fun func(it: ref int) { fun func(it: ref int) {
it++ it++

View File

@@ -1,4 +1,4 @@
import io:* import simple_print:*
obj FuncObj { obj FuncObj {
fun operator()(a:int, b:*char): void { fun operator()(a:int, b:*char): void {