1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
5 * This source code is subject to terms and conditions of the Apache License, Version 2.0. A
6 * copy of the license can be found in the License.html file at the root of this distribution. If
7 * you cannot locate the Apache License, Version 2.0, please send an email to
8 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound
9 * by the terms of the Apache License, Version 2.0.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
16 using System.Collections.Generic;
18 using System.Diagnostics;
19 using Microsoft.Scripting.Utils;
20 namespace Microsoft.Scripting.Interpreter {
21 internal sealed class LoadObjectInstruction : Instruction {
22 private readonly object _value;
24 internal LoadObjectInstruction(object value) {
28 public override int ProducedStack { get { return 1; } }
30 public override int Run(InterpretedFrame frame) {
31 frame.Data[frame.StackIndex++] = _value;
35 public override string ToString() {
36 return "LoadObject(" + (_value ?? "null") + ")";
40 internal sealed class LoadCachedObjectInstruction : Instruction {
41 private readonly uint _index;
43 internal LoadCachedObjectInstruction(uint index) {
47 public override int ProducedStack { get { return 1; } }
49 public override int Run(InterpretedFrame frame) {
50 frame.Data[frame.StackIndex++] = frame.Interpreter._objects[_index];
54 public override string ToDebugString(int instructionIndex, object cookie, Func<int, int> labelIndexer, IList<object> objects) {
55 return String.Format("LoadCached({0}: {1})", _index, objects[(int)_index]);
58 public override string ToString() {
59 return "LoadCached(" + _index + ")";
63 internal sealed class PopInstruction : Instruction {
64 internal static readonly PopInstruction Instance = new PopInstruction();
66 private PopInstruction() { }
68 public override int ConsumedStack { get { return 1; } }
70 public override int Run(InterpretedFrame frame) {
75 public override string ToString() {
80 // NOTE: Consider caching if used frequently
81 internal sealed class PopNInstruction : Instruction {
82 private readonly int _n;
84 internal PopNInstruction(int n) {
88 public override int ConsumedStack { get { return _n; } }
90 public override int Run(InterpretedFrame frame) {
95 public override string ToString() {
96 return "Pop(" + _n + ")";
100 internal sealed class DupInstruction : Instruction {
101 internal readonly static DupInstruction Instance = new DupInstruction();
103 private DupInstruction() { }
105 public override int ConsumedStack { get { return 0; } }
106 public override int ProducedStack { get { return 1; } }
108 public override int Run(InterpretedFrame frame) {
109 frame.Data[frame.StackIndex] = frame.Peek();
114 public override string ToString() {