aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs
diff options
context:
space:
mode:
authorUbitUmarov2019-10-18 14:16:37 +0100
committerUbitUmarov2019-10-18 14:16:37 +0100
commitf09a18a7a897994aaed7f7fc4ce751ff7871bb27 (patch)
treeb935237a8ca1affbff68de70a7b7baacf6b74821 /OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs
parentadd LSL_Integer osIsNotValidNumber(LSL_Float v) (diff)
downloadopensim-SC-f09a18a7a897994aaed7f7fc4ce751ff7871bb27.zip
opensim-SC-f09a18a7a897994aaed7f7fc4ce751ff7871bb27.tar.gz
opensim-SC-f09a18a7a897994aaed7f7fc4ce751ff7871bb27.tar.bz2
opensim-SC-f09a18a7a897994aaed7f7fc4ce751ff7871bb27.tar.xz
Yengine: Also error on division by Zero
Diffstat (limited to 'OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs63
1 files changed, 57 insertions, 6 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs
index f5e91f7..89f4ee3 100644
--- a/OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs
+++ b/OpenSim/Region/ScriptEngine/YEngine/MMRScriptBinOpStr.cs
@@ -34,6 +34,7 @@ using System.Reflection;
34using System.Reflection.Emit; 34using System.Reflection.Emit;
35using System.Text; 35using System.Text;
36using System.Text.RegularExpressions; 36using System.Text.RegularExpressions;
37using OpenSim.Region.ScriptEngine.Shared;
37 38
38using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat; 39using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
39using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger; 40using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
@@ -120,6 +121,10 @@ namespace OpenSim.Region.ScriptEngine.Yengine
120 private static MethodInfo infoMethVecDivInt = GetBinOpsMethod("MethVecDivInt", new Type[] { typeof(LSL_Vector), typeof(int) }); 121 private static MethodInfo infoMethVecDivInt = GetBinOpsMethod("MethVecDivInt", new Type[] { typeof(LSL_Vector), typeof(int) });
121 private static MethodInfo infoMethVecMulRot = GetBinOpsMethod("MethVecMulRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) }); 122 private static MethodInfo infoMethVecMulRot = GetBinOpsMethod("MethVecMulRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) });
122 private static MethodInfo infoMethVecDivRot = GetBinOpsMethod("MethVecDivRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) }); 123 private static MethodInfo infoMethVecDivRot = GetBinOpsMethod("MethVecDivRot", new Type[] { typeof(LSL_Vector), typeof(LSL_Rotation) });
124 private static MethodInfo infoMethDoubleDivDouble = GetBinOpsMethod("MethDoubleDivDouble", new Type[] { typeof(Double), typeof(Double) });
125 private static MethodInfo infoMethLongDivLong = GetBinOpsMethod("MethLongDivLong", new Type[] { typeof(long), typeof(long) });
126 private static MethodInfo infoMethDoubleModDouble = GetBinOpsMethod("MethDoubleModDouble", new Type[] { typeof(Double), typeof(Double) });
127 private static MethodInfo infoMethLongModLong = GetBinOpsMethod("MethLongModLong", new Type[] { typeof(long), typeof(long) });
123 128
124 private static MethodInfo GetBinOpsMethod(string name, Type[] types) 129 private static MethodInfo GetBinOpsMethod(string name, Type[] types)
125 { 130 {
@@ -589,7 +594,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
589 result.PopPre(scg, errorAt); 594 result.PopPre(scg, errorAt);
590 left.PushVal(scg, errorAt, tokenTypeFloat); 595 left.PushVal(scg, errorAt, tokenTypeFloat);
591 right.PushVal(scg, errorAt, tokenTypeFloat); 596 right.PushVal(scg, errorAt, tokenTypeFloat);
592 scg.ilGen.Emit(errorAt, OpCodes.Div); 597 //scg.ilGen.Emit(errorAt, OpCodes.Div);
598 scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleDivDouble);
593 result.PopPost(scg, errorAt, tokenTypeFloat); 599 result.PopPost(scg, errorAt, tokenTypeFloat);
594 } 600 }
595 601
@@ -598,7 +604,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
598 result.PopPre(scg, errorAt); 604 result.PopPre(scg, errorAt);
599 left.PushVal(scg, errorAt, tokenTypeFloat); 605 left.PushVal(scg, errorAt, tokenTypeFloat);
600 right.PushVal(scg, errorAt, tokenTypeFloat); 606 right.PushVal(scg, errorAt, tokenTypeFloat);
601 scg.ilGen.Emit(errorAt, OpCodes.Rem); 607 //scg.ilGen.Emit(errorAt, OpCodes.Rem);
608 scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleModDouble);
602 result.PopPost(scg, errorAt, tokenTypeFloat); 609 result.PopPost(scg, errorAt, tokenTypeFloat);
603 } 610 }
604 611
@@ -694,7 +701,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
694 result.PopPre(scg, errorAt); 701 result.PopPre(scg, errorAt);
695 left.PushVal(scg, errorAt, tokenTypeFloat); 702 left.PushVal(scg, errorAt, tokenTypeFloat);
696 right.PushVal(scg, errorAt, tokenTypeFloat); 703 right.PushVal(scg, errorAt, tokenTypeFloat);
697 scg.ilGen.Emit(errorAt, OpCodes.Div); 704 //scg.ilGen.Emit(errorAt, OpCodes.Div);
705 scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleDivDouble);
698 result.PopPost(scg, errorAt, tokenTypeFloat); 706 result.PopPost(scg, errorAt, tokenTypeFloat);
699 } 707 }
700 708
@@ -703,7 +711,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
703 result.PopPre(scg, errorAt); 711 result.PopPre(scg, errorAt);
704 left.PushVal(scg, errorAt, tokenTypeFloat); 712 left.PushVal(scg, errorAt, tokenTypeFloat);
705 right.PushVal(scg, errorAt, tokenTypeFloat); 713 right.PushVal(scg, errorAt, tokenTypeFloat);
706 scg.ilGen.Emit(errorAt, OpCodes.Rem); 714 //scg.ilGen.Emit(errorAt, OpCodes.Rem);
715 scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethDoubleModDouble);
707 result.PopPost(scg, errorAt, tokenTypeFloat); 716 result.PopPost(scg, errorAt, tokenTypeFloat);
708 } 717 }
709 718
@@ -917,7 +926,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
917 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8); 926 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
918 right.PushVal(scg, errorAt, tokenTypeInt); 927 right.PushVal(scg, errorAt, tokenTypeInt);
919 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8); 928 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
920 scg.ilGen.Emit(errorAt, OpCodes.Div); 929 //scg.ilGen.Emit(errorAt, OpCodes.Div);
930 scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethLongDivLong);
921 scg.ilGen.Emit(errorAt, OpCodes.Conv_I4); 931 scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
922 result.PopPost(scg, errorAt, tokenTypeInt); 932 result.PopPost(scg, errorAt, tokenTypeInt);
923 } 933 }
@@ -931,7 +941,8 @@ namespace OpenSim.Region.ScriptEngine.Yengine
931 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8); 941 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
932 right.PushVal(scg, errorAt, tokenTypeInt); 942 right.PushVal(scg, errorAt, tokenTypeInt);
933 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8); 943 scg.ilGen.Emit(errorAt, OpCodes.Conv_I8);
934 scg.ilGen.Emit(errorAt, OpCodes.Rem); 944 //scg.ilGen.Emit(errorAt, OpCodes.Rem);
945 scg.ilGen.Emit(errorAt, OpCodes.Call, infoMethLongModLong);
935 scg.ilGen.Emit(errorAt, OpCodes.Conv_I4); 946 scg.ilGen.Emit(errorAt, OpCodes.Conv_I4);
936 result.PopPost(scg, errorAt, tokenTypeInt); 947 result.PopPost(scg, errorAt, tokenTypeInt);
937 } 948 }
@@ -1573,5 +1584,45 @@ namespace OpenSim.Region.ScriptEngine.Yengine
1573 { 1584 {
1574 return left / right; 1585 return left / right;
1575 } 1586 }
1587
1588 public static double MethDoubleDivDouble(double a, double b)
1589 {
1590 double r = a / b;
1591 if (double.IsNaN(r) || double.IsInfinity(r))
1592 throw new ScriptException("Division by Zero");
1593 return r;
1594 }
1595
1596 public static long MethLongDivLong(long a, long b)
1597 {
1598 try
1599 {
1600 return a / b;
1601 }
1602 catch (DivideByZeroException)
1603 {
1604 throw new ScriptException("Division by Zero");
1605 }
1606 }
1607
1608 public static double MethDoubleModDouble(double a, double b)
1609 {
1610 double r = a % b;
1611 if (double.IsNaN(r) || double.IsInfinity(r))
1612 throw new ScriptException("Division by Zero");
1613 return r;
1614 }
1615
1616 public static long MethLongModLong(long a, long b)
1617 {
1618 try
1619 {
1620 return a % b;
1621 }
1622 catch (DivideByZeroException)
1623 {
1624 throw new ScriptException("Division by Zero");
1625 }
1626 }
1576 } 1627 }
1577} 1628}