当前位置: 首页>>代码示例>>C#>>正文


C# CodeGen.GetLocalTmp方法代码示例

本文整理汇总了C#中CodeGen.GetLocalTmp方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGen.GetLocalTmp方法的具体用法?C# CodeGen.GetLocalTmp怎么用?C# CodeGen.GetLocalTmp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeGen的用法示例。


在下文中一共展示了CodeGen.GetLocalTmp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Emit

        public override void Emit(CodeGen cg) {
            Slot tempContext = cg.ContextSlot;
            Slot newContext = cg.GetLocalTmp(typeof(CodeContext));

            _scope.Emit(cg);            //Locals dictionary
            cg.EmitCodeContext();       //CodeContext
            //cg.EmitBoolean(true);       //Visible = true
            cg.EmitCall(typeof(RuntimeHelpers), "CreateNestedCodeContext");

            newContext.EmitSet(cg);

            cg.ContextSlot = newContext;
            _body.Emit(cg);
            cg.ContextSlot = tempContext;
        }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:15,代码来源:ScopeStatment.cs

示例2: EmitArgument

 public static ReturnFixer EmitArgument(CodeGen cg, Slot argSlot)
 {
     argSlot.EmitGet(cg);
     if (argSlot.Type.IsByRef) {
         Type elementType = argSlot.Type.GetElementType();
         Type concreteType = typeof(StrongBox<>).MakeGenericType(elementType);
         Slot refSlot = cg.GetLocalTmp(concreteType);
         cg.EmitLoadValueIndirect(elementType);
         cg.EmitNew(concreteType, new Type[] { elementType });
         refSlot.EmitSet(cg);
         refSlot.EmitGet(cg);
         return new ReturnFixer(refSlot, argSlot);
     } else {
         cg.EmitBoxing(argSlot.Type);
         return null;
     }
 }
开发者ID:robertlj,项目名称:IronScheme,代码行数:17,代码来源:ReturnFixer.cs

