示例#1
0
        public void Run()
        {
            var version = typeof(IodineContext).Assembly.GetName().Version;

            Console.WriteLine("Iodine v{0}-alpha", version.ToString(3));
            Console.WriteLine("Fallback REPL. Enter expressions to have them be evaluated");

            IodineContext context = new IodineContext();

            context.ShouldOptimize = false;

            context.Globals ["quit"] = new QuitObject();

            while (true)
            {
                Console.Write(">>> ");
                var source = Console.ReadLine().Trim();
                try {
                    if (source.Length > 0)
                    {
                        SourceUnit   unit   = SourceUnit.CreateFromSource(source);
                        var          result = unit.Compile(context);
                        IodineObject ret    = context.Invoke(result, new IodineObject[] { });
                        if (!(ret is IodineNull))
                        {
                            Console.WriteLine(ret.Represent(context.VirtualMachine));
                        }
                    }
                } catch (UnhandledIodineExceptionException ex) {
                    Console.Error.WriteLine("*** {0}", ex.OriginalException.GetAttribute("message"));
                    ex.PrintStack();
                    context.VirtualMachine.Top = null;
                    Console.Error.WriteLine();
                } catch (ModuleNotFoundException ex) {
                    Console.Error.WriteLine(ex.ToString());
                } catch (SyntaxException syntaxException) {
                    DisplayErrors(syntaxException.ErrorLog);
                } catch (Exception ex) {
                    Console.Error.WriteLine("Fatal exception has occured!");
                    Console.Error.WriteLine(ex.Message);
                    Console.Error.WriteLine("Stack trace: \n{0}", ex.StackTrace);
                    //Console.Error.WriteLine ("\nIodine stack trace \n{0}", engine.VirtualMachine.GetStackTrace ());
                }
            }
        }
 public override string ToString()
 {
     return(internalObject.Represent(internalVm).ToString());
 }