From a33613b5b58ab257582e485c86869b316e7e2552 Mon Sep 17 00:00:00 2001 From: Kai Zeng Date: Wed, 20 Jul 2016 20:54:19 -0700 Subject: [PATCH] code clean up --- csharp/Repl/RoslynScriptEngine.cs | 11 +++++++---- csharp/Repl/ScriptResult.cs | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/csharp/Repl/RoslynScriptEngine.cs b/csharp/Repl/RoslynScriptEngine.cs index 45004b2..091694d 100644 --- a/csharp/Repl/RoslynScriptEngine.cs +++ b/csharp/Repl/RoslynScriptEngine.cs @@ -41,6 +41,8 @@ namespace Microsoft.Spark.CSharp private readonly SparkContext sc; private readonly SparkCLRHost host; + private readonly ParseOptions options; + public RoslynScriptEngine(SparkConf sparkConf, SparkContext sc) { this.sparkConf = sparkConf; @@ -54,6 +56,8 @@ namespace Microsoft.Spark.CSharp var sparkLocalDir = sparkConf.Get("spark.local.dir", Path.GetTempPath()); compilationDumpDirectory = Path.Combine(sparkLocalDir, Path.GetRandomFileName()); Directory.CreateDirectory(compilationDumpDirectory); + + options = new CSharpParseOptions(LanguageVersion.CSharp6, DocumentationMode.Parse, SourceCodeKind.Script); } internal Script CreateScript(string code) @@ -103,7 +107,7 @@ namespace Microsoft.Spark.CSharp { message.Append("[").Append(diagnostic.Severity).Append("] ").Append(": ").Append(diagnostic).Append("\r\n"); } - return new ScriptResult(null, null, new Exception(message.ToString())); + return new ScriptResult(compilationException: new Exception(message.ToString())); } var compilationDump = DumpCompilation(script.GetCompilation()); @@ -135,11 +139,11 @@ namespace Microsoft.Spark.CSharp } } previousState = endState; - return new ScriptResult(endState.ReturnValue, null, null); + return new ScriptResult(returnValue: endState.ReturnValue); } catch (Exception e) { - return new ScriptResult(null, e, null); + return new ScriptResult(executionException: e); } } @@ -165,7 +169,6 @@ namespace Microsoft.Spark.CSharp /// internal bool IsCompleteSubmission(string code) { - var options = new CSharpParseOptions(LanguageVersion.CSharp6, DocumentationMode.Diagnose, SourceCodeKind.Script); SyntaxTree syntaxTree = SyntaxFactory.ParseSyntaxTree(code, options); return SyntaxFactory.IsCompleteSubmission(syntaxTree); } diff --git a/csharp/Repl/ScriptResult.cs b/csharp/Repl/ScriptResult.cs index 3ad6dad..c5e8be3 100644 --- a/csharp/Repl/ScriptResult.cs +++ b/csharp/Repl/ScriptResult.cs @@ -33,10 +33,10 @@ namespace Microsoft.Spark.CSharp IsCompleteSubmission = true; } - public object ReturnValue { get; private set; } - public bool IsCompleteSubmission { get; private set; } + public object ReturnValue { get; private set; } + public ExceptionDispatchInfo ExecuteExceptionInfo { get; private set; } public ExceptionDispatchInfo CompileExceptionInfo { get; private set; }