示例3: EmitNewEnvironment

        public override void EmitNewEnvironment(CodeGen cg)
        {
            ConstructorInfo ctor = EnvironmentType.GetConstructor(new Type[] {StorageType});

              // emit: dict.Tuple[.Item000...].Item000 = dict, and then leave dict on the stack

              cg.EmitNew(ctor);
              cg.Emit(OpCodes.Dup);

              Slot tmp = cg.GetLocalTmp(EnvironmentType);
              tmp.EmitSet(cg);

              cg.EmitPropertyGet(EnvironmentType, "Data");

              var fld = StorageType.GetField("$parent$");

              //cg.EmitFieldGet(fld);

              tmp.EmitGet(cg);
              cg.EmitFieldSet(fld);

              cg.FreeLocalTmp(tmp);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:23,代码来源:PropertyEnvironmentFactory.cs

示例4: EmitSet

        internal override void EmitSet(CodeGen cg)
        {
            // Disallow "[] = l", "[], a = l, l", "[[]] = [l]", etc
            if (items.Length == 0) {
                cg.Context.AddError("can't assign to " + EmptySequenceString, this);
                return;
            }

            // int leftCount = items.Length;
            Slot leftCount = cg.GetLocalTmp(typeof(int));
            cg.EmitInt(items.Length);
            leftCount.EmitSet(cg);

            // object[] values = new object[leftCount];
            Slot values = cg.GetLocalTmp(typeof(object[]));
            leftCount.EmitGet(cg);
            cg.Emit(OpCodes.Newarr, typeof(object));
            values.EmitSet(cg);

            // ie = Ops.GetEnumerator(<value on stack>)
            Slot ie = cg.GetLocalTmp(typeof(IEnumerator));
            cg.EmitCall(typeof(Ops), "GetEnumeratorForUnpack");
            ie.EmitSet(cg);

            // int rightCount = Ops.GetEnumeratorValues(ie, ref values);
            Slot rightCount = cg.GetLocalTmp(typeof(int));

            ie.EmitGet(cg);
            values.EmitGetAddr(cg);
            cg.EmitCall(typeof(Ops), "GetEnumeratorValues");
            rightCount.EmitSet(cg);

            // if (leftCount != rightCount)
            //      throw Ops.ValueErrorForUnpackMismatch(leftCount, rightCount);
            Label equalSizes = cg.DefineLabel();

            leftCount.EmitGet(cg);
            rightCount.EmitGet(cg);
            cg.Emit(OpCodes.Ceq);
            cg.Emit(OpCodes.Brtrue_S, equalSizes);

            leftCount.EmitGet(cg);
            rightCount.EmitGet(cg);
            cg.EmitCall(typeof(Ops).GetMethod("ValueErrorForUnpackMismatch"));
            cg.Emit(OpCodes.Throw);

            cg.MarkLabel(equalSizes);

            // for (int i = 0; i < leftCount; i++)
            //     items[i].Assign(values[i], env);

            int i = 0;
            foreach (Expression expr in items) {
                values.EmitGet(cg);
                cg.EmitInt(i++);
                cg.Emit(OpCodes.Ldelem_Ref);
                expr.EmitSet(cg);
            }

            cg.FreeLocalTmp(leftCount);
            cg.FreeLocalTmp(rightCount);
            cg.FreeLocalTmp(values);
            cg.FreeLocalTmp(ie);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:64,代码来源:Expressions.cs

示例5: FinishCompare

        internal void FinishCompare(CodeGen cg)
        {
            BinaryExpression bright = (BinaryExpression)right;

            Slot valTmp = cg.GetLocalTmp(typeof(object));
            Slot retTmp = cg.GetLocalTmp(typeof(object));
            bright.left.Emit(cg);
            cg.Emit(OpCodes.Dup);
            valTmp.EmitSet(cg);

            cg.EmitCall(op.Target.Method);
            cg.Emit(OpCodes.Dup);
            retTmp.EmitSet(cg);
            cg.EmitTestTrue();

            Label end = cg.DefineLabel();
            cg.Emit(OpCodes.Brfalse, end);

            valTmp.EmitGet(cg);

            if (IsComparison(bright.right)) {
                bright.FinishCompare(cg);
            } else {
                bright.right.Emit(cg);
                cg.EmitCall(bright.op.Target.Method);
            }

            retTmp.EmitSet(cg);
            cg.MarkLabel(end);
            retTmp.EmitGet(cg);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:31,代码来源:Expressions.cs

示例6: Emit

        internal override void Emit(CodeGen cg)
        {
            Label eol = cg.DefineLabel();
            Label breakTarget = cg.DefineLabel();
            Label continueTarget = cg.DefineLabel();

            cg.EmitPosition(Start, header);

            list.Emit(cg);
            cg.EmitCall(typeof(Ops), "GetEnumeratorForIteration");

            Slot iter;
            if (cg.IsGenerator()) {
                iter = cg.Names.GetTempSlot("iter", typeof(IEnumerator));
            } else {
                iter = cg.GetLocalTmp(typeof(IEnumerator));
            }

            iter.EmitSet(cg);

            cg.MarkLabel(continueTarget);
            iter.EmitGet(cg);
            cg.EmitCall(typeof(IEnumerator), "MoveNext");

            cg.Emit(OpCodes.Brfalse, eol);

            cg.PushTargets(breakTarget, continueTarget);

            iter.EmitGet(cg);
            cg.EmitCall(typeof(IEnumerator).GetProperty("Current").GetGetMethod());
            lhs.EmitSet(cg);

            body.Emit(cg);

            cg.Emit(OpCodes.Br, continueTarget);

            cg.PopTargets();

            cg.MarkLabel(eol);
            if (elseStmt != null) {
                elseStmt.Emit(cg);
            }
            cg.MarkLabel(breakTarget);

            if (!cg.IsGenerator()) {
                cg.FreeLocalTmp(iter);
            }
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:48,代码来源:Statements.cs

示例7: EmitGet

        public override void EmitGet(CodeGen cg)
        {
            //
            // if ($env.TryGetValue(name, out local) && local != Uninitialized.instance) {
            //     local
            // } else {
            //     global
            // }

            Slot local = cg.GetLocalTmp(typeof(object));
            Label notFound = cg.DefineLabel();
            Label found = cg.DefineLabel();
            environment.EmitGet(cg);
            cg.EmitName(name);
            local.EmitGetAddr(cg);
            cg.EmitCall(typeof(IDictionary<object, object>).GetMethod("TryGetValue"));
            cg.Emit(OpCodes.Brfalse_S, notFound);
            local.EmitGet(cg);
            cg.EmitUninitialized();
            cg.Emit(OpCodes.Beq_S, notFound);
            local.EmitGet(cg);
            cg.Emit(OpCodes.Br_S, found);
            cg.MarkLabel(notFound);
            global.EmitGet(cg);
            cg.MarkLabel(found);
            cg.FreeLocalTmp(local);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:27,代码来源:Slot.cs

示例8: Emit

        internal override void Emit(CodeGen cg)
        {
            cg.EmitPosition(Start, header);
            SignatureInfo sigInfo = GetSignature(cg);

            FlowChecker.Check(this);

            string mname = name.GetString() + "$f" + counter++;

            // create the new method & setup it's locals
            CodeGen impl = cg.DefineMethod(mname, typeof(object), sigInfo.ParamTypes, sigInfo.ParamNames);
            impl.Names = CodeGen.CreateLocalNamespace(impl);
            impl.Context = cg.Context;

            for (int arg = sigInfo.HasContext ? 1 : 0; arg < sigInfo.ParamNames.Length; arg++) {
                impl.Names.SetSlot(sigInfo.ParamNames[arg], impl.GetArgumentSlot(arg));
            }

            if (sigInfo.HasContext) {
                if (IsClosure) {
                    impl.StaticLinkSlot = impl.GetArgumentSlot(0);
                }
                impl.ContextSlot = impl.GetArgumentSlot(0);
                impl.ModuleSlot = new PropertySlot(impl.ContextSlot, typeof(ICallerContext).GetProperty("Module"));
            }

            // then generate the actual method
            EmitFunctionImplementation(impl, cg);
            impl.Finish();

            if (NeedsWrapperMethod()) impl = MakeWrapperMethodN(cg, impl.MethodInfo, sigInfo.HasContext);

            //  Create instance of the Function? object
            Type funcType, targetType;
            using (impl) {
                GetFunctionType(out funcType, out targetType);
                cg.EmitModuleInstance();
                cg.EmitString(name.GetString());

                cg.EmitDelegate(impl, targetType, sigInfo.ContextSlot);
            }

            int first = sigInfo.HasContext ? 1 : 0;
            //  Emit string array (minus the first environment argument)
            cg.EmitInt(sigInfo.ParamNames.Length - first);
            cg.Emit(OpCodes.Newarr, typeof(string));
            for (int i = first; i < sigInfo.ParamNames.Length; i++) {
                cg.Emit(OpCodes.Dup);
                cg.EmitInt(i - first);
                cg.EmitStringOrNull(sigInfo.ParamNames[i].GetString());
                cg.Emit(OpCodes.Stelem_Ref);
            }
            cg.EmitObjectArray(defaults);

            if (flags == FunctionAttributes.None) {
                cg.Emit(OpCodes.Newobj, funcType.GetConstructor(
                    new Type[] { typeof(PythonModule), typeof(string), targetType, typeof(string[]), typeof(object[]) }));
            } else {
                cg.EmitInt((int)flags);
                cg.Emit(OpCodes.Newobj, funcType.GetConstructor(
                    new Type[] { typeof(PythonModule), typeof(string), targetType, typeof(string[]), typeof(object[]), typeof(FunctionAttributes) }));
            }

            string doc = Body.Documentation;
            if (doc != null) {
                cg.Emit(OpCodes.Dup);
                cg.EmitString(doc);
                cg.EmitCall(typeof(PythonFunction).GetProperty("Documentation").GetSetMethod());
            }

            // update func_code w/ appropriate state.
            cg.Emit(OpCodes.Dup);

            Slot functionCode = cg.GetLocalTmp(typeof(FunctionCode));

            cg.EmitCall(typeof(PythonFunction).GetProperty("FunctionCode").GetGetMethod());
            cg.Emit(OpCodes.Castclass, typeof(FunctionCode));
            cg.Emit(OpCodes.Dup);
            functionCode.EmitSet(cg);
            if (IsExternal) {
                cg.EmitInt(this.ExternalStart.Line);
            } else {
                cg.EmitInt(this.Start.Line);
            }
            cg.EmitCall(typeof(FunctionCode), "SetLineNumber");

            functionCode.EmitGet(cg);
            if (IsExternal) {
                cg.EmitString(ExternalInfo.OriginalFileName);
            } else {
                cg.EmitString(this.filename);
            }
            cg.EmitCall(typeof(FunctionCode), "SetFilename");

            // Only codegen the call into SetFlags if there are flags to set.
            FunctionCode.FuncCodeFlags codeFlags = 0;
            if (cg.Context.TrueDivision) codeFlags |= FunctionCode.FuncCodeFlags.FutureDivision;
            if (this.yieldCount > 0) codeFlags |= FunctionCode.FuncCodeFlags.Generator;
            if (codeFlags != 0) {
                functionCode.EmitGet(cg);
//.........这里部分代码省略.........
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:101,代码来源:FuncDef.cs

示例9: EmitSet

        // This override assumes that the IL stack already holds the value to be assigned from.
        public virtual void EmitSet(CodeGen cg)
        {
            // localTmpVal = <top of IL stack>
            Slot localTmpVal = cg.GetLocalTmp(typeof(object));
            localTmpVal.EmitSet(cg);

            // <slot> = localTmpVal
            EmitSet(cg, localTmpVal);

            cg.FreeLocalTmp(localTmpVal);
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:12,代码来源:Slot.cs

示例10: EmitSet

        public override void EmitSet(CodeGen cg)
        {
            Contract.RequiresNotNull(cg, "cg");

            Slot val = cg.GetLocalTmp(Type);
            val.EmitSet(cg);
            EmitSet(cg, val);
            cg.FreeLocalTmp(val);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:9,代码来源:IndexSlot.cs

示例11: EmitGeneratorTry

        private void EmitGeneratorTry(CodeGen cg, TryFlowResult flow)
        {
            //
            // Initialize the flow control flag
            //
            Slot flowControlFlag = null;

            if (flow.Any) {
                flowControlFlag = cg.GetLocalTmp(typeof(int));
                cg.EmitInt(CodeGen.FinallyExitsNormally);
                flowControlFlag.EmitSet(cg);
            }

            Slot exception = null;
            if (_finally != null) {
                exception = cg.GetTemporarySlot(typeof(Exception));
                cg.EmitNull();
                exception.EmitSet(cg);
            }

            //******************************************************************
            // Entering the try block
            //******************************************************************

            if (_target != null) {
                cg.MarkLabel(_target.EnsureLabel(cg));
            }

            //******************************************************************
            // If we have a 'finally', transform it into try..catch..finally
            // and rethrow
            //******************************************************************
            Label endFinallyBlock = new Label();
            if (_finally != null) {
                cg.PushExceptionBlock(TargetBlockType.Try, flowControlFlag);
                cg.BeginExceptionBlock();
                endFinallyBlock = cg.DefineLabel();

                //**************************************************************
                // If there is a yield in any catch, that catch will be hoisted
                // and we need to dispatch to it from here
                //**************************************************************
                if (_yieldInCatch) {
                    EmitYieldDispatch(_catchYields, cg);
                }

                if (YieldInBlock(_finallyYields)) {
                    foreach (YieldTarget yt in _finallyYields) {
                        cg.GotoRouter.EmitGet(cg);
                        cg.EmitInt(yt.Index);
                        cg.Emit(OpCodes.Beq, endFinallyBlock);
                    }
                }
            }

            //******************************************************************
            // If we have a 'catch', start a try block to handle all the catches
            //******************************************************************

            Label endCatchBlock = new Label();
            if (HaveHandlers()) {
                cg.PushExceptionBlock(TargetBlockType.Try, flowControlFlag);
                endCatchBlock = cg.BeginExceptionBlock();
            }

            //******************************************************************
            // Emit the try block body
            //******************************************************************

            // First, emit the dispatch within the try block
            EmitYieldDispatch(_tryYields, cg);

            // Then, emit the actual body
            _body.Emit(cg);
            //cg.EmitSequencePointNone();

            //******************************************************************
            // Emit the catch blocks
            //******************************************************************

            if (HaveHandlers()) {
                List<CatchRecord> catches = new List<CatchRecord>();
                cg.PushExceptionBlock(TargetBlockType.Catch, flowControlFlag);

                foreach (CatchBlock cb in _handlers) {
                    cg.BeginCatchBlock(cb.Test);

                    if (cb.Yield) {
                        // The catch block body contains yield, therefore
                        // delay the body emit till after the try block.
                        Slot slot = cg.GetLocalTmp(cb.Test);
                        slot.EmitSet(cg);
                        catches.Add(new CatchRecord(slot, cb));
                    } else {
                        // Save the exception (if the catch block asked for it) or pop
                        EmitSaveExceptionOrPop(cg, cb);
                        // Emit the body right now, since it doesn't contain yield
                        cb.Body.Emit(cg);
                    }
                }
//.........这里部分代码省略.........
开发者ID:robertlj,项目名称:IronScheme,代码行数:101,代码来源:TryStatement.cs

示例12: EmitSimpleTry

        private void EmitSimpleTry(CodeGen cg, TryFlowResult flow)
        {
            //
            // Initialize the flow control flag
            //
            Slot flowControlFlag = null;
            if (flow.Any) {
                Debug.Assert(_finally != null);

                flowControlFlag = cg.GetLocalTmp(typeof(int));
                cg.EmitInt(CodeGen.FinallyExitsNormally);
                flowControlFlag.EmitSet(cg);

                //  If there is a control flow in finally, emit outer:
                //  try {
                //      // try block body and all catch handling
                //  } catch (Exception all) {
                //      saved = all;
                //  } finally {
                //      finally_body
                //      if (saved != null) {
                //          throw saved;
                //      }
                //  }

                if (HaveHandlers()) {
                    cg.PushExceptionBlock(TargetBlockType.Try, flowControlFlag);
                    cg.BeginExceptionBlock();
                }
            }

            //******************************************************************
            // 1. ENTERING TRY
            //******************************************************************

            cg.PushExceptionBlock(TargetBlockType.Try, flowControlFlag);
            cg.BeginExceptionBlock();

            //******************************************************************
            // 2. Emit the try statement body
            //******************************************************************

            _body.Emit(cg);
            //cg.EmitSequencePointNone();

            //******************************************************************
            // 3. Emit the catch blocks
            //******************************************************************

            if (HaveHandlers()) {
                cg.PushExceptionBlock(TargetBlockType.Catch, flowControlFlag);

                foreach (CatchBlock cb in _handlers) {
                    // Begin the strongly typed exception block
                    cg.BeginCatchBlock(cb.Test);

                    // Save the exception (if the catch block asked for it) or pop
                    EmitSaveExceptionOrPop(cg, cb);

                    //
                    // Emit the catch block body
                    //
                    cb.Body.Emit(cg);
                }

                cg.PopTargets(TargetBlockType.Catch);
            }

            //******************************************************************
            // 4. Emit the finally block
            //******************************************************************

            if (_finally != null) {
                Slot rethrow = null;
                if (flow.Any) {
                    // If there is a control flow in finally, end the catch
                    // statement and emit the catch-all and finally clause
                    // with rethrow at the end.

                    if (HaveHandlers()) {
                        cg.EndExceptionBlock();
                        cg.PopTargets(TargetBlockType.Try);
                    }

                    cg.PushExceptionBlock(TargetBlockType.Catch, flowControlFlag);
                    cg.BeginCatchBlock(typeof(Exception));

                    rethrow = cg.GetLocalTmp(typeof(Exception));
                    rethrow.EmitSet(cg);

                    cg.PopTargets(TargetBlockType.Catch);
                }

                cg.PushExceptionBlock(TargetBlockType.Finally, flowControlFlag);
                cg.BeginFinallyBlock();

                //
                // Emit the finally block body
                //
                _finally.Emit(cg);
//.........这里部分代码省略.........
开发者ID:robertlj,项目名称:IronScheme,代码行数:101,代码来源:TryStatement.cs

示例13: EmitAddress

 internal virtual void EmitAddress(CodeGen cg, Type asType)
 {
     EmitAs(cg, asType);
     Slot tmp = cg.GetLocalTmp(asType);
     tmp.EmitSet(cg);
     tmp.EmitGetAddr(cg);
 }
开发者ID:kkirstein,项目名称:IronScheme,代码行数:7,代码来源:Expression.cs

示例14: Generate

 public override void Generate(CodeGen cg, Slot contextSlot, Slot[] argSlots)
 {
     if (argumentType.IsByRef) {
         Type baseType = argumentType.GetElementType();
         Slot tmp = cg.GetLocalTmp(baseType);
         // Emit the default value as the base type
         EmitDefaultValue(cg, defaultValue, baseType);
         tmp.EmitSet(cg);
         // And pass the reference to the callee
         tmp.EmitGetAddr(cg);
     } else {
         // Emit the default value directly as the argument type
         EmitDefaultValue(cg, defaultValue, argumentType);
     }
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:15,代码来源:MethodBinder.cs

示例15: EmitNestedTupleInit

        private static void EmitNestedTupleInit(CodeGen cg, Type storageType)
        {
            if (Tuple.GetSize(storageType) > Tuple.MaxSize)
              {

            Slot tmp = cg.GetLocalTmp(storageType);
            tmp.EmitSet(cg);

            Type[] nestedTuples = storageType.GetGenericArguments();
            for (int i = 0; i < nestedTuples.Length; i++)
            {
              Type t = nestedTuples[i];
              if (t.IsSubclassOf(typeof(Tuple)))
              {
                tmp.EmitGet(cg);

                cg.EmitNew(t.GetConstructor(ArrayUtils.EmptyTypes));
                cg.EmitPropertySet(storageType, String.Format("Item{0:D3}", i));

                tmp.EmitGet(cg);
                cg.EmitPropertyGet(storageType, String.Format("Item{0:D3}", i));

                EmitNestedTupleInit(cg, t);
              }
            }

            cg.FreeLocalTmp(tmp);
              }
              else
              {
            int capacity = 0;
            foreach (Type t in storageType.GetGenericArguments())
            {
              if (t == typeof(None))
              {
                break;
              }
              capacity++;
            }
            cg.EmitInt(capacity);
            cg.EmitCall(typeof(RuntimeHelpers), "UninitializeEnvironmentTuple");
              }
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:43,代码来源:PropertyEnvironmentFactory.cs


注:本文中的CodeGen.GetLocalTmp方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。