diff --git a/k.krak b/k.krak index b952993..339fa3b 100644 --- a/k.krak +++ b/k.krak @@ -167,9 +167,28 @@ fun main(argc: int, argv: **char): int { // resolves all binding possibilities for one top level item passes[str("name_type_resolve")] = fun(item: *tree) { - println("Running name type resolver?") - // just temp - pass_poset.add_close_dep(make_pair(item, str("name_type_resolve")), make_pair(item, str("name_possibility_resolve"))) + if !pass_poset.done(make_pair(item, str("name_possibility_resolve"))) { + pass_poset.add_open_dep(make_pair(item, str("name_type_resolve")), make_pair(item, str("name_possibility_resolve"))) + return + } + var unify: fun(*binding, *binding): void = fun(t1: *binding, t2: *binding) { + println("trying to unify " + t1->bound_to->to_string() + " and " + t2->bound_to->to_string()) + if (t1->bound_to->equality(t2->bound_to, false) || t1->bound_to->is_unknown()) + t1->set(t2->bound_to) + else + t2->set(t1->bound_to) + } + var traverse_for_unify: fun(*tree): void = fun(t: *tree) { + t->children.for_each(traverse_for_unify) + match (t->data) { + ast::_declaration() if (t->children.size > 1) + unify(get_type(t->children[0]), get_type(t->children[1])) + /*ast::_assignment()*/ + /*ast::_call()*/ + /*ast::_return()*/ + } + } + traverse_for_unify(item) } // emit C diff --git a/stdlib/ast.krak b/stdlib/ast.krak index 9a6df8f..e7d02c4 100644 --- a/stdlib/ast.krak +++ b/stdlib/ast.krak @@ -32,6 +32,18 @@ adt ast { _cast: *binding, _value: pair> } +fun get_type(a: *tree): *binding { + 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->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 + ")" @@ -272,7 +284,7 @@ obj binding (Object) { } fun set(to: *T) { // don't set null, that will set all unbound ones - if (bound_to == null>()) { + if (bound_to == null()) { bound_to = to return }