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


C# CodeGen.Emit方法代码示例

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


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

示例1: Emit

        public override void Emit(CodeGen cg) {
          
            if (_typeOperand.IsAssignableFrom(_expression.Type)) {
                // if its always true just emit the bool
                cg.EmitConstant(true);
                return;
            }

            _expression.EmitAsObject(cg);

            EmitLocation(cg);

            cg.Emit(OpCodes.Isinst, _typeOperand);
            cg.Emit(OpCodes.Ldnull);
            cg.Emit(OpCodes.Cgt_Un);

            if (ScriptDomainManager.Options.LightweightDebugging)
            {
              if (!cg.IsDynamicMethod)
              {
                var s = SpanToLong(Span);
                cg.EmitConstant(s);
                cg.EmitCall(Debugging.DebugMethods.ExpressionOut);
              }
            }
        }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:26,代码来源:TypeBinaryExpression.cs

示例2: EmitGet

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

            _instance.EmitGet(cg);
            cg.EmitInt(_index);
            if (Type == typeof(object)) cg.Emit(OpCodes.Ldelem_Ref);
            else cg.Emit(OpCodes.Ldelem, Type);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:9,代码来源:IndexSlot.cs

示例3: EmitGet

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

            _instance.EmitGet(cg);
            if (!_type.IsAssignableFrom(_instance.Type)) {
                if (_type.IsValueType) {
                    Debug.Assert(_instance.Type == typeof(object));
                    cg.Emit(OpCodes.Unbox_Any, _type);
                } else {
                    cg.Emit(OpCodes.Castclass, _type);
                }
            }
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:14,代码来源:CastSlot.cs

