🐛 some bug fix

This commit is contained in:
ValKmjolnir 2024-10-18 19:26:06 +08:00
parent 96a4fc77cd
commit 2b56581482
4 changed files with 48 additions and 29 deletions

View File

@ -144,6 +144,9 @@ bool ast2mir::visit_array_literal(ast::array_literal* node) {
}
bool ast2mir::visit_struct_decl(ast::struct_decl* node) {
if (node->get_generic_types()) {
return true;
}
auto new_struct = new mir_struct;
new_struct->name = node->get_name();
new_struct->location = node->get_location();
@ -156,6 +159,9 @@ bool ast2mir::visit_struct_decl(ast::struct_decl* node) {
}
bool ast2mir::visit_func_decl(ast::func_decl* node) {
if (node->get_generic_types()) {
return true;
}
auto name = node->get_name();
if (impl_struct_name.length()) {
const auto tmp = type {
@ -206,6 +212,9 @@ bool ast2mir::visit_func_decl(ast::func_decl* node) {
}
bool ast2mir::visit_impl_struct(ast::impl_struct* node) {
if (node->get_generic_types()) {
return true;
}
impl_struct_name = node->get_struct_name();
for(auto i : node->get_methods()) {
i->accept(this);
@ -297,11 +306,19 @@ bool ast2mir::visit_call(ast::call* node) {
auto new_block = new mir_block(node->get_location());
auto temp = block;
block = new_block;
block->add_content(new mir_call_id(
node->get_head()->get_location(),
node->get_head()->get_id()->get_name(),
node->get_head()->get_resolve()
));
if (node->get_head()->get_generic_types()) {
block->add_content(new mir_call_id(
node->get_head()->get_location(),
node->get_head()->get_resolve().full_path_name(),
node->get_head()->get_resolve()
));
} else {
block->add_content(new mir_call_id(
node->get_head()->get_location(),
node->get_head()->get_id()->get_name(),
node->get_head()->get_resolve()
));
}
for(auto i : node->get_chain()) {
i->accept(this);
}

View File

@ -542,7 +542,7 @@ void mir2sir::visit_mir_struct_init(mir_struct_init* node) {
));
const auto& dm = ctx.global.domain.at(node->get_type().loc_file);
const auto& st = dm.structs.at(node->get_type().name);
const auto& st = dm.structs.at(node->get_type().name_for_search());
for(const auto& i : node->get_fields()) {
const auto target = ssa_gen.create();
const auto index = st.field_index(i.name);

View File

@ -905,28 +905,6 @@ void regist_pass::regist_single_impl(ast::impl_struct* node) {
auto& stct = dm.structs.count(node->get_struct_name())
? dm.structs.at(node->get_struct_name())
: dm.generic_structs.at(node->get_struct_name());
if (node->get_generic_types()) {
if (node->get_generic_types()->get_types().empty()) {
rp.report(node, "generic impl must have at least one generic type.");
return;
}
const auto& impl_generic_vec = node->get_generic_types()->get_types();
if (stct.generic_template.size() != impl_generic_vec.size()) {
rp.report(node, "generic type count does not match.");
return;
}
for(u64 i = 0; i < stct.generic_template.size(); ++i) {
const auto& name = impl_generic_vec[i]->get_name()->get_name();
if (stct.generic_template[i] != name) {
rp.report(impl_generic_vec[i], "generic type \"" + name +
"\" does not match with \"" +
stct.generic_template[i] + "\"."
);
}
}
// copy ast of this impl struct for template expansion
stct.generic_struct_impl.push_back(node->clone());
}
ctx.generics = {};
for(const auto& i : stct.generic_template) {
@ -955,6 +933,29 @@ void regist_pass::regist_single_impl(ast::impl_struct* node) {
stct.static_method.insert({i->get_name(), func});
}
}
if (node->get_generic_types()) {
if (node->get_generic_types()->get_types().empty()) {
rp.report(node, "generic impl must have at least one generic type.");
return;
}
const auto& impl_generic_vec = node->get_generic_types()->get_types();
if (stct.generic_template.size() != impl_generic_vec.size()) {
rp.report(node, "generic type count does not match.");
return;
}
for(u64 i = 0; i < stct.generic_template.size(); ++i) {
const auto& name = impl_generic_vec[i]->get_name()->get_name();
if (stct.generic_template[i] != name) {
rp.report(impl_generic_vec[i], "generic type \"" + name +
"\" does not match with \"" +
stct.generic_template[i] + "\"."
);
}
}
// copy ast of this impl struct for template expansion
stct.generic_struct_impl.push_back(node->clone());
}
}
colgm_func regist_pass::generate_method(ast::func_decl* node,

View File

@ -565,7 +565,6 @@ void semantic::check_method_call_args(const colgm_func& func,
type semantic::resolve_call_id(call_id* node) {
auto infer = resolve_identifier(node->get_id());
node->set_resolve_type(infer);
if (infer.is_error()) {
return infer;
}
@ -602,6 +601,8 @@ type semantic::resolve_call_id(call_id* node) {
infer.generics = types;
}
}
node->set_resolve_type(infer);
return infer;
}