jpl stuff
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1120 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
803a4b04eb
commit
be83a4a309
97
LGPL/JPL/java/Makefile.in
Normal file
97
LGPL/JPL/java/Makefile.in
Normal file
@ -0,0 +1,97 @@
|
||||
################################################################
|
||||
# Build jpl.jar
|
||||
################################################################
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
#
|
||||
# default base directory for YAP installation
|
||||
#
|
||||
ROOTDIR = @prefix@
|
||||
#
|
||||
# where the binary should be
|
||||
#
|
||||
BINDIR = $(ROOTDIR)/bin
|
||||
#
|
||||
# where YAP should look for binary libraries
|
||||
#
|
||||
LIBDIR=$(ROOTDIR)/lib/Yap
|
||||
#
|
||||
# where YAP should look for architecture-independent Prolog libraries
|
||||
#
|
||||
SHAREDIR=$(ROOTDIR)/share
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
#
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
SHELL=/bin/sh
|
||||
RANLIB=@RANLIB@
|
||||
srcdir=@srcdir@
|
||||
SHLIB_CFLAGS=@SHLIB_CFLAGS@
|
||||
SHLIB_SUFFIX=@SHLIB_SUFFIX@
|
||||
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
|
||||
CWD=$(PWD)
|
||||
#
|
||||
JAVAC=@JAVAC@
|
||||
JAR=@JAR@
|
||||
JPL=jpl.jar
|
||||
|
||||
CLS= jpl/Atom.java \
|
||||
jpl/Compound.java \
|
||||
jpl/Float.java \
|
||||
jpl/Integer.java \
|
||||
jpl/JBoolean.java \
|
||||
jpl/JPLException.java \
|
||||
jpl/JPL.java \
|
||||
jpl/JRef.java \
|
||||
jpl/JVoid.java \
|
||||
jpl/PrologException.java \
|
||||
jpl/Query.java \
|
||||
jpl/Term.java \
|
||||
jpl/Util.java \
|
||||
jpl/Variable.java \
|
||||
jpl/Version.java
|
||||
|
||||
FLI= jpl/fli/atom_t.java \
|
||||
jpl/fli/BooleanHolder.java \
|
||||
jpl/fli/DoubleHolder.java \
|
||||
jpl/fli/engine_t.java \
|
||||
jpl/fli/fid_t.java \
|
||||
jpl/fli/functor_t.java \
|
||||
jpl/fli/IntHolder.java \
|
||||
jpl/fli/LongHolder.java \
|
||||
jpl/fli/module_t.java \
|
||||
jpl/fli/ObjectHolder.java \
|
||||
jpl/fli/PointerHolder.java \
|
||||
jpl/fli/predicate_t.java \
|
||||
jpl/fli/Prolog.java \
|
||||
jpl/fli/qid_t.java \
|
||||
jpl/fli/StringHolder.java \
|
||||
jpl/fli/term_t.java
|
||||
|
||||
|
||||
JAVA=$(CLS) $(FLI)
|
||||
CLASSES=$(JAVA:.java=.class)
|
||||
|
||||
all: $(JPL)
|
||||
|
||||
$(JAVA):
|
||||
-@ ( cd jpl ; @LN_S@ ../$(srcdir)/jpl/*.java .)
|
||||
-@ ( cd jpl/fli ; @LN_S@ ../../$(srcdir)/jpl/fli/*.java .)
|
||||
|
||||
$(JPL): $(JAVA)
|
||||
$(JAVAC) $(JAVA)
|
||||
$(JAR) cf $(JPL) $(CLASSES)
|
||||
|
||||
clean::
|
||||
rm -f *~ $(CLASSES)
|
||||
|
||||
distclean: clean
|
||||
rm -r $(JPL)
|
||||
install: $(JPL)
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap
|
||||
$(INSTALL_DATA) $(JPL) $(DESTDIR)$(SHAREDIR)/Yap
|
||||
|
157
LGPL/JPL/java/jpl/Atom.java
Normal file
157
LGPL/JPL/java/jpl/Atom.java
Normal file
@ -0,0 +1,157 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Atom.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.StringHolder;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Atom
|
||||
/**
|
||||
* Atom is a specialised Compound with zero arguments, representing a Prolog atom with the same name.
|
||||
* An Atom is constructed with a String parameter (its name, unquoted), which cannot thereafter be changed.
|
||||
* <pre>Atom a = new Atom("hello");</pre>
|
||||
* An Atom can be used (and re-used) as an argument of Compound Terms.
|
||||
* Two Atom instances are equal (by equals()) iff they have equal names.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Compound
|
||||
*/
|
||||
public class Atom extends Compound {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes (none)
|
||||
//==================================================================/
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* @param name the Atom's name (unquoted)
|
||||
*/
|
||||
public Atom(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
// these are all inherited from Compound
|
||||
|
||||
public final int type() {
|
||||
return Prolog.ATOM;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly String representation of an Atom.
|
||||
*
|
||||
* @return a debug-friendly String representation of an Atom
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(Atom " + toString() + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
// (this is done with the put() method inherited from Compound)
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a Prolog term to a JPL Atom. This is only called from Term.getTerm(),
|
||||
* and we can assume the term_t refers to a Prolog atom,
|
||||
* so we just create a new Atom object with the atom's name.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
* @param term The Prolog term to be converted
|
||||
* @return A new Atom instance
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
StringHolder holder = new StringHolder();
|
||||
Prolog.get_atom_chars(term, holder); // ignore return val; assume success...
|
||||
|
||||
return new Atom(holder.value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a term_t to an Atom, knowing that it refers to a SWI-Prolog string,
|
||||
* so we just create a new Atom object initialised with the string's value.
|
||||
* JPL users should avoid SWI-Prolog's non-ISO strings, but in some obscure
|
||||
* circumstances they are returned unavoidably, so we have to handle them
|
||||
* (and this is how).
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
* @param term The term_t to convert
|
||||
* @return A new Atom instance
|
||||
*/
|
||||
protected static Term getString(Map vars_to_Vars, term_t term) {
|
||||
StringHolder holder = new StringHolder();
|
||||
Prolog.get_string_chars(term, holder); // ignore return val; assume success...
|
||||
// System.err.println("Warning: Prolog returns a string: \"" + holder.value + "\"");
|
||||
return new Atom(holder.value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing substitutions
|
||||
//==================================================================/
|
||||
|
||||
// (done with the inherited Compound.getSubst() method)
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
324
LGPL/JPL/java/jpl/Compound.java
Normal file
324
LGPL/JPL/java/jpl/Compound.java
Normal file
@ -0,0 +1,324 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Compound.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.IntHolder;
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.StringHolder;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Compound
|
||||
/**
|
||||
* A Compound represents a structured term,
|
||||
* comprising a functor and arguments (Terms).
|
||||
* Atom is a subclass of Compound, whose instances have zero arguments.
|
||||
* Direct instances of Compound must have one or more arguments
|
||||
* (it is an error to attempt to construct a Compound with zero args;
|
||||
* a JPLException will be thrown).
|
||||
* For example, this Java expression yields
|
||||
* a representation of the term f(a):
|
||||
* <pre>
|
||||
* new Compound( "f", new Term[] { new Atom("a") } )
|
||||
* </pre>
|
||||
* Note the use of the "anonymous array" notation to denote the arguments
|
||||
* (an anonymous array of Term).
|
||||
* <br>
|
||||
* Alternatively, construct the Term from Prolog source syntax:
|
||||
* <pre>
|
||||
* Util.textToTerm("f(a)")
|
||||
* </pre>
|
||||
* The <i>arity</i> of a Compound is the quantity of its arguments.
|
||||
* Once constructed, neither the name, arity nor any argument of a Compound can be altered.
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Atom
|
||||
*/
|
||||
public class Compound extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* the name of this Compound
|
||||
*/
|
||||
protected final String name;
|
||||
|
||||
/**
|
||||
* the arguments of this Compound
|
||||
*/
|
||||
protected final Term[] args;
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Creates a Compound with name but no args (i.e. an Atom).
|
||||
*
|
||||
* @param name the name of this Compound
|
||||
* @param args the arguments of this Compound
|
||||
*/
|
||||
protected Compound(String name) {
|
||||
if (name == null) {
|
||||
throw new JPLException("jpl.Atom: cannot construct with null name");
|
||||
}
|
||||
this.name = name;
|
||||
this.args = new Term[] {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a Compound with name and args.
|
||||
*
|
||||
* @param name the name of this Compound
|
||||
* @param args the arguments of this Compound
|
||||
*/
|
||||
public Compound(String name, Term[] args) {
|
||||
if (name == null) {
|
||||
throw new JPLException("jpl.Compound: cannot construct with null name");
|
||||
}
|
||||
if (args == null) {
|
||||
throw new JPLException("jpl.Compound: cannot construct with null args");
|
||||
}
|
||||
if (args.length == 0) {
|
||||
throw new JPLException("jpl.Compound: cannot construct with zero args");
|
||||
}
|
||||
this.name = name;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns the ith argument (counting from 1) of this Compound;
|
||||
* throws an ArrayIndexOutOfBoundsException if i is inappropriate.
|
||||
*
|
||||
* @return the ith argument (counting from 1) of this Compound
|
||||
*/
|
||||
public final Term arg(int i) {
|
||||
return args[i - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this Compound's functor has (String) 'name' and 'arity'.
|
||||
*
|
||||
* @return whether this Compound's functor has (String) 'name' and 'arity'
|
||||
*/
|
||||
public final boolean hasFunctor(String name, int arity) {
|
||||
return name.equals(name) && arity == args.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name (unquoted) of this Compound.
|
||||
*
|
||||
* @return the name (unquoted) of this Compound
|
||||
*/
|
||||
public final String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arity (1+) of this Compound.
|
||||
*
|
||||
* @return the arity (1+) of this Compound
|
||||
*/
|
||||
public final int arity() {
|
||||
return args.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a prefix functional representation of a Compound of the form name(arg1,...),
|
||||
* where each argument is represented according to its toString() method.
|
||||
* <br>
|
||||
* NB 'name' should be quoted iff necessary, and Term.toString(Term[]) is not
|
||||
* really a Term method, more a utility...
|
||||
*
|
||||
* @return string representation of an Compound
|
||||
*/
|
||||
public String toString() {
|
||||
return quotedName() + (args.length > 0 ? "(" + Term.toString(args) + ")" : "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Two Compounds are equal if they are identical (same object) or their names and arities are equal and their
|
||||
* respective arguments are equal.
|
||||
*
|
||||
* @param obj the Object to compare (not necessarily another Compound)
|
||||
* @return true if the Object satisfies the above condition
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return (this == obj || (obj instanceof Compound && name.equals(((Compound) obj).name) && Term.terms_equals(args, ((Compound) obj).args)));
|
||||
}
|
||||
|
||||
public int type() {
|
||||
return Prolog.COMPOUND;
|
||||
}
|
||||
|
||||
public String typeName(){
|
||||
return "Compound";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (protected)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns a quoted (iff necessary) form of the Atom's name, as understood by Prolog read/1
|
||||
*
|
||||
* @return a quoted form of the Atom's name, as understood by Prolog read/1
|
||||
*/
|
||||
protected String quotedName() {
|
||||
return ((Atom) (new Query(new Compound("sformat", new Term[] { new Variable("S"), new Atom("~q"), new Compound(".", new Term[] { new Atom(this.name), new Atom("[]")})
|
||||
})))
|
||||
.oneSolution()
|
||||
.get(
|
||||
"S")).name;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns the arguments of this Compound.
|
||||
*
|
||||
* @return the arguments of this Compound
|
||||
* @deprecated
|
||||
*/
|
||||
public final Term[] args() {
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ith argument (counting from 0) of this Compound.
|
||||
*
|
||||
* @return the ith argument (counting from 0) of this Compound
|
||||
* @deprecated
|
||||
*/
|
||||
public final Term arg0(int i) {
|
||||
return args[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of a Compound.
|
||||
*
|
||||
* @return a debug-friendly representation of a Compound
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(Compound " + name + " " + Term.debugString(args) + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To put a Compound in a term, we create a sequence of term_t
|
||||
* references from the Term.terms_to_term_ts() method, and then
|
||||
* use the Prolog.cons_functor_v() method to create a Prolog compound
|
||||
* term.
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables
|
||||
* @param term A (previously created) term_t which is to be
|
||||
* set to a Prolog term corresponding to the Term subtype
|
||||
* (Atom, Variable, Compound, etc.) on which the method is invoked.
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
|
||||
Prolog.cons_functor_v(term, Prolog.new_functor(Prolog.new_atom(name), args.length), Term.putTerms(varnames_to_vars, args));
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts the Prolog term in term_t (known to be a compound) to a JPL Compound.
|
||||
* In this case, we create a list of Terms by calling Term.getTerm for each
|
||||
* term_t reference we get from Prolog.get_arg
|
||||
* (Not sure why we couldn't get a sequence from there, but...).<p>
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables
|
||||
* @param term The Prolog term to convert
|
||||
* @return A new Compound
|
||||
*/
|
||||
protected static Term getTerm(Map varnames_to_vars, term_t term) {
|
||||
|
||||
// we need holders to get the term's name and arity back from the FLI:
|
||||
StringHolder name_holder = new StringHolder();
|
||||
IntHolder arity_holder = new IntHolder();
|
||||
Prolog.get_name_arity(term, name_holder, arity_holder); // assume it succeeds
|
||||
|
||||
Term args[] = new Term[arity_holder.value];
|
||||
for (int i = 1; i <= arity_holder.value; i++) {
|
||||
term_t termi = Prolog.new_term_ref();
|
||||
Prolog.get_arg(i, term, termi);
|
||||
args[i - 1] = Term.getTerm(varnames_to_vars, termi);
|
||||
}
|
||||
return new Compound(name_holder.value, args);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Nothing needs to be done except to pass the buck to this Compound's args.
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to JPL Terms
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
Term.getSubsts(varnames_to_Terms, vars_to_Vars, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
295
LGPL/JPL/java/jpl/Float.java
Normal file
295
LGPL/JPL/java/jpl/Float.java
Normal file
@ -0,0 +1,295 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Float.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.DoubleHolder;
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Float
|
||||
/**
|
||||
* Float is a specialised Term with a double field, representing a Prolog 64-bit ISO/IEC floating point value.
|
||||
* Once constructed, a Float's value cannot be altered.
|
||||
* <pre>
|
||||
* Float f = new Float( 3.14159265 );
|
||||
* </pre>
|
||||
* A Float can be used (and re-used) in Compound Terms.
|
||||
* Two Float instances are equal (by .equals()) iff their (double) values are equal.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Compound
|
||||
*/
|
||||
public class Float extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* the Float's immutable value
|
||||
*/
|
||||
protected final double value;
|
||||
|
||||
//==================================================================/
|
||||
// Constructors and Initialization
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* This constructor creates a Float with the supplied
|
||||
* (double) value.
|
||||
*
|
||||
* @param value this Float's value
|
||||
*/
|
||||
public Float(double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* throws a JPLException (arg(int) is defined only for Compound and Atom)
|
||||
*
|
||||
* @return the ith argument (counting from 1) of this Float (never)
|
||||
*/
|
||||
public final Term arg(int i) {
|
||||
throw new JPLException("jpl.Float.arg(int) is undefined");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this Float's functor has (String) 'name' and 'arity' (never)
|
||||
*
|
||||
* @return whether this Float's functor has (String) 'name' and 'arity' (never)
|
||||
*/
|
||||
public final boolean hasFunctor(String name, int arity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this Float's functor has (int) 'name' and 'arity' (never)
|
||||
*
|
||||
* @return whether this Float's functor has (int) 'name' and 'arity' (never)
|
||||
*/
|
||||
public final boolean hasFunctor(int val, int arity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this Float's functor has (double) 'name' and 'arity'
|
||||
*
|
||||
* @return whether this Float's functor has (double) 'name' and 'arity'
|
||||
*/
|
||||
public final boolean hasFunctor(double val, int arity) {
|
||||
return val == this.value && arity == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* throws a JPLException (name() is defined only for Compound, Atom and Variable)
|
||||
*
|
||||
* @return the name of this Float (never)
|
||||
*/
|
||||
public final String name() {
|
||||
throw new JPLException("jpl.Float.name() is undefined");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arity (0) of this Float
|
||||
*
|
||||
* @return the arity (0) of this Float
|
||||
*/
|
||||
public final int arity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the (double) value of this Float, converted to an int
|
||||
*
|
||||
* @return the (double) value of this Float, converted to an int
|
||||
*/
|
||||
public final int intValue() {
|
||||
return (new Double(value)).intValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the (double) value of this Float, converted to a long
|
||||
*
|
||||
* @return the (double) value of this Float, converted to a long
|
||||
*/
|
||||
public final long longValue() {
|
||||
return (new Double(value)).longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the (double) value of this Float, converted to a float
|
||||
*
|
||||
* @return the (double) value of this Float, converted to a float
|
||||
*/
|
||||
public final float floatValue() {
|
||||
return (new Double(value)).floatValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the (double) value of this Float
|
||||
*
|
||||
* @return the (double) value of this Float
|
||||
*/
|
||||
public final double doubleValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Prolog source text representation of this Float
|
||||
*
|
||||
* @return a Prolog source text representation of this Float
|
||||
*/
|
||||
public String toString() {
|
||||
return "" + value + "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Two Floats are equal if they are the same object, or their values are equal
|
||||
*
|
||||
* @param obj The Object to compare
|
||||
* @return true if the Object satisfies the above condition
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return this == obj || (obj instanceof Float && value == ((Float) obj).value);
|
||||
}
|
||||
|
||||
public final int type() {
|
||||
return Prolog.FLOAT;
|
||||
}
|
||||
|
||||
public String typeName(){
|
||||
return "Float";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The (nonexistent) args of this Float
|
||||
*
|
||||
* @return the (nonexistent) args of this Float
|
||||
* @deprecated
|
||||
*/
|
||||
public Term[] args() {
|
||||
return new Term[] {};
|
||||
}
|
||||
|
||||
/**
|
||||
* The immutable value of this jpl.Float object, as a Java double
|
||||
*
|
||||
* @return the Float's value
|
||||
* @deprecated
|
||||
*/
|
||||
public double value() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly String representation of this Float
|
||||
*
|
||||
* @return a debug-friendly String representation of this Float
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(Float " + toString() + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To convert a JPL Float to a Prolog term, we put its value field into the
|
||||
* term_t as a float.
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables.
|
||||
* @param term A (previously created) term_t which is to be
|
||||
* set to a Prolog float corresponding to this Float's value
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
Prolog.put_float(term, value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a Prolog term (known to be a float) to a JPL Float.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables
|
||||
* @param term The Prolog term (a float) to convert
|
||||
* @return A new Float instance
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
DoubleHolder double_holder = new DoubleHolder();
|
||||
|
||||
Prolog.get_float(term, double_holder); // assume it succeeds...
|
||||
return new jpl.Float(double_holder.value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Nothing needs to be done if the Term is an Atom, Integer or (as in this case) a Float
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to JPL Terms
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
269
LGPL/JPL/java/jpl/Integer.java
Normal file
269
LGPL/JPL/java/jpl/Integer.java
Normal file
@ -0,0 +1,269 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Integer.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.IntHolder;
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Integer
|
||||
/**
|
||||
* Integer is a specialised Term with a long field, representing a Prolog integer value.
|
||||
* <pre>
|
||||
* Integer i = new Integer(1024);
|
||||
* </pre>
|
||||
* Once constructed, the value of an Integer instance cannot be altered.
|
||||
* An Integer can be used (and re-used) as an argument of Compounds.
|
||||
* Beware confusing jpl.Integer with java.lang.Integer.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Compound
|
||||
*/
|
||||
public class Integer extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* the Integer's immutable long value
|
||||
*/
|
||||
protected final long value;
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* @param value This Integer's (long) value
|
||||
*/
|
||||
public Integer(long value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value This Integer's (int) value
|
||||
*/
|
||||
public Integer(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Tests whether this Integer's functor has (int) 'name' and 'arity'
|
||||
*
|
||||
* @return whether this Integer's functor has (int) 'name' and 'arity'
|
||||
*/
|
||||
public final boolean hasFunctor(int val, int arity) {
|
||||
return val == this.value && arity == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the arity (0) of this jpl.Integer
|
||||
*
|
||||
* @return the arity (0) of this jpl.Integer
|
||||
*/
|
||||
public final int arity() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this Integer as an int if possible, else throws exception
|
||||
*
|
||||
* @return the int value of this Integer (if representable)
|
||||
*/
|
||||
public final int intValue() {
|
||||
if (value < java.lang.Integer.MIN_VALUE || value > java.lang.Integer.MAX_VALUE) {
|
||||
throw new JPLException("cannot represent Integer value as an int");
|
||||
} else {
|
||||
return (int) value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this Integer converted to a long
|
||||
*
|
||||
* @return the value of this Integer converted to a long
|
||||
*/
|
||||
public final long longValue() {
|
||||
return (new java.lang.Long(value)).longValue(); // safe but inefficient...
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this Integer converted to a float
|
||||
*
|
||||
* @return the value of this Integer converted to a float
|
||||
*/
|
||||
public final float floatValue() {
|
||||
return (new java.lang.Long(value)).floatValue(); // safe but inefficient...
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this Integer converted to a double
|
||||
*
|
||||
* @return the value of this Integer converted to a double
|
||||
*/
|
||||
public final double doubleValue() {
|
||||
return (new java.lang.Long(value)).doubleValue(); // safe but inefficient...
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Prolog source text representation of this Integer's value
|
||||
*
|
||||
* @return a Prolog source text representation of this Integer's value
|
||||
*/
|
||||
public String toString() {
|
||||
return "" + value + ""; // hopefully invokes Integer.toString() or equivalent
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// equals
|
||||
/**
|
||||
* Two Integer instances are equal if they are the same object, or if their values are equal
|
||||
*
|
||||
* @param obj The Object to compare (not necessarily an Integer)
|
||||
* @return true if the Object satisfies the above condition
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return this == obj || (obj instanceof Integer && value == ((Integer) obj).value);
|
||||
}
|
||||
|
||||
public final int type() {
|
||||
return Prolog.INTEGER;
|
||||
}
|
||||
|
||||
public String typeName(){
|
||||
return "Integer";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns the int value of this jpl.Integer
|
||||
*
|
||||
* @return the Integer's value
|
||||
* @deprecated
|
||||
*/
|
||||
public final int value() {
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* The (nonexistent) args of this Integer
|
||||
*
|
||||
* @return the (nonexistent) args of this Integer
|
||||
* @deprecated
|
||||
*/
|
||||
public Term[] args() {
|
||||
return new Term[] {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of this Integer's value
|
||||
*
|
||||
* @return a debug-friendly representation of this Integer's value
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(Integer " + toString() + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To convert an Integer into a Prolog term, we put its value into the term_t.
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables.
|
||||
* @param term A (previously created) term_t which is to be
|
||||
* set to a Prolog integer
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
Prolog.put_integer(term, value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a Prolog term (known to be an integer) to a new Integer instance.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables
|
||||
* @param term The Prolog term (an integer) which is to be converted
|
||||
* @return A new Integer instance
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
IntHolder int_holder = new IntHolder();
|
||||
|
||||
Prolog.get_integer(term, int_holder); // assume it succeeds...
|
||||
return new jpl.Integer(int_holder.value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Nothing needs to be done if the Term is an Atom, Integer or Float
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to Terms.
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
217
LGPL/JPL/java/jpl/JBoolean.java
Normal file
217
LGPL/JPL/java/jpl/JBoolean.java
Normal file
@ -0,0 +1,217 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: JBoolean.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.BooleanHolder;
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// JBoolean
|
||||
/**
|
||||
* A jpl.JBoolean is a specialised Term with a boolean field, representing JPL's Prolog representation of a Java boolean value.
|
||||
* <pre>
|
||||
* JBoolean b = new JBoolean( true or false );
|
||||
* </pre>
|
||||
* A JBoolean can be used (and re-used) in Compound Terms.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Compound
|
||||
*/
|
||||
public class JBoolean extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* the JBoolean's value (a boolean)
|
||||
*/
|
||||
protected final boolean value;
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Constructs a JBoolean with the supplied boolean value.
|
||||
*
|
||||
* @param b this JBoolean's value (a boolean)
|
||||
*/
|
||||
public JBoolean(boolean b) {
|
||||
this.value = b;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Tests whether this JBoolean's functor has (String) 'name' and 'arity'
|
||||
*
|
||||
* @return whether this JBoolean's functor has (String) 'name' and 'arity'
|
||||
*/
|
||||
public final boolean hasFunctor(String name, int arity) {
|
||||
return name.equals("@") && arity==1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Prolog source text representation of this JBoolean
|
||||
*
|
||||
* @return a Prolog source text representation of this JBoolean
|
||||
*/
|
||||
public String toString() {
|
||||
return (value ? "@(true)" : "@(false)");
|
||||
}
|
||||
|
||||
/**
|
||||
* Two JBooleans are equal if their values are equal
|
||||
*
|
||||
* @param obj The Object to compare (not necessarily a JBoolean)
|
||||
* @return true if the Object satisfies the above condition
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return this == obj || (obj instanceof JBoolean && value == ((JBoolean) obj).value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (peculiar)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The boolean value which this jpl.JBoolean object represents
|
||||
*
|
||||
* @return the boolean value which this jpl.JBoolean object represents
|
||||
*/
|
||||
public boolean boolValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public final int type() {
|
||||
return Prolog.JBOOLEAN;
|
||||
}
|
||||
|
||||
public String typeName(){
|
||||
return "JBoolean";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The (nonexistent) args of this JBoolean
|
||||
*
|
||||
* @return the (nonexistent) args of this JBoolean
|
||||
* @deprecated
|
||||
*/
|
||||
public Term[] args() {
|
||||
throw new JPLException("jpl.JBoolean.args() is undefined");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of this JBoolean
|
||||
*
|
||||
* @return a debug-friendly representation of this JBoolean
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(JBoolean " + toString() + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To convert a JBoolean to a term, we unify the (freshly created, hence unbound)
|
||||
* term_t with either @(false) or @(true) as appropriate.
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables.
|
||||
* @param term A (newly created) term_t which is to be
|
||||
* set to a Prolog @(false) or @(true) structure denoting the
|
||||
* .value of this JBoolean instance
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
Prolog.put_jboolean(term, value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a term_t to a JBoolean. If the Prolog term is either
|
||||
* @(false) or @(true), we just create a new JBoolean with a corresponding value.
|
||||
* NB This conversion is only invoked if "JPL-aware" term import is specified.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variable to JPL Variables.
|
||||
* @param term The term (either @(false) or @(true)) to convert
|
||||
* @return A new JBoolean instance
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
BooleanHolder b = new BooleanHolder();
|
||||
|
||||
Prolog.get_jboolean(term, b); // assume it succeeds...
|
||||
return new jpl.JBoolean(b.value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Nothing needs to be done if the Term denotes an Atom, Integer, Float, JRef or JBoolean
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to Terms.
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
199
LGPL/JPL/java/jpl/JPL.java
Normal file
199
LGPL/JPL/java/jpl/JPL.java
Normal file
@ -0,0 +1,199 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: JPL.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import jpl.fli.Prolog;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// JPL
|
||||
/**
|
||||
* The jpl.JPL class contains methods which allow (i) inspection and alteration
|
||||
* of the "default" initialisation arguments (ii) explicit initialisation
|
||||
* (iii) discovery of whether the Prolog engine is already initialised,
|
||||
* and if so, with what arguments.
|
||||
* The Prolog engine must be initialized
|
||||
* before any queries are made, but this will happen automatically
|
||||
* (upon the first call to a Prolog FLI routine) if it has not already
|
||||
* been done explicitly.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public class JPL {
|
||||
protected static final boolean DEBUG = false;
|
||||
|
||||
protected static boolean modeDontTellMe = true;
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// setDTMMode
|
||||
/**
|
||||
* Sets the global "dont-tell-me" mode (default value: true).
|
||||
* When 'true', bindings will *not* be returned for any variable (in a Query's goal)
|
||||
* whose name begins with an underscore character (except for "anonymous" variables,
|
||||
* i.e. those whose name comprises just the underscore character, whose bindings are never returned).
|
||||
* When 'false', bindings are returned for *all* variables except anonymous ones;
|
||||
* this mode may be useful when traditional top-level interpreter behaviour is wanted,
|
||||
* e.g. in a Java-based Prolog IDE or debugger.<p>
|
||||
* This method should be regarded as experimental, and may subsequently be deprecated
|
||||
* in favour of some more general mechanism for setting options, perhaps per-Query and
|
||||
* per-call as well as globally.
|
||||
*
|
||||
* @param dtm new "dont-tell-me" mode value
|
||||
*/
|
||||
public static void setDTMMode( boolean dtm){
|
||||
modeDontTellMe = dtm;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// getDefaultInitArgs
|
||||
/**
|
||||
* Returns, in an array of String, the sequence of command-line
|
||||
* arguments that would be used if the Prolog engine were to be initialised now.
|
||||
* Returns null if the Prolog VM has already been initialised (in which
|
||||
* case the default init args are irrelevant and the actual init args are of interest)<p>
|
||||
*
|
||||
* @see jpl.JPL#getActualInitArgs
|
||||
* @return current default initialisation arguments, or null if already initialised
|
||||
*/
|
||||
public static String[] getDefaultInitArgs() {
|
||||
return Prolog.get_default_init_args();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// setDefaultInitArgs
|
||||
/**
|
||||
* Specifies, in an array of String, the sequence of command-line
|
||||
* arguments that should be used if the Prolog engine is subsequently initialised.<p>
|
||||
*
|
||||
* @param args new default initialization arguments
|
||||
*/
|
||||
public static void setDefaultInitArgs(String[] args) {
|
||||
Prolog.set_default_init_args(args);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// getActualInitArgs
|
||||
/**
|
||||
* Returns, in an array of String, the sequence of command-line
|
||||
* arguments that were actually used when the Prolog engine was formerly initialised.
|
||||
*
|
||||
* This method returns null if the Prolog engine has not yet been initialised,
|
||||
* and thus may be used to test this condition.
|
||||
*
|
||||
* @return actual initialization arguments
|
||||
*/
|
||||
public static String[] getActualInitArgs() {
|
||||
return Prolog.get_actual_init_args();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// init
|
||||
/**
|
||||
* Initializes the Prolog engine, using the String argument
|
||||
* parameters passed. This method need be called only if you want to both
|
||||
* (i) initialise the Prolog engine with parameters other than the default ones
|
||||
* and (ii) force initialisation to occur
|
||||
* (rather than allow it to occur automatically at the first query).
|
||||
* For parameter options, consult your local
|
||||
* Prolog documentation. The parameter values are passed directly
|
||||
* to initialization routines for the Prolog environment.<p>
|
||||
*
|
||||
* This method must be called before making any queries.
|
||||
*
|
||||
* @param args Initialization parameter list
|
||||
*/
|
||||
public static boolean init(String[] args) {
|
||||
return Prolog.set_default_init_args(args) && init();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// init
|
||||
/**
|
||||
* Initialises the Prolog engine using the current default initialisation parameters,
|
||||
* and returns 'true' (or 'false' if already initialised).
|
||||
*/
|
||||
public static boolean init() {
|
||||
return Prolog.initialise();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// halt
|
||||
/**
|
||||
* Terminates the Prolog session.<p>
|
||||
*
|
||||
* <b>Note.</b> This method calls the FLI halt() method with a
|
||||
* status of 0, but the halt method currently is a no-op in SWI.
|
||||
* @deprecated
|
||||
*/
|
||||
public static void halt() {
|
||||
Prolog.halt(0);
|
||||
}
|
||||
|
||||
// a static reference to the current Version
|
||||
private static final Version version_ = new Version();
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// version
|
||||
/**
|
||||
* Returns (as a Version) an identification of this version of JPL.
|
||||
* @return the running version of JPL.
|
||||
*/
|
||||
public static Version version() {
|
||||
return version_;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// version_string
|
||||
/**
|
||||
* Returns a String (eg "3.0.0-alpha") identifying this version of JPL.
|
||||
* @return a String (eg "3.0.0-alpha") identifying this version of JPL.
|
||||
*/
|
||||
public static String version_string() {
|
||||
return version_.major + "." + version_.minor + "." + version_.patch + "-" + version_.status;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(version_string());
|
||||
}
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
61
LGPL/JPL/java/jpl/JPLException.java
Normal file
61
LGPL/JPL/java/jpl/JPLException.java
Normal file
@ -0,0 +1,61 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: JPLException.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// JPLException
|
||||
/**
|
||||
* This is the base class for exceptions thrown by JPL's Java-calls-Prolog interface.
|
||||
* Such exceptions represent errors and exceptional conditions within the interface code itself;
|
||||
* see jpl.PrologException for the way Prolog exceptions are returned to calling Java code.
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public class JPLException extends RuntimeException {
|
||||
public JPLException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public JPLException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
215
LGPL/JPL/java/jpl/JRef.java
Normal file
215
LGPL/JPL/java/jpl/JRef.java
Normal file
@ -0,0 +1,215 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: JRef.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.ObjectHolder;
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// JRef
|
||||
/**
|
||||
* JRef is a specialised Term with an Object field, representing JPL's Prolog references to Java objects (or to null).
|
||||
* <pre>
|
||||
* JRef r = new JRef( non_String_object_or_null );
|
||||
* </pre>
|
||||
* A JRef can be used (and re-used) in Compound Terms.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Compound
|
||||
*/
|
||||
public class JRef extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* the JRef's value (a non-String Object or null)
|
||||
*/
|
||||
protected final Object ref;
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* This constructor creates a JRef, initialized with the supplied
|
||||
* non-String object (or null).
|
||||
*
|
||||
* @param ref this JRef's value (a non-String object, or null)
|
||||
*/
|
||||
public JRef(Object ref) {
|
||||
if (ref instanceof String) {
|
||||
throw new JPLException("a JRef cannot have a String value (String maps to atom)");
|
||||
} else {
|
||||
this.ref = ref;
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns a Prolog source text representation of this JRef
|
||||
*
|
||||
* @return a Prolog source text representation of this JRef
|
||||
*/
|
||||
public String toString() {
|
||||
return "" + ref + ""; // WRONG
|
||||
}
|
||||
|
||||
/**
|
||||
* Two JRefs are equal if their references are identical (?)
|
||||
*
|
||||
* @param obj The Object to compare
|
||||
* @return true if the Object satisfies the above condition
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return this == obj || (obj instanceof JRef && ref == ((JRef) obj).ref);
|
||||
}
|
||||
|
||||
public final int type() {
|
||||
return Prolog.JREF;
|
||||
}
|
||||
|
||||
public String typeName(){
|
||||
return "JRef";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (peculiar)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The non-String object (or null) which this jpl.JRef represents
|
||||
*
|
||||
* @return the non-String object (or null) which this jpl.JRef represents
|
||||
*/
|
||||
public Object ref() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The (nonexistent) args of this JRef
|
||||
*
|
||||
* @return the (nonexistent) args of this JRef
|
||||
* @deprecated
|
||||
*/
|
||||
public Term[] args() {
|
||||
return new Term[] {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of this JRef
|
||||
*
|
||||
* @return a debug-friendly representation of this JRef
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(JRef " + toString() + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To convert a JRef to a term, we put its Object field (.value) into the
|
||||
* term_t as a JPL ref (i.e. @/1) structure.
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables.
|
||||
* @param term A (newly created) term_t which is to be
|
||||
* set to a Prolog 'ref' (i.e. @/1) structure denoting the
|
||||
* .value of this JRef instance
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
|
||||
Prolog.put_jref(term, ref);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a term_t to a JRef. Assuming the Prolog term is a
|
||||
* ref, we just create a new JRef using the term_t's value.
|
||||
* NB This conversion is only invoked if "JPL-aware" term import is specified.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
* @param term The term (a ref) to convert
|
||||
* @return A new JRef instance
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
ObjectHolder obj = new ObjectHolder();
|
||||
|
||||
Prolog.get_jref(term, obj); // assume it succeeds...
|
||||
return new jpl.JRef(obj.value);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Nothing needs to be done if the Term is an Atom, Integer, Float or JRef
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to Terms.
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
185
LGPL/JPL/java/jpl/JVoid.java
Normal file
185
LGPL/JPL/java/jpl/JVoid.java
Normal file
@ -0,0 +1,185 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: JVoid.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// JVoid
|
||||
/**
|
||||
* A jpl.JVoid is a specialised Term. Instances of this class
|
||||
* denote JPL 'jvoid' values in Prolog, i.e. @(void):
|
||||
* <pre>
|
||||
* JVoid b = new JVoid();
|
||||
* </pre>
|
||||
* A JVoid can be used (and re-used) in Compound Terms.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
* @see jpl.Term
|
||||
* @see jpl.Compound
|
||||
*/
|
||||
public class JVoid extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes (none)
|
||||
//==================================================================/
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* This constructor creates a JVoid.
|
||||
*
|
||||
*/
|
||||
public JVoid() {
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns a Prolog source text representation of this JVoid
|
||||
*
|
||||
* @return a Prolog source text representation of this JVoid
|
||||
*/
|
||||
public String toString() {
|
||||
return "@(void)";
|
||||
}
|
||||
|
||||
/**
|
||||
* Two JVoids are equal
|
||||
*
|
||||
* @param obj The Object to compare (not necessarily another JVoid)
|
||||
* @return true if the Object satisfies the above condition
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return this == obj || (obj instanceof JVoid);
|
||||
}
|
||||
|
||||
public final int type() {
|
||||
return Prolog.JVOID;
|
||||
}
|
||||
|
||||
public String typeName(){
|
||||
return "JVoid";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The (nonexistent) args of this JVoid
|
||||
*
|
||||
* @return the (nonexistent) args of this JVoid
|
||||
* @deprecated
|
||||
*/
|
||||
public Term[] args() {
|
||||
return new Term[] {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of this JVoid
|
||||
*
|
||||
* @return a debug-friendly representation of this JVoid
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(JVoid)";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To convert a JVoid to a term, we unify the (freshly created, hence unbound)
|
||||
* term_t with @(void).
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables.
|
||||
* @param term A (previously created and unbound) term_t which is to be
|
||||
* assigned a Prolog @(void) structure
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
Prolog.put_jvoid(term);
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a term_t to a JVoid. Assuming the Prolog term to be
|
||||
* @(void), we just create a new JVoid instance.
|
||||
* NB This conversion is only invoked if "JPL-aware" term import is specified.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
* @param term The term_t to convert
|
||||
* @return A new JVoid instance
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
return new jpl.JVoid();
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Nothing needs to be done if the Term denotes an Atom, Integer, Float, JRef, JBoolean or JVoid
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to Terms.
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
* Variables.
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
74
LGPL/JPL/java/jpl/PrologException.java
Normal file
74
LGPL/JPL/java/jpl/PrologException.java
Normal file
@ -0,0 +1,74 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: PrologException.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// PrologException
|
||||
/**
|
||||
* PrologException instances wrap Prolog exceptions thrown (either by a Prolog engine or by user code)
|
||||
* in the course of finding a solution to a Query. See JPLException for the handling of errors within the JPL Java-calls-Prolog interface.
|
||||
* <p>
|
||||
* This class allows Java code which uses JPL's Java-calls-Prolog API to handle
|
||||
* Prolog exceptions, which is in general necessary for hybrid Java+Prolog programming.
|
||||
* <p>
|
||||
* Use the term() accessor to obtain a Term representation of the term that was
|
||||
* thrown from within Prolog.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public final class PrologException extends JPLException {
|
||||
private Term term_ = null;
|
||||
|
||||
protected PrologException(Term term) {
|
||||
super("PrologException: " + term.toString());
|
||||
|
||||
this.term_ = term;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a reference to the Term thrown by the call to throw/1
|
||||
*/
|
||||
public Term term() {
|
||||
return this.term_;
|
||||
}
|
||||
}
|
791
LGPL/JPL/java/jpl/Query.java
Normal file
791
LGPL/JPL/java/jpl/Query.java
Normal file
@ -0,0 +1,791 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Query.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import jpl.fli.*;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Query
|
||||
/**
|
||||
* A Query instance is created by an application in order to query the Prolog engine.
|
||||
* It is initialised with a
|
||||
* Compound (or Atom) denoting the goal which is to be called, and also contains assorted private state
|
||||
* relating to solutions. In some future version, it will contain details of the module
|
||||
* in which the goal is to be called.<p>
|
||||
* A Query is either open or closed: when closed, it has no connection to the Prolog engine;
|
||||
* when open, it is linked to an active goal within the Prolog engine.
|
||||
* Only one Query can be open at any one time<p>
|
||||
* The Query class implements the Enumeration interface, and it is
|
||||
* through this interface that one obtains successive solutions. The Enumeration
|
||||
* hasMoreElements() method returns true if the call or redo succeeded (otherwise
|
||||
* false), and if the call or redo did succeed, the nextElement() method returns
|
||||
* a Hashtable representing variable bindings; the elements in the
|
||||
* Hashtable are Terms, indexed by the Variables with which they are associated.
|
||||
* For example, if <i>p(a)</i> and <i>p(b)</i> are facts in the Prolog
|
||||
* database, then the following is equivalent to printing all
|
||||
* the solutions to the Prolog query <i>p(X)</i>:
|
||||
* <pre>
|
||||
* Variable X = new Variable();
|
||||
* Term arg[] = { X };
|
||||
* Query q = new Query( "p", arg );
|
||||
*
|
||||
* while ( q.hasMoreElements() ){
|
||||
* Term bound_to_x = ((Hashtable)q.nextElement()).get( X );
|
||||
* System.out.println( bound_to_x );
|
||||
* }
|
||||
* </pre>
|
||||
* Make sure to close the Query (using the rewind() method) if you do not need
|
||||
* any further solutions which it may have.
|
||||
* It is safe (although redundant) to close a Query whose solutions are already exhausted,
|
||||
* or which is already closed.
|
||||
*
|
||||
* To obtain just one solution from a Query, use the oneSolution() method.
|
||||
*
|
||||
* To obtain all solutions, use the allSolutions() method.
|
||||
*
|
||||
* To determine merely whether the Query is provable,
|
||||
* use the query() method (soon to be deprecated in favour of hasSolution()).
|
||||
* (i.e. has at least one solution).
|
||||
* <hr>
|
||||
* <i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin
|
||||
* <p>
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
* <p>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i>
|
||||
* <hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class Query implements Enumeration {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
private static Map m = new Hashtable(); // maps (engine_t) engine handle to (Query) topmost query
|
||||
|
||||
/**
|
||||
* the Compound (hence perhaps an Atom, but not Integer, Float or Variable) corresponding to the goal of this Query
|
||||
*/
|
||||
protected final Compound goal_; // set by all initialisers
|
||||
protected final String hostModule = "user"; // until revised constructors allow this to be specified
|
||||
protected final String contextModule = "user"; // until revised constructors allow this to be specified
|
||||
|
||||
/**
|
||||
* @deprecated Use .goal().name() instead.
|
||||
* @return the name of this Query's goal (redundant, deprecated)
|
||||
*/
|
||||
public final String name() {
|
||||
return goal_.name(); // it can only be a Compound or Atom
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use .goal().args() instead.
|
||||
* @return the arguments of this Query's goal (redundant, deprecated)
|
||||
*/
|
||||
public final Term[] args() {
|
||||
return goal_.args();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Compound (hence perhaps an Atom) which is the goal of this Query
|
||||
* @return a Term representing the goal of this Query
|
||||
*/
|
||||
public final Compound goal() {
|
||||
return goal_;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Constructors and Initialization
|
||||
//==================================================================/
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// Query
|
||||
/**
|
||||
* This constructor creates a Query whose goal is the specified Term.
|
||||
* The Query is initially closed.
|
||||
* <b>NB</b> Creating an instance of the Query class does not
|
||||
* result in a call to a Prolog engine.
|
||||
* <b>NB</b> The goal can be an Atom (Atom extends Compound), but cannot be an instance
|
||||
* of jpl.Float, jpl.Integer or jpl.Variable.
|
||||
* @param t the goal of this Query
|
||||
*/
|
||||
public Query(Term t) { // formerly insisted (confusingly) on a Compound (or Atom)
|
||||
this.goal_ = Query1( t);
|
||||
}
|
||||
|
||||
private Compound Query1( Term t ) {
|
||||
if (t instanceof Compound) {
|
||||
return (Compound) t;
|
||||
} else if (t instanceof Integer) {
|
||||
throw new JPLException("a Query's goal must be an Atom or Compound (not an Integer)");
|
||||
} else if (t instanceof Float) {
|
||||
throw new JPLException("a Query's goal must be an Atom or Compound (not a Float)");
|
||||
} else if (t instanceof Variable) {
|
||||
throw new JPLException("a Query's goal must be an Atom or Compound (not a Variable)");
|
||||
} else {
|
||||
throw new JPLException("a Query's goal must be an Atom or Compound");
|
||||
}
|
||||
}
|
||||
|
||||
// Query
|
||||
/**
|
||||
* If text denotes an atom, this constructor is shorthand for
|
||||
* <font face="monospace">new Query(new Compound(name,args))</font>,
|
||||
* but if text denotes a term containing N query symbols
|
||||
* and there are N args, each query is replaced by its corresponding arg
|
||||
* to provide the new Query's goal.
|
||||
*
|
||||
* @param text the name of the principal functor of this Query's goal
|
||||
* @param args the arguments of this Query's goal
|
||||
*/
|
||||
public Query(String text, Term[] args) {
|
||||
this(Query1(text, args));
|
||||
}
|
||||
|
||||
// convenience case for a single arg
|
||||
public Query(String text, Term arg) {
|
||||
this(Query1(text, new Term[] {arg}));
|
||||
}
|
||||
|
||||
private static Term Query1( String text, Term[] args) {
|
||||
Term t = Util.textToTerm(text);
|
||||
if ( t instanceof Atom ){
|
||||
return new Compound(text,args);
|
||||
} else {
|
||||
return t.putParams(args);
|
||||
}
|
||||
}
|
||||
|
||||
// Query
|
||||
/**
|
||||
* This constructor builds a Query from the given Prolog source text
|
||||
*
|
||||
* @param text the Prolog source text of this Query
|
||||
*/
|
||||
public Query(String text) {
|
||||
this(Util.textToTerm(text));
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Making Prolog Queries
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* These variables are used and set across the hasMoreElements
|
||||
* and nextElement Enumeration interface implementation
|
||||
*/
|
||||
private boolean open = false;
|
||||
// the following state variables are used and defined only if this query is open:
|
||||
private boolean called = false; // open/get/close vs. hasMoreSolutions/nextSolution
|
||||
private engine_t engine = null; // handle of attached Prolog engine iff open, else null
|
||||
private Query subQuery = null; // the open Query (if any) on top of which this open Query is stacked, else null
|
||||
private predicate_t predicate = null; // handle of this Query's predicate iff open, else undefined
|
||||
private fid_t fid = null; // id of current Prolog foreign frame iff open, else null
|
||||
private term_t term0 = null; // term refs of this Query's args iff open, else undefined
|
||||
private qid_t qid = null; // id of current Prolog query iff open, else null
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// hasMoreSolutions
|
||||
/**
|
||||
* This method returns true if JPL was able to initiate a "call" of this
|
||||
* Query within the Prolog engine. It is designed to be used
|
||||
* with the nextSolution() method to retrieve one or
|
||||
* more substitutions in the form of Hashtables. To iterate through
|
||||
* all the solutions to a Query, for example, one might write
|
||||
* <pre>
|
||||
* Query q = // obtain Query reference
|
||||
* while ( q.hasMoreSolutions() ){
|
||||
* Hashtable solution = q.nextSolution();
|
||||
* // process solution...
|
||||
* }
|
||||
* </pre>
|
||||
* To ensure thread-safety, you should wrap sequential calls to
|
||||
* this method in a synchronized block, using the static
|
||||
* lock method to obtain the monitor.
|
||||
* <pre>
|
||||
* Query q = // obtain Query reference
|
||||
* synchronized ( jpl.Query.lock() ){
|
||||
* while ( q.hasMoreElements() ){
|
||||
* Hashtable solution = q.nextSolution();
|
||||
* // process solution...
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* If this method is called on an already-open Query,
|
||||
* or while another Query is open, then a
|
||||
* QueryInProgressException will be thrown, containing a reference to the currently
|
||||
* open Query.
|
||||
*
|
||||
* @return true if the Prolog query succeeds; otherwise false.
|
||||
*/
|
||||
public synchronized final boolean hasMoreSolutions() {
|
||||
|
||||
if (!open) {
|
||||
open();
|
||||
}
|
||||
return get1();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// open
|
||||
/**
|
||||
* This method returns true if JPL was able to initiate a "call" of this
|
||||
* Query within the Prolog engine. It is designed to be used
|
||||
* with the getSolution() and close() methods to retrieve one or
|
||||
* more substitutions in the form of Hashtables.
|
||||
* To ensure thread-safety, you should wrap sequential calls to
|
||||
* this method in a synchronized block, using the static
|
||||
* lock method to obtain the monitor.
|
||||
* <pre>
|
||||
* Query q = // obtain Query reference
|
||||
* synchronized ( jpl.Query.lock() ){
|
||||
* while ( q.hasMoreElements() ){
|
||||
* Hashtable solution = q.nextSolution();
|
||||
* // process solution...
|
||||
* }
|
||||
* }
|
||||
* </pre>
|
||||
* <p>
|
||||
* If this method is called on an already-open Query,
|
||||
* or if the query cannot be set up for whatever reason,
|
||||
* then a JPLException will be thrown.
|
||||
*/
|
||||
public synchronized final void open() {
|
||||
|
||||
if (open) {
|
||||
throw new JPLException("Query is already open");
|
||||
}
|
||||
int self = Prolog.thread_self();
|
||||
// System.out.println("JPL thread_self()=" + self);
|
||||
if (Prolog.thread_self() == -1) { // this Java thread has no attached Prolog engine?
|
||||
engine = Prolog.attach_pool_engine(); // may block for a while, or fail
|
||||
// System.out.println("JPL attaching engine[" + engine.value + "] for " + this.hashCode() + ":" + this.toString());
|
||||
} else { // this Java thread has an attached engine
|
||||
engine = Prolog.current_engine();
|
||||
// System.out.println("JPL reusing engine[" + engine.value + "] for " + this.hashCode() + ":" + this.toString());
|
||||
}
|
||||
if (m.containsKey(new Long(engine.value))) {
|
||||
subQuery = (Query) m.get(new Long(engine.value)); // get this engine's previous topmost query
|
||||
// System.out.println("JPL reusing engine[" + engine.value + "] pushing " + subQuery.hashCode() + ":" + subQuery.toString());
|
||||
} else {
|
||||
subQuery = null;
|
||||
}
|
||||
m.put(new Long(engine.value), this); // update this engine's topmost query
|
||||
predicate = Prolog.predicate(goal_.name(), goal_.args.length, hostModule);
|
||||
fid = Prolog.open_foreign_frame(); // always succeeds?
|
||||
Map varnames_to_vars = new Hashtable();
|
||||
term0 = Term.putTerms(varnames_to_vars, goal_.args);
|
||||
// THINKS: invert varnames_to_Vars and use it when getting substitutions?
|
||||
qid = Prolog.open_query(Prolog.new_module(Prolog.new_atom(contextModule)), Prolog.Q_NORMAL, predicate, term0);
|
||||
open = true;
|
||||
called = false;
|
||||
}
|
||||
|
||||
private final boolean get1() {
|
||||
|
||||
// try to get the next solution; if none, close the query;
|
||||
if (Prolog.next_solution(qid)) {
|
||||
called = true; // OK to call get2()
|
||||
return true;
|
||||
} else {
|
||||
// if failure was due to throw/1, build exception term and throw it
|
||||
term_t exception_term_t = Prolog.exception(qid);
|
||||
if (exception_term_t.value != 0L) {
|
||||
Term exception_term = Term.getTerm(new Hashtable(), exception_term_t);
|
||||
close();
|
||||
throw new PrologException(exception_term);
|
||||
} else {
|
||||
close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// getSolution
|
||||
/**
|
||||
* This method returns a java.util.Hashtable, which represents
|
||||
* a set of bindings from the names of query variables to terms within the solution.
|
||||
* The Hashtable contains instances of Terms, keyed on those
|
||||
* Variables which were referenced in this Query's goal.
|
||||
* <p>
|
||||
* For example, if a Query has an occurrence of a jpl.Variable,
|
||||
* say, named X, one can obtain the Term bound to X in the solution
|
||||
* by looking up X in the Hashtable.
|
||||
* <pre>
|
||||
* Variable X = new Variable();
|
||||
* Query q = // obtain Query reference (with X in the Term array)
|
||||
* while ( q.hasMoreSolutions() ){
|
||||
* Hashtable solution = q.nextSolution();
|
||||
* // make t the Term bound to X in the solution
|
||||
* Term t = (Term)solution.get( X );
|
||||
* // ...
|
||||
* }
|
||||
* </pre>
|
||||
* Programmers should obey the following rules when using this method.
|
||||
* <menu>
|
||||
* <li> The nextSolution() method should only be called after the
|
||||
* hasMoreSolutions() method returns true; otherwise a JPLException
|
||||
* will be raised, indicating that no Query is in progress.
|
||||
* <li> The nextSolution() and hasMoreSolutions() should be called
|
||||
* in the same thread of execution, at least for a given Query
|
||||
* instance.
|
||||
* <li> The nextSolution() method should not be called while
|
||||
* another Thread is in the process of evaluating a Query. The
|
||||
* JPL High-Level interface is designed to be thread safe, and
|
||||
* is thread-safe as long as the previous two rules are obeyed.
|
||||
* </menu>
|
||||
*
|
||||
* This method will throw a JPLException if no query is in progress.
|
||||
* It will throw a QueryInProgressException if another Query
|
||||
* (besides this one) is in progress while this method is called.
|
||||
*
|
||||
* @return A Hashtable representing a substitution, or null
|
||||
*/
|
||||
public synchronized final Hashtable getSolution() {
|
||||
// oughta check: Query is open and thread has its engine
|
||||
if (get1()) {
|
||||
return get2();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized final Hashtable getSubstWithNameVars() {
|
||||
// oughta check: Query is open and thread has its engine
|
||||
if (get1()) {
|
||||
return get2WithNameVars();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// nextSolution
|
||||
/**
|
||||
* This method returns a java.util.Hashtable, which represents
|
||||
* a binding from the names of query variables to terms within the solution.
|
||||
* The Hashtable contains instances of Terms, keyed on those
|
||||
* Variables which were referenced in this Query's goal.
|
||||
* <p>
|
||||
* For example, if a Query has an occurrence of a jpl.Variable,
|
||||
* say, named X, one can obtain the Term bound to X in the solution
|
||||
* by looking up X in the Hashtable.
|
||||
* <pre>
|
||||
* Variable X = new Variable();
|
||||
* Query q = // obtain Query reference (with X in the Term array)
|
||||
* while ( q.hasMoreSolutions() ){
|
||||
* Hashtable solution = q.nextSolution();
|
||||
* // make t the Term bound to X in the solution
|
||||
* Term t = (Term)solution.get( X );
|
||||
* // ...
|
||||
* }
|
||||
* </pre>
|
||||
* Programmers should obey the following rules when using this method.
|
||||
* <menu>
|
||||
* <li> The nextSolution() method should only be called after the
|
||||
* hasMoreSolutions() method returns true; otherwise a JPLException
|
||||
* will be raised, indicating that no Query is in progress.
|
||||
* <li> The nextSolution() and hasMoreSolutions() should be called
|
||||
* in the same thread of execution, at least for a given Query
|
||||
* instance.
|
||||
* <li> The nextSolution() method should not be called while
|
||||
* another Thread is in the process of evaluating a Query. The
|
||||
* JPL High-Level interface is designed to be thread safe, and
|
||||
* is thread-safe as long as the previous two rules are obeyed.
|
||||
* </menu>
|
||||
*
|
||||
* This method will throw a JPLException if no query is in progress.
|
||||
* It will throw a QueryInProgressException if another Query
|
||||
* (besides this one) is in progress while this method is called.
|
||||
*
|
||||
* @return A Hashtable representing a substitution.
|
||||
*/
|
||||
public synchronized final Hashtable nextSolution() {
|
||||
return get2();
|
||||
}
|
||||
|
||||
private final Hashtable get2() {
|
||||
if (!open) {
|
||||
throw new JPLException("Query is not open");
|
||||
} else {
|
||||
Hashtable substitution = new Hashtable();
|
||||
// NB I reckon computeSubstitutions needn't be in Term (but where else?)
|
||||
Term.getSubsts(substitution, new Hashtable(), goal_.args);
|
||||
return substitution;
|
||||
}
|
||||
}
|
||||
|
||||
// assumes that Query's last arg is a Variable which will be bound to a [Name=Var,..] dict
|
||||
private final Hashtable get2WithNameVars() {
|
||||
if (!open) {
|
||||
throw new JPLException("Query is not open");
|
||||
} else {
|
||||
Term[] args = goal_.args; // for slight convenience below
|
||||
Term argNV = args[args.length - 1]; // the Query's last arg
|
||||
String nameNV = ((Variable) argNV).name; // its name
|
||||
|
||||
// get the [Name=Var,..] dict from the last arg
|
||||
Map varnames_to_Terms1 = new Hashtable();
|
||||
Map vars_to_Vars1 = new Hashtable();
|
||||
args[args.length - 1].getSubst(varnames_to_Terms1, vars_to_Vars1);
|
||||
|
||||
Hashtable varnames_to_Terms2 = new Hashtable();
|
||||
Term nvs = (Term) varnames_to_Terms1.get(nameNV);
|
||||
Map vars_to_Vars2 = Util.namevarsToMap(nvs);
|
||||
for (int i = 0; i < args.length - 1; ++i) {
|
||||
args[i].getSubst(varnames_to_Terms2, vars_to_Vars2);
|
||||
}
|
||||
|
||||
return varnames_to_Terms2;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// hasMoreElements
|
||||
/**
|
||||
* This method is completes the java.util.Enumeration
|
||||
* interface. It is a wrapper for hasMoreSolutions.
|
||||
*
|
||||
* @return true if the Prolog query succeeds; false, o/w.
|
||||
*/
|
||||
public synchronized final boolean hasMoreElements() {
|
||||
return hasMoreSolutions();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// nextElement
|
||||
/**
|
||||
* This method completes the java.util.Enumeration
|
||||
* interface. It is a wrapper for nextSolution.
|
||||
* <p>
|
||||
* This method will throw a QueryInProgressException if another Query
|
||||
* (besides this one) is in progress while this method is called.
|
||||
*
|
||||
* @return A Hashtable representing a substitution.
|
||||
*/
|
||||
public synchronized final Object nextElement() {
|
||||
return nextSolution();
|
||||
}
|
||||
|
||||
public synchronized final void rewind() {
|
||||
close();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// close
|
||||
/**
|
||||
* This method is used to close an open query so that the query
|
||||
* may be re-run, even if the Query's Enumeration has more
|
||||
* elements. Calling rewind() on an exhausted Enumeration has
|
||||
* no effect.<p>
|
||||
*
|
||||
* Here is a way to get the first three solutions to a Query,
|
||||
* while subsequently being able to use the same Query object to
|
||||
* obtain new solutions:
|
||||
* <pre>
|
||||
* Query q = new Query( predicate, args );
|
||||
* int i = 0;
|
||||
* for ( int i = 0; i < 3 && q.hasMoreSolutions(); ++i ){
|
||||
* Hasthable sub = (Hashtable) q.nextSolution();
|
||||
* ...
|
||||
* }
|
||||
* q.close();
|
||||
* </pre><p>
|
||||
*/
|
||||
public synchronized final void close() {
|
||||
if (!open) {
|
||||
return; // it is not an error to attempt to close a closed Query
|
||||
}
|
||||
if (Prolog.thread_self() == -1) {
|
||||
throw new JPLException("no engine is attached to this thread");
|
||||
}
|
||||
if (Prolog.current_engine().value != engine.value) {
|
||||
throw new JPLException("this Query's engine is not that which is attached to this thread");
|
||||
}
|
||||
Query topmost = (Query) m.get(new Long(engine.value));
|
||||
if (topmost != this) {
|
||||
throw new JPLException(
|
||||
"this Query ("
|
||||
+ this.hashCode()
|
||||
+ ":"
|
||||
+ this.toString()
|
||||
+ ") is not topmost ("
|
||||
+ topmost.hashCode()
|
||||
+ ":"
|
||||
+ topmost.toString()
|
||||
+ ") within its engine["
|
||||
+ engine.value
|
||||
+ "]");
|
||||
}
|
||||
Prolog.close_query(qid);
|
||||
qid = null; // for tidiness
|
||||
Prolog.discard_foreign_frame(fid);
|
||||
fid = null; // for tidiness
|
||||
m.remove(new Long(engine.value));
|
||||
if (subQuery == null) { // only Query open in this engine?
|
||||
if (Prolog.current_engine_is_pool()) { // this (Query's) engine is from the pool?
|
||||
Prolog.release_pool_engine();
|
||||
// System.out.println("JPL releasing engine[" + engine.value + "]");
|
||||
} else {
|
||||
// System.out.println("JPL leaving engine[" + engine.value + "]");
|
||||
}
|
||||
} else {
|
||||
m.put(new Long(engine.value), subQuery);
|
||||
// System.out.println("JPL retaining engine[" + engine.value + "] popping subQuery(" + subQuery.hashCode() + ":" + subQuery.toString() + ")");
|
||||
}
|
||||
// eid = -1; // for tidiness
|
||||
engine = null;
|
||||
subQuery = null;
|
||||
open = false;
|
||||
called = false;
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// allSolutions
|
||||
/**
|
||||
* calls the Query's goal to exhaustion and returns an array containing every solution
|
||||
* (in the order in which they were found).
|
||||
* @return an array of Hashtables (possibly none), each of which is a solution
|
||||
* (in the order in which they were found) of the Query.
|
||||
* <b>NB</b> in JPL 1.0.1, this method returned null when a Query had no solutions;
|
||||
* in JPL 2.x.x it returns an emprt array (thus the length of the array is, in every case,
|
||||
* the quantity of solutions).<p>
|
||||
*
|
||||
* This method will throw a QueryInProgressException if this or another Query
|
||||
* is already open.
|
||||
*
|
||||
* @see jpl.Query#hasMoreElements
|
||||
* @see jpl.Query#nextElement
|
||||
* @see jpl.Query#hasMoreSolutions
|
||||
* @see jpl.Query#nextSolution
|
||||
* @see jpl.Query#rewind
|
||||
* @see jpl.Query#oneSolution
|
||||
* @see jpl.Query#allSolutions
|
||||
* @see jpl.Query#query
|
||||
*/
|
||||
public synchronized final Hashtable[] allSolutions() {
|
||||
if (open) {
|
||||
throw new JPLException("Query is already open");
|
||||
} else {
|
||||
// get a vector of solutions:
|
||||
Vector v = new Vector();
|
||||
while (hasMoreSolutions()) {
|
||||
v.addElement(nextSolution());
|
||||
}
|
||||
|
||||
// turn the vector into an array:
|
||||
Hashtable solutions[] = new Hashtable[v.size()]; // 0 solutions -> Hashtable[0]
|
||||
v.copyInto(solutions);
|
||||
|
||||
return solutions;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// oneSolution
|
||||
/**
|
||||
* Returns the first solution, if any, as a (possibly empty) Hashtable.
|
||||
*
|
||||
* This method will throw a JPLException if this Query
|
||||
* is already open, and the Query will remain open as before.
|
||||
* Otherwise, upon return, the Query will be closed.
|
||||
* @return the first solution, if the query has one, as a (possibly empty) Hashtable.
|
||||
* If the return value is null, this means that the Query has no solutions.<p>
|
||||
*
|
||||
* @see jpl.Query#hasMoreElements
|
||||
* @see jpl.Query#nextElement
|
||||
* @see jpl.Query#hasMoreSolutions
|
||||
* @see jpl.Query#nextSolution
|
||||
* @see jpl.Query#rewind
|
||||
* @see jpl.Query#oneSolution
|
||||
* @see jpl.Query#allSolutions
|
||||
* @see jpl.Query#query
|
||||
*/
|
||||
public synchronized final Hashtable oneSolution() {
|
||||
if (open) {
|
||||
throw new JPLException("Query is already open");
|
||||
} else {
|
||||
Hashtable solution = null;
|
||||
if (hasMoreSolutions()) {
|
||||
solution = nextSolution();
|
||||
}
|
||||
rewind();
|
||||
return solution;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// query
|
||||
/**
|
||||
* @deprecated Use .hasSolution() instead.
|
||||
* JPL will attempt to call this Query's goal within the attached Prolog engine.
|
||||
* @return the provability of the Query, i.e. 'true' if it has at least
|
||||
* one solution, 'false' if the call fails without finding a solution.<p>
|
||||
*
|
||||
* Only the first solution (if there is one) will be found;
|
||||
* any bindings will be discarded, and the Query will be closed.<p>
|
||||
* This method will throw a QueryInProgressException if this or another Query
|
||||
* is already open.
|
||||
*
|
||||
* @see jpl.Query#hasMoreElements
|
||||
* @see jpl.Query#nextElement
|
||||
* @see jpl.Query#hasMoreSolutions
|
||||
* @see jpl.Query#nextSolution
|
||||
* @see jpl.Query#rewind
|
||||
* @see jpl.Query#oneSolution
|
||||
* @see jpl.Query#allSolutions
|
||||
* @see jpl.Query#query
|
||||
*/
|
||||
public synchronized final boolean query() {
|
||||
return oneSolution() != null;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// hasSolution
|
||||
/**
|
||||
* JPL will attempt to call this Query's goal within the attached Prolog engine.
|
||||
* @return the provability of the Query, i.e. 'true' if it has at least
|
||||
* one solution, 'false' if the call fails without finding a solution.<p>
|
||||
*
|
||||
* Only the first solution (if there is one) will be found;
|
||||
* any bindings will be discarded, and the Query will be closed.<p>
|
||||
* This method will throw a QueryInProgressException if this or another Query
|
||||
* is already open.
|
||||
*
|
||||
* @see jpl.Query#hasMoreElements
|
||||
* @see jpl.Query#nextElement
|
||||
* @see jpl.Query#hasMoreSolutions
|
||||
* @see jpl.Query#nextSolution
|
||||
* @see jpl.Query#rewind
|
||||
* @see jpl.Query#oneSolution
|
||||
* @see jpl.Query#allSolutions
|
||||
* @see jpl.Query#query
|
||||
*/
|
||||
public synchronized final boolean hasSolution() {
|
||||
return oneSolution() != null;
|
||||
}
|
||||
|
||||
public final int abort() {
|
||||
if (open) {
|
||||
(new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
int rc1 = Prolog.attach_engine(engine);
|
||||
System.out.println("q.abort(): attach_engine() returns " + rc1);
|
||||
int rc2 = Prolog.action_abort();
|
||||
System.out.println("q.abort(): action_abort() returns " + rc2);
|
||||
// int rc3 = Prolog.release_pool_engine();
|
||||
// System.out.println("q.abort(): release_pool_engine() returns " + rc3);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
})).start(); // call the query in a separate thread
|
||||
/*
|
||||
int rc0a = Prolog.pool_engine_id(this.engine);
|
||||
System.out.println("q.abort(): this.engine has id=" + rc0a);
|
||||
|
||||
engine_t e = Prolog.current_engine();
|
||||
System.out.println("q.abort(): " + (e == null ? "no current engine" : "current engine id=" + Prolog.pool_engine_id(e)));
|
||||
|
||||
int rc0b = Prolog.release_pool_engine();
|
||||
System.err.println("q.abort(): release_pool_engine() returns " + rc0b);
|
||||
|
||||
engine_t e2 = Prolog.current_engine();
|
||||
System.out.println("q.abort(): " + (e == null ? "no current engine" : "current engine id=" + Prolog.pool_engine_id(e2)));
|
||||
|
||||
int rc1 = Prolog.attach_engine(this.engine);
|
||||
System.out.println("q.abort(): attach_engine() returns " + rc1);
|
||||
|
||||
engine_t e3 = Prolog.current_engine();
|
||||
System.out.println("q.abort(): " + (e == null ? "no current engine" : "current engine id=" + Prolog.pool_engine_id(e3)));
|
||||
|
||||
int rc2 = Prolog.action_abort();
|
||||
System.out.println("q.abort(): action_abort() returns " + rc2);
|
||||
|
||||
int rc3 = Prolog.release_pool_engine();
|
||||
System.out.println("q.abort(): release_pool_engine() returns " + rc3);
|
||||
|
||||
int rc4 = Prolog.attach_engine(e);
|
||||
System.out.println("q.abort(): attach_engine() returns " + rc4);
|
||||
*/
|
||||
return 0;
|
||||
} else {
|
||||
System.out.println("q.abort(): query is not open");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// misc
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns the String representation of a Query.
|
||||
*
|
||||
* @return the String representation of a Query
|
||||
*/
|
||||
public String toString() {
|
||||
return goal_.name + "( " + Term.toString(goal_.args) + " )";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of a Query
|
||||
*
|
||||
* @return a debug-friendly representation of a Query
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(Query " + goal_.name + " " + Term.debugString(goal_.args) + ")";
|
||||
}
|
||||
}
|
671
LGPL/JPL/java/jpl/Term.java
Normal file
671
LGPL/JPL/java/jpl/Term.java
Normal file
@ -0,0 +1,671 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Term.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.IntHolder;
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Term
|
||||
/**
|
||||
* Term is the abstract base class for
|
||||
* Compound, Atom, Variable, Integer and Float, which comprise a Java-oriented concrete syntax for Prolog.
|
||||
* You cannot create instances of Term directly; rather, you should create
|
||||
* instances of Term's concrete subclasses.
|
||||
* Alternatively, use textToTerm() to construct a Term from its conventional
|
||||
* Prolog source text representation.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public abstract class Term {
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* This default constructor is provided in order for subclasses
|
||||
* to be able to define their own default constructors.
|
||||
*/
|
||||
protected Term() {
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (abstract, common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* returns the ano-th (1+) argument of a (Compound) Term
|
||||
* throws a JPLException for any other subclass
|
||||
*
|
||||
* @return the ano-th argument of a (Compound) Term
|
||||
*/
|
||||
public Term arg(int ano) {
|
||||
throw new JPLException("jpl." + this.typeName() + ".arg() is undefined");
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests whether this Term's functor has (String) 'name' and 'arity'
|
||||
* Returns false if called inappropriately
|
||||
*
|
||||
* @return whether this Term's functor has (String) 'name' and 'arity'
|
||||
*/
|
||||
public boolean hasFunctor(String name, int arity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this Term's functor has (int) 'name' and 'arity'
|
||||
* Returns false if called inappropriately
|
||||
*
|
||||
* @return whether this Term's functor has (int) 'name' and 'arity'
|
||||
*/
|
||||
public boolean hasFunctor(int value, int arity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether this Term's functor has (double) 'name' and 'arity'
|
||||
* Returns false if called inappropriately
|
||||
*
|
||||
* @return whether this Term's functor has (double) 'name' and 'arity'
|
||||
*/
|
||||
public boolean hasFunctor(double value, int arity) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns, as a String, the name of a Compound, Atom or Variable
|
||||
* throws a JPLException from an Integer or Float
|
||||
*
|
||||
* @return the name of a Compound, Atom or Variable
|
||||
*/
|
||||
public String name() {
|
||||
throw new JPLException("jpl." + this.typeName() + ".name() is undefined");
|
||||
};
|
||||
|
||||
/**
|
||||
* returns, as an int, the arity of a Compound, Atom, Integer or Float
|
||||
* throws a JPLException from a Variable
|
||||
*
|
||||
* @return the arity of a Compound, Atom, Integer or Float
|
||||
*/
|
||||
public int arity() {
|
||||
throw new JPLException("jpl." + this.typeName() + ".arity() is undefined");
|
||||
};
|
||||
|
||||
/**
|
||||
* returns the value (as an int) of an Integer or Float
|
||||
* throws a JPLException from a Compound, Atom or Variable
|
||||
*
|
||||
* @return the value (as an int) of an Integer or Float
|
||||
*/
|
||||
public int intValue() {
|
||||
throw new JPLException("jpl." + this.typeName() + ".intValue() is undefined");
|
||||
}
|
||||
/**
|
||||
* returns the value (as a long) of an Integer or Float
|
||||
* throws a JPLException from a Compound, Atom or Variable
|
||||
*
|
||||
* @return the value (as a long) of an Integer or Float
|
||||
*/
|
||||
public long longValue() {
|
||||
throw new JPLException("jpl." + this.typeName() + ".longValue() is undefined");
|
||||
}
|
||||
/**
|
||||
* returns the value (as a float) of an Integer or Float
|
||||
* throws a JPLException from a Compound, Atom or Variable
|
||||
*
|
||||
* @return the value (as a float) of an Integer or Float
|
||||
*/
|
||||
public float floatValue() {
|
||||
throw new JPLException("jpl." + this.typeName() + ".floatValue() is undefined");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the value (as a double) of an Integer or Float
|
||||
* throws a JPLException from any other subclass
|
||||
*
|
||||
* @return the value (as an double) of an Integer or Float
|
||||
*/
|
||||
public double doubleValue() {
|
||||
throw new JPLException("jpl." + this.typeName() + ".doubleValue() is undefined");
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* returns the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc
|
||||
*
|
||||
* @return the type of this term, as one of jpl.fli.Prolog.COMPOUND, .ATOM, .VARIABLE, .INTEGER, .FLOAT etc
|
||||
*/
|
||||
public abstract int type();
|
||||
|
||||
/**
|
||||
* returns the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc
|
||||
*
|
||||
* @return the name of the type of this term, as one of "Compound", "Atom", "Variable", "Integer", "Float" etc
|
||||
*/
|
||||
public abstract String typeName();
|
||||
|
||||
/**
|
||||
* whether this Term represents an atom
|
||||
*
|
||||
* @return whether this Term represents an atom
|
||||
*/
|
||||
public boolean isAtom() {
|
||||
return this instanceof Atom;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term represents a compound term
|
||||
*
|
||||
* @return whether this Term represents a compound atom
|
||||
*/
|
||||
public boolean isCompound() {
|
||||
return this instanceof Compound;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term represents an atom
|
||||
*
|
||||
* @return whether this Term represents an atom
|
||||
*/
|
||||
public boolean isFloat() {
|
||||
return this instanceof Float;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term represents an atom
|
||||
*
|
||||
* @return whether this Term represents an atom
|
||||
*/
|
||||
public boolean isInteger() {
|
||||
return this instanceof Integer;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term is a JBoolean
|
||||
*
|
||||
* @return whether this Term is a JBoolean
|
||||
*/
|
||||
public boolean isJBoolean() {
|
||||
return this instanceof JBoolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term is a JRef
|
||||
*
|
||||
* @return whether this Term is a JRef
|
||||
*/
|
||||
public boolean isJRef() {
|
||||
return this instanceof JRef;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term is a JVoid
|
||||
*
|
||||
* @return whether this Term is a JVoid
|
||||
*/
|
||||
public boolean isJVoid() {
|
||||
return this instanceof JVoid;
|
||||
}
|
||||
|
||||
/**
|
||||
* whether this Term is a variable
|
||||
*
|
||||
* @return whether this Term is a variable
|
||||
*/
|
||||
public boolean isVariable() {
|
||||
return this instanceof Variable;
|
||||
}
|
||||
|
||||
public Term putParams(Term[] ps) {
|
||||
IntHolder next = new IntHolder();
|
||||
next.value = 0;
|
||||
Term t2 = this.putParams1(next, ps);
|
||||
if (next.value != ps.length) {
|
||||
throw new JPLException("Term.putParams: more actual params than formal");
|
||||
}
|
||||
return t2;
|
||||
}
|
||||
|
||||
public Term putParams(Term plist) {
|
||||
Term[] ps = plist.toTermArray();
|
||||
return putParams(ps);
|
||||
}
|
||||
|
||||
protected Term putParams1(IntHolder next, Term[] ps) {
|
||||
switch (this.type()) {
|
||||
case Prolog.COMPOUND :
|
||||
return new Compound(this.name(), putParams2(this.args(), next, ps));
|
||||
case Prolog.ATOM :
|
||||
if (this.name().equals("?")) {
|
||||
if (next.value >= ps.length) {
|
||||
throw new JPLException("Term.putParams: fewer actual params than formal params");
|
||||
}
|
||||
return ps[next.value++];
|
||||
} // else drop through to default
|
||||
default :
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
static protected Term[] putParams2(Term[] ts, IntHolder next, Term[] ps) {
|
||||
int n = ts.length;
|
||||
Term[] ts2 = new Term[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
ts2[i] = ts[i].putParams1(next, ps);
|
||||
}
|
||||
return ts2;
|
||||
}
|
||||
|
||||
/**
|
||||
* the length of this list, iff it is one, else an exception is thrown
|
||||
*
|
||||
* @throws JPLException
|
||||
* @return the length (as an int) of this list, iff it is one
|
||||
*/
|
||||
public int listLength() {
|
||||
int len = 0;
|
||||
|
||||
if (this.hasFunctor(".", 2)) {
|
||||
return 1 + this.arg(2).listLength();
|
||||
} else if (this.hasFunctor("[]", 0)) {
|
||||
return 0;
|
||||
} else {
|
||||
throw new JPLException("Term.listLength: term is not a list");
|
||||
}
|
||||
}
|
||||
|
||||
/** returns an array of terms which are the successive members of this list, if it is a list, else throws an exception
|
||||
*
|
||||
* @throws JPLException
|
||||
* @return an array of terms which are the successive members of this list, if it is a list
|
||||
*/
|
||||
public Term[] toTermArray() {
|
||||
try {
|
||||
int len = this.listLength();
|
||||
Term[] ts = new Term[len];
|
||||
Term t = this;
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
ts[i] = t.arg(1);
|
||||
t = t.arg(2);
|
||||
}
|
||||
return ts;
|
||||
} catch (JPLException e) {
|
||||
throw new JPLException("Term.toTermArray: term is not a proper list");
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* returns, as a Term[], the arguments of a Compound
|
||||
* returns an empty Term[] from an Atom, Integer or Float
|
||||
* throws a JPLException from a Variable
|
||||
*
|
||||
* @return the arguments of a Compound as a Term[
|
||||
* @deprecated
|
||||
*/
|
||||
public abstract Term[] args();
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of a Term
|
||||
*
|
||||
* @return a debug-friendly representation of a Term
|
||||
* @deprecated
|
||||
*/
|
||||
public abstract String debugString();
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly representation of a list of Terms
|
||||
*
|
||||
* @return a debug-friendly representation of a list of Terms
|
||||
* @deprecated
|
||||
*/
|
||||
public static String debugString(Term arg[]) {
|
||||
String s = "[";
|
||||
|
||||
for (int i = 0; i < arg.length; ++i) {
|
||||
s += arg[i].debugString();
|
||||
if (i != arg.length - 1) {
|
||||
s += ", ";
|
||||
}
|
||||
}
|
||||
return s + "]";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//
|
||||
// To convert a Term to a term_t, we need to traverse the Term
|
||||
// structure and build a corresponding Prolog term_t object.
|
||||
// There are some issues:
|
||||
//
|
||||
// - Prolog term_ts rely on the *consecutive* nature of term_t
|
||||
// references. In particular, to build a compound structure
|
||||
// in the Prolog FLI, one must *first* determine the arity of the
|
||||
// compound, create a *sequence* of term_t references, and then
|
||||
// put atoms, functors, etc. into those term references. We
|
||||
// do this in these methods by first determining the arity of the
|
||||
// Compound, and then by "put"-ing a type into a term_t.
|
||||
// The "put" method is implemented differently in each of Term's
|
||||
// five subclasses.
|
||||
//
|
||||
// - What if we are trying to make a term_t from a Term, but the
|
||||
// Term has multiple instances of the same Variable? We want
|
||||
// to ensure that _one_ Prolog variable will be created, or else
|
||||
// queries will give incorrect answers. We thus pass a Hashtable
|
||||
// (var_table) through these methods. The table contains term_t
|
||||
// instances, keyed on Variable instances.
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Cache the reference to the Prolog term_t here.
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to JPL Variables.
|
||||
* @param term A (previously created) term_t which is to be
|
||||
* put with a Prolog term-type appropriate to the Term type
|
||||
* (e.g., Atom, Variable, Compound, etc.) on which the method is
|
||||
* invoked.)
|
||||
*/
|
||||
protected abstract void put(Map varnames_to_vars, term_t term);
|
||||
|
||||
/**
|
||||
* This static method converts an array of Terms to a *consecutive*
|
||||
* sequence of term_t objects. Note that the first term_t object
|
||||
* returned is a term_t class (structure); the succeeding term_t
|
||||
* objects are consecutive references obtained by incrementing the
|
||||
* *value* field of the term_t.
|
||||
*
|
||||
* @param varnames_to_vars Map from variable names to JPL Variables.
|
||||
* @param args An array of jpl.Term references.
|
||||
* @return consecutive term_t references (first of which is
|
||||
* a structure)
|
||||
*/
|
||||
protected static term_t putTerms(Map varnames_to_vars, Term[] args) {
|
||||
|
||||
// first create a sequence of term_ts. The 0th term_t
|
||||
// will be a jpl.fli.term_t. Successive Prolog term_t
|
||||
// references will reside in the Prolog engine, and
|
||||
// can be obtained by term0.value+i.
|
||||
//
|
||||
term_t term0 = Prolog.new_term_refs(args.length);
|
||||
|
||||
// for each new term reference, construct a Prolog term
|
||||
// by putting an appropriate Prolog type into the reference.
|
||||
//
|
||||
long ith_term_t = term0.value;
|
||||
for (int i = 0; i < args.length; ++i, ++ith_term_t) {
|
||||
term_t term = new term_t();
|
||||
term.value = ith_term_t;
|
||||
args[i].put(varnames_to_vars, term); // each subclass defines its own put()
|
||||
}
|
||||
|
||||
return term0;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//
|
||||
// Converting back from term_ts to Terms is simple, since
|
||||
// the (simplified) Term representation is canonical (there is only one
|
||||
// correct structure for any given Prolog term).
|
||||
//
|
||||
// One problem concerns variable bindings. We illustrate
|
||||
// with several examples. First, consider the Prolog fact
|
||||
//
|
||||
// p( f(X,X)).
|
||||
//
|
||||
// And the query
|
||||
//
|
||||
// ?- p( Y).
|
||||
//
|
||||
// A solution should be
|
||||
//
|
||||
// y = f(X,X)
|
||||
//
|
||||
// and indeed, if this query is run, the term_t to which Y will
|
||||
// be unified is a compound, f(X,X). The problem is, how do
|
||||
// we know, in converting the term_ts to Terms in the compound f/2
|
||||
// whether we should create one Variable or two? This begs the
|
||||
// question, how do we _identify_ Variables in JPL? The answer
|
||||
// to the latter question is, by reference; two Variable (Java)
|
||||
// references refer to the same variable iff they are, in memory,
|
||||
// the same Variable object. That is, they satisfy the Java == relation.
|
||||
// (Note that this condition is _not_ true of the other Term types.)
|
||||
//
|
||||
// Given this design decision, therefore, we should create a
|
||||
// single Variable instance and a Compound instance whose two arg
|
||||
// values refer to the same Variable object. We therefore need to keep
|
||||
// track, in converting a term_t to a Term (in particular, in
|
||||
// converting a term_t whose type is variable to a Variable), of
|
||||
// which Variables have been created. We do this by using the vars
|
||||
// Hashtable, which gets passed recursively though the from_term_t
|
||||
// methods; this table holds the Variable instances that have been
|
||||
// created, keyed by the unique and internal-to-Prolog string
|
||||
// representation of the variable (I'm not sure about this...).
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* This method calls from_term_t on each term in the n consecutive term_ts.
|
||||
* A temporary jpl.term_t "holder" (byref) structure must be created
|
||||
* in order to extract type information from the Prolog engine.
|
||||
*
|
||||
* @param vars_to_Vars A Map from Prolog variables to jpl.Variable instances
|
||||
* @param n The number of consecutive term_ts
|
||||
* @param term0 The 0th term_t (structure); subsequent
|
||||
* term_ts are not structures.
|
||||
* @return An array of converted Terms
|
||||
*/
|
||||
/*
|
||||
protected static Term[] from_term_ts(Map vars_to_Vars, int n, term_t term0) {
|
||||
|
||||
// create an (uninitialised) array of n Term references
|
||||
Term[] terms = new Term[n];
|
||||
|
||||
// for each term_t (from 0...n-1), create a term_t
|
||||
// (temporary) structure and dispatch the translation
|
||||
// to a Term to the static from_term_t method of the Term
|
||||
// class. This will perform (Prolog) type analysis on the
|
||||
// term_t and call the appropriate static method to create
|
||||
// a Term of the right type (e.g., Atom, Variable, List, etc.)
|
||||
//
|
||||
long ith_term_t = term0.value;
|
||||
for (int i = 0; i < n; ++i, ++ith_term_t) {
|
||||
term_t term = new term_t();
|
||||
term.value = ith_term_t;
|
||||
|
||||
terms[i] = Term.from_term_t(vars_to_Vars, term);
|
||||
}
|
||||
|
||||
return terms;
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* We discover the Prolog type of the term, then forward the
|
||||
* call to the appropriate subclass
|
||||
*
|
||||
* @param vars A Map from Prolog variables to jpl.Variable instances
|
||||
* @param term The Prolog term (in a term_t holder) to convert
|
||||
* @return The converted Term subtype instance.
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t term) {
|
||||
int type = Prolog.term_type(term);
|
||||
|
||||
switch (type) {
|
||||
case Prolog.VARIABLE :
|
||||
return Variable.getTerm(vars_to_Vars, term);
|
||||
case Prolog.ATOM :
|
||||
return Atom.getTerm(vars_to_Vars, term);
|
||||
case Prolog.STRING :
|
||||
return Atom.getString(vars_to_Vars, term);
|
||||
case Prolog.INTEGER :
|
||||
return Integer.getTerm(vars_to_Vars, term);
|
||||
case Prolog.FLOAT :
|
||||
return Float.getTerm(vars_to_Vars, term);
|
||||
case Prolog.COMPOUND :
|
||||
return Compound.getTerm(vars_to_Vars, term);
|
||||
default :
|
||||
// should never happen...
|
||||
throw new JPLException("Term.from_term_t: unknown term type=" + type);
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//
|
||||
// Once a solution has been found, the Prolog term_t references
|
||||
// will have been instantiated and will refer to new terms. To compute
|
||||
// a substitution, we traverse the (original) Term structure, looking
|
||||
// at the term_t reference in the Term. The only case we really care
|
||||
// about is if the (original) Term is a Variable; if so, the term_t
|
||||
// back in the Prolog engine may be instantiated (non Variable parts
|
||||
// of the original Term cannot change or become uninstantiated). In
|
||||
// this case, we can store this term in a Hashtable, keyed by the
|
||||
// Variable with which the term was unified.
|
||||
//==================================================================/
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// getSubst
|
||||
/**
|
||||
* This method computes a substitution from a Term. The bindings
|
||||
* Hashtable stores Terms, keyed by Variables. Thus, a
|
||||
* substitution is as it is in mathematical logic, a sequence
|
||||
* of the form \sigma = {t_0/x_0, ..., t_n/x_n}. Once the
|
||||
* substitution is computed, the substitution should satisfy
|
||||
*
|
||||
* \sigma T = t
|
||||
*
|
||||
* where T is the Term from which the substitution is computed,
|
||||
* and t is the term_t which results from the Prolog query.<p>
|
||||
*
|
||||
* A second Hashtable, vars, is required; this table holds
|
||||
* the Variables that occur (thus far) in the unified term.
|
||||
* The Variable instances in this table are guaranteed to be
|
||||
* unique and are keyed on Strings which are Prolog internal
|
||||
* representations of the variables.
|
||||
*
|
||||
* @param bindings table holding Term substitutions, keyed on
|
||||
* Variables.
|
||||
* @param vars A Hashtable holding the Variables that occur
|
||||
* thus far in the term; keyed by internal (Prolog) string rep.
|
||||
*/
|
||||
protected abstract void getSubst(Map varnames_to_Terms, Map vars_to_Vars);
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// getSubsts
|
||||
/**
|
||||
* Just calls computeSubstitution for each Term in the array.
|
||||
*
|
||||
* @param varnames_to_Terms a Map from variable names to Terms
|
||||
* @param vars_to_Vars a Map from Prolog variables to JPL Variables
|
||||
* @param arg a list of Terms
|
||||
*/
|
||||
protected static void getSubsts(Map varnames_to_Terms, Map vars_to_Vars, Term[] args) {
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
args[i].getSubst(varnames_to_Terms, vars_to_Vars);
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// terms_equals
|
||||
/**
|
||||
* This method is used (by Compound.equals) to determine the Terms in two Term arrays
|
||||
* are pairwise equal, where two Terms are equal if they satisfy
|
||||
* the equals predicate (defined differently in each Term subclass).
|
||||
*
|
||||
* @param t1 an array of Terms
|
||||
* @param t2 another array of Terms
|
||||
* @return true if all of the Terms in the (same-length) arrays are pairwise equal
|
||||
*/
|
||||
protected static boolean terms_equals(Term[] t1, Term[] t2) {
|
||||
if (t1.length != t2.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < t1.length; ++i) {
|
||||
if (!t1[i].equals(t2[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// toString
|
||||
/**
|
||||
* Converts a list of Terms to a String.
|
||||
*
|
||||
* @param args An array of Terms to convert
|
||||
* @return String representation of a list of Terms
|
||||
*/
|
||||
public static String toString(Term[] args) {
|
||||
String s = "";
|
||||
|
||||
for (int i = 0; i < args.length; ++i) {
|
||||
s += args[i].toString();
|
||||
if (i != args.length - 1) {
|
||||
s += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
172
LGPL/JPL/java/jpl/Util.java
Normal file
172
LGPL/JPL/java/jpl/Util.java
Normal file
@ -0,0 +1,172 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Util.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Map;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Util
|
||||
/**
|
||||
* This class provides a bunch of static utility methods for the JPL
|
||||
* High-Level Interface.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public final class Util {
|
||||
//------------------------------------------------------------------/
|
||||
// termArrayToList
|
||||
/**
|
||||
* Converts an array of Terms to a JPL representation of a Prolog list of terms
|
||||
* whose members correspond to the respective array elements.
|
||||
*
|
||||
* @param terms An array of Term
|
||||
* @return Term a list of the array elements
|
||||
*/
|
||||
public static Term termArrayToList(Term[] terms) {
|
||||
Term list = new Atom("[]");
|
||||
|
||||
for (int i = terms.length - 1; i >= 0; --i) {
|
||||
list = new Compound(".", new Term[] { terms[i], list });
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a solution hashtable to an array of Terms.
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to Terms
|
||||
* @return Term[] An array of the Terms to which successive variables are bound
|
||||
*/
|
||||
public static Term[] bindingsToTermArray(Map varnames_to_Terms) {
|
||||
Term[] ts = new Term[varnames_to_Terms.size()];
|
||||
|
||||
for (java.util.Iterator i = varnames_to_Terms.keySet().iterator(); i.hasNext();) {
|
||||
Variable k = (Variable) i.next();
|
||||
ts[k.index] = (Term) (varnames_to_Terms.get(k));
|
||||
}
|
||||
return ts;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// toString
|
||||
/**
|
||||
* Converts a substitution, in the form of a Map from variable names to Terms, to a String.
|
||||
*
|
||||
* @param varnames_to_Terms A Map from variable names to Terms.
|
||||
* @return String A String representation of the variable bindings
|
||||
*/
|
||||
public static String toString(Map varnames_to_Terms) {
|
||||
if (varnames_to_Terms == null) {
|
||||
return "[no solution]";
|
||||
}
|
||||
java.util.Iterator varnames = varnames_to_Terms.keySet().iterator();
|
||||
|
||||
String s = "Bindings: ";
|
||||
while (varnames.hasNext()) {
|
||||
String varname = (String) varnames.next();
|
||||
s += varname + "=" + varnames_to_Terms.get(varname).toString() + "; ";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// namevarsToMap
|
||||
/**
|
||||
* Converts a (JPL) list of Name=Var pairs (as yielded by atom_to_term/3)
|
||||
* to a Map from Prolog variables (necessarily in term_t holders) to named JPL Variables
|
||||
*
|
||||
* @param nvs A JPL list of Name=Var pairs (as yielded by atom_to_term/3)
|
||||
* @return Map A Map from Prolog variables (necessarily in term_t holders) to named JPL Variables
|
||||
*/
|
||||
public static Map namevarsToMap(Term nvs) {
|
||||
|
||||
try {
|
||||
Map vars_to_Vars = new Hashtable();
|
||||
|
||||
/*
|
||||
while (nvs.hasFunctor(".", 2) && ((Compound) nvs).arg(1).hasFunctor("=", 2)) {
|
||||
Atom name = (Atom) ((Compound) ((Compound) nvs).arg(1)).arg(1); // get the Name of the =/2 pair
|
||||
Variable var = (Variable) ((Compound) ((Compound) nvs).arg(1)).arg(2); // get the Var of the =/2 pair
|
||||
|
||||
vars_to_Vars.put(var.term_, new Variable(name.name())); // map the Prolog variable to a new, named Variable
|
||||
nvs = ((Compound) nvs).arg(2); // advance to next list cell
|
||||
}
|
||||
*/
|
||||
while (nvs.hasFunctor(".", 2) && nvs.arg(1).hasFunctor("=", 2)) {
|
||||
// the cast to Variable is necessary to access the (protected) .term_ field
|
||||
vars_to_Vars.put(((Variable)nvs.arg(1).arg(2)).term_, new Variable(nvs.arg(1).arg(1).name())); // map the Prolog variable to a new, named Variable
|
||||
nvs = nvs.arg(2); // advance to next list cell
|
||||
}
|
||||
|
||||
// maybe oughta check that nvs is [] ?
|
||||
return vars_to_Vars;
|
||||
} catch (java.lang.ClassCastException e) { // nvs is not of the expected structure
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// textToTerm
|
||||
/**
|
||||
* Converts a Prolog source text to a corresponding JPL Term
|
||||
* (in which each Variable has the appropriate name from the source text).
|
||||
* Throws PrologException containing error(syntax_error(_),_) if text is invalid.
|
||||
*
|
||||
* @param text A Prolog source text denoting a term
|
||||
* @return Term a JPL Term equivalent to the given source text
|
||||
*/
|
||||
public static Term textToTerm(String text) {
|
||||
// it might be better to use PL_chars_to_term()
|
||||
Query q = new Query(new Compound("atom_to_term", new Term[] { new Atom(text), new Variable("Term"), new Variable("NVdict")}));
|
||||
q.open();
|
||||
Map s = q.getSubstWithNameVars();
|
||||
if (s != null) {
|
||||
q.close();
|
||||
return (Term) s.get("Term");
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
301
LGPL/JPL/java/jpl/Variable.java
Normal file
301
LGPL/JPL/java/jpl/Variable.java
Normal file
@ -0,0 +1,301 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Variable.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 2004 Paul Singleton
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import jpl.fli.Prolog;
|
||||
import jpl.fli.term_t;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Variable
|
||||
/**
|
||||
* This class supports Java representations of Prolog variables.<p>
|
||||
*
|
||||
* A jpl.Variable instance is equivalent to a variable in a fragment of Prolog source text:
|
||||
* it is *not* a "live" variable within a Prolog stack or heap.
|
||||
* A corresponding Prolog variable is created only upon opening
|
||||
* a Query whose goal refers to a Variable (and then only temporarily).
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 2004 Paul Singleton<p>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class Variable extends Term {
|
||||
|
||||
//==================================================================/
|
||||
// Attributes
|
||||
//==================================================================/
|
||||
|
||||
private static long n = 0; // the integral part of the next automatic variable name to be allocated
|
||||
|
||||
public final String name; // the name of this Variable
|
||||
|
||||
protected transient term_t term_ = null; // defined between Query.open() and Query.get2()
|
||||
protected transient int index; // only used by (redundant?)
|
||||
|
||||
//==================================================================/
|
||||
// Constructors
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Create a new Variable with 'name' (which must not be null or ""),
|
||||
* and may one day be constrained to comply with traditional Prolog syntax.
|
||||
*
|
||||
* @param name the source name of this Variable
|
||||
*/
|
||||
public Variable(String name) {
|
||||
if (name == null) {
|
||||
throw new JPLException("constructor jpl.Variable(name): name cannot be null");
|
||||
}
|
||||
if (!isValidName(name)) {
|
||||
throw new JPLException("constructor jpl.Variable(name): name cannot be empty String");
|
||||
}
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Constructors (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Create a new Variable with new sequential name of the form "_261".
|
||||
*
|
||||
* @deprecated use Variable(String name) instead
|
||||
*/
|
||||
public Variable() {
|
||||
this.name = "_" + Long.toString(n++); // e.g. _0, _1 etc.
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (common)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* returns the lexical name of this Variable
|
||||
*
|
||||
* @return the lexical name of this Variable
|
||||
*/
|
||||
public final String name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Prolog source text representation of this Variable
|
||||
*
|
||||
* @return a Prolog source text representation of this Variable
|
||||
*/
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Variable is equal to another if their names are the same and they are not anonymous.
|
||||
*
|
||||
* @param obj The Object to compare.
|
||||
* @return true if the Object is a Variable and the above condition apply.
|
||||
*/
|
||||
public final boolean equals(Object obj) {
|
||||
return obj instanceof Variable && !this.name.equals("_") && this.name.equals(((Variable) obj).name);
|
||||
}
|
||||
|
||||
public final int type() {
|
||||
return Prolog.VARIABLE;
|
||||
}
|
||||
|
||||
public String typeName() {
|
||||
return "Variable";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (private)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Tests the lexical validity of s as a variable's name
|
||||
*
|
||||
* @return the lexical validity of s as a variable's name
|
||||
* @deprecated
|
||||
*/
|
||||
private boolean isValidName(String s) {
|
||||
if (s == null) {
|
||||
throw new java.lang.NullPointerException(); // JPL won't call it this way
|
||||
}
|
||||
int len = s.length();
|
||||
if (len == 0) {
|
||||
throw new JPLException("invalid variable name");
|
||||
}
|
||||
char c = s.charAt(0);
|
||||
if (!(c == '_' || c >= 'A' && c <= 'Z')) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 1; i < len; i++) {
|
||||
c = s.charAt(i);
|
||||
if (!(c == '_' || c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z' || c >= '0' && c <= '9')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Methods (deprecated)
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* The (nonexistent) args of this Variable
|
||||
*
|
||||
* @return the (nonexistent) args of this Variable
|
||||
* @deprecated
|
||||
*/
|
||||
public Term[] args() {
|
||||
return new Term[] {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a debug-friendly String representation of an Atom.
|
||||
*
|
||||
* @return a debug-friendly String representation of an Atom
|
||||
* @deprecated
|
||||
*/
|
||||
public String debugString() {
|
||||
return "(Variable " + toString() + ")";
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting JPL Terms to Prolog terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* To put a Variable, we must check whether a (non-anonymous) variable with the same name
|
||||
* has already been put in the Term. If one has, then the corresponding Prolog variable has
|
||||
* been stashed in the varnames_to_vars Map, keyed by the Variable name, so we can look
|
||||
* it up and reuse it (this way, the sharing of variables in the Prolog term
|
||||
* reflects the sharing of Variable names in the Term.
|
||||
* Otherwise, if this Variable name has not
|
||||
* already been seen in the Term, then we put a new Prolog variable and add it into the Map
|
||||
* (keyed by this Variable name).
|
||||
*
|
||||
* @param varnames_to_vars A Map from variable names to Prolog variables.
|
||||
* @param term A (previously created) term_t which is to be
|
||||
* set to a (new or reused) Prolog variable.
|
||||
*/
|
||||
protected final void put(Map varnames_to_vars, term_t term) {
|
||||
term_t var;
|
||||
// if this var is anonymous or as yet unseen, put a new Prolog variable
|
||||
if (this.name.equals("_") || (var = (term_t) varnames_to_vars.get(this.name)) == null) {
|
||||
this.term_ = term;
|
||||
this.index = varnames_to_vars.size(); // i.e. first var in is #0 etc.
|
||||
Prolog.put_variable(term);
|
||||
if (!this.name.equals("_")) {
|
||||
varnames_to_vars.put(this.name, term);
|
||||
}
|
||||
} else {
|
||||
this.term_ = var;
|
||||
Prolog.put_term(term, var);
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Converting Prolog terms to JPL Terms
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* Converts a term_t (known to refer to a Prolog variable) to a Variable.
|
||||
* If the variable has already been seen (and hence converted),
|
||||
* return its corresponding Variable from the map,
|
||||
* else create a new Variable, stash it in the map (keyed by the Prolog variable),
|
||||
* and return it.
|
||||
*
|
||||
* @param vars_to_Vars a map from Prolog to JPL variables
|
||||
* @param var The term_t (known to be a variable) to convert
|
||||
* @return A new or reused Variable
|
||||
*/
|
||||
protected static Term getTerm(Map vars_to_Vars, term_t var) {
|
||||
|
||||
for (Iterator i = vars_to_Vars.keySet().iterator(); i.hasNext();) {
|
||||
term_t varX = (term_t) i.next(); // a previously seen Prolog variable
|
||||
if (Prolog.compare(varX, var) == 0) { // identical Prolog variables?
|
||||
return (Term) vars_to_Vars.get(varX); // return the associated JPL Variable
|
||||
}
|
||||
}
|
||||
// otherwise, the Prolog variable in term has not been seen before
|
||||
Variable Var = new Variable(); // allocate a new (sequentially named) Variable to represent it
|
||||
Var.term_ = var; // this should become redundant...
|
||||
vars_to_Vars.put(var, Var); // use Hashtable(var,null), but only need set(var)
|
||||
return Var;
|
||||
}
|
||||
|
||||
//==================================================================/
|
||||
// Computing Substitutions
|
||||
//==================================================================/
|
||||
|
||||
/**
|
||||
* If this Variable instance is not an anonymous or (in dont-tell-me mode) a dont-tell-me variable, and its binding is not already in the varnames_to_Terms Map,
|
||||
* put the result of converting the term_t to which this variable
|
||||
* has been unified to a Term in the Map, keyed on this Variable's name.
|
||||
*
|
||||
* @param varnames_to_Terms A Map of bindings from variable names to JPL Terms.
|
||||
* @param vars_to_Vars A Map from Prolog variables to JPL Variables.
|
||||
*/
|
||||
protected final void getSubst(Map varnames_to_Terms, Map vars_to_Vars) {
|
||||
// NB a Variable.name cannot be "" i.e. of 0 length
|
||||
// if (!(this.name.charAt(0) == '_') && varnames_to_Terms.get(this.name) == null) {
|
||||
if (tellThem() && varnames_to_Terms.get(this.name) == null) {
|
||||
varnames_to_Terms.put(this.name, Term.getTerm(vars_to_Vars, this.term_));
|
||||
}
|
||||
}
|
||||
|
||||
// whether, according to prevailing policy and theis Variable's name,
|
||||
// any binding should be returned
|
||||
// (yes, unless it's anonymous or we're in dont-tell-me mode and its a dont-tell-me variable)
|
||||
private final boolean tellThem() {
|
||||
return !(this.name.equals("_") || jpl.JPL.modeDontTellMe && this.name.charAt(0) == '_');
|
||||
// return !this.name.equals("_");
|
||||
}
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
9
LGPL/JPL/java/jpl/Version.java
Normal file
9
LGPL/JPL/java/jpl/Version.java
Normal file
@ -0,0 +1,9 @@
|
||||
// $Id: Version.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
package jpl;
|
||||
class Version
|
||||
{
|
||||
public final int major = 3;
|
||||
public final int minor = 0;
|
||||
public final int patch = 3;
|
||||
public final String status = "alpha";
|
||||
}
|
60
LGPL/JPL/java/jpl/fli/BooleanHolder.java
Normal file
60
LGPL/JPL/java/jpl/fli/BooleanHolder.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: BooleanHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// BooleanHolder
|
||||
/**
|
||||
* A BooleanHolder is merely a Holder class for a boolean value.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class BooleanHolder
|
||||
{
|
||||
public boolean value;
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
60
LGPL/JPL/java/jpl/fli/DoubleHolder.java
Normal file
60
LGPL/JPL/java/jpl/fli/DoubleHolder.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: DoubleHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// DoubleHolder
|
||||
/**
|
||||
* A DoubleHolder is merely a Holder class for a double value.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class DoubleHolder
|
||||
{
|
||||
public double value;
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
60
LGPL/JPL/java/jpl/fli/IntHolder.java
Normal file
60
LGPL/JPL/java/jpl/fli/IntHolder.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: IntHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// IntHolder
|
||||
/**
|
||||
* An IntHolder is merely a Holder class for an Int value.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class IntHolder
|
||||
{
|
||||
public int value;
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
61
LGPL/JPL/java/jpl/fli/LongHolder.java
Normal file
61
LGPL/JPL/java/jpl/fli/LongHolder.java
Normal file
@ -0,0 +1,61 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: LongHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// LongHolder
|
||||
/**
|
||||
* A Long Holder merely holds a long value.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class LongHolder {
|
||||
public long value = 0L;
|
||||
|
||||
public boolean equals(LongHolder lh) {
|
||||
return lh.value == this.value;
|
||||
}
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
60
LGPL/JPL/java/jpl/fli/ObjectHolder.java
Normal file
60
LGPL/JPL/java/jpl/fli/ObjectHolder.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: ObjectHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// ObjectHolder
|
||||
/**
|
||||
* A ObjectHolder is merely a Holder class for an Object reference (or null).
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class ObjectHolder
|
||||
{
|
||||
public Object value;
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
63
LGPL/JPL/java/jpl/fli/PointerHolder.java
Normal file
63
LGPL/JPL/java/jpl/fli/PointerHolder.java
Normal file
@ -0,0 +1,63 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: PointerHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// PointerHolder
|
||||
/**
|
||||
* A PointerHolder is a trivial extension of a LongHolder. This is sort of
|
||||
* a no-no in Java, as the long value stored herein is sometimes a
|
||||
* machine address. (Don't tell Sun.)
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
// There could be issues in the future with signedness, since Java
|
||||
// does not have an unsigned type; make sure not to do any arithmetic
|
||||
// with the stored value.
|
||||
//----------------------------------------------------------------------/
|
||||
public class PointerHolder extends LongHolder
|
||||
{
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
240
LGPL/JPL/java/jpl/fli/Prolog.java
Normal file
240
LGPL/JPL/java/jpl/fli/Prolog.java
Normal file
@ -0,0 +1,240 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: Prolog.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// Prolog
|
||||
/**
|
||||
* This class consists only of constants (static finals) and static
|
||||
* native methods. The constants and methods defined herein are in
|
||||
* (almost) strict 1-1 correspondence with the functions in the Prolog
|
||||
* FLI by the same name (except without the PL_, SQ_, etc. prefixes).<p>
|
||||
*
|
||||
* See the file jpl_fli_Prolog.c for the native implementations of these
|
||||
* methods. Refer to your local Prolog FLI documentations for the meanings
|
||||
* of these methods, and observe the following:<p>
|
||||
*
|
||||
* <menu>
|
||||
* <li> The types and signatures of the following methods are almost
|
||||
* in 1-1 correspondence with the Prolog FLI. The Prolog types
|
||||
* term_t, atom_t, functor_t, etc. are mirrored in this package with
|
||||
* classes by the same name, making the C and Java uses of these
|
||||
* interfaces similar.</li>
|
||||
* <li> As term_t, functor_t, etc. types are Java classes, they are
|
||||
* passed to these methods <b>by value</b>; however, calling these
|
||||
* methods on such class instances does have side effects. In general,
|
||||
* the value fields of these instances will be modified, in much the
|
||||
* same way the term_t, functor_t, etc. Prolog instances would be
|
||||
* modified.</li>
|
||||
* <li> The exceptions to this rule occur when maintaining the same
|
||||
* signature would be impossible, e.g., when the Prolog FLI functions
|
||||
* require <i>pointers</i>; in this case, the signatures have been
|
||||
* modified to take *Holder classes (Int, Double, String, etc.),
|
||||
* to indicate a call by reference parameter.
|
||||
* <li> Functions which take variable-length argument lists in C
|
||||
* take arrays in Java; from Java 1.1 onwards, anonymous arrays
|
||||
* can be used e.g. Term[] { new Atom("a"), new Atom ("b") }
|
||||
* </menu>
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
public final class Prolog {
|
||||
static {
|
||||
System.loadLibrary("jpl");
|
||||
}
|
||||
|
||||
/* term types */
|
||||
public static final int VARIABLE = 1;
|
||||
public static final int ATOM = 2;
|
||||
public static final int INTEGER = 3;
|
||||
public static final int FLOAT = 4;
|
||||
public static final int STRING = 5;
|
||||
public static final int COMPOUND = 6;
|
||||
|
||||
public static final int JBOOLEAN = 101;
|
||||
public static final int JREF = 102;
|
||||
public static final int JVOID = 103;
|
||||
|
||||
/**
|
||||
* @deprecated use Prolog.COMPOUND
|
||||
*/
|
||||
public static final int TERM = 6;
|
||||
|
||||
public static final int succeed = 1;
|
||||
public static final int fail = 0;
|
||||
|
||||
/* query flags */
|
||||
public static final int Q_NORMAL = 0x02;
|
||||
public static final int Q_NODEBUG = 0x04;
|
||||
public static final int Q_CATCH_EXCEPTION = 0x08;
|
||||
public static final int Q_PASS_EXCEPTION = 0x10;
|
||||
|
||||
/* conversion flags */
|
||||
public static final int CVT_ATOM = 0x0001;
|
||||
public static final int CVT_STRING = 0x0002;
|
||||
public static final int CVT_LIST = 0x0004;
|
||||
public static final int CVT_INTEGER = 0x0008;
|
||||
public static final int CVT_FLOAT = 0x0010;
|
||||
public static final int CVT_VARIABLE = 0x0020;
|
||||
public static final int CVT_NUMBER = (CVT_INTEGER | CVT_FLOAT);
|
||||
public static final int CVT_ATOMIC = (CVT_NUMBER | CVT_ATOM | CVT_STRING);
|
||||
public static final int CVT_ALL = 0x00ff;
|
||||
public static final int BUF_DISCARDABLE = 0x0000;
|
||||
public static final int BUF_RING = 0x0100;
|
||||
public static final int BUF_MALLOC = 0x0200;
|
||||
|
||||
/* new, for revised term_t-to-Variable stuff */
|
||||
public static native int compare(term_t t1, term_t t2); // returns -1, 0 or 1
|
||||
|
||||
/* Creating and destroying term-refs */
|
||||
public static native term_t new_term_ref();
|
||||
public static native term_t new_term_refs(int n);
|
||||
public static native term_t copy_term_ref(term_t from);
|
||||
public static native void reset_term_refs(term_t r);
|
||||
|
||||
/* Constants */
|
||||
public static native atom_t new_atom(String s);
|
||||
public static native String atom_chars(atom_t a);
|
||||
public static native functor_t new_functor(atom_t f, int a);
|
||||
public static native atom_t functor_name(functor_t f);
|
||||
public static native int functor_arity(functor_t f);
|
||||
|
||||
public static native void unregister_atom(atom_t a); // called from atom_t's finalize()
|
||||
|
||||
/* Get Java-values from Prolog terms */
|
||||
public static native boolean get_atom(term_t t, atom_t a);
|
||||
public static native boolean get_atom_chars(term_t t, StringHolder a);
|
||||
public static native boolean get_string_chars(term_t t, StringHolder s);
|
||||
public static native boolean get_integer(term_t t, IntHolder i);
|
||||
public static native boolean get_pointer(term_t t, PointerHolder ptr);
|
||||
public static native boolean get_float(term_t t, DoubleHolder d);
|
||||
public static native boolean get_functor(term_t t, functor_t f);
|
||||
public static native boolean get_name_arity(term_t t, StringHolder name, IntHolder arity);
|
||||
public static native boolean get_module(term_t t, module_t module);
|
||||
public static native boolean get_arg(int index, term_t t, term_t a);
|
||||
|
||||
public static native boolean get_jref(term_t t, ObjectHolder obj);
|
||||
public static native boolean get_jboolean(term_t t, BooleanHolder b);
|
||||
|
||||
/* Verify types */
|
||||
public static native int term_type(term_t t);
|
||||
public static native boolean is_variable(term_t t);
|
||||
public static native boolean is_atom(term_t t);
|
||||
public static native boolean is_integer(term_t t);
|
||||
public static native boolean is_float(term_t t);
|
||||
public static native boolean is_compound(term_t t);
|
||||
public static native boolean is_functor(term_t t, functor_t f);
|
||||
public static native boolean is_atomic(term_t t);
|
||||
public static native boolean is_number(term_t t);
|
||||
|
||||
/* Assign to term-references */
|
||||
public static native void put_variable(term_t t);
|
||||
public static native void put_atom(term_t t, atom_t a);
|
||||
public static native void put_integer(term_t t, long i);
|
||||
public static native void put_pointer(term_t t, PointerHolder ptr);
|
||||
public static native void put_float(term_t t, double f);
|
||||
public static native void put_functor(term_t t, functor_t functor);
|
||||
public static native void put_term(term_t t1, term_t t2);
|
||||
public static native void put_jref(term_t t, Object ref);
|
||||
public static native void put_jboolean(term_t t, boolean b);
|
||||
public static native void put_jvoid(term_t t);
|
||||
|
||||
/* ... */
|
||||
public static native void cons_functor_v(term_t h, functor_t fd, term_t a0);
|
||||
public static native void cons_list(term_t l, term_t h, term_t t);
|
||||
|
||||
// unification:
|
||||
// public static native int unify(term_t t1, term_t t2);
|
||||
|
||||
// predicates:
|
||||
public static native predicate_t pred(functor_t f, module_t m);
|
||||
public static native predicate_t predicate(String name, int arity, String module);
|
||||
public static native int predicate_info(predicate_t pred, atom_t name, IntHolder arity, module_t module);
|
||||
|
||||
// querying (general):
|
||||
public static native qid_t open_query(module_t m, int flags, predicate_t pred, term_t t0);
|
||||
public static native boolean next_solution(qid_t qid);
|
||||
public static native void close_query(qid_t qid);
|
||||
public static native void cut_query(qid_t qid);
|
||||
|
||||
// querying (simplified):
|
||||
public static native boolean call(term_t t, module_t m);
|
||||
public static native boolean call_predicate(module_t m, int debug, predicate_t pred, term_t t0);
|
||||
|
||||
// foreign frames:
|
||||
public static native fid_t open_foreign_frame();
|
||||
public static native void close_foreign_frame(fid_t cid);
|
||||
public static native void discard_foreign_frame(fid_t cid);
|
||||
|
||||
// modules:
|
||||
public static native module_t context();
|
||||
public static native atom_t module_name(module_t module);
|
||||
public static native module_t new_module(atom_t name);
|
||||
public static native int strip_module(term_t in, module_t m, term_t out);
|
||||
|
||||
// not yet mapped: raise_exception()
|
||||
// not yet mapped: throw()
|
||||
|
||||
// exceptions:
|
||||
public static native term_t exception(qid_t qid);
|
||||
|
||||
// initialisation:
|
||||
public static native String[] get_default_init_args();
|
||||
public static native boolean set_default_init_args(String argv[]);
|
||||
public static native boolean initialise();
|
||||
public static native String[] get_actual_init_args();
|
||||
public static native void halt(int status);
|
||||
|
||||
// thread & engine management:
|
||||
public static native int thread_self();
|
||||
public static native engine_t attach_pool_engine();
|
||||
public static native int release_pool_engine();
|
||||
public static native engine_t current_engine();
|
||||
public static native boolean current_engine_is_pool();
|
||||
public static native String get_c_lib_version();
|
||||
|
||||
public static native int action_abort();
|
||||
public static native int attach_engine(engine_t e);
|
||||
public static native int pool_engine_id(engine_t e);
|
||||
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
60
LGPL/JPL/java/jpl/fli/StringHolder.java
Normal file
60
LGPL/JPL/java/jpl/fli/StringHolder.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: StringHolder.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// StringHolder
|
||||
/**
|
||||
* A StringHolder is merely a Holder class for a String value.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class StringHolder
|
||||
{
|
||||
public String value;
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
82
LGPL/JPL/java/jpl/fli/atom_t.java
Normal file
82
LGPL/JPL/java/jpl/fli/atom_t.java
Normal file
@ -0,0 +1,82 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: atom_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// atom_t
|
||||
/**
|
||||
* An atom_t is a specialised LongHolder which decrements its atom's
|
||||
* reference count when garbage-collected (finalized).
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class atom_t
|
||||
extends LongHolder
|
||||
{
|
||||
//------------------------------------------------------------------/
|
||||
// toString
|
||||
/**
|
||||
* The String representation of an atom_t is just the atom's name.
|
||||
*
|
||||
* @return atom's name
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//------------------------------------------------------------------/
|
||||
public String
|
||||
toString()
|
||||
{
|
||||
return Prolog.atom_chars( this );
|
||||
}
|
||||
|
||||
protected void finalize() throws Throwable {
|
||||
|
||||
super.finalize();
|
||||
Prolog.unregister_atom( this);
|
||||
}
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
56
LGPL/JPL/java/jpl/fli/engine_t.java
Normal file
56
LGPL/JPL/java/jpl/fli/engine_t.java
Normal file
@ -0,0 +1,56 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: engine_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// engine_t
|
||||
/**
|
||||
* A engine_t holds a reference to a Prolog engine.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes: Note that a engine_t is not a term,
|
||||
// consistent with the treatment in the Prolog FLI.
|
||||
//----------------------------------------------------------------------/
|
||||
public class engine_t extends LongHolder {
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
60
LGPL/JPL/java/jpl/fli/fid_t.java
Normal file
60
LGPL/JPL/java/jpl/fli/fid_t.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: fid_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// fid_t
|
||||
/**
|
||||
* An fid_t holds the value of a frame id in the Prolog Engine.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class fid_t
|
||||
extends LongHolder
|
||||
{
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
61
LGPL/JPL/java/jpl/fli/functor_t.java
Normal file
61
LGPL/JPL/java/jpl/fli/functor_t.java
Normal file
@ -0,0 +1,61 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: functor_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// functor_t
|
||||
/**
|
||||
* A functor_t holds a reference to a Prolog functor_t in the
|
||||
* Prolog engine.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes: Note that a functor_t is not a term,
|
||||
// consistent with the treatment in the Prolog FLI.
|
||||
//----------------------------------------------------------------------/
|
||||
public class functor_t
|
||||
extends LongHolder
|
||||
{
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
61
LGPL/JPL/java/jpl/fli/module_t.java
Normal file
61
LGPL/JPL/java/jpl/fli/module_t.java
Normal file
@ -0,0 +1,61 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: module_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// module_t
|
||||
/**
|
||||
* A module_t is a PointerHolder type which holds a reference to a Prolog
|
||||
* module_t reference.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class module_t
|
||||
extends PointerHolder
|
||||
{
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
61
LGPL/JPL/java/jpl/fli/predicate_t.java
Normal file
61
LGPL/JPL/java/jpl/fli/predicate_t.java
Normal file
@ -0,0 +1,61 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: predicate_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// predicate_t
|
||||
/**
|
||||
* A predicate_t is a PointerHolder class whose value is a reference to a
|
||||
* Prolog predicate_t.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class predicate_t
|
||||
extends PointerHolder
|
||||
{
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
60
LGPL/JPL/java/jpl/fli/qid_t.java
Normal file
60
LGPL/JPL/java/jpl/fli/qid_t.java
Normal file
@ -0,0 +1,60 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: qid_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// qid_t
|
||||
/**
|
||||
* A qid_t holds a reference to a Prolog qid_t.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class qid_t
|
||||
extends LongHolder
|
||||
{
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
133
LGPL/JPL/java/jpl/fli/term_t.java
Normal file
133
LGPL/JPL/java/jpl/fli/term_t.java
Normal file
@ -0,0 +1,133 @@
|
||||
//tabstop=4
|
||||
//*****************************************************************************/
|
||||
// Project: jpl
|
||||
//
|
||||
// File: $Id: term_t.java,v 1.1 2004-08-27 20:27:56 vsc Exp $
|
||||
// Date: $Date: 2004-08-27 20:27:56 $
|
||||
// Author: Fred Dushin <fadushin@syr.edu>
|
||||
//
|
||||
//
|
||||
// Description:
|
||||
//
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
// Copyright (c) 1998 Fred Dushin
|
||||
// All rights reserved.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Library Public License
|
||||
// as published by the Free Software Foundation; either version 2
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Library Public License for more details.
|
||||
//*****************************************************************************/
|
||||
package jpl.fli;
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------/
|
||||
// term_t
|
||||
/**
|
||||
* A term_t is a simple class which mirrors the term_t type in
|
||||
* the Prolog FLI. All it really does is hold a term reference,
|
||||
* which is an internal representation of a term in the Prolog
|
||||
* Engine.
|
||||
*
|
||||
* <hr><i>
|
||||
* Copyright (C) 1998 Fred Dushin<p>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.<p>
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library Public License for more details.<p>
|
||||
* </i><hr>
|
||||
* @author Fred Dushin <fadushin@syr.edu>
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//----------------------------------------------------------------------/
|
||||
public class term_t
|
||||
extends LongHolder
|
||||
{
|
||||
public static final long UNASSIGNED = -1L;
|
||||
|
||||
public
|
||||
term_t()
|
||||
{
|
||||
value = UNASSIGNED;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// toString
|
||||
/**
|
||||
* This static method converts a term_t, which is assumed to contain
|
||||
* a reference to a *consecutive* list of term_t references to a
|
||||
* String representation of a list of terms, in this case, a comma
|
||||
* separated list.
|
||||
*
|
||||
* @param n the number of consecutive term_ts
|
||||
* @param term0 a term_t whose value is the 0th term_t.
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//------------------------------------------------------------------/
|
||||
public static String
|
||||
toString( int n, term_t term0 )
|
||||
{
|
||||
String s = "";
|
||||
int i;
|
||||
long ith_term_t;
|
||||
|
||||
for ( i = 0, ith_term_t = term0.value; i < n; ++i, ++ith_term_t ){
|
||||
term_t term = new term_t();
|
||||
term.value = ith_term_t;
|
||||
s += term.toString();
|
||||
|
||||
if ( i != n - 1 ){
|
||||
s += ", ";
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------/
|
||||
// equals
|
||||
/**
|
||||
* Instances of term_ts are stored in Term objects (see jpl.Term),
|
||||
* and these term_ts are in some cases stored in Hashtables.
|
||||
* Supplying this predicate provides the right behavior in Hashtable
|
||||
* lookup (see the rules for Hashtable lookup in java.util).<p>
|
||||
*
|
||||
* Note. Two term_ts are *not* equal if their values have not
|
||||
* been assigned. (Since Prolog FLI term_ts are unsigned values and
|
||||
* the UNASSIGNED value is -1, this should work).
|
||||
*
|
||||
* @param obj the Object to comapre.
|
||||
* @return true if the supplied object is a term_t instances
|
||||
* and the long values are the same
|
||||
*/
|
||||
// Implementation notes:
|
||||
//
|
||||
//------------------------------------------------------------------/
|
||||
public boolean
|
||||
equals( Object obj )
|
||||
{
|
||||
return
|
||||
(obj instanceof term_t) &&
|
||||
this.value == ((term_t)obj).value &&
|
||||
this.value != UNASSIGNED;
|
||||
}
|
||||
}
|
||||
|
||||
//345678901234567890123456789012346578901234567890123456789012345678901234567890
|
4255
LGPL/JPL/jpl.yap
Normal file
4255
LGPL/JPL/jpl.yap
Normal file
File diff suppressed because it is too large
Load Diff
63
LGPL/JPL/src/Makefile.in
Normal file
63
LGPL/JPL/src/Makefile.in
Normal file
@ -0,0 +1,63 @@
|
||||
#
|
||||
#
|
||||
JAVA_HOME=@JAVA_HOME@
|
||||
JVM_INC = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux
|
||||
JVM_LIB = -L$(JAVA_HOME)/jre/lib/i386 -L$(JAVA_HOME)/jre/lib/i386/client -ljava -lverify -ljvm
|
||||
#
|
||||
#
|
||||
#
|
||||
# default base directory for YAP installation
|
||||
# (EROOT for architecture-dependent files)
|
||||
#
|
||||
prefix = @prefix@
|
||||
ROOTDIR = $(prefix)
|
||||
EROOTDIR = @exec_prefix@
|
||||
#
|
||||
# where the binary should be
|
||||
#
|
||||
BINDIR = $(EROOTDIR)/bin
|
||||
#
|
||||
# where YAP should look for libraries
|
||||
#
|
||||
LIBDIR=$(EROOTDIR)/lib/Yap
|
||||
#
|
||||
#
|
||||
CC=@CC@
|
||||
CFLAGS= @CFLAGS@ $(YAP_EXTRAS) $(DEFS) -I$(srcdir) -I../.. -I$(srcdir)/../../../include -I$(srcdir)/../../../library/yap2swi $(JVM_INC) -DIN_YAP=1 -DJAVA_HOME=\"$(JAVA_HOME)\"
|
||||
#
|
||||
#
|
||||
# You shouldn't need to change what follows.
|
||||
#
|
||||
INSTALL=@INSTALL@
|
||||
INSTALL_DATA=@INSTALL_DATA@
|
||||
INSTALL_PROGRAM=@INSTALL_PROGRAM@
|
||||
SHELL=/bin/sh
|
||||
RANLIB=@RANLIB@
|
||||
srcdir=@srcdir@
|
||||
SHLIB_CFLAGS=@SHLIB_CFLAGS@
|
||||
SHLIB_SUFFIX=@SHLIB_SUFFIX@
|
||||
#4.1VPATH=@srcdir@:@srcdir@/OPTYap
|
||||
CWD=$(PWD)
|
||||
#
|
||||
|
||||
OBJS=jpl.o
|
||||
SOBJS=jpl@SHLIB_SUFFIX@
|
||||
|
||||
all: $(SOBJS)
|
||||
|
||||
jpl.o: $(srcdir)/jpl.c
|
||||
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/jpl.c -o jpl.o
|
||||
|
||||
|
||||
@DO_SECOND_LD@%@SHLIB_SUFFIX@: %.o
|
||||
@DO_SECOND_LD@ @SHLIB_LD@ -o $@ $<
|
||||
|
||||
@DO_SECOND_LD@jpl_jni@SHLIB_SUFFIX@: jpl_jni.o jvm.o
|
||||
@DO_SECOND_LD@ @SHLIB_LD@ -o jpl_jni@SHLIB_SUFFIX@ jpl.o $(JVM_LIB)
|
||||
|
||||
install: all
|
||||
$(INSTALL_PROGRAM) $(SOBJS) $(DESTDIR)$(LIBDIR)
|
||||
|
||||
clean:
|
||||
rm -f *.o *~ $(OBJS) $(SOBJS) *.BAK
|
||||
|
6649
LGPL/JPL/src/jpl.c
Normal file
6649
LGPL/JPL/src/jpl.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user