The compiler: a facade to the CompilerParameters/CompilerContext/Pipeline subsystem.
        public void Run(string text)
        {
            BooCompiler compiler = new BooCompiler();
            compiler.Parameters.Ducky = true;
            compiler.Parameters.Pipeline = new CompileToMemory();
            compiler.Parameters.Input.Add(new StringInput("Script", text));

            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                compiler.Parameters.References.Add(assembly);
            }

            CompilerContext context = compiler.Run();

            if (context.GeneratedAssembly == null)
            {
                if (context.Errors.Count > 0)
                {
                    errors = context.Errors.ToString(true);
                }
                return;
            }

            try
            {
                Type[] types = context.GeneratedAssembly.GetTypes();
                Type scriptModule = types[types.Length - 1];
                MethodInfo mainEntry = scriptModule.Assembly.EntryPoint;
                mainEntry.Invoke(null, new object[mainEntry.GetParameters().Length]);
            }
            catch (Exception ex)
            {
                errors = ex.Message;
            }
        }
示例#2
0
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
     pipeline.Insert(1, new ImplicitBaseClassCompilerStep(typeof(BooConfigReader), "Prepare", "Horn.Core.Dsl"));
     pipeline.InsertBefore(typeof(ProcessMethodBodiesWithDuckTyping), new RightShiftToMethodCompilerStep());
     pipeline.Insert(2, new UnderscorNamingConventionsToPascalCaseCompilerStep());
     pipeline.Insert(3, new UseSymbolsStep());
 }
 protected override Type CompileMigration(MigrationReference migrationReference)
 {
   BooCompiler compiler = new BooCompiler();
   compiler.Parameters.Input.Add(new FileInput(migrationReference.Path));
   compiler.Parameters.References.Add(typeof(IDatabaseMigration).Assembly);
   foreach (string reference in _configuration.References)
   {
     _log.Debug("Referencing: " + reference);
     compiler.Parameters.References.Add(Assembly.LoadFrom(reference));
   }
   compiler.Parameters.OutputType = CompilerOutputType.Library;
   compiler.Parameters.GenerateInMemory = true;
   compiler.Parameters.OutputAssembly = Path.Combine(_workingDirectoryManager.WorkingDirectory, Path.GetFileNameWithoutExtension(migrationReference.Path) + ".dll");
   compiler.Parameters.Ducky = true;
   compiler.Parameters.Pipeline = new CompileToFile();
   CompilerContext cc = compiler.Run();
   if (cc.Errors.Count > 0)
   {
     foreach (CompilerError error in cc.Errors)
     {
       _log.ErrorFormat("{0}", error);
     }
     throw new InvalidOperationException();
   }
   if (cc.GeneratedAssembly == null)
   {
     throw new InvalidOperationException();
   }
   return MigrationHelpers.LookupMigration(cc.GeneratedAssembly, migrationReference);
 }
示例#4
0
		public ICompilationUnit Parse(IProjectContent projectContent, string fileName, string fileContent)
		{
			LoggingService.Debug("Parse " + fileName);
			int lineCount = 1;
			foreach (char c in fileContent) {
				if (c == '\n') {
					lineCount++;
				}
			}
			int[] lineLength = new int[lineCount];
			int length = 0;
			int i = 0;
			foreach (char c in fileContent) {
				if (c == '\n') {
					lineLength[i] = length;
					i += 1;
					length = 0;
				} else if (c != '\r') {
					length += 1;
				}
			}
			lineLength[i] = length;
			BooCompiler compiler = new BooCompiler();
			compiler.Parameters.Input.Add(new StringInput(fileName, fileContent));
			ICompilationUnit cu = Parse(projectContent, fileName, lineLength, compiler);
			AddCommentsAndRegions(cu, fileContent, fileName);
			return cu;
		}
