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;
 
 import java.util.List;
 
InternalRegisterBean represents WAMInternalRegisters as a Java bean, and adds the ability to attach a java.beans.PropertyChangeListener to it. The change listener will be notified when registers or flags change value.

CRC Card
Responsibilities Collaborations
Provide change notification on registers and flags.

Author(s):
Rupert Smith
 
 public class InternalRegisterBean extends WAMInternalRegisters implements RegisterModel
 {
    
Defines the names of the machine registers.
 
     public static final String[] REGISTER_NAMES =
         new String[] { "ip""hp""hbp""sp""up""ep""bp""b0""trp" };

    
Defines the names of the machine flags.
 
     public static final String[] FLAG_NAMES = new String[] { "writeMode" };

    
Holds any property change listener to notify of register value changes.
 
     private PropertyChangeListener listener;

    
Creates an instance of the WAM machine internal register file and flags.

Parameters:
ip The current instruction pointer into the code.
hp The heap pointer.
hbp The top of heap at the latest choice point.
sp The secondary heap pointer, used for the heap address of the next term to match.
up The unification stack pointer.
ep The environment base pointer.
bp The choice point base pointer.
b0 The last call choice point pointer.
trp The trail pointer.
writeMode The write mode flag.
 
     public InternalRegisterBean(int ipint hpint hbpint spint upint epint bpint b0int trp,
         boolean writeMode)
     {
         super(iphphbpspupepbpb0trpwriteMode);
     }

    
Establishes a PropertyChangeListener to notify of changes to the register file or flags.

Parameters:
listener A PropertyChangeListener to notify of changes to the register file or flags.
 
     public void setPropertyChangeListener(PropertyChangeListener listener)
     {
         this. = listener;
     }

    
Updates the register file, with a new set of registers.

Parameters:
registers The new register values.
 
     public void updateRegisters(WAMInternalRegisters registers)
     {
         List<PropertyChangeEventchanges = delta(thisregisters);
 
          = registers.ip;
          = registers.hp;
          = registers.hbp;
          = registers.sp;
          = registers.up;
          = registers.ep;
          = registers.bp;
          = registers.b0;
          = registers.trp;
          = registers.writeMode;
 
         notifyChanges(changes);
     }

    
Provides the current instruction pointer into the code.
    public int getIP()
    {
        return ;
    }

    
Provides the heap pointer.
    public int getHP()
    {
        return ;
    }

    
Provides the top of heap at the latest choice point.
    public int getHBP()
    {
        return ;
    }

    
Provides the secondary heap pointer, used for the heap address of the next term to match.
    public int getSP()
    {
        return ;
    }

    
Provides the unification stack pointer.
    public int getUp()
    {
        return ;
    }

    
Provides the environment base pointer.
    public int getEP()
    {
        return ;
    }

    
Provides the choice point base pointer.
    public int getBP()
    {
        return ;
    }

    
Provides the last call choice point pointer.
    public int getB0()
    {
        return ;
    }

    
Provides the trail pointer.
    public int getTRP()
    {
        return ;
    }

    
Provides the write mode flag.
    public boolean getWriteMode()
    {
        return ;
    }

    
    public String[] getRegisterNames()
    {
        return ;
    }

    
    public String[] getFlagNames()
    {
        return ;
    }

    
    public int getRegisterSizeBytes(String name)
    {
        return 4;
    }

    
    public byte[] getRegister(String name)
    {
        return new byte[0];
    }

    
    public boolean getFlag(String name)
    {
        return false;
    }

    
Compares the current register file, with a new set, and creates a list property change notifications for any that have changed value.

Parameters:
newRegisters The new register values.
    private List<PropertyChangeEventdelta(WAMInternalRegisters oldRegistersWAMInternalRegisters newRegisters)
    {
        List<PropertyChangeEventresult = new LinkedList<PropertyChangeEvent>();
        if (oldRegisters.ip != newRegisters.ip)
        {
            result.add(new PropertyChangeEvent(this"IP"oldRegisters.ipnewRegisters.ip));
        }
        if (oldRegisters.hp != newRegisters.hp)
        {
            result.add(new PropertyChangeEvent(this"HP"oldRegisters.hpnewRegisters.hp));
        }
        if (oldRegisters.hbp != newRegisters.hbp)
        {
            result.add(new PropertyChangeEvent(this"HBP"oldRegisters.hbpnewRegisters.hbp));
        }
        if (oldRegisters.sp != newRegisters.sp)
        {
            result.add(new PropertyChangeEvent(this"SP"oldRegisters.spnewRegisters.sp));
        }
        if (oldRegisters.up != newRegisters.up)
        {
            result.add(new PropertyChangeEvent(this"UP"oldRegisters.upnewRegisters.up));
        }
        if (oldRegisters.ep != newRegisters.ep)
        {
            result.add(new PropertyChangeEvent(this"EP"oldRegisters.epnewRegisters.ep));
        }
        if (oldRegisters.bp != newRegisters.bp)
        {
            result.add(new PropertyChangeEvent(this"BP"oldRegisters.bpnewRegisters.bp));
        }
        if (oldRegisters.b0 != newRegisters.b0)
        {
            result.add(new PropertyChangeEvent(this"B0"oldRegisters.b0newRegisters.b0));
        }
        if (oldRegisters.trp != newRegisters.trp)
        {
            result.add(new PropertyChangeEvent(this"TRP"oldRegisters.trpnewRegisters.trp));
        }
        if (oldRegisters.writeMode != newRegisters.writeMode)
        {
            result.add(new PropertyChangeEvent(this"writeMode"oldRegisters.writeModenewRegisters.writeMode));
        }
        return result;
    }

    
Fires off a list of property change events to any interested listeners.

Parameters:
changes The list of property changes to fire off.
    private void notifyChanges(List<PropertyChangeEventchanges)
    {
        if ( != null)
        {
            for (PropertyChangeEvent event : changes)
            {
                .propertyChange(event);
            }
        }
    }
New to GrepCode? Check out our FAQ X