Cleanup of main script type class
This commit is contained in:
parent
5d700aa0e9
commit
acc687f213
|
@ -10,7 +10,6 @@
|
||||||
namespace Porygon::Evaluation {
|
namespace Porygon::Evaluation {
|
||||||
class NumericEvalValue : public EvalValue {
|
class NumericEvalValue : public EvalValue {
|
||||||
std::variant<int64_t , double> _intValue, _floatValue;
|
std::variant<int64_t , double> _intValue, _floatValue;
|
||||||
|
|
||||||
bool _isFloat;
|
bool _isFloat;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,64 @@ namespace Porygon{
|
||||||
return make_shared<ScriptType>(TypeClass::Error);
|
return make_shared<ScriptType>(TypeClass::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptType::operator==(const shared_ptr<const ScriptType> &b) const {
|
||||||
|
if (_class == TypeClass::Nil){
|
||||||
|
auto bClass = b->_class;
|
||||||
|
if (bClass == TypeClass::UserData || bClass == TypeClass::String || bClass == TypeClass::All)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return _class == b->_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptType::operator!=(const shared_ptr<const ScriptType> &b) const {
|
||||||
|
return ! (operator==(b));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptType::CanBeIndexedWithIdentifier(uint32_t hash) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<const ScriptType> ScriptType::GetIndexedType(uint32_t hash) const {
|
||||||
|
throw "This type told the binder it can be indexed, but it does not implement the resulting type.";
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptType::CanBeIterated() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<const ScriptType> ScriptType::GetIteratorKeyType() const {
|
||||||
|
throw "This type told the binder it can be iterated, but it does not implement the resulting type.";
|
||||||
|
}
|
||||||
|
|
||||||
|
CastResult ScriptType::CastableTo(const shared_ptr<const ScriptType> &castType, bool explicitCast) const {
|
||||||
|
if (_class == TypeClass::All){
|
||||||
|
return CastResult ::UncheckedCast;
|
||||||
|
}
|
||||||
|
if (explicitCast)
|
||||||
|
return CastResult::InvalidCast;
|
||||||
|
return CastResult::InvalidCast;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ScriptType::ToString(TypeClass c) {
|
||||||
|
switch (c){
|
||||||
|
|
||||||
|
case TypeClass::Error: return "error";
|
||||||
|
case TypeClass::Nil: return "nil";
|
||||||
|
case TypeClass::Number: return "number";
|
||||||
|
case TypeClass::Bool: return "bool";
|
||||||
|
case TypeClass::String: return "string";
|
||||||
|
case TypeClass::Function: return "function";
|
||||||
|
case TypeClass::UserData: return "userdata";
|
||||||
|
case TypeClass::Table: return "table";
|
||||||
|
case TypeClass::All: return "all";
|
||||||
|
}
|
||||||
|
throw exception();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ScriptType::ToString() const {
|
||||||
|
return ToString(this->_class);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C"{
|
extern "C"{
|
||||||
ScriptType* CreateScriptType(Porygon::TypeClass t){
|
ScriptType* CreateScriptType(Porygon::TypeClass t){
|
||||||
return new ScriptType(t);
|
return new ScriptType(t);
|
||||||
|
|
|
@ -26,85 +26,36 @@ namespace Porygon{
|
||||||
All,
|
All,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ScriptType{
|
class ScriptType{
|
||||||
TypeClass _class;
|
TypeClass _class;
|
||||||
public:
|
public:
|
||||||
|
static shared_ptr<const ScriptType> BoolType;
|
||||||
|
static shared_ptr<const ScriptType> NilType;
|
||||||
|
|
||||||
explicit ScriptType(TypeClass c){
|
explicit ScriptType(TypeClass c){
|
||||||
_class = c;
|
_class = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static shared_ptr<const ScriptType> BoolType;
|
|
||||||
static shared_ptr<const ScriptType> NilType;
|
|
||||||
virtual ~ScriptType() = default;
|
virtual ~ScriptType() = default;
|
||||||
|
|
||||||
[[nodiscard]] inline TypeClass GetClass() const{
|
[[nodiscard]] inline TypeClass GetClass() const{
|
||||||
return _class;
|
return _class;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool operator ==(const shared_ptr<const ScriptType>& b) const{
|
virtual bool operator ==(const shared_ptr<const ScriptType>& b) const;
|
||||||
if (_class == TypeClass::Nil){
|
virtual bool operator !=(const shared_ptr<const ScriptType>& b) const;
|
||||||
auto bClass = b->_class;
|
|
||||||
if (bClass == TypeClass::UserData || bClass == TypeClass::String || bClass == TypeClass::All)
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return _class == b->_class;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool operator !=(const shared_ptr<const ScriptType>& b) const{
|
|
||||||
return ! (operator==(b));
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool CanBeIndexedWith(const ScriptType* indexer) const;
|
virtual bool CanBeIndexedWith(const ScriptType* indexer) const;
|
||||||
[[nodiscard]]
|
[[nodiscard]] virtual bool CanBeIndexedWithIdentifier(uint32_t hash) const;
|
||||||
virtual bool CanBeIndexedWithIdentifier(uint32_t hash) const{
|
[[nodiscard]] virtual shared_ptr<const ScriptType> GetIndexedType(const ScriptType* indexer) const;
|
||||||
return false;
|
[[nodiscard]] virtual shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const;
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]] virtual bool CanBeIterated() const;
|
||||||
virtual shared_ptr<const ScriptType> GetIndexedType(const ScriptType* indexer) const;
|
[[nodiscard]] virtual shared_ptr<const ScriptType> GetIteratorKeyType() const;
|
||||||
[[nodiscard]]
|
|
||||||
virtual shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const{
|
|
||||||
throw "This type told the binder it can be indexed, but it does not implement the resulting type.";
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]] virtual CastResult CastableTo(const shared_ptr<const ScriptType>& castType, bool explicitCast) const;
|
||||||
virtual bool CanBeIterated() const{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
[[nodiscard]]
|
|
||||||
virtual shared_ptr<const ScriptType> GetIteratorKeyType() const{
|
|
||||||
throw "This type told the binder it can be iterated, but it does not implement the resulting type.";
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] virtual CastResult CastableTo(const shared_ptr<const ScriptType>& castType, bool explicitCast) const{
|
static std::string ToString(TypeClass c);
|
||||||
if (_class == TypeClass::All){
|
[[nodiscard]] virtual std::string ToString() const;
|
||||||
return CastResult ::UncheckedCast;
|
|
||||||
}
|
|
||||||
if (explicitCast)
|
|
||||||
return CastResult::InvalidCast;
|
|
||||||
return CastResult::InvalidCast;
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string ToString(TypeClass c){
|
|
||||||
switch (c){
|
|
||||||
|
|
||||||
case TypeClass::Error: return "error";
|
|
||||||
case TypeClass::Nil: return "nil";
|
|
||||||
case TypeClass::Number: return "number";
|
|
||||||
case TypeClass::Bool: return "bool";
|
|
||||||
case TypeClass::String: return "string";
|
|
||||||
case TypeClass::Function: return "function";
|
|
||||||
case TypeClass::UserData: return "userdata";
|
|
||||||
case TypeClass::Table: return "table";
|
|
||||||
case TypeClass::All: return "all";
|
|
||||||
}
|
|
||||||
throw exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] virtual std::string ToString() const{
|
|
||||||
return ToString(this->_class);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class NumericScriptType : public ScriptType{
|
class NumericScriptType : public ScriptType{
|
||||||
|
|
Loading…
Reference in New Issue