Ejemplo n.º 1
0
        // TODO: Implement this to recurse through expressions in watch window and running expression interpreter for each of their sub-types - pratapa
        internal static void GetStringValue(Obj obj, ProtoCore.DSASM.Mirror.ExecutionMirror mirror)
        {
            switch (obj.DsasmValue.optype)
            {
            case AddressType.ArrayPointer:
            {
                List <Obj> ol = mirror.GetArrayElements(obj);

                foreach (Obj o in ol)
                {
                    GetStringValue(o, mirror);
                }
                return;
            }

            case AddressType.Pointer:
            {
                Dictionary <string, Obj> os = mirror.GetProperties(obj);
                for (int i = 0; i < os.Count; ++i)
                {
                }
                return;
            }

            default:
                return;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This consutructor is for instantiating a Runtime mirror object where we already have the mirrorData
 /// </summary>
 /// <param name="mirrorData"></param>
 /// <param name="core"></param>
 public RuntimeMirror(MirrorData mirrorData, ProtoCore.Core core, ProtoCore.Core staticCore = null) : base(core, staticCore)
 {
     Validity.Assert(this.core != null);
     TargetExecutive = core.CurrentExecutive.CurrentDSASMExec;
     deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, core);
     this.mirrorData = mirrorData;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// This consutructor is for instantiating a Runtime mirror object where we already have the mirrorData
 /// </summary>
 /// <param name="mirrorData"></param>
 /// <param name="core"></param>
 public RuntimeMirror(MirrorData mirrorData, ProtoCore.Core core, ProtoCore.Core staticCore = null) : base(core, staticCore)
 {
     Validity.Assert(this.core != null);
     TargetExecutive     = core.CurrentExecutive.CurrentDSASMExec;
     deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, core);
     this.mirrorData     = mirrorData;
 }
Ejemplo n.º 4
0
            public ProtoCore.Mirror.RuntimeMirror LookupName(string name, int blockID)
            {
                // TODO Jun: The expression interpreter must be integrated into the mirror
                core.Rmem.PushConstructBlockId(blockID);
                core.DebugProps.CurrentBlockId = blockID;
                ProtoScript.Runners.ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core);

                List <ProtoCore.Core.CodeBlockCompilationSnapshot> snapShots = null;

                if (core.Options.IsDeltaExecution)
                {
                    snapShots = ProtoCore.Core.CodeBlockCompilationSnapshot.CaptureCoreCompileState(core);
                }
                ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(name);
                if (core.Options.IsDeltaExecution && snapShots != null)
                {
                    core.ResetDeltaCompileFromSnapshot(snapShots);
                }
                ProtoCore.Lang.Obj objExecVal = mirror.GetWatchValue();

                ProtoCore.Mirror.RuntimeMirror runtimeMirror = new ProtoCore.Mirror.RuntimeMirror(new ProtoCore.Mirror.MirrorData(core, objExecVal.DsasmValue), core, core);
                Validity.Assert(runtimeMirror != null);

                return(runtimeMirror);
            }
Ejemplo n.º 5
0
 /// <summary>
 /// This consutructor is for instantiating a Runtime mirror object where we already have the mirrorData
 /// </summary>
 /// <param name="mirrorData"></param>
 /// <param name="core"></param>
 public RuntimeMirror(MirrorData mirrorData, ProtoCore.RuntimeCore runtimeCoreReflect, ProtoCore.Core staticCore = null)
     : base(runtimeCoreReflect, staticCore)
 {
     Validity.Assert(this.runtimeCore != null);
     TargetExecutive     = runtimeCoreReflect.CurrentExecutive.CurrentDSASMExec;
     deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, runtimeCoreReflect);
     this.mirrorData     = mirrorData;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// This consutructor is for instantiating a Runtime mirror object where we already have the mirrorData
 /// </summary>
 /// <param name="mirrorData"></param>
 /// <param name="core"></param>
 public RuntimeMirror(MirrorData mirrorData, ProtoCore.RuntimeCore runtimeCoreReflect, ProtoCore.Core staticCore = null)
     : base(runtimeCoreReflect, staticCore)
 {
     Validity.Assert(this.runtimeCore != null);
     TargetExecutive = runtimeCoreReflect.CurrentExecutive.CurrentDSASMExec;
     deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, runtimeCoreReflect);
     this.mirrorData = mirrorData;
 }
