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.machine;
 
 import java.util.Map;
 
WAMBaseMachine provides the basic services common to all WAM machines. This consists of managing the interning name tables for functors and variables, and managing the call table for the entry addresses of procedures.

CRC Card
Responsibilities Collaborations
Provide symbol table for functors names.
Provide symbol table for variable names.
Store and retrieve the entry points to byte code procedures.

Author(s):
Rupert Smith
 
 public abstract class WAMBaseMachine extends VariableAndFunctorInternerImpl implements WAMMachineWAMCodeView
 {
    
Used for debugging.
 
     /* private static final Logger log = Logger.getLogger(WAMBaseMachine.class.getName()); */

    
The symbol table key for call points.
 
     protected static final String SYMKEY_CALLPOINTS = "call_points";

    
Holds the symbol table.
 
     protected SymbolTable<IntegerStringObjectsymbolTable;

    
Holds the reverse symbol table to look up names by addresses.
 
     protected Map<IntegerIntegerreverseTable = new HashMap<IntegerInteger>();

    
Creates the base machine, providing variable and functor symbol tables.

Parameters:
symbolTable The symbol table.
 
     protected WAMBaseMachine(SymbolTable<IntegerStringObjectsymbolTable)
     {
         super("WAM_Variable_Namespace""WAM_Functor_Namespace");
         this. = symbolTable;
     }

    
 
     public abstract void emmitCode(WAMCompiledPredicate predicatethrows LinkageException;

    
 
     public abstract void emmitCode(WAMCompiledQuery querythrows LinkageException;

    
 
     public abstract void emmitCode(int offsetint address);

    
Extracts the raw byte code from the machine for a given call table entry.

Parameters:
callPoint The call table entry giving the location and length of the code.
Returns:
The byte code at the specified location.
 
     public abstract byte[] retrieveCode(WAMCallPoint callPoint);

    
Looks up the offset of the start of the code for the named functor.

Parameters:
functorName The interned name of the functor to find the start address of the code for.
Returns:
The call table entry of the functors code within the code area of the machine, or an invalid address if the functor is not known to the machine.
 
     public WAMCallPoint resolveCallPoint(int functorName)
     {
         /*log.fine("public WAMCallPoint resolveCallPoint(int functorName): called");*/
 
         WAMCallPoint result = (WAMCallPoint.get(functorName);
 
         if (result == null)
        {
            result = new WAMCallPoint(-1, 0, functorName);
        }
        return result;
    }

    
    public void reserveReferenceToLabel(int labelNameint offset)
    {
        // Create call point with label name if it does not already exist.
        WAMReservedLabel label = (WAMReservedLabel.get(labelName);
        if (label == null)
        {
            label = new WAMReservedLabel(labelName);
            .put(labelNamelabel);
        }
        // Add to the mapping from the label to referenced from addresses to fill in later.
        label.referenceList.add(offset);
    }

    
    public void resolveLabelPoint(int labelNameint address)
    {
        // Create the label with resolved address, if it does not already exist.
        WAMReservedLabel label = (WAMReservedLabel.get(labelName);
        if (label == null)
        {
            label = new WAMReservedLabel(labelName);
            .put(labelNamelabel);
        }
        label.entryPoint = address;
        // Fill in all references to the label with the correct value. This does nothing if the label was just created.
        for (Integer offset : label.referenceList)
        {
            emmitCode(offsetlabel.entryPoint);
        }
        // Keep a reverse lookup from address to label name.
        .put(addresslabelName);
    }

    
    public Integer getNameForAddress(int address)
    {
        return .get(address);
    }

    
Resets the machine, to its initial state. This should clear any programs from the machine, and clear all of its stacks and heaps.
    public void reset()
    {
        // Clear the entire symbol table.
        .clear();
        .clear();
    }

    
Records the offset of the start of the code for the named functor.

Parameters:
functorName The interned name of the functor to find the start address of the code for.
offset The offset of the start of the functors code within the code area.
length The size of the code to set the address for.
Returns:
The call table entry for the functors code within the code area of the machine.
    protected WAMCallPoint setCodeAddress(int functorNameint offsetint length)
    {
        WAMCallPoint entry = new WAMCallPoint(offsetlengthfunctorName);
        .put(functorNameentry);
        // Keep a reverse lookup from address to functor name.
        .put(offsetfunctorName);
        return entry;
    }
New to GrepCode? Check out our FAQ X