Function lookup now handles overloading
This commit is contained in:
@@ -280,15 +280,30 @@ obj ast_transformation (Object) {
|
||||
f->function_call.parameters.for_each(fun(param: *ast_node) print(param);)
|
||||
return f
|
||||
}
|
||||
fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
||||
var results = scope_lookup(name, scope)
|
||||
if (!results.size) {
|
||||
println(string("identifier lookup failed for ") + name)
|
||||
return null<ast_node>()
|
||||
}
|
||||
return results[0]
|
||||
}
|
||||
fun function_lookup(name: string, scope: *ast_node, param_types: vector<*type>): *ast_node {
|
||||
var param_string = string()
|
||||
param_types.for_each(fun(t: *type) param_string += t->to_string() + ", ";)
|
||||
var results = scope_lookup(name, scope)
|
||||
for (var i = 0; i < results.size; i++;)
|
||||
if (is_function(results[i])) {
|
||||
var func_param_types = get_ast_type(results[i])->parameter_types
|
||||
if (func_param_types.size != param_types.size)
|
||||
continue
|
||||
var param_types_match = true
|
||||
for (var j = 0; j < param_types.size; j++;) {
|
||||
if (*func_param_types[j] != *param_types[j]) {
|
||||
param_types_match = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if (param_types_match)
|
||||
return results[i]
|
||||
} else
|
||||
println(string("either isn't function or types don't match ") + get_ast_type(results[i])->to_string() + " with needed " + param_string)
|
||||
println(string("function lookup failed for ") + name)
|
||||
return null<ast_node>()
|
||||
}
|
||||
fun identifier_lookup(name: string, scope: *ast_node): *ast_node {
|
||||
var results = scope_lookup(name, scope)
|
||||
if (!results.size) {
|
||||
println(string("identifier lookup failed for ") + name)
|
||||
|
||||
@@ -38,17 +38,19 @@ obj type (Object) {
|
||||
base.copy_construct(&base_type::none())
|
||||
parameter_types.construct()
|
||||
indirection = 0
|
||||
return_type = null<type>()
|
||||
return this
|
||||
}
|
||||
fun construct(base_in: base_type, indirection_in: int): *type {
|
||||
base.copy_construct(&base_in)
|
||||
parameter_types.construct()
|
||||
indirection = indirection_in
|
||||
return_type = null<type>()
|
||||
return this
|
||||
}
|
||||
fun construct(parameter_types_in: vector<*type>, return_type_in: *type, indirection_in: int): *type {
|
||||
base.copy_construct(&base_type::function())
|
||||
parameter_types.copy_construct(¶meter_types)
|
||||
parameter_types.copy_construct(¶meter_types_in)
|
||||
return_type = return_type_in
|
||||
indirection = indirection_in
|
||||
return this
|
||||
@@ -67,6 +69,12 @@ obj type (Object) {
|
||||
base.destruct()
|
||||
parameter_types.destruct()
|
||||
}
|
||||
fun operator!=(other: ref type):bool return !(*this == other);
|
||||
fun operator==(other: ref type):bool {
|
||||
if ( (return_type && other.return_type && *return_type != *other.return_type) || (return_type && !other.return_type) || (!return_type && other.return_type) )
|
||||
return false
|
||||
return base == other.base && parameter_types == other.parameter_types && indirection == other.indirection
|
||||
}
|
||||
fun to_string(): string {
|
||||
match (base) {
|
||||
base_type::none() return string("none, indirection: ") + indirection
|
||||
|
||||
Reference in New Issue
Block a user