示例#5
0
		public override Assembly Compile(string path, string outPath, bool cache)
		{
			Assembly asm = null;
			try
			{
				if (this.ExistsAndUpToDate(path, outPath) && cache)
					return Assembly.LoadFrom(outPath);

				// Precompile script to a temp file
				var precompiled = this.PreCompile(File.ReadAllText(path));
				var tmp = Path.GetTempFileName();
				File.WriteAllText(tmp, precompiled);

				// Compile
				var compiler = new Boo.Lang.Compiler.BooCompiler();
				compiler.Parameters.AddAssembly(typeof(Log).Assembly);
				compiler.Parameters.AddAssembly(Assembly.GetEntryAssembly());
				compiler.Parameters.Input.Add(new FileInput(tmp));
				compiler.Parameters.OutputAssembly = outPath;
				compiler.Parameters.Pipeline = new CompileToFile();

#if DEBUG
				compiler.Parameters.Debug = true;
#else
				compiler.Parameters.Debug = false;
#endif

				var context = compiler.Run();
				if (context.GeneratedAssembly == null)
				{
					var errors = context.Errors;
					var newExs = new CompilerErrorsException();

					foreach (var err in errors)
					{
						var newEx = new CompilerError(path, err.LexicalInfo.Line, err.LexicalInfo.Column, err.Message, false);
						newExs.Errors.Add(newEx);
					}

					throw newExs;
				}

				asm = context.GeneratedAssembly;
			}
			catch (CompilerErrorsException)
			{
				throw;
			}
			catch (UnauthorizedAccessException)
			{
				// Thrown if file can't be copied. Happens if script was
				// initially loaded from cache.
			}
			catch (Exception ex)
			{
				Log.Exception(ex);
			}

			return asm;
		}
示例#6
0
 private static BooCompiler GetCompiler()
 {
     var boo = new BooCompiler();
     boo.Parameters.Pipeline = new CompileToMemory();
     boo.Parameters.References.Add(typeof(IFormDefinition).Assembly);
     return boo;
 }
示例#7
0
 private void setupSources(BooCompiler compiler, ViewCompilerInfo info) {
     compiler.Parameters.Input.Clear();
     foreach (var source in info.Sources) {
         var input = new StringInput(source.Key, source.GetContent());
         compiler.Parameters.Input.Add(input);
     }
 }
示例#8
0
        public override bool Execute()
        {
            BooCompiler compiler = new BooCompiler();
            if (OutputAssembly == null)
            {
                compiler.Parameters.Pipeline = new CompileToMemory();
            }
            else
            {
                compiler.Parameters.Pipeline = new CompileToFile();
                compiler.Parameters.OutputAssembly = OutputAssembly.ItemSpec;
            }
            compiler.Parameters.OutputType = CompilerOutputType.ConsoleApplication;

            if (files == null || files.Length == 0)
            {
                Log.LogError("Must specify at least one file for the book task");
                return false;
            }

            foreach (ITaskItem taskItem in files)
            {
                FileInput input = new FileInput(taskItem.ItemSpec);
                compiler.Parameters.Input.Add(input);
            }

            foreach (ITaskItem reference in references)
            {
                Assembly assembly = Assembly.LoadFrom(reference.ItemSpec);
                compiler.Parameters.References.Add(assembly);
            }

            CompilerContext run = compiler.Run();

            if (run.Errors.Count > 0)
            {
                string s = run.Errors.ToString(true);
                Log.LogError("Failed to compile code: " + s);
                return false;
            }

            MethodInfo methodInfo = run.GeneratedAssembly.EntryPoint;
            if (methodInfo == null)
            {
                Log.LogError("Could not find entry point for the files");
                return false;
            }
            try
            {
                methodInfo.Invoke(null, new object[] { new string[0] });
            }
            catch (TargetInvocationException e)
            {
                Log.LogError("Scripts failed to run!");
                Log.LogError(e.InnerException.ToString());
            }

            return true;
        }
