public HassiumArgumentConfig Parse(string[] args) { this.args = args; position = 0; HassiumArgumentConfig config = new HassiumArgumentConfig(); if (args.Length == 0) DisplayHelp(); while (position < args.Length) { switch (args[position++].ToLower()) { case "-h": case "--help": DisplayHelp(); break; case "-s": case "--show-tokens": config.ShowTokens = true; break; case "-t": case "--time": config.ShowTime = true; break; default: position--; config.FilePath = expectData("[PATH]"); for (int i = 1; i < args.Length; i++) config.Arguments.Add(args[i]); return config; } } return config; }
public static void ExecuteConfig(HassiumArgumentConfig config) { if (!File.Exists(config.FilePath)) { Console.WriteLine("File {0} does not exist!", config.FilePath); Environment.Exit(0); } try { if (config.ShowTokens) { foreach (var token in new Lexer().Scan(File.ReadAllText(config.FilePath))) Console.WriteLine(token.ToString()); return; } var module = Compiler.CodeGen.Compiler.CompileModuleFromSource(File.ReadAllText(config.FilePath)); Stopwatch watch = new Stopwatch(); watch.Start(); new VirtualMachine().Execute(module, config.Arguments.ToArray()); if (config.ShowTime) Console.WriteLine("Execution Time: {0} milliseconds.", watch.ElapsedMilliseconds); } catch (CompileException ex) { Console.WriteLine("At {0}:", ex.SourceLocation); Console.WriteLine(ex.Message); } catch (InternalException ex) { Console.WriteLine("At location {0}:", ex.VM.CurrentSourceLocation); Console.WriteLine("{0} at:", ex.Message); while (ex.VM.CallStack.Count > 0) Console.WriteLine(ex.VM.CallStack.Pop()); } }