Esempio n. 1
0
 public SpyPoint(SpyPort p, TermNode g)
     : base()
 {
     port     = p;
     saveGoal = g;
     level    = g.Level;
 }
Esempio n. 2
0
    public PredicateDescr(string m, string f, string n, int a, ClauseNode c)
    {
      module = m;
      definingFile = (f == null) ? "predefined or asserted predicate" : f;
      name = n;
      arity = a;
#if debugging
      spyMode = SpyPort.none;
#endif
      clauseList = clauseListEnd = c;
      // disqualify this predicate for first-argument indexing if arity=0
    }
Esempio n. 3
0
            public PredicateDescr(string module, string definingFile, string functor, int arity, ClauseNode clauseList)
            {
                this.module       = module;
                this.definingFile = (definingFile == null) ? "predefined or asserted predicate" : definingFile;
                this.functor      = functor;
                this.arity        = arity;
#if enableSpying
                spyMode = SpyPort.None;
#endif
                this.clauseList       = clauseListEnd = clauseList;
                this.lastCachedClause = null; // no cached clauses (yet)
            }
      public PredicateDescr (string module, string definingFile, string functor, int arity, ClauseNode clauseList)
      {
        this.module = module;
        this.definingFile = (definingFile == null) ? "predefined or asserted predicate" : definingFile;
        this.functor = functor;
        this.arity = arity;
#if enableSpying
        spyMode = SpyPort.None;
#endif
        this.clauseList = clauseListEnd = clauseList;
        this.lastCachedClause = null; // no cached clauses (yet)
      }
Esempio n. 5
0
            public void SetSpy(bool enabled, string functor, int arity, SpyPort setPorts, bool warn)
            {
                string spySet = "[";

                if (enabled)
                {
                    spied   = true;
                    spyMode = SpyPort.None;

                    foreach (SpyPort port in Enum.GetValues(typeof(SpyPort)))
                    {
                        if (setPorts > 0 && (setPorts | port) == setPorts)
                        {
                            spyMode |= port;

                            if (port != SpyPort.Full)
                            {
                                spySet += port.ToString() + (port == SpyPort.Redo ? "]" : ",");
                            }
                        }
                    }

                    if (setPorts != SpyPort.None)
                    {
                        IO.Message("Spying {0} enabled for {1}/{2}", spySet, functor, arity);
                    }
                }
                else if (spied) // nospy
                {
                    spied = false;
                    IO.Message("Spying disabled for {0}/{1}", functor, arity);
                }
                else if (warn)
                {
                    IO.Message("There was no spypoint on {0}/{1}", functor, arity);
                }
            }
Esempio n. 6
0
 public void Kill()
 {
     port = SpyPort.None;
 }
 public void Kill()
 {
     port = SpyPort.None;
 }
 public SpyPoint(SpyPort p, TermNode g)
     : base()
 {
     port = p;
     saveGoal = g;
     level = g.Level;
 }
Esempio n. 9
0
    public void SetSpy(bool enabled, string functor, int arity, SpyPort setPorts, bool warn)
    {
      string spySet = "[";

      if (enabled)
      {
        spied = true;
        spyMode = SpyPort.none;

        foreach (SpyPort port in Enum.GetValues(typeof(SpyPort)))
          if (setPorts > 0 && (setPorts | port) == setPorts)
          {
            spyMode |= port;

            if (port != SpyPort.full)
              spySet += port.ToString() + (port == SpyPort.redo ? "]" : ",");
          }

        if (setPorts != SpyPort.none)
          PrologIO.Message("Spying {0} enabled for {1}/{2}", spySet, functor, arity);
      }
      else if (spied) // nospy
      {
        spied = false;
        PrologIO.Message("Spying disabled for {0}/{1}", functor, arity);
      }
      else if (warn)
        PrologIO.Message("There was no spypoint on {0}/{1}", functor, arity);
    }
