當前位置: 首頁>>代碼示例>>C#>>正文


C# EmitContext.Emit方法代碼示例

本文整理匯總了C#中Mono.CSharp.EmitContext.Emit方法的典型用法代碼示例。如果您正苦於以下問題:C# EmitContext.Emit方法的具體用法?C# EmitContext.Emit怎麽用?C# EmitContext.Emit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.CSharp.EmitContext的用法示例。


在下文中一共展示了EmitContext.Emit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Emit

 public override void Emit(EmitContext ec)
 {
     if (Value)
         ec.Emit (OpCodes.Ldc_I4_1);
     else
         ec.Emit (OpCodes.Ldc_I4_0);
 }
開發者ID:speier,項目名稱:shake,代碼行數:7,代碼來源:constant.cs

示例2: Emit

		public override void Emit (EmitContext ec)
		{
			//
			// Emits null pointer
			//
			ec.Emit (OpCodes.Ldc_I4_0);
			ec.Emit (OpCodes.Conv_U);
		}
開發者ID:Tak,項目名稱:monodevelop-novell,代碼行數:8,代碼來源:literal.cs

示例3: DoEmit

        protected override void DoEmit(EmitContext ec)
        {
            if (statement != null) {
                statement.EmitStatement (ec);
                if (unwind_protect)
                    ec.Emit (OpCodes.Leave, ec.CreateReturnLabel ());
                else {
                    ec.Emit (OpCodes.Ret);
                }
                return;
            }

            base.DoEmit (ec);
        }
開發者ID:segaman,項目名稱:NRefactory,代碼行數:14,代碼來源:lambda.cs

示例4: Emit

        public override void Emit(EmitContext ec)
        {
            if (statement != null) {
                statement.EmitStatement (ec);
                ec.Emit (OpCodes.Ret);
                return;
            }

            base.Emit (ec);
        }
開發者ID:RainsSoft,項目名稱:MonoCompilerAsAService,代碼行數:10,代碼來源:lambda.cs

示例5: Emit

		public override void Emit (EmitContext ec)
		{
			ec.EmitNull ();

			// Only to make verifier happy
			if (type.IsGenericParameter)
				ec.Emit (OpCodes.Unbox_Any, type);
		}
開發者ID:rabink,項目名稱:mono,代碼行數:8,代碼來源:constant.cs

示例6: Emit

		public override void Emit (EmitContext ec)
		{
			//
			// It can be null for struct initializers or System.Object
			//
			if (base_ctor == null) {
				if (type == ec.BuiltinTypes.Object)
					return;

				ec.Emit (OpCodes.Ldarg_0);
				ec.Emit (OpCodes.Initobj, type);
				return;
			}
			
			var call = new CallEmitter ();
			call.InstanceExpression = new CompilerGeneratedThis (type, loc); 
			call.EmitPredefined (ec, base_ctor, argument_list, false);
		}
開發者ID:0xb1dd1e,項目名稱:NRefactory,代碼行數:18,代碼來源:method.cs

示例7: EmitValueChangedCallback

		internal void EmitValueChangedCallback (EmitContext ec, string name, TypeSpec type, Location loc)
		{
			if (listener_id == null)
				listener_id = ListenerProxy.Register (ModificationListener);

			if (listener_proxy_value == null)
				listener_proxy_value = typeof (ListenerProxy).GetMethod ("ValueChanged");

#if STATIC
			throw new NotSupportedException ();
#else
			// object value, int row, int col, string name, int listenerId
			if (type.IsStructOrEnum)
				ec.Emit (OpCodes.Box, type);

			ec.EmitInt (loc.Row);
			ec.EmitInt (loc.Column);
			ec.Emit (OpCodes.Ldstr, name);
			ec.EmitInt (listener_id.Value);
			ec.Emit (OpCodes.Call, listener_proxy_value);
#endif
		}
開發者ID:FrancisVarga,項目名稱:mono,代碼行數:22,代碼來源:eval.cs

示例8: Emit

		public override void Emit (EmitContext ec)
		{
			if (Value == null) {
				ec.Emit (OpCodes.Ldnull);
				return;
			}

			//
			// Use string.Empty for both literals and constants even if
			// it's not allowed at language level
			//
			if (Value.Length == 0 && RootContext.Optimize && ec.CurrentType != TypeManager.string_type) {
				if (TypeManager.string_empty == null)
					TypeManager.string_empty = TypeManager.GetPredefinedField (TypeManager.string_type, "Empty", loc, TypeManager.string_type);

				if (TypeManager.string_empty != null) {
					ec.Emit (OpCodes.Ldsfld, TypeManager.string_empty);
					return;
				}
			}

			ec.Emit (OpCodes.Ldstr, Value);
		}
開發者ID:jdecuyper,項目名稱:mono,代碼行數:23,代碼來源:constant.cs

