Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
SubInstruction.cs
Go to the documentation of this file.
2
4
5internal abstract class SubInstruction : Instruction
6{
7 private sealed class SubInt16 : SubInstruction
8 {
9 public override int Run(InterpretedFrame frame)
10 {
11 int stackIndex = frame.StackIndex;
12 object[] data = frame.Data;
13 object obj = data[stackIndex - 2];
14 if (obj != null)
15 {
16 object obj2 = data[stackIndex - 1];
17 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)(short)((short)obj - (short)obj2)));
18 }
19 frame.StackIndex = stackIndex - 1;
20 return 1;
21 }
22 }
23
24 private sealed class SubInt32 : SubInstruction
25 {
26 public override int Run(InterpretedFrame frame)
27 {
28 int stackIndex = frame.StackIndex;
29 object[] data = frame.Data;
30 object obj = data[stackIndex - 2];
31 if (obj != null)
32 {
33 object obj2 = data[stackIndex - 1];
34 data[stackIndex - 2] = ((obj2 == null) ? null : ScriptingRuntimeHelpers.Int32ToObject((int)obj - (int)obj2));
35 }
36 frame.StackIndex = stackIndex - 1;
37 return 1;
38 }
39 }
40
41 private sealed class SubInt64 : SubInstruction
42 {
43 public override int Run(InterpretedFrame frame)
44 {
45 int stackIndex = frame.StackIndex;
46 object[] data = frame.Data;
47 object obj = data[stackIndex - 2];
48 if (obj != null)
49 {
50 object obj2 = data[stackIndex - 1];
51 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)((long)obj - (long)obj2)));
52 }
53 frame.StackIndex = stackIndex - 1;
54 return 1;
55 }
56 }
57
58 private sealed class SubUInt16 : SubInstruction
59 {
60 public override int Run(InterpretedFrame frame)
61 {
62 int stackIndex = frame.StackIndex;
63 object[] data = frame.Data;
64 object obj = data[stackIndex - 2];
65 if (obj != null)
66 {
67 object obj2 = data[stackIndex - 1];
68 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)(ushort)((ushort)obj - (ushort)obj2)));
69 }
70 frame.StackIndex = stackIndex - 1;
71 return 1;
72 }
73 }
74
75 private sealed class SubUInt32 : SubInstruction
76 {
77 public override int Run(InterpretedFrame frame)
78 {
79 int stackIndex = frame.StackIndex;
80 object[] data = frame.Data;
81 object obj = data[stackIndex - 2];
82 if (obj != null)
83 {
84 object obj2 = data[stackIndex - 1];
85 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)((uint)obj - (uint)obj2)));
86 }
87 frame.StackIndex = stackIndex - 1;
88 return 1;
89 }
90 }
91
92 private sealed class SubUInt64 : SubInstruction
93 {
94 public override int Run(InterpretedFrame frame)
95 {
96 int stackIndex = frame.StackIndex;
97 object[] data = frame.Data;
98 object obj = data[stackIndex - 2];
99 if (obj != null)
100 {
101 object obj2 = data[stackIndex - 1];
102 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)((ulong)obj - (ulong)obj2)));
103 }
104 frame.StackIndex = stackIndex - 1;
105 return 1;
106 }
107 }
108
109 private sealed class SubSingle : SubInstruction
110 {
111 public override int Run(InterpretedFrame frame)
112 {
113 int stackIndex = frame.StackIndex;
114 object[] data = frame.Data;
115 object obj = data[stackIndex - 2];
116 if (obj != null)
117 {
118 object obj2 = data[stackIndex - 1];
119 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)((float)obj - (float)obj2)));
120 }
121 frame.StackIndex = stackIndex - 1;
122 return 1;
123 }
124 }
125
126 private sealed class SubDouble : SubInstruction
127 {
128 public override int Run(InterpretedFrame frame)
129 {
130 int stackIndex = frame.StackIndex;
131 object[] data = frame.Data;
132 object obj = data[stackIndex - 2];
133 if (obj != null)
134 {
135 object obj2 = data[stackIndex - 1];
136 data[stackIndex - 2] = ((obj2 == null) ? null : ((object)((double)obj - (double)obj2)));
137 }
138 frame.StackIndex = stackIndex - 1;
139 return 1;
140 }
141 }
142
143 private static Instruction s_Int16;
144
145 private static Instruction s_Int32;
146
147 private static Instruction s_Int64;
148
149 private static Instruction s_UInt16;
150
151 private static Instruction s_UInt32;
152
153 private static Instruction s_UInt64;
154
155 private static Instruction s_Single;
156
157 private static Instruction s_Double;
158
159 public override int ConsumedStack => 2;
160
161 public override int ProducedStack => 1;
162
163 public override string InstructionName => "Sub";
164
166 {
167 }
168
170 {
171 return type.GetNonNullableType().GetTypeCode() switch
172 {
173 TypeCode.Int16 => s_Int16 ?? (s_Int16 = new SubInt16()),
174 TypeCode.Int32 => s_Int32 ?? (s_Int32 = new SubInt32()),
175 TypeCode.Int64 => s_Int64 ?? (s_Int64 = new SubInt64()),
176 TypeCode.UInt16 => s_UInt16 ?? (s_UInt16 = new SubUInt16()),
177 TypeCode.UInt32 => s_UInt32 ?? (s_UInt32 = new SubUInt32()),
178 TypeCode.UInt64 => s_UInt64 ?? (s_UInt64 = new SubUInt64()),
179 TypeCode.Single => s_Single ?? (s_Single = new SubSingle()),
180 TypeCode.Double => s_Double ?? (s_Double = new SubDouble()),
181 _ => throw ContractUtils.Unreachable,
182 };
183 }
184}
TypeCode
Definition TypeCode.cs:4