Esempio n. 10
0
        private bool Debugger(SpyPort port, TermNode goalNode, Term currClause, bool isFact, int callNo)
        {
            if (!reporting) return false;

              // only called if reporting = true. This means that at least one of the following conditions hold:
              // (1) debug is true. This means that trace = true and/or we must check whether this port has a spypoint
              // (2) xmlTrace = true.
              // Console-interaction will only occur if debug && (trace || spied)
              bool spied = false;
              bool console;
              string s;
              int free = 0;
              string lmar;

              if (!trace) // determine spied-status
              {
            if (goalNode.PredDescr == null) goalNode.FindPredicateDefinition(ps);

            spied = (goalNode.Spied && (goalNode.SpyPort | port) == goalNode.SpyPort);
              }
              console = debug && (trace || spied);
              // continue only if either trace or spied, or if an XML-trace is to be constructed
              if (!console && !xmlTrace) return false;

              lmar = null;

              Term goal = goalNode.Term;
              int level = goalNode.Level;

              if (@"\tdebug\tnodebug\tspy\tnospy\tnospyall\tconsult\ttrace\tnotrace\txmltrace\t".IndexOf(goal.Functor) != -1) return false;

              if (console) // this part is not required for xmlTrace
              {
            if (!qskip && level >= levelMax) return false;

            levelMax = INF;   // recover from (q)s(kip) command
            qskip = false; // ...

            const int widthMin = 20; // minimal width of writeable portion of line
            #if mswindows
            int width = Utils.NumCols - 10;
            #else
            int width = 140;
            #endif
            int indent = 3 * (level - levelMin);
            int condensedLevel = 0;

            while (indent > width - widthMin)
            {
              indent -= width - widthMin;
              condensedLevel++;
            }

            if (condensedLevel == 0)
            {
              lmar = Utils.RepeatString("|  ", level).Substring(0, indent);
              free = width - indent;
            }
            else
            {
              string dots = "| ... ";
              lmar = dots + Utils.RepeatString("|  ", level).Substring(0, indent);
              free = width - indent - dots.Length;
            }

            PrologIO.Write(lmar);
              }

              switch (port)
              {
            case SpyPort.call:
              if (console)
              {
            s = Utils.WrapWithMargin(goal.ToString(), lmar + "|     ", free);
            PrologIO.Write("{0,2:d2} Goal: {1}", level, s);
            s = Utils.WrapWithMargin(currClause.ToString(), lmar, free);
            PrologIO.Write("{0}{1,2:d2} {2}: {3}", lmar, level, "Try ", s);
              }
              if (xmlTrace)
              {
            if (level > prevLevel)
            {
              xtw.WriteStartElement("body");
              xtw.WriteAttributeString("goal", goal.ToString());
              xtw.WriteAttributeString("level", level.ToString());
            }
            else if (level < prevLevel)
              xtw.WriteEndElement();
            else
              XmlTraceWriteTerm("goal", "goal", goal);
            XmlTraceWriteTerm("try", isFact ? "fact" : "pred", currClause);
              }
              break;
            case SpyPort.redo:
              if (console)
              {
            s = Utils.WrapWithMargin(currClause.ToString(), lmar + "|     ", free);
            PrologIO.Write("{0,2:d2} {1}: {2}", level, "Try ", s); // fact or clause
              }
              if (xmlTrace)
              {
            if (level < prevLevel) xtw.WriteEndElement();
            XmlTraceWriteTerm("try", isFact ? "fact" : "clause", currClause);
              }
              break;
            case SpyPort.fail:
              if (console)
              {
            //s = Utils.WrapWithMargin (" ", lmar + "         ", free);
            //IO.Write ("{0,2:d2} Fail  {1}", level, s);
            s = Utils.WrapWithMargin(goal.ToString(), lmar + "|     ", free);
            PrologIO.Write("{0,2:d2} Fail: {1}", level, s);
              }
              if (xmlTrace)
              {
            if (level < prevLevel) xtw.WriteEndElement();
            XmlTraceWriteTerm("fail", "goal", goal);
              }
              break;
            case SpyPort.exit:
              if (console)
              {
            s = Utils.WrapWithMargin(goal.ToString(), lmar + "         ", free);
            PrologIO.Write("{0,2:d2} Exit: {1}", level, s);
              }
              if (xmlTrace)
              {
            if (level < prevLevel) xtw.WriteEndElement();
            XmlTraceWriteTerm("exit", "match", goal);
              }
              break;
              }

              prevLevel = level;

              redo = false;

              if (rushToEnd || !console) return false;

              return DoDebuggingAction(port, lmar, goalNode);
        }