示例9: AddressOf

		public void AddressOf (EmitContext ec, AddressOp mode)
		{
			if (builder == null)
				builder = ec.GetTemporaryLocal (type);

			if (builder.LocalType.IsByRef) {
				//
				// if is_address, than this is just the address anyways,
				// so we just return this.
				//
				ec.Emit (OpCodes.Ldloc, builder);
			} else {
				ec.Emit (OpCodes.Ldloca, builder);
			}
		}
開發者ID:dyxu,項目名稱:vimrc,代碼行數:15,代碼來源:assign.cs

示例10: Emit

		//
		// if `dup_args' is true, a copy of the arguments will be left
		// on the stack. If `dup_args' is true, you can specify `this_arg'
		// which will be duplicated before any other args. Only EmitCall
		// should be using this interface.
		//
		public void Emit (EmitContext ec, bool dup_args, LocalTemporary this_arg)
		{
			LocalTemporary[] temps = null;

			if (dup_args && Count != 0)
				temps = new LocalTemporary [Count];

			if (reordered != null && Count > 1) {
				foreach (NamedArgument na in reordered)
					na.EmitAssign (ec);
			}

			int i = 0;
			foreach (Argument a in args) {
				a.Emit (ec);
				if (dup_args) {
					ec.Emit (OpCodes.Dup);
					(temps [i++] = new LocalTemporary (a.Type)).Store (ec);
				}
			}

			if (dup_args) {
				if (this_arg != null)
					this_arg.Emit (ec);

				for (i = 0; i < temps.Length; i++) {
					temps[i].Emit (ec);
					temps[i].Release (ec);
				}
			}
		}
開發者ID:pgoron,項目名稱:monodevelop,代碼行數:37,代碼來源:argument.cs

示例11: EmitLoad

		public void EmitLoad (EmitContext ec, bool boxInstance)
		{
			var instance_type = instance.Type;

			//
			// Push the instance expression
			//
			if (addressRequired) {
				//
				// If the expression implements IMemoryLocation, then
				// we can optimize and use AddressOf on the
				// return.
				//
				// If not we have to use some temporary storage for
				// it.
				var iml = instance as IMemoryLocation;
				if (iml != null) {
					iml.AddressOf (ec, AddressOp.Load);
				} else {
					LocalTemporary temp = new LocalTemporary (instance_type);
					instance.Emit (ec);
					temp.Store (ec);
					temp.AddressOf (ec, AddressOp.Load);
				}

				return;
			}

			instance.Emit (ec);

			// Only to make verifier happy
			if (boxInstance && RequiresBoxing ()) {
				ec.Emit (OpCodes.Box, instance_type);
			}
		}
開發者ID:blinds52,項目名稱:mono,代碼行數:35,代碼來源:codegen.cs

示例12: Emit

		public void Emit (EmitContext ec, bool conditionalAccess)
		{
			Label NullOperatorLabel;
			Nullable.Unwrap unwrap;

			if (conditionalAccess && Expression.IsNeverNull (instance))
				conditionalAccess = false;

			if (conditionalAccess) {
				NullOperatorLabel = ec.DefineLabel ();
				unwrap = instance as Nullable.Unwrap;
			} else {
				NullOperatorLabel = new Label ();
				unwrap = null;
			}

			IMemoryLocation instance_address = null;
			bool conditional_access_dup = false;

			if (unwrap != null) {
				unwrap.Store (ec);
				unwrap.EmitCheck (ec);
				ec.Emit (OpCodes.Brtrue_S, NullOperatorLabel);
			} else {
				if (conditionalAccess && addressRequired) {
					//
					// Don't allocate temp variable when instance load is cheap and load and load-address
					// operate on same memory
					//
					instance_address = instance as VariableReference;
					if (instance_address == null)
						instance_address = instance as LocalTemporary;

					if (instance_address == null) {
						EmitLoad (ec, false);
						ec.Emit (OpCodes.Dup);
						ec.EmitLoadFromPtr (instance.Type);

						conditional_access_dup = true;
					} else {
						instance.Emit (ec);
					}
				} else {
					EmitLoad (ec, !conditionalAccess);

					if (conditionalAccess) {
						conditional_access_dup = !IsInexpensiveLoad ();
						if (conditional_access_dup)
							ec.Emit (OpCodes.Dup);
					}
				}

				if (conditionalAccess) {
					if (instance.Type.Kind == MemberKind.TypeParameter)
						ec.Emit (OpCodes.Box, instance.Type);

					ec.Emit (OpCodes.Brtrue_S, NullOperatorLabel);

					if (conditional_access_dup)
						ec.Emit (OpCodes.Pop);
				}
			}

			if (conditionalAccess) {
				if (!ec.ConditionalAccess.Statement) {
					if (ec.ConditionalAccess.Type.IsNullableType)
						Nullable.LiftedNull.Create (ec.ConditionalAccess.Type, Location.Null).Emit (ec);
					else
						ec.EmitNull ();
				}

				ec.Emit (OpCodes.Br, ec.ConditionalAccess.EndLabel);
				ec.MarkLabel (NullOperatorLabel);

				if (instance_address != null) {
					instance_address.AddressOf (ec, AddressOp.Load);
				} else if (unwrap != null) {
					unwrap.Emit (ec);
					var tmp = ec.GetTemporaryLocal (unwrap.Type);
					ec.Emit (OpCodes.Stloc, tmp);
					ec.Emit (OpCodes.Ldloca, tmp);
					ec.FreeTemporaryLocal (tmp, unwrap.Type);
				} else if (!conditional_access_dup) {
					instance.Emit (ec);
				}
			}
		}
