🐛 fix 2 bugs.

1. unary optimized number not generated bug
2. self-referenced module path not displayed correctly
This commit is contained in:
ValKmjolnir 2023-07-24 19:50:30 +08:00
parent 788e0026c2
commit 26a62dde9b
3 changed files with 14 additions and 15 deletions

View File

@ -848,6 +848,12 @@ void codegen::and_gen(binary_operator* node) {
}
void codegen::unary_gen(unary_operator* node) {
// generate optimized result
if (node->get_optimized_number()) {
num_gen(node->get_optimized_number());
return;
}
calc_gen(node->get_value());
switch(node->get_operator_type()) {
case unary_operator::unary_type::negative:

View File

@ -155,21 +155,12 @@ bool linker::check_self_import(const std::string& file) {
return false;
}
std::string linker::generate_self_import_path() {
std::string linker::generate_self_import_path(const std::string& filename) {
std::string res = "";
usize size = module_load_stack.size();
if (!size) {
return res;
}
usize count = 0;
for(const auto& i : module_load_stack) {
res += "<" + i + ">";
if (count!=size-1) {
res += " -> ";
}
++count;
res += "[" + i + "] -> ";
}
return res;
return res + "[" + filename + "]";
}
void linker::link(code_block* new_tree_root, code_block* old_tree_root) {
@ -194,6 +185,8 @@ code_block* linker::import_regular_file(call_expr* node) {
auto location = node->get_first()->get_location();
delete node->get_first();
node->set_first(new nil_expr(location));
// this will make node to call_expr(nil),
// will not be optimized when generating bytecodes
// avoid infinite loading loop
filename = find_file(filename, node->get_location());
@ -201,8 +194,8 @@ code_block* linker::import_regular_file(call_expr* node) {
return new code_block({0, 0, 0, 0, filename});
}
if (check_self_import(filename)) {
err.err("link", "self-referenced module <" + filename + ">\n" +
" reference path: " + generate_self_import_path());
err.err("link", "self-referenced module <" + filename + ">:\n" +
" reference path: " + generate_self_import_path(filename));
return new code_block({0, 0, 0, 0, filename});
}
exist(filename);

View File

@ -35,7 +35,7 @@ private:
bool exist(const std::string&);
u16 find(const std::string&);
bool check_self_import(const std::string&);
std::string generate_self_import_path();
std::string generate_self_import_path(const std::string&);
void link(code_block*, code_block*);
std::string get_path(call_expr*);
std::string find_file(const std::string&, const span&);