예제 #1
0
파일: repl.cs 프로젝트: nestalk/mono
		static int Main (string [] args)
		{
			var cmd = new CommandLineParser (Console.Out);
			cmd.UnknownOptionHandler += HandleExtraArguments;

			var settings = cmd.ParseArguments (args);
			if (settings == null)
				return 1;
			var startup_files = new string [settings.SourceFiles.Count];
			int i = 0;
			foreach (var source in settings.SourceFiles)
				startup_files [i++] = source.FullPathName;
			settings.SourceFiles.Clear ();

			var eval = new Evaluator (new CompilerContext (settings, new ConsoleReportPrinter ()));

			eval.InteractiveBaseClass = typeof (InteractiveBaseShell);
			eval.DescribeTypeExpressions = true;

			CSharpShell shell;
#if !ON_DOTNET
			if (attach.HasValue) {
				shell = new ClientCSharpShell (eval, attach.Value);
			} else if (agent != null) {
				new CSharpAgent (eval, agent).Run (startup_files);
				return 0;
			} else
#endif
			{
				shell = new CSharpShell (eval);
			}
			return shell.Run (startup_files);
		}
예제 #2
0
        public static void Main(String[] myArgs)
        {
            _Compiler = new Runner();

            //var a = _Compiler.Execute("Math.Abs(-42);");
            //Assert.AreEqual(42, a);

            //var b = _Compiler.Execute("class Fact { public int Run(int n) { return n <= 0 ? 1 : n*Run(n-1); } }");
            //var c = _Compiler.Execute("new Fact().Run(5);");
            //Assert.AreEqual(120, c);

            //var d = _Compiler.Execute("\"abcdefgh\".Substring(1, 2);");
            //Assert.AreEqual("bc", d);

            //var e = _Compiler.Execute("var test = 123;");
            //Assert.AreEqual("bc", e);

            #region Feel free to step through...

            _Compiler = new Runner();
            var a = _Compiler.Execute("Math.Abs(-42);");
            var b = _Compiler.Execute("Math.Sin(Math.PI / 6);");
            var c = _Compiler.Execute("class Fact { public int Run(int n) { return n <= 0 ? 1 : n*Run(n-1); } }");
            var d = _Compiler.Execute("new Fact().Run(5);");
            var e = _Compiler.Execute("\"abcdefgh\".Substring(1, 2);");
            var f = _Compiler.Execute("class Echo { public Object Print(Object o) { return o; } }");
            var g = _Compiler.Execute("var test = 123;");
            var h = _Compiler.Execute("new Echo().Print(test);");

            #endregion

            #region Start the interactive (read-eval-print loop) shell...

            var _Report = new Report(new ConsoleReportPrinter());
            var _CLP    = new CommandLineParser(_Report);
                _CLP.UnknownOptionHandler += Mono.Driver.HandleExtraArguments;

            var _Settings = _CLP.ParseArguments(myArgs);
            if (_Settings == null || _Report.Errors > 0)
                Environment.Exit(1);

            var _Evaluator = new Evaluator(_Settings, _Report)
            {
                InteractiveBaseClass    = typeof(InteractiveBaseShell),
                DescribeTypeExpressions = true
            };

            //// Adding a assembly twice will lead to delayed errors...
            //_Evaluator.ReferenceAssembly(typeof(YourAssembly).Assembly);

            var _CSharpShell = new CSharpShell(_Evaluator).Run();

            #endregion
        }
예제 #3
0
파일: driver.cs 프로젝트: riviti/NRefactory
        public static bool InvokeCompiler(string [] args, TextWriter error)
        {
            try {
                CommandLineParser cmd = new CommandLineParser (error);
                var setting = cmd.ParseArguments (args);
                if (setting == null)
                    return false;

                var d = new Driver (new CompilerContext (setting, new StreamReportPrinter (error)));
                return d.Compile ();
            } finally {
                Reset ();
            }
        }
