提交 1b8d34db 编写于 作者: M Miguel de Icaza

[repl] Fix running specified scripts from command line, allow #! syntax, add print command

We were calling the Reset () method after we had initialized the driver
with the new command line arguments, clearing the list of files to execute
before we executed them.

Added support for #! in the csharp repl, and added the print() command to
the InteractiveBase
上级 1012ab0b
......@@ -115,6 +115,7 @@ namespace Mono.CSharp
if (inited)
return new string [0];
CompilerCallableEntryPoint.Reset ();
var crp = new ConsoleReportPrinter ();
driver = Driver.Create (args, false, crp);
if (driver == null)
......@@ -123,7 +124,6 @@ namespace Mono.CSharp
crp.Fatal = driver.fatal_errors;
ctx = driver.ctx;
CompilerCallableEntryPoint.Reset ();
RootContext.ToplevelTypes = new ModuleContainer (ctx);
var startup_files = new List<string> ();
......@@ -1051,6 +1051,16 @@ namespace Mono.CSharp
{
Evaluator.LoadAssembly (assembly);
}
static public void print (string text)
{
Output.WriteLine (text);
}
static public void print (string fmt, params object [] args)
{
Output.WriteLine (fmt, args);
}
#endif
/// <summary>
......@@ -1067,6 +1077,7 @@ namespace Mono.CSharp
" Prompt - The prompt used by the C# shell\n" +
" ContinuationPrompt - The prompt for partial input\n" +
" Time(() -> { }) - Times the specified code\n" +
" print (obj) - Shorthand for Console.WriteLine\n" +
" quit; - You'll never believe it - this quits the repl!\n" +
" help; - This help text\n";
}
......
......@@ -59,7 +59,6 @@ namespace Mono {
} catch {
return 1;
}
return new CSharpShell ().Run (startup_files);
}
}
......@@ -202,11 +201,20 @@ namespace Mono {
void ExecuteSources (IEnumerable<string> sources, bool ignore_errors)
{
bool first = true;
foreach (string file in sources){
try {
try {
using (System.IO.StreamReader r = System.IO.File.OpenText (file)){
ReadEvalPrintLoopWith (p => r.ReadLine ());
ReadEvalPrintLoopWith (p => {
var line = r.ReadLine ();
if (first && line.StartsWith ("#!")){
line = r.ReadLine ();
first = false;
}
return line;
});
}
} catch (FileNotFoundException){
Console.Error.WriteLine ("cs2001: Source file `{0}' not found", file);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册