private static void LaunchRepl(IodineOptions options, IodineModule module = null) { string interpreterDir = Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ); if (module != null) { foreach (KeyValuePair <string, IodineObject> kv in module.Attributes) { context.Globals [kv.Key] = kv.Value; } } string iosh = Path.Combine(interpreterDir, "tools", "iosh.id"); if (File.Exists(iosh) && !options.FallBackFlag) { EvalSourceUnit(options, SourceUnit.CreateFromFile(iosh)); } else { ReplShell shell = new ReplShell(context); shell.Run(); } }
private static void CheckSourceUnit(IodineOptions options, SourceUnit unit) { try { context.ShouldCache = false; unit.Compile(context); } catch (SyntaxException ex) { DisplayErrors(ex.ErrorLog); } }
private static void ExecuteOptions(IodineOptions options) { if (options.DebugFlag) { RunDebugServer(); } if (options.WarningFlag) { context.WarningFilter = WarningType.SyntaxWarning; } if (options.SupressWarningFlag) { context.WarningFilter = WarningType.None; } switch (options.InterpreterAction) { case InterpreterAction.Check: CheckIfFileExists(options.FileName); CheckSourceUnit(options, SourceUnit.CreateFromFile(options.FileName)); break; case InterpreterAction.ShowVersion: DisplayInfo(); break; case InterpreterAction.ShowHelp: DisplayUsage(); break; case InterpreterAction.EvaluateFile: CheckIfFileExists(options.FileName); EvalSourceUnit(options, SourceUnit.CreateFromFile(options.FileName)); break; case InterpreterAction.EvaluateArgument: EvalSourceUnit(options, SourceUnit.CreateFromSource(options.FileName)); break; case InterpreterAction.Repl: LaunchRepl(options); break; } }
private static void EvalSourceUnit(IodineOptions options, SourceUnit unit) { try { IodineModule module = unit.Compile(context); if (context.Debug) { context.VirtualMachine.SetTrace(WaitForDebugger); } do { context.Invoke(module, new IodineObject[] { }); if (module.HasAttribute("main")) { context.Invoke(module.GetAttribute("main"), new IodineObject[] { options.IodineArguments }); } } while (options.LoopFlag); if (options.ReplFlag) { LaunchRepl(options, module); } } catch (UnhandledIodineExceptionException ex) { HandleIodineException(ex); } catch (SyntaxException ex) { DisplayErrors(ex.ErrorLog); Panic("Compilation failed with {0} errors!", ex.ErrorLog.ErrorCount); } catch (ModuleNotFoundException ex) { Console.Error.WriteLine(ex.ToString()); Panic("Program terminated."); } catch (Exception e) { Console.Error.WriteLine("Fatal exception has occured!"); Console.Error.WriteLine(e.Message); Console.Error.WriteLine("Stack trace: \n{0}", e.StackTrace); Console.Error.WriteLine( "\nIodine stack trace \n{0}", context.VirtualMachine.GetStackTrace() ); Panic("Program terminated."); } }
public static void Main(string[] args) { context = IodineContext.Create(); AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => { if (e.ExceptionObject is UnhandledIodineExceptionException) { HandleIodineException(e.ExceptionObject as UnhandledIodineExceptionException); } }; IodineOptions options = IodineOptions.Parse(args); context.ShouldCache = !options.SupressAutoCache; context.ShouldOptimize = !options.SupressOptimizer; ExecuteOptions(options); }
public static IodineOptions Parse(string[] args) { IodineOptions ret = new IodineOptions(); int i; bool sentinel = true; for (i = 0; i < args.Length && sentinel; i++) { switch (args [i]) { case "-d": case "--debug": ret.DebugFlag = true; break; case "-l": case "--loop": ret.LoopFlag = true; break; case "-w": ret.WarningFlag = true; break; case "-x": ret.SupressWarningFlag = true; break; case "-f": case "--fallback-repl": ret.FallBackFlag = true; break; case "-r": case "--repl": ret.ReplFlag = true; break; case "-c": case "--check": ret.InterpreterAction = InterpreterAction.Check; break; case "-v": case "--version": ret.InterpreterAction = InterpreterAction.ShowVersion; break; case "-h": case "--help": ret.InterpreterAction = InterpreterAction.ShowHelp; break; case "-e": case "--eval": ret.InterpreterAction = InterpreterAction.EvaluateArgument; break; case "--no-cache": ret.SupressAutoCache = true; break; case "--no-optimize": ret.SupressOptimizer = true; break; default: if (args [i].StartsWith("-")) { Console.Error.WriteLine("Unknown option '{0}'", args [i]); } else { ret.FileName = args [i]; if (ret.InterpreterAction == InterpreterAction.Repl) { ret.InterpreterAction = InterpreterAction.EvaluateFile; } } sentinel = false; break; } } IodineObject[] arguments = new IodineObject [ args.Length - i > 0 ? args.Length - i : 0 ]; int start = i; for (; i < args.Length; i++) { arguments [i - start] = new IodineString(args [i]); } ret.IodineArguments = new IodineList(arguments); return(ret); }