Пример #1
0
        public void Initialize(MosaCompiler compiler)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(@"compiler");
            }

            Compiler = compiler;

            Architecture         = Compiler.CompilerOptions.Architecture;
            TypeSystem           = Compiler.TypeSystem;
            TypeLayout           = Compiler.TypeLayout;
            CompilerTrace        = Compiler.CompilerTrace;
            CompilerOptions      = Compiler.CompilerOptions;
            CompilationScheduler = Compiler.CompilationScheduler;
            Linker = compiler.Linker;

            PreCompilePipeline  = new CompilerPipeline();
            PostCompilePipeline = new CompilerPipeline();
            Counters            = new Counters();
            PlugSystem          = new PlugSystem();
            CompilerData        = new CompilerData(this);

            // Create new dictionary
            IntrinsicTypes = new Dictionary <string, Type>();

            // Get all the classes that implement the IIntrinsicInternalMethod interface
            IEnumerable <Type> types = AppDomain.CurrentDomain.GetAssemblies()
                                       .SelectMany(s => s.GetTypes())
                                       .Where(p => typeof(IIntrinsicInternalMethod).IsAssignableFrom(p) && p.IsClass);

            // Iterate through all the found types
            foreach (var t in types)
            {
                // Now get all the ReplacementTarget attributes
                var attributes = (ReplacementTargetAttribute[])t.GetCustomAttributes(typeof(ReplacementTargetAttribute), true);
                for (int i = 0; i < attributes.Length; i++)
                {
                    // Finally add the dictionary entry mapping the target string and the type
                    IntrinsicTypes.Add(attributes[i].Target, t);
                }
            }

            PlatformInternalRuntimeType = GetPlatformInternalRuntimeType();

            // Extended Setup
            ExtendCompilerSetup();

            // Build the default pre-compiler pipeline
            Architecture.ExtendPreCompilerPipeline(this.PreCompilePipeline);

            // Build the default post-compiler pipeline
            Architecture.ExtendPostCompilerPipeline(this.PostCompilePipeline);
        }
Пример #2
0
        public void Initialize(MosaCompiler compiler)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(@"compiler");
            }

            Compiler = compiler;

            Architecture         = Compiler.CompilerOptions.Architecture;
            TypeSystem           = Compiler.TypeSystem;
            TypeLayout           = Compiler.TypeLayout;
            CompilerTrace        = Compiler.CompilerTrace;
            CompilerOptions      = Compiler.CompilerOptions;
            CompilationScheduler = Compiler.CompilationScheduler;
            Linker = compiler.Linker;

            PreCompilePipeline  = new CompilerPipeline();
            PostCompilePipeline = new CompilerPipeline();
            GlobalCounters      = new Counters();
            PlugSystem          = new PlugSystem();
            CompilerData        = new CompilerData();

            // Create new dictionary
            IntrinsicTypes = new Dictionary <string, Type>();

            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                if (type.IsClass && typeof(IIntrinsicInternalMethod).IsAssignableFrom(type))
                {
                    // Now get all the ReplacementTarget attributes
                    var attributes = (ReplacementTargetAttribute[])type.GetCustomAttributes(typeof(ReplacementTargetAttribute), true);
                    for (int i = 0; i < attributes.Length; i++)
                    {
                        // Finally add the dictionary entry mapping the target string and the type
                        IntrinsicTypes.Add(attributes[i].Target, type);
                    }
                }
            }

            PlatformInternalRuntimeType = GetPlatformInternalRuntimeType();
            InternalRuntimeType         = GeInternalRuntimeType();

            // Extended Setup
            ExtendCompilerSetup();

            // Build the default pre-compiler pipeline
            Architecture.ExtendPreCompilerPipeline(PreCompilePipeline);

            // Build the default post-compiler pipeline
            Architecture.ExtendPostCompilerPipeline(PostCompilePipeline);
        }