[interpreter] Size reduction
authorMarek Safar <marek.safar@gmail.com>
Tue, 4 Mar 2014 18:40:25 +0000 (19:40 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 4 Mar 2014 18:40:25 +0000 (19:40 +0100)
26 files changed:
mcs/class/Mono.Dynamic.Interpreter/Makefile
mcs/class/Mono.Dynamic.Interpreter/Mono.Dynamic.Interpreter.dll.sources
mcs/class/dlr/Runtime/Microsoft.Dynamic/Ast/ConstantExpression.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Generation/CompilerHelpers.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AddInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AndInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AritmeticInstruction.cs [new file with mode: 0644]
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ComparisonInstruction.cs [new file with mode: 0644]
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/EqualInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/GreaterThanInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/GreaterThanOrEqualInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionFactory.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/LessThanInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/LessThanOrEqualInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ModInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/MulInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NotEqualInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/OrInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShlInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShrInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/SubInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/XorInstruction.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Math/Complex64.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Utils/MathUtils.cs
mcs/class/dlr/Runtime/Microsoft.Dynamic/Utils/ReflectionUtils.cs
mcs/class/dlr/Runtime/Microsoft.Scripting/PlatformAdaptationLayer.cs

index bb8851ac6a4e79efea3f2283249f3f2cf1ab40a7..e72e6cf66c220d373d747a684062294b0ff44cbb 100644 (file)
@@ -4,8 +4,8 @@ include ../../build/rules.make
 
 LIBRARY = Mono.Dynamic.Interpreter.dll
 
-LIB_MCS_FLAGS = -r:System.dll -r:System.Core.dll -r:System.Numerics.dll \
-       -d:FEATURE_CORE_DLR,FEATURE_NUMERICS,FEATURE_DBNULL,FEATURE_DEFAULT_PARAMETER_VALUE,FEATURE_GET_TYPE_INFO,FEATURE_VARIANCE,FEATURE_SERIALIZATION,CLR45 \
+LIB_MCS_FLAGS = -r:System.dll -r:System.Core.dll \
+       -d:FEATURE_CORE_DLR,FEATURE_DBNULL,FEATURE_DEFAULT_PARAMETER_VALUE,FEATURE_GET_TYPE_INFO,FEATURE_VARIANCE,FEATURE_SERIALIZATION,CLR45 \
        -d:MONO_INTERPRETER \
        -delaysign -keyfile:../mono.pub
 
index 80cfc9ef1637b5fdc8ef428d0568fef8d8ca193f..e56c1f3f40be4f161bb36f04e48b8cbda3db8d41 100644 (file)
@@ -42,8 +42,10 @@ Assembly/AssemblyInfo.cs
 
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AddInstruction.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AndInstruction.cs
+../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AritmeticInstruction.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ArrayOperations.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.cs
+../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ComparisonInstruction.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ConstantInstruction.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/CallInstruction.Generated.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ControlFlowInstructions.cs
@@ -76,7 +78,6 @@ Assembly/AssemblyInfo.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/TypeOperations.cs
 ../dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/XorInstruction.cs
 
-../dlr/Runtime/Microsoft.Dynamic/Math/BigIntegerV4.cs
 ../dlr/Runtime/Microsoft.Dynamic/Math/Complex64.cs
 
 ../dlr/Runtime/Microsoft.Dynamic/Runtime/ArgumentArray.cs
index 7c75d149125f683119147e5091eea5e019a27623..881f0a3351ccab77eb2c5e67ccb1c0f14c6bcb06 100644 (file)
@@ -61,18 +61,24 @@ namespace Microsoft.Scripting.Ast {
                 return NullLiteral;
             }
 
+#if !MONO_INTERPRETER
             BigInteger bi = value as BigInteger;
             if ((object)bi != null) {
                 return BigIntegerConstant(bi);
+#endif
+
 #if FEATURE_NUMERICS
-            } else if (value is BigInt) {
+            if (value is BigInt)
                 return BigIntConstant((BigInt)value);
-            } else if (value is Complex) {
+            if (value is Complex)
                 return ComplexConstant((Complex)value);
 #endif
-            } else if (value is Complex64) {
+
+#if !MONO_INTERPRETER
+            if (value is Complex64)
                 return Complex64Constant((Complex64)value);
-            } else if (value is Type) {
+#endif
+            if (value is Type) {
                 return Expression.Constant(value, typeof(Type));
             } else if (value is ConstructorInfo) {
                 return Expression.Constant(value, typeof(ConstructorInfo));
@@ -112,6 +118,7 @@ namespace Microsoft.Scripting.Ast {
             }
         }
 
+#if !MONO_INTERPRETER
         private static Expression BigIntegerConstant(BigInteger value) {
             int ival;
             if (value.AsInt32(out ival)) {
@@ -167,7 +174,7 @@ namespace Microsoft.Scripting.Ast {
             );
 #endif
         }
-
+#endif
         private static Expression CreateArray<T>(T[] array) {
             // TODO: could we use blobs?
             Expression[] init = new Expression[array.Length];
@@ -201,6 +208,7 @@ namespace Microsoft.Scripting.Ast {
         }
 #endif
 
+#if !MONO_INTERPRETER
         private static Expression Complex64Constant(Complex64 value) {
             if (value.Real != 0.0) {
                 if (value.Imag != 0.0) {
@@ -222,5 +230,6 @@ namespace Microsoft.Scripting.Ast {
                 );
             }
         }
+#endif
     }
 }
index 919d1b5b5e5c2ce639cc7c6c8b054813af95f172..5f3cba2ff6e6ea837d0f8b2c2c9d0141a11937c4 100644 (file)
@@ -29,6 +29,7 @@ using System.Diagnostics;
 using System.Dynamic;
 using System.Linq;
 using System.Reflection;
+using System.Threading;
 #if FEATURE_REFEMIT
 using System.Reflection.Emit;
 #endif
@@ -47,8 +48,8 @@ namespace Microsoft.Scripting.Generation {
     public delegate void ActionRef<T0, T1>(ref T0 arg0, ref T1 arg1);
 
     public static class CompilerHelpers {
-        public static readonly MethodAttributes PublicStatic = MethodAttributes.Public | MethodAttributes.Static;
-        private static readonly MethodInfo _CreateInstanceMethod = typeof(ScriptingRuntimeHelpers).GetMethod("CreateInstance");
+               public const MethodAttributes PublicStatic = MethodAttributes.Public | MethodAttributes.Static;
+               private static MethodInfo _CreateInstanceMethod;
 
         private static int _Counter; // for generating unique names for lambda methods
 
@@ -110,7 +111,10 @@ namespace Microsoft.Scripting.Generation {
             if (mb.IsGenericMethod) {
                 MethodInfo mi = mb as MethodInfo;
 
-                if (mi.GetGenericMethodDefinition() == _CreateInstanceMethod) {
+                               if (_CreateInstanceMethod == null)
+                                       Interlocked.CompareExchange (ref _CreateInstanceMethod, typeof(ScriptingRuntimeHelpers).GetMethod ("CreateInstance"), null);
+
+                               if (mi.GetGenericMethodDefinition() == _CreateInstanceMethod) {
                     return true;
                 }
             }
@@ -875,7 +879,7 @@ namespace Microsoft.Scripting.Generation {
                 )
             );
         }
-
+#if !MONO_INTERPRETER
         #region Factories
 #if !FEATURE_NUMERICS
         [CLSCompliant(false)]
@@ -902,5 +906,6 @@ namespace Microsoft.Scripting.Generation {
 
 #endif
         #endregion
+#endif
     }
 }
index 3846e4d215ffefff7b4f919cce824e27e458dcd6..1cdb14a387c3adc0ca89ada7206c4ba0bd132501 100644 (file)
@@ -19,92 +19,66 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class AddInstruction : Instruction {
-        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
+    internal abstract class AddInstruction : AritmeticInstruction {
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
+        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
         private AddInstruction() {
         }
 
         internal sealed class AddInt32 : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l + (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l + (Int32)r));
             }
         }
 
         internal sealed class AddInt16 : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)unchecked((Int16)l + (Int16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)unchecked((Int16)l + (Int16)r);
             }
         }
 
         internal sealed class AddInt64 : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)unchecked((Int64)l + (Int64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)unchecked((Int64)l + (Int64)r);
             }
         }
 
         internal sealed class AddUInt16 : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)unchecked((UInt16)l + (UInt16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)unchecked((UInt16)l + (UInt16)r);
             }
         }
 
         internal sealed class AddUInt32 : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)unchecked((UInt32)l + (UInt32)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)unchecked((UInt32)l + (UInt32)r);
             }
         }
 
         internal sealed class AddUInt64 : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)unchecked((UInt64)l + (UInt64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)unchecked((UInt64)l + (UInt64)r);
             }
         }
 
         internal sealed class AddSingle : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l + (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l + (Single)r);
             }
         }
 
         internal sealed class AddDouble : AddInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l + (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l + (Double)r;
             }
         }
 