예제 #4
0
파일: repl.cs 프로젝트: GirlD/mono
		static int Main (string [] args)
		{
			var cmd = new CommandLineParser (Console.Out);
			cmd.UnknownOptionHandler += HandleExtraArguments;

			// Enable unsafe code by default
			var settings = new CompilerSettings () {
				Unsafe = true
			};

			if (!cmd.ParseArguments (settings, args))
				return 1;

			var startup_files = new string [settings.SourceFiles.Count];
			int i = 0;
			foreach (var source in settings.SourceFiles)
				startup_files [i++] = source.FullPathName;
			settings.SourceFiles.Clear ();

			TextWriter agent_stderr = null;
			ReportPrinter printer;
			if (agent != null) {
				agent_stderr = new StringWriter ();
				printer = new StreamReportPrinter (agent_stderr);
			} else {
				printer = new ConsoleReportPrinter ();
			}

			var eval = new Evaluator (new CompilerContext (settings, printer));

			eval.InteractiveBaseClass = typeof (InteractiveBaseShell);
			eval.DescribeTypeExpressions = true;
			eval.WaitOnTask = true;

			CSharpShell shell;
#if !ON_DOTNET
			if (attach.HasValue) {
				shell = new ClientCSharpShell (eval, attach.Value);
			} else if (agent != null) {
				new CSharpAgent (eval, agent, agent_stderr).Run (startup_files);
				return 0;
			} else
#endif
			{
				shell = new CSharpShell (eval);
			}
			return shell.Run (startup_files);
		}
예제 #5
0
파일: driver.cs 프로젝트: holmak/NRefactory
        public static CompilerCompilationUnit ParseFile(string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
        {
            lock (parseLock) {
                try {
                    //                                     Driver d = Driver.Create (args, false, null, reportPrinter);
                    //                                     if (d == null)
                    //                                             return null;

                    var r = new Report (reportPrinter);
                    CommandLineParser cmd = new CommandLineParser (r, Console.Out);
                    var setting = cmd.ParseArguments (args);
                    if (setting == null || r.Errors > 0)
                        return null;
                    setting.Version = LanguageVersion.V_5;

                    CompilerContext ctx = new CompilerContext (setting, r);

                    var files = new List<CompilationSourceFile> ();
                    var unit = new CompilationSourceFile (inputFile, inputFile, 0);
                    var module = new ModuleContainer (ctx);
                    unit.NamespaceContainer = new NamespaceContainer (null, module, null, unit);
                    files.Add (unit);
                    Location.Initialize (files);

                    // TODO: encoding from driver
                    SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.UTF8);

                    RootContext.ToplevelTypes = module;

                    CSharpParser parser = new CSharpParser (reader, unit);
                    parser.Lexer.TabSize = 1;
                    parser.Lexer.sbag = new SpecialsBag ();
                    parser.LocationsBag = new LocationsBag ();
                    parser.UsingsBag = new UsingsBag ();
                    parser.parse ();

                    return new CompilerCompilationUnit () {
                        ModuleCompiled = RootContext.ToplevelTypes,
                        LocationsBag = parser.LocationsBag,
                        UsingsBag = parser.UsingsBag,
                        SpecialsBag = parser.Lexer.sbag,
                        LastYYValue = parser.LastYYVal
                    };
                } finally {
                    Reset ();
                }
            }
        }
예제 #6
0
        public void ClearSession(Action callback = null)
        {
            ThreadPool.QueueUserWorkItem((o) =>
            {
                _errors = new List<string>();
                _warnings = new List<string>();

                var report = new Report(new Printer(msg => _errors.Add(msg.Text), msg => _warnings.Add(msg.Text)));
                var settings = new CommandLineParser(report).ParseArguments(new string[] { });
                _eval = new Evaluator(settings, report);

                foreach (string @namespace in Options.DefaultNamespaces)
                {
                    addUsing(@namespace);
                }

                if (callback != null)
                    callback();
            });
        }
