Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
GreaterThanInstruction.cs170 linesDownload Raw Back to interpreter
1/* ****************************************************************************2 *3 * Copyright (c) Microsoft Corporation.4 *5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A6 * copy of the license can be found in the License.html file at the root of this distribution. If7 * you cannot locate the Apache License, Version 2.0, please send an email to8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound9 * by the terms of the Apache License, Version 2.0.10 *11 * You must not remove this notice, or any other, from this software.12 *13 *14 * ***************************************************************************/15 16using System.Diagnostics;17 18namespace System.Management.Automation.Interpreter19{20    internal abstract class GreaterThanInstruction : Instruction21    {22        private static Instruction s_SByte, s_int16, s_char, s_int32, s_int64, s_byte, s_UInt16, s_UInt32, s_UInt64, s_single, s_double;23 24        public override int ConsumedStack { get { return 2; } }25 26        public override int ProducedStack { get { return 1; } }27 28        private GreaterThanInstruction()29        {30        }31 32        internal sealed class GreaterThanSByte : GreaterThanInstruction33        {34            public override int Run(InterpretedFrame frame)35            {36                sbyte right = (sbyte)frame.Pop();37                frame.Push(((sbyte)frame.Pop()) > right);38                return +1;39            }40        }41 42        internal sealed class GreaterThanInt16 : GreaterThanInstruction43        {44            public override int Run(InterpretedFrame frame)45            {46                Int16 right = (Int16)frame.Pop();47                frame.Push(((Int16)frame.Pop()) > right);48                return +1;49            }50        }51 52        internal sealed class GreaterThanChar : GreaterThanInstruction53        {54            public override int Run(InterpretedFrame frame)55            {56                char right = (char)frame.Pop();57                frame.Push(((char)frame.Pop()) > right);58                return +1;59            }60        }61 62        internal sealed class GreaterThanInt32 : GreaterThanInstruction63        {64            public override int Run(InterpretedFrame frame)65            {66                Int32 right = (Int32)frame.Pop();67                frame.Push(((Int32)frame.Pop()) > right);68                return +1;69            }70        }71 72        internal sealed class GreaterThanInt64 : GreaterThanInstruction73        {74            public override int Run(InterpretedFrame frame)75            {76                Int64 right = (Int64)frame.Pop();77                frame.Push(((Int64)frame.Pop()) > right);78                return +1;79            }80        }81 82        internal sealed class GreaterThanByte : GreaterThanInstruction83        {84            public override int Run(InterpretedFrame frame)85            {86                byte right = (byte)frame.Pop();87                frame.Push(((byte)frame.Pop()) > right);88                return +1;89            }90        }91 92        internal sealed class GreaterThanUInt16 : GreaterThanInstruction93        {94            public override int Run(InterpretedFrame frame)95            {96                UInt16 right = (UInt16)frame.Pop();97                frame.Push(((UInt16)frame.Pop()) > right);98                return +1;99            }100        }101 102        internal sealed class GreaterThanUInt32 : GreaterThanInstruction103        {104            public override int Run(InterpretedFrame frame)105            {106                UInt32 right = (UInt32)frame.Pop();107                frame.Push(((UInt32)frame.Pop()) > right);108                return +1;109            }110        }111 112        internal sealed class GreaterThanUInt64 : GreaterThanInstruction113        {114            public override int Run(InterpretedFrame frame)115            {116                UInt64 right = (UInt64)frame.Pop();117                frame.Push(((UInt64)frame.Pop()) > right);118                return +1;119            }120        }121 122        internal sealed class GreaterThanSingle : GreaterThanInstruction123        {124            public override int Run(InterpretedFrame frame)125            {126                Single right = (Single)frame.Pop();127                frame.Push(((Single)frame.Pop()) > right);128                return +1;129            }130        }131 132        internal sealed class GreaterThanDouble : GreaterThanInstruction133        {134            public override int Run(InterpretedFrame frame)135            {136                double right = (double)frame.Pop();137                frame.Push(((double)frame.Pop()) > right);138                return +1;139            }140        }141 142        public static Instruction Create(Type type)143        {144            Debug.Assert(!type.IsEnum);145            switch (type.GetTypeCode())146            {147                case TypeCode.SByte: return s_SByte ??= new GreaterThanSByte();148                case TypeCode.Byte: return s_byte ??= new GreaterThanByte();149                case TypeCode.Char: return s_char ??= new GreaterThanChar();150                case TypeCode.Int16: return s_int16 ??= new GreaterThanInt16();151                case TypeCode.Int32: return s_int32 ??= new GreaterThanInt32();152                case TypeCode.Int64: return s_int64 ??= new GreaterThanInt64();153                case TypeCode.UInt16: return s_UInt16 ??= new GreaterThanUInt16();154                case TypeCode.UInt32: return s_UInt32 ??= new GreaterThanUInt32();155                case TypeCode.UInt64: return s_UInt64 ??= new GreaterThanUInt64();156                case TypeCode.Single: return s_single ??= new GreaterThanSingle();157                case TypeCode.Double: return s_double ??= new GreaterThanDouble();158 159                default:160                    throw Assert.Unreachable;161            }162        }163 164        public override string ToString()165        {166            return "GreaterThan()";167        }168    }169}170