Prolog Cafe v1.2

jp.ac.kobe_u.cs.prolog.lang
Class Prolog

java.lang.Object
  extended by jp.ac.kobe_u.cs.prolog.lang.Prolog
All Implemented Interfaces:
java.io.Serializable

public class Prolog
extends java.lang.Object
implements java.io.Serializable

Prolog engine.

See Also:
Serialized Form

Field Summary
 Term[] aregs
          Argument registers
 int B0
          Cut pointer
protected  boolean bounded
          Not supported yet.
protected  java.lang.String charConversion
          Not supported yet.
 Predicate cont
          Continuation goal register
 PrologControl control
          Prolog thread
protected  java.util.Hashtable<VariableTerm,VariableTerm> copyHash
          Hashtable for creating a copy of term.
protected  long CPFTimeStamp
          Current time stamp of choice point frame
protected  java.io.PushbackReader currentInput
          Current input stream.
protected  java.io.PrintWriter currentOutput
          Current output stream.
protected  java.lang.String debug
          Prolog implementation flag: debug.
protected  java.lang.String doubleQuotes
          Not supported yet.
protected  Term exception
          Holds an exception term for catch/3 and throw/1.
 int exceptionRaised
          Exception level of continuation passing loop: 0 for no exception, 1 for halt/0, 2 for freeze/2 (not supported yet)
protected  HashtableOfTerm hashManager
          Hashtable for managing internal databases.
protected  java.lang.String integerRoundingFunction
          Prolog implementation flag: integer_rounding_function.
 InternalDatabase internalDB
          Internal Database
protected  int maxArity
          Prolog implementation flag: max_arity.
protected  int maxInteger
          Prolog implementation flag: max_integer.
protected  int minInteger
          Prolog implementation flag: min_integer.
static SymbolTerm Nil
          Holds an atom [] (empty list).
 PrologClassLoader pcl
          Class loader
protected  Term pendingGoals
          Holds a list of frozen goals for freeze/2 (not implemented yet).
protected  long previousRuntime
          Holds the previous time as long for statistics/2.
protected  java.lang.String printStackTrace
          Prolog implementation flag: print_stack_trace.
static int PUSHBACK_SIZE
          The size of the pushback buffer used for creating input streams.
 CPFStack stack
          Choice point frame stack
protected  long startRuntime
          Holds the start time as long for statistics/2.
protected  HashtableOfTerm streamManager
          Hashtable for managing input and output streams.
 Trail trail
          Trail stack
protected  java.lang.String unknown
          Prolog implementation flag: unknown.
protected  java.io.PrintWriter userError
          Standard error stream.
protected  java.io.PushbackReader userInput
          Standard input stream.
protected  java.io.PrintWriter userOutput
          Standard output stream.
 
Constructor Summary
Prolog(PrologControl c)
          Constructs new Prolog engine.
 
Method Summary
 Term copy(Term t)
          Returns a copy of term t.
 void cut(int i)
          Discards all choice points after the value of i.
 Predicate fail()
          Do backtrak.
 java.lang.String getCharConversion()
          Returns the value of Prolog implementation flag: char_conversion.
 long getCPFTimeStamp()
          Returns the current time stamp of choice point frame.
 java.io.PushbackReader getCurrentInput()
          Returns the current input stream.
 java.io.PrintWriter getCurrentOutput()
          Returns the current output stream.
 java.lang.String getDebug()
          Returns the value of Prolog implementation flag: debug.
 java.lang.String getDoubleQuotes()
          Returns the value of Prolog implementation flag: double_quotes.
 Term getException()
          Returns the value of exception.
 HashtableOfTerm getHashManager()
          Returns the hash manager.
 java.lang.String getIntegerRoundingFunction()
          Returns the value of Prolog implementation flag: integer_rounding_function.
 int getMaxArity()
          Returns the value of Prolog implementation flag: max_arity.
 int getMaxInteger()
          Returns the value of Prolog implementation flag: max_integer.
 int getMinInteger()
          Returns the value of Prolog implementation flag: min_integer.
 long getPreviousRuntime()
          Returns the value of previousRuntime.
 java.lang.String getPrintStackTrace()
          Returns the value of Prolog implementation flag: print_stack_trace.
 long getStartRuntime()
          Returns the value of startRuntime.
 HashtableOfTerm getStreamManager()
          Returns the stream manager.
 java.lang.String getUnknown()
          Returns the value of Prolog implementation flag: unknown.
 java.io.PrintWriter getUserError()
          Returns the standard error stream.
 java.io.PushbackReader getUserInput()
          Returns the standard input stream.
 java.io.PrintWriter getUserOutput()
          Returns the standard output stream.
 void init()
          Initializes this Prolog engine.
