2019-06-12 13:19:28 +00:00
|
|
|
|
|
|
|
#ifndef PORYGONLANG_TABLESCRIPTTYPE_HPP
|
|
|
|
#define PORYGONLANG_TABLESCRIPTTYPE_HPP
|
|
|
|
#include <unordered_map>
|
|
|
|
#include "Binder/BoundVariables/BoundVariable.hpp"
|
|
|
|
|
|
|
|
class TableScriptType : public ScriptType{
|
2019-06-14 20:21:33 +00:00
|
|
|
const unordered_map<uint32_t, BoundVariable*>* _values;
|
2019-06-13 14:26:10 +00:00
|
|
|
const int _localVariableCount;
|
2019-06-12 13:19:28 +00:00
|
|
|
public:
|
2019-06-14 20:21:33 +00:00
|
|
|
explicit TableScriptType(unordered_map<uint32_t, BoundVariable*>* values, int localVariableCount)
|
2019-06-13 14:26:10 +00:00
|
|
|
: ScriptType(TypeClass::Table),
|
|
|
|
_values(values),
|
|
|
|
_localVariableCount(localVariableCount)
|
|
|
|
{}
|
2019-06-12 13:19:28 +00:00
|
|
|
|
|
|
|
~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";
|
|
|
|
}
|
|
|
|
|
2019-06-14 20:21:33 +00:00
|
|
|
const unordered_map<uint32_t, BoundVariable*>* GetValues(){
|
2019-06-12 13:19:28 +00:00
|
|
|
return _values;
|
|
|
|
}
|
|
|
|
|
2019-06-13 14:26:10 +00:00
|
|
|
const int GetLocalVariableCount(){
|
|
|
|
return _localVariableCount;
|
2019-06-12 13:19:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#include "ScriptType.hpp"
|
|
|
|
|
|
|
|
#endif //PORYGONLANG_TABLESCRIPTTYPE_HPP
|