private List<Obj> UnpackToList(ExecutionMirror mirror, Obj obj) { if (obj == null || !obj.DsasmValue.IsArray) return null; return mirror.MirrorTarget.rmem.Heap.ToHeapObject<DSArray>(obj.DsasmValue).Values.Select(x => mirror.Unpack(x)).ToList(); }
/// <summary> /// VM Debugging API for general Debugging purposes /// temporarily used by Cmmand Line REPL /// </summary> /// <returns></returns> public string GetCoreDump() { // Prints out the final Value of every symbol in the program // Traverse order: // Exelist, Globals symbols StringBuilder globaltrace = null; ProtoCore.DSASM.Executive exec = runnerCore.CurrentExecutive.CurrentDSASMExec; ProtoCore.DSASM.Mirror.ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(exec, runnerCore); ProtoCore.DSASM.Executable exe = exec.rmem.Executable; // Only display symbols defined in the default top-most langauge block; // Otherwise garbage information may be displayed. string formattedString = string.Empty; if (exe.runtimeSymbols.Length > 0) { int blockId = 0; ProtoCore.DSASM.SymbolTable symbolTable = exe.runtimeSymbols[blockId]; for (int i = 0; i < symbolTable.symbolList.Count; ++i) { //int n = symbolTable.symbolList.Count - 1; //formatParams.ResetOutputDepth(); ProtoCore.DSASM.SymbolNode symbolNode = symbolTable.symbolList[i]; bool isLocal = ProtoCore.DSASM.Constants.kGlobalScope != symbolNode.functionIndex; bool isStatic = (symbolNode.classScope != ProtoCore.DSASM.Constants.kInvalidIndex && symbolNode.isStatic); if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp) { // These have gone out of scope, their values no longer exist //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); continue; } ProtoCore.Runtime.RuntimeMemory rmem = exec.rmem; ProtoCore.DSASM.StackValue sv = rmem.GetStackData(blockId, i, ProtoCore.DSASM.Constants.kGlobalScope); formattedString = formattedString + string.Format("{0} = {1}\n", symbolNode.name, execMirror.GetStringValue(sv, rmem.Heap, blockId)); //if (null != globaltrace) //{ // int maxLength = 1020; // while (formattedString.Length > maxLength) // { // globaltrace.AppendLine(formattedString.Substring(0, maxLength)); // formattedString = formattedString.Remove(0, maxLength); // } // globaltrace.AppendLine(formattedString); //} } //formatParams.ResetOutputDepth(); } //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); return(formattedString); }
public void TestCompilerAndRuntimeComponent01() { String code = @" // Any DS code goes here a = 10; "; // Compile core var opts = new Options(); opts.ExecutionMode = ExecutionMode.Serial; ProtoCore.Core core = new Core(opts); core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core)); ProtoScriptRunner runner = new ProtoScriptRunner(); // Compile bool compileSucceeded = runner.CompileAndGenerateExe(code, core); Assert.IsTrue(compileSucceeded == true); // Execute RuntimeCore runtimeCore = runner.ExecuteVM(core); // Verify ExecutionMirror mirror = new ExecutionMirror(runtimeCore.CurrentExecutive.CurrentDSASMExec, runtimeCore);
internal static void CompareCores(Core c1, Core c2) { Assert.AreEqual(c1.DSExecutable.runtimeSymbols.Length, c2.DSExecutable.runtimeSymbols.Length); for (int symTableIndex = 0; symTableIndex < c1.DSExecutable.runtimeSymbols.Length; symTableIndex++) { foreach (SymbolNode symNode in c1.DSExecutable.runtimeSymbols[symTableIndex].symbolList.Values) { ExecutionMirror runExecMirror = new ExecutionMirror(c1.CurrentExecutive.CurrentDSASMExec, c1); ExecutionMirror debugExecMirror = new ExecutionMirror(c2.CurrentExecutive.CurrentDSASMExec, c2); bool lookupOk = false; StackValue runValue = new StackValue(); if (symNode.name.StartsWith("%") || symNode.functionIndex != Constants.kInvalidIndex) continue; //Don't care about internal variables try { runValue = runExecMirror.GetGlobalValue(symNode.name); Console.WriteLine(symNode.name + ": " + runValue); lookupOk = true; } catch (NotImplementedException) { } catch (Exception ex) { if ((ex is ArgumentOutOfRangeException || ex is IndexOutOfRangeException) && (c1.RunningBlock != symNode.runtimeTableIndex)) { // Quite possible that variables defined in the inner // language block have been garbage collected and // stack frame pointer has been adjusted when return // to the outer block. } else { throw ex; } } if (lookupOk) { StackValue debugValue = debugExecMirror.GetGlobalValue(symNode.name); if (!StackUtils.CompareStackValues(debugValue, runValue, c2, c1)) { Assert.Fail(string.Format("\tThe value of variable \"{0}\" doesn't match in run mode and in debug mode.\n", symNode.name)); } } } } }
internal static ProtoCore.Core TestRunnerRunOnly(string includePath, string code, Dictionary<int, List<string>> map, string geometryFactory, string persistentManager, out ExecutionMirror mirror, out RuntimeCore runtimeCoreOut) { ProtoCore.Core core; ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner(); ProtoScript.Config.RunConfiguration runnerConfig; // Specify some of the requirements of IDE. var options = new ProtoCore.Options(); options.ExecutionMode = ProtoCore.ExecutionMode.Serial; options.SuppressBuildOutput = false; options.WatchTestMode = true; // Cyclic dependency threshold is lowered from the default (2000) // as this causes the test framework to be painfully slow options.kDynamicCycleThreshold = 5; // Pass the absolute path so that imported filepaths can be resolved // in "FileUtils.GetDSFullPathName()" includePath = Path.GetDirectoryName(includePath); options.IncludeDirectories.Add(includePath); //StreamWriter sw = File.CreateText(executionLogFilePath); TextOutputStream fs = new TextOutputStream(map); core = new ProtoCore.Core(options); core.Configurations.Add(ConfigurationKeys.GeometryXmlProperties, true); //core.Configurations.Add(ConfigurationKeys.GeometryFactory, geometryFactory); //core.Configurations.Add(ConfigurationKeys.PersistentManager, persistentManager); // By specifying this option we inject a mock Executive ('InjectionExecutive') // that prints stackvalues at every assignment statement // by overriding the POP_handler instruction - pratapa //core.ExecutiveProvider = new InjectionExecutiveProvider(); core.BuildStatus.MessageHandler = fs; core.Compilers.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Compiler(core)); core.Compilers.Add(ProtoCore.Language.kImperative, new ProtoImperative.Compiler(core)); runnerConfig = new ProtoScript.Config.RunConfiguration(); runnerConfig.IsParrallel = false; DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper()); //Run mirror = fsr.Execute(code, core, out runtimeCoreOut); //sw.Close(); return core; }
private VMState RunVM(List <Instruction> breakPoints) { //Get the next available location and set a break point //Unset the break point at the current location Instruction currentInstr = null; // will be instantialized when a proper breakpoint is reached VMState vms = null; try { if (executionsuspended) { core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionResume); } Execute(core.DebugProps.DebugEntryPC, breakPoints); isEnded = true; // the script has ended smoothly, } catch (ProtoCore.Exceptions.DebugHalting) { if (core.CurrentExecutive == null) //This was before the VM was properly started { return(null); } currentInstr = GetCurrentInstruction(); // set the current instruction to the current breakpoint instruction core.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBreak); executionsuspended = true; } catch (ProtoCore.Exceptions.EndOfScript) { isEnded = true; } finally { ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(core.CurrentExecutive.CurrentDSASMExec, core); vms = new VMState(execMirror, core); vms.isEnded = isEnded; ProtoCore.CodeModel.CodePoint start = new ProtoCore.CodeModel.CodePoint(); ProtoCore.CodeModel.CodePoint end = new ProtoCore.CodeModel.CodePoint(); if (currentInstr != null) // equal to null means that the whole script has ended, reset the cursor { start = InstructionToBeginCodePoint(currentInstr); end = InstructionToEndCodePoint(currentInstr); } CurrentInstruction = currentInstr; vms.ExecutionCursor = new ProtoCore.CodeModel.CodeRange { StartInclusive = start, EndExclusive = end }; } return(vms); }
public void TestCompilerAndRuntimeComponent01() { String code = @" // DesignScript code here a = 10; "; // Compile ProtoScriptRunner runner = new ProtoScriptRunner(); bool compileSucceeded = runner.CompileAndGenerateExe(code, core, new ProtoCore.CompileTime.Context()); Assert.IsTrue(compileSucceeded == true); // Execute runtimeCore = runner.ExecuteVM(core); // Verify ExecutionMirror mirror = new ExecutionMirror(runtimeCore.CurrentExecutive.CurrentDSASMExec, runtimeCore);
/// <summary> /// VM Debugging API for general Debugging purposes /// temporarily used by Cmmand Line REPL /// </summary> /// <returns></returns> public string GetCoreDump() { // Prints out the final Value of every symbol in the program // Traverse order: // Exelist, Globals symbols ProtoCore.DSASM.Executive exec = runtimeCore.CurrentExecutive.CurrentDSASMExec; ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(exec, runtimeCore); Executable exe = exec.exe; // Only display symbols defined in the default top-most langauge block; // Otherwise garbage information may be displayed. string formattedString = string.Empty; if (exe.runtimeSymbols.Length > 0) { int blockId = 0; ProtoCore.DSASM.SymbolTable symbolTable = exe.runtimeSymbols[blockId]; for (int i = 0; i < symbolTable.symbolList.Count; ++i) { SymbolNode symbolNode = symbolTable.symbolList[i]; bool isLocal = ProtoCore.DSASM.Constants.kGlobalScope != symbolNode.functionIndex; bool isStatic = (symbolNode.classScope != ProtoCore.DSASM.Constants.kInvalidIndex && symbolNode.isStatic); if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp) { continue; } ProtoCore.Runtime.RuntimeMemory rmem = exec.rmem; StackValue sv = rmem.GetSymbolValue(symbolNode); formattedString = formattedString + string.Format("{0} = {1}\n", symbolNode.name, execMirror.GetStringValue(sv, rmem.Heap, blockId)); } } return formattedString; }
public VMState(ExecutionMirror mirror, ProtoCore.Core core, int fi = -1) { this.mirror = mirror; this.core = core; }
private VMState RunVM(List<Instruction> breakPoints) { //Get the next available location and set a break point //Unset the break point at the current location Instruction currentInstr = null; // will be instantialized when a proper breakpoint is reached VMState vms = null; try { if (executionsuspended) runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionResume); Execute(runtimeCore.DebugProps.DebugEntryPC, breakPoints); isEnded = true; // the script has ended smoothly, } catch (ProtoCore.Exceptions.DebugHalting) { if (runtimeCore.CurrentExecutive == null) //This was before the VM was properly started return null; currentInstr = GetCurrentInstruction(); // set the current instruction to the current breakpoint instruction runtimeCore.NotifyExecutionEvent(ProtoCore.ExecutionStateEventArgs.State.kExecutionBreak); executionsuspended = true; } catch (ProtoCore.Exceptions.EndOfScript) { isEnded = true; } finally { ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(runtimeCore.CurrentExecutive.CurrentDSASMExec, runtimeCore); vms = new VMState(execMirror, core); vms.isEnded = isEnded; ProtoCore.CodeModel.CodePoint start = new ProtoCore.CodeModel.CodePoint(); ProtoCore.CodeModel.CodePoint end = new ProtoCore.CodeModel.CodePoint(); if (currentInstr != null) // equal to null means that the whole script has ended, reset the cursor { start = InstructionToBeginCodePoint(currentInstr); end = InstructionToEndCodePoint(currentInstr); } CurrentInstruction = currentInstr; vms.ExecutionCursor = new ProtoCore.CodeModel.CodeRange { StartInclusive = start, EndExclusive = end }; } return vms; }
private bool InterpretExpression(string expression) { if ((null != internalWorker) && internalWorker.IsBusy) return false; // Sorry but we're kinda busy right now. if (string.IsNullOrEmpty(expression)) return false; Logger.LogInfo("InterpretExpression", expression); if (null == this.core || (null == debugRunner)) return false; // Only in debug mode. currentWatchedStackValue = null; ExpressionInterpreterRunner exprInterpreter = null; IOutputStream buildStream = core.BuildStatus.MessageHandler; IOutputStream runtimeStream = core.RuntimeStatus.MessageHandler; // Disable output before interpret expression. core.BuildStatus.MessageHandler = null; core.RuntimeStatus.MessageHandler = null; exprInterpreter = new ExpressionInterpreterRunner(this.core); try { currentWatchedStackValue = ExecExecutiveExpression(exprInterpreter, expression); if (currentWatchedStackValue == null) { currentWatchedMirror = exprInterpreter.Execute(expression); if (null != currentWatchedMirror) { currentWatchedStackValue = currentWatchedMirror.GetWatchValue(); } } } catch (ProtoCore.Exceptions.CompileErrorsOccured compileError) { } catch (Exception exception) { } // Re-enable output after execution is done. core.BuildStatus.MessageHandler = buildStream; core.RuntimeStatus.MessageHandler = runtimeStream; return (null != currentWatchedStackValue); }
private void DisplayCoreDump(ExecutionMirror executionMirror, IOutputStream outputStream) { if (null == executionMirror) return; // This can be "null" if there's compilation errors. ITextEditorSettings editorSettings = TextEditorCore.Instance.TextEditorSettings; if (false == editorSettings.DisplayOutput) return; // The output display has been disabled, don't display. try { List<string> variableList = null; executionMirror.GetCoreDump(out variableList, editorSettings.MaxArrayDisplaySize, editorSettings.MaxOutputDepth); if (null != variableList) { foreach (string variable in variableList) { outputStream.Write(new ProtoCore.OutputMessage( OutputMessage.MessageType.Info, variable)); Logger.LogPerf("CoreDump-ExecSession", variable); } } } catch (System.Exception ex) { outputStream.Write(new ProtoCore.OutputMessage(OutputMessage.MessageType.Error, ex.Message)); Logger.LogPerf("CoreDumpEx", ex.Message); } }
private void CleanUpRunners() { Logger.LogInfo("DetachFromDebugger", "Detach"); // Clear up all watch related data members. this.workerParams.CurrentVmState = null; this.currentWatchedMirror = null; this.currentWatchedStackValue = null; if (null != scriptRunner) scriptRunner = null; if (null != debugRunner) { debugRunner.Shutdown(); debugRunner = null; } if (null != internalWorker) { // @TODO(Ben): Perhaps cancellation is needed? internalWorker = null; } //Fix DG-1464973 Sprint25: rev 3444 : Multiple import issue - dispose core after execution //Core Cleanup should happen only after execution has finished, //DebugRunner is ShutDown. if (null != this.core) { this.core.Cleanup(); this.core = null; } workerParams.ResetStates(); SetExecutionState(ExecutionStateChangedEventArgs.States.None); }
/// <summary> /// VM Debugging API for general Debugging purposes /// temporarily used by Cmmand Line REPL /// </summary> /// <returns></returns> public string GetCoreDump() { // Prints out the final Value of every symbol in the program // Traverse order: // Exelist, Globals symbols ProtoCore.DSASM.Executive exec = runnerCore.CurrentExecutive.CurrentDSASMExec; ProtoCore.DSASM.Mirror.ExecutionMirror execMirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(exec, runnerCore); ProtoCore.DSASM.Executable exe = exec.rmem.Executable; // Only display symbols defined in the default top-most langauge block; // Otherwise garbage information may be displayed. string formattedString = string.Empty; if (exe.runtimeSymbols.Length > 0) { int blockId = 0; ProtoCore.DSASM.SymbolTable symbolTable = exe.runtimeSymbols[blockId]; for (int i = 0; i < symbolTable.symbolList.Count; ++i) { //int n = symbolTable.symbolList.Count - 1; //formatParams.ResetOutputDepth(); ProtoCore.DSASM.SymbolNode symbolNode = symbolTable.symbolList[i]; bool isLocal = ProtoCore.DSASM.Constants.kGlobalScope != symbolNode.functionIndex; bool isStatic = (symbolNode.classScope != ProtoCore.DSASM.Constants.kInvalidIndex && symbolNode.isStatic); if (symbolNode.isArgument || isLocal || isStatic || symbolNode.isTemp) { // These have gone out of scope, their values no longer exist //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); continue; } ProtoCore.Runtime.RuntimeMemory rmem = exec.rmem; StackValue sv = rmem.GetStackData(blockId, i, ProtoCore.DSASM.Constants.kGlobalScope); formattedString = formattedString + string.Format("{0} = {1}\n", symbolNode.name, execMirror.GetStringValue(sv, rmem.Heap, blockId)); //if (null != globaltrace) //{ // int maxLength = 1020; // while (formattedString.Length > maxLength) // { // globaltrace.AppendLine(formattedString.Substring(0, maxLength)); // formattedString = formattedString.Remove(0, maxLength); // } // globaltrace.AppendLine(formattedString); //} } //formatParams.ResetOutputDepth(); } //return ((null == globaltrace) ? string.Empty : globaltrace.ToString()); return formattedString; }