@@ -130,92 +104,66 @@ namespace Microsoft.Scripting.Interpreter {
         }
     }
 
-    internal abstract class AddOvfInstruction : Instruction {
-        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
+    internal abstract class AddOvfInstruction : AritmeticInstruction {
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
+        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
         private AddOvfInstruction() {
         }
 
         internal sealed class AddOvfInt32 : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l + (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l + (Int32)r));
             }
         }
 
         internal sealed class AddOvfInt16 : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((Int16)((Int16)l + (Int16)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((Int16)((Int16)l + (Int16)r));
             }
         }
 
         internal sealed class AddOvfInt64 : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((Int64)((Int64)l + (Int64)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((Int64)((Int64)l + (Int64)r));
             }
         }
 
         internal sealed class AddOvfUInt16 : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt16)((UInt16)l + (UInt16)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt16)((UInt16)l + (UInt16)r));
             }
         }
 
         internal sealed class AddOvfUInt32 : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt32)((UInt32)l + (UInt32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt32)((UInt32)l + (UInt32)r));
             }
         }
 
         internal sealed class AddOvfUInt64 : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt64)((UInt64)l + (UInt64)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt64)((UInt64)l + (UInt64)r));
             }
         }
 
         internal sealed class AddOvfSingle : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l + (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l + (Single)r);
             }
         }
 
         internal sealed class AddOvfDouble : AddOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l + (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l + (Double)r;
             }
         }
 
index 2b423f581f0d3f421958d380fb7bea6a893bc6d8..b8f21ccca21c4c8ab41cde7b6c7b4fb5e00fba17 100644 (file)
@@ -1,5 +1,5 @@
 ï»¿// 
-// AndbInstruction.cs:
+// AndInstruction.cs:
 //
 // Authors: Marek Safar (marek.safar@gmail.com)
 //     
@@ -32,153 +32,108 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class AndInstruction : Instruction {
+    internal abstract class AndInstruction : AritmeticInstruction {
         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
         private static Instruction _Int16Lifted, _Int32Lifted, _Int64Lifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _BooleanLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private AndInstruction() {
         }
 
         internal sealed class AndInt32 : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32)frame.Data[frame.StackIndex - 2];
-                var r = (Int32)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject((Int32)l & (Int32)r);
             }
         }
 
         internal sealed class AndInt16 : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16)frame.Data[frame.StackIndex - 2];
-                var r = (Int16)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)((Int16)l & (Int16)r);
             }
         }
 
         internal sealed class AndInt64 : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64)frame.Data[frame.StackIndex - 2];
-                var r = (Int64)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)((Int64)l & (Int64)r);
             }
         }
 
         internal sealed class AndUInt16 : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16)frame.Data[frame.StackIndex - 2];
-                var r = (UInt16)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)((UInt16)l & (UInt16)r);
             }
         }
 
         internal sealed class AndUInt32 : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32)frame.Data[frame.StackIndex - 2];
-                var r = (UInt32)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)((UInt32)l & (UInt32)r);
             }
         }
 
         internal sealed class AndUInt64 : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64)frame.Data[frame.StackIndex - 2];
-                var r = (UInt64)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)((UInt64)l & (UInt64)r);
             }
         }
 
         internal sealed class AndBoolean : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Boolean)frame.Data[frame.StackIndex - 2];
-                var r = (Boolean)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Boolean)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Boolean)((Boolean)l & (Boolean)r);
             }
         }
 
         internal sealed class AndInt32Lifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((Int32?)l & (Int32?)r);
             }
         }
 
         internal sealed class AndInt16Lifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int16?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16?)((Int16?)l & (Int16?)r);
             }
         }
 
         internal sealed class AndInt64Lifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int64?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64?)((Int64?)l & (Int64?)r);
             }
         }
 
         internal sealed class AndUInt16Lifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt16?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16?)((UInt16?)l & (UInt16?)r);
             }
         }
 
         internal sealed class AndUInt32Lifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32?)((UInt32?)l & (UInt32?)r);
             }
         }
 
         internal sealed class AndUInt64Lifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt64?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64?)((UInt64?)l & (UInt64?)r);
             }
         }
 
         internal sealed class AndBooleanLifted : AndInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Boolean?)frame.Data[frame.StackIndex - 2];
