using Qrakhen.Qamp.Core.Logging; namespace Qrakhen.Qamp.Core.Values; public static class ValueOperation { private static ILogger _logger = LoggerService.Get(nameof(ValueOperation)); public static Value Not(Value v) { _logger.Method($"{v}"); Assert.NotVoid(v); ulong inner = v.Unsigned; return new Value(inner == 0); } public static Value Add(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); bool convert = a.Type != b.Type; // meh, lets make c# do that for us for now return new Value(a.Dynamic + b.Dynamic); } public static Value Subtract(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); return new Value(a.Dynamic - b.Dynamic); } public static Value Divide(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.NotZero(b); return new Value(a.Dynamic / b.Dynamic); } public static Value Modulo(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.NotZero(b); return new Value(a.Dynamic % b.Dynamic); } public static Value Multiply(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); return new Value(a.Dynamic * b.Dynamic); } public static Value Negate(Value a) { _logger.Method($"{a}"); Assert.NotVoid(a); Assert.IsPrimitive(a); return new Value(-a.Dynamic); } public static Value BitwiseOr(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.IsInteger(a, b); return new Value(a.Dynamic | b.Dynamic); } public static Value BitwiseAnd(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.IsInteger(a, b); return new Value(a.Dynamic & b.Dynamic); } public static Value BitwiseXor(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.IsInteger(a, b); return new Value(a.Dynamic ^ b.Dynamic); } public static Value BitwiseLeft(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.IsInteger(a, b); return new Value(a.Dynamic << (int)(b.Dynamic ?? 0)); } public static Value BitwiseRight(Value a, Value b) { _logger.Method($"{a}, {b}"); Assert.NotVoid(a, b); Assert.IsPrimitive(a, b); Assert.IsInteger(a, b); return new Value(a.Dynamic >> (int)(b.Dynamic ?? 0)); } public static Value BitwiseInvert(Value a) { _logger.Method($"{a}"); Assert.NotVoid(a); Assert.IsPrimitive(a); Assert.IsInteger(a); return new Value(~a.Dynamic); } }