mirror of
https://codeberg.org/ProgramSnail/lang_2023.git
synced 2025-12-26 08:48:44 +00:00
bug fixes
This commit is contained in:
parent
bb8b32a7c8
commit
8647918f37
6 changed files with 87 additions and 102 deletions
|
|
@ -24,7 +24,7 @@ inline T Read() {
|
|||
|
||||
template<typename T>
|
||||
inline void Error(const T& value) { // only for strings ??
|
||||
std::cout << "\x1b[1;33mError:\x1b[0m ";
|
||||
std::cout << "\x1b[1;35mError:\x1b[0m ";
|
||||
std::cout << value;
|
||||
std::cout << '\n';
|
||||
exit(1);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ template<typename Value, typename ValueManager>
|
|||
class ContextManager {
|
||||
public:
|
||||
ContextManager() {
|
||||
contexts_.emplace_back(true); // no difference ??
|
||||
contexts_.emplace_back(false); // global context
|
||||
contexts_.emplace_back(true); // first context
|
||||
}
|
||||
|
||||
size_t ContextCount() {
|
||||
|
|
@ -86,8 +87,8 @@ public:
|
|||
}
|
||||
|
||||
void ExitContext() {
|
||||
if (contexts_.empty()) {
|
||||
error_handling::HandleInternalError("contexts_ is empty",
|
||||
if (contexts_.size() <= 2) {
|
||||
error_handling::HandleInternalError("only global context & first context in contexts_",
|
||||
"ContextManager.ExitContext",
|
||||
std::nullopt);
|
||||
}
|
||||
|
|
@ -103,6 +104,10 @@ public:
|
|||
return contexts_.back().DefineVariable(name, value_id);
|
||||
}
|
||||
|
||||
bool DefineGlobalType(const std::string& name, utils::IdType type_id) {
|
||||
return contexts_.front().DefineLocalType(name, type_id);
|
||||
}
|
||||
|
||||
bool DefineLocalType(const std::string& name, utils::IdType type_id) {
|
||||
return contexts_.back().DefineLocalType(name, type_id);
|
||||
}
|
||||
|
|
@ -113,8 +118,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -126,8 +131,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -139,8 +144,8 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -161,8 +166,8 @@ public:
|
|||
return maybe_variable.value();
|
||||
}
|
||||
|
||||
if (contexts_[i].IsHidingPrevious()) {
|
||||
break;
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
|
|
@ -175,9 +180,9 @@ public:
|
|||
return maybe_type.value();
|
||||
}
|
||||
|
||||
// if (contexts_[i].IsHidingPrevious()) { // TODO: old types automatically shadowed by new ??
|
||||
// break;
|
||||
// }
|
||||
if (contexts_[i].IsHidingPrevious() && i > 0) { // not for global context
|
||||
i = 1; // go to global context after --i
|
||||
}
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public:
|
|||
for (size_t i = 0; i < info::type::InternalTypesCount; ++i) {
|
||||
info::type::InternalType type = static_cast<info::type::InternalType>(i);
|
||||
std::string type_name = info::type::ToString(type);
|
||||
context_manager_.DefineLocalType(type_name, global_info_.FindAbstractType(type_name).value()->node->type->graph_id_);
|
||||
context_manager_.DefineGlobalType(type_name, global_info_.FindAbstractType(type_name).value()->node->type->graph_id_);
|
||||
}
|
||||
Visit(partition);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue