IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
StackState.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2014 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24
25namespace IKVM.Runtime
26{
27
29 {
30
32 readonly int _pc;
33 int _sp;
34
40 internal StackState(InstructionState[] state, int pc)
41 {
42 _state = state;
43 _pc = pc;
44 _sp = state[_pc].GetStackHeight();
45 }
46
47 internal RuntimeJavaType PeekType()
48 {
49 if (_sp == 0)
50 throw new VerifyError("Unable to pop operand off an empty stack");
51
52 var type = _state[_pc].GetStackByIndex(_sp - 1);
53 if (RuntimeVerifierJavaType.IsThis(type))
54 type = ((RuntimeVerifierJavaType)type).UnderlyingType;
55
56 return type;
57 }
58
59 internal RuntimeJavaType PopAnyType()
60 {
61 if (_sp == 0)
62 throw new VerifyError("Unable to pop operand off an empty stack");
63
64 var type = _state[_pc].GetStackByIndex(--_sp);
65
66 if (RuntimeVerifierJavaType.IsThis(type))
67 type = ((RuntimeVerifierJavaType)type).UnderlyingType;
68
69 if (RuntimeVerifierJavaType.IsFaultBlockException(type))
70 {
71 RuntimeVerifierJavaType.ClearFaultBlockException(type);
72 type = type.Context.JavaBase.TypeOfjavaLangThrowable;
73 }
74
75 return type;
76 }
77
78 internal RuntimeJavaType PopType(RuntimeJavaType baseType)
79 {
80 return InstructionState.PopTypeImpl(baseType, PopAnyType());
81 }
82
83 // NOTE this can *not* be used to pop double or long
84 internal RuntimeJavaType PopType()
85 {
86 return InstructionState.PopTypeImpl(PopAnyType());
87 }
88
89 internal void PopInt()
90 {
91 InstructionState.PopIntImpl(PopAnyType());
92 }
93
94 internal void PopFloat()
95 {
96 InstructionState.PopFloatImpl(PopAnyType());
97 }
98
99 internal void PopDouble()
100 {
101 InstructionState.PopDoubleImpl(PopAnyType());
102 }
103
104 internal void PopLong()
105 {
106 InstructionState.PopLongImpl(PopAnyType());
107 }
108
109 internal RuntimeJavaType PopArrayType()
110 {
111 return InstructionState.PopArrayTypeImpl(PopAnyType());
112 }
113
118 internal RuntimeJavaType PopObjectType()
119 {
120 return InstructionState.PopObjectTypeImpl(PopAnyType());
121 }
122
128 internal RuntimeJavaType PopObjectType(RuntimeJavaType baseType)
129 {
130 return InstructionState.PopObjectTypeImpl(baseType, PopObjectType());
131 }
132
133 }
134
135}
readonly InstructionState[] _state
Definition StackState.cs:31