-                var r = (Boolean?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Boolean?)(l & r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return ((Boolean?)l & (Boolean?)r);
             }
         }
 
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AritmeticInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AritmeticInstruction.cs
new file mode 100644 (file)
index 0000000..03e6694
--- /dev/null
@@ -0,0 +1,50 @@
+// 
+// AritmeticInstruction.cs:
+//
+// Authors: Marek Safar (marek.safar@gmail.com)
+//     
+// Copyright 2014 Xamarin Inc
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//
+
+using System;
+using System.Diagnostics;
+using Microsoft.Scripting.Runtime;
+using Microsoft.Scripting.Utils;
+
+namespace Microsoft.Scripting.Interpreter {
+    internal abstract class AritmeticInstruction : Instruction {
+
+        public override int ConsumedStack { get { return 2; } }
+        public override int ProducedStack { get { return 1; } }
+
+        protected abstract object Calculate (object l, object r);
+
+        public override int Run(InterpretedFrame frame) {
+            object l = frame.Data[frame.StackIndex - 2];
+            object r = frame.Data[frame.StackIndex - 1];
+            frame.Data[frame.StackIndex - 2] = Calculate (l, r);
+            frame.StackIndex--;
+            return +1;
+        }
+    }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ComparisonInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ComparisonInstruction.cs
new file mode 100644 (file)
index 0000000..622e860
--- /dev/null
@@ -0,0 +1,50 @@
+// 
+// AritmeticInstruction.cs:
+//
+// Authors: Marek Safar (marek.safar@gmail.com)
+//     
+// Copyright 2014 Xamarin Inc
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+//
+
+using System;
+using System.Diagnostics;
+using Microsoft.Scripting.Runtime;
+using Microsoft.Scripting.Utils;
+
+namespace Microsoft.Scripting.Interpreter {
+    internal abstract class ComparisonInstruction : AritmeticInstruction {
+
+        protected bool LiftedToNull { get; set; }
+
+        protected override object Calculate (object l, object r)
+        {
+            if (l == null || r == null)
+                return DoNullComparison (l, r);
+
+            return DoCalculate (l, r);
+        }
+
+        protected abstract object DoNullComparison (object l, object r);
+        protected abstract object DoCalculate (object l, object r);
+    }
+}
index 38e904d3eaeabdd218d59fc34c2b2fc0cbe86237..cc89ee3d444c259e116c1b3d8b03847baf323a4c 100644 (file)
@@ -22,191 +22,113 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class EqualInstruction : Instruction {
+    internal abstract class EqualInstruction : ComparisonInstruction {
         // Perf: EqualityComparer<T> but is 3/2 to 2 times slower.
         private static Instruction _Reference, _Boolean, _SByte, _Int16, _Char, _Int32, _Int64, _Byte, _UInt16, _UInt32, _UInt64, _Single, _Double;
         private static Instruction _BooleanLifted, _SByteLifted, _Int16Lifted, _CharLifted, _Int32Lifted, _Int64Lifted,
             _ByteLifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _SingleLifted, _DoubleLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private EqualInstruction() {
         }
 
-        public bool LiftedToNull { get; set; }
+        protected override object DoNullComparison (object l, object r)
+        {
+            return LiftedToNull ? (object) null : (object) l == r;
+        }
 
         internal sealed class EqualBoolean : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Boolean)l == (Boolean)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Boolean)l == (Boolean)r;
             }
         }
 
         internal sealed class EqualSByte : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (SByte)l == (SByte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (SByte)l == (SByte)r;
             }
         }
 
         internal sealed class EqualInt16 : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int16)l == (Int16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int16)l == (Int16)r;
             }
         }
 
         internal sealed class EqualChar : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Char)l == (Char)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Char)l == (Char)r;
             }
         }
 
         internal sealed class EqualInt32 : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int32)l == (Int32)r;
-
-                frame.StackIndex--;
-                return +1;            }
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int32)l == (Int32)r;
+            }
         }
 
         internal sealed class EqualInt64 : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int64)l == (Int64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int64)l == (Int64)r;
             }
         }
 
         internal sealed class EqualByte : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Byte)l == (Byte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Byte)l == (Byte)r;
             }
         }
 
         internal sealed class EqualUInt16 : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt16)l == (UInt16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt16)l == (UInt16)r;
             }
         }
 
         internal sealed class EqualUInt32 : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt32)l == (UInt32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt32)l == (UInt32)r;
             }
         }
 
         internal sealed class EqualUInt64 : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt64)l == (UInt64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt64)l == (UInt64)r;
             }
         }
 
         internal sealed class EqualSingle : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Single)l == (Single)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Single)l == (Single)r;
             }
         }
 
         internal sealed class EqualDouble : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l == r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Double)l == (Double)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Double)l == (Double)r;
             }
         }
 
         internal sealed class EqualReference : EqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                frame.Push(frame.Pop() == frame.Pop());
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return l == r;
+            }
+
+            protected override object DoCalculate (object l, object r)
+            {
+                throw Assert.Unreachable;
             }
         }
 
index 8849613fd51f1fbd9efc07e0b7799a418ebf4e98..48d69a85ae6c565005d6221807071190dd51dfd2 100644 (file)
@@ -35,169 +35,92 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    public abstract class GreaterThanInstruction : Instruction {
+    abstract class GreaterThanInstruction : ComparisonInstruction {
         private static Instruction _SByte, _Int16, _Char, _Int32, _Int64, _Byte, _UInt16, _UInt32, _UInt64, _Single, _Double;
         private static Instruction _SByteLifted, _Int16Lifted, _CharLifted, _Int32Lifted, _Int64Lifted, _ByteLifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _SingleLifted, _DoubleLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private GreaterThanInstruction() {
         }
 
-        public bool LiftedToNull { get; set; }
+        protected override object DoNullComparison (object l, object r)
+        {
+            return LiftedToNull ? (object) null : (object) false;
+        }
 
         internal sealed class GreaterThanSByte : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (SByte)l > (SByte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (SByte)l > (SByte)r;
             }
         }
 
         internal sealed class GreaterThanInt16 : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int16)l > (Int16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int16)l > (Int16)r;
             }
         }
 
         internal sealed class GreaterThanChar : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Char)l > (Char)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Char)l > (Char)r;
             }
         }
 
         internal sealed class GreaterThanInt32 : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int32)l > (Int32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int32)l > (Int32)r;
             }
         }
 
         internal sealed class GreaterThanInt64 : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int64)l > (Int64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int64)l > (Int64)r;
             }
         }
 
         internal sealed class GreaterThanByte : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Byte)l > (Byte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Byte)l > (Byte)r;
             }
         }
 
         internal sealed class GreaterThanUInt16 : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt16)l > (UInt16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt16)l > (UInt16)r;
             }
         }
 
         internal sealed class GreaterThanUInt32 : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt32)l > (UInt32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt32)l > (UInt32)r;
             }
         }
 
         internal sealed class GreaterThanUInt64 : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt64)l > (UInt64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt64)l > (UInt64)r;
             }
         }
 
         internal sealed class GreaterThanSingle : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Single)l > (Single)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Single)l > (Single)r;
             }
         }
 
         internal sealed class GreaterThanDouble : GreaterThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Double)l > (Double)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Double)l > (Double)r;
             }
         }
 