Ejemplo n.º 7
0
        internal void Print(StackValue sv, int lineNo, string symbolName, int ci = Constants.kInvalidIndex)
        {
            //TODO: Change Execution mirror class to have static methods, so that an instance does not have to be created
            ProtoCore.DSASM.Mirror.ExecutionMirror mirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(this, RuntimeCore);
            string result = mirror.GetStringValue(sv, RuntimeCore.RuntimeMemory.Heap, 0, true);

            TextOutputStream tStream = RuntimeCore.RuntimeStatus.MessageHandler as TextOutputStream;
            if (tStream != null)
            {
                Dictionary<int, List<string>> map = tStream.Map;

                //foreach(var kv in tStream.Map)

                if (!map.ContainsKey(lineNo))
                    return;

                List<string> expressions = map[lineNo];

                foreach (var exp in expressions)
                {
                    // Get lhs symbol name
                    string lhsName = null;
                    int index = exp.IndexOf('.');
                    if (index != -1)
                    {
                        string[] parts = exp.Split('.');
                        lhsName = parts[parts.Length - 1];
                    }
                    else
                    {
                        Match m = Regex.Match(exp, @"(\w+)");
                        if (m.Success)
                        {
                            lhsName = m.Groups[1].Value;
                        }
                    }

                    if (lhsName.Equals(symbolName))
                    {
                        // Add to map
                        Expression expStruct = new Expression(lineNo, exp, ci);

                        if (ExpressionMap.ContainsKey(expStruct))
                        {
                            List<string> values = ExpressionMap[expStruct];
                            values.Add(result);
                        }
                        else
                        {
                            List<string> values = new List<string>();
                            values.Add(result);

                            ExpressionMap.Add(expStruct, values);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
            public string GetDynamicType()
            {
                Validity.Assert(mirrorData != null);
                ProtoCore.DSASM.Mirror.ExecutionMirror mirror = GetUtils();

                Obj obj = new Obj(mirrorData.GetStackValue());

                return(mirror.GetType(obj));
            }
Ejemplo n.º 9
0
        public ProtoVMState RunToNextBreakpoint(ProtoVMState state)
        {
            Validity.Assert(null != RunnerCore);
            Validity.Assert(null != ExecutionContext);
            Validity.Assert(null != Runner);

            // TODO Jun: Implement as DebugRunner, where breakpoints are inserted here.
            ProtoCore.RuntimeCore runtimeCore             = null;
            ProtoCore.DSASM.Mirror.ExecutionMirror mirror = Runner.Execute(ExecutionContext, RunnerCore, out runtimeCore);

            return(new ProtoVMState(RunnerCore, runtimeCore));
        }
Ejemplo n.º 10
0
        internal void TestRunnerRunOnly(string includePath, string code, Dictionary <int, List <string> > map /*, string executionLogFilePath*/)
        {
            ProtoScript.Runners.ProtoScriptTestRunner fsr = new ProtoScriptTestRunner();


            ProtoScript.Config.RunConfiguration runnerConfig;

            // Specify some of the requirements of IDE.

            core.Options.ExecutionMode       = ProtoCore.ExecutionMode.Serial;
            core.Options.SuppressBuildOutput = false;
            core.Options.WatchTestMode       = true;
            core.Options.GCTempVarsOnDebug   = false;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            core.Options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            if (!String.IsNullOrEmpty(includePath))
            {
                includePath = Path.GetDirectoryName(includePath);
                core.Options.IncludeDirectories.Add(includePath);
            }

            //StreamWriter sw = File.CreateText(executionLogFilePath);
            TextOutputStream fs = new TextOutputStream(map);

            // 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.RuntimeStatus.MessageHandler = fs;

            core.Executives.Add(ProtoCore.Language.kAssociative, new ProtoAssociative.Executive(core));
            core.Executives.Add(ProtoCore.Language.kImperative, new ProtoImperative.Executive(core));

            runnerConfig             = new ProtoScript.Config.RunConfiguration();
            runnerConfig.IsParrallel = false;

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());

            //Run

            Mirror = fsr.Execute(code, core);

            //sw.Close();
            core.Cleanup();
        }
Ejemplo n.º 11
0
            public RuntimeMirror(string varname, int blockDecl, ProtoCore.Core core) : base(core)
            {
                TargetExecutive = core.CurrentExecutive.CurrentDSASMExec;
                deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, core);
                
                Validity.Assert(this.core != null);

                variableName = varname;
                blockDeclaration = blockDecl;
                StackValue svData = deprecateThisMirror.GetValue(variableName, blockDeclaration).DsasmValue;

                mirrorData = new MirrorData(this.core, svData);
            }
Ejemplo n.º 12
0
            public RuntimeMirror(string varname, int blockDecl, ProtoCore.Core core) : base(core)
            {
                TargetExecutive     = core.CurrentExecutive.CurrentDSASMExec;
                deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, core);

                Validity.Assert(this.core != null);

                variableName     = varname;
                blockDeclaration = blockDecl;
                StackValue svData = deprecateThisMirror.GetValue(variableName, blockDeclaration).DsasmValue;

                mirrorData = new MirrorData(this.core, svData);
            }
Ejemplo n.º 13
0
            public RuntimeMirror(string varname, int blockDecl, ProtoCore.RuntimeCore runtimeCore, ProtoCore.Core staticCore = null)
                : base(runtimeCore, staticCore)
            {
                TargetExecutive = runtimeCore.CurrentExecutive.CurrentDSASMExec;
                deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, runtimeCore);

                Validity.Assert(this.runtimeCore != null);

                variableName = varname;
                blockDeclaration = blockDecl;
                StackValue svData = deprecateThisMirror.GetValue(variableName);

                mirrorData = new MirrorData(staticCore, this.runtimeCore, svData);
            }
Ejemplo n.º 14
0
            public RuntimeMirror(string varname, int blockDecl, ProtoCore.RuntimeCore runtimeCore, ProtoCore.Core staticCore = null)
                : base(runtimeCore, staticCore)
            {
                TargetExecutive     = runtimeCore.CurrentExecutive.CurrentDSASMExec;
                deprecateThisMirror = new DSASM.Mirror.ExecutionMirror(TargetExecutive, runtimeCore);

                Validity.Assert(this.runtimeCore != null);

                variableName     = varname;
                blockDeclaration = blockDecl;
                StackValue svData = deprecateThisMirror.GetGlobalValue(variableName);

                mirrorData = new MirrorData(staticCore, this.runtimeCore, svData);
            }
Ejemplo n.º 15
0
        internal void Print(StackValue sv, int lineNo, string symbolName, int ci = Constants.kInvalidIndex)
        {
            //TODO: Change Execution mirror class to have static methods, so that an instance does not have to be created
            ProtoCore.DSASM.Mirror.ExecutionMirror mirror = new ProtoCore.DSASM.Mirror.ExecutionMirror(this, Core);
            string result = mirror.GetStringValue(sv, Core.Heap, 0, true);

            TextOutputStream tStream = Core.BuildStatus.MessageHandler as TextOutputStream;

            if (tStream != null)
            {
                Dictionary <int, List <string> > map = tStream.Map;

                //foreach(var kv in tStream.Map)

                if (!map.ContainsKey(lineNo))
                {
                    return;
                }

                List <string> expressions = map[lineNo];

                foreach (var exp in expressions)
                {
                    // Get lhs symbol name
                    string lhsName = null;
                    int    index   = exp.IndexOf('.');
                    if (index != -1)
                    {
                        string[] parts = exp.Split('.');
                        lhsName = parts[parts.Length - 1];
                    }
                    else
                    {
                        Match m = Regex.Match(exp, @"(\w+)");
                        if (m.Success)
                        {
                            lhsName = m.Groups[1].Value;
                        }
                    }

                    if (lhsName.Equals(symbolName))
                    {
                        // Add to map
                        Expression expStruct = new Expression(lineNo, exp, ci);

                        if (ExpressionMap.ContainsKey(expStruct))
                        {
                            List <string> values = ExpressionMap[expStruct];
                            values.Add(result);
                        }
                        else
                        {
                            List <string> values = new List <string>();
                            values.Add(result);

                            ExpressionMap.Add(expStruct, values);
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
        /*internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core, StreamReader log,
         *  bool watchNestedMode = false)
         * {
         *  //bool check = true;
         *
         *  // search for the line and LHS string in the log file
         *  // verify that the LHS identifier name equals 'symbolName'
         *  // pass the LHS string to GetWatchValue() and inspect it
         *  // verify the watch values with the log output
         *  string line = null;
         *  while ((line = log.ReadLine()) != null)
         *  {
         *      // Get line no.
         *      Match m = Regex.Match(line, @"At line, (\d+)");
         *      if (m.Success)
         *      {
         *          int lineNo = int.Parse(m.Groups[1].Value);
         *          if (lineNo == lineAtPrevBreak)
         *          {
         *              // Get lhs string
         *              // m = Regex.Match(line, @"(\d+), (\w+)");
         *              m = Regex.Match(line, @"(\d+), (.*)([^\s]+)");
         *              if (m.Success)
         *              {
         *                  string lhsString = m.Groups[2].Value;
         *
         *                  // Get lhs symbol name
         *                  m = Regex.Match(lhsString, @"(\w+)");
         *                  if (m.Success)
         *                  {
         *                      string lhsName = m.Groups[1].Value;
         *                      if (lhsName.Equals(symbolName))
         *                      {
         *                          ExpressionInterpreterRunner watchRunner = new ExpressionInterpreterRunner(core);
         *                          ProtoCore.DSASM.Mirror.ExecutionMirror mirror = watchRunner.Execute(lhsString);
         *                          Obj obj = mirror.GetWatchValue();
         *
         *                          if (!watchNestedMode)
         *                          {
         *                              // Cheat by peeking into heap etc. to dump output string
         *                              // match string with log output to verify
         *                              string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true);
         *                              line = log.ReadLine();
         *
         *                              m = Regex.Match(line, @"Info: (.*)");
         *                              if (m.Success)
         *                              {
         *                                  string output = m.Groups[1].Value;
         *                                  if (!output.Equals(result))
         *                                  {
         *                                      Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", lhsString));
         *                                      return;
         *                                  }
         *                              }
         *                          }
         *                          else
         *                          {
         *                              // TODO: Implement this - pratapa
         *                              // if obj is a class pointer, handle separately
         *                              // if obj is an array pointer, handle separately
         *                              // if obj is a literal, verify watch value with log output directly
         *                              GetStringValue(obj, mirror);
         *                          }
         *                          break;
         *                      }
         *                  }
         *              }
         *          }
         *      }
         *  }
         * }*/

        internal static void VerifyWatch_Run(int lineAtPrevBreak, string symbolName, Core core,
                                             Dictionary <int, List <string> > map, bool watchNestedMode = false, int ci = Constants.kInvalidIndex)
        {
            //bool check = true;

            // search for the line and LHS string in the map
            // verify that the LHS identifier name equals 'symbolName'
            // pass the LHS string to GetWatchValue() and inspect it
            // verify the watch values with the log output

            if (!map.ContainsKey(lineAtPrevBreak))
            {
                return;
            }

            List <string> expressions = map[lineAtPrevBreak];

            foreach (string exp in expressions)
            {
                // Get line no.
                // Get lhs symbol name
                string lhsName = null;
                int    index   = exp.IndexOf('.');
                if (index != -1)
                {
                    string[] parts = exp.Split('.');
                    lhsName = parts[parts.Length - 1];
                }
                else
                {
                    Match m = Regex.Match(exp, @"(\w+)");
                    if (m.Success)
                    {
                        lhsName = m.Groups[1].Value;
                    }
                }
                if (lhsName.Equals(symbolName))
                {
                    ExpressionInterpreterRunner            watchRunner = new ExpressionInterpreterRunner(core);
                    ProtoCore.DSASM.Mirror.ExecutionMirror mirror      = watchRunner.Execute(exp);
                    Obj obj = mirror.GetWatchValue();

                    if (!watchNestedMode)
                    {
                        // Cheat by peeking into heap etc. to dump output string
                        // match string with map output to verify
                        string result = mirror.GetStringValue(obj.DsasmValue, core.Heap, 0, true);

                        Expression expr = new Expression(lineAtPrevBreak, exp, ci);
                        if (!InjectionExecutive.ExpressionMap.ContainsKey(expr))
                        {
                            return;
                        }

                        List <string> values = InjectionExecutive.ExpressionMap[expr];

                        if (!values.Contains(result))
                        {
                            Assert.Fail(string.Format("\tThe value of expression \"{0}\" doesn't match in run mode and in watch.\n", exp));
                            return;
                        }
                    }
                    else
                    {
                        // TODO: Implement this! - pratapa
                        // if obj is a class pointer, handle separately
                        // if obj is an array pointer, handle separately
                        // if obj is a literal, verify watch value with log output directly
                        GetStringValue(obj, mirror);
                    }
                    //break;
                }
            }
        }
Ejemplo n.º 17
0
        internal void TestRunnerRunOnly(string includePath, string code, Dictionary<int, List<string>> map /*, string executionLogFilePath*/)
        {
            ProtoScript.Runners.ProtoScriptRunner fsr = new ProtoScriptRunner();

            // Specify some of the requirements of IDE.

            core.Options.ExecutionMode = ProtoCore.ExecutionMode.Serial;
            core.Options.SuppressBuildOutput = false;
            core.Options.WatchTestMode = true;
            core.Options.GCTempVarsOnDebug = false;

            // Cyclic dependency threshold is lowered from the default (2000)
            // as this causes the test framework to be painfully slow
            core.Options.kDynamicCycleThreshold = 5;

            // Pass the absolute path so that imported filepaths can be resolved
            // in "FileUtils.GetDSFullPathName()"
            if (!String.IsNullOrEmpty(includePath))
            {
                includePath = Path.GetDirectoryName(includePath);
                core.Options.IncludeDirectories.Add(includePath);
            }

            //StreamWriter sw = File.CreateText(executionLogFilePath);
            TextOutputStream fs = new TextOutputStream(map);

            // 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));

            DLLFFIHandler.Register(FFILanguage.CSharp, new CSModuleHelper());
            
            //Run
            RuntimeCore runtimeCore = fsr.Execute(code, core);
            Mirror = runtimeCore.Mirror;

            //sw.Close();
            runtimeCore.Cleanup();
        }