Team Ai
Datasetpublic

MegaBites-AI/Windows-powershell

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes372downloads
StackOperations.cs114 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;17using System.Globalization;18 19namespace System.Management.Automation.Interpreter20{21    internal sealed class LoadObjectInstruction : Instruction22    {23        private readonly object _value;24 25        internal LoadObjectInstruction(object value)26        {27            _value = value;28        }29 30        public override int ProducedStack { get { return 1; } }31 32        public override int Run(InterpretedFrame frame)33        {34            frame.Data[frame.StackIndex++] = _value;35            return +1;36        }37 38        public override string ToString()39        {40            return "LoadObject(" + (_value ?? "null") + ")";41        }42    }43 44    internal sealed class LoadCachedObjectInstruction : Instruction45    {46        private readonly uint _index;47 48        internal LoadCachedObjectInstruction(uint index)49        {50            _index = index;51        }52 53        public override int ProducedStack { get { return 1; } }54 55        public override int Run(InterpretedFrame frame)56        {57            frame.Data[frame.StackIndex++] = frame.Interpreter._objects[_index];58            return +1;59        }60 61        public override string ToDebugString(int instructionIndex, object cookie, Func<int, int> labelIndexer, IList<object> objects)62        {63            return string.Format(CultureInfo.InvariantCulture, "LoadCached({0}: {1})", _index, objects[(int)_index]);64        }65 66        public override string ToString()67        {68            return "LoadCached(" + _index + ")";69        }70    }71 72    internal sealed class PopInstruction : Instruction73    {74        internal static readonly PopInstruction Instance = new PopInstruction();75 76        private PopInstruction() { }77 78        public override int ConsumedStack { get { return 1; } }79 80        public override int Run(InterpretedFrame frame)81        {82            frame.Pop();83            return +1;84        }85 86        public override string ToString()87        {88            return "Pop()";89        }90    }91 92    internal sealed class DupInstruction : Instruction93    {94        internal static readonly DupInstruction Instance = new DupInstruction();95 96        private DupInstruction() { }97 98        public override int ConsumedStack { get { return 0; } }99 100        public override int ProducedStack { get { return 1; } }101 102        public override int Run(InterpretedFrame frame)103        {104            frame.Data[frame.StackIndex++] = frame.Peek();105            return +1;106        }107 108        public override string ToString()109        {110            return "Dup()";111        }112    }113}114