private FieldBuilder EmitLoadFreeEnv(FreeAddress address) { JITInterpreter_DS.EmitLoadThis(mILGenerator); ASTNodeVisitor_JITCompiler visitor = mParent; for (int i = 1; i < address.envIndex; ++i) { mILGenerator.Emit(OpCodes.Ldfld, visitor.mHeapEnvFieldBuilders[PREV_ENV_FIELD_NAME]); visitor = visitor.mParent; } return(visitor.mHeapEnvFieldBuilders[visitor.mLambdaNode.locals[address.index]]); }
private void EmitInitHeapEnv() { if (!HasHeapEnv()) { return; } mHeapEnvBuilder = mILGenerator.DeclareLocal(mHeapEnvTypeBuilder); if (JITInterpreter_DS.Instance().HasSymbolInfo()) { mHeapEnvBuilder.SetLocalSymInfo(HEAP_ENV_LOCAL_NAME); } var constructor = mHeapEnvTypeBuilder.DefineDefaultConstructor(MethodAttributes.Public); mILGenerator.Emit(OpCodes.Newobj, constructor); EmitStoreLocal(mILGenerator, mHeapEnvBuilder); if (mLambdaNode.childrenFreeAddresses.Where(v => v.envIndex > 0).GetEnumerator().MoveNext()) { var fieldBuilder = mHeapEnvTypeBuilder.DefineField(PREV_ENV_FIELD_NAME, mEnvTypeBuilder, FieldAttributes.Public); mHeapEnvFieldBuilders[PREV_ENV_FIELD_NAME] = fieldBuilder; JITInterpreter_DS.EmitLoadLocal(mILGenerator, mHeapEnvBuilder); JITInterpreter_DS.EmitLoadThis(mILGenerator); mILGenerator.Emit(OpCodes.Stfld, fieldBuilder); } var heapLocals = mLambdaNode.childrenFreeAddresses.Where(a => a.envIndex == 0).Select(a => a.index).OrderBy(a => a).ToList(); foreach (var index in heapLocals) { var fieldBuilder = mHeapEnvTypeBuilder.DefineField(mLambdaNode.locals[index], typeof(object), FieldAttributes.Public); mHeapEnvFieldBuilders[mLambdaNode.locals[index]] = fieldBuilder; if (index < mLambdaNode.formalCount) { JITInterpreter_DS.EmitLoadLocal(mILGenerator, mHeapEnvBuilder); JITInterpreter_DS.EmitLoadArg(mILGenerator, HasThisArgument(), mArgBuilders[index]); mILGenerator.Emit(OpCodes.Stfld, fieldBuilder); } } }