index de2da8fd9658b1b2cef82a9a4f74bffcaf47dfa2..fd3f5ecdb17c301ffd4efc2dcffff3f59088e215 100644 (file)
@@ -35,169 +35,92 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    public abstract class GreaterThanOrEqualInstruction : Instruction {
+    abstract class GreaterThanOrEqualInstruction : ComparisonInstruction {
         private static Instruction _SByte, _Int16, _Char, _Int32, _Int64, _Byte, _UInt16, _UInt32, _UInt64, _Single, _Double;
         private static Instruction _SByteLifted, _Int16Lifted, _CharLifted, _Int32Lifted, _Int64Lifted, _ByteLifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _SingleLifted, _DoubleLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private GreaterThanOrEqualInstruction() {
         }
 
-        public bool LiftedToNull { get; set; }
+        protected override object DoNullComparison (object l, object r)
+        {
+            return LiftedToNull ? (object) null : (object) false;
+        }
 
         internal sealed class GreaterThanOrEqualSByte : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (SByte)l >= (SByte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (SByte)l >= (SByte)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualInt16 : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int16)l >= (Int16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int16)l >= (Int16)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualChar : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Char)l >= (Char)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Char)l >= (Char)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualInt32 : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int32)l >= (Int32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int32)l >= (Int32)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualInt64 : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int64)l >= (Int64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int64)l >= (Int64)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualByte : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Byte)l >= (Byte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Byte)l >= (Byte)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualUInt16 : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt16)l >= (UInt16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt16)l >= (UInt16)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualUInt32 : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt32)l >= (UInt32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt32)l >= (UInt32)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualUInt64 : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt64)l >= (UInt64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt64)l >= (UInt64)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualSingle : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Single)l >= (Single)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Single)l >= (Single)r;
             }
         }
 
         internal sealed class GreaterThanOrEqualDouble : GreaterThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Double)l >= (Double)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Double)l >= (Double)r;
             }
         }
 
index 5f916ce64b6894ba3e4b87b8e23a1363915af885..4a1f464a53e7e74bb72cdc64618dd02dcd2a6bd5 100644 (file)
@@ -48,7 +48,9 @@ namespace Microsoft.Scripting.Interpreter {
 #if FEATURE_NUMERICS
                     { typeof(BigInt), InstructionFactory<BigInt>.Factory },
 #endif
+#if !MONO_INTERPRETER
                     { typeof(BigInteger), InstructionFactory<BigInteger>.Factory }  
+#endif
                 };
             }
 
index 3bde7a4ee8fd34a3d7956b7ded1d5ef7f43c547a..586deb8bd234bf0663f9f8ff47b1f6e5353eec27 100644 (file)
@@ -35,169 +35,92 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    public abstract class LessThanInstruction : Instruction {
+    abstract class LessThanInstruction : ComparisonInstruction {
         private static Instruction _SByte, _Int16, _Char, _Int32, _Int64, _Byte, _UInt16, _UInt32, _UInt64, _Single, _Double;
         private static Instruction _SByteLifted, _Int16Lifted, _CharLifted, _Int32Lifted, _Int64Lifted, _ByteLifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _SingleLifted, _DoubleLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private LessThanInstruction() {
         }
 
-        public bool LiftedToNull { get; set; }
+        protected override object DoNullComparison (object l, object r)
+        {
+            return LiftedToNull ? (object) null : (object) false;
+        }
 
         internal sealed class LessThanSByte : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (SByte)l < (SByte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (SByte)l < (SByte)r;
             }
         }
 
         internal sealed class LessThanInt16 : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int16)l < (Int16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int16)l < (Int16)r;
             }
         }
 
         internal sealed class LessThanChar : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Char)l < (Char)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Char)l < (Char)r;
             }
         }
 
         internal sealed class LessThanInt32 : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int32)l < (Int32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int32)l < (Int32)r;
             }
         }
 
         internal sealed class LessThanInt64 : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int64)l < (Int64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int64)l < (Int64)r;
             }
         }
 
         internal sealed class LessThanByte : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Byte)l < (Byte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Byte)l < (Byte)r;
             }
         }
 
         internal sealed class LessThanUInt16 : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt16)l < (UInt16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt16)l < (UInt16)r;
             }
         }
 
         internal sealed class LessThanUInt32 : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt32)l < (UInt32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt32)l < (UInt32)r;
             }
         }
 
         internal sealed class LessThanUInt64 : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt64)l < (UInt64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt64)l < (UInt64)r;
             }
         }
 
         internal sealed class LessThanSingle : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Single)l < (Single)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Single)l < (Single)r;
             }
         }
 
         internal sealed class LessThanDouble : LessThanInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Double)l < (Double)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Double)l < (Double)r;
             }
         }
 
