Support Any type in function parameters
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-09-12 13:26:59 +02:00
parent eca0c6b075
commit b94c811e94
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
6 changed files with 14 additions and 10 deletions

View File

@ -124,6 +124,8 @@ namespace Porygon::Binder {
return ScriptType::BoolType; return ScriptType::BoolType;
case HashedString::ConstHash("string"): case HashedString::ConstHash("string"):
return StringScriptType::Dynamic; return StringScriptType::Dynamic;
case HashedString::ConstHash(("any")):
return ScriptType::AnyType;
case HashedString::ConstHash("table"): case HashedString::ConstHash("table"):
return make_shared<TableScriptType>(); return make_shared<TableScriptType>();
default: default:

View File

@ -41,7 +41,7 @@ namespace Porygon {
return false; return false;
} }
for (size_t i = 0; i < parameters->size(); i++){ for (size_t i = 0; i < parameters->size(); i++){
if (_parameterTypes[i]->GetClass() == TypeClass::All) if (_parameterTypes[i]->GetClass() == TypeClass::Any)
continue; continue;
auto parameter = parameters->at(i); auto parameter = parameters->at(i);
const auto& parameterType = parameter->GetType(); const auto& parameterType = parameter->GetType();

View File

@ -8,6 +8,7 @@ namespace Porygon{
shared_ptr<const ScriptType> ScriptType::BoolType = make_shared<ScriptType>(TypeClass::Bool); shared_ptr<const ScriptType> ScriptType::BoolType = make_shared<ScriptType>(TypeClass::Bool);
shared_ptr<const ScriptType> ScriptType::NilType = make_shared<ScriptType>(TypeClass::Nil); shared_ptr<const ScriptType> ScriptType::NilType = make_shared<ScriptType>(TypeClass::Nil);
shared_ptr<const ScriptType> ScriptType::AnyType = make_shared<ScriptType>(TypeClass::Any);
shared_ptr<const NumericScriptType> NumericScriptType::AwareInt = make_shared<NumericScriptType>(true, false); shared_ptr<const NumericScriptType> NumericScriptType::AwareInt = make_shared<NumericScriptType>(true, false);
shared_ptr<const NumericScriptType> NumericScriptType::AwareFloat = make_shared<NumericScriptType>(true, true); shared_ptr<const NumericScriptType> NumericScriptType::AwareFloat = make_shared<NumericScriptType>(true, true);
shared_ptr<const NumericScriptType> NumericScriptType::Unaware = make_shared<NumericScriptType>(false, false); shared_ptr<const NumericScriptType> NumericScriptType::Unaware = make_shared<NumericScriptType>(false, false);
@ -20,7 +21,7 @@ namespace Porygon{
bool ScriptType::operator==(const shared_ptr<const ScriptType> &b) const { bool ScriptType::operator==(const shared_ptr<const ScriptType> &b) const {
if (_class == TypeClass::Nil){ if (_class == TypeClass::Nil){
auto bClass = b->_class; auto bClass = b->_class;
if (bClass == TypeClass::UserData || bClass == TypeClass::String || bClass == TypeClass::All) if (bClass == TypeClass::UserData || bClass == TypeClass::String || bClass == TypeClass::Any)
return true; return true;
} }
return _class == b->_class; return _class == b->_class;
@ -47,7 +48,7 @@ namespace Porygon{
} }
CastResult ScriptType::CastableTo(const shared_ptr<const ScriptType> &castType, bool explicitCast) const { CastResult ScriptType::CastableTo(const shared_ptr<const ScriptType> &castType, bool explicitCast) const {
if (_class == TypeClass::All){ if (_class == TypeClass::Any){
return CastResult ::UncheckedCast; return CastResult ::UncheckedCast;
} }
if (explicitCast) if (explicitCast)
@ -66,7 +67,7 @@ namespace Porygon{
case TypeClass::Function: return "function"; case TypeClass::Function: return "function";
case TypeClass::UserData: return "userdata"; case TypeClass::UserData: return "userdata";
case TypeClass::Table: return "table"; case TypeClass::Table: return "table";
case TypeClass::All: return "all"; case TypeClass::Any: return "all";
} }
throw exception(); throw exception();
} }

View File

@ -19,7 +19,7 @@ namespace Porygon{
Function, Function,
UserData, UserData,
Table, Table,
All, Any,
}; };
class ScriptType{ class ScriptType{
@ -27,6 +27,7 @@ namespace Porygon{
public: public:
static shared_ptr<const ScriptType> BoolType; static shared_ptr<const ScriptType> BoolType;
static shared_ptr<const ScriptType> NilType; static shared_ptr<const ScriptType> NilType;
static shared_ptr<const ScriptType> AnyType;
explicit ScriptType(TypeClass c){ explicit ScriptType(TypeClass c){
_class = c; _class = c;

View File

@ -45,7 +45,7 @@ namespace Porygon{
if (stringKey != nullptr && stringKey->IsKnownAtBind() && _values != nullptr){ if (stringKey != nullptr && stringKey->IsKnownAtBind() && _values != nullptr){
return _values-> at(Utilities::HashedString::CreateLookup(stringKey->GetHashValue()))->GetType(); return _values-> at(Utilities::HashedString::CreateLookup(stringKey->GetHashValue()))->GetType();
} }
return make_shared<ScriptType>(TypeClass::All); return make_shared<ScriptType>(TypeClass::Any);
} }
[[nodiscard]] inline shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const final{ [[nodiscard]] inline shared_ptr<const ScriptType> GetIndexedType(uint32_t hash) const final{
@ -63,7 +63,7 @@ namespace Porygon{
[[nodiscard]] [[nodiscard]]
shared_ptr<const ScriptType> GetIteratorKeyType() const final { shared_ptr<const ScriptType> GetIteratorKeyType() const final {
return make_shared<ScriptType>(TypeClass::All); return make_shared<ScriptType>(TypeClass::Any);
} }
}; };
} }

View File

@ -91,7 +91,7 @@ namespace Porygon::StandardLibraries{
return new Evaluation::StringEvalValue(parameter); return new Evaluation::StringEvalValue(parameter);
} }
static shared_ptr<GenericFunctionScriptType> GetToStringFuncType(){ static shared_ptr<GenericFunctionScriptType> GetToStringFuncType(){
return GetFuncType(StringScriptType::Dynamic, {{make_shared<ScriptType>(TypeClass::All)}}); return GetFuncType(StringScriptType::Dynamic, {{make_shared<ScriptType>(TypeClass::Any)}});
} }
//endregion //endregion
//region Type //region Type
@ -108,12 +108,12 @@ namespace Porygon::StandardLibraries{
case TypeClass::Function: return new Evaluation::StringEvalValue(u"function"); case TypeClass::Function: return new Evaluation::StringEvalValue(u"function");
case TypeClass::UserData: return new Evaluation::StringEvalValue(u"userdata"); case TypeClass::UserData: return new Evaluation::StringEvalValue(u"userdata");
case TypeClass::Table: return new Evaluation::StringEvalValue(u"table"); case TypeClass::Table: return new Evaluation::StringEvalValue(u"table");
case TypeClass::All: return new Evaluation::StringEvalValue(u"all"); case TypeClass::Any: return new Evaluation::StringEvalValue(u"all");
} }
throw exception(); throw exception();
} }
static shared_ptr<GenericFunctionScriptType> GetTypeFuncType(){ static shared_ptr<GenericFunctionScriptType> GetTypeFuncType(){
return GetFuncType(StringScriptType::Dynamic,{{make_shared<ScriptType>(TypeClass::All)}}); return GetFuncType(StringScriptType::Dynamic,{{make_shared<ScriptType>(TypeClass::Any)}});
} }
//endregion //endregion
//region IsFloat //region IsFloat