// Returns true if [a] and [b] are equivalent. Immutable values (null, bools, // numbers, ranges, and strings) are equal if they have the same data. All // other values are equal if they are identical objects. public static bool Equals(Obj a, Obj b) { if (a == b) { return(true); } if (a.Type != b.Type) { return(false); } if (a.Type == ObjType.Num) { return(a.Num == b.Num); } // If we get here, it's only possible for two heap-allocated immutable objects // to be equal. if (a.Type != ObjType.Obj) { return(true); } // Must be the same type. if (a.GetType() != b.GetType()) { return(false); } ObjString aString = a as ObjString; if (aString != null) { ObjString bString = (ObjString)b; return(aString.Str.Equals(bString.Str)); } ObjRange aRange = a as ObjRange; if (aRange != null) { ObjRange bRange = (ObjRange)b; return(ObjRange.Equals(aRange, bRange)); } // All other types are only equal if they are same, which they aren't if // we get here. return(false); }
static bool range_from_numbers(WrenVM vm, Obj start, Obj end, bool inclusive, out Obj range) { if (end.Type == ObjType.Num) { double from = start.Num; double to = end.Num; range = new ObjRange(from, to, inclusive); return true; } vm.Fiber.Error = Obj.MakeString("Right hand side of range must be a number."); range = null; return false; }
public static bool Equals(ObjRange a, ObjRange b) { return(a != null && b != null && a.From == b.From && a.To == b.To && a.IsInclusive == b.IsInclusive); }
public static bool Equals(ObjRange a, ObjRange b) { return a != null && b != null && a.From == b.From && a.To == b.To && a.IsInclusive == b.IsInclusive; }