Esempio n. 11
0
        private bool DoDebuggingAction(SpyPort port, string lmar, TermNode goalNode)
        {
            const string prompt = "|  TODO: ";
              const string filler = "|        ";
              int level;
              string cmd;
              int n = INF;
              int leap = 0; // difference between current level and new level

              while (true)
              {
            level = goalNode.Level;

            while (true)
            {
              PrologIO.Write(lmar + prompt);
              cmd = Console.ReadLine().Replace(" ", "");

              if (cmd.Length > 1)
              {
            string cmd0 = cmd.Substring(0, 1);
            try { n = Int32.Parse(cmd.Substring(1)); }
            catch { break; }

            if ("sr".IndexOf(cmd0) != -1 && Math.Abs(n) > level)
              PrologIO.WriteLine(lmar + filler + "*** Illegal value {0} -- must be in the range -{1}..{1}", n, level);
            else
            {
              if (n != INF && "cloqfgan+-.?h".IndexOf(cmd0) != -1)
                PrologIO.WriteLine(lmar + filler + "*** Unexpected argument {0}", n);
              else
              {
                if (n < 0) { level += n; leap = -n; } else { leap = level - n; level = n; }

                cmd = cmd0;
                break;
              }
            }
              }
              else
              {
            leap = 0;
            if (cmd != "") cmd = cmd.Substring(0, 1);
            break;
              }
            }

            switch (cmd)
            {
              case "":   // creap
              case "c":  // ...
            return false;
              case "l":  // leap
            SetSwitch("Tracing", ref trace, false);
            return false;
              case "s":  // skip
            if (n == INF) levelMax = level; else levelMax = n + 1;
            return false;
              case "o":  // out (skip to exit or fail)
            PrologIO.WriteLine(lmar + filler + "*** NOT YET IMPLEMENTED");
            break;
              case "q":  // q-skip (skip subgoals except if a spypoint was set)
            levelMax = level;
            qskip = true;
            return false;
              case "r":  // retry
            if (port == SpyPort.call && leap == 0)
            {
              PrologIO.WriteLine(lmar + filler + "*** retry command has no effect here");

              return false;
            }
            else
            {
              RetryCurrentGoal(level);

              if (xmlTrace)
              {
                XmlTraceWriteElement("RETRY",
                  (n == INF) ? "Retry entered by user" : String.Format("Retry to level {0} entered by user", level));
                XmlTraceWriteEnds(leap);
              }
              return true;
            }
              case "f":  // fail
            if (port == SpyPort.fail)
            {
              PrologIO.WriteLine(lmar + filler + "*** fail command has no effect here");

              return false;
            }
            else
            {
              if (!CanBacktrack(true)) throw new AbortQueryException();

              if (xmlTrace)
              {
                XmlTraceWriteElement("FAILED",
                  (n == INF) ? "Goal failed by user" : String.Format("Retry to level {0} entered by user", level));
                XmlTraceWriteEnds(leap);
              }
              return true;
            }
              case "g":  // ancestors
            ShowAncestorGoals(lmar + filler);
            break;
              case "n":  // nodebug
            SetSwitch("Debugging", ref debug, false);
            return false;
              case "a":
            if (xmlTrace) XmlTraceWriteElement("ABORT", "Session aborted by user");
            throw new AbortQueryException();
              case "+":  // spy this
            goalNode.PredDescr.SetSpy(true, goalNode.Term.Functor, goalNode.Term.Arity, SpyPort.full, false);
            return false;
              case "-":  // nospy this
            goalNode.PredDescr.SetSpy(false, goalNode.Term.Functor, goalNode.Term.Arity, SpyPort.full, false);
            return false;
              case ".":  // run to completion
            rushToEnd = true;
            return false;
              case "?":  // help
              case "h":  // ...
            string[] help = new string[] {
              "c, CR      creep       Single-step to the next port",
              "l          leap        Resume running, switch tracing off; stop at the next spypoint.",
              "s [<N>]    skip        If integer N provided: skip to Exit or Fail port of level N.",
              "o          out         NOT YET IMPLEMENTED. Skip to the Exit or Fail port of the ancestor.",
              "q          quasi-skip  Same as skip, but will stop if an intermediate spypoint is found.",
              "r [<N>]    retry       Transfer control back to the Call port at level N.",
              "f          fail        Fail the current goal.",
              "g          ancestors   Show ancestor goals.",
              "n          nodebug     Switch the debugger off.",
              "a          abort       Abort the execution of the current query.",
              "+          spy this    Set a spypoint on the current goal.",
              "-          nospy this  Remove the spypoint for the current goal, if it exists.",
              ".          rush        Run to completion without furder prompting.",
              "?, h       help        Show this text."
            };
            foreach (string line in help)
              PrologIO.WriteLine(lmar + filler + line);
            break;
              default:
            PrologIO.WriteLine(lmar + filler + "*** Unknown command '{0}' -- enter ? or h for help", cmd);
            break;
            }
              }
        }