Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
GotoInstruction.cs
Go to the documentation of this file.
2
4{
5 private static readonly GotoInstruction[] s_cache = new GotoInstruction[256];
6
7 private readonly bool _hasResult;
8
9 private readonly bool _hasValue;
10
11 private readonly bool _labelTargetGetsValue;
12
13 public override string InstructionName => "Goto";
14
15 public override int ConsumedStack
16 {
17 get
18 {
19 if (!_hasValue)
20 {
21 return 0;
22 }
23 return 1;
24 }
25 }
26
27 public override int ProducedStack
28 {
29 get
30 {
31 if (!_hasResult)
32 {
33 return 0;
34 }
35 return 1;
36 }
37 }
38
39 private GotoInstruction(int targetIndex, bool hasResult, bool hasValue, bool labelTargetGetsValue)
40 : base(targetIndex)
41 {
42 _hasResult = hasResult;
43 _hasValue = hasValue;
44 _labelTargetGetsValue = labelTargetGetsValue;
45 }
46
47 internal static GotoInstruction Create(int labelIndex, bool hasResult, bool hasValue, bool labelTargetGetsValue)
48 {
49 if (labelIndex < 32)
50 {
51 int num = (8 * labelIndex) | (labelTargetGetsValue ? 4 : 0) | (hasResult ? 2 : 0) | (hasValue ? 1 : 0);
52 return s_cache[num] ?? (s_cache[num] = new GotoInstruction(labelIndex, hasResult, hasValue, labelTargetGetsValue));
53 }
54 return new GotoInstruction(labelIndex, hasResult, hasValue, labelTargetGetsValue);
55 }
56
57 public override int Run(InterpretedFrame frame)
58 {
59 object obj = (_hasValue ? frame.Pop() : Interpreter.NoValue);
60 return frame.Goto(_labelIndex, _labelTargetGetsValue ? obj : Interpreter.NoValue, gotoExceptionHandler: false);
61 }
62}
GotoInstruction(int targetIndex, bool hasResult, bool hasValue, bool labelTargetGetsValue)
static GotoInstruction Create(int labelIndex, bool hasResult, bool hasValue, bool labelTargetGetsValue)
override int Run(InterpretedFrame frame)
int Goto(int labelIndex, object value, bool gotoExceptionHandler)