|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--com.svincent.moksa.WamObject
|
+--com.svincent.moksa.Wam
An implementation of a Warren's Abstract Machine, as documented in Warren's Abstract Machine: a Tutorial Reconstruction, by Hassan Ait-Kaci.
Some variations may exist between my implementation and Hassan's description.
There are a number of instructions in Warren's machine that we don't implement here. In particular, since we are representing Prolog terms as Java compoundTerms, and have no heap, most of the instructions described in chapter 2 (up until section 2.3) of Hassan's book are unneccesary.
Most of them are replaced by new calls and calls to
PrologTerm.unify.
| Inner Class Summary | |
static class |
Wam.ChoicePoint
Represents a choice point. |
static class |
Wam.ExceptionHandler
A registered exception handler for the current thread of execution. |
| Field Summary | |
Continuation |
Fail
A very common continuation |
| Constructor Summary | |
Wam(PrologEngine _engine)
|
|
| Method Summary | |
void |
asserta(Rule rule)
Add a new alternative rule for the given name. |
void |
assertz(Rule rule)
Add a new alternative rule for the given name. |
boolean |
badparm(int parmIdx,
PrologTerm desiredValue)
Called when facts are processing their parameters. |
Continuation |
findExceptionHandler(PrologTerm exception)
|
Continuation |
getContinuation()
Get the current continuation. |
PrologEngine |
getEngine()
|
PrologFactory |
getFactory()
|
Io |
getIo()
|
protected Wam.ChoicePoint |
getLastChoicepoint()
Retrieve the current trail pointer. |
PrologTerm |
getRegister(int idx)
Get the value of register 'idx'. |
Rule |
getRule(java.lang.String name)
Get the first alternative rule for the given name. |
long |
getTimestamp()
Retrieve a timestamp. |
protected int |
getTrailPointer()
Retrieve the current trail pointer. |
boolean |
invoke(PrologTerm _goal)
Invoke a goal. |
Trailable |
popTrail()
|
void |
retryMeElse(Rule next)
We just backtracked to the current choicepoint. |
void |
setContinuation(Continuation _continuation)
Set the value of continuation register. |
void |
setRegister(int idx,
PrologTerm v)
Set the value of register 'idx'. |
void |
trail(Trailable obj)
Places this object on the trail stack, marking it to be undone when the trail is unwound. |
void |
trustMe()
We just backtracked to the last choicepoint. |
void |
tryMeElse(Rule rule,
int arity,
Rule next)
Allocates a new choice point frame on the stack setting its next clause field to 'next'. |
protected void |
unwindTrail()
Unwinds the trail stack, which contains things that need to be undone when a choicepoint occurs. |
| Methods inherited from class com.svincent.moksa.WamObject |
tag,
tag |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Field Detail |
public Continuation Fail
| Constructor Detail |
public Wam(PrologEngine _engine)
| Method Detail |
public PrologEngine getEngine()
public PrologFactory getFactory()
public Io getIo()
public long getTimestamp()
public Continuation getContinuation()
public void setContinuation(Continuation _continuation)
public PrologTerm getRegister(int idx)
public void setRegister(int idx,
PrologTerm v)
public boolean badparm(int parmIdx,
PrologTerm desiredValue)
throws PrologException
public Rule getRule(java.lang.String name)
public boolean invoke(PrologTerm _goal)
throws PrologException
public void tryMeElse(Rule rule,
int arity,
Rule next)
Allocates a new choice point frame on the stack setting its next clause field to 'next'.
This should be called before the first clause of any
multi-clause rule. Subsequent clauses, except for the last
clause, should call retryMeElse.
The last clause should call trustMe.
arity - the arity of the procedure offering alternatives.
Needed so that the Wam knows how many argument registers to save.next - a pointer to the next choicepoint continuation.retryMeElse(Rule),
trustMe()public void retryMeElse(Rule next)
We just backtracked to the current choicepoint. Setup the next possible choice.
One way of thinking about this is: if there are N choicepoints
(choice1..choiceN), then retryMeElse should be
called before executing choice2 through choice(N-1).
arity - the arity of the procedure offering alternatives.
Needed so that the Wam knows how many argument registers to save.next - a pointer to the next choicepoint continuation.tryMeElse(Rule, int, Rule)public void trustMe()
We just backtracked to the last choicepoint. No more choices, so we've got to trust this fellow.
tryMeElse(Rule, int, Rule)protected Wam.ChoicePoint getLastChoicepoint()
protected int getTrailPointer()
public void trail(Trailable obj)
protected void unwindTrail()
Unwinds the trail stack, which contains things that need to be undone when a choicepoint occurs.
This version of the method unwinds the trail to the last ChoicePoint.
public Trailable popTrail()
public Continuation findExceptionHandler(PrologTerm exception)
throws PrologException
public void asserta(Rule rule)
public void assertz(Rule rule)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
This is documentation for Moksa Prolog, which can be found at http://www.svincent.com/moksa/
Copyright © 1999 Shawn P. Vincent.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.