開發者ID:blinds52,項目名稱:mono,代碼行數:87,代碼來源:codegen.cs

示例13: EmitPredefined

		public void EmitPredefined (EmitContext ec, MethodSpec method, Arguments Arguments, bool statement = false, Location? loc = null)
		{
			Expression instance_copy = null;

			if (!HasAwaitArguments && ec.HasSet (BuilderContext.Options.AsyncBody)) {
				HasAwaitArguments = Arguments != null && Arguments.ContainsEmitWithAwait ();
				if (HasAwaitArguments && InstanceExpressionOnStack) {
					throw new NotSupportedException ();
				}
			}

			OpCode call_op;
			LocalTemporary lt = null;

			if (method.IsStatic) {
				call_op = OpCodes.Call;
			} else {
				call_op = IsVirtualCallRequired (InstanceExpression, method) ? OpCodes.Callvirt : OpCodes.Call;

				if (HasAwaitArguments) {
					instance_copy = InstanceExpression.EmitToField (ec);
					var ie = new InstanceEmitter (instance_copy, IsAddressCall (instance_copy, call_op, method.DeclaringType));

					if (Arguments == null) {
						ie.EmitLoad (ec, true);
					}
				} else if (!InstanceExpressionOnStack) {
					var ie = new InstanceEmitter (InstanceExpression, IsAddressCall (InstanceExpression, call_op, method.DeclaringType));
					ie.Emit (ec, ConditionalAccess);

					if (DuplicateArguments) {
						ec.Emit (OpCodes.Dup);
						if (Arguments != null && Arguments.Count != 0) {
							lt = new LocalTemporary (ie.GetStackType (ec));
							lt.Store (ec);
							instance_copy = lt;
						}
					}
				}
			}

			if (Arguments != null && !InstanceExpressionOnStack) {
				EmittedArguments = Arguments.Emit (ec, DuplicateArguments, HasAwaitArguments);
				if (EmittedArguments != null) {
					if (instance_copy != null) {
						var ie = new InstanceEmitter (instance_copy, IsAddressCall (instance_copy, call_op, method.DeclaringType));
						ie.Emit (ec, ConditionalAccess);

						if (lt != null)
							lt.Release (ec);
					}

					EmittedArguments.Emit (ec);
				}
			}

			if (call_op == OpCodes.Callvirt && (InstanceExpression.Type.IsGenericParameter || InstanceExpression.Type.IsStructOrEnum)) {
				ec.Emit (OpCodes.Constrained, InstanceExpression.Type);
			}

			if (loc != null) {
				//
				// Emit explicit sequence point for expressions like Foo.Bar () to help debugger to
				// break at right place when LHS expression can be stepped-into
				//
				ec.MarkCallEntry (loc.Value);
			}

			//
			// Set instance expression to actual result expression. When it contains await it can be
			// picked up by caller
			//
			InstanceExpression = instance_copy;

			if (method.Parameters.HasArglist) {
				var varargs_types = GetVarargsTypes (method, Arguments);
				ec.Emit (call_op, method, varargs_types);
			} else {
				//
				// If you have:
				// this.DoFoo ();
				// and DoFoo is not virtual, you can omit the callvirt,
				// because you don't need the null checking behavior.
				//
				ec.Emit (call_op, method);
			}

			// 
			// Pop the return value if there is one and stack should be empty
			//
			if (statement && method.ReturnType.Kind != MemberKind.Void)
				ec.Emit (OpCodes.Pop);
		}
開發者ID:blinds52,項目名稱:mono,代碼行數:93,代碼來源:codegen.cs

示例14: Emit

		public override void Emit (EmitContext ec)
		{
			Label l_initialized = ec.DefineLabel ();

			if (mg_cache != null) {
				ec.Emit (OpCodes.Ldsfld, mg_cache.Spec);
				ec.Emit (OpCodes.Brtrue_S, l_initialized);
			}

			base.Emit (ec);

			if (mg_cache != null) {
				ec.Emit (OpCodes.Stsfld, mg_cache.Spec);
				ec.MarkLabel (l_initialized);
				ec.Emit (OpCodes.Ldsfld, mg_cache.Spec);
			}
		}
開發者ID:psni,項目名稱:mono,代碼行數:17,代碼來源:delegate.cs

示例15: Emit

		public override void Emit (EmitContext ec)
		{
			if (builder == null)
				throw new InternalErrorException ("Emit without Store, or after Release");

			ec.Emit (OpCodes.Ldloc, builder);
		}
開發者ID:dyxu,項目名稱:vimrc,代碼行數:7,代碼來源:assign.cs


注:本文中的Mono.CSharp.EmitContext.Emit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。