index 6c120f59349cd13656971a6e79540bca72597fd0..a441ee52a2b34b467be68fff7dbc503e13136214 100644 (file)
@@ -35,169 +35,92 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    public abstract class LessThanOrEqualInstruction : Instruction {
+    abstract class LessThanOrEqualInstruction : ComparisonInstruction {
         private static Instruction _SByte, _Int16, _Char, _Int32, _Int64, _Byte, _UInt16, _UInt32, _UInt64, _Single, _Double;
         private static Instruction _SByteLifted, _Int16Lifted, _CharLifted, _Int32Lifted, _Int64Lifted, _ByteLifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _SingleLifted, _DoubleLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private LessThanOrEqualInstruction() {
         }
 
-        public bool LiftedToNull { get; set; }
+        protected override object DoNullComparison (object l, object r)
+        {
+            return LiftedToNull ? (object) null : (object) false;
+        }
 
         internal sealed class LessThanOrEqualSByte : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (SByte)l <= (SByte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (SByte)l <= (SByte)r;
             }
         }
 
         internal sealed class LessThanOrEqualInt16 : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int16)l <= (Int16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int16)l <= (Int16)r;
             }
         }
 
         internal sealed class LessThanOrEqualChar : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Char)l <= (Char)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Char)l <= (Char)r;
             }
         }
 
         internal sealed class LessThanOrEqualInt32 : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int32)l <= (Int32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int32)l <= (Int32)r;
             }
         }
 
         internal sealed class LessThanOrEqualInt64 : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int64)l <= (Int64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int64)l <= (Int64)r;
             }
         }
 
         internal sealed class LessThanOrEqualByte : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Byte)l <= (Byte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Byte)l <= (Byte)r;
             }
         }
 
         internal sealed class LessThanOrEqualUInt16 : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt16)l <= (UInt16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt16)l <= (UInt16)r;
             }
         }
 
         internal sealed class LessThanOrEqualUInt32 : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt32)l <= (UInt32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt32)l <= (UInt32)r;
             }
         }
 
         internal sealed class LessThanOrEqualUInt64 : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt64)l <= (UInt64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt64)l <= (UInt64)r;
             }
         }
 
         internal sealed class LessThanOrEqualSingle : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Single)l <= (Single)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Single)l <= (Single)r;
             }
         }
 
         internal sealed class LessThanOrEqualDouble : LessThanOrEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) false;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Double)l <= (Double)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Double)l <= (Double)r;
             }
         }
 
index 4e8bb37138ced1e2199690cdf6b2374d280a93fa..1718a7299cb3d18b450598c36f0ccddd4dc4a274 100644 (file)
@@ -32,92 +32,65 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class ModInstruction : Instruction {
+    internal abstract class ModInstruction : AritmeticInstruction {
         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private ModInstruction() {
         }
 
         internal sealed class ModInt32 : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l % (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l % (Int32)r));
             }
         }
 
         internal sealed class ModInt16 : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)unchecked((Int16)l % (Int16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)unchecked((Int16)l % (Int16)r);
             }
         }
 
         internal sealed class ModInt64 : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)unchecked((Int64)l % (Int64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)unchecked((Int64)l % (Int64)r);
             }
         }
 
         internal sealed class ModUInt16 : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)unchecked((UInt16)l % (UInt16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)unchecked((UInt16)l % (UInt16)r);
             }
         }
 
         internal sealed class ModUInt32 : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)unchecked((UInt32)l % (UInt32)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)unchecked((UInt32)l % (UInt32)r);
             }
         }
 
         internal sealed class ModUInt64 : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)unchecked((UInt64)l % (UInt64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)unchecked((UInt64)l % (UInt64)r);
             }
         }
 
         internal sealed class ModSingle : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l % (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l % (Single)r);
             }
         }
 
         internal sealed class ModDouble : ModInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l % (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l % (Double)r;
             }
         }
 
index 745e1a0bcad9818682a395f5d977fe29c2c14144..526b24e54d5509981ce892db37e431a92b997b8c 100644 (file)
@@ -32,92 +32,66 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class MulInstruction : Instruction {
-        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
+    internal abstract class MulInstruction : AritmeticInstruction {
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
+        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
         private MulInstruction() {
         }
 
         internal sealed class MulInt32 : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l * (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l * (Int32)r));
             }
         }
 
         internal sealed class MulInt16 : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)unchecked((Int16)l * (Int16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)unchecked((Int16)l * (Int16)r);
             }
         }
 
         internal sealed class MulInt64 : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)unchecked((Int64)l * (Int64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)unchecked((Int64)l * (Int64)r);
             }
         }
 
         internal sealed class MulUInt16 : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)unchecked((UInt16)l * (UInt16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)unchecked((UInt16)l * (UInt16)r);
             }
         }
 
         internal sealed class MulUInt32 : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)unchecked((UInt32)l * (UInt32)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)unchecked((UInt32)l * (UInt32)r);
             }
         }
 
         internal sealed class MulUInt64 : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)unchecked((UInt64)l * (UInt64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)unchecked((UInt64)l * (UInt64)r);
             }
         }
 
         internal sealed class MulSingle : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l * (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l * (Single)r);
             }
         }
 
         internal sealed class MulDouble : MulInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l * (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l * (Double)r;
             }
         }
 
@@ -143,92 +117,66 @@ namespace Microsoft.Scripting.Interpreter {
         }
     }
 
-    internal abstract class MulOvfInstruction : Instruction {
-        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
+    internal abstract class MulOvfInstruction : AritmeticInstruction {
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
+        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
         private MulOvfInstruction() {
         }
 
         internal sealed class MulOvfInt32 : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l * (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l * (Int32)r));
             }
         }
 
         internal sealed class MulOvfInt16 : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((Int16)((Int16)l * (Int16)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((Int16)((Int16)l * (Int16)r));
             }
         }
 
         internal sealed class MulOvfInt64 : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((Int64)((Int64)l * (Int64)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((Int64)((Int64)l * (Int64)r));
             }
         }
 
         internal sealed class MulOvfUInt16 : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt16)((UInt16)l * (UInt16)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt16)((UInt16)l * (UInt16)r));
             }
         }
 
         internal sealed class MulOvfUInt32 : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt32)((UInt32)l * (UInt32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt32)((UInt32)l * (UInt32)r));
             }
         }
 
         internal sealed class MulOvfUInt64 : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt64)((UInt64)l * (UInt64)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt64)((UInt64)l * (UInt64)r));
             }
         }
 
         internal sealed class MulOvfSingle : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l * (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l * (Single)r);
             }
         }
 
         internal sealed class MulOvfDouble : MulOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l * (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l * (Double)r;
             }
         }
 
