diff --git a/k.krak b/k.krak index 9a7a375..bceefc1 100644 --- a/k.krak +++ b/k.krak @@ -90,6 +90,7 @@ fun main(argc: int, argv: **char): int { var multiple_binding_options = map<*tree, vec<*tree>>() var primitive_ops.construct(): map>> + var number_tower = vec(binding_p(type::_char()), binding_p(type::_uchar()), binding_p(type::_short()), @@ -150,6 +151,21 @@ fun main(argc: int, argv: **char): int { } math.remove(math.size-1) + // address of + var template_type = binding_p(type::_template_placeholder()) + primitive_ops[str("op&")].add(_template(str("&"), map(str("T"), template_type), vec(_compiler_intrinsic(str("&"), binding_p(type::_fun(make_triple(make_pair(vec( + template_type + ), + binding_p(type::_ptr(template_type)) + ), false, false))), vec<*binding>())))) + // dereference + var template_type = binding_p(type::_template_placeholder()) + primitive_ops[str("op*")].add(_template(str("*"), map(str("T"), template_type), vec(_compiler_intrinsic(str("*"), binding_p(type::_fun(make_triple(make_pair(vec( + binding_p(type::_ptr(template_type)) + ), + template_type + ), false, false))), vec<*binding>())))) + // resolves all binding possibilities for one top level item passes[str("name_possibility_resolve")] = fun(item: *tree) { println("Running name possibility resolver?") @@ -707,7 +723,7 @@ fun main(argc: int, argv: **char): int { C_str += ")" } } - ast::_compiler_intrinsic(b) { error("compiler_intrinsic gen unimplemented"); } + ast::_compiler_intrinsic(b) { /* this can happen cuz of templated primitive ops and is_top_level_item includes parentless stuff...*/ } ast::_cast(b) { C_str += idt + "((" + to_c_type(b) + ")" emit_C(t->children[0], 0) @@ -974,10 +990,10 @@ fun syntax_to_ast(file_name: str, syntax: *tree, import_paths: ref vecchildren[0]->data.terminal) { - return _call(vec(make_ast_binding(concat(syntax->children[0])), + return _call(vec(make_ast_binding("op" + concat(syntax->children[0])), syntax_to_ast_helper(syntax->children[1], declared_template_types))) } else { - return _call(vec(make_ast_binding(concat(syntax->children[1])), + return _call(vec(make_ast_binding("op" + concat(syntax->children[1])), syntax_to_ast_helper(syntax->children[0], declared_template_types))) } } else { diff --git a/stdlib/ast.krak b/stdlib/ast.krak index 5c010e4..59ad623 100644 --- a/stdlib/ast.krak +++ b/stdlib/ast.krak @@ -232,7 +232,7 @@ fun is_compiler_intrinsic(i: *tree): bool { match(i->data) { ast::_compiler fun is_cast(i: *tree): bool { match(i->data) { ast::_cast(b) return true; } return false; } fun is_value(i: *tree): bool { match(i->data) { ast::_value(b) return true; } return false; } -fun is_top_level_item(i: *tree): bool { return i->parent != null>() && is_translation_unit(i->parent); } +fun is_top_level_item(i: *tree): bool { return i->parent == null>() || is_translation_unit(i->parent); } fun get_ancestor_satisfying(t: *tree, p: fun(*tree): bool): *tree { t = t->parent diff --git a/stdlib/type2.krak b/stdlib/type2.krak index cd7f486..2ddb4fc 100644 --- a/stdlib/type2.krak +++ b/stdlib/type2.krak @@ -39,6 +39,8 @@ fun unify(t1: *binding, t2: *binding) { unify(t1->bound_to->_fun.first.second, t2->bound_to->_fun.first.second) for (var i = 0; i < t1->bound_to->_fun.first.first.size; i++;) unify(t1->bound_to->_fun.first.first[i], t2->bound_to->_fun.first.first[i]) + } else if (is_ptr(t1->bound_to)) { + unify(t1->bound_to->_ptr, t2->bound_to->_ptr) } } else { error("Doesn't typecheck! Attempted to unify " + to_string(t1->bound_to) + " and " + to_string(t2->bound_to)) @@ -112,7 +114,7 @@ fun shallow_equality(a: *type, b: *type):bool { if (is_ptr(a) != is_ptr(b)) return false if (is_ptr(a) && is_ptr(b)) - return shallow_equality(a->_ptr->bound_to, b->_ptr->bound_to) + return true match(*a) { type::_fun(x) { return is_fun(b) && a->_fun.third == b->_fun.third