FINALLY FIXED THE PROBLEM - was using set instead of set_single, so it set it's child as well, causing the type loop. Also, the binding replace child evaluated the parameters first, changing t's parent before t->parent->replace_child happened
This commit is contained in:
@@ -43,15 +43,33 @@ fun deref_to_string<T>(in: *T, ts: fun(*T): str): str
|
||||
return str("null")
|
||||
else
|
||||
return ts(in)
|
||||
fun binding_deref_to_string<T>(b: *binding<T>): str {
|
||||
var pre = b->get_bound_to(binding_epoch::pre_ref())
|
||||
var post = b->get_bound_to(binding_epoch::post_ref())
|
||||
if pre == post {
|
||||
return deref_to_string(pre)
|
||||
} else {
|
||||
return "pre_ref:" + deref_to_string(pre) + "/post_ref:" + deref_to_string(post)
|
||||
}
|
||||
}
|
||||
fun binding_deref_to_string<T>(b: *binding<T>, ts: fun(*T): str): str {
|
||||
var pre = b->get_bound_to(binding_epoch::pre_ref())
|
||||
var post = b->get_bound_to(binding_epoch::post_ref())
|
||||
if pre == post {
|
||||
return deref_to_string(pre, ts)
|
||||
} else {
|
||||
return "pre_ref:" + deref_to_string(pre, ts) + "/post_ref:" + deref_to_string(post, ts)
|
||||
}
|
||||
}
|
||||
fun to_string(a: ref ast): str {
|
||||
match(a) {
|
||||
ast::_translation_unit(b) return str("_translation_unit(") + b + ")"
|
||||
ast::_import(b) return str("_import(") + to_string(b.first->data) + ")[" + str(",").join(b.second.data) + "]"
|
||||
ast::_identifier(b) return str("_identifier(") + b.first + ": " + "pre_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::post_ref())) + ")"
|
||||
ast::_binding(b) return str("_binding(") + b.first + "[" + str(",").join(b.second.map(fun(x:*binding<type>): str { return "pre_ref:" + deref_to_string(x->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + deref_to_string(x->get_bound_to(binding_epoch::post_ref())); })) + "]" + "-> pre_ref:" + deref_to_string(b.third->get_bound_to(binding_epoch::pre_ref()), fun(t: *tree<ast>): str return to_string(t->data);) + " /post_ref:" + deref_to_string(b.third->get_bound_to(binding_epoch::post_ref()), fun(t: *tree<ast>): str return to_string(t->data);)+ ")"
|
||||
ast::_identifier(b) return str("_identifier(") + b.first + ": " + binding_deref_to_string(b.second) + ")"
|
||||
ast::_binding(b) return str("_binding(") + b.first + "[" + str(",").join(b.second.map(fun(x:*binding<type>): str { return binding_deref_to_string(x); })) + "]" + "-> " + binding_deref_to_string(b.third, fun(t: *tree<ast>): str return to_string(t->data);) + ")"
|
||||
ast::_type_def(b) return str("_type_def(") + b + ")"
|
||||
ast::_adt_def(b) return str("_adt_def(") + b + ")"
|
||||
ast::_function(b) return str("_function(") + b.first + ": " + "pre_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::post_ref())) + ", ext?:" + to_string(b.third) + ")"
|
||||
ast::_function(b) return str("_function(") + b.first + ": " + binding_deref_to_string(b.second) + ", ext?:" + to_string(b.third) + ")"
|
||||
ast::_template(b) return str("_template(") + b.first + "[" + str(",").join(b.second.keys) + "])"
|
||||
ast::_declaration() return str("_declaration")
|
||||
ast::_block() return str("_block")
|
||||
@@ -65,9 +83,9 @@ fun to_string(a: ref ast): str {
|
||||
ast::_continue() return str("_continue")
|
||||
ast::_defer() return str("_defer")
|
||||
ast::_call(b) return "_call(add_scope: " + to_string(b) + ")"
|
||||
ast::_compiler_intrinsic(b) return str("_compiler_intrinsic(") + b.first + ": " + "pre_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::post_ref())) + ")"
|
||||
ast::_compiler_intrinsic(b) return str("_compiler_intrinsic(") + b.first + ": " + binding_deref_to_string(b.second) + ")"
|
||||
ast::_cast(b) return str("_cast")
|
||||
ast::_value(b) return str("_value(") + b.first + ": " + "pre_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + deref_to_string(b.second->get_bound_to(binding_epoch::post_ref())) + ")"
|
||||
ast::_value(b) return str("_value(") + b.first + ": " + binding_deref_to_string(b.second) + ")"
|
||||
}
|
||||
}
|
||||
fun _translation_unit(p: str): *tree<ast> {
|
||||
|
||||
@@ -81,6 +81,11 @@ obj binding<T> (Object) {
|
||||
}
|
||||
}
|
||||
}
|
||||
fun set_single(to: T, epoch: binding_epoch) {
|
||||
var p = new<T>()
|
||||
p->copy_construct(&to)
|
||||
set_single(p, epoch)
|
||||
}
|
||||
fun set_single(to: *T, epoch: binding_epoch) {
|
||||
match (epoch) {
|
||||
binding_epoch::pre_ref() { bound_to_pre_ref = to; }
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import mem
|
||||
import vec
|
||||
import io:*
|
||||
import str:*
|
||||
|
||||
obj tree<T> (Object) {
|
||||
var data: T
|
||||
|
||||
@@ -103,32 +103,32 @@ fun shallow_equality(a: *type, b: *type, epoch: binding_epoch):bool {
|
||||
return *a == *b
|
||||
}
|
||||
|
||||
fun inst_temp_type(t: *binding<type>, replacements: ref map<*binding<type>, *binding<type>>, epoch: binding_epoch): *binding<type> {
|
||||
match (*t->get_bound_to(epoch)) {
|
||||
fun inst_temp_type(t: *binding<type>, replacements: ref map<*binding<type>, *binding<type>>, read_epoch: binding_epoch, write_epoch: binding_epoch): *binding<type> {
|
||||
match (*t->get_bound_to(read_epoch)) {
|
||||
type::_unknown() error("Unknown in temp type")
|
||||
type::_obj(o) {
|
||||
var binding_types = o->data._binding.second.map(fun(b: *binding<type>): *binding<type> return inst_temp_type(b, replacements, epoch);)
|
||||
var binding_types = o->data._binding.second.map(fun(b: *binding<type>): *binding<type> return inst_temp_type(b, replacements, read_epoch, write_epoch);)
|
||||
for (var i = 0; i < o->data._binding.second.size; i++;) {
|
||||
if (o->data._binding.second[i] != binding_types[i])
|
||||
return binding_p(type::_obj(_binding(o->data._binding.first, binding_types, o->data._binding.third)), epoch)
|
||||
return binding_p(type::_obj(_binding(o->data._binding.first, binding_types, o->data._binding.third)), write_epoch)
|
||||
}
|
||||
}
|
||||
type::_ptr(p) {
|
||||
var cp = inst_temp_type(p, replacements, epoch)
|
||||
var cp = inst_temp_type(p, replacements, read_epoch, write_epoch)
|
||||
if (cp == p)
|
||||
return t
|
||||
else
|
||||
return binding_p(type::_ptr(cp), epoch)
|
||||
return binding_p(type::_ptr(cp), write_epoch)
|
||||
}
|
||||
type::_fun(b) {
|
||||
// triple<pair<param_types, return_type>, is_variadic, is raw>
|
||||
var rt = make_pair(b.first.second.first, inst_temp_type(b.first.second.second, replacements, epoch))
|
||||
var pts = b.first.first.map(fun(pt: pair<ref_type, *binding<type>>): pair<ref_type, *binding<type>> return make_pair(pt.first, inst_temp_type(pt.second, replacements, epoch));)
|
||||
var rt = make_pair(b.first.second.first, inst_temp_type(b.first.second.second, replacements, read_epoch, write_epoch))
|
||||
var pts = b.first.first.map(fun(pt: pair<ref_type, *binding<type>>): pair<ref_type, *binding<type>> return make_pair(pt.first, inst_temp_type(pt.second, replacements, read_epoch, write_epoch));)
|
||||
if (rt.second != b.first.second.second)
|
||||
return binding_p(type::_fun(make_triple(make_pair(pts, rt), b.second, b.third)), epoch)
|
||||
return binding_p(type::_fun(make_triple(make_pair(pts, rt), b.second, b.third)), write_epoch)
|
||||
for (var i = 0; i < pts.size; i++;)
|
||||
if (pts[i].second != b.first.first[i].second)
|
||||
return binding_p(type::_fun(make_triple(make_pair(pts, rt), b.second, b.third)), epoch)
|
||||
return binding_p(type::_fun(make_triple(make_pair(pts, rt), b.second, b.third)), write_epoch)
|
||||
return t
|
||||
}
|
||||
type::_template_placeholder() return replacements[t]
|
||||
@@ -174,11 +174,16 @@ fun equality(a: *type, b: *type, count_unknown_as_equal: bool, epoch: binding_ep
|
||||
}
|
||||
return *a == *b
|
||||
}
|
||||
fun deref_to_string<T>(in: *T): str
|
||||
if (in == mem::null<T>())
|
||||
return str("null")
|
||||
else
|
||||
return to_string(in)
|
||||
fun to_string(it: *type): str {
|
||||
match (*it) {
|
||||
type::_unknown() return str("_unknown")
|
||||
type::_void() return str("_void")
|
||||
type::_ptr(p) return "* pre_ref:" + to_string(p->get_bound_to(binding_epoch::pre_ref())) + "/post_ref" + to_string(p->get_bound_to(binding_epoch::post_ref()))
|
||||
type::_ptr(p) return "*(pre_ref:" + deref_to_string(p->get_bound_to(binding_epoch::pre_ref())) + "/post_ref" + deref_to_string(p->get_bound_to(binding_epoch::post_ref())) + ")"
|
||||
type::_obj(b) {
|
||||
return "_obj(" + to_string(b->data) + ")"
|
||||
}
|
||||
@@ -189,10 +194,10 @@ fun to_string(it: *type): str {
|
||||
to_ret += "_run("
|
||||
else
|
||||
to_ret += "_fun("
|
||||
to_ret += str(", ").join(b.first.first.map(fun(pt: pair<ref_type, *binding<type>>): str return to_string(pt.first) + "pre_ref:" + to_string(pt.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref" + to_string(pt.second->get_bound_to(binding_epoch::post_ref()));))
|
||||
to_ret += str(", ").join(b.first.first.map(fun(pt: pair<ref_type, *binding<type>>): str return to_string(pt.first) + "(pre_ref:" + deref_to_string(pt.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref" + deref_to_string(pt.second->get_bound_to(binding_epoch::post_ref())) + ")";))
|
||||
if (b.third)
|
||||
to_ret += " ..."
|
||||
return to_ret + "): " + to_string(b.first.second.first) + "* pre_ref:" + to_string(b.first.second.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + to_string(b.first.second.second->get_bound_to(binding_epoch::post_ref()))
|
||||
return to_ret + "): " + to_string(b.first.second.first) + ": (pre_ref:" + deref_to_string(b.first.second.second->get_bound_to(binding_epoch::pre_ref())) + "/post_ref:" + deref_to_string(b.first.second.second->get_bound_to(binding_epoch::post_ref())) + ")"
|
||||
}
|
||||
type::_template_placeholder() return str("_template_placeholder")
|
||||
type::_bool() return str("_bool")
|
||||
|
||||
Reference in New Issue
Block a user