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


C# ILEmitter.LdcI4方法代码示例

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


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

示例1: EmitArgFullPreCall

		public static void EmitArgFullPreCall(ILEmitter/*!*/ il, IPlace/*!*/ stack, bool argsAware,
		  int formalParamCount, int formalTypeParamCount, out LocalBuilder locArgsCount)
		{
			if (argsAware)
			{
				locArgsCount = il.DeclareLocal(typeof(int));

				// locArgsCount = stack.MakeArgsAware(<formal tpye param count | formal param count>);
				stack.EmitLoad(il);
				il.LdcI4((formalTypeParamCount << 16) | formalParamCount);
				il.Emit(OpCodes.Call, Methods.PhpStack.MakeArgsAware);
				il.Stloc(locArgsCount);
			}
			else
			{
				locArgsCount = null;

				// CALL stack.RemoveFrame();
				stack.EmitLoad(il);
				il.Emit(OpCodes.Call, Methods.PhpStack.RemoveFrame);
			}
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:22,代码来源:PhpStackBuilder.cs

示例2: EmitDeclareHelper

		/// <summary>
		/// Emits helper declaring all single-declared functions and classes in the script being built.
		/// </summary>
		/// <remarks>
		/// For each function and class emits a call to <see cref="ApplicationContext.DeclareFunction"/> and 
        /// <see cref="ApplicationContext.DeclareType"/>, respectively, which declares it.
		/// The helper is called as the first instruction of Main helper. 
		/// </remarks>		
		private void EmitDeclareHelper()
		{
			PureCompilationUnit unit = this.PureCompilationUnit;
			ILEmitter il = new ILEmitter(declareHelperBuilder);
			IndexedPlace app_context_place = new IndexedPlace(PlaceHolder.Argument, 0);
            TypeBuilder publicsContainer = null;    // container type for public stubs of global declarations (which are inaccessible from other assemblies)

			foreach (PhpFunction function in unit.GetDeclaredFunctions())
			{
				if (function.IsDefinite)
				{
					app_context_place.EmitLoad(il);

					// NEW RoutineDelegate(<static method>);
					il.Emit(OpCodes.Ldnull);
					il.Emit(OpCodes.Ldftn, function.ArgLessInfo);
					il.Emit(OpCodes.Newobj, Constructors.RoutineDelegate);

					// LOAD <full name>;
					il.Emit(OpCodes.Ldstr, function.FullName);

					// LOAD <attributes>;
					il.LdcI4((int)function.MemberDesc.MemberAttributes);

                    // LOAD <argfull>
                    if (function.ArgFullInfo != null)
                        CodeGenerator.EmitLoadMethodInfo(
                            il,
                            (function.ArgFullInfo.DeclaringType != null)
                                ? function.ArgFullInfo
                                : EmitPhpFunctionPublicStub(ref publicsContainer, function) // function.ArgFullInfo is real global method not accessible from other assemblies, must be wrapped
                            /*, AssemblyBuilder.DelegateBuilder*/);
                    else
                        il.Emit(OpCodes.Ldnull);
                    
					// CALL <application context>.DeclareFunction(<stub>, <name>, <member attributes>, <argfull>)
					il.Emit(OpCodes.Call, Methods.ApplicationContext.DeclareFunction);
				}
			}

			foreach (PhpType type in unit.GetDeclaredTypes())
			{
				if (type.IsDefinite)
				{
					// CALL <application context>.DeclareType(<type desc>, <name>);
					type.EmitAutoDeclareOnApplicationContext(il, app_context_place);
				}
			}

			foreach (GlobalConstant constant in unit.GetDeclaredConstants())
			{
				if (constant.IsDefinite)
				{
					app_context_place.EmitLoad(il);

					// CALL <application context>.DeclareConstant(<name>, <value>);
					il.Emit(OpCodes.Ldstr, constant.FullName);
                    //il.Emit(OpCodes.Ldsfld, constant.RealField);
                    //if (constant.RealField.FieldType.IsValueType) il.Emit(OpCodes.Box, constant.RealField.FieldType);
                    il.LoadLiteralBox(constant.Value);
					il.Emit(OpCodes.Call, Methods.ApplicationContext.DeclareConstant);
				}
			}

			il.Emit(OpCodes.Ret);

            // complete the publicsContainer type, if created:
            if (publicsContainer != null)
                publicsContainer.CreateType();
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:78,代码来源:ModuleBuilders.CLR.cs

示例3: EmitReturnValueCopy

        /// <summary>
        /// Emit <see cref="PhpVariable.Copy"/> if needed. It means <see cref="Expression.Access"/> has to be <see cref="AccessType.Read"/> and <paramref name="returnType"/> has to be copiable.
        /// </summary>
        /// <param name="il">The <see cref="ILEmitter"/>.</param>
        /// <param name="returnType"><see cref="PhpTypeCode"/> of function call return value.</param>
        protected void EmitReturnValueCopy(ILEmitter/*!*/il, PhpTypeCode returnType)
        {
            Debug.Assert(il != null);

            // copy only if we are reading the return value &&
            // only if return type is copiable:
            if (access != AccessType.None &&   // reading, not literals:
                PhpTypeCodeEnum.IsDeeplyCopied(returnType) &&
                returnType != PhpTypeCode.PhpReference) // PhpSmartReference can be an issue if method returns an object field (but this is handled by binders)
            {
                il.LdcI4((int)CopyReason.ReturnedByCopy);
                il.Emit(OpCodes.Call, Methods.PhpVariable.Copy);
            }
        }
开发者ID:MpApQ,项目名称:Phalanger,代码行数:19,代码来源:FunctionCall.cs

示例4: EmitSetConversion

		internal void EmitSetConversion(ILEmitter/*!*/ il, PhpTypeCode sourceTypeCode, Type/*!*/ targetType)
		{
			LocalBuilder strictness = il.GetTemporaryLocal(typeof(PHP.Core.ConvertToClr.ConversionStrictness));
			if (!ClrOverloadBuilder.EmitConvertToClr(il, sourceTypeCode, targetType, strictness))
			{
				Label label_ok = il.DefineLabel();

				il.Ldloc(strictness);
				il.LdcI4((int)PHP.Core.ConvertToClr.ConversionStrictness.Failed);
				il.Emit(OpCodes.Ceq);
				il.Emit(OpCodes.Brfalse, label_ok);

				il.Emit(OpCodes.Ldstr, Property.DeclaringType.FullName);
				il.Emit(OpCodes.Ldstr, Property.FullName);
				il.Emit(OpCodes.Call, Methods.PhpException.PropertyTypeMismatch);

				il.MarkLabel(label_ok, true);
			}
			il.ReturnTemporaryLocal(strictness);
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:20,代码来源:Properties.cs

示例5: EmitDeclareFunction

		/// <summary>
		/// Emits call to <see cref="ScriptContext.DeclareFunction"/>.
		/// </summary>
		internal static void EmitDeclareFunction(ILEmitter/*!*/il, IPlace/*!*/scriptContextPlace, PhpFunction/*!*/ function)
        {
            Label lbl_fieldinitialized = il.DefineLabel();

            // private static PhpRoutine <routine>'function = null;
            var attrs = FieldAttributes.Static | FieldAttributes.Private;
            var field = il.TypeBuilder.DefineField(string.Format("<routine>'{0}", function.FullName), typeof(PhpRoutineDesc), attrs);

            // if (<field> == null)
            il.Emit(OpCodes.Ldsfld, field);
            il.Emit(OpCodes.Brtrue, lbl_fieldinitialized);
            {
                // <field> = new PhpRoutineDesc(<attributes>, new RoutineDelegate(null, <delegate>))

                // LOAD <attributes>;
                il.LdcI4((int)function.MemberDesc.MemberAttributes);

                // new RoutineDelegate(null, <delegate>, true)
                il.Emit(OpCodes.Ldnull);
                il.Emit(OpCodes.Ldftn, function.ArgLessInfo);
                il.Emit(OpCodes.Newobj, Constructors.RoutineDelegate);
                il.LoadBool(true);

                // new PhpRoutineDesc:
                il.Emit(OpCodes.Newobj, Constructors.PhpRoutineDesc_Attr_Delegate_Bool);

                // <field> = <STACK>
                il.Emit(OpCodes.Stsfld, field);

                // new PurePhpFunction(<field>, fullName, argfull);   // writes desc.Member
                il.Emit(OpCodes.Ldsfld, field);
                il.Emit(OpCodes.Ldstr, function.FullName);
                CodeGenerator.EmitLoadMethodInfo(il, function.ArgFullInfo/*, AssemblyBuilder.DelegateBuilder*/);
                il.Emit(OpCodes.Newobj, Constructors.PurePhpFunction);
                il.Emit(OpCodes.Pop);
                
            }
            il.MarkLabel(lbl_fieldinitialized);

            // CALL ScriptContent.DeclareFunction(<field>, <name>);
            scriptContextPlace.EmitLoad(il);
            
            // LOAD <field>
            il.Emit(OpCodes.Ldsfld, field);            

            // LOAD <fullName>
            il.Emit(OpCodes.Ldstr, function.FullName);

            //
            il.Emit(OpCodes.Call, Methods.ScriptContext.DeclareFunction);
        }
开发者ID:dw4dev,项目名称:Phalanger,代码行数:54,代码来源:CodeGenerator.cs

示例6: EmitPeekArgument

		/// <summary>
		/// Emits code which pops argument from the <see cref="PhpStack"/> and pushes it on the evaluation stack.
		/// </summary>
		private void EmitPeekArgument(ILEmitter/*!*/ il, int index)
		{
			bool optional = index >= signature.MandatoryParamCount;
			int stack_offset = index + 1;

			if (signature.IsAlias(index))
			{
				// LOAD stack.PeekReference[Optional](<stack_offset>, [default_value]);
				arglessStackPlace.EmitLoad(il);                           // stack
				il.LdcI4(stack_offset);                                   // offset on stack

				if (optional)
					il.Emit(OpCodes.Call, Methods.PhpStack.PeekReferenceOptional);
				else
					il.Emit(OpCodes.Call, Methods.PhpStack.PeekReference);
			}
			else
			{
				// LOAD stack.PeekValue[Optional](<stack_offset>);
				arglessStackPlace.EmitLoad(il);                           // stack
				il.LdcI4(stack_offset);                                   // offset on stack

				if (optional)
					il.Emit(OpCodes.Call, Methods.PhpStack.PeekValueOptional);
				else
					il.Emit(OpCodes.Call, Methods.PhpStack.PeekValue);
			}
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:31,代码来源:Methods.cs

示例7: EmitPeekPseudoGenericArgument

        private void EmitPeekPseudoGenericArgument(ILEmitter/*!*/ il, int index)
		{
			bool optional = index >= signature.MandatoryGenericParamCount;
			int stack_offset = index + 1;

			// LOAD stack.PeekType[Optional](<stack_offset>, [default_value]);
			arglessStackPlace.EmitLoad(il);                           // stack
			il.LdcI4(stack_offset);                                   // offset on stack

			if (optional)
				il.Emit(OpCodes.Call, Methods.PhpStack.PeekTypeOptional);
			else
				il.Emit(OpCodes.Call, Methods.PhpStack.PeekType);
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:14,代码来源:Methods.cs

示例8: EmitLoad

		/// <summary>
		/// Emits code that loads the value from this storage place.
		/// </summary>
		/// <param name="il">The <see cref="ILEmitter"/> to emit the code to.</param>
		public void EmitLoad(ILEmitter il)
		{
			switch (holder)
			{
				case PlaceHolder.Local: il.Ldloc(index); break;
				case PlaceHolder.Argument: il.Ldarg(index); break;
				case PlaceHolder.None: il.LdcI4(index); break;
			}
		}
开发者ID:dw4dev,项目名称:Phalanger,代码行数:13,代码来源:Places.cs

示例9: EmitLoadDefault

        /// <summary>
        /// Emits load of default value assuming given method fails.
        /// </summary>
        /// <param name="il">ILEmitter.</param>
        /// <param name="method">Method which default return value have to be loaded.</param>
        /// <returns></returns>
        public static PhpTypeCode EmitLoadDefault(ILEmitter/*!*/il, MethodInfo/*!*/method)
        {
            if (method.ReturnType == Types.Bool[0] || method.ReturnTypeCustomAttributes.IsDefined(typeof(CastToFalseAttribute), false))
            {
                il.LoadBool(false);
                return PhpTypeCode.Boolean;
            }

            if (method.ReturnType == Types.Int[0])
            {
                il.LdcI4(0);
                return PhpTypeCode.Integer;
            }

            return PhpTypeCode.Void;
        }
开发者ID:proff,项目名称:Phalanger,代码行数:22,代码来源:OverloadsBuilder.cs

示例10: EmitReferencePeekUnchecked

		public static object EmitReferencePeekUnchecked(ILEmitter/*!*/ il, int index, object/*!*/ stackPlace)
		{
			Debug.Assert(il != null && stackPlace != null);

			// LOAD stack.PeekReferenceUnchecked(<index+1>);
			((IPlace)stackPlace).EmitLoad(il);
			il.LdcI4(index);
			il.Emit(OpCodes.Call, Methods.PhpStack.PeekReferenceUnchecked);

			return typeof(PhpReference);
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:11,代码来源:PhpStackBuilder.cs

示例11: EmitValuePeek

		public static object EmitValuePeek(ILEmitter/*!*/ il, int index, object/*!*/ stackPlace)
		{
			Debug.Assert(il != null && stackPlace != null);

			// CALL stack.PeekValue(<index+1>);
			((IPlace)stackPlace).EmitLoad(il);
			il.LdcI4(index + 1);
			il.Emit(OpCodes.Call, Methods.PhpStack.PeekValue);

			return typeof(object);
		}
开发者ID:tiaohai,项目名称:Phalanger,代码行数:11,代码来源:PhpStackBuilder.cs


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