示例#9
0
        private void setupAssemblies(BooCompiler compiler, ViewCompilerInfo info) {
            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
                if(assembly.IsDynamic) continue;
				if(!compiler.Parameters.References.Contains(assembly)) {
					compiler.Parameters.References.Add(assembly);
				}
            }
        }
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
     pipeline.Insert(1,
                     new ImplicitBaseClassCompilerStep(typeof (BaseDaemonConfigurationDSL), "Prepare",
                                                       "Puppy.Monitoring.Daemon.DSL"));
     pipeline.InsertBefore(typeof (ProcessMethodBodiesWithDuckTyping),
                           new UnderscoreNamingConventionsToPascalCaseCompilerStep());
 }
 protected override void AddCompilerSteps(BooCompiler compiler, string filename, CompilerPipeline pipeline)
 {
     compiler.Parameters.AddAssembly(typeof(Boo.Lang.Compiler.Ast.DepthFirstTransformer).Assembly);
     compiler.Parameters.Pipeline.Insert(1,
         new MethodSubstitutionBaseClassCompilerStep(typeof(MyMethodSubstitutionBaseClass),
             "System",
             "Boo.Lang.Compiler.Ast.DepthFirstTransformer"));
 }
        protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
        {
            pipeline.Insert(1,
                            new ImplicitBaseClassCompilerStep(typeof (BaseOrderActionsDSL), "Prepare",
                                                               //default namespaces
                                                               "Rhino.DSL.Tests.SchedulingDSL"));
			pipeline.InsertBefore(typeof (ProcessMethodBodiesWithDuckTyping),
							 new UnderscoreNamingConventionsToPascalCaseCompilerStep());
        }
示例#13
0
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, 
     string[] urls)
 {
     int step = 1;
     pipeline.Insert(step++, new ImplicitBaseClassCompilerStep(typeof (MigrationBase), "Execute", "evo.Core.DSL"));
     pipeline.Insert(step++, new AutoImportCompilerStep("System", "evo.Core", "evo.Core.DSL"));
     pipeline.Insert(step++, new UseSymbolsStep());
     pipeline.Insert(step++, new AutoReferenceFilesCompilerStep());
 }
 public UnityScriptCompiler(UnityScriptCompilerParameters parameters)
 {
     if (parameters == null)
     {
         throw new ArgumentNullException("parameters");
     }
     this._parameters = parameters;
     this._compiler = new BooCompiler(this._parameters);
 }
示例#15
0
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
     pipeline.Insert(1, new ImplicitBaseClassCompilerStep(typeof (PhantomBase), "Execute", typeof(UtilityFunctions).Namespace));
     pipeline.Insert(2, new ExpressionToTargetNameStep());
     pipeline.Insert(3, new ExpressionToDependencyNamesStep());
     pipeline.Insert(4, new ExpressionToCallTargetNameStep());
     pipeline.Insert(5, new UseSymbolsStep());
     pipeline.Insert(6, new AutoReferenceFilesCompilerStep());
 }
示例#16
0
        public BooTemplateTypeBuilder(TemplateOptions options)
        {
            _booCompiler = new BooCompiler();
            CompilerResults = new CompilerResults( new TempFileCollection() );
            this.options = options;

            _booCompiler.Parameters.GenerateInMemory = true;
            _booCompiler.Parameters.Debug = true;
            _booCompiler.Parameters.OutputType = CompilerOutputType.Library;
        }
 public CompilerContext Compile(string name, string code, CompilerPipeline pipeline = null, Action<CompilerParameters> prepare = null) {
     if(null==pipeline) pipeline = new Parse();
     var compiler = new BooCompiler();
     compiler.Parameters.Pipeline = pipeline;
     compiler.Parameters.Input.Add(new ReaderInput(name, new StringReader(code)));
     if(prepare!=null) {
         prepare(compiler.Parameters);
     }
     return compiler.Run();
 }
示例#18
0
		private void RunCompilerStepAfterExpressionResolutionOn(CompileUnit compileUnit, ICompilerStep step)
		{
			var pipeline = new Boo.Lang.Compiler.Pipelines.ResolveExpressions { step };

			var compiler = new Boo.Lang.Compiler.BooCompiler(new CompilerParameters { Pipeline = pipeline });
			var result = compiler.Run(compileUnit);

			if (result.Errors.Count > 0)
				Assert.Fail(result.Errors.ToString(true));
		}
 protected override void CustomizeCompiler(
     BooCompiler compiler,
     CompilerPipeline pipeline,
     string[] urls)
 {
     pipeline.Insert(1,
         new ImplicitBaseClassCompilerStep(
             typeof(ResponseStrategy),
             "ExecuteRule",
             "System.Net.Mail"));
 }
 protected override void CustomizeCompiler(
   BooCompiler compiler,
   CompilerPipeline pipeline,
   string[] urls)
 {
   pipeline.Insert(1,
                   new ImplicitBaseClassCompilerStep(
                     typeof(QuoteGeneratorRule),
                     "Evaluate",
                     "BooDslExampleApp.QuoteGeneration"));
   pipeline.Insert(2, new UseSymbolsStep());
 }
