|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object se.sics.jasper.SICStus
public class SICStus
This class encapsulates the SICStus emulator and provides the basic functionality for interacting with Prolog. The User's Manual documents in more detail how to use this class. Refer to that document for more information.
This class uses native
methods to interface with
the C-Prolog interface of SICStus Prolog. Hence, this class cannot
be used from within an applet.
You should not inherit from SICStus
.
Constructor Summary | |
---|---|
SICStus()
Creates a SICStus object. |
|
SICStus(java.lang.String bootPath)
Creates a SICStus object. |
|
SICStus(java.lang.String[] argv,
java.lang.String bootPath)
Creates a SICStus object. |
Method Summary | |
---|---|
Term |
consFunctor(java.lang.String functor,
Term[] args)
Creates a term initialized to a compound term. |
Term |
consList(Term head,
Term tail)
Creates a term initialized to a list with given head and tail. |
int |
debugLevel()
Currently Unsupported; see the Release Notes. |
static SICStus |
getCaller()
Returns the SICStus object corresponding to the SICStus runtime that called us. |
static SICStus |
getInitializedSICStus()
Deprecated, do not use. |
se.sics.jasper.Server |
getServer()
For internal use by Jasper. |
void |
init()
Does nothing. |
Term |
listFromString(java.lang.String str)
Creates a term initialized to a list of character codes from a Java String . |
void |
load(java.lang.String file)
Interface to SP_load() , which in turn calls the
Prolog predicate load_files/[1,2] (See the User's
Manual). |
static void |
main(java.lang.String[] argv)
This main-function is just a small test function. |
Term |
newObjectTerm(java.lang.Object obj)
Creates a term initialized to a *global* reference to a Java object. |
Prolog |
newProlog()
Returns the Prolog interface for this SICStus object. |
Term |
newTerm()
Creates a null-term (i.e. the empty list, '[]'). |
Term |
newTerm(double d)
Creates a term initialized to a Prolog float. |
Term |
newTerm(java.lang.Double d)
|
Term |
newTerm(float f)
Creates a term initialized to a Prolog float. |
Term |
newTerm(java.lang.Float f)
|
Term |
newTerm(int i)
Creates a term initialized to a Prolog integer from a Java int . |
Term |
newTerm(java.lang.Integer i)
|
Term |
newTerm(long j)
Creates a term initialized to a Prolog integer from a Java long . |
Term |
newTerm(java.lang.Long j)
|
Term |
newTerm(java.lang.String a)
Creates a term initialized to a Prolog atom. |
Term |
newTerm(java.lang.String functor,
Term[] args)
Creates a term initialized to a Prolog compound term. |
Term |
newTerm(Term t)
Creates a term initialized to an existing term. |
Term |
newVariable()
Creates a term initialized to an unbound variable. |
Term |
numberFromString(java.lang.String str)
Creates a term initialized to a Prolog number from a string. |
Query |
openPrologQuery(java.lang.String string,
java.util.Map varMap)
Opens a query, specified as a string, for obtaining multiple solutions. |
SPQuery |
openQuery(SPPredicate pred,
SPTerm[] args)
Deprecated Use module and predicate name directly instead. |
SPQuery |
openQuery(java.lang.String string,
java.util.Map varMap)
Opens a query, specified as a string, for obtaining multiple solutions. |
SPQuery |
openQuery(java.lang.String module,
java.lang.String name,
SPTerm[] args)
Opens a query for obtaining multiple solutions. |
Term |
prologReadFromString(java.lang.String string,
java.util.Map varMap)
Creates a term by reading from a string. |
boolean |
query(SPPredicate pred,
SPTerm[] args)
Deprecated Use module and predicate name directly instead. |
boolean |
query(java.lang.String string,
java.util.Map varMap)
Finds the first solution to a query specified as a string. |
boolean |
query(java.lang.String module,
java.lang.String name,
SPTerm[] args)
Finds the first solution to a query. |
boolean |
queryCutFail(SPPredicate pred,
SPTerm[] args)
Deprecated Use module and predicate name directly instead. |
boolean |
queryCutFail(java.lang.String string,
java.util.Map varMap)
Finds the first solution to a query specified as a string, then cuts away any choicepoints and fails, i.e. ignores everything but the side-effects during the first solution. |
boolean |
queryCutFail(java.lang.String module,
java.lang.String name,
SPTerm[] args)
Finds the first solution to a query, then cuts away any choicepoints and fails, i.e. ignores everything but the side-effects during the first solution. |
SPTerm |
readFromString(java.lang.String string)
Equivalent to readFromString(string, null); |
SPTerm |
readFromString(java.lang.String string,
java.util.Map varMap)
Creates a term by reading from a string. |
void |
restore(java.lang.String savFile)
Interface to SP_restore() . |
boolean |
reuseTermRefs()
Unsupported. |
int |
setDebugLevel(int level)
Currently Unsupported. |
int |
setPrintDepth(int level)
Currently Unsupported. |
boolean |
setReuseTermRefs(boolean newVal)
Unsupported; see the release notes for details. |
void |
setServer(se.sics.jasper.Server s)
For internal use by Jasper. |
boolean |
setShouldCheckAge(boolean newVal)
Currently Unsupported; see the release notes for details. |
boolean |
shouldCheckAge()
Currently Unsupported; see the release notes for details. |
void |
startServer()
Starts serving requests from a Prolog client. |
void |
stopServer()
Stops the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SICStus() throws SPException
SICStus(null,null)
.
SPException
- Something went wrong during startup.SPException
public SICStus(java.lang.String bootPath) throws SPException
SICStus(null,bootPath)
.
bootPath
- The path where SICStus should look for its
start-up files. Currently ignored.
SPException
- Something went wrong during
startup.SPException
,
SICStus(String[],String)
public SICStus(java.lang.String[] argv, java.lang.String bootPath) throws SPException
SP_initialize(argc, argv,
options)
. It initializes the emulator's memory manager,
allocates WAM memory areas, etc. It also loads the SICStus
Runtime Library (sprt.sav
), also known as the
bootfile. If the bootfile cannot be found, you may
specify the exact location of it by using the system property
sicstus.path
. If you need to set sicstus.path
,
it should be set to the parent directory of the directory where the
Runtime Library is located.
Any (Java) system property
se.sics.sicstus.property.
NAME will be
passed to the created SICStus instance as the (Prolog) system
property NAME (since 4.1.2).
This object can only be initialized once.
argv
- Argument vector to the emulator.bootPath
- The path where SICStus should look for its
start-up files. The value should be a path such that
<bootPath>/bin
contains
sprt.sav
. Currently ignored.
SPException
- Something went wrong during
startup.SPException
,
getInitializedSICStus()
Method Detail |
---|
public final boolean shouldCheckAge()
setShouldCheckAge(boolean)
public final boolean setShouldCheckAge(boolean newVal)
true
then the methods on SPTerm
will throw exceptions when used
in a way that may potentially create dangling pointers in the
Prolog heap. Returns the old value of the flag.
Off by default in the interest of backward compatibility since it will throw exception for some legal code. It is probably a good idea to turn this on for new code (and for existing non-production code). This flag will probably be on by default in the future, please try it and report good or bad experiences to sicstus-support@sics.se
Can be set with the
se.sics.jasper.SICStus.checkSPTermAge
system
property.
public final boolean reuseTermRefs()
setReuseTermRefs(boolean)
public final boolean setReuseTermRefs(boolean newVal)
false
then SPTerm.delete()
will not make the
SP_term_ref associated with the deleted SPTerm
object
available for re-use. Returns the old value of the flag.
This flag is currently on by default, there should be no reason to turn it off.
Can be set with the
se.sics.jasper.SICStus.reuseTermRefs
system property.
public final int debugLevel()
setDebugLevel(int)
public int setDebugLevel(int level)
se.sics.jasper.SICStus.debugLevel
system propery.
public static void main(java.lang.String[] argv)
SICStus()
public static SICStus getInitializedSICStus()
public void load(java.lang.String file) throws SPException
SP_load()
, which in turn calls the
Prolog predicate load_files/[1,2] (See the User's
Manual). Note: The preferred way to load
Prolog code is through restore
.
file
- The Prolog code to load. This can be a .pl-file,
or a .po-file.
SPException
- A Prolog exception was thrown.restore(java.lang.String)
public void restore(java.lang.String savFile) throws SPException
SP_restore()
. Restores the specified
.sav-file. This is the preferred way of loading Prolog code
instead of using load
.
This method must be called before any other SICStus
method is called, and may only be used if the SICStus object has been
created with new
. Note that calling this method will
unload all foreign resources.
Example:
% sicstus SICStus 3.7 beta3: Tue Jun 02 12:29:02 MET DST 1998 | ?- compile(bench),save_program('bench.sav'). {compiling /home/jojo/sicstus/sicstus3/bench.pl...} {/home/jojo/sicstus/sicstus3/bench.pl compiled, 90 msec 6384 bytes} {SICStus state saved in /home/jojo/sicstus/sicstus3/bench.sav} yes | ?- halt.and then restore
bench.sav
from Java by calling
SICStus.restore()
.
restore("bench.sav");
savFile
- The .sav-file to restore.
SPException
load(java.lang.String)
public int setPrintDepth(int level)
toString
method
of the class SPException
returns).
level
- The new maximum print depth for exception terms.
se.sics.jasper.SICStus.printDepth
system property.
The default value is 5.public boolean query(java.lang.String module, java.lang.String name, SPTerm[] args) throws SPException, IllegalTermException
openQuery
.
module
- The module used for the query.name
- The predicate name used for the query.args
- The arguments to the predicate. The number of
arguments must match the functor of the predicate.
SPException
- If a Prolog exception was thrown.
IllegalTermException
openQuery(java.lang.String, java.lang.String, se.sics.jasper.SPTerm[])
,
SPException
,
SPTerm
public boolean query(java.lang.String string, java.util.Map varMap) throws SPException
openQuery
.
query
in interface Prolog
string
- The goal to use for the query, with terminating period.varMap
- The arguments to the predicate as a map from
variable names to SPTerm objects. On success varMap will get
entries added for all variables (with names not starting with
underscore) in the goal that were not already present as
input. May be null.
Allocates one SPTerm
for each
entry added to the map (and, possibly, a small number of SPTerm
objects for internal use). If varMap is null then this method
behaves as if no SPTerm objects were created.
SPException
- If a Prolog exception was thrown.openQuery(java.lang.String, java.lang.String, se.sics.jasper.SPTerm[])
,
queryCutFail(java.lang.String, java.lang.String, se.sics.jasper.SPTerm[])
,
SPTerm
public boolean query(SPPredicate pred, SPTerm[] args) throws SPException, IllegalTermException
openQuery
.
pred
- The predicate object to use for the query.args
- The arguments to the predicate. The number of
arguments must match the functor of the predicate.
SPException
- If a Prolog exception was thrown.
IllegalTermException
openQuery(java.lang.String, java.lang.String, se.sics.jasper.SPTerm[])
,
SPException
,
SPPredicate
,
SPTerm
public boolean queryCutFail(java.lang.String module, java.lang.String name, SPTerm[] args) throws SPException
module
- The module used for the query.name
- The predicate name used for the query.args
- The arguments to the predicate.
SPException
SPException
public boolean queryCutFail(java.lang.String string, java.util.Map varMap) throws SPException
queryCutFail
in interface Prolog
string
- The goal to use for the query, with terminating period.varMap
- The arguments to the predicate as a map from
variable names to SPTerm objects. May be null. No bindings are
added.
SPException
query(java.lang.String, java.lang.String, se.sics.jasper.SPTerm[])
public boolean queryCutFail(SPPredicate pred, SPTerm[] args) throws SPException
pred
- The predicate object used for the query.args
- The arguments to the predicate. The number of
arguments must match the functor of the predicate.
SPException
SPException
,
SPPredicate
public SPQuery openQuery(java.lang.String module, java.lang.String name, SPTerm[] args) throws IllegalTermException, SPException
nextSolution
to do
that. When no more solutions are needed, the query must be closed
using methods close
or
cut
on the query-object.
Multiple queries can be open at the same
time. See nextSolution
for details and restrictions.
module
- The module used for the query.name
- The predicate name used for the query.args
- The arguments to the predicate. The number of
arguments must match the functor of the predicate.
query
object.
IllegalTermException
SPException
SPQuery.nextSolution()
,
SPQuery.close()
,
SPQuery.cut()
public SPQuery openQuery(java.lang.String string, java.util.Map varMap) throws SPException
nextSolution
to do that. When no more solutions are needed,
the query must be closed using methods close
or cut
on the query-object.
Multiple queries can be open at the same time. See nextSolution
for details
and restrictions.
Allocates one SPTerm
for each entry added to the map
(and, possibly, a small number of SPTerm objects for internal
use). If varMap is null then this method behaves as if no
SPTerm objects were created. When the query is closed (or cut)
then all SPTerm objects are reclaimed.
string
- The goal to use for the query, with terminating period.varMap
- The arguments to the predicate as a map from
variable names to SPTerm objects. The map will get
entries added for all variables (with names not starting with
underscore) in the goal that were not already present as
input. May be null.
query
object.
SPException
SPQuery.nextSolution()
,
SPQuery.close()
,
SPQuery.cut()
public SPQuery openQuery(SPPredicate pred, SPTerm[] args) throws IllegalTermException, SPException
nextSolution
to do
that. When no more solutions are needed, the query must be closed
using methods close
or
cut
on the query-object.
Multiple queries can be open at the same
time. See nextSolution
for details and restrictions.
pred
- The predicate-object to open a query on.args
- The arguments to the predicate. The number of
arguments must match the functor of the predicate.
query
object.
IllegalTermException
SPException
SPQuery.nextSolution()
,
SPQuery.close()
,
SPQuery.cut()
,
SPPredicate
public SPTerm readFromString(java.lang.String string, java.util.Map varMap) throws SPException
string
- The printed representation of the term, with terminating period.varMap
- Bindings for any variables occurring in the term,
as a map from variable names to SPTerm objects. The map will
get entries added for all variables (with names not starting
with underscore) in the term that were not already present as
input. May be null.
Allocates one SPTerm
for each
entry added to the map (and, possibly, a small number of SPTerm
objects for internal use). If varMap is null then this method
behaves as if only the returned SPTerm object were created.
SPException
public SPTerm readFromString(java.lang.String string) throws SPException
SPException
public Query openPrologQuery(java.lang.String string, java.util.Map varMap) throws SPException
Prolog
nextSolution
to do that. When no more solutions are needed,
the query must be closed using methods close
or cut
on the query-object.
Multiple queries can be open at the same time. See nextSolution
for details
and restrictions.
openPrologQuery
in interface Prolog
string
- The goal to use for the query, with terminating period.varMap
- The arguments to the predicate as a map from
variable names to Term objects. The map will get
entries added for all variables (with names not starting with
underscore) in the goal that were not already present as
input. May be null.
query
object.
SPException
Query.nextSolution()
,
Query.close()
,
Query.cut()
public Term prologReadFromString(java.lang.String string, java.util.Map varMap) throws SPException
Prolog
prologReadFromString
in interface Prolog
string
- The printed representation of the term, with terminating period.varMap
- Bindings for any variables occurring in the term,
as a map from variable names to Term objects. The map will
get entries added for all variables (with names not starting
with underscore) in the term that were not already present as
input. May be null.
SPException
public Term newTerm()
Prolog
newTerm
in interface Prolog
public Term newTerm(Term t) throws IllegalTermException, ConversionFailedException
Prolog
newTerm
in interface Prolog
t
- The Term object whose term to use
IllegalTermException
ConversionFailedException
public Term newTerm(java.lang.Integer i)
public Term newTerm(int i)
Prolog
int
.
newTerm
in interface Prolog
i
- Initial value of the integer.public Term newTerm(java.lang.Long j) throws IllegalTermException, ConversionFailedException
IllegalTermException
ConversionFailedException
public Term newTerm(long j) throws IllegalTermException, ConversionFailedException
Prolog
long
.
newTerm
in interface Prolog
j
- Initial value of the integer (long).
IllegalTermException
ConversionFailedException
public Term newTerm(java.lang.Double d)
public Term newTerm(double d)
Prolog
newTerm
in interface Prolog
d
- Initial value of the float.public Term newTerm(java.lang.Float f)
public Term newTerm(float f)
Prolog
newTerm
in interface Prolog
f
- Initial value of the float.public Term newTerm(java.lang.String a) throws ConversionFailedException
Prolog
newTerm
in interface Prolog
a
- String describing the initial value of the atom.
ConversionFailedException
public Term newTerm(java.lang.String functor, Term[] args) throws ConversionFailedException, IllegalTermException
Prolog
newTerm
in interface Prolog
functor
- The functor of the compound term as a stringargs
- The arguments as an array of Terms
ConversionFailedException
IllegalTermException
public Term newVariable() throws ConversionFailedException, IllegalTermException
Prolog
newVariable
in interface Prolog
ConversionFailedException
IllegalTermException
public Term consFunctor(java.lang.String functor, Term[] args) throws ConversionFailedException, IllegalTermException
Prolog
consFunctor
in interface Prolog
functor
- The term's functor as a Java String
args
- The arguments of the term
ConversionFailedException
IllegalTermException
public Term consList(Term head, Term tail) throws ConversionFailedException, IllegalTermException
Prolog
consList
in interface Prolog
head
- The head of the listtail
- The tail of the list
ConversionFailedException
IllegalTermException
public Term newObjectTerm(java.lang.Object obj) throws IllegalTermException, ConversionFailedException
Prolog
newObjectTerm
in interface Prolog
obj
- A reference to a Java object.
IllegalTermException
ConversionFailedException
public Term numberFromString(java.lang.String str) throws ConversionFailedException, IllegalTermException
Prolog
numberFromString
in interface Prolog
str
- The string containing the printed representation of the number.
ConversionFailedException
IllegalTermException
public Term listFromString(java.lang.String str) throws ConversionFailedException, IllegalTermException
Prolog
String
.
listFromString
in interface Prolog
str
- The string of characters.
ConversionFailedException
IllegalTermException
public Prolog newProlog() throws java.lang.InterruptedException
Prolog
) interface for this SICStus
object, and return the new client.
The server may be started by calling
startServer()
java.lang.InterruptedException
public static SICStus getCaller()
public void startServer()
stopServer()
.
Before calling this method you should call
newProlog()
and hand the result over to
another Thread
.
public void stopServer()
Thread
running in the startServer()
method to
return.
public se.sics.jasper.Server getServer()
Prolog
getServer
in interface Prolog
public void setServer(se.sics.jasper.Server s)
public void init()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |