2019-06-01 11:43:25 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2019-05-21 18:59:26 +00:00
|
|
|
#ifndef PORYGONLANG_SCRIPTTYPE_HPP
|
|
|
|
#define PORYGONLANG_SCRIPTTYPE_HPP
|
|
|
|
|
2019-06-01 10:33:52 +00:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
2019-06-01 11:43:25 +00:00
|
|
|
#include <memory>
|
|
|
|
#include "Binder/BoundVariables/BoundVariableKey.hpp"
|
2019-06-01 10:33:52 +00:00
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2019-05-21 18:59:26 +00:00
|
|
|
enum class TypeClass{
|
|
|
|
Error,
|
|
|
|
Nil,
|
|
|
|
Number,
|
|
|
|
Bool,
|
|
|
|
String,
|
|
|
|
Function,
|
|
|
|
UserData,
|
|
|
|
Table,
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScriptType{
|
|
|
|
TypeClass _class;
|
|
|
|
public:
|
|
|
|
explicit ScriptType(TypeClass c){
|
|
|
|
_class = c;
|
|
|
|
}
|
|
|
|
|
2019-05-28 16:50:23 +00:00
|
|
|
virtual ~ScriptType() = default;
|
|
|
|
|
2019-05-25 14:15:20 +00:00
|
|
|
const TypeClass GetClass(){
|
2019-05-21 18:59:26 +00:00
|
|
|
return _class;
|
|
|
|
}
|
2019-05-28 16:50:23 +00:00
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
virtual bool operator ==(const ScriptType& b){
|
2019-05-28 16:50:23 +00:00
|
|
|
return _class == b._class;
|
|
|
|
};
|
|
|
|
|
2019-06-01 17:20:31 +00:00
|
|
|
virtual bool operator ==(ScriptType* b){
|
|
|
|
return _class == b->_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual bool operator !=(const ScriptType& b){
|
|
|
|
return ! (operator==(b));
|
|
|
|
}
|
|
|
|
virtual bool operator !=(ScriptType* b){
|
2019-05-28 16:50:23 +00:00
|
|
|
return ! (operator==(b));
|
|
|
|
}
|
2019-06-06 15:35:51 +00:00
|
|
|
|
|
|
|
virtual bool CanBeIndexedWith(ScriptType* indexer);
|
|
|
|
|
|
|
|
virtual ScriptType* GetIndexedType(ScriptType* indexer);
|
2019-05-21 18:59:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-05-21 20:15:51 +00:00
|
|
|
|
|
|
|
bool IsAwareOfFloat(){
|
|
|
|
return _awareOfFloat;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsFloat(){
|
|
|
|
return _isFloat;
|
|
|
|
}
|
2019-05-21 18:59:26 +00:00
|
|
|
};
|
|
|
|
|
2019-06-01 10:33:52 +00:00
|
|
|
class FunctionScriptType : public ScriptType{
|
2019-06-01 17:20:31 +00:00
|
|
|
shared_ptr<ScriptType> _returnType;
|
2019-06-08 14:02:21 +00:00
|
|
|
vector<shared_ptr<ScriptType>> _parameterTypes;
|
|
|
|
vector<shared_ptr<BoundVariableKey>> _parameterKeys;
|
2019-06-01 10:33:52 +00:00
|
|
|
public:
|
2019-06-08 14:02:21 +00:00
|
|
|
FunctionScriptType(std::shared_ptr<ScriptType> returnType, vector<shared_ptr<ScriptType>> parameterTypes,
|
|
|
|
vector<shared_ptr<BoundVariableKey>> parameterKeys)
|
2019-06-01 10:33:52 +00:00
|
|
|
: ScriptType(TypeClass::Function){
|
2019-06-01 11:43:25 +00:00
|
|
|
_returnType = std::move(returnType);
|
2019-06-01 10:33:52 +00:00
|
|
|
_parameterTypes = std::move(parameterTypes);
|
|
|
|
_parameterKeys = std::move(parameterKeys);
|
|
|
|
}
|
2019-06-01 17:20:31 +00:00
|
|
|
shared_ptr<ScriptType> GetReturnType(){
|
|
|
|
return _returnType;
|
2019-06-01 10:33:52 +00:00
|
|
|
}
|
|
|
|
|
2019-06-08 14:02:21 +00:00
|
|
|
vector<shared_ptr<ScriptType>> GetParameterTypes(){
|
2019-06-01 10:33:52 +00:00
|
|
|
return _parameterTypes;
|
|
|
|
}
|
|
|
|
|
2019-06-08 14:02:21 +00:00
|
|
|
vector<shared_ptr<BoundVariableKey>> GetParameterKeys(){
|
2019-06-01 10:33:52 +00:00
|
|
|
return _parameterKeys;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-05-21 18:59:26 +00:00
|
|
|
#endif //PORYGONLANG_SCRIPTTYPE_HPP
|