示例#21
0
        /// <summary>
        /// Customise the compiler to fit the etl engine
        /// </summary>
        protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
        {
            compiler.Parameters.References.Add(typeof(EtlDslEngine).Assembly);
            compiler.Parameters.References.Add(typeof(EtlProcess).Assembly);
            pipeline.Insert(1, new AutoReferenceFilesCompilerStep());
            pipeline.Insert(2, new UseModuleNameAsNamespaceIfMissing());
            pipeline.Insert(3, new AutoImportCompilerStep(
                "Rhino.Etl.Core",
                "Rhino.Etl.Dsl",
                "Rhino.Etl.Dsl.Macros"));

            pipeline.InsertAfter(typeof(MacroAndAttributeExpansion), new CorrelateTypesToModuleName(moduleNameToContainedTypes));
        }
 protected override void CustomizeCompiler(BooCompiler compiler, CompilerPipeline pipeline, string[] urls)
 {
     // save to disk
     pipeline = new CompileToFile();
     compiler.Parameters.Pipeline = pipeline;
     //compiler.Parameters.Ducky = true;
     pipeline.Insert(1,
                     new AnonymousBaseClassCompilerStep(typeof (DeclerativeDslBase),
                                                        "Prepare", // method to override  
                                                        "DSL.Demo.Model",
                                                        "DSL.Demo.Declerative")); // namespace to add
     pipeline.Insert(2, new CaptureCompilerContextStep());
 }
示例#23
0
		public void MacroMacroCompilation()
		{
			CompilerParameters parameters = new CompilerParameters(false);
			parameters.References.Add(typeof(IEnumerable<>).Assembly);
			
			parameters.Input.Add(BooLangExtensionsSource("Macros/MacroMacro.boo"));
			parameters.Input.Add(BooLangExtensionsSource("Macros/AssertMacro.boo"));

			parameters.Pipeline = new Boo.Lang.Compiler.Pipelines.ResolveExpressions();

			Boo.Lang.Compiler.BooCompiler compiler = new Boo.Lang.Compiler.BooCompiler(parameters);
			CompilerContext results = compiler.Run();
			Assert.AreEqual(0, results.Errors.Count, results.Errors.ToString());
		}
        protected Assembly Compile(string filename, CompilerOutputType compilerOutputType)
        {
            BooCompiler compiler = new BooCompiler();
            compiler.Parameters.OutputType = compilerOutputType;
            compiler.Parameters.GenerateInMemory = true;
            compiler.Parameters.Pipeline = new CompileToMemory();
            AddCompilerSteps(compiler, filename, compiler.Parameters.Pipeline);
            compiler.Parameters.Input.Add(new FileInput(filename));

            CompilerContext run = compiler.Run();
            if (run.Errors.Count > 0)
                throw new CompilerError(run.Errors.ToString(true));
            return run.GeneratedAssembly;
        }
