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;
case HashedString::ConstHash("string"):
return StringScriptType::Dynamic;
case HashedString::ConstHash(("any")):
return ScriptType::AnyType;
case HashedString::ConstHash("table"):
return make_shared<TableScriptType>();
default:

View File

@ -41,7 +41,7 @@ namespace Porygon {
return false;
}
for (size_t i = 0; i < parameters->size(); i++){
if (_parameterTypes[i]->GetClass() == TypeClass::All)
if (_parameterTypes[i]->GetClass() == TypeClass::Any)
continue;
auto parameter = parameters->at(i);
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::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::AwareFloat = make_shared<NumericScriptType>(true, true);
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 {
if (_class == TypeClass::Nil){
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 _class == b->_class;
@ -47,7 +48,7 @@ namespace Porygon{
}
CastResult ScriptType::CastableTo(const shared_ptr<const ScriptType> &castType, bool explicitCast) const {
if (_class == TypeClass::All){
if (_class == TypeClass::Any){
return CastResult ::UncheckedCast;
}
if (explicitCast)
@ -66,7 +67,7 @@ namespace Porygon{
case TypeClass::Function: return "function";
case TypeClass::UserData: return "userdata";
case TypeClass::Table: return "table";
case TypeClass::All: return "all";
case TypeClass::Any: return "all";
}
throw exception();
}

View File

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

View File

@ -45,7 +45,7 @@ namespace Porygon{
if (stringKey != nullptr && stringKey->IsKnownAtBind() && _values != nullptr){
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{
@ -63,7 +63,7 @@ namespace Porygon{
[[nodiscard]]
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);
}
static shared_ptr<GenericFunctionScriptType> GetToStringFuncType(){
return GetFuncType(StringScriptType::Dynamic, {{make_shared<ScriptType>(TypeClass::All)}});
return GetFuncType(StringScriptType::Dynamic, {{make_shared<ScriptType>(TypeClass::Any)}});
}
//endregion
//region Type
@ -108,12 +108,12 @@ namespace Porygon::StandardLibraries{
case TypeClass::Function: return new Evaluation::StringEvalValue(u"function");
case TypeClass::UserData: return new Evaluation::StringEvalValue(u"userdata");
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();
}
static shared_ptr<GenericFunctionScriptType> GetTypeFuncType(){
return GetFuncType(StringScriptType::Dynamic,{{make_shared<ScriptType>(TypeClass::All)}});
return GetFuncType(StringScriptType::Dynamic,{{make_shared<ScriptType>(TypeClass::Any)}});
}
//endregion
//region IsFloat