address of and dereference implemented as templated compiler intrinsics
This commit is contained in:
22
k.krak
22
k.krak
@@ -90,6 +90,7 @@ fun main(argc: int, argv: **char): int {
|
|||||||
|
|
||||||
var multiple_binding_options = map<*tree<ast>, vec<*tree<ast>>>()
|
var multiple_binding_options = map<*tree<ast>, vec<*tree<ast>>>()
|
||||||
var primitive_ops.construct(): map<str, vec<*tree<ast>>>
|
var primitive_ops.construct(): map<str, vec<*tree<ast>>>
|
||||||
|
|
||||||
var number_tower = vec(binding_p(type::_char()),
|
var number_tower = vec(binding_p(type::_char()),
|
||||||
binding_p(type::_uchar()),
|
binding_p(type::_uchar()),
|
||||||
binding_p(type::_short()),
|
binding_p(type::_short()),
|
||||||
@@ -150,6 +151,21 @@ fun main(argc: int, argv: **char): int {
|
|||||||
}
|
}
|
||||||
math.remove(math.size-1)
|
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<type>>()))))
|
||||||
|
// 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<type>>()))))
|
||||||
|
|
||||||
// resolves all binding possibilities for one top level item
|
// resolves all binding possibilities for one top level item
|
||||||
passes[str("name_possibility_resolve")] = fun(item: *tree<ast>) {
|
passes[str("name_possibility_resolve")] = fun(item: *tree<ast>) {
|
||||||
println("Running name possibility resolver?")
|
println("Running name possibility resolver?")
|
||||||
@@ -707,7 +723,7 @@ fun main(argc: int, argv: **char): int {
|
|||||||
C_str += ")"
|
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) {
|
ast::_cast(b) {
|
||||||
C_str += idt + "((" + to_c_type(b) + ")"
|
C_str += idt + "((" + to_c_type(b) + ")"
|
||||||
emit_C(t->children[0], 0)
|
emit_C(t->children[0], 0)
|
||||||
@@ -974,10 +990,10 @@ fun syntax_to_ast(file_name: str, syntax: *tree<symbol>, import_paths: ref vec<s
|
|||||||
return parse_type(s, declared_template_types);
|
return parse_type(s, declared_template_types);
|
||||||
}))
|
}))
|
||||||
} else if (syntax->children[0]->data.terminal) {
|
} else if (syntax->children[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)))
|
syntax_to_ast_helper(syntax->children[1], declared_template_types)))
|
||||||
} else {
|
} 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)))
|
syntax_to_ast_helper(syntax->children[0], declared_template_types)))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ fun is_compiler_intrinsic(i: *tree<ast>): bool { match(i->data) { ast::_compiler
|
|||||||
fun is_cast(i: *tree<ast>): bool { match(i->data) { ast::_cast(b) return true; } return false; }
|
fun is_cast(i: *tree<ast>): bool { match(i->data) { ast::_cast(b) return true; } return false; }
|
||||||
fun is_value(i: *tree<ast>): bool { match(i->data) { ast::_value(b) return true; } return false; }
|
fun is_value(i: *tree<ast>): bool { match(i->data) { ast::_value(b) return true; } return false; }
|
||||||
|
|
||||||
fun is_top_level_item(i: *tree<ast>): bool { return i->parent != null<tree<ast>>() && is_translation_unit(i->parent); }
|
fun is_top_level_item(i: *tree<ast>): bool { return i->parent == null<tree<ast>>() || is_translation_unit(i->parent); }
|
||||||
|
|
||||||
fun get_ancestor_satisfying(t: *tree<ast>, p: fun(*tree<ast>): bool): *tree<ast> {
|
fun get_ancestor_satisfying(t: *tree<ast>, p: fun(*tree<ast>): bool): *tree<ast> {
|
||||||
t = t->parent
|
t = t->parent
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ fun unify(t1: *binding<type>, t2: *binding<type>) {
|
|||||||
unify(t1->bound_to->_fun.first.second, t2->bound_to->_fun.first.second)
|
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++;)
|
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])
|
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 {
|
} else {
|
||||||
error("Doesn't typecheck! Attempted to unify " + to_string(t1->bound_to) + " and " + to_string(t2->bound_to))
|
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))
|
if (is_ptr(a) != is_ptr(b))
|
||||||
return false
|
return false
|
||||||
if (is_ptr(a) && is_ptr(b))
|
if (is_ptr(a) && is_ptr(b))
|
||||||
return shallow_equality(a->_ptr->bound_to, b->_ptr->bound_to)
|
return true
|
||||||
match(*a) {
|
match(*a) {
|
||||||
type::_fun(x) {
|
type::_fun(x) {
|
||||||
return is_fun(b) && a->_fun.third == b->_fun.third
|
return is_fun(b) && a->_fun.third == b->_fun.third
|
||||||
|
|||||||
Reference in New Issue
Block a user