/// <summary>A default interpreter</summary> public Interpreter() { sink = new StdoutOutputSinkWrapper(); ErrorReporting.SetSink(new StderrOutputSinkWrapper()); if (JSIL) { ErrorReporting.SetSink(sink); } initialise(); }
private static int runModule(string code, string modname, string mode, WSOutputSink sink) { var interp = new Interpreter(sink); ErrorReporting.SetSink(new OutputSinkWrapper(Console.Error)); interp.RPCSink = sink; interp.AddModuleRoot(Path.GetFullPath(".")); interp.FailedImportHook = loadCachedModule; interp.LoadPrelude(); Parser parser = new Parser(modname, code); ParseNode module; try { module = parser.Parse(); ExecutionTreeTranslator ett = new ExecutionTreeTranslator(); Node eModule = ett.Translate(module as ObjectParseNode); sink.SendEvent("build-succeeded", modname); if (mode == "build") { return(0); } interp.EnterModule(modname); try { eModule.Evaluate(interp); } catch (GraceExceptionPacketException ex) { sink.SendRuntimeError(ex.ExceptionPacket.Description, ex.ExceptionPacket.StackTrace); } } catch (StaticErrorException ex) { sink.SendStaticError(ex.Code, ex.Module, ex.Line, ex.Message); } catch (ThreadAbortException) { throw; } catch (WebSocketClosedException) { return(0); } catch (Exception ex) { System.Console.Error.WriteLine( "An internal error occurred. " + "Debugging information follows."); System.Console.Error.WriteLine("Runtime version: " + Interpreter.GetRuntimeVersion()); System.Console.Error.WriteLine(ex); System.Console.Error.WriteLine(ex.StackTrace); System.Console.Error.WriteLine( "\nAn internal error occurred. " + "This is a bug in the implementation."); } sink.SendEvent("execution-complete", modname); return(0); }
/// <param name="s">Destination for error messages</param> public Interpreter(OutputSink s) { sink = s; ErrorReporting.SetSink(s); initialise(); }