#ifndef PORYGONLANG_SCRIPTTYPE_HPP #define PORYGONLANG_SCRIPTTYPE_HPP #include #include #include #include "Binder/BoundVariables/BoundVariableKey.hpp" #include "Utilities/HashedString.hpp" using namespace std; enum class TypeClass{ Error, Nil, Number, Bool, String, Function, UserData, Table, }; class ScriptType{ TypeClass _class; public: explicit ScriptType(TypeClass c){ _class = c; } virtual ~ScriptType() = default; const TypeClass GetClass(){ return _class; } virtual bool operator ==(const ScriptType& b){ return _class == b._class; }; virtual bool operator ==(ScriptType* b){ return _class == b->_class; }; virtual bool operator !=(const ScriptType& b){ return ! (operator==(b)); } virtual bool operator !=(ScriptType* b){ return ! (operator==(b)); } virtual bool CanBeIndexedWith(ScriptType* indexer); virtual shared_ptr GetIndexedType(ScriptType* indexer); }; class NumericScriptType : public ScriptType{ // Are we aware of whether this is a float or not? bool _awareOfFloat; // Is this value a float? bool _isFloat; public: explicit NumericScriptType(bool floatAware, bool isFloat) : ScriptType(TypeClass::Number){ _awareOfFloat = floatAware; _isFloat = isFloat; } bool IsAwareOfFloat(){ return _awareOfFloat; } bool IsFloat(){ return _isFloat; } }; class StringScriptType : public ScriptType{ bool _isKnownAtBind; int _hashValue; public: explicit StringScriptType(bool knownAtBind, int hashValue): ScriptType(TypeClass::String){ _isKnownAtBind = knownAtBind; _hashValue = hashValue; } bool IsKnownAtBind(){ return _isKnownAtBind; } int GetHashValue(){ return _hashValue; } }; class FunctionScriptType : public ScriptType{ shared_ptr _returnType; vector> _parameterTypes; vector> _parameterKeys; int _scopeIndex; public: FunctionScriptType(std::shared_ptr returnType, vector> parameterTypes, vector> parameterKeys, int scopeIndex) : ScriptType(TypeClass::Function){ _returnType = std::move(returnType); _parameterTypes = std::move(parameterTypes); _parameterKeys = std::move(parameterKeys); _scopeIndex = scopeIndex; } shared_ptr GetReturnType(){ return _returnType; } vector> GetParameterTypes(){ return _parameterTypes; } vector> GetParameterKeys(){ return _parameterKeys; } int GetScopeIndex(){ return _scopeIndex; } }; class NumericalTableScriptType : public ScriptType{ shared_ptr _valueType; // Consider adding a check whether the table actually contains a type if every key is static. public: explicit NumericalTableScriptType(shared_ptr valueType) : ScriptType(TypeClass::Table){ _valueType = std::move(valueType); } bool CanBeIndexedWith(ScriptType* indexer) final{ return indexer->GetClass() == TypeClass ::Number; } shared_ptr GetIndexedType(ScriptType* indexer) final{ return _valueType; } }; #endif //PORYGONLANG_SCRIPTTYPE_HPP