Пример #1
0
        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();
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            if (args.Length == 0) {
                ReplShell shell = new ReplShell ();
                shell.Run ();
                Environment.Exit (0);
            }
            IodineOptions options = IodineOptions.Parse (args);
            if (options.ShowVersion) {
                int major = Assembly.GetExecutingAssembly ().GetName ().Version.Major;
                int minor = Assembly.GetExecutingAssembly ().GetName ().Version.Minor;
                int patch = Assembly.GetExecutingAssembly ().GetName ().Version.Build;
                Console.WriteLine ("Iodine v{0}.{1}.{2}-alpha", major, minor, patch);
                Environment.Exit (0);
            }

            ErrorLog errorLog = new ErrorLog ();
            IodineModule module = IodineModule.LoadModule (errorLog, options.FileName);

            if (module == null) {
                DisplayErrors (errorLog);
                Panic ("Compilation failed with {0} errors!", errorLog.ErrorCount);
            } else {
                VirtualMachine vm = new VirtualMachine ();
                try {
                    module.Invoke (vm, new IodineObject[] { });
                    if (module.HasAttribute ("main")) {
                        module.GetAttribute ("main").Invoke (vm, new IodineObject[] { options.Arguments });
                    }
                } catch (UnhandledIodineExceptionException ex) {
                    Console.Error.WriteLine ("An unhandled {0} has occured!", ex.OriginalException.TypeDef.Name);
                    Console.Error.WriteLine ("\tMessage: {0}", ex.OriginalException.GetAttribute ("message").ToString ());
                    Console.WriteLine ();
                    ex.PrintStack ();
                    Console.Error.WriteLine ();
                    Panic ("Program terminated.");
                } catch (SyntaxException ex) {
                    DisplayErrors (ex.ErrorLog);
                    Panic ("Compilation failed with {0} errors!", ex.ErrorLog.ErrorCount);
                } 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}", vm.Trace ());
                    Panic ("Program terminated.");
                }
            }
        }