示例#1
0
        public async Task <Variable> ProcessFileAsync(string filename, bool mainFile = false)
        {
            string   script = Utils.GetFileContents(filename);
            Variable result = await ProcessAsync(script, filename, mainFile);

            return(result);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
            {
                Console.WriteLine();
                Console.WriteLine("Goodbye! ¡Adiós! Ciao! Adieu! Adeus! Tschüss! Пока! 再见 さようなら הֱיה שלום وداعا");
            };

            ClearLine();

            // Subscribe to the printing events from the interpreter.
            // A printing event will be triggered after each successful statement
            // execution. On error an exception will be thrown.
            Interpreter.Instance.OnOutput += Print;

            string scriptFilename = "scripts/test.cscs";

            scriptFilename = "";
            string script = Utils.GetFileContents(scriptFilename);

            Environment.SetEnvironmentVariable("MONO_REGISTRY_PATH",
                                               "/Library/Frameworks/Mono.framework/Versions/Current/etc/mono/registry/");

            DebuggerServer.BaseDirectory = "";
            if (string.IsNullOrWhiteSpace(script) && (args.Length < 1 || args[1] == "debugger"))
            {
                DebuggerServer.StartServer(13337, true);
            }

            if (args.Length >= 3)
            {
                Translation.TranslateScript(args);
                return;
            }
            if (args.Length > 0)
            {
                if (args[0].EndsWith(EXT))
                {
                    scriptFilename = args[0];
                    Console.WriteLine("Reading script from " + scriptFilename);
                    script = Utils.GetFileContents(scriptFilename);
                }
                else
                {
                    script = args[0];
                }
            }

            if (!string.IsNullOrWhiteSpace(script))
            {
                ProcessScript(script, scriptFilename);
                return;
            }

            RunLoop();
        }
示例#3
0
文件: Main.cs 项目: ammogcoder/mobile
        static void Main(string[] args)
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e)
            {
                Console.WriteLine();
                Console.WriteLine("Goodbye! ¡Adiós! Ciao! Adieu! Adeus! Tschüss! Пока! 再见 さようなら הֱיה שלום وداعا");
            };

            ClearLine();

            // Subscribe to the printing events from the interpreter.
            // A printing event will be triggered after each successful statement
            // execution. On error an exception will be thrown.
            Interpreter.Instance.GetOutput += Print;

            //ProcessScript("include(\"scripts/functions.cscs\");");
            string scriptFilename = "scripts/temp.cscs";
            string script         = "";

            script = Utils.GetFileContents(scriptFilename);

            if (string.IsNullOrWhiteSpace(script) && (args.Length < 1 || args[1] == "debugger"))
            {
                DebuggerServer.StartServer(13337, true);
                //return;
            }

            if (args.Length >= 3)
            {
                Translation.TranslateScript(args);
                return;
            }
            if (args.Length > 0)
            {
                if (args[0].EndsWith(EXT))
                {
                    scriptFilename = args[0];
                    Console.WriteLine("Reading script from " + scriptFilename);
                    script = Utils.GetFileContents(scriptFilename);
                }
                else
                {
                    script = args[0];
                }
            }

            if (!string.IsNullOrWhiteSpace(script))
            {
                ProcessScript(script, scriptFilename);
                return;
            }

            RunLoop();
        }
示例#4
0
        public Variable ProcessFile(string filename, bool mainFile = false)
        {
            string script = Utils.GetFileContents(filename);

            return(Process(script, filename, mainFile));
        }
