From 4f062593990fcafd15b0ece64abeb430073e0379 Mon Sep 17 00:00:00 2001 From: Mr-Rm Date: Sun, 31 May 2026 15:32:09 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D1=81=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=81=20=D0=B4=D0=B0=D1=82=D0=BE=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/OneScript.Native/Runtime/DynamicOperations.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/OneScript.Native/Runtime/DynamicOperations.cs b/src/OneScript.Native/Runtime/DynamicOperations.cs index 4cfc523a0..2307a2570 100644 --- a/src/OneScript.Native/Runtime/DynamicOperations.cs +++ b/src/OneScript.Native/Runtime/DynamicOperations.cs @@ -28,10 +28,8 @@ public static BslValue Add(BslValue left, BslValue right) if (left is BslStringValue str) return BslStringValue.Create(str + right); - if (left is BslDateValue bslDate && right is BslNumericValue num) - { - return BslDateValue.Create(bslDate - (decimal) num); - } + if (left is BslDateValue bslDate) + return BslDateValue.Create(bslDate + (decimal)right); var dLeft = (decimal)left; var dRight = (decimal)right; From 7f3a4dc4162270b149c313691f90c008eb1e4c02 Mon Sep 17 00:00:00 2001 From: Mr-Rm Date: Sun, 31 May 2026 15:41:25 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=B2=D1=8B=D1=87=D0=B8=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=B7=20=D0=B4=D0=B0=D1=82=D1=8B=20=D1=81?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=D0=B2=D0=B5=D0=B4=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D1=82=D0=B8=D0=BF=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/DynamicOperations.cs | 37 ++++++------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/src/OneScript.Native/Runtime/DynamicOperations.cs b/src/OneScript.Native/Runtime/DynamicOperations.cs index 2307a2570..a9966086f 100644 --- a/src/OneScript.Native/Runtime/DynamicOperations.cs +++ b/src/OneScript.Native/Runtime/DynamicOperations.cs @@ -33,40 +33,25 @@ public static BslValue Add(BslValue left, BslValue right) var dLeft = (decimal)left; var dRight = (decimal)right; - return BslNumericValue.Create(dLeft + dRight); + return BslNumericValue.Create(dLeft + dRight); // or throw ConvertToNumberException(); } public static BslValue Subtract(BslValue left, BslValue right) { if (left is BslNumericValue num) + return BslNumericValue.Create(num - (decimal)right); + + if (left is BslDateValue date) { - var result = num - (decimal)right; - return BslNumericValue.Create(result); - } - else if (left is BslDateValue date) - { - switch (right) - { - case BslNumericValue numRight: - { - var result = date - numRight; - return BslDateValue.Create(result); - } - case BslDateValue dateRight: - { - var result = date - dateRight; - return BslNumericValue.Create(result); - } - } - } - else - { - var dLeft = (decimal)left; - var dRight = (decimal)right; - return BslNumericValue.Create(dLeft - dRight); + if (right is BslDateValue dateRight) + return BslNumericValue.Create(date - dateRight); + + return BslDateValue.Create(date - (decimal)right); } - throw BslExceptions.ConvertToNumberException(); + var dLeft = (decimal)left; + var dRight = (decimal)right; + return BslNumericValue.Create(dLeft - dRight); // or throw ConvertToNumberException(); } public static bool ToBoolean(BslValue value) From 09a504474003e4a0b5644ec5410b723b10b72e53 Mon Sep 17 00:00:00 2001 From: Mr-Rm Date: Sun, 31 May 2026 16:05:39 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3=20=D0=BC=D0=B5=D0=BB=D0=BA=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/DynamicOperations.cs | 110 ++++++++---------- 1 file changed, 46 insertions(+), 64 deletions(-) diff --git a/src/OneScript.Native/Runtime/DynamicOperations.cs b/src/OneScript.Native/Runtime/DynamicOperations.cs index a9966086f..13289a4c2 100644 --- a/src/OneScript.Native/Runtime/DynamicOperations.cs +++ b/src/OneScript.Native/Runtime/DynamicOperations.cs @@ -52,27 +52,15 @@ public static BslValue Subtract(BslValue left, BslValue right) var dLeft = (decimal)left; var dRight = (decimal)right; return BslNumericValue.Create(dLeft - dRight); // or throw ConvertToNumberException(); - } - - public static bool ToBoolean(BslValue value) - { - return (bool)value; - } - - public static decimal ToNumber(BslValue value) - { - return (decimal)value; - } - - public static DateTime ToDate(BslValue value) - { - return (DateTime)value; - } - - public static string ToString(BslValue value) - { - return value.ToString(); - } + } + + public static bool ToBoolean(BslValue value) => (bool)value; + + public static decimal ToNumber(BslValue value) => (decimal)value; + + public static DateTime ToDate(BslValue value) => (DateTime)value; + + public static string ToString(BslValue value) => value.ToString(); // FIXME: тут не должно быть Null, но из-за несовершенства мира они тут бывают. Когда задолбает - надо починить и убрать отсюда проверки на null public static bool Equality(BslValue left, BslValue right) @@ -99,32 +87,32 @@ public static int Comparison(BslValue left, BslValue right) } public static BslValue WrapClrObjectToValue(object value) - { + { return value switch { - null => BslUndefinedValue.Instance, - string s => BslStringValue.Create(s), - decimal d => BslNumericValue.Create(d), - - int n => BslNumericValue.Create(n), - uint n => BslNumericValue.Create(n), - short n => BslNumericValue.Create(n), - ushort n => BslNumericValue.Create(n), - byte n => BslNumericValue.Create(n), - sbyte n => BslNumericValue.Create(n), - long l => BslNumericValue.Create(l), - ulong l => BslNumericValue.Create(l), - - double dbl => BslNumericValue.Create((decimal) dbl), - bool boolean => BslBooleanValue.Create(boolean), - DateTime date => BslDateValue.Create(date), - BslValue bslValue => bslValue, - _ => throw new TypeConversionException(new BilingualString( - $"Невозможно преобразовать {value.GetType()} в тип {nameof(BslValue)}", - $"Can't Convert {value.GetType()} to {nameof(BslValue)}")) - }; - } - + null => BslUndefinedValue.Instance, + string s => BslStringValue.Create(s), + decimal d => BslNumericValue.Create(d), + + int n => BslNumericValue.Create(n), + uint n => BslNumericValue.Create(n), + short n => BslNumericValue.Create(n), + ushort n => BslNumericValue.Create(n), + byte n => BslNumericValue.Create(n), + sbyte n => BslNumericValue.Create(n), + long l => BslNumericValue.Create(l), + ulong l => BslNumericValue.Create(l), + + double dbl => BslNumericValue.Create((decimal) dbl), + bool boolean => BslBooleanValue.Create(boolean), + DateTime date => BslDateValue.Create(date), + BslValue bslValue => bslValue, + _ => throw new TypeConversionException(new BilingualString( + $"Невозможно преобразовать {value.GetType()} в тип {nameof(BslValue)}", + $"Can't Convert {value.GetType()} to {nameof(BslValue)}")) + }; + } + public static BslValue ConstructorCall(ITypeManager typeManager, IServiceContainer services, string typeName, IBslProcess process, BslValue[] args) { var type = typeManager.GetTypeByName(typeName); @@ -138,39 +126,33 @@ public static BslValue ConstructorCall(ITypeManager typeManager, IServiceContain }; return (BslValue) factory.Activate(context, args.Cast().ToArray()); - } - - // TODO: Сделать прямой маппинг на статические фабрики-методы, а не через Factory.Activate - public static T StrictConstructorCall(ITypeManager typeManager, IServiceContainer services, string typeName, IBslProcess process, BslValue[] args) + } + + // TODO: Сделать прямой маппинг на статические фабрики-методы, а не через Factory.Activate + public static T StrictConstructorCall(ITypeManager typeManager, IServiceContainer services, + string typeName, IBslProcess process, BslValue[] args) where T : BslValue - { - return (T) ConstructorCall(typeManager, services, typeName, process, args); - } + => (T)ConstructorCall(typeManager, services, typeName, process, args); public static BslObjectValue GetExceptionInfo(IExceptionInfoFactory factory, Exception e) - { - return factory.GetExceptionInfo(e); - } + => factory.GetExceptionInfo(e); public static BslTypeValue GetTypeByName(ITypeManager manager, string name) - { - var foundType = manager.GetTypeByName(name); - return new BslTypeValue(foundType); - } + => new(manager.GetTypeByName(name)); public static BslValue GetIndexedValue(object target, BslValue index) { - if (!(target is IRuntimeContextInstance context) || !context.IsIndexed) + if (target is not IRuntimeContextInstance context || !context.IsIndexed) { throw RuntimeException.IndexedAccessIsNotSupportedException(); } - return (BslValue)context.GetIndexedValue((IValue)index); + return (BslValue)context.GetIndexedValue(index); } public static void SetIndexedValue(object target, BslValue index, BslValue value) { - if (!(target is IRuntimeContextInstance context) || !context.IsIndexed) + if (target is not IRuntimeContextInstance context || !context.IsIndexed) { throw RuntimeException.IndexedAccessIsNotSupportedException(); } @@ -180,7 +162,7 @@ public static void SetIndexedValue(object target, BslValue index, BslValue value public static BslValue GetPropertyValue(object target, string propertyName) { - if (!(target is IRuntimeContextInstance context)) + if (target is not IRuntimeContextInstance context) throw BslExceptions.ValueIsNotObjectException(); var propIndex = context.GetPropertyNumber(propertyName); @@ -189,7 +171,7 @@ public static BslValue GetPropertyValue(object target, string propertyName) public static BslValue TryCallContextMethod(BslValue instance, string methodName, IBslProcess process, BslValue[] arguments) { - if (!(instance is IRuntimeContextInstance context)) + if (instance is not IRuntimeContextInstance context) throw BslExceptions.ValueIsNotObjectException(); return CallContextMethod(context, methodName, process, arguments);