public async Task <bool> ExecuteNextStatement() { int endGroupRead = 0; if (m_debugging.Pointer >= m_script.Length - 1) { LastResult = null; End = true; return(true); } //int startPointer = m_debugging.Pointer; if (ProcessingBlock) { endGroupRead = m_debugging.GoToNextStatement(); if (ProcessingBlock && endGroupRead > 0) { return(true); } } Executing = true; try { LastResult = await DebuggerUtils.Execute(m_debugging); } catch (ParsingException exc) { if (m_debugging.InTryBlock) { throw exc; } ProcessException(m_debugging, exc); return(true); } finally { Executing = false; } endGroupRead = m_debugging.GoToNextStatement(); // Check if after this statement the Step In is completed and we can unwind the stack: bool completedSteppingIn = Completed(m_debugging) || (ProcessingBlock && endGroupRead > 0) || LastResult.Type == Variable.VarType.CONTINUE || LastResult.Type == Variable.VarType.BREAK || LastResult.IsReturn; return(completedSteppingIn); }
private Variable ProcessBlock(ParsingScript script) { int blockStart = script.Pointer; Variable result = null; while (script.StillValid()) { int endGroupRead = script.GoToNextStatement(); if (endGroupRead > 0) { return(result != null ? result : new Variable()); } if (!script.StillValid()) { throw new ArgumentException("Couldn't process block [" + script.Substr(blockStart,Constants.MAX_CHARS_TO_SHOW) + "]"); } result = script.ExecuteTo(); if (result.IsReturn || result.Type == Variable.VarType.BREAK || result.Type == Variable.VarType.CONTINUE) { return(result); } } return(result); }
public async Task <Variable> DebugBlockIfNeeded(ParsingScript stepInScript, bool done, Action <bool> doneEvent) { if (SteppingOut || Continue || ReplMode || !m_firstBlock) { return(null); } m_firstBlock = false; done = stepInScript.GoToNextStatement() > 0; if (done) { return(Variable.EmptyInstance); } ProcessingBlock = true; ParsingScript tempScript = new ParsingScript(stepInScript.String, stepInScript.Pointer); tempScript.ParentScript = stepInScript; tempScript.InTryBlock = stepInScript.InTryBlock; /* string body = */ Utils.GetBodyBetween(tempScript, Constants.START_GROUP, Constants.END_GROUP); await StepIn(stepInScript); ProcessingBlock = false; done = stepInScript.Pointer >= tempScript.Pointer || LastResult.IsReturn || LastResult.Type == Variable.VarType.BREAK || LastResult.Type == Variable.VarType.CONTINUE; doneEvent(done); return(LastResult); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, m_name, true); string filename = args[0].AsString(); string pathname = script.GetFilePath(filename); EncodeFileFunction.EncodeDecode(pathname, false); ParsingScript tempScript = script.GetIncludeFileScript(filename); string includeScript = tempScript.String; EncodeFileFunction.EncodeDecode(pathname, true); Variable result = null; if (script.Debugger != null) { result = script.Debugger.StepInIncludeIfNeeded(tempScript).Result; } while (tempScript.Pointer < includeScript.Length) { result = tempScript.Execute(); tempScript.GoToNextStatement(); } return(result == null ? Variable.EmptyInstance : result); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, m_name, true); string filename = args[0].AsString(); string[] lines = Utils.GetFileLines(filename); string includeFile = string.Join(Environment.NewLine, lines); Dictionary <int, int> char2Line; string includeScript = Utils.ConvertToScript(includeFile, out char2Line); ParsingScript tempScript = new ParsingScript(includeScript, 0, char2Line); tempScript.Filename = filename; tempScript.OriginalScript = string.Join(Constants.END_LINE.ToString(), lines); tempScript.ParentScript = script; tempScript.InTryBlock = script.InTryBlock; Variable result = null; if (script.Debugger != null) { result = script.Debugger.StepInIncludeIfNeeded(tempScript); } while (tempScript.Pointer < includeScript.Length) { result = tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } return(result == null ? Variable.EmptyInstance : result); }
public Variable Process(string script, string filename = "") { Dictionary <int, int> char2Line; string data = Utils.ConvertToScript(script, out char2Line); if (string.IsNullOrWhiteSpace(data)) { return(null); } ParsingScript toParse = new ParsingScript(data, 0, char2Line); toParse.OriginalScript = script; toParse.Filename = filename; Variable result = null; while (toParse.Pointer < data.Length) { result = toParse.ExecuteTo(); toParse.GoToNextStatement(); } return(result); }
protected override Variable Evaluate(ParsingScript script) { bool isList; List <Variable> functionArgs = Utils.GetArgs(script, Constants.START_ARG, Constants.END_ARG, out isList); //script.MoveForwardIf(Constants.END_ARG); script.MoveBackIf(Constants.START_GROUP); if (functionArgs.Count != m_args.Length) { throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " + m_args.Length + " declared, " + functionArgs.Count + " supplied"); } // 1. Add passed arguments as local variables to the Parser. StackLevel stackLevel = new StackLevel(m_name); for (int i = 0; i < m_args.Length; i++) { stackLevel.Variables[m_args[i]] = new GetVarFunction(functionArgs[i]); } ParserFunction.AddLocalVariables(stackLevel); // 2. Execute the body of the function. Variable result = null; ParsingScript tempScript = new ParsingScript(m_body); tempScript.ScriptOffset = m_parentOffset; if (m_parentScript != null) { tempScript.Char2Line = m_parentScript.Char2Line; tempScript.Filename = m_parentScript.Filename; tempScript.OriginalScript = m_parentScript.OriginalScript; } while (tempScript.Pointer < m_body.Length - 1 && (result == null || !result.IsReturn)) { result = tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } ParserFunction.PopLocalVariables(); //script.MoveForwardIf(Constants.END_ARG); //script.MoveForwardIf(Constants.END_STATEMENT); if (result == null) { result = Variable.EmptyInstance; } else { result.IsReturn = false; } return(result); }
public async Task <Variable> ProcessAsync(string script, string filename = "", bool mainFile = false) { Dictionary <int, int> char2Line; string data = Utils.ConvertToScript(script, out char2Line, filename); if (string.IsNullOrWhiteSpace(data)) { return(null); } ParsingScript toParse = new ParsingScript(data, 0, char2Line); toParse.OriginalScript = script; toParse.Filename = filename; if (mainFile) { toParse.MainFilename = toParse.Filename; } Variable result = null; while (toParse.Pointer < data.Length) { result = await toParse.ExecuteAsync(); toParse.GoToNextStatement(); } return(result); }
public Variable DebugBlockIfNeeded(ParsingScript stepInScript, ref bool done) { if (SteppingOut || Continue || ReplMode || !m_firstBlock) { return(null); } m_firstBlock = false; done = stepInScript.GoToNextStatement() > 0; if (done) { return(Variable.EmptyInstance); } ProcessingBlock = true; ParsingScript tempScript = new ParsingScript(stepInScript.String, stepInScript.Pointer); tempScript.ParentScript = stepInScript; tempScript.InTryBlock = stepInScript.InTryBlock; string body = Utils.GetBodyBetween(tempScript, Constants.START_GROUP, Constants.END_GROUP); Trace("Started ProcessBlock"); StepIn(stepInScript); ProcessingBlock = false; done = stepInScript.Pointer >= tempScript.Pointer; Trace("Finished ProcessBlock"); return(LastResult); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); Utils.CheckArgs(args.Count, 1, m_name, true); string filename = args[0].AsString(); string[] lines = Utils.GetFileLines(filename); string includeFile = string.Join(Environment.NewLine, lines); Dictionary <int, int> char2Line; string includeScript = Utils.ConvertToScript(includeFile, out char2Line); ParsingScript tempScript = new ParsingScript(includeScript, 0, char2Line); tempScript.Filename = filename; tempScript.OriginalScript = string.Join(Constants.END_LINE.ToString(), lines); while (tempScript.Pointer < includeScript.Length) { tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } return(Variable.EmptyInstance); }
private async Task <Variable> ProcessBlockAsync(ParsingScript script) { int blockStart = script.Pointer; Variable result = null; if (script.Debugger != null) { bool done = false; result = await script.Debugger.DebugBlockIfNeeded(script, done, (newDone) => { done = newDone; }); if (done) { return(result); } } while (script.StillValid()) { int endGroupRead = script.GoToNextStatement(); if (endGroupRead > 0 || !script.StillValid()) { return(result != null ? result : new Variable()); } result = await script.ExecuteAsync(); if (result.IsReturn || result.Type == Variable.VarType.BREAK || result.Type == Variable.VarType.CONTINUE) { return(result); } } return(result); }
public bool ExecuteNextStatement() { int endGroupRead = 0; if (m_debugging.Pointer >= m_script.Length - 1) { LastResult = null; #if UNITY_EDITOR == false && UNITY_STANDALONE == false && __ANDROID__ == false && __IOS__ == false End = true; Trace("END!"); #endif return(true); } //int startPointer = m_debugging.Pointer; if (ProcessingBlock) { endGroupRead = m_debugging.GoToNextStatement(); if (ProcessingBlock && endGroupRead > 0) { return(true); } } Executing = true; try { LastResult = DebuggerUtils.Execute(m_debugging); } catch (ParsingException exc) { ProcessException(m_debugging, exc); return(true); } finally { Executing = false; } endGroupRead = m_debugging.GoToNextStatement(); //int endPointer = m_debugging.Pointer; //processed = m_debugging.Substr(startPointer, endPointer - startPointer); return(Completed(m_debugging) || (ProcessingBlock && endGroupRead > 0)); }
public async Task <bool> ExecuteNextStatement() { int endGroupRead = 0; if (m_debugging.Pointer >= m_script.Length - 1) { LastResult = null; End = true; Trace("END of parsing"); return(true); } //int startPointer = m_debugging.Pointer; if (ProcessingBlock) { endGroupRead = m_debugging.GoToNextStatement(); if (ProcessingBlock && endGroupRead > 0) { return(true); } } Executing = true; try { LastResult = await DebuggerUtils.Execute(m_debugging); } catch (ParsingException exc) { ProcessException(m_debugging, exc); return(true); } finally { Executing = false; } endGroupRead = m_debugging.GoToNextStatement(); //int endPointer = m_debugging.Pointer; //processed = m_debugging.Substr(startPointer, endPointer - startPointer); return(Completed(m_debugging) || (ProcessingBlock && endGroupRead > 0)); }
async Task <string> ProcessRepl(string repl, string filename = "") { ReplMode = true; Dictionary <int, int> char2Line; string script = Utils.ConvertToScript(repl, out char2Line); ParsingScript tempScript = new ParsingScript(script, 0, char2Line); tempScript.OriginalScript = repl; tempScript.Debugger = this; if (!string.IsNullOrWhiteSpace(filename)) { tempScript.Filename = filename; } Variable result = null; bool excThrown = false; string stringRes = ""; try { while (tempScript.Pointer < script.Length) { result = await DebuggerUtils.Execute(tempScript); tempScript.GoToNextStatement(); while (tempScript.TryCurrent() == Constants.END_STATEMENT) { tempScript.Forward(); } } if (TrySendFile(result, tempScript, ref excThrown) || excThrown) { return(""); } stringRes = string.IsNullOrEmpty(Output) ? "" : Output + (Output.EndsWith("\n") ? "" : "\n"); stringRes += result == null ? "" : result.AsString(); stringRes += (stringRes.EndsWith("\n") ? "" : "\n"); } catch (Exception exc) { Console.WriteLine("ProcessRepl Exception: " + exc); return(""); // The exception was already thrown and sent back. } finally { ReplMode = false; } return(stringRes); }
protected override Variable Evaluate(ParsingScript script) { List <Variable> args = script.GetFunctionArgs(); script.MoveBackIf(Constants.START_GROUP); if (args.Count != m_args.Length) { throw new ArgumentException("Function [" + m_name + "] arguments mismatch: " + m_args.Length + " declared, " + args.Count + " supplied"); } // 1. Add passed arguments as local variables to the Parser. RegisterArguments(args); // 2. Execute the body of the function. Variable result = null; ParsingScript tempScript = new ParsingScript(m_body); tempScript.ScriptOffset = m_parentOffset; if (m_parentScript != null) { tempScript.Char2Line = m_parentScript.Char2Line; tempScript.Filename = m_parentScript.Filename; tempScript.OriginalScript = m_parentScript.OriginalScript; } tempScript.ParentScript = script; tempScript.InTryBlock = script.InTryBlock; if (script.Debugger != null) { result = script.Debugger.StepInFunctionIfNeeded(tempScript); } while (tempScript.Pointer < m_body.Length - 1 && (result == null || !result.IsReturn)) { result = tempScript.ExecuteTo(); tempScript.GoToNextStatement(); } ParserFunction.PopLocalVariables(); if (result == null) { result = Variable.EmptyInstance; } else { result.IsReturn = false; } return(result); }
internal Variable ProcessSwitch(ParsingScript script) { Variable switchValue = Utils.GetItem(script); script.Forward(); Variable result = Variable.EmptyInstance; var caseSep = ":".ToCharArray(); bool caseDone = false; while (script.StillValid()) { var nextToken = Utils.GetBodySize(script, Constants.CASE, Constants.DEFAULT); if (string.IsNullOrEmpty(nextToken)) { break; } if (nextToken == Constants.DEFAULT && !caseDone) { result = ProcessBlock(script); break; } if (!caseDone) { Variable caseValue = script.Execute(caseSep); script.Forward(); if (switchValue.Type == caseValue.Type && switchValue.Equals(caseValue)) { caseDone = true; result = ProcessBlock(script); if (script.Prev == '}') { break; } script.Forward(); } } } script.MoveForwardIfNotPrevious('}'); script.GoToNextStatement(); return(result); }
private Variable ProcessBlock(ParsingScript script) { int blockStart = script.Pointer; Variable result = null; if (script.Debugger != null) { bool done = false; result = script.Debugger.DebugBlockIfNeeded(script, ref done); if (done) { return(result); } } while (script.StillValid()) { int endGroupRead = script.GoToNextStatement(); if (endGroupRead > 0 || !script.StillValid()) { return(result != null ? result : new Variable()); } /*if (!script.StillValid()) * { * throw new ArgumentException("Couldn't process block [" + * script.Substr(blockStart, Constants.MAX_CHARS_TO_SHOW) + "]"); * }*/ result = script.ExecuteTo(); if (result.IsReturn || result.Type == Variable.VarType.BREAK || result.Type == Variable.VarType.CONTINUE) { return(result); } } return(result); }
private Variable ProcessBlock(ParsingScript script) { int blockStart = script.Pointer; Variable result = null; while (script.StillValid()) { int endGroupRead = script.GoToNextStatement(); if (endGroupRead > 0 || !script.StillValid()) { return(result != null ? result : new Variable()); } result = script.Execute(); if (result.IsReturn || result.Type == Variable.VarType.BREAK || result.Type == Variable.VarType.CONTINUE) { return(result); } } return(result); }
string ProcessRepl(string repl) { ReplMode = true; Dictionary <int, int> char2Line; string script = Utils.ConvertToScript(repl, out char2Line); ParsingScript tempScript = new ParsingScript(script, 0, char2Line); tempScript.OriginalScript = repl; tempScript.Debugger = this; Variable result = null; try { while (tempScript.Pointer < script.Length) { result = DebuggerUtils.Execute(tempScript); tempScript.GoToNextStatement(); } } catch (Exception exc) { return("Exception thrown: " + exc.Message); } finally { ReplMode = false; } string stringRes = Output + "\n"; stringRes += result == null ? "" : result.AsString(); return(stringRes); }