// Emits creation of the hoisted local storage private void EmitNewHoistedLocals(LambdaCompiler lc) { if (_hoistedLocals == null) { return; } // create the array lc.IL.EmitInt(_hoistedLocals.Variables.Count); lc.IL.Emit(OpCodes.Newarr, typeof(object)); // initialize all elements int i = 0; foreach (ParameterExpression v in _hoistedLocals.Variables) { // array[i] = new StrongBox<T>(...); lc.IL.Emit(OpCodes.Dup); lc.IL.EmitInt(i++); Type boxType = typeof(StrongBox <>).MakeGenericType(v.Type); if (IsMethod && lc.Parameters.Contains(v)) { // array[i] = new StrongBox<T>(argument); int index = lc.Parameters.IndexOf(v); lc.EmitLambdaArgument(index); lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(new Type[] { v.Type })); } else if (v == _hoistedLocals.ParentVariable) { // array[i] = new StrongBox<T>(closure.Locals); ResolveVariable(v, _closureHoistedLocals).EmitLoad(); lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(new Type[] { v.Type })); } else { // array[i] = new StrongBox<T>(); lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(Type.EmptyTypes)); } // if we want to cache this into a local, do it now if (ShouldCache(v)) { lc.IL.Emit(OpCodes.Dup); CacheBoxToLocal(lc, v); } lc.IL.Emit(OpCodes.Stelem_Ref); } // store it EmitSet(_hoistedLocals.SelfVariable); }
private void EmitNewHoistedLocals(LambdaCompiler lc) { if (this._hoistedLocals != null) { lc.IL.EmitInt(this._hoistedLocals.Variables.Count); lc.IL.Emit(OpCodes.Newarr, typeof(object)); int num = 0; foreach (ParameterExpression expression in this._hoistedLocals.Variables) { lc.IL.Emit(OpCodes.Dup); lc.IL.EmitInt(num++); Type type = typeof(StrongBox <>).MakeGenericType(new Type[] { expression.Type }); if (this.IsMethod && lc.Parameters.Contains(expression)) { int index = lc.Parameters.IndexOf(expression); lc.EmitLambdaArgument(index); lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(new Type[] { expression.Type })); } else if (expression == this._hoistedLocals.ParentVariable) { this.ResolveVariable(expression, this._closureHoistedLocals).EmitLoad(); lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(new Type[] { expression.Type })); } else { lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(Type.EmptyTypes)); } if (this.ShouldCache(expression)) { lc.IL.Emit(OpCodes.Dup); this.CacheBoxToLocal(lc, expression); } lc.IL.Emit(OpCodes.Stelem_Ref); } this.EmitSet(this._hoistedLocals.SelfVariable); } }
private void EmitNewHoistedLocals(LambdaCompiler lc) { if (this._hoistedLocals != null) { lc.IL.EmitInt(this._hoistedLocals.Variables.Count); lc.IL.Emit(OpCodes.Newarr, typeof(object)); int num = 0; foreach (ParameterExpression expression in this._hoistedLocals.Variables) { lc.IL.Emit(OpCodes.Dup); lc.IL.EmitInt(num++); Type type = typeof(StrongBox<>).MakeGenericType(new Type[] { expression.Type }); if (this.IsMethod && lc.Parameters.Contains(expression)) { int index = lc.Parameters.IndexOf(expression); lc.EmitLambdaArgument(index); lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(new Type[] { expression.Type })); } else if (expression == this._hoistedLocals.ParentVariable) { this.ResolveVariable(expression, this._closureHoistedLocals).EmitLoad(); lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(new Type[] { expression.Type })); } else { lc.IL.Emit(OpCodes.Newobj, type.GetConstructor(Type.EmptyTypes)); } if (this.ShouldCache(expression)) { lc.IL.Emit(OpCodes.Dup); this.CacheBoxToLocal(lc, expression); } lc.IL.Emit(OpCodes.Stelem_Ref); } this.EmitSet(this._hoistedLocals.SelfVariable); } }
// Emits creation of the hoisted local storage private void EmitNewHoistedLocals(LambdaCompiler lc) { if (_hoistedLocals == null) { return; } // create the array lc.IL.EmitInt(_hoistedLocals.Variables.Count); lc.IL.Emit(OpCodes.Newarr, typeof(object)); // initialize all elements int i = 0; foreach (ParameterExpression v in _hoistedLocals.Variables) { // array[i] = new StrongBox<T>(...); lc.IL.Emit(OpCodes.Dup); lc.IL.EmitInt(i++); Type boxType = typeof(StrongBox<>).MakeGenericType(v.Type); if (IsMethod && lc.Parameters.Contains(v)) { // array[i] = new StrongBox<T>(argument); int index = lc.Parameters.IndexOf(v); lc.EmitLambdaArgument(index); lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(new Type[] { v.Type })); } else if (v == _hoistedLocals.ParentVariable) { // array[i] = new StrongBox<T>(closure.Locals); ResolveVariable(v, _closureHoistedLocals).EmitLoad(); lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(new Type[] { v.Type })); } else { // array[i] = new StrongBox<T>(); lc.IL.Emit(OpCodes.Newobj, boxType.GetConstructor(Type.EmptyTypes)); } // if we want to cache this into a local, do it now if (ShouldCache(v)) { lc.IL.Emit(OpCodes.Dup); CacheBoxToLocal(lc, v); } lc.IL.Emit(OpCodes.Stelem_Ref); } // store it EmitSet(_hoistedLocals.SelfVariable); }