GNU Prolog for Java

gnu.prolog.vm
Class Interpreter

java.lang.Object
  extended by gnu.prolog.vm.Interpreter
All Implemented Interfaces:
HasEnvironment

public final class Interpreter
extends Object
implements HasEnvironment

This class represent interpreter, it should be used only from one thread If you need to use interpreter from two threads, create new interpreter from Environment


Nested Class Summary
static class Interpreter.Goal
          user level calls
 
Field Summary
protected  VariableTerm[] variables
           
protected  int variablesAmount
           
 
Constructor Summary
protected Interpreter(Environment environment)
          this constructor should not be used by client programs
 
Method Summary
 void addSpecialUndo(gnu.prolog.vm.UndoData undoDatum)
          add special undo
 void addVariableUndo(VariableTerm variable)
          add variable undo
 int execute(Interpreter.Goal goal)
          Execute the Interpreter.Goal and return the status code indicating how successful this was.
 Object getContext(String key)
          Deprecated. 
 Environment getEnvironment()
          get environment
 int getExitCode()
          Only call this method if you have had PrologCode.HALT returned by the most recent call to execute(Goal).
 Tracer getTracer()
           
 int getUndoPosition()
          get current undo position
 BacktrackInfo peekBacktrackInfo()
          peek top backtrack information
 BacktrackInfo popBacktrackInfo()
          pop backtrack information
 void popBacktrackInfoUntil(BacktrackInfo cutPoint)
           
 Interpreter.Goal prepareGoal(Term term)
          prepare goal for execution If this is called before the Goal which was previously prepared but has not yet been stopped is stopped then we save that state so we can jump back to it when this goal has been stopped.
 void pushBacktrackInfo(BacktrackInfo bi)
          push backtrack information
 Object putContext(String key, Object contextValue)
          Deprecated. 
 int runOnce(Term goalTerm)
          Run the provided goalTerm once returning the value returned by execute(Goal) and then stop the goal.
 int simpleUnify(Term t1, Term t2)
          unify two terms, no undo done
 void stop(Interpreter.Goal goal)
          Once the goal has been finished with and if the goal has not been stopped (as it will have been if SUCCESS_LAST or FAIL has been returned) then stop(Goal) should be run.
 void undo(int position)
          undo changes until this position
 int unify(Term t1, Term t2)
          unify two terms
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

variables

protected VariableTerm[] variables

variablesAmount

protected int variablesAmount
Constructor Detail

Interpreter

protected Interpreter(Environment environment)
this constructor should not be used by client programs

Parameters:
environment -
Method Detail

getEnvironment

public Environment getEnvironment()
get environment

Specified by:
getEnvironment in interface HasEnvironment

getTracer

public Tracer getTracer()

putContext

@Deprecated
public Object putContext(String key,
                                    Object contextValue)
Deprecated. 


getContext

@Deprecated
public Object getContext(String key)
Deprecated. 


pushBacktrackInfo

public void pushBacktrackInfo(BacktrackInfo bi)
push backtrack information

Parameters:
bi -

popBacktrackInfo

public BacktrackInfo popBacktrackInfo()
pop backtrack information

Returns:
the popped top backtrack information

popBacktrackInfoUntil

public void popBacktrackInfoUntil(BacktrackInfo cutPoint)

peekBacktrackInfo

public BacktrackInfo peekBacktrackInfo()
peek top backtrack information

Returns:
the top backtrack information

getUndoPosition

public int getUndoPosition()
get current undo position

Returns:
the current undo position

undo

public void undo(int position)
undo changes until this position

Parameters:
position -

addVariableUndo

public void addVariableUndo(VariableTerm variable)
add variable undo

Parameters:
variable -

addSpecialUndo

public void addSpecialUndo(gnu.prolog.vm.UndoData undoDatum)
add special undo

Parameters:
undoDatum -

simpleUnify

public int simpleUnify(Term t1,
                       Term t2)
                throws PrologException
unify two terms, no undo done

Parameters:
t1 -
t2 -
Returns:
PrologCode.SUCCESS_LAST or PrologCode.FAIL
Throws:
PrologException

unify

public int unify(Term t1,
                 Term t2)
          throws PrologException
unify two terms

Parameters:
t1 -
t2 -
Returns:
PrologCode.SUCCESS_LAST or PrologCode.FAIL
Throws:
PrologException

prepareGoal

public Interpreter.Goal prepareGoal(Term term)
prepare goal for execution If this is called before the Goal which was previously prepared but has not yet been stopped is stopped then we save that state so we can jump back to it when this goal has been stopped.

Parameters:
term -
Returns:
the prepared Goal

execute

public int execute(Interpreter.Goal goal)
            throws PrologException
Execute the Interpreter.Goal and return the status code indicating how successful this was.

Parameters:
goal - the goal created using prepareGoal(Term) which is to be run.
Returns:
SUCCESS, PrologCode.SUCCESS_LAST , PrologCode.FAIL (or PrologCode.HALT)
Throws:
PrologException

stop

public void stop(Interpreter.Goal goal)
Once the goal has been finished with and if the goal has not been stopped (as it will have been if SUCCESS_LAST or FAIL has been returned) then stop(Goal) should be run.

Parameters:
goal - the goal to stop.

runOnce

public int runOnce(Term goalTerm)
            throws PrologException
Run the provided goalTerm once returning the value returned by execute(Goal) and then stop the goal. This is thus an atomic operation on the Interpreter. Runs prepareGoal(Term) then execute(Goal) then if necessary stop(Goal). Returns the return code from execute(Goal).

Parameters:
goalTerm - the term to be executed
Returns:
PrologCode.SUCCESS, PrologCode.SUCCESS_LAST or PrologCode.FAIL
Throws:
PrologException

getExitCode

public int getExitCode()
Only call this method if you have had PrologCode.HALT returned by the most recent call to execute(Goal). Otherwise and IllegalStateException will be thrown.

Returns:
The exit code when the prolog interpreter was halted

GNU Prolog for Java