HM-style return type overloaded function infrencing works!

This commit is contained in:
Nathan Braswell
2018-09-24 00:08:07 -04:00
parent 9178c2a29d
commit 2148577523
3 changed files with 132 additions and 53 deletions

View File

@@ -32,18 +32,6 @@ adt ast {
_cast: *binding<type>,
_value: pair<str, *binding<type>>
}
fun get_type(a: *tree<ast>): *binding<type> {
match(a->data) {
ast::_identifier(b) return b.second
ast::_binding(b) return get_type(b.second->bound_to)
ast::_function(b) return b.second
ast::_call() return get_type(a->children[0])->bound_to->base._fun.first.second
/*ast::_compiler_intrinsic(b) return str("_compiler_intrinsic(") + b.first + ")"*/
ast::_cast(b) return b
ast::_value(b) return b.second
}
error("Trying to get type of node without one: " + to_string(a->data))
}
fun to_string(a: ref ast): str {
match(a) {
ast::_translation_unit(b) return str("_translation_unit(") + b + ")"

View File

@@ -61,7 +61,23 @@ obj type (Object) {
fun equality(other: ref type, care_about_ref: bool):bool {
if (care_about_ref && (is_ref != other.is_ref))
return false
return base == other.base && indirection == other.indirection
if (indirection != other.indirection)
return false
match(base) {
base_type::_fun(b) {
if ( !(other.is_fun() && base._fun.second == other.base._fun.second && base._fun.third == other.base._fun.third) )
return false
if ( !(base._fun.first.second->bound_to->equality(other.base._fun.first.second->bound_to, care_about_ref)) )
return false
if ( !(base._fun.first.first.size == other.base._fun.first.first.size) )
return false
for (var i = 0; i < base._fun.first.first.size; i++;)
if ( !(base._fun.first.first[i]->bound_to->equality(other.base._fun.first.first[i]->bound_to, care_about_ref)) )
return false
return true
}
}
return base == other.base
}
fun to_string(): str {
var indr_string = str("")