Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ActionCallInstruction.cs
Go to the documentation of this file.
2
4
5internal sealed class ActionCallInstruction : CallInstruction
6{
7 private readonly Action _target;
8
9 public override int ArgumentCount => 0;
10
11 public override int ProducedStack => 0;
12
14 {
15 _target = (Action)target.CreateDelegate(typeof(Action));
16 }
17
18 public override int Run(InterpretedFrame frame)
19 {
20 _target();
21 frame.StackIndex = frame.StackIndex;
22 return 1;
23 }
24
25 public override string ToString()
26 {
27 return "Call(" + _target.Method?.ToString() + ")";
28 }
29}
30internal sealed class ActionCallInstruction<T0> : CallInstruction
31{
32 private readonly bool _isInstance;
33
34 private readonly Action<T0> _target;
35
36 public override int ProducedStack => 0;
37
38 public override int ArgumentCount => 1;
39
41 {
42 _isInstance = !target.IsStatic;
43 _target = (Action<T0>)target.CreateDelegate(typeof(Action<T0>));
44 }
45
46 public override int Run(InterpretedFrame frame)
47 {
48 object obj = frame.Data[frame.StackIndex - 1];
49 if (_isInstance)
50 {
52 }
53 if (_isInstance && CallInstruction.TryGetLightLambdaTarget(obj, out var lightLambda))
54 {
55 InterpretLambdaInvoke(lightLambda, Array.Empty<object>());
56 }
57 else
58 {
59 _target((T0)obj);
60 }
61 frame.StackIndex--;
62 return 1;
63 }
64
65 public override string ToString()
66 {
67 return "Call(" + _target.Method?.ToString() + ")";
68 }
69}
70internal sealed class ActionCallInstruction<T0, T1> : CallInstruction
71{
72 private readonly bool _isInstance;
73
74 private readonly Action<T0, T1> _target;
75
76 public override int ProducedStack => 0;
77
78 public override int ArgumentCount => 2;
79
81 {
82 _isInstance = !target.IsStatic;
83 _target = (Action<T0, T1>)target.CreateDelegate(typeof(Action<T0, T1>));
84 }
85
86 public override int Run(InterpretedFrame frame)
87 {
88 object obj = frame.Data[frame.StackIndex - 2];
89 if (_isInstance)
90 {
92 }
93 if (_isInstance && CallInstruction.TryGetLightLambdaTarget(obj, out var lightLambda))
94 {
95 InterpretLambdaInvoke(lightLambda, new object[1] { frame.Data[frame.StackIndex - 1] });
96 }
97 else
98 {
99 _target((T0)obj, (T1)frame.Data[frame.StackIndex - 1]);
100 }
101 frame.StackIndex -= 2;
102 return 1;
103 }
104
105 public override string ToString()
106 {
107 return "Call(" + _target.Method?.ToString() + ")";
108 }
109}
110internal sealed class ActionCallInstruction<T0, T1, T2> : CallInstruction
111{
112 private readonly bool _isInstance;
113
114 private readonly Action<T0, T1, T2> _target;
115
116 public override int ProducedStack => 0;
117
118 public override int ArgumentCount => 3;
119
121 {
122 _isInstance = !target.IsStatic;
123 _target = (Action<T0, T1, T2>)target.CreateDelegate(typeof(Action<T0, T1, T2>));
124 }
125
126 public override int Run(InterpretedFrame frame)
127 {
128 object obj = frame.Data[frame.StackIndex - 3];
129 if (_isInstance)
130 {
132 }
133 if (_isInstance && CallInstruction.TryGetLightLambdaTarget(obj, out var lightLambda))
134 {
135 InterpretLambdaInvoke(lightLambda, new object[2]
136 {
137 frame.Data[frame.StackIndex - 2],
138 frame.Data[frame.StackIndex - 1]
139 });
140 }
141 else
142 {
143 _target((T0)obj, (T1)frame.Data[frame.StackIndex - 2], (T2)frame.Data[frame.StackIndex - 1]);
144 }
145 frame.StackIndex -= 3;
146 return 1;
147 }
148
149 public override string ToString()
150 {
151 return "Call(" + _target.Method?.ToString() + ")";
152 }
153}
154internal sealed class ActionCallInstruction<T0, T1, T2, T3> : CallInstruction
155{
156 private readonly bool _isInstance;
157
158 private readonly Action<T0, T1, T2, T3> _target;
159
160 public override int ProducedStack => 0;
161
162 public override int ArgumentCount => 4;
163
165 {
166 _isInstance = !target.IsStatic;
167 _target = (Action<T0, T1, T2, T3>)target.CreateDelegate(typeof(Action<T0, T1, T2, T3>));
168 }
169
170 public override int Run(InterpretedFrame frame)
171 {
172 object obj = frame.Data[frame.StackIndex - 4];
173 if (_isInstance)
174 {
176 }
177 if (_isInstance && CallInstruction.TryGetLightLambdaTarget(obj, out var lightLambda))
178 {
179 InterpretLambdaInvoke(lightLambda, new object[3]
180 {
181 frame.Data[frame.StackIndex - 3],
182 frame.Data[frame.StackIndex - 2],
183 frame.Data[frame.StackIndex - 1]
184 });
185 }
186 else
187 {
188 _target((T0)obj, (T1)frame.Data[frame.StackIndex - 3], (T2)frame.Data[frame.StackIndex - 2], (T3)frame.Data[frame.StackIndex - 1]);
189 }
190 frame.StackIndex -= 4;
191 return 1;
192 }
193
194 public override string ToString()
195 {
196 return "Call(" + _target.Method?.ToString() + ")";
197 }
198}
object InterpretLambdaInvoke(LightLambda targetLambda, object[] args)
static bool TryGetLightLambdaTarget(object instance, [NotNullWhen(true)] out LightLambda lightLambda)
virtual Delegate CreateDelegate(Type delegateType)
Definition MethodInfo.cs:48
delegate void Action()