protected  void initOnce()
          Initializes some local instances only once.
 boolean isBounded()
          Returns the value of Prolog implementation flag: bounded.
 Predicate jtry(Predicate p, Predicate next)
          Creates a new choice point frame.
 void neckCut()
          Discards all choice points after the value of B0.
 void restore()
          Restores the argument registers and continuation goal register from the current choice point frame.
 Predicate retry(Predicate p, Predicate next)
          Resets all necessary information from the current choice point frame, updates its next clause field to next, and then returns p.
 void setB0()
          Sets the top of choice porint stack to B0 (cut pointer).
 void setCharConversion(java.lang.String mode)
          Sets the value of Prolog implementation flag: char_conversion.
 void setCurrentInput(java.io.PushbackReader in)
          Sets the current input stream to in.
 void setCurrentOutput(java.io.PrintWriter out)
          Sets the current output stream to out.
 void setDebug(java.lang.String mode)
          Sets the value of Prolog implementation flag: debug.
 void setDoubleQuotes(java.lang.String mode)
          Sets the value of Prolog implementation flag: double_quotes.
 void setException(Term t)
          Sets the value of exception.
 void setPreviousRuntime(long t)
          Sets the value of previousRuntime.
 void setPrintStackTrace(java.lang.String mode)
          Sets the value of Prolog implementation flag: print_stack_trace.
 void setUnknown(java.lang.String mode)
          Sets the value of Prolog implementation flag: unknown.
 Predicate switch_on_hash(java.util.Hashtable<Term,Predicate> hash, Predicate otherwise)
          If the dereferenced value of arugment register areg[1] is an integer, float, atom, or compound term (except for non-empty list), this returns the Predicate object to which its key is mapped in hashtable hash.
 Predicate switch_on_term(Predicate var, Predicate Int, Predicate flo, Predicate con, Predicate str, Predicate lis)
          Returns the Predicate object refered, respectively, var, Int, flo, con, str, or lis, depending on whether the dereferenced value of argument register areg[1] is a variable, integer, float, atom, compound term, or non-empty list, respectively.
 Predicate trust(Predicate p)
          Resets all necessary information from the current choice point frame, discard it, and then returns p.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

control

public PrologControl control
Prolog thread


aregs

public Term[] aregs
Argument registers


cont

public Predicate cont
Continuation goal register


stack

public CPFStack stack
Choice point frame stack


trail

public Trail trail
Trail stack


B0

public int B0
Cut pointer


pcl

public PrologClassLoader pcl
Class loader


internalDB

public InternalDatabase internalDB
Internal Database


CPFTimeStamp

protected long CPFTimeStamp
Current time stamp of choice point frame


exceptionRaised