예제 #7
0
파일: repl.cs 프로젝트: saga/mono
		static int Main (string [] args)
		{
			var r = new Report (new ConsoleReportPrinter ());
			var cmd = new CommandLineParser (r);
			cmd.UnknownOptionHandler += HandleExtraArguments;

			var settings = cmd.ParseArguments (args);
			if (settings == null || r.Errors > 0)
				return 1;

			var eval = new Evaluator (settings, r);

			eval.InteractiveBaseClass = typeof (InteractiveBaseShell);
			eval.DescribeTypeExpressions = true;

			string[] startup_files = { };
			/*
			try {
				startup_files = Evaluator.InitAndGetStartupFiles (args, HandleExtraArguments);
				Evaluator.DescribeTypeExpressions = true;
				Evaluator.SetInteractiveBaseClass (typeof (InteractiveBaseShell));
			} catch {
				return 1;
			}
			*/

			CSharpShell shell;
#if !ON_DOTNET
			if (attach.HasValue) {
				shell = new ClientCSharpShell (eval, attach.Value);
			} else if (agent != null) {
				new CSharpAgent (eval, agent).Run (startup_files);
				return 0;
			} else
#endif
			{
				shell = new CSharpShell (eval);
			}

			return shell.Run (startup_files);
		}
예제 #8
0
		public static int Main (string[] args)
		{
			Location.InEmacs = Environment.GetEnvironmentVariable ("EMACS") == "t";

			CommandLineParser cmd = new CommandLineParser (Console.Out);
			var settings = cmd.ParseArguments (args);
			if (settings == null)
				return 1;

			if (cmd.HasBeenStopped)
				return 0;

			Driver d = new Driver (new CompilerContext (settings, new ConsoleReportPrinter ()));

			if (d.Compile () && d.Report.Errors == 0) {
				if (d.Report.Warnings > 0) {
					Console.WriteLine ("Compilation succeeded - {0} warning(s)", d.Report.Warnings);
				}
				Environment.Exit (0);
				return 0;
			}
			
			
			Console.WriteLine("Compilation failed: {0} error(s), {1} warnings",
				d.Report.Errors, d.Report.Warnings);
			Environment.Exit (1);
			return 1;
		}
예제 #9
0
 private Evaluator CreateEvaluator(Printer errors)
 {
     var report = new Report(errors);
     var settings = new CommandLineParser(report).ParseArguments(new string[] {});
     return new Evaluator(settings, report);
 }
예제 #10
0
		public static CompilerCompilationUnit ParseFile (string[] args, Stream input, string inputFile, ReportPrinter reportPrinter)
		{
			lock (parseLock) {
				try {
//                                     Driver d = Driver.Create (args, false, null, reportPrinter);
//                                     if (d == null)
//                                             return null;
       
                                       var r = new Report (reportPrinter);
                                       CommandLineParser cmd = new CommandLineParser (r, Console.Out);
                                       var setting = cmd.ParseArguments (args);
                                       if (setting == null || r.Errors > 0)
						return null;

                                       CompilerContext ctx = new CompilerContext (setting, r);
                                       var d = new Driver (ctx);

					Location.AddFile (null, inputFile);
					Location.Initialize ();
	
					// TODO: encoding from driver
					SeekableStreamReader reader = new SeekableStreamReader (input, Encoding.Default);
					
					RootContext.ToplevelTypes = new ModuleContainer (ctx);
					CompilationUnit unit = null;
					try {
						unit = (CompilationUnit) Location.SourceFiles [0];
					} catch (Exception) {
						string path = Path.GetFullPath (inputFile);
						unit = new CompilationUnit (inputFile, path, 0);
					}
					CSharpParser parser = new CSharpParser (reader, unit, RootContext.ToplevelTypes);
					parser.Lexer.TabSize = 1;
					parser.Lexer.sbag = new SpecialsBag ();
					parser.LocationsBag = new LocationsBag ();
					parser.UsingsBag = new UsingsBag ();
					parser.parse ();
					
					return new CompilerCompilationUnit () { ModuleCompiled = RootContext.ToplevelTypes, LocationsBag = parser.LocationsBag, UsingsBag = parser.UsingsBag, SpecialsBag = parser.Lexer.sbag };
				} finally {
					Reset ();
				}
			}
		}