Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2014-01-22 20:52:21 +0400
committerMarek Safar <marek.safar@gmail.com>2014-01-22 20:54:14 +0400
commitee5bf38ad0ad3ce30bfdc94d091033c43c6e4657 (patch)
tree2e9a576dde4e64e2183588228526a55aa68b5d9b /mcs/class/dlr
parenta2febcf2de87a2d4d86da572db8f18b55d7e1d56 (diff)
[dlr] Implement few missing interpreter instructions
Diffstat (limited to 'mcs/class/dlr')
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AndInstruction.cs134
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ArrayOperations.cs23
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/Instruction.cs12
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs55
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ModInstruction.cs145
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/MulInstruction.cs256
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NegateInstruction.cs214
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NotInstruction.cs119
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/OrInstruction.cs134
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShlInstruction.cs123
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShrInstruction.cs123
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/SubInstruction.cs256
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/XorInstruction.cs134
-rw-r--r--mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs67
14 files changed, 1770 insertions, 25 deletions
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AndInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AndInstruction.cs
new file mode 100644
index 00000000000..09ec87df22a
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/AndInstruction.cs
@@ -0,0 +1,134 @@
+//
+// AndbInstruction.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 AndInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
+
+ 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) {
+ 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;
+ }
+ }
+
+ internal sealed class AndInt16 : AndInstruction {
+ 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)((Int16)l & (Int16)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class AndInt64 : AndInstruction {
+ 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 & (Int64)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class AndUInt16 : AndInstruction {
+ 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)((UInt16)l & (UInt16)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class AndUInt32 : AndInstruction {
+ 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 & (UInt32)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class AndUInt64 : AndInstruction {
+ 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 & (UInt64)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class AndBoolean : AndInstruction {
+ 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] = (Boolean)((Boolean)l & (Boolean)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new AndInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new AndInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new AndInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new AndUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new AndUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new AndUInt64());
+ case TypeCode.Boolean: return _Boolean ?? (_Boolean = new AndBoolean());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "And()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ArrayOperations.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ArrayOperations.cs
index 0c5a9e16a7b..d8e0bc6c831 100644
--- a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ArrayOperations.cs
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ArrayOperations.cs
@@ -90,6 +90,29 @@ namespace Microsoft.Scripting.Interpreter {
}
}
+ public sealed class GetArrayLengthInstruction : Instruction {
+ private static Instruction instance;
+
+ private GetArrayLengthInstruction() { }
+
+ public override int ConsumedStack { get { return 1; } }
+ public override int ProducedStack { get { return 1; } }
+
+ public override int Run(InterpretedFrame frame) {
+ var array = (Array)frame.Pop();
+ frame.Push(array.Length);
+ return +1;
+ }
+
+ public static Instruction Create() {
+ return instance ?? (instance = new GetArrayLengthInstruction());
+ }
+
+ public override string InstructionName {
+ get { return "GetArrayLength"; }
+ }
+ }
+
public sealed class SetArrayItemInstruction<TElement> : Instruction {
internal SetArrayItemInstruction() { }
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/Instruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/Instruction.cs
index 28267ec2a58..6f67063353b 100644
--- a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/Instruction.cs
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/Instruction.cs
@@ -58,16 +58,4 @@ namespace Microsoft.Scripting.Interpreter {
return null;
}
}
-
- internal sealed class NotInstruction : Instruction {
- public static readonly Instruction Instance = new NotInstruction();
-
- private NotInstruction() { }
- public override int ConsumedStack { get { return 1; } }
- public override int ProducedStack { get { return 1; } }
- public override int Run(InterpretedFrame frame) {
- frame.Push((bool)frame.Pop() ? ScriptingRuntimeHelpers.False : ScriptingRuntimeHelpers.True);
- return +1;
- }
- }
}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs
index c605977208d..3fa74e9b967 100644
--- a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/InstructionList.cs
@@ -601,6 +601,10 @@ namespace Microsoft.Scripting.Interpreter {
}
}
+ public void EmitGetArrayLength(Type arrayType) {
+ Emit(GetArrayLengthInstruction.Create());
+ }
+
public void EmitSetArrayItem(Type arrayType) {
Type elementType = arrayType.GetElementType();
if (elementType.IsClass() || elementType.IsInterface()) {
@@ -634,22 +638,52 @@ namespace Microsoft.Scripting.Interpreter {
}
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters")]
public void EmitSub(Type type, bool @checked) {
- throw new NotSupportedException();
+ if (@checked) {
+ Emit(SubOvfInstruction.Create(type));
+ } else {
+ Emit(SubInstruction.Create(type));
+ }
}
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters")]
public void EmitMul(Type type, bool @checked) {
- throw new NotSupportedException();
+ if (@checked) {
+ Emit(MulOvfInstruction.Create(type));
+ } else {
+ Emit(MulInstruction.Create(type));
+ }
}
public void EmitDiv(Type type) {
Emit(DivInstruction.Create(type));
}
+ public void EmitMod(Type type) {
+ Emit(ModInstruction.Create(type));
+ }
+
#endregion
+ public void EmitShl(Type type) {
+ Emit(ShlInstruction.Create(type));
+ }
+
+ public void EmitShr(Type type) {
+ Emit(ShrInstruction.Create(type));
+ }
+
+ public void EmitOr(Type type) {
+ Emit(OrInstruction.Create(type));
+ }
+
+ public void EmitAnd(Type type) {
+ Emit(AndInstruction.Create(type));
+ }
+
+ public void EmitExclusiveOr(Type type) {
+ Emit(XorInstruction.Create(type));
+ }
+
#region Comparisons
public void EmitEqual(Type type) {
@@ -692,10 +726,17 @@ namespace Microsoft.Scripting.Interpreter {
#endregion
- #region Boolean Operators
+ #region Unary Operators
+
+ public void EmitNegate(Type type, bool @checked) {
+ if (@checked)
+ Emit(NegateOvfInstruction.Create(type));
+ else
+ Emit(NegateInstruction.Create(type));
+ }
- public void EmitNot() {
- Emit(NotInstruction.Instance);
+ public void EmitNot(Type type) {
+ Emit(NotInstruction.Create(type));
}
#endregion
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ModInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ModInstruction.cs
new file mode 100644
index 00000000000..4e8bb37138c
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ModInstruction.cs
@@ -0,0 +1,145 @@
+//
+// ModInstruction.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 ModInstruction : Instruction {
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new ModInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new ModInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new ModInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new ModUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new ModUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new ModUInt64());
+ case TypeCode.Single: return _Single ?? (_Single = new ModSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new ModDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Mod()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/MulInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/MulInstruction.cs
new file mode 100644
index 00000000000..4529adc4512
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/MulInstruction.cs
@@ -0,0 +1,256 @@
+//
+// MulInstruction.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 MulInstruction : Instruction {
+ 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 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new MulInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new MulInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new MulInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new MulUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new MulUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new MulUInt64());
+ case TypeCode.Single: return _Single ?? (_Single = new MulSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new MulDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Mul()";
+ }
+ }
+
+ internal abstract class MulOvfInstruction : Instruction {
+ 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 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;
+ }
+ }
+
+ 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] = (Int16)checked((Int16)l * (Int16)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (Int64)checked((Int64)l * (Int64)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (UInt16)checked((UInt16)l * (UInt16)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (UInt32)checked((UInt32)l * (UInt32)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (UInt64)checked((UInt64)l * (UInt64)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new MulOvfInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new MulOvfInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new MulOvfInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new MulOvfUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new MulOvfUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new MulOvfUInt64());
+ case TypeCode.Single: return _Single ?? (_Single = new MulOvfSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new MulOvfDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "MulOvf()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NegateInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NegateInstruction.cs
new file mode 100644
index 00000000000..58c60f6803b
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NegateInstruction.cs
@@ -0,0 +1,214 @@
+//
+// NegateInstruction.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 NegateInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _Single, _Double;
+
+ public override int ConsumedStack { get { return 1; } }
+ public override int ProducedStack { get { return 1; } }
+
+ private NegateInstruction() {
+ }
+
+ internal sealed class NegateInt32 : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = ScriptingRuntimeHelpers.Int32ToObject(unchecked(-(Int32)v));
+ return 1;
+ }
+ }
+
+ internal sealed class NegateInt16 : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Int16)unchecked(-(Int16)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NegateInt64 : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Int64)unchecked(-(Int64)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NegateUInt16 : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt16)unchecked(-(UInt16)v);
+ return 1;
+
+ }
+ }
+
+ internal sealed class NegateUInt32 : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt32)unchecked(-(UInt32)v);
+ return 1;
+
+ }
+ }
+
+ internal sealed class NegateSingle : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Single)unchecked(-(Single)v);
+ return 1;
+
+ }
+ }
+
+ internal sealed class NegateDouble : NegateInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Double)unchecked(-(Double)v);
+ return 1;
+
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new NegateInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new NegateInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new NegateInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new NegateUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new NegateUInt32());
+ case TypeCode.Single: return _Single ?? (_Single = new NegateSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new NegateDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Negate()";
+ }
+ }
+
+ internal abstract class NegateOvfInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _Single, _Double;
+
+ public override int ConsumedStack { get { return 1; } }
+ public override int ProducedStack { get { return 1; } }
+
+ private NegateOvfInstruction() {
+ }
+
+ internal sealed class NegateOvfInt32 : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = ScriptingRuntimeHelpers.Int32ToObject(checked(-(Int32)v));
+ return 1;
+ }
+ }
+
+ internal sealed class NegateOvfInt16 : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Int16)checked(-(Int16)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NegateOvfInt64 : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Int64)checked(-(Int64)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NegateOvfUInt16 : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt16)checked(-(UInt16)v);
+ return 1;
+
+ }
+ }
+
+ internal sealed class NegateOvfUInt32 : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt32)checked(-(UInt32)v);
+ return 1;
+
+ }
+ }
+
+ internal sealed class NegateOvfSingle : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Single)checked(-(Single)v);
+ return 1;
+
+ }
+ }
+
+ internal sealed class NegateOvfDouble : NegateOvfInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Double)checked(-(Double)v);
+ return 1;
+
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new NegateOvfInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new NegateOvfInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new NegateOvfInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new NegateOvfUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new NegateOvfUInt32());
+ case TypeCode.Single: return _Single ?? (_Single = new NegateOvfSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new NegateOvfDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "NegateOvf()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NotInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NotInstruction.cs
new file mode 100644
index 00000000000..3cfce546518
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/NotInstruction.cs
@@ -0,0 +1,119 @@
+//
+// NotInstruction.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 NotInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
+
+ public override int ConsumedStack { get { return 1; } }
+ public override int ProducedStack { get { return 1; } }
+
+ private NotInstruction() {
+ }
+
+ internal sealed class NotBoolean : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ frame.Push((bool)frame.Pop() ? ScriptingRuntimeHelpers.False : ScriptingRuntimeHelpers.True);
+ return 1;
+ }
+ }
+
+ internal sealed class NotInt32 : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = ScriptingRuntimeHelpers.Int32ToObject(~(Int32)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NotInt16 : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Int16)(~(Int16)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NotInt64 : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (Int64)(~(Int64)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NotUInt16 : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt64)(~(UInt64)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NotUInt32 : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt32)(~(UInt32)v);
+ return 1;
+ }
+ }
+
+ internal sealed class NotUInt64 : NotInstruction {
+ public override int Run(InterpretedFrame frame) {
+ object v = frame.Data[frame.StackIndex - 1];
+ frame.Data[frame.StackIndex - 1] = (UInt64)(~(UInt64)v);
+ return 1;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new NotInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new NotInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new NotInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new NotUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new NotUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new NotUInt64());
+ case TypeCode.Boolean: return _Boolean ?? (_Boolean = new NotBoolean());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Not()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/OrInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/OrInstruction.cs
new file mode 100644
index 00000000000..b183b689042
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/OrInstruction.cs
@@ -0,0 +1,134 @@
+//
+// OrInstruction.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 OrInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
+
+ 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) {
+ 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;
+ }
+ }
+
+ internal sealed class OrInt16 : OrInstruction {
+ 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)((Int16)l | (Int16)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class OrInt64 : OrInstruction {
+ 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 | (Int64)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class OrUInt16 : OrInstruction {
+ 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)((UInt16)l | (UInt16)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class OrUInt32 : OrInstruction {
+ 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 | (UInt32)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class OrUInt64 : OrInstruction {
+ 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 | (UInt64)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class OrBoolean : OrInstruction {
+ 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] = (Boolean)((Boolean)l | (Boolean)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new OrInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new OrInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new OrInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new OrUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new OrUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new OrUInt64());
+ case TypeCode.Boolean: return _Boolean ?? (_Boolean = new OrBoolean());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Or()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShlInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShlInstruction.cs
new file mode 100644
index 00000000000..4db455315ab
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShlInstruction.cs
@@ -0,0 +1,123 @@
+//
+// ShlInstruction.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 ShlInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64;
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new ShlInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new ShlInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new ShlInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new ShlUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new ShlUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new ShlUInt64());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Shl()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShrInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShrInstruction.cs
new file mode 100644
index 00000000000..cefb800f17b
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/ShrInstruction.cs
@@ -0,0 +1,123 @@
+//
+// ShrInstruction.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 ShrInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64;
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new ShrInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new ShrInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new ShrInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new ShrUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new ShrUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new ShrUInt64());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Shr()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/SubInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/SubInstruction.cs
new file mode 100644
index 00000000000..4571e4f930e
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/SubInstruction.cs
@@ -0,0 +1,256 @@
+//
+// SubInstruction.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 SubInstruction : Instruction {
+ 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 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new SubInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new SubInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new SubInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new SubUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new SubUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new SubUInt64());
+ case TypeCode.Single: return _Single ?? (_Single = new SubSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new SubDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Sub()";
+ }
+ }
+
+ internal abstract class SubOvfInstruction : Instruction {
+ 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 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;
+ }
+ }
+
+ 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] = (Int16)checked((Int16)l - (Int16)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (Int64)checked((Int64)l - (Int64)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (UInt16)checked((UInt16)l - (UInt16)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (UInt32)checked((UInt32)l - (UInt32)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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] = (UInt64)checked((UInt64)l - (UInt64)r);
+ frame.StackIndex--;
+ return +1;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ 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;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new SubOvfInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new SubOvfInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new SubOvfInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new SubOvfUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new SubOvfUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new SubOvfUInt64());
+ case TypeCode.Single: return _Single ?? (_Single = new SubOvfSingle());
+ case TypeCode.Double: return _Double ?? (_Double = new SubOvfDouble());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "SubOvf()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/XorInstruction.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/XorInstruction.cs
new file mode 100644
index 00000000000..37360a8beed
--- /dev/null
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/Instructions/XorInstruction.cs
@@ -0,0 +1,134 @@
+//
+// AndbInstruction.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 XorInstruction : Instruction {
+ private static Instruction _Int16, _Int32, _Int64, _UInt16, _UInt32, _UInt64, _Boolean;
+
+ 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) {
+ 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;
+ }
+ }
+
+ internal sealed class XorInt16 : XorInstruction {
+ 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)((Int16)l ^ (Int16)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class XorInt64 : XorInstruction {
+ 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 ^ (Int64)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class XorUInt16 : XorInstruction {
+ 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)((UInt16)l ^ (UInt16)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class XorUInt32 : XorInstruction {
+ 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 ^ (UInt32)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class XorUInt64 : XorInstruction {
+ 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 ^ (UInt64)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ internal sealed class XorBoolean : XorInstruction {
+ 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] = (Boolean)((Boolean)l ^ (Boolean)r);
+ frame.StackIndex--;
+ return 1;
+ }
+ }
+
+ public static Instruction Create(Type type) {
+ Debug.Assert(!type.IsEnum());
+ switch (type.GetTypeCode()) {
+ case TypeCode.Int16: return _Int16 ?? (_Int16 = new XorInt16());
+ case TypeCode.Int32: return _Int32 ?? (_Int32 = new XorInt32());
+ case TypeCode.Int64: return _Int64 ?? (_Int64 = new XorInt64());
+ case TypeCode.UInt16: return _UInt16 ?? (_UInt16 = new XorUInt16());
+ case TypeCode.UInt32: return _UInt32 ?? (_UInt32 = new XorUInt32());
+ case TypeCode.UInt64: return _UInt64 ?? (_UInt64 = new XorUInt64());
+ case TypeCode.Boolean: return _Boolean ?? (_Boolean = new XorBoolean());
+
+ default:
+ throw Assert.Unreachable;
+ }
+ }
+
+ public override string ToString() {
+ return "Xor()";
+ }
+ }
+}
diff --git a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs
index cf88b40df59..fa98324b654 100644
--- a/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs
+++ b/mcs/class/dlr/Runtime/Microsoft.Dynamic/Interpreter/LightCompiler.cs
@@ -561,6 +561,7 @@ namespace Microsoft.Scripting.Interpreter {
case ExpressionType.Multiply:
case ExpressionType.MultiplyChecked:
case ExpressionType.Divide:
+ case ExpressionType.Modulo:
CompileArithmetic(node.NodeType, node.Left, node.Right);
return;
@@ -579,6 +580,17 @@ namespace Microsoft.Scripting.Interpreter {
CompileComparison(node.NodeType, node.Left, node.Right);
return;
+ case ExpressionType.LeftShift:
+ case ExpressionType.RightShift:
+ CompileShift(node.NodeType, node.Left, node.Right);
+ return;
+
+ case ExpressionType.And:
+ case ExpressionType.Or:
+ case ExpressionType.ExclusiveOr:
+ CompileLogical(node.NodeType, node.Left, node.Right);
+ return;
+
default:
throw new NotImplementedException(node.NodeType.ToString());
}
@@ -629,6 +641,30 @@ namespace Microsoft.Scripting.Interpreter {
case ExpressionType.Multiply: _instructions.EmitMul(left.Type, false); break;
case ExpressionType.MultiplyChecked: _instructions.EmitMul(left.Type, true); break;
case ExpressionType.Divide: _instructions.EmitDiv(left.Type); break;
+ case ExpressionType.Modulo: _instructions.EmitMod(left.Type); break;
+ default: throw Assert.Unreachable;
+ }
+ }
+
+ private void CompileShift(ExpressionType nodeType, Expression left, Expression right) {
+ Debug.Assert(right.Type == typeof (int));
+ Compile(left);
+ Compile(right);
+ switch (nodeType) {
+ case ExpressionType.LeftShift: _instructions.EmitShl(left.Type); break;
+ case ExpressionType.RightShift: _instructions.EmitShr(left.Type); break;
+ default: throw Assert.Unreachable;
+ }
+ }
+
+ private void CompileLogical(ExpressionType nodeType, Expression left, Expression right) {
+ Debug.Assert(left.Type == right.Type && TypeUtils.IsIntegerOrBool(left.Type));
+ Compile(left);
+ Compile(right);
+ switch (nodeType) {
+ case ExpressionType.And: _instructions.EmitAnd(left.Type); break;
+ case ExpressionType.Or: _instructions.EmitOr(left.Type); break;
+ case ExpressionType.ExclusiveOr: _instructions.EmitExclusiveOr(left.Type); break;
default: throw Assert.Unreachable;
}
}
@@ -673,13 +709,14 @@ namespace Microsoft.Scripting.Interpreter {
return;
}
+ private void CompileNegateExpression(UnaryExpression node, bool @checked) {
+ Compile(node.Operand);
+ _instructions.EmitNegate(node.Type, @checked);
+ }
+
private void CompileNotExpression(UnaryExpression node) {
- if (node.Operand.Type == typeof(bool)) {
- Compile(node.Operand);
- _instructions.EmitNot();
- } else {
- throw new NotImplementedException();
- }
+ Compile(node.Operand);
+ _instructions.EmitNot(node.Type);
}
private void CompileUnaryExpression(Expression expr) {
@@ -690,9 +727,23 @@ namespace Microsoft.Scripting.Interpreter {
EmitCall(node.Method);
} else {
switch (node.NodeType) {
+ case ExpressionType.ArrayLength:
+ Compile(node.Operand);
+ _instructions.EmitGetArrayLength (node.Type);
+ return;
+ case ExpressionType.Negate:
+ CompileNegateExpression(node, false);
+ return;
+ case ExpressionType.NegateChecked:
+ CompileNegateExpression(node, true);
+ return;
case ExpressionType.Not:
CompileNotExpression(node);
return;
+ case ExpressionType.UnaryPlus:
+ // unary plus is a nop:
+ Compile(node.Operand);
+ return;
case ExpressionType.TypeAs:
CompileTypeAsExpression(node);
return;
@@ -1205,7 +1256,11 @@ namespace Microsoft.Scripting.Interpreter {
// need to generate code.
if (!CollectionUtils.TrueForAll(parameters, (p) => !p.ParameterType.IsByRef) ||
(!node.Method.IsStatic && node.Method.DeclaringType.IsValueType() && !node.Method.DeclaringType.IsPrimitive())) {
+#if MONO_INTERPRETER
+ throw new NotImplementedException ("Interpreter of ref types");
+#else
_forceCompile = true;
+#endif
}
// CF bug workaround