Initial work on standard library
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
|
||||
#include "BoundScope.hpp"
|
||||
#include "../../StandardLibraries/StaticScope.hpp"
|
||||
|
||||
namespace Porygon::Binder {
|
||||
BoundScope::BoundScope(map<Utilities::HashedString, BoundVariable *> *tableScope) {
|
||||
@@ -40,16 +41,21 @@ namespace Porygon::Binder {
|
||||
}
|
||||
|
||||
int BoundScope::Exists(const Utilities::HashedString& key) {
|
||||
for (int i = _currentScope - 1; i >= 0; i--) {
|
||||
auto scope = _localScope.at(i);
|
||||
auto found = scope->find(key);
|
||||
if (found != scope->end()) {
|
||||
return i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
auto found = this->_tableScope->find(key);
|
||||
if (found != _tableScope->end()) {
|
||||
return 0;
|
||||
}
|
||||
for (int i = _currentScope - 1; i >= 0; i--) {
|
||||
auto scope = _localScope.at(i);
|
||||
found = scope->find(key);
|
||||
if (found != scope->end()) {
|
||||
return i + 1;
|
||||
}
|
||||
auto result = StandardLibraries::StaticScope::GetBoundVariable(key);
|
||||
if (result != nullptr){
|
||||
return -2;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -61,6 +67,8 @@ namespace Porygon::Binder {
|
||||
return find->second;
|
||||
}
|
||||
return nullptr;
|
||||
} else if (scope == -2){
|
||||
return StandardLibraries::StaticScope::GetBoundVariable(identifier);
|
||||
} else {
|
||||
auto s = this->_localScope.at(scope - 1);
|
||||
auto find = s->find(identifier);
|
||||
@@ -83,7 +91,7 @@ namespace Porygon::Binder {
|
||||
|
||||
VariableAssignment BoundScope::AssignVariable(const Utilities::HashedString& identifier, const std::shared_ptr<ScriptType> &type) {
|
||||
int exists = this->Exists(identifier);
|
||||
if (exists == -1) {
|
||||
if (exists < 0) {
|
||||
// Creation
|
||||
_tableScope->insert({identifier, new BoundVariable(type)});
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, 0, true));
|
||||
|
||||
Reference in New Issue
Block a user