Work on making userdata work through extern C entry points
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:
@@ -83,11 +83,16 @@ BoundStatement *Binder::BindIndexAssignmentStatement(const ParsedStatement *stat
|
||||
}
|
||||
|
||||
std::shared_ptr<ScriptType> ParseTypeIdentifier(HashedString s){
|
||||
switch (s.GetHash()){
|
||||
auto hash = s.GetHash();
|
||||
switch (hash){
|
||||
case HashedString::ConstHash("number"): return std::make_shared<NumericScriptType>(false, false);
|
||||
case HashedString::ConstHash("bool"): return std::make_shared<ScriptType>(TypeClass::Bool);
|
||||
case HashedString::ConstHash("string"): return std::make_shared<StringScriptType>(false, 0);
|
||||
default: return std::make_shared<UserDataScriptType>(s.GetHash());
|
||||
default:
|
||||
if (!UserDataStorage::HasUserDataType(hash)){
|
||||
return nullptr;
|
||||
}
|
||||
return std::make_shared<UserDataScriptType>(hash);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +107,10 @@ BoundStatement *Binder::BindFunctionDeclarationStatement(const ParsedStatement *
|
||||
for (int i = 0; i < parameters->size(); i++){
|
||||
auto var = parameters -> at(i);
|
||||
auto parsedType = ParseTypeIdentifier(var->GetType());
|
||||
if (parsedType == nullptr){
|
||||
this -> _scriptData -> Diagnostics -> LogError(DiagnosticCode::InvalidTypeName, statement->GetStartPosition(), statement->GetLength());
|
||||
return new BoundBadStatement();
|
||||
}
|
||||
parameterTypes.at(i) = parsedType;
|
||||
auto parameterAssignment = this->_scope->CreateExplicitLocal(var->GetIdentifier().GetHash(), parsedType);
|
||||
if (parameterAssignment.GetResult() == VariableAssignmentResult::Ok){
|
||||
@@ -442,7 +451,7 @@ BoundExpression* Binder::BindNumericalTableExpression(const ParsedNumericalTable
|
||||
}
|
||||
|
||||
BoundExpression *Binder::BindTableExpression(const ParsedTableExpression *expression) {
|
||||
auto tableScope = new unordered_map<int, BoundVariable*>();
|
||||
auto tableScope = new unordered_map<uint32_t, BoundVariable*>();
|
||||
auto innerScope = new BoundScope(tableScope);
|
||||
auto currentScope = this -> _scope;
|
||||
this -> _scope = innerScope;
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
#include "BoundScope.hpp"
|
||||
|
||||
BoundScope::BoundScope(unordered_map<int, BoundVariable *> *tableScope) {
|
||||
BoundScope::BoundScope(unordered_map<uint32_t, BoundVariable *> *tableScope) {
|
||||
_tableScope = tableScope;
|
||||
_currentScope = 1;
|
||||
_lastCreatedScope = 1;
|
||||
auto localUpmostScope = new unordered_map<int, BoundVariable*>();
|
||||
auto localUpmostScope = new unordered_map<uint32_t, BoundVariable*>();
|
||||
_localScope.push_back(localUpmostScope);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ void BoundScope::GoInnerScope() {
|
||||
_lastCreatedScope++;
|
||||
_currentScope = _lastCreatedScope;
|
||||
if (_localScope.size() < _currentScope){
|
||||
auto innerScope = new unordered_map<int, BoundVariable*>();
|
||||
auto innerScope = new unordered_map<uint32_t, BoundVariable*>();
|
||||
_localScope.push_back(innerScope);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +53,7 @@ int BoundScope::Exists(int key) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
BoundVariable *BoundScope::GetVariable(int scope, int identifier) {
|
||||
BoundVariable *BoundScope::GetVariable(uint32_t scope, uint32_t identifier) {
|
||||
if (scope == 0){
|
||||
auto find = this -> _tableScope->find(identifier);
|
||||
if (find != _tableScope->end()){
|
||||
@@ -70,7 +70,7 @@ BoundVariable *BoundScope::GetVariable(int scope, int identifier) {
|
||||
}
|
||||
}
|
||||
|
||||
VariableAssignment BoundScope::CreateExplicitLocal(int identifier, std::shared_ptr<ScriptType> type) {
|
||||
VariableAssignment BoundScope::CreateExplicitLocal(uint32_t identifier, std::shared_ptr<ScriptType> type) {
|
||||
auto scope = this->_localScope.at(this->_currentScope - 1);
|
||||
if (scope -> find(identifier) != scope -> end()){
|
||||
return VariableAssignment(VariableAssignmentResult::ExplicitLocalVariableExists, nullptr);
|
||||
@@ -79,7 +79,7 @@ VariableAssignment BoundScope::CreateExplicitLocal(int identifier, std::shared_p
|
||||
return VariableAssignment(VariableAssignmentResult::Ok, new BoundVariableKey(identifier, this->_currentScope, true));
|
||||
}
|
||||
|
||||
VariableAssignment BoundScope::AssignVariable(int identifier, const std::shared_ptr<ScriptType>& type) {
|
||||
VariableAssignment BoundScope::AssignVariable(uint32_t identifier, const std::shared_ptr<ScriptType>& type) {
|
||||
int exists = this->Exists(identifier);
|
||||
if (exists == -1){
|
||||
// Creation
|
||||
|
||||
@@ -14,21 +14,21 @@
|
||||
using namespace std;
|
||||
|
||||
class BoundScope {
|
||||
unordered_map<int, BoundVariable*>* _tableScope;
|
||||
vector<unordered_map<int, BoundVariable*>*> _localScope;
|
||||
unordered_map<uint32_t, BoundVariable*>* _tableScope;
|
||||
vector<unordered_map<uint32_t, BoundVariable*>*> _localScope;
|
||||
int _currentScope;
|
||||
int _lastCreatedScope;
|
||||
public:
|
||||
explicit BoundScope(unordered_map<int, BoundVariable*> *tableScope);
|
||||
explicit BoundScope(unordered_map<uint32_t, BoundVariable*> *tableScope);
|
||||
~BoundScope();
|
||||
|
||||
void GoInnerScope();
|
||||
void GoOuterScope();
|
||||
|
||||
int Exists(int key);
|
||||
BoundVariable* GetVariable(int scope, int identifier);
|
||||
VariableAssignment CreateExplicitLocal(int identifier, std::shared_ptr<ScriptType> type);
|
||||
VariableAssignment AssignVariable(int identifier, const std::shared_ptr<ScriptType>& type);
|
||||
BoundVariable* GetVariable(uint32_t scope, uint32_t identifier);
|
||||
VariableAssignment CreateExplicitLocal(uint32_t identifier, std::shared_ptr<ScriptType> type);
|
||||
VariableAssignment AssignVariable(uint32_t identifier, const std::shared_ptr<ScriptType>& type);
|
||||
|
||||
size_t GetLocalVariableCount(){
|
||||
return _localScope.size();
|
||||
|
||||
Reference in New Issue
Block a user