Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
QuoteInstruction.cs
Go to the documentation of this file.
4
6
7internal sealed class QuoteInstruction : Instruction
8{
9 private sealed class ExpressionQuoter : ExpressionVisitor
10 {
12
13 private readonly InterpretedFrame _frame;
14
16
22
23 protected internal override Expression VisitLambda<T>(Expression<T> node)
24 {
25 if (node.ParameterCount > 0)
26 {
28 int i = 0;
29 for (int parameterCount = node.ParameterCount; i < parameterCount; i++)
30 {
31 hashSet.Add(node.GetParameter(i));
32 }
34 }
36 if (node.ParameterCount > 0)
37 {
39 }
40 if (expression == node.Body)
41 {
42 return node;
43 }
44 return node.Rewrite(expression, null);
45 }
46
47 protected internal override Expression VisitBlock(BlockExpression node)
48 {
49 if (node.Variables.Count > 0)
50 {
52 }
54 if (node.Variables.Count > 0)
55 {
57 }
58 if (array == null)
59 {
60 return node;
61 }
62 return node.Rewrite(node.Variables, array);
63 }
64
66 {
67 if (node.Variable != null)
68 {
69 _shadowedVars.Push(new HashSet<ParameterExpression> { node.Variable });
70 }
73 if (node.Variable != null)
74 {
76 }
77 if (expression == node.Body && expression2 == node.Filter)
78 {
79 return node;
80 }
82 }
83
85 {
86 int count = node.Variables.Count;
89 int[] array = new int[count];
90 for (int i = 0; i < array.Length; i++)
91 {
92 IStrongBox box = GetBox(node.Variables[i]);
93 if (box == null)
94 {
95 array[i] = list2.Count;
96 list2.Add(node.Variables[i]);
97 }
98 else
99 {
100 array[i] = -1 - list.Count;
101 list.Add(box);
102 }
103 }
104 if (list.Count == 0)
105 {
106 return node;
107 }
109 if (list2.Count == 0)
110 {
111 return constantExpression;
112 }
114 }
115
120
122 {
124 if (box == null)
125 {
126 return node;
127 }
129 }
130
132 {
134 {
135 if (value.InClosure)
136 {
137 return _frame.Closure[value.Index];
138 }
139 return (IStrongBox)_frame.Data[value.Index];
140 }
141 return null;
142 }
143 }
144
145 private readonly Expression _operand;
146
148
149 public override int ProducedStack => 1;
150
151 public override string InstructionName => "Quote";
152
158
159 public override int Run(InterpretedFrame frame)
160 {
162 if (_hoistedVariables != null)
163 {
165 }
166 frame.Push(expression);
167 return 1;
168 }
169}
bool TryGetValue(TKey key, [MaybeNullWhen(false)] out TValue value)
void Add(TKey key, TValue value)
static Expression[] VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)
virtual ? Expression Visit(Expression? node)
static ConstantExpression Constant(object? value)
static CatchBlock MakeCatchBlock(Type type, ParameterExpression? variable, Expression body, Expression? filter)
static UnaryExpression Convert(Expression expression, Type type)
static RuntimeVariablesExpression RuntimeVariables(params ParameterExpression[] variables)
static InvocationExpression Invoke(Expression expression)
static IRuntimeVariables MergeRuntimeVariables(IRuntimeVariables first, IRuntimeVariables second, int[] indexes)
readonly Stack< HashSet< ParameterExpression > > _shadowedVars
override Expression VisitRuntimeVariables(RuntimeVariablesExpression node)
readonly Dictionary< ParameterExpression, LocalVariable > _variables
ExpressionQuoter(Dictionary< ParameterExpression, LocalVariable > hoistedVariables, InterpretedFrame frame)
readonly Dictionary< ParameterExpression, LocalVariable > _hoistedVariables
QuoteInstruction(Expression operand, Dictionary< ParameterExpression, LocalVariable > hoistedVariables)
static MemberExpression GetStrongBoxValueField(Expression strongbox)
Definition Utils.cs:88