[dlr] Implement few missing interpreter instructions
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Interpreter / Instructions / ArrayOperations.cs
index 0c5a9e16a7b3ab54b6add10e1933c3f9e8a49315..d8e0bc6c8319b7b0737907ea67763bbd9f7573e7 100644 (file)
@@ -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() { }