Exemple #1
0
        public void GenerateCodeForAssembly()
        {
#if !XBOX
            // Generate the abstract syntax tree if it hasn't already been generated.
            if (this.AbstractSyntaxTree == null)
            {
                Parse();
                Optimize();
            }

            // Initialize global code-gen information.
            var optimizationInfo = new OptimizationInfo(this.Engine);
            optimizationInfo.AbstractSyntaxTree      = this.AbstractSyntaxTree;
            optimizationInfo.StrictMode              = this.StrictMode;
            optimizationInfo.MethodOptimizationHints = this.MethodOptimizationHints;


            var re = this.Engine.ReflectionEmitInfo;

            // Create method
            string methodName = IsMainClass ? "Main" : string.Format("Func_{0}", GeneratedMethod.Prepare());

            var methodBuilder = re.TypeBuilder.DefineMethod(methodName,
                                                            System.Reflection.MethodAttributes.HideBySig | System.Reflection.MethodAttributes.Static | System.Reflection.MethodAttributes.Public,
                                                            typeof(object), GetParameterTypes());

            // Generate the IL for the method.
            ILGenerator generator = new ReflectionEmitILGenerator(methodBuilder.GetILGenerator());

            GenerateCode(generator, optimizationInfo);
            generator.Complete();

            this.GeneratedMethod = new GeneratedMethod(optimizationInfo.NestedFunctions);
#endif
        }
        public void GenerateCodeForAssembly()
        {
            #if !XBOX
            // Generate the abstract syntax tree if it hasn't already been generated.
            if (this.AbstractSyntaxTree == null)
            {
                Parse();
                Optimize();
            }

            // Initialize global code-gen information.
            var optimizationInfo = new OptimizationInfo(this.Engine);
            optimizationInfo.AbstractSyntaxTree = this.AbstractSyntaxTree;
            optimizationInfo.StrictMode = this.StrictMode;
            optimizationInfo.MethodOptimizationHints = this.MethodOptimizationHints;

            var re = this.Engine.ReflectionEmitInfo;

            // Create method
            string methodName = IsMainClass ? "Main" : string.Format("Func_{0}", GeneratedMethod.Prepare());

            var methodBuilder = re.TypeBuilder.DefineMethod(methodName,
                System.Reflection.MethodAttributes.HideBySig | System.Reflection.MethodAttributes.Static | System.Reflection.MethodAttributes.Public,
                typeof(object), GetParameterTypes());

            // Generate the IL for the method.
            ILGenerator generator = new ReflectionEmitILGenerator(methodBuilder.GetILGenerator());

            GenerateCode(generator, optimizationInfo);
            generator.Complete();

            this.GeneratedMethod = new GeneratedMethod(optimizationInfo.NestedFunctions);
            #endif
        }