PorygonLang/src/ScriptType.cpp

31 lines
1008 B
C++
Raw Normal View History

#include "Script.hpp"
namespace Porygon{
const bool ScriptType::CanBeIndexedWith(ScriptType *indexer) const{
// String type is the only simple script type we want to
return _class == TypeClass::String && indexer->_class == TypeClass::Number && !((NumericScriptType*)indexer)->IsFloat();
}
const shared_ptr<ScriptType> ScriptType::GetIndexedType(ScriptType *indexer) const{
if (_class == TypeClass::String){
return make_shared<ScriptType>(TypeClass::String);
}
return make_shared<ScriptType>(TypeClass::Error);
}
extern "C"{
ScriptType* CreateScriptType(Porygon::TypeClass t){
return new ScriptType(t);
}
ScriptType* CreateNumericScriptType(bool isAware, bool isFloat){
return new NumericScriptType(isAware, isFloat);
}
ScriptType* CreateStringScriptType(bool knownAtBind, uint32_t hash){
return new StringScriptType(knownAtBind, hash);
}
}
}