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;
 
WAMMachine is an abstract machine capable of handling the WAM language in its compiled form.

CRC Card
Responsibilities Collaborations
Provide symbol table for functors names.
Provide symbol table for variable names.
Accept injected byte code for functors into the machine.
Provide the address of that start offset of code for named functors.

Author(s):
Rupert Smith
 
 public interface WAMMachine extends VariableAndFunctorInterner
 {
    
Provides a call point for the named functor. This method is primarily for use when storing or linking compiled byte code, into its binary form in a machine. The returned call point provides a binary address to use for calls to the specified functor.

Parameters:
functorName The interned name of the functor to get a binary call point for.
Returns:
The call point of the specified functor to call.
 
     WAMCallPoint resolveCallPoint(int functorName);

    
Reserves a forward address referencing a label id, within the current predicate. The forward address will be filled in once the label to which it refers is known. This is done using the resolveLabelPoint(int,int) method.

Parameters:
labelName The interned name of the label to reserve a code address space for.
offset The referenced from offset within the code area to the label.
 
     void reserveReferenceToLabel(int labelNameint offset);

    
Resolves all forward reference to a label id, to a known address. The address of the label is also specified. Once a label address has been resolved by calling this method, any subsequent reference to the label, created with the reserveReferenceToLabel(int,int) method, will immediately resolve onto it. That is to say that, this method only needs to be invoked once for each label.

Parameters:
labelName The interned name of the label to resolve.
address The address of the resolved label.
 
     void resolveLabelPoint(int labelNameint address);

    
Attempts to find a label or functor name for a given address within the code area of the machine.

Parameters:
address The address to look up.
Returns:
The label or functor name matching the address, or null if none is set at that address.
 
     Integer getNameForAddress(int address);

    
Adds compiled byte code to the code area of the machine.

Parameters:
predicate The compiled predicate to add byte code to the machine for.
Throws:
com.thesett.aima.logic.fol.LinkageException If the predicate to be added to the machine, cannot be added to it, because it depends on the existence of other callable predicate heads which are not in the machine. Implementations may elect to raise this as an error at the time the functor is added to the machine, or during execution, or simply to fail to find a solution.
 
     void emmitCode(WAMCompiledPredicate predicatethrows LinkageException;

    
Adds compiled byte code for a query to the code area of the machine.

Parameters:
query The compiled query to add byte code to the machine for.
Throws:
com.thesett.aima.logic.fol.LinkageException If the query to be added to the machine, cannot be added to it, because it depends on the existence of other callable query heads which are not in the machine. Implementations may elect to raise this as an error at the time the functor is added to the machine, or during execution, or simply to fail to find a solution.
    void emmitCode(WAMCompiledQuery querythrows LinkageException;

    
Adds an address into code at a specified offset. This will happen when working with forward references. When code is initially added, a forward reference may not yet reside at a known address, in which case the address can be filled in with a dummy value, and the offset recorded. This can be used to fill in the correct value later.

Parameters:
offset The offset into the code area to write the address.
address The address to fill in.
    void emmitCode(int offsetint address);

    
Extracts the binary byte code from the machine for a given call point.

Parameters:
callPoint The call point giving the location of the code.
Returns:
The byte code at the specified location.
    byte[] retrieveCode(WAMCallPoint callPoint);
New to GrepCode? Check out our FAQ X