PorygonLang/src/ScriptType.hpp

90 lines
2.1 KiB
C++
Raw Normal View History

#include <utility>
#ifndef PORYGONLANG_SCRIPTTYPE_HPP
#define PORYGONLANG_SCRIPTTYPE_HPP
#include <utility>
#include <vector>
#include <memory>
#include "Binder/BoundVariables/BoundVariableKey.hpp"
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;
const TypeClass GetClass(){
return _class;
}
2019-05-28 16:50:23 +00:00
virtual bool operator ==(ScriptType b){
return _class == b._class;
};
virtual bool operator !=(ScriptType b){
return ! (operator==(b));
}
};
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;
}
};
class FunctionScriptType : public ScriptType{
std::shared_ptr<ScriptType> _returnType;
std::vector<std::shared_ptr<ScriptType>> _parameterTypes;
std::vector<std::shared_ptr<BoundVariableKey>> _parameterKeys;
public:
FunctionScriptType(std::shared_ptr<ScriptType> returnType, std::vector<std::shared_ptr<ScriptType>> parameterTypes,
std::vector<std::shared_ptr<BoundVariableKey>> parameterKeys)
: ScriptType(TypeClass::Function){
_returnType = std::move(returnType);
_parameterTypes = std::move(parameterTypes);
_parameterKeys = std::move(parameterKeys);
}
ScriptType* GetReturnType(){
return _returnType.get();
}
std::vector<std::shared_ptr<ScriptType>> GetParameterTypes(){
return _parameterTypes;
}
std::vector<std::shared_ptr<BoundVariableKey>> GetParameterKeys(){
return _parameterKeys;
}
};
#endif //PORYGONLANG_SCRIPTTYPE_HPP