示例#5
0
        async Task ProcessClientCommand(string data)
        {
            string load = "";

            DebuggerUtils.DebugAction action = DebuggerUtils.StringToAction(data, ref load);
            string result = "N/A";

            SteppingIn     = SteppingOut = false;
            SendBackResult = true;
            m_firstBlock   = true;
            End            = false;
            string responseToken = DebuggerUtils.ResponseMainToken(action);

            //Trace("REQUEST: " + data);
            if (action == DebuggerUtils.DebugAction.REPL ||
                action == DebuggerUtils.DebugAction._REPL)
            {
                string filename = "";
                if (action == DebuggerUtils.DebugAction.REPL)
                {
                    int ind = load.IndexOf('|');
                    if (ind >= 0)
                    {
                        if (ind > 0)
                        {
                            filename = load.Substring(0, ind);
                        }
                        if (ind + 1 < load.Length)
                        {
                            load = load.Substring(ind + 1);
                        }
                    }
                }
                result = await ProcessRepl(load, filename);

                result = responseToken + (result == null ? "" : result);
                SendBack(result, false);
                return;
            }
            if (action == DebuggerUtils.DebugAction.SET_BP)
            {
                TheBreakpoints.AddBreakpoints(this, load);
                return;
            }

            if (action == DebuggerUtils.DebugAction.FILE)
            {
                MainInstance = this;
                string filename  = load;
                string rawScript = Utils.GetFileContents(filename);

                if (string.IsNullOrWhiteSpace(rawScript))
                {
                    ProcessException(null, new ParsingException("Could not load script " + filename));
                    return;
                }

                try
                {
                    m_script = Utils.ConvertToScript(rawScript, out m_char2Line, filename);
                }
                catch (ParsingException exc)
                {
                    ProcessException(m_debugging, exc);
                    return;
                }
                m_debugging                = new ParsingScript(m_script, 0, m_char2Line);
                m_debugging.Filename       = filename;
                m_debugging.MainFilename   = m_debugging.Filename;
                m_debugging.OriginalScript = rawScript;
                m_debugging.Debugger       = this;

                m_steppingIns.Clear();
                m_completedStepIn.Reset();
                ProcessingBlock = SendBackResult = InInclude = End = false;
                m_blockLevel    = m_maxBlockLevel = 0;
            }
            else if (action == DebuggerUtils.DebugAction.VARS)
            {
                result = GetAllVariables(m_debugging);
            }
            else if (action == DebuggerUtils.DebugAction.ALL)
            {
                result = await DebugScript();
            }
            else if (action == DebuggerUtils.DebugAction.STACK)
            {
                result = GetStack();
            }
            else if (action == DebuggerUtils.DebugAction.CONTINUE)
            {
                Continue = true;
                action   = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_IN)
            {
                SteppingIn = true;
                Continue   = false;
                action     = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_OUT)
            {
                SteppingOut = true;
                Continue    = false;
                action      = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.NEXT)
            {
                Continue = false;
            }
            else
            {
                Console.WriteLine("UNKNOWN CMD: {0}", data);
                return;
            }

            if (action == DebuggerUtils.DebugAction.NEXT)
            {
                if (m_debugging == null)
                {
                    result = "Error: Not initialized";
                    Console.WriteLine(result);
                }
                else
                {
                    Variable res = await ProcessNext();

                    //Trace("MAIN Ret:" + (LastResult != null && LastResult.IsReturn) +
                    //      " NULL:" + (res == null) + " db.sb=" + m_debugging.Debugger.SendBackResult +
                    //      " PTR:" + m_debugging.Pointer + "/" + m_script.Length);
                    if (End)
                    {
                        responseToken = DebuggerUtils.ResponseMainToken(DebuggerUtils.DebugAction.END);
                    }
                    else if (res == null || !SendBackResult)
                    {
                        // It will be processed by the stepped-out OR by completed stepped-in code.
                        return;
                    }
                    else
                    {
                        result = CreateResult(Output);
                        if (string.IsNullOrEmpty(result))
                        {
                            return;
                        }
                    }
                }
            }

            result = responseToken + result;
            SendBack(result, true);
        }
示例#6
0
        void ProcessClientCommand(string data)
        {
            string load = "";

            DebuggerUtils.DebugAction action = DebuggerUtils.StringToAction(data, ref load);
            string result = "N/A";

            SteppingIn     = SteppingOut = false;
            SendBackResult = true;
            m_firstBlock   = true;
            string responseToken = DebuggerUtils.ResponseMainToken(action);

            Trace("REQUEST: " + data);
            if (action == DebuggerUtils.DebugAction.REPL ||
                action == DebuggerUtils.DebugAction._REPL)
            {
                result = responseToken + ProcessRepl(load);
                SendBack(result);
                return;
            }
            if (action == DebuggerUtils.DebugAction.SET_BP)
            {
                TheBreakpoints.AddBreakpoints(this, load);
                return;
            }

            if (action == DebuggerUtils.DebugAction.FILE)
            {
                MainInstance = this;
                string filename  = load;
                string rawScript = Utils.GetFileContents(filename);

                m_script                   = Utils.ConvertToScript(rawScript, out m_char2Line);
                m_debugging                = new ParsingScript(m_script, 0, m_char2Line);
                m_debugging.Filename       = filename;
                m_debugging.OriginalScript = m_script;
                m_debugging.Debugger       = this;
            }
            else if (action == DebuggerUtils.DebugAction.VARS)
            {
                result = GetAllVariables(m_debugging);
            }
            else if (action == DebuggerUtils.DebugAction.ALL)
            {
                result = DebugScript();
            }
            else if (action == DebuggerUtils.DebugAction.STACK)
            {
                result = GetStack();
            }
            else if (action == DebuggerUtils.DebugAction.CONTINUE)
            {
                Continue = true;
                action   = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_IN)
            {
                SteppingIn = true;
                Continue   = false;
                action     = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.STEP_OUT)
            {
                SteppingOut = true;
                Continue    = false;
                action      = DebuggerUtils.DebugAction.NEXT;
            }
            else if (action == DebuggerUtils.DebugAction.NEXT)
            {
                Continue = false;
            }
            else
            {
                Console.WriteLine("UNKNOWN CMD: {0}", data);
                return;
            }

            if (action == DebuggerUtils.DebugAction.NEXT)
            {
                if (m_debugging == null)
                {
                    result = "Error: Not initialized";
                    Console.WriteLine(result);
                }
                else
                {
                    Variable res = ProcessNext();
                    Trace("MAIN Ret:" + (LastResult != null && LastResult.IsReturn) +
                          " NULL:" + (res == null) + " db.sb=" + m_debugging.Debugger.SendBackResult +
                          " PTR:" + m_debugging.Pointer + "/" + m_script.Length);
                    if (End)
                    {
                        responseToken = DebuggerUtils.ResponseMainToken(DebuggerUtils.DebugAction.END);
                    }
                    else if (res == null || !SendBackResult)
                    {
                        // It will be processed by the stepped-out OR by completed stepped-in code.
                        return;
                    }
                    else
                    {
                        result = CreateResult(Output);
                    }
                }
            }

            result = responseToken + result;
            SendBack(result);
        }