private void DeclareLocals() { var formalBuilders = new List <ParameterBuilder>(); for (int i = 0; i < mLambdaNode.formalCount; ++i) { formalBuilders.Add(MethodBuilder.DefineParameter(i + 1, ParameterAttributes.In, mLambdaNode.locals[i])); } var heapLocals = mLambdaNode.childrenFreeAddresses.Where(a => a.envIndex == 0).Select(a => a.index).OrderBy(a => a).ToList(); for (int i = 0; i < mLambdaNode.formalCount; ++i) { if (heapLocals.IndexOf(i) == -1) { mLocalBuilders.Add(formalBuilders[i]); } else { var localBuilder = mILGenerator.DeclareLocal(typeof(SharedValue)); if (JITInterpreter_DS2.Instance().HasSymbolInfo()) { localBuilder.SetLocalSymInfo("_" + mLambdaNode.locals[i]); } mLocalBuilders.Add(localBuilder); JITInterpreter_DS2.EmitLoadArg(mILGenerator, HasThisArgument(), formalBuilders[i]); mILGenerator.Emit(OpCodes.Newobj, typeof(SharedValue).GetConstructor(new Type[] { typeof(object) })); JITInterpreter_DS2.EmitStoreLocal(mILGenerator, localBuilder); } } for (int i = mLambdaNode.formalCount; i < mLambdaNode.locals.Count; ++i) { if (heapLocals.IndexOf(i) == -1) { var localBuilder = mILGenerator.DeclareLocal(typeof(object)); if (JITInterpreter_DS2.Instance().HasSymbolInfo()) { localBuilder.SetLocalSymInfo("_" + mLambdaNode.locals[i]); } mLocalBuilders.Add(localBuilder); } else { var localBuilder = mILGenerator.DeclareLocal(typeof(SharedValue)); if (JITInterpreter_DS2.Instance().HasSymbolInfo()) { localBuilder.SetLocalSymInfo("_" + mLambdaNode.locals[i]); } mLocalBuilders.Add(localBuilder); mILGenerator.Emit(OpCodes.Ldnull); mILGenerator.Emit(OpCodes.Newobj, typeof(SharedValue).GetConstructor(new Type[] { typeof(object) })); JITInterpreter_DS2.EmitStoreLocal(mILGenerator, localBuilder); } } }
private void EndEmitPopLocal(LocalAddress address) { var builder = mLocalBuilders[address.index]; if (builder is ParameterBuilder) { JITInterpreter_DS2.EmitStoreArg(mILGenerator, HasThisArgument(), builder as ParameterBuilder); } else { LocalBuilder localBuilder = builder as LocalBuilder; if (localBuilder.LocalType == typeof(object)) { JITInterpreter_DS2.EmitStoreLocal(mILGenerator, localBuilder); } else { mILGenerator.Emit(OpCodes.Stfld, typeof(SharedValue).GetField("value")); } } }