public int exceptionRaised
Exception level of continuation passing loop:
  • 0 for no exception,
  • 1 for halt/0,
  • 2 for freeze/2 (not supported yet)


  • bounded

    protected boolean bounded
    Not supported yet. Prolog implementation flag: bounded.


    maxInteger

    protected int maxInteger
    Prolog implementation flag: max_integer.


    minInteger

    protected int minInteger
    Prolog implementation flag: min_integer.


    integerRoundingFunction

    protected java.lang.String integerRoundingFunction
    Prolog implementation flag: integer_rounding_function.


    charConversion

    protected java.lang.String charConversion
    Not supported yet. Prolog implementation flag: char_conversion.


    debug

    protected java.lang.String debug
    Prolog implementation flag: debug.


    maxArity

    protected int maxArity
    Prolog implementation flag: max_arity.


    unknown

    protected java.lang.String unknown
    Prolog implementation flag: unknown.


    doubleQuotes

    protected java.lang.String doubleQuotes
    Not supported yet. Prolog implementation flag: double_quotes.


    printStackTrace

    protected java.lang.String printStackTrace
    Prolog implementation flag: print_stack_trace.


    pendingGoals

    protected Term pendingGoals
    Holds a list of frozen goals for freeze/2 (not implemented yet).


    exception

    protected Term exception
    Holds an exception term for catch/3 and throw/1.


    startRuntime

    protected long startRuntime
    Holds the start time as long for statistics/2.


    previousRuntime

    protected long previousRuntime
    Holds the previous time as long for statistics/2.


    copyHash

    protected java.util.Hashtable<VariableTerm,VariableTerm> copyHash
    Hashtable for creating a copy of term.


    PUSHBACK_SIZE

    public static int PUSHBACK_SIZE
    The size of the pushback buffer used for creating input streams.


    userInput

    protected transient java.io.PushbackReader userInput
    Standard input stream.


    userOutput

    protected transient java.io.PrintWriter userOutput
    Standard output stream.


    userError

    protected transient java.io.PrintWriter userError
    Standard error stream.


    currentInput

    protected transient java.io.PushbackReader currentInput
    Current input stream.


    currentOutput

    protected transient java.io.PrintWriter currentOutput
    Current output stream.


    streamManager

    protected HashtableOfTerm streamManager
    Hashtable for managing input and output streams.


    hashManager

    protected HashtableOfTerm hashManager
    Hashtable for managing internal databases.


    Nil

    public static SymbolTerm Nil
    Holds an atom [] (empty list).

    Constructor Detail

    Prolog

    public Prolog(PrologControl c)
    Constructs new Prolog engine.

    Method Detail

    initOnce

    protected void initOnce()
    Initializes some local instances only once. This initOnce method is invoked in the constructor and initializes the following instances:
    • userInput
    • userOutput
    • userError
    • copyHash
    • hashManager
    • streamManager


    init

    public void init()
    Initializes this Prolog engine.


    setB0

    public void setB0()
    Sets the top of choice porint stack to B0 (cut pointer).


    cut

    public void cut(int i)
    Discards all choice points after the value of i.


    neckCut

    public void neckCut()
    Discards all choice points after the value of B0.


    copy

    public Term copy(Term t)
    Returns a copy of term t.

    Parameters:
    t - a term to be copied. It must be dereferenced.

    fail

    public Predicate fail()
    Do backtrak. This method restores the value of B0 and returns the backtrak point in current choice point.


    switch_on_term

    public Predicate switch_on_term(Predicate var,
                                    Predicate Int,
                                    Predicate flo,
                                    Predicate con,
                                    Predicate str,
                                    Predicate lis)
    Returns the Predicate object refered, respectively, var, Int, flo, con, str, or lis, depending on whether the dereferenced value of argument register areg[1] is a variable, integer, float, atom, compound term, or non-empty list, respectively.


    switch_on_hash

    public Predicate switch_on_hash(java.util.Hashtable<Term,Predicate> hash,
                                    Predicate otherwise)
    If the dereferenced value of arugment register areg[1] is an integer, float, atom, or compound term (except for non-empty list), this returns the Predicate object to which its key is mapped in hashtable hash. The key is calculated as follows:
    • integer - itself
    • float - itself
    • atom - itself
    • compound term - functor/arity
    If there is no mapping for the key of areg[1], this returns otherwise.


    restore

    public void restore()
    Restores the argument registers and continuation goal register from the current choice point frame.


    jtry

    public Predicate jtry(Predicate p,
                          Predicate next)
    Creates a new choice point frame.


    retry

    public Predicate retry(Predicate p,
                           Predicate next)
    Resets all necessary information from the current choice point frame, updates its next clause field to next, and then returns p.


    trust

    public Predicate trust(Predicate p)
    Resets all necessary information from the current choice point frame, discard it, and then returns p.


    getCPFTimeStamp

    public long getCPFTimeStamp()
    Returns the current time stamp of choice point frame.


    isBounded

    public boolean isBounded()
    Returns the value of Prolog implementation flag: bounded.


    getMaxInteger

    public int getMaxInteger()
    Returns the value of Prolog implementation flag: max_integer.


    getMinInteger

    public int getMinInteger()
    Returns the value of Prolog implementation flag: min_integer.


    getIntegerRoundingFunction

    public java.lang.String getIntegerRoundingFunction()
    Returns the value of Prolog implementation flag: integer_rounding_function.


    getCharConversion

    public java.lang.String getCharConversion()
    Returns the value of Prolog implementation flag: char_conversion.


    setCharConversion

    public void setCharConversion(java.lang.String mode)
    Sets the value of Prolog implementation flag: char_conversion.


    getDebug

    public java.lang.String getDebug()
    Returns the value of Prolog implementation flag: debug.


    setDebug

    public void setDebug(java.lang.String mode)
    Sets the value of Prolog implementation flag: debug.


    getMaxArity

    public int getMaxArity()
    Returns the value of Prolog implementation flag: max_arity.


    getUnknown

    public java.lang.String getUnknown()
    Returns the value of Prolog implementation flag: unknown.


    setUnknown

    public void setUnknown(java.lang.String mode)
    Sets the value of Prolog implementation flag: unknown.


    getDoubleQuotes

    public java.lang.String getDoubleQuotes()
    Returns the value of Prolog implementation flag: double_quotes.


    setDoubleQuotes

    public void setDoubleQuotes(java.lang.String mode)
    Sets the value of Prolog implementation flag: double_quotes.


    getPrintStackTrace

    public java.lang.String getPrintStackTrace()
    Returns the value of Prolog implementation flag: print_stack_trace.


    setPrintStackTrace

    public void setPrintStackTrace(java.lang.String mode)
    Sets the value of Prolog implementation flag: print_stack_trace.


    getException

    public Term getException()
    Returns the value of exception. This is used in catch/3.


    setException

    public void setException(Term t)
    Sets the value of exception. This is used in throw/1.


    getStartRuntime

    public long getStartRuntime()
    Returns the value of startRuntime. This is used in statistics/2.


    getPreviousRuntime

    public long getPreviousRuntime()
    Returns the value of previousRuntime. This is used in statistics/2.


    setPreviousRuntime

    public void setPreviousRuntime(long t)
    Sets the value of previousRuntime. This is used in statistics/2.


    getUserInput

    public java.io.PushbackReader getUserInput()
    Returns the standard input stream.


    getUserOutput

    public java.io.PrintWriter getUserOutput()
    Returns the standard output stream.


    getUserError

    public java.io.PrintWriter getUserError()
    Returns the standard error stream.


    getCurrentInput

    public java.io.PushbackReader getCurrentInput()
    Returns the current input stream.


    setCurrentInput

    public void setCurrentInput(java.io.PushbackReader in)
    Sets the current input stream to in.


    getCurrentOutput

    public java.io.PrintWriter getCurrentOutput()
    Returns the current output stream.


    setCurrentOutput

    public void setCurrentOutput(java.io.PrintWriter out)
    Sets the current output stream to out.


    getStreamManager

    public HashtableOfTerm getStreamManager()
    Returns the stream manager.


    getHashManager

    public HashtableOfTerm getHashManager()
    Returns the hash manager.


    Prolog Cafe v1.2

    Copyright (C) 1997-2008 M.BANBARA and N.TAMURA