index 2bd1224374fbc722d3a0df85faa9f9e2c4d0e13f..396c3ff71591af1fee0df35dd4b55f84fcc14e28 100644 (file)
@@ -22,191 +22,113 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class NotEqualInstruction : Instruction {
+    internal abstract class NotEqualInstruction : ComparisonInstruction {
         // Perf: EqualityComparer<T> but is 3/2 to 2 times slower.
         private static Instruction _Reference, _Boolean, _SByte, _Int16, _Char, _Int32, _Int64, _Byte, _UInt16, _UInt32, _UInt64, _Single, _Double;
         private static Instruction _BooleanLifted, _SByteLifted, _Int16Lifted, _CharLifted, _Int32Lifted, _Int64Lifted,
             _ByteLifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _SingleLifted, _DoubleLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private NotEqualInstruction() {
         }
 
-        public bool LiftedToNull { get; set; }
+        protected override object DoNullComparison (object l, object r)
+        {
+            return LiftedToNull ? (object) null : (object) l != r;
+        }
 
         internal sealed class NotEqualBoolean : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Boolean)l != (Boolean)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Boolean)l != (Boolean)r;
             }
         }
 
         internal sealed class NotEqualSByte : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (SByte)l != (SByte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (SByte)l != (SByte)r;
             }
         }
 
         internal sealed class NotEqualInt16 : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int16)l != (Int16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int16)l != (Int16)r;
             }
         }
 
         internal sealed class NotEqualChar : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Char)l != (Char)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Char)l != (Char)r;
             }
         }
 
         internal sealed class NotEqualInt32 : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int32)l != (Int32)r;
-
-                frame.StackIndex--;
-                return +1;            }
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int32)l != (Int32)r;
+            }
         }
 
         internal sealed class NotEqualInt64 : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Int64)l != (Int64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Int64)l != (Int64)r;
             }
         }
 
         internal sealed class NotEqualByte : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Byte)l != (Byte)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Byte)l != (Byte)r;
             }
         }
 
         internal sealed class NotEqualUInt16 : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt16)l != (UInt16)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt16)l != (UInt16)r;
             }
         }
 
         internal sealed class NotEqualUInt32 : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt32)l != (UInt32)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt32)l != (UInt32)r;
             }
         }
 
         internal sealed class NotEqualUInt64 : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (UInt64)l != (UInt64)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (UInt64)l != (UInt64)r;
             }
         }
 
         internal sealed class NotEqualSingle : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Single)l != (Single)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Single)l != (Single)r;
             }
         }
 
         internal sealed class NotEqualDouble : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                if (l == null || r == null)
-                    frame.Data[frame.StackIndex - 2] = LiftedToNull ? (object) null : (object) l != r;
-                else
-                    frame.Data[frame.StackIndex - 2] = (Double)l != (Double)r;
-
-                frame.StackIndex--;
-                return +1;
+            protected override object DoCalculate (object l, object r)
+            {
+                return (Double)l != (Double)r;
             }
         }
 
         internal sealed class NotEqualReference : NotEqualInstruction {
-            public override int Run(InterpretedFrame frame) {
-                frame.Push(frame.Pop() != frame.Pop());
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return l != r;
+            }
+
+            protected override object DoCalculate (object l, object r)
+            {
+                throw Assert.Unreachable;
             }
         }
 
index baaad40fb7079ccc38bd0962e29607e853f1a141..03d89974eafc77f04a9e6ea9c091fb49be4fa6b0 100644 (file)
@@ -32,153 +32,108 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class OrInstruction : Instruction {
+    internal abstract class OrInstruction : AritmeticInstruction {
         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
         private static Instruction _Int16Lifted, _Int32Lifted, _Int64Lifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _BooleanLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private OrInstruction() {
         }
 
         internal sealed class OrInt32 : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject((Int32)l | (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject((Int32)l | (Int32)r);
             }
         }
 
         internal sealed class OrInt16 : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)((Int16)l | (Int16)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)((Int16)l | (Int16)r);
             }
         }
 
         internal sealed class OrInt64 : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)((Int64)l | (Int64)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)((Int64)l | (Int64)r);
             }
         }
 
         internal sealed class OrUInt16 : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)((UInt16)l | (UInt16)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)((UInt16)l | (UInt16)r);
             }
         }
 
         internal sealed class OrUInt32 : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)((UInt32)l | (UInt32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)((UInt32)l | (UInt32)r);
             }
         }
 
         internal sealed class OrUInt64 : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)((UInt64)l | (UInt64)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)((UInt64)l | (UInt64)r);
             }
         }
 
         internal sealed class OrBoolean : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = frame.Data[frame.StackIndex - 2];
-                var r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Boolean)((Boolean)l | (Boolean)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Boolean)((Boolean)l | (Boolean)r);
             }
         }
 
         internal sealed class OrInt32Lifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((Int32?)l | (Int32?)r);
             }
         }
 
         internal sealed class OrInt16Lifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int16?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16?)((Int16?)l | (Int16?)r);
             }
         }
 
         internal sealed class OrInt64Lifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int64?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64?)((Int64?)l | (Int64?)r);
             }
         }
 
         internal sealed class OrUInt16Lifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt16?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16?)((Int16?)l | (Int16?)r);
             }
         }
 
         internal sealed class OrUInt32Lifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32?)((UInt32?)l | (UInt32?)r);
             }
         }
 
         internal sealed class OrUInt64Lifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt64?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64?)((UInt64?)l | (UInt64?)r);
             }
         }
 
         internal sealed class OrBooleanLifted : OrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Boolean?)frame.Data[frame.StackIndex - 2];
-                var r = (Boolean?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Boolean?)(l | r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Boolean?)((Boolean?)l | (Boolean?)r);
             }
         }
 
index 5406dd01b0096b7deab584e3a4ee4bf6623d1388..419be4fcc74a7a717597e86d4b88d6ec2cbd124b 100644 (file)
@@ -32,133 +32,94 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class ShlInstruction : Instruction {
+    internal abstract class ShlInstruction : AritmeticInstruction {
         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64;
         private static Instruction _Int16Lifted, _Int32Lifted, _Int64Lifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private ShlInstruction() {
         }
 
         internal sealed class ShlInt32 : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject((Int32)l << (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject((Int32)l << (Int32)r);
             }
         }
 
         internal sealed class ShlInt16 : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32)((Int16)l << (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32)((Int16)l << (Int32)r);
             }
         }
 
         internal sealed class ShlInt64 : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)((Int64)l << (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)((Int64)l << (Int32)r);
             }
         }
 
         internal sealed class ShlUInt16 : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32)((UInt16)l << (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32)((UInt16)l << (Int32)r);
             }
         }
 
         internal sealed class ShlUInt32 : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)((UInt32)l << (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)((UInt32)l << (Int32)r);
             }
         }
 
         internal sealed class ShlUInt64 : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)((UInt64)l << (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)((UInt64)l << (Int32)r);
             }
         }
 
         internal sealed class ShlInt32Lifted : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l << r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((Int32?)l << (Int32?)r);
             }
         }
 
         internal sealed class ShlInt16Lifted : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32)(l << r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32)((Int16?)l << (Int32?)r);
             }
         }
 
         internal sealed class ShlInt64Lifted : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64?)(l << r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return  (Int64?)((Int64?)l << (Int32?)r);
             }
         }
 
         internal sealed class ShlUInt16Lifted : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l << r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((UInt16?)l << (Int32?)r);
             }
         }
 
         internal sealed class ShlUInt32Lifted : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32?)(l << r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32?)((UInt32?)l << (Int32?)r);
             }
         }
 
         internal sealed class ShlUInt64Lifted : ShlInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64?)(l << r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64?)((UInt64?)l << (Int32?)r);
             }
         }
 
