MegaBites-AI/Windows-powershell
0372
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 MulInstruction : Instruction21 {22 private static Instruction s_int16, s_int32, s_int64, 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 MulInstruction()29 {30 }31 32 internal sealed class MulInt32 : MulInstruction33 {34 public override int Run(InterpretedFrame frame)35 {36 object l = frame.Data[frame.StackIndex - 2];37 object r = frame.Data[frame.StackIndex - 1];38 frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(unchecked((Int32)l * (Int32)r));39 frame.StackIndex--;40 return +1;41 }42 }43 44 internal sealed class MulInt16 : MulInstruction45 {46 public override int Run(InterpretedFrame frame)47 {48 object l = frame.Data[frame.StackIndex - 2];49 object r = frame.Data[frame.StackIndex - 1];50 frame.Data[frame.StackIndex - 2] = (Int16)unchecked((Int16)l * (Int16)r);51 frame.StackIndex--;52 return +1;53 }54 }55 56 internal sealed class MulInt64 : MulInstruction57 {58 public override int Run(InterpretedFrame frame)59 {60 object l = frame.Data[frame.StackIndex - 2];61 object r = frame.Data[frame.StackIndex - 1];62 frame.Data[frame.StackIndex - 2] = (Int64)unchecked((Int64)l * (Int64)r);63 frame.StackIndex--;64 return +1;65 }66 }67 68 internal sealed class MulUInt16 : MulInstruction69 {70 public override int Run(InterpretedFrame frame)71 {72 object l = frame.Data[frame.StackIndex - 2];73 object r = frame.Data[frame.StackIndex - 1];74 frame.Data[frame.StackIndex - 2] = (UInt16)unchecked((UInt16)l * (UInt16)r);75 frame.StackIndex--;76 return +1;77 }78 }79 80 internal sealed class MulUInt32 : MulInstruction81 {82 public override int Run(InterpretedFrame frame)83 {84 object l = frame.Data[frame.StackIndex - 2];85 object r = frame.Data[frame.StackIndex - 1];86 frame.Data[frame.StackIndex - 2] = (UInt32)unchecked((UInt32)l * (UInt32)r);87 frame.StackIndex--;88 return +1;89 }90 }91 92 internal sealed class MulUInt64 : MulInstruction93 {94 public override int Run(InterpretedFrame frame)95 {96 object l = frame.Data[frame.StackIndex - 2];97 object r = frame.Data[frame.StackIndex - 1];98 frame.Data[frame.StackIndex - 2] = (UInt64)unchecked((Int16)l * (Int16)r);99 frame.StackIndex--;100 return +1;101 }102 }103 104 internal sealed class MulSingle : MulInstruction105 {106 public override int Run(InterpretedFrame frame)107 {108 object l = frame.Data[frame.StackIndex - 2];109 object r = frame.Data[frame.StackIndex - 1];110 frame.Data[frame.StackIndex - 2] = (Single)((Single)l * (Single)r);111 frame.StackIndex--;112 return +1;113 }114 }115 116 internal sealed class MulDouble : MulInstruction117 {118 public override int Run(InterpretedFrame frame)119 {120 object l = frame.Data[frame.StackIndex - 2];121 object r = frame.Data[frame.StackIndex - 1];122 frame.Data[frame.StackIndex - 2] = (double)l * (double)r;123 frame.StackIndex--;124 return +1;125 }126 }127 128 public static Instruction Create(Type type)129 {130 Debug.Assert(!type.IsEnum);131 switch (type.GetTypeCode())132 {133 case TypeCode.Int16: return s_int16 ??= new MulInt16();134 case TypeCode.Int32: return s_int32 ??= new MulInt32();135 case TypeCode.Int64: return s_int64 ??= new MulInt64();136 case TypeCode.UInt16: return s_UInt16 ??= new MulUInt16();137 case TypeCode.UInt32: return s_UInt32 ??= new MulUInt32();138 case TypeCode.UInt64: return s_UInt64 ??= new MulUInt64();139 case TypeCode.Single: return s_single ??= new MulSingle();140 case TypeCode.Double: return s_double ??= new MulDouble();141 142 default:143 throw Assert.Unreachable;144 }145 }146 147 public override string ToString()148 {149 return "Mul()";150 }151 }152 153 internal abstract class MulOvfInstruction : Instruction154 {155 private static Instruction s_int16, s_int32, s_int64, s_UInt16, s_UInt32, s_UInt64, s_single, s_double;156 157 public override int ConsumedStack { get { return 2; } }158 159 public override int ProducedStack { get { return 1; } }160 161 private MulOvfInstruction()162 {163 }164 165 internal sealed class MulOvfInt32 : MulOvfInstruction166 {167 public override int Run(InterpretedFrame frame)168 {169 object l = frame.Data[frame.StackIndex - 2];170 object r = frame.Data[frame.StackIndex - 1];171 frame.Data[frame.StackIndex - 2] = ScriptingRuntimeHelpers.Int32ToObject(checked((Int32)l * (Int32)r));172 frame.StackIndex--;173 return +1;174 }175 }176 177 internal sealed class MulOvfInt16 : MulOvfInstruction178 {179 public override int Run(InterpretedFrame frame)180 {181 object l = frame.Data[frame.StackIndex - 2];182 object r = frame.Data[frame.StackIndex - 1];183 frame.Data[frame.StackIndex - 2] = (Int16)checked((Int16)l * (Int16)r);184 frame.StackIndex--;185 return +1;186 }187 }188 189 internal sealed class MulOvfInt64 : MulOvfInstruction190 {191 public override int Run(InterpretedFrame frame)192 {193 object l = frame.Data[frame.StackIndex - 2];194 object r = frame.Data[frame.StackIndex - 1];195 frame.Data[frame.StackIndex - 2] = (Int64)checked((Int64)l * (Int64)r);196 frame.StackIndex--;197 return +1;198 }199 }200 201 internal sealed class MulOvfUInt16 : MulOvfInstruction202 {203 public override int Run(InterpretedFrame frame)204 {205 object l = frame.Data[frame.StackIndex - 2];206 object r = frame.Data[frame.StackIndex - 1];207 frame.Data[frame.StackIndex - 2] = (UInt16)checked((UInt16)l * (UInt16)r);208 frame.StackIndex--;209 return +1;210 }211 }212 213 internal sealed class MulOvfUInt32 : MulOvfInstruction214 {215 public override int Run(InterpretedFrame frame)216 {217 object l = frame.Data[frame.StackIndex - 2];218 object r = frame.Data[frame.StackIndex - 1];219 frame.Data[frame.StackIndex - 2] = (UInt32)checked((UInt32)l * (UInt32)r);220 frame.StackIndex--;221 return +1;222 }223 }224 225 internal sealed class MulOvfUInt64 : MulOvfInstruction226 {227 public override int Run(InterpretedFrame frame)228 {229 object l = frame.Data[frame.StackIndex - 2];230 object r = frame.Data[frame.StackIndex - 1];231 frame.Data[frame.StackIndex - 2] = (UInt64)checked((Int16)l * (Int16)r);232 frame.StackIndex--;233 return +1;234 }235 }236 237 internal sealed class MulOvfSingle : MulOvfInstruction238 {239 public override int Run(InterpretedFrame frame)240 {241 object l = frame.Data[frame.StackIndex - 2];242 object r = frame.Data[frame.StackIndex - 1];243 frame.Data[frame.StackIndex - 2] = (Single)((Single)l * (Single)r);244 frame.StackIndex--;245 return +1;246 }247 }248 249 internal sealed class MulOvfDouble : MulOvfInstruction250 {251 public override int Run(InterpretedFrame frame)252 {253 object l = frame.Data[frame.StackIndex - 2];254 object r = frame.Data[frame.StackIndex - 1];255 frame.Data[frame.StackIndex - 2] = (double)l * (double)r;256 frame.StackIndex--;257 return +1;258 }259 }260 261 public static Instruction Create(Type type)262 {263 Debug.Assert(!type.IsEnum);264 switch (type.GetTypeCode())265 {266 case TypeCode.Int16: return s_int16 ??= new MulOvfInt16();267 case TypeCode.Int32: return s_int32 ??= new MulOvfInt32();268 case TypeCode.Int64: return s_int64 ??= new MulOvfInt64();269 case TypeCode.UInt16: return s_UInt16 ??= new MulOvfUInt16();270 case TypeCode.UInt32: return s_UInt32 ??= new MulOvfUInt32();271 case TypeCode.UInt64: return s_UInt64 ??= new MulOvfUInt64();272 case TypeCode.Single: return s_single ??= new MulOvfSingle();273 case TypeCode.Double: return s_double ??= new MulOvfDouble();274 275 default:276 throw Assert.Unreachable;277 }278 }279 280 public override string ToString()281 {282 return "MulOvf()";283 }284 }285}286 