Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LightLambda.cs
Go to the documentation of this file.
7using System.Text;
8
10
11[DebuggerDisplay("{DebugView,nq}")]
12public class LightLambda
13{
14 private sealed class DebugViewPrinter
15 {
16 private readonly Interpreter _interpreter;
17
19
21
23
24 private string _indent = " ";
25
31
32 private void Analyze()
33 {
36 foreach (Instruction instruction in array)
37 {
38 if (instruction is EnterTryCatchFinallyInstruction { Handler: var handler })
39 {
40 AddTryStart(handler.TryStartIndex);
41 AddHandlerExit(handler.TryEndIndex + 1);
42 if (handler.IsFinallyBlockExist)
43 {
44 _handlerEnter.Add(handler.FinallyStartIndex, "finally");
45 AddHandlerExit(handler.FinallyEndIndex);
46 }
47 if (handler.IsCatchBlockExist)
48 {
49 ExceptionHandler[] handlers = handler.Handlers;
51 {
52 _handlerEnter.Add(exceptionHandler.HandlerStartIndex - 1, exceptionHandler.ToString());
53 AddHandlerExit(exceptionHandler.HandlerEndIndex);
55 if (filter != null)
56 {
57 _handlerEnter.Add(filter.StartIndex - 1, "filter");
58 AddHandlerExit(filter.EndIndex);
59 }
60 }
61 }
62 }
64 {
65 AddTryStart(handler2.TryStartIndex);
66 AddHandlerExit(handler2.TryEndIndex + 1);
67 _handlerEnter.Add(handler2.FinallyStartIndex, "fault");
68 AddHandlerExit(handler2.FinallyEndIndex);
69 }
70 }
71 }
72
73 private void AddTryStart(int index)
74 {
76 {
78 }
79 else
80 {
81 _tryStart[index] = value + 1;
82 }
83 }
84
85 private void AddHandlerExit(int index)
86 {
88 }
89
90 private void Indent()
91 {
92 _indent = new string(' ', _indent.Length + 2);
93 }
94
95 private void Dedent()
96 {
97 _indent = new string(' ', _indent.Length - 2);
98 }
99
100 public override string ToString()
101 {
103 string value = _interpreter.Name ?? "lambda_method";
104 stringBuilder.Append("object ").Append(value).AppendLine("(object[])");
105 stringBuilder.AppendLine("{");
106 stringBuilder.Append(" .locals ").Append(_interpreter.LocalCount).AppendLine();
107 stringBuilder.Append(" .maxstack ").Append(_interpreter.Instructions.MaxStackDepth).AppendLine();
108 stringBuilder.Append(" .maxcontinuation ").Append(_interpreter.Instructions.MaxContinuationDepth).AppendLine();
109 stringBuilder.AppendLine();
113 for (int i = 0; i < instructions.Length; i++)
114 {
117 {
118 for (int j = 0; j < value2; j++)
119 {
120 stringBuilder.Append(_indent).AppendLine(".try");
121 stringBuilder.Append(_indent).AppendLine("{");
122 Indent();
123 }
124 }
126 {
127 stringBuilder.Append(_indent).AppendLine(value3);
128 stringBuilder.Append(_indent).AppendLine("{");
129 Indent();
130 }
135 handler.AppendFormatted(_indent);
136 handler.AppendLiteral("IP_");
137 handler.AppendFormatted(i.ToString().PadLeft(4, '0'));
138 handler.AppendLiteral(": ");
139 handler.AppendFormatted(instructionView.GetValue());
140 stringBuilder2.AppendLine(invariantCulture, ref handler);
141 }
143 stringBuilder.AppendLine("}");
144 return stringBuilder.ToString();
145 }
146
147 private void EmitExits(StringBuilder sb, int index)
148 {
150 {
151 for (int i = 0; i < value; i++)
152 {
153 Dedent();
154 sb.Append(_indent).AppendLine("}");
155 }
156 }
157 }
158 }
159
160 private readonly IStrongBox[] _closure;
161
162 private readonly Interpreter _interpreter;
163
165
167
174
184
186 {
188 }
189
190 public object? Run(params object?[] arguments)
191 {
193 for (int i = 0; i < arguments.Length; i++)
194 {
195 interpretedFrame.Data[i] = arguments[i];
196 }
197 InterpretedFrame prevFrame = interpretedFrame.Enter();
198 try
199 {
201 }
202 finally
203 {
204 for (int j = 0; j < arguments.Length; j++)
205 {
206 arguments[j] = interpretedFrame.Data[j];
207 }
208 interpretedFrame.Leave(prevFrame);
209 }
210 return interpretedFrame.Pop();
211 }
212
213 public object? RunVoid(params object?[] arguments)
214 {
216 for (int i = 0; i < arguments.Length; i++)
217 {
218 interpretedFrame.Data[i] = arguments[i];
219 }
220 InterpretedFrame prevFrame = interpretedFrame.Enter();
221 try
222 {
224 }
225 finally
226 {
227 for (int j = 0; j < arguments.Length; j++)
228 {
229 arguments[j] = interpretedFrame.Data[j];
230 }
231 interpretedFrame.Leave(prevFrame);
232 }
233 return null;
234 }
235}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static Delegate CreateObjectArrayDelegate(Type delegateType, Func< object[], object > handler)
static CultureInfo InvariantCulture
object? RunVoid(params object?[] arguments)
readonly LightDelegateCreator _delegateCreator
object? Run(params object?[] arguments)
LightLambda(LightDelegateCreator delegateCreator, IStrongBox[] closure)
StringBuilder Append(char value, int repeatCount)