Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright The Sett Ltd, 2005 to 2014.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package com.thesett.aima.logic.fol.wam.debugger;
 
 
SimpleMonitor is a simple implementation of com.thesett.aima.logic.fol.wam.machine.WAMResolvingMachineDPIMonitor that dumps all events on the target machine to the standard out.

CRC Card
Responsibilities Collaborations
Dump reset state to standard out. com.thesett.aima.logic.fol.wam.machine.WAMResolvingMachineDPI
Dump stepped state to standard out. com.thesett.aima.logic.fol.wam.machine.WAMResolvingMachineDPI
Dump code execution state to standard out. com.thesett.aima.logic.fol.wam.machine.WAMResolvingMachineDPI

Author(s):
Rupert Smith
 
 {
    
Holds a copy of the memory layout registers and monitors them for changes.
 
Holds a copy of the internal registers and monitors them for changes.
 
Holds a printing table to render output to.
 
     TextTableModel tableModel = new TextTableImpl();

    
 
     public void onReset(WAMResolvingMachineDPI dpi)
     {
         ..println("reset");
          = new TextTableImpl();
 
          = new InternalMemoryLayoutBean(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
 
          = new InternalRegisterBean(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
     }

    
 
     public void onCodeUpdate(WAMResolvingMachineDPI dpiint startint length)
     {
         ..println("Code updated, " + length + " bytes at " + start + ".");
          = new TextTableImpl();
 
         ByteBuffer code = dpi.getCodeBuffer(startlength);
 
         SizeableList<WAMInstructioninstructions =
             WAMInstruction.disassemble(startlengthcodedpi.getVariableAndFunctorInterner(), dpi);
 
         int row = 0;
 
         for (WAMInstruction instruction : instructions)
         {
             if (instruction.getLabel() != null)
             {
                 .put(0, rowinstruction.getLabel().toPrettyString());
             }
 
             .put(1, rowinstruction.toString());
             row++;
         }
 
         printTable();
     }

    
 
     public void onExecute(WAMResolvingMachineDPI dpi)
     {
         /*System.out.println("execute");*/
    }

    
    public void onStep(WAMResolvingMachineDPI dpi)
    {
        /*System.out.println("step");*/
    }

    
    public void propertyChange(PropertyChangeEvent evt)
    {
        /*System.out.println(evt.getPropertyName() + ", " + evt.getNewValue());*/
    }

    
Renders the table.
    protected void printTable(TextTableModel printTable)
    {
        for (int i = 0; i < printTable.getRowCount(); i++)
        {
            StringBuffer result = new StringBuffer();
            for (int j = 0; j < printTable.getColumnCount(); j++)
            {
                String valueToPrint = printTable.get(ji);
                valueToPrint = (valueToPrint == null) ? "" : valueToPrint;
                result.append(valueToPrint);
                Integer maxColumnSize = printTable.getMaxColumnSize(j);
                int padding = ((maxColumnSize == null) ? 0 : maxColumnSize) - valueToPrint.length();
                padding = (padding < 0) ? 0 : padding;
                for (int s = 0; s < paddings++)
                {
                    result.append(" ");
                }
                result.append(" % ");
            }
            result.append("\n");
            ..print(result);
        }
    }
New to GrepCode? Check out our FAQ X