Fix XMM scanning on Mac x86.
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Interpreter / Instructions / StackOperations.cs
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. 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.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 using System.Collections.Generic;
17 using System;
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;
23
24         internal LoadObjectInstruction(object value) {
25             _value = value;
26         }
27
28         public override int ProducedStack { get { return 1; } }
29
30         public override int Run(InterpretedFrame frame) {
31             frame.Data[frame.StackIndex++] = _value;
32             return +1;
33         }
34
35         public override string ToString() {
36             return "LoadObject(" + (_value ?? "null") + ")";
37         }
38     }
39
40     internal sealed class LoadCachedObjectInstruction : Instruction {
41         private readonly uint _index;
42
43         internal LoadCachedObjectInstruction(uint index) {
44             _index = index;
45         }
46
47         public override int ProducedStack { get { return 1; } }
48
49         public override int Run(InterpretedFrame frame) {
50             frame.Data[frame.StackIndex++] = frame.Interpreter._objects[_index];
51             return +1;
52         }
53
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]);
56         }
57         
58         public override string ToString() {
59             return "LoadCached(" + _index + ")";
60         }
61     }
62
63     internal sealed class PopInstruction : Instruction {
64         internal static readonly PopInstruction Instance = new PopInstruction();
65
66         private PopInstruction() { }
67
68         public override int ConsumedStack { get { return 1; } }
69
70         public override int Run(InterpretedFrame frame) {
71             frame.Pop();
72             return +1;
73         }
74
75         public override string ToString() {
76             return "Pop()";
77         }
78     }
79
80     // NOTE: Consider caching if used frequently
81     internal sealed class PopNInstruction : Instruction {
82         private readonly int _n;
83
84         internal PopNInstruction(int n) {
85             _n = n;
86         }
87
88         public override int ConsumedStack { get { return _n; } }
89
90         public override int Run(InterpretedFrame frame) {
91             frame.Pop(_n);
92             return +1;
93         }
94
95         public override string ToString() {
96             return "Pop(" + _n + ")";
97         }
98     }
99
100     internal sealed class DupInstruction : Instruction {
101         internal readonly static DupInstruction Instance = new DupInstruction();
102
103         private DupInstruction() { }
104
105         public override int ConsumedStack { get { return 0; } }
106         public override int ProducedStack { get { return 1; } }
107
108         public override int Run(InterpretedFrame frame) {
109             frame.Data[frame.StackIndex] = frame.Peek();
110                         frame.StackIndex++;
111             return +1;
112         }
113
114         public override string ToString() {
115             return "Dup()";
116         }
117     }
118 }