Beispiel #1
0
        protected override MethodInfo GetUserEntryPointMethod()
        {
            PureCompilationUnit unit = PureModuleBuilder.PureCompilationUnit;

            Debug.Assert(unit.EntryPoint != null);
            return(unit.EntryPoint.ArgFullInfo);
        }
Beispiel #2
0
        public PureModuleBuilder /*!*/ DefineModule(PureCompilationUnit /*!*/ compilationUnit)
        {
            PureModuleBuilder builder = new PureModuleBuilder(compilationUnit, this);

            PureAssembly.Module = builder;
            return(builder);
        }
Beispiel #3
0
        public override bool Build(IEnumerable <PhpSourceFile> /*!*/ sourceFiles, CompilationContext /*!*/ context)
        {
            PureCompilationUnit unit = new PureCompilationUnit(false, false);

            bool success = unit.Compile(sourceFiles, this, context, context.Config.Globalization.PageEncoding);

            if (success)
            {
                Save();
            }

            return(success);
        }
Beispiel #4
0
        protected override void EmitEntryPoint(MethodBuilder /*!*/ builder)
        {
            PureCompilationUnit unit = PureModuleBuilder.PureCompilationUnit;

            Debug.Assert(unit.EntryPoint != null);

            ILEmitter il = new ILEmitter(builder);

            // LOAD new RoutineDelegate(<main PHP method>);
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Ldftn, unit.EntryPoint.ArgLessInfo);
            il.Emit(OpCodes.Newobj, Constructors.RoutineDelegate);

            // ScriptContext.RunApplication(<main helper delegate>, null, null);
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Ldnull);
            il.Emit(OpCodes.Call, Methods.ScriptContext.RunApplication);

            // RETURN;
            il.Emit(OpCodes.Ret);
        }
Beispiel #5
0
		public PureModuleBuilder(PureCompilationUnit/*!*/ compilationUnit, PureAssemblyBuilder/*!*/ assemblyBuilder)
			: base(compilationUnit, assemblyBuilder.PureAssembly)
		{
			this.assemblyBuilder = assemblyBuilder;
			DefineBuilders();
		}
		public PureModuleBuilder/*!*/ DefineModule(PureCompilationUnit/*!*/ compilationUnit)
		{
			PureModuleBuilder builder = new PureModuleBuilder(compilationUnit, this);
			PureAssembly.Module = builder;
			return builder;
		}
		public override bool Build(IEnumerable<PhpSourceFile>/*!*/ sourceFiles, CompilationContext/*!*/ context)
		{
			PureCompilationUnit unit = new PureCompilationUnit(false, false);

			bool success = unit.Compile(sourceFiles, this, context, context.Config.Globalization.PageEncoding);

			if (success) Save();

			return success;
		}
Beispiel #8
0
        /// <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();
            }
        }
Beispiel #9
0
 public PureModuleBuilder(PureCompilationUnit /*!*/ compilationUnit, PureAssemblyBuilder /*!*/ assemblyBuilder)
     : base(compilationUnit, assemblyBuilder.PureAssembly)
 {
     this.assemblyBuilder = assemblyBuilder;
     DefineBuilders();
 }
Beispiel #10
0
 /// <summary>
 /// Called by the builder.
 /// </summary>
 internal PureModule(PureCompilationUnit /*!*/ compilationUnit, PureAssembly /*!*/ assembly)
     : base(compilationUnit, assembly)
 {
 }
Beispiel #11
0
		/// <summary>
		/// Called by the builder.
		/// </summary>
		internal PureModule(PureCompilationUnit/*!*/ compilationUnit, PureAssembly/*!*/ assembly)
			: base(compilationUnit, assembly)
		{
		}