48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
|
|
||
|
#ifndef PORYGONLANG_TABLESCRIPTTYPE_HPP
|
||
|
#define PORYGONLANG_TABLESCRIPTTYPE_HPP
|
||
|
#include <unordered_map>
|
||
|
#include "Binder/BoundVariables/BoundVariable.hpp"
|
||
|
|
||
|
class TableScriptType : public ScriptType{
|
||
|
unordered_map<int, BoundVariable*>* _values;
|
||
|
int _deepestScope;
|
||
|
public:
|
||
|
explicit TableScriptType(unordered_map<int, BoundVariable*>* values, int deepestScope) : ScriptType(TypeClass::Table){
|
||
|
_values = values;
|
||
|
_deepestScope = deepestScope;
|
||
|
}
|
||
|
|
||
|
~TableScriptType() final{
|
||
|
for (auto i : *_values){
|
||
|
delete i.second;
|
||
|
}
|
||
|
delete _values;
|
||
|
}
|
||
|
|
||
|
bool CanBeIndexedWith(ScriptType* indexer) final{
|
||
|
return indexer->GetClass() == TypeClass ::String;
|
||
|
}
|
||
|
|
||
|
shared_ptr<ScriptType> GetIndexedType(ScriptType* indexer) final{
|
||
|
auto stringKey = (StringScriptType*)indexer;
|
||
|
if (stringKey->IsKnownAtBind()){
|
||
|
return _values-> at(stringKey->GetHashValue())->GetType();
|
||
|
}
|
||
|
throw "TODO: indexing with dynamic keys";
|
||
|
}
|
||
|
|
||
|
unordered_map<int, BoundVariable*>* GetValues(){
|
||
|
return _values;
|
||
|
}
|
||
|
|
||
|
int GetDeepestScope(){
|
||
|
return _deepestScope;
|
||
|
}
|
||
|
|
||
|
};
|
||
|
|
||
|
#include "ScriptType.hpp"
|
||
|
|
||
|
#endif //PORYGONLANG_TABLESCRIPTTYPE_HPP
|