index 5099a41c18b491a74f5827eb8b3a5827b5275273..9af9f363e5dbdc01447243fbe2ef0b88ae97aa6e 100644 (file)
@@ -32,133 +32,94 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class ShrInstruction : Instruction {
+    internal abstract class ShrInstruction : AritmeticInstruction {
         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64;
         private static Instruction _Int16Lifted, _Int32Lifted, _Int64Lifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private ShrInstruction() {
         }
 
         internal sealed class ShrInt32 : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject((Int32)l >> (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject((Int32)l >> (Int32)r);
             }
         }
 
         internal sealed class ShrInt16 : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32)((Int16)l >> (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32)((Int16)l >> (Int32)r);
             }
         }
 
         internal sealed class ShrInt64 : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)((Int64)l >> (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)((Int64)l >> (Int32)r);
             }
         }
 
         internal sealed class ShrUInt16 : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32)((UInt16)l >> (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32)((UInt16)l >> (Int32)r);
             }
         }
 
         internal sealed class ShrUInt32 : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)((UInt32)l >> (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)((UInt32)l >> (Int32)r);
             }
         }
 
         internal sealed class ShrUInt64 : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)((UInt64)l >> (Int32)r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)((UInt64)l >> (Int32)r);
             }
         }
 
         internal sealed class ShrInt32Lifted : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l >> r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((Int32?)l >> (Int32?)r);
             }
         }
 
         internal sealed class ShrInt16Lifted : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32)(l >> r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32)((Int16?)l >> (Int32?)r);
             }
         }
 
         internal sealed class ShrInt64Lifted : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64?)(l >> r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64?)((Int64?)l >> (Int32?)r);
             }
         }
 
         internal sealed class ShrUInt16Lifted : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l >> r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((UInt16?)l >> (Int32?)r);
             }
         }
 
         internal sealed class ShrUInt32Lifted : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32?)(l >> r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32?)((UInt32?)l >> (Int32?)r);
             }
         }
 
         internal sealed class ShrUInt64Lifted : ShrInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64?)(l >> r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64?)((UInt64?)l >> (Int32?)r);
             }
         }
 
index 8ca97e97f7eea15a89a158bcffba1d5b95d1cd58..2c088e4fb0965331fe86a575bbb6e5bba162cd69 100644 (file)
@@ -32,92 +32,66 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class SubInstruction : Instruction {
-        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
+    internal abstract class SubInstruction : AritmeticInstruction {
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
+        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
         private SubInstruction() {
         }
 
         internal sealed class SubInt32 : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l - (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l - (Int32)r));
             }
         }
 
         internal sealed class SubInt16 : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)unchecked((Int16)l - (Int16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)unchecked((Int16)l - (Int16)r);
             }
         }
 
         internal sealed class SubInt64 : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)unchecked((Int64)l - (Int64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)unchecked((Int64)l - (Int64)r);
             }
         }
 
         internal sealed class SubUInt16 : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)unchecked((UInt16)l - (UInt16)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)unchecked((UInt16)l - (UInt16)r);
             }
         }
 
         internal sealed class SubUInt32 : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)unchecked((UInt32)l - (UInt32)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32)unchecked((UInt32)l - (UInt32)r);
             }
         }
 
         internal sealed class SubUInt64 : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)unchecked((UInt64)l - (UInt64)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)unchecked((UInt64)l - (UInt64)r);
             }
         }
 
         internal sealed class SubSingle : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l - (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l - (Single)r);
             }
         }
 
         internal sealed class SubDouble : SubInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l - (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l - (Double)r;
             }
         }
 
@@ -143,92 +117,66 @@ namespace Microsoft.Scripting.Interpreter {
         }
     }
 
-    internal abstract class SubOvfInstruction : Instruction {
-        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
+    internal abstract class SubOvfInstruction : AritmeticInstruction {
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
+        private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Single, _Double;
 
         private SubOvfInstruction() {
         }
 
         internal sealed class SubOvfInt32 : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l - (Int32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l - (Int32)r));
             }
         }
 
         internal sealed class SubOvfInt16 : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((Int16)((Int16)l - (Int16)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((Int16)((Int16)l - (Int16)r));
             }
         }
 
         internal sealed class SubOvfInt64 : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((Int64)((Int64)l - (Int64)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((Int64)((Int64)l - (Int64)r));
             }
         }
 
         internal sealed class SubOvfUInt16 : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt16)((UInt16)l - (UInt16)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt16)((UInt16)l - (UInt16)r));
             }
         }
 
         internal sealed class SubOvfUInt32 : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt32)((UInt32)l - (UInt32)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt32)((UInt32)l - (UInt32)r));
             }
         }
 
         internal sealed class SubOvfUInt64 : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = checked((UInt64)((UInt64)l - (UInt64)r));
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return checked((UInt64)((UInt64)l - (UInt64)r));
             }
         }
 
         internal sealed class SubOvfSingle : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Single)((Single)l - (Single)r);
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Single)((Single)l - (Single)r);
             }
         }
 
         internal sealed class SubOvfDouble : SubOvfInstruction {
-            public override int Run(InterpretedFrame frame) {
-                object l = frame.Data[frame.StackIndex - 2];
-                object r = frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Double)l - (Double)r;
-                frame.StackIndex--;
-                return +1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Double)l - (Double)r;
             }
         }
 
index 21f285c02e68f71fd37d7b013133ac3d0bb0ff0f..8ad9f606f65f55b3c2818dd1c1f790f2b26d5c86 100644 (file)
@@ -32,153 +32,108 @@ using Microsoft.Scripting.Runtime;
 using Microsoft.Scripting.Utils;
 
 namespace Microsoft.Scripting.Interpreter {
-    internal abstract class XorInstruction : Instruction {
+    internal abstract class XorInstruction : AritmeticInstruction {
         private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
         private static Instruction _Int16Lifted, _Int32Lifted, _Int64Lifted, _UInt16Lifted, _UInt32Lifted, _UInt64Lifted, _BooleanLifted;
 
-        public override int ConsumedStack { get { return 2; } }
-        public override int ProducedStack { get { return 1; } }
-
         private XorInstruction() {
         }
 
         internal sealed class XorInt32 : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32)frame.Data[frame.StackIndex - 2];
-                var r = (Int32)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return ScriptingRuntimeHelpers.Int32ToObject((Int32)l ^ (Int32)r);
             }
         }
 
         internal sealed class XorInt16 : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16)frame.Data[frame.StackIndex - 2];
