Terraria v1.4.4.9
Terraria source code documentation
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Macros
NegateInstruction.cs
Go to the documentation of this file.
2
4
5internal abstract class NegateInstruction : Instruction
6{
7 private sealed class NegateInt16 : NegateInstruction
8 {
9 public override int Run(InterpretedFrame frame)
10 {
11 object obj = frame.Pop();
12 if (obj == null)
13 {
14 frame.Push(null);
15 }
16 else
17 {
18 frame.Push((short)(-(short)obj));
19 }
20 return 1;
21 }
22 }
23
24 private sealed class NegateInt32 : NegateInstruction
25 {
26 public override int Run(InterpretedFrame frame)
27 {
28 object obj = frame.Pop();
29 if (obj == null)
30 {
31 frame.Push(null);
32 }
33 else
34 {
35 frame.Push(-(int)obj);
36 }
37 return 1;
38 }
39 }
40
41 private sealed class NegateInt64 : NegateInstruction
42 {
43 public override int Run(InterpretedFrame frame)
44 {
45 object obj = frame.Pop();
46 if (obj == null)
47 {
48 frame.Push(null);
49 }
50 else
51 {
52 frame.Push(-(long)obj);
53 }
54 return 1;
55 }
56 }
57
58 private sealed class NegateSingle : NegateInstruction
59 {
60 public override int Run(InterpretedFrame frame)
61 {
62 object obj = frame.Pop();
63 if (obj == null)
64 {
65 frame.Push(null);
66 }
67 else
68 {
69 frame.Push(0f - (float)obj);
70 }
71 return 1;
72 }
73 }
74
75 private sealed class NegateDouble : NegateInstruction
76 {
77 public override int Run(InterpretedFrame frame)
78 {
79 object obj = frame.Pop();
80 if (obj == null)
81 {
82 frame.Push(null);
83 }
84 else
85 {
86 frame.Push(0.0 - (double)obj);
87 }
88 return 1;
89 }
90 }
91
92 private static Instruction s_Int16;
93
94 private static Instruction s_Int32;
95
96 private static Instruction s_Int64;
97
98 private static Instruction s_Single;
99
100 private static Instruction s_Double;
101
102 public override int ConsumedStack => 1;
103
104 public override int ProducedStack => 1;
105
106 public override string InstructionName => "Negate";
107
109 {
110 }
111
113 {
114 return type.GetNonNullableType().GetTypeCode() switch
115 {
116 TypeCode.Int16 => s_Int16 ?? (s_Int16 = new NegateInt16()),
117 TypeCode.Int32 => s_Int32 ?? (s_Int32 = new NegateInt32()),
118 TypeCode.Int64 => s_Int64 ?? (s_Int64 = new NegateInt64()),
119 TypeCode.Single => s_Single ?? (s_Single = new NegateSingle()),
120 TypeCode.Double => s_Double ?? (s_Double = new NegateDouble()),
121 _ => throw ContractUtils.Unreachable,
122 };
123 }
124}
TypeCode
Definition TypeCode.cs:4