示例#25
0
        public override Assembly Compile(string path, string outPath)
        {
            Assembly asm = null;
            try
            {
                if (this.ExistsAndUpToDate(path, outPath))
                    return Assembly.LoadFrom(outPath);

                var compiler = new Boo.Lang.Compiler.BooCompiler();
                compiler.Parameters.AddAssembly(typeof(Log).Assembly);
                compiler.Parameters.AddAssembly(typeof(ScriptManager).Assembly);
                compiler.Parameters.Input.Add(new FileInput(path));
                compiler.Parameters.OutputAssembly = outPath;
                compiler.Parameters.Pipeline = new CompileToFile();

                var context = compiler.Run();
                if (context.GeneratedAssembly == null)
                {
                    var errors = context.Errors;
                    var newExs = new CompilerErrorsException();

                    foreach (var err in errors)
                    {
                        var newEx = new CompilerError(path, err.LexicalInfo.Line, err.LexicalInfo.Column, err.Message, false);
                        newExs.Errors.Add(newEx);
                    }

                    throw newExs;
                }

                asm = context.GeneratedAssembly;

                //this.SaveAssembly(asm, outPath);
            }
            catch (CompilerErrorsException)
            {
                throw;
            }
            catch (UnauthorizedAccessException)
            {
                // Thrown if file can't be copied. Happens if script was
                // initially loaded from cache.
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            return asm;
        }
示例#26
0
文件: Compiler.cs 项目: 0xb1dd1e/boo
		public static Assembly CompileString(string code)
		{
			var compiler = new BooCompiler(new CompilerParameters(false));
			
			compiler.Parameters.GenerateInMemory = true;
			compiler.Parameters.Pipeline = new NihPipeline();
			compiler.Parameters.Input.Add(new StringInput("string.nih", code));

			var result = compiler.Run();
			if (result.Errors.Count > 0)
				throw new CompilationErrorsException(result.Errors);
			
			return result.GeneratedAssembly;
		}
示例#27
0
文件: App.cs 项目: Bombadil77/boo
        public int Run(string[] args)
        {
            int resultCode = 127;

            AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;

            CheckBooCompiler();

            var parameters = new CompilerParameters(false);
            try
            {
                var setupTime = Stopwatch.StartNew();

                CommandLineParser.ParseInto(parameters, args);

                if (0 == parameters.Input.Count)
                    throw new ApplicationException(ResourceManager.GetString("BooC.NoInputSpecified"));

                var compiler = new BooCompiler(parameters);
                setupTime.Stop();

                var processingTime = Stopwatch.StartNew();
                var context = compiler.Run();
                processingTime.Stop();

                if (context.Warnings.Count > 0)
                {
                    Console.Error.WriteLine(context.Warnings);
                    Console.Error.WriteLine(Boo.Lang.ResourceManager.Format("BooC.Warnings", context.Warnings.Count));
                }

                if (context.Errors.Count == 0)
                    resultCode = 0;
                else
                {
                    foreach (CompilerError error in context.Errors)
                        Console.Error.WriteLine(error.ToString(parameters.TraceInfo));
                    Console.Error.WriteLine(ResourceManager.Format("BooC.Errors", context.Errors.Count));
                }

                if (parameters.TraceWarning)
                    Console.Error.WriteLine(ResourceManager.Format("BooC.ProcessingTime", parameters.Input.Count, processingTime.ElapsedMilliseconds, setupTime.ElapsedMilliseconds));
            }
            catch (Exception x)
            {
                var message = (parameters.TraceWarning) ? (object)x : (object)x.Message;
                Console.Error.WriteLine(ResourceManager.Format("BooC.FatalError", message));
            }
            return resultCode;
        }
        public void TransformerIsAppliedToCompileUnit()
        {
            StubTransformer transformer = new StubTransformer();

            TransformerCompilerStep transformerStep = new TransformerCompilerStep(transformer);

            CompileUnit unit = new CompileUnit();

            BooCompiler compiler = new BooCompiler();
            compiler.Parameters.Pipeline = new CompilerPipeline();
            compiler.Parameters.Pipeline.Insert(0, transformerStep);
            compiler.Run(unit);

            Assert.IsTrue(transformer.CompileUnitVisited);
        }
示例#29
0
		public void NameMatchingCanBeCustomized()
		{
			var parameters = new CompilerParameters();
			const string code = @"
l = []
l.ADD(42)
l.add(42)
print JOIN(l, "", "")
";
			parameters.Input.Add(new StringInput("code", code));
			parameters.Pipeline = new ResolveExpressions();
			parameters.Pipeline.Insert(0, new ActionStep(
			                           	() => My<NameResolutionService>.Instance.EntityNameMatcher = MatchIgnoringCase));
			CompilerContext result = new Boo.Lang.Compiler.BooCompiler(parameters).Run();
			Assert.AreEqual(0, result.Errors.Count, result.Errors.ToString());
		}
示例#30
-21
		public void EnvironmentBindingsCanBeCustomizedThroughCompilerParametersEnvironment()
		{
			EntityFormatter actualFormatter = null;
			var expectedFormatter = new EntityFormatter();
			
			var compiler = new Boo.Lang.Compiler.BooCompiler();
			compiler.Parameters.Pipeline = new CompilerPipeline { new ActionStep(() => actualFormatter = My<EntityFormatter>.Instance) };
			compiler.Parameters.Environment = new ClosedEnvironment(expectedFormatter);
			compiler.Run();

			Assert.AreSame(expectedFormatter, actualFormatter);
		}