-                var r = (Int16)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int16)((Int16)l ^ (Int16)r);
             }
         }
 
         internal sealed class XorInt64 : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64)frame.Data[frame.StackIndex - 2];
-                var r = (Int64)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64)((Int64)l ^ (Int64)r);
             }
         }
 
         internal sealed class XorUInt16 : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16)frame.Data[frame.StackIndex - 2];
-                var r = (UInt16)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16)((UInt16)l ^ (UInt16)r);
             }
         }
 
         internal sealed class XorUInt32 : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32)frame.Data[frame.StackIndex - 2];
-                var r = (UInt32)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return  (UInt32)((UInt32)l ^ (UInt32)r);
             }
         }
 
         internal sealed class XorUInt64 : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64)frame.Data[frame.StackIndex - 2];
-                var r = (UInt64)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64)((UInt64)l ^ (UInt64)r);
             }
         }
 
         internal sealed class XorBoolean : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Boolean)frame.Data[frame.StackIndex - 2];
-                var r = (Boolean)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Boolean)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Boolean)((Boolean)l ^ (Boolean)r);
             }
         }
 
         internal sealed class XorInt32Lifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int32?)frame.Data[frame.StackIndex - 2];
-                var r = (Int32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int32?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int32?)((Int32?)l ^ (Int32?)r);
             }
         }
 
         internal sealed class XorInt16Lifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int16?)frame.Data[frame.StackIndex - 2];
-                var r = (Int16?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int16?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return  (Int16?)((Int16?)l ^ (Int16?)r);
             }
         }
 
         internal sealed class XorInt64Lifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Int64?)frame.Data[frame.StackIndex - 2];
-                var r = (Int64?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Int64?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Int64?)((Int64?)l ^ (Int64?)r);
             }
         }
 
         internal sealed class XorUInt16Lifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt16?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt16?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt16?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt16?)((UInt16?)l ^ (UInt16?)r);
             }
         }
 
         internal sealed class XorUInt32Lifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt32?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt32?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt32?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt32?)((UInt32?)l ^ (UInt32?)r);
             }
         }
 
         internal sealed class XorUInt64Lifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (UInt64?)frame.Data[frame.StackIndex - 2];
-                var r = (UInt64?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (UInt64?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (UInt64?)((UInt64?)l ^ (UInt64?)r);
             }
         }
 
         internal sealed class XorBooleanLifted : XorInstruction {
-            public override int Run(InterpretedFrame frame) {
-                var l = (Boolean?)frame.Data[frame.StackIndex - 2];
-                var r = (Boolean?)frame.Data[frame.StackIndex - 1];
-                frame.Data[frame.StackIndex - 2] = (Boolean?)(l ^ r);
-                frame.StackIndex--;
-                return 1;
+            protected override object Calculate (object l, object r)
+            {
+                return (Boolean?)((Boolean?)l ^ (Boolean?)r);
             }
         }
 
index bb6da752e40b4e9e17d4746f85fd8edc5d8894fa..6a57c23f15adf3cff0ed5199bd3199611e045aa4 100644 (file)
@@ -21,6 +21,8 @@ using BigInt = System.Numerics.BigInteger;
 #endif
 
 namespace Microsoft.Scripting.Math {
+
+#if !MONO_INTERPRETER
     /// <summary>
     /// Implementation of the complex number data type.
     /// </summary>
@@ -273,4 +275,6 @@ namespace Microsoft.Scripting.Math {
             return this == ((Complex64)obj);
         }
     }
+#endif
+
 }
\ No newline at end of file
index 3b1642735262d9b207c9ab74e32fdbe6fd2c3b3d..435fb259b6bff3f7442833d837ee584563274bbf 100644 (file)
@@ -683,7 +683,7 @@ namespace Microsoft.Scripting.Utils {
 
             return four;
         }
-
+#if !MONO_INTERPRETER
 #if !FEATURE_NUMERICS
         public static BigInteger GetRandBits(this Random generator, int bits) {
             ContractUtils.Requires(bits > 0);
@@ -825,7 +825,6 @@ namespace Microsoft.Scripting.Utils {
             );
         }
 #endif
-
         public static bool TryToFloat64(this BigInteger self, out double result) {
             return StringUtils.TryParseDouble(
                 self.ToString(10),
@@ -865,7 +864,7 @@ namespace Microsoft.Scripting.Utils {
             return index * 8 + BitLength((int)bytes[index]);
         }
 #endif
-
+#endif
         // Like GetBitCount(Abs(x)), except 0 maps to 0
         public static int BitLength(long x) {
             if (x == 0) {
@@ -1163,6 +1162,7 @@ namespace Microsoft.Scripting.Utils {
 
         #endregion
 
+#if !MONO_INTERPRETER
         #region Complex
 
 #if !FEATURE_NUMERICS
@@ -1224,6 +1224,7 @@ namespace Microsoft.Scripting.Utils {
 #endif
 
         #endregion
+#endif
     }
 
 }
index 95e23e634a8580123075be7777806e551a372e4a..342f258a62deb34ce4c6059fe741341d8af24cb0 100644 (file)
@@ -138,7 +138,7 @@ namespace Microsoft.Scripting.Utils {
     public static class ReflectionUtils {
         #region Accessibility
 
-        public static BindingFlags AllMembers = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
+        public const BindingFlags AllMembers = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
 
         public static bool IsPublic(this PropertyInfo property) {
             return property.GetGetMethod(nonPublic: false) != null
index d197e8ee4be2b0d3b092f07a591d35a6f8efa6db..4659f3d0f39e4de71ef5aad4c1277d0970fc098b 100644 (file)
@@ -53,6 +53,9 @@ namespace Microsoft.Scripting {
         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
         public static readonly PlatformAdaptationLayer Default = new PlatformAdaptationLayer();
 
+#if MONO_INTERPRETER
+        public const bool IsCompactFramework = false;
+#else
         public static readonly bool IsCompactFramework =
 #if WIN8
             false;
@@ -61,6 +64,8 @@ namespace Microsoft.Scripting {
             Environment.OSVersion.Platform == PlatformID.Xbox;
 #endif
 
+#endif
+
 #if SILVERLIGHT
 
         // this dictionary is readonly after initialization: