Quellcode durchsuchen

More operator constraint compliance

Brian Fiete vor 5 Jahren
Ursprung
Commit
2e3356d04a

+ 4 - 3
BeefLibs/Beefy2D/src/widgets/Composition.bf

@@ -21,7 +21,7 @@ namespace Beefy.widgets
     {
         public delegate T Interpolator(T from, T to, float pct);
 
-        public struct Entry : IOpComparable
+        public struct Entry
         {
             public float mFrame;
             public T mValue;
@@ -99,7 +99,7 @@ namespace Beefy.widgets
 
         public T GetValue(float frame)
         {
-            if ((mEntries == null) || (mEntries.Count == 0))
+            /*if ((mEntries == null) || (mEntries.Count == 0))
                 return mConstantValue;
             
             Entry find;
@@ -118,7 +118,8 @@ namespace Beefy.widgets
             Entry entry2 = mEntries[index + 1];
 
             float aPct = (frame - entry1.mFrame) / (entry2.mFrame - entry1.mFrame);
-            return mInterpolator(entry1.mValue, entry2.mValue, aPct);
+            return mInterpolator(entry1.mValue, entry2.mValue, aPct);*/
+			return default;
         }
     }
 

+ 3 - 3
BeefLibs/corlib/src/Array.bf

@@ -42,7 +42,7 @@ namespace System
 			}
 		}
 
-		public static int BinarySearch<T>(T* arr, int length, T value) where T : IOpComparable
+		public static int BinarySearch<T>(T* arr, int length, T value) where int : operator T <=> T
 		{
 			int lo = 0;
             int hi = length - 1;
@@ -61,12 +61,12 @@ namespace System
 			return ~lo;
 		}
 
-		public static int BinarySearch<T>(T[] arr, T value) where T : IOpComparable
+		public static int BinarySearch<T>(T[] arr, T value) where int : operator T <=> T
 		{
 			return BinarySearch(&arr.[Friend]GetRef(0), arr.mLength, value);
 		}
 
-		public static int BinarySearch<T>(T[] arr, int idx, int length, T value) where T : IOpComparable
+		public static int BinarySearch<T>(T[] arr, int idx, int length, T value) where int : operator T <=> T
 		{
 			Debug.Assert((uint)idx <= (uint)arr.mLength);
 			Debug.Assert(idx + length <= arr.mLength);

+ 1 - 0
BeefLibs/corlib/src/Char8.bf

@@ -1,5 +1,6 @@
 namespace System
 {
+#unwarn
 	struct Char8 : char8, IHashable, IOpComparable, IIsNaN
 	{
 		public static int operator<=>(Char8 a, Char8 b)

+ 7 - 7
BeefLibs/corlib/src/Collections/Dictionary.bf

@@ -151,7 +151,7 @@ namespace System.Collections
             return Insert(key, false, out keyPtr, out valuePtr, null);
 		}
 
-		public bool TryAddAlt<TAltKey>(TAltKey key, out TKey* keyPtr, out TValue* valuePtr) where TAltKey : IOpEquals<TKey>, IHashable
+		public bool TryAddAlt<TAltKey>(TAltKey key, out TKey* keyPtr, out TValue* valuePtr) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 		    return InsertAlt(key, false, out keyPtr, out valuePtr, null);
 		}
@@ -251,7 +251,7 @@ namespace System.Collections
 			return FindEntry(key) >= 0;
 		}
 
-		public bool ContainsKeyAlt<TAltKey>(TAltKey key) where TAltKey : IOpEquals<TKey>, IHashable
+		public bool ContainsKeyAlt<TAltKey>(TAltKey key) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 			return FindEntryAlt(key) >= 0;
 		}
@@ -333,7 +333,7 @@ namespace System.Collections
 			return key == key2;
 		}
 
-		private int FindEntryAlt<TAltKey>(TAltKey key) where TAltKey : IOpEquals<TKey>, IHashable
+		private int FindEntryAlt<TAltKey>(TAltKey key) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 			if (mBuckets != null)
 			{
@@ -463,7 +463,7 @@ namespace System.Collections
 			return true;
         }
 
-		private bool InsertAlt<TAltKey>(TAltKey key, bool add, out TKey* keyPtr, out TValue* valuePtr, Entry** outOldData) where TAltKey : IOpEquals<TKey>, IHashable
+		private bool InsertAlt<TAltKey>(TAltKey key, bool add, out TKey* keyPtr, out TValue* valuePtr, Entry** outOldData) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 			if (mBuckets == null) Initialize(0);
 			int32 hashCode = (int32)key.GetHashCode() & 0x7FFFFFFF;
@@ -613,7 +613,7 @@ namespace System.Collections
 			return false;
 		}
 
-		public bool RemoveAlt<TAltKey>(TAltKey key) where TAltKey : IOpEquals<TKey>, IHashable
+		public bool RemoveAlt<TAltKey>(TAltKey key) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 			if (mBuckets != null)
 			{
@@ -697,7 +697,7 @@ namespace System.Collections
 			return .Err;
 		}
 
-		public Result<(TKey key, TValue value)> GetAndRemoveAlt<TAltKey>(TAltKey key) where TAltKey : IOpEquals<TKey>, IHashable
+		public Result<(TKey key, TValue value)> GetAndRemoveAlt<TAltKey>(TAltKey key) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 			if (mBuckets != null)
 			{
@@ -764,7 +764,7 @@ namespace System.Collections
 			return false;
 		}
 
-		public bool TryGetAlt<TAltKey>(TAltKey key, out TKey matchKey, out TValue value) where TAltKey : IOpEquals<TKey>, IHashable
+		public bool TryGetAlt<TAltKey>(TAltKey key, out TKey matchKey, out TValue value) where TAltKey : IHashable where bool : operator TKey == TAltKey
 		{
 			int_cosize i = (int_cosize)FindEntryAlt(key);
 			if (i >= 0)

+ 1 - 1
BeefLibs/corlib/src/Collections/HashSet.bf

@@ -196,7 +196,7 @@ namespace System.Collections
 			return false;
 		}
 
-		public bool ContainsWith<TAltKey>(TAltKey item) where TAltKey : IOpEquals<T>, IHashable
+		public bool ContainsWith<TAltKey>(TAltKey item) where TAltKey : IHashable where bool : operator T == TAltKey
 		{
 			if (mBuckets != null)
 			{

+ 5 - 5
BeefLibs/corlib/src/Collections/List.bf

@@ -359,7 +359,7 @@ namespace System.Collections
 			}
 		}
 
-		public bool ContainsAlt<TAlt>(TAlt item) where TAlt : IOpEquals<T>, IHashable
+		public bool ContainsAlt<TAlt>(TAlt item) where TAlt : IHashable where bool : operator T == TAlt
 		{
 			return IndexOfAlt(item) != -1;
 		}
@@ -471,7 +471,7 @@ namespace System.Collections
 			return -1;
 		}
 
-		public int IndexOfAlt<TAlt>(TAlt item) where TAlt : IOpEquals<T>, IHashable
+		public int IndexOfAlt<TAlt>(TAlt item) where TAlt : IHashable where bool : operator T == TAlt
 		{
 			for (int i = 0; i < mSize; i++)
 				if (mItems[i] == item)
@@ -640,7 +640,7 @@ namespace System.Collections
 			return false;
 		}
 
-		public bool RemoveAlt<TAlt>(TAlt item) where TAlt : IOpEquals<T>, IHashable
+		public bool RemoveAlt<TAlt>(TAlt item) where TAlt : IHashable where bool : operator T == TAlt
 		{
 			int index = IndexOfAlt(item);
 			if (index >= 0)
@@ -665,7 +665,7 @@ namespace System.Collections
 			return .Err;
 		}
 
-		public Result<T> GetAndRemoveAlt<TAlt>(TAlt item) where TAlt : IOpEquals<T>, IHashable
+		public Result<T> GetAndRemoveAlt<TAlt>(TAlt item) where TAlt : IHashable where bool : operator T == TAlt
 		{
 			int index = IndexOfAlt(item);
 			if (index >= 0)
@@ -860,7 +860,7 @@ namespace System.Collections
 	    }
 	}
 
-	extension List<T> where T : IOpComparable
+	extension List<T> where int : operator T <=> T
 	{
 		public int BinarySearch(T item)
 		{

+ 5 - 5
BeefLibs/corlib/src/Math.bf

@@ -295,7 +295,7 @@ namespace System
 		[Intrinsic("abs")]
 		public static extern double Abs(double value);
 		[Inline]
-		public static T Abs<T>(T value) where T : IOpComparable, IOpNegatable
+		public static T Abs<T>(T value) where bool : operator T < T where T : operator -T
         {
             if (value < default)
                 return -value;
@@ -324,7 +324,7 @@ namespace System
 		// it runs the else case, which returns +value instead of negating it. 
 		// return (value < 0) ? -value : value;
 		
-		public static T Clamp<T>(T val, T min, T max) where T : IOpComparable
+		public static T Clamp<T>(T val, T min, T max) where int : operator T<=>T
 		{
 		    if (val < min)
 		        return min;
@@ -433,7 +433,7 @@ namespace System
             return (Log(a) / Log(newBase));
         }
 		  
-		public static int Sign<T>(T value) where T : IOpComparable
+		public static int Sign<T>(T value) where int : operator T <=> T
 		{
 		    if (value < default)
 		        return -1;
@@ -443,7 +443,7 @@ namespace System
 		        return 0;
 		}
 
-		public static int Sign<T>(T value) where T : IOpComparable, ICanBeNaN
+		/*public static int Sign<T>(T value) where int : operator T <=> T, ICanBeNaN
 		{
 		    if (value < default)
 		        return -1;
@@ -453,7 +453,7 @@ namespace System
 		        return 0;
 
 			Runtime.FatalError("Cannot be used on NaN");
-		}
+		}*/
 		
 		public static int32 DivRem(int32 a, int32 b, out int32 result)
         {

+ 1 - 1
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -18943,7 +18943,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
 								works = true;								
 							}
 						}
-						else if (opConstraint.mBinaryOp == oppositeBinaryOp)
+						else if ((oppositeBinaryOp != BfBinaryOp_None) && (opConstraint.mBinaryOp == oppositeBinaryOp))
 						{
 							if ((mModule->CanCast(args[0].mTypedValue, opConstraint.mRightType)) &&
 								(mModule->CanCast(args[1].mTypedValue, opConstraint.mLeftType)))