示例4: Emit

        public override void Emit(CodeGen cg)
        {
            bool eoiused = false;
            Label eoi = cg.DefineLabel();
            foreach (IfStatementTest t in _tests) {
                Label next = cg.DefineLabel();

                if (t.Test.Span.IsValid)
                {
                  cg.EmitPosition(t.Test.Start, t.Test.End);
                }

                t.Test.EmitBranchFalse(cg, next);

                t.Body.Emit(cg);

                // optimize no else case
                if (IsNotIfOrReturn(t.Body))
                {
                  eoiused = true;
                  cg.Emit(OpCodes.Br, eoi);
                }
                cg.MarkLabel(next);
            }
            if (_else != null) {
                _else.Emit(cg);
            }
            if (eoiused)
            {
              cg.MarkLabel(eoi);
            }
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:32,代码来源:IfStatement.cs

示例5: EmitGetAddr

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

            Debug.Assert(cg == _codeGen);

            cg.Emit(OpCodes.Ldloca, _localBuilder);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:8,代码来源:LocalSlot.cs

示例6: EmitGet

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

            _param.EmitGet(cg);
            cg.EmitInt(_index);
            cg.Emit(OpCodes.Ldelem_Ref);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:8,代码来源:ParamArraySlot.cs

示例7: EmitDelete

 public override void EmitDelete(CodeGen cg, SymbolId name, bool check)
 {
     // Emit the following:
     //    RuntimeHelpers.RemoveName(context, symbol_id)
     _frame.EmitGet(cg);
     cg.EmitSymbolId(name);
     cg.EmitCall(typeof(RuntimeHelpers), "RemoveName");
     cg.Emit(OpCodes.Pop);
 }
开发者ID:robertlj,项目名称:IronScheme,代码行数:9,代码来源:LocalNamedFrameSlot.cs

示例8: Emit

 internal override void Emit(CodeGen cg)
 {
     left.Emit(cg);
     cg.Emit(OpCodes.Dup);
     cg.EmitCall(typeof(Ops), "IsTrue");
     //cg.emitNonzero(left);
     Label l = cg.DefineLabel();
     cg.Emit(OpCodes.Brfalse, l);
     cg.Emit(OpCodes.Pop);
     right.Emit(cg);
     cg.MarkLabel(l);
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:12,代码来源:Expressions.cs

示例9: EmitCheck

        public virtual void EmitCheck(CodeGen cg, SymbolId name)
        {
            Contract.RequiresNotNull(cg, "cg");

            Label endCheck = cg.DefineLabel();
            cg.Emit(OpCodes.Dup);
            cg.EmitUninitialized();
            cg.Emit(OpCodes.Bne_Un_S, endCheck);
            if (_local) {
                cg.EmitSymbolId(name);
                cg.EmitUnbox(typeof(SymbolId));
                cg.EmitCall(typeof(RuntimeHelpers), "ThrowUnboundLocalError");
            } else {
                cg.Emit(OpCodes.Pop);
                cg.EmitCodeContext();
                cg.EmitSymbolId(name);
                cg.EmitUnbox(typeof(SymbolId));
                cg.EmitCall(typeof(RuntimeHelpers), "LookupName");
            }
            cg.MarkLabel(endCheck);
        }
开发者ID:robertlj,项目名称:IronScheme,代码行数:21,代码来源:Slot.cs

示例10: EmitSet

 public override void EmitSet(CodeGen cg)
 {
     Contract.RequiresNotNull(cg, "cg");
     Debug.Assert(cg == this._codeGen);
     if (_index < byte.MaxValue)
     {
       cg.Emit(OpCodes.Starg_S, (byte)_index);
     }
     else
     {
       cg.Emit(OpCodes.Starg, (short)_index);
     }
 }
开发者ID:robertlj,项目名称:IronScheme,代码行数:13,代码来源:ArgSlot.cs

示例11: Emit

 internal override void Emit(CodeGen cg)
 {
     if (Options.DebugMode) {
         cg.EmitPosition(this);
         cg.EmitTestTrue(test);
         Label endLabel = cg.DefineLabel();
         cg.Emit(OpCodes.Brtrue, endLabel);
         cg.EmitExprOrNone(message);
         cg.EmitConvertFromObject(typeof(string));
         cg.EmitCall(typeof(Ops), "AssertionError", new Type[] { typeof(string) });
         cg.Emit(OpCodes.Throw);
         cg.MarkLabel(endLabel);
     }
 }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:14,代码来源:Statements.cs

示例12: Emit

        public override void Emit(CodeGen cg) {
            //cg.EmitPosition(Start, _header);

            Label breakTarget = cg.DefineLabel();
            Label defaultTarget = breakTarget;
            Label[] labels = new Label[_cases.Count];

            // Create all labels
            for (int i = 0; i < _cases.Count; i++) {
                labels[i] = cg.DefineLabel();

                // Default case.
                if (_cases[i].IsDefault) {
                    // Set the default target
                    defaultTarget = labels[i];
                }
            }

            // Emit the test value
            _testValue.Emit(cg);

            // Check if jmp table can be emitted
            if (!TryEmitJumpTable(cg, labels, defaultTarget)) {
                // There might be scenario(s) where the jmp table is not emitted
                // Emit the switch as conditional branches then
                EmitConditionalBranches(cg, labels);
            }

            // If "default" present, execute default code, else exit the switch            
            cg.Emit(OpCodes.Br, defaultTarget);

            cg.PushTargets(breakTarget, cg.BlockContinueLabel, this);

            // Emit the bodies
            for (int i = 0; i < _cases.Count; i++) {
                // First put the corresponding labels
                cg.MarkLabel(labels[i]);
                // And then emit the Body!!
                _cases[i].Body.Emit(cg);
            }

            cg.PopTargets();
            cg.MarkLabel(breakTarget);
        }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:44,代码来源:SwitchStatement.cs

示例13: Emit

        public override void Emit(CodeGen cg) {
            Label startTarget = cg.DefineLabel();
            Label breakTarget = cg.DefineLabel();
            Label continueTarget = cg.DefineLabel();

            cg.MarkLabel(startTarget);                        
            cg.PushTargets(breakTarget, continueTarget, this);
            _body.Emit(cg);

            cg.MarkLabel(continueTarget);
            // TODO: Check if we need to emit position somewhere else also.
            //cg.EmitPosition(Start, _header);

            _test.Emit(cg);
            cg.Emit(OpCodes.Brtrue, startTarget);

            cg.PopTargets();            
            cg.MarkLabel(breakTarget);
        }
开发者ID:JamesTryand,项目名称:IronScheme,代码行数:19,代码来源:DoStatement.cs

示例14: 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

示例15: EmitWithFinallyBlock

        private void EmitWithFinallyBlock(CodeGen cg, Slot exc, Slot exit, Slot isTryYielded)
        {
            // we are certain that Finally will never yield
            cg.PushFinallyBlock(null, null);
            cg.BeginFinallyBlock();

            //finally body
            Label endOfFinally = cg.DefineLabel();

            // isTryYielded == True ?
            isTryYielded.EmitGet(cg);
            cg.EmitTestTrue();
            cg.Emit(OpCodes.Brtrue, endOfFinally);

            // exc == False ?
            exc.EmitGet(cg);
            cg.EmitTestTrue();
            cg.Emit(OpCodes.Brfalse, endOfFinally);

            //exit(None, None, None)
            cg.EmitCallerContext();
            exit.EmitGet(cg);
            cg.Emit(OpCodes.Ldnull);
            cg.Emit(OpCodes.Ldnull);
            cg.Emit(OpCodes.Ldnull);
            cg.EmitCall(typeof(Ops), "CallWithContext", new Type[] { typeof(ICallerContext), typeof(object), typeof(object), typeof(object), typeof(object) });
            cg.Emit(OpCodes.Pop);

            cg.MarkLabel(endOfFinally);
            cg.PopTargets();

            // finally end
        }
开发者ID:FabioNascimento,项目名称:DICommander,代码行数:33,代码来源:Statements.cs


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