Fixes for equality

This commit is contained in:
Deukhoofd 2018-12-09 11:45:38 +01:00
parent e1b9bb2002
commit 92586e4939
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
6 changed files with 72 additions and 2 deletions

View File

@ -39,5 +39,19 @@ namespace Upsilon.BaseTypes
{ {
return Value.ToString(); return Value.ToString();
} }
protected bool Equals(ScriptBoolean other)
{
return other.Value == Value;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ScriptBoolean) obj);
}
} }
} }

View File

@ -2,6 +2,7 @@ namespace Upsilon.BaseTypes
{ {
internal class ScriptNull : ScriptType internal class ScriptNull : ScriptType
{ {
public override Type Type => Type.Nil; public override Type Type => Type.Nil;
public override object ToCSharpObject() public override object ToCSharpObject()
{ {
@ -17,5 +18,18 @@ namespace Upsilon.BaseTypes
{ {
return "null"; return "null";
} }
protected bool Equals(ScriptNull other)
{
return true;
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ScriptNull) obj);
}
} }
} }

View File

@ -55,5 +55,19 @@ namespace Upsilon.BaseTypes.UserData
{ {
return new ScriptNumberLong(Dictionary.Count); return new ScriptNumberLong(Dictionary.Count);
} }
protected bool Equals(DictionaryUserData other)
{
return Dictionary.Equals(other.Dictionary);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((DictionaryUserData) obj);
}
} }
} }

View File

@ -55,5 +55,19 @@ namespace Upsilon.BaseTypes.UserData
{ {
return _typeInfo.UnaryOperator(Value, par1, op); return _typeInfo.UnaryOperator(Value, par1, op);
} }
protected bool Equals(GenericUserData other)
{
return Value.Equals(other.Value);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((GenericUserData) obj);
}
} }
} }

View File

@ -71,5 +71,19 @@ namespace Upsilon.BaseTypes.UserData
{ {
return new ScriptNumberLong(List.Count); return new ScriptNumberLong(List.Count);
} }
protected bool Equals(ListUserData other)
{
return List.Equals(other.List);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((ListUserData) obj);
}
} }
} }

View File

@ -382,9 +382,9 @@ namespace Upsilon.Evaluator
} }
goto default; goto default;
case BoundBinaryOperator.OperatorKind.Equality: case BoundBinaryOperator.OperatorKind.Equality:
return new ScriptBoolean(Equals(left, right)); return new ScriptBoolean(left.Equals(right));
case BoundBinaryOperator.OperatorKind.Inequality: case BoundBinaryOperator.OperatorKind.Inequality:
return new ScriptBoolean(!Equals(left, right)); return new ScriptBoolean(!left.Equals(right));
case BoundBinaryOperator.OperatorKind.Less: case BoundBinaryOperator.OperatorKind.Less:
if (left.Type == Type.Number && right.Type == Type.Number) if (left.Type == Type.Number && right.Type == Type.Number)
{ {