Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
Instruction.cs89 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.Collections.Generic;17 18namespace System.Management.Automation.Interpreter19{20#nullable enable21    internal interface IInstructionProvider22    {23        void AddInstructions(LightCompiler compiler);24    }25#nullable restore26 27    internal abstract class Instruction28    {29        public const int UnknownInstrIndex = int.MaxValue;30 31        public virtual int ConsumedStack { get { return 0; } }32 33        public virtual int ProducedStack { get { return 0; } }34 35        public virtual int ConsumedContinuations { get { return 0; } }36 37        public virtual int ProducedContinuations { get { return 0; } }38 39        public int StackBalance40        {41            get { return ProducedStack - ConsumedStack; }42        }43 44        public int ContinuationsBalance45        {46            get { return ProducedContinuations - ConsumedContinuations; }47        }48 49        public abstract int Run(InterpretedFrame frame);50 51        public virtual string InstructionName52        {53            get { return GetType().Name.Replace("Instruction", string.Empty); }54        }55 56        public override string ToString()57        {58            return InstructionName + "()";59        }60 61        public virtual string ToDebugString(int instructionIndex, object cookie, Func<int, int> labelIndexer, IList<object> objects)62        {63            return ToString();64        }65 66        public virtual object GetDebugCookie(LightCompiler compiler)67        {68            return null;69        }70    }71 72    internal sealed class NotInstruction : Instruction73    {74        public static readonly Instruction Instance = new NotInstruction();75 76        private NotInstruction() { }77 78        public override int ConsumedStack { get { return 1; } }79 80        public override int ProducedStack { get { return 1; } }81 82        public override int Run(InterpretedFrame frame)83        {84            frame.Push((bool)frame.Pop() ? ScriptingRuntimeHelpers.False : ScriptingRuntimeHelpers.True);85            return +1;86        }87    }88}89