org.millscript.millscript.vm
Class BasicMachine

java.lang.Object
  extended by org.millscript.millscript.vm.TraceableMachine
      extended by org.millscript.millscript.vm.BasicMachine
Direct Known Subclasses:
Machine

public abstract class BasicMachine
extends TraceableMachine

This class provides the skeletal implementation for a machine.


Field Summary
protected  java.lang.Object[] piggyBank
          This is the equivalent of the call stack in a conventional implementation.
protected  java.lang.Object[] valueStack
          This is an operand stack.
 
Fields inherited from class org.millscript.millscript.vm.TraceableMachine
doingIndex
 
Constructor Summary
BasicMachine()
           
 
Method Summary
 int getCount()
          Returns the number of objects in the stack.
 java.lang.Object getIndex(int n)
          Returns the object at the specified position in the stack.
 java.lang.Object peekObject()
          Returns the object at the top of the stack.
 void pokeObject(java.lang.Object x)
          Replaces the object at the top of the stack with the specified object.
 java.lang.Object[] popArgsArray(int nargs)
          Pops the specified number of values from the top of the value stack and returns them as an array.
 java.lang.Object[] popArgsIntoArray(java.lang.Object[] args)
          Pops enough arguments off the stack to fill the supplied array.
 org.millscript.commons.util.ListIterator<java.lang.Object> popArgsIterator(int nargs)
          Pops the specified number of values from the top of the operand stack and returns an iterator to iterate over them.
 org.millscript.commons.util.IList<java.lang.Object> popArgsList(int nargs, boolean mutable)
          Pops the specifed number of values from the top of the operand stack and returns them as a list.
 java.lang.Object popObject()
          Pops the object off the top of the operand stack and returns it as the value of this method.
 void pushArgsArray(java.lang.Object[] args)
          Pushes all of the values in the specified array onto the stack.
 void pushArgsIterator(java.util.Iterator<?> it)
          Pushes each of the values from the specified iterator onto the stack.
 void pushArgsList(org.millscript.commons.util.IList<?> list)
          Pushes all of the values in the specified list onto the stack.
 void pushArgsMapIterator(org.millscript.commons.util.MapIterator<?,?> it)
          Pushes each of the values from the specified map iterator onto the stack.
 void pushBoolean(boolean b)
          Pushes the specified boolean value onto the operand stack.
 void pushObject(java.lang.Object val)
          Pushes the specified object onto the operand stack.
 void reset()
          Resets this machine after an error, making it ready to action new code.
 void restoreSaved()
          Restore all the variables in the current save set (in reverse order) and dispose of the save set.
 void saveRef(Ref r)
          Save a variable and its current value.
 void setCount(int n)
          Sets the number of values on the stack.
 void startSaving()
          Start a new save-set.
 
Methods inherited from class org.millscript.millscript.vm.TraceableMachine
doingList, enterFunction, enterUpdater, exitFunction, exitUpdater
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

piggyBank

protected java.lang.Object[] piggyBank
This is the equivalent of the call stack in a conventional implementation.


valueStack

protected java.lang.Object[] valueStack
This is an operand stack.

Constructor Detail

BasicMachine

public BasicMachine()
Method Detail

getCount

public int getCount()
Returns the number of objects in the stack.

Returns:
the number of objects in the stack

getIndex

public java.lang.Object getIndex(int n)
Returns the object at the specified position in the stack.

Parameters:
n - index of the element to return
Returns:
the object at the specified position in the stack

peekObject

public java.lang.Object peekObject()
Returns the object at the top of the stack. The object is left at it's current position on the stack.

Returns:
the object at the top of the stack

pokeObject

public void pokeObject(java.lang.Object x)
Replaces the object at the top of the stack with the specified object.

Parameters:
x - the object to put at the top of the stack

popArgsArray

public java.lang.Object[] popArgsArray(int nargs)
Pops the specified number of values from the top of the value stack and returns them as an array.

Parameters:
nargs - the number of values to pop
Returns:

popArgsIntoArray

public java.lang.Object[] popArgsIntoArray(java.lang.Object[] args)
Pops enough arguments off the stack to fill the supplied array. The item at the top of the stack goes at the end of the array.

Parameters:
args - the array to fill with values from the stack
Returns:
the supplied array filled with new values

popArgsIterator

public org.millscript.commons.util.ListIterator<java.lang.Object> popArgsIterator(int nargs)
Pops the specified number of values from the top of the operand stack and returns an iterator to iterate over them.

Parameters:
nargs - the number of values to pop
Returns:
an iterator over the poped values

popArgsList

public org.millscript.commons.util.IList<java.lang.Object> popArgsList(int nargs,
                                                                       boolean mutable)
Pops the specifed number of values from the top of the operand stack and returns them as a list.

Parameters:
nargs - the number of values to pop
Returns:
a list of the poped values

popObject

public java.lang.Object popObject()
Pops the object off the top of the operand stack and returns it as the value of this method.

Returns:
the object from the top of the operand stack.

pushArgsArray

public void pushArgsArray(java.lang.Object[] args)
Pushes all of the values in the specified array onto the stack. The items are pushed onto the stack from first in the array to the last.

Parameters:
args - the array to get values to push onto the stack from

pushArgsIterator

public void pushArgsIterator(java.util.Iterator<?> it)
Pushes each of the values from the specified iterator onto the stack.

Parameters:
it - the iterator to get values to push onto the stack from

pushArgsList

public void pushArgsList(org.millscript.commons.util.IList<?> list)
Pushes all of the values in the specified list onto the stack. The items are pushed onto the stack from first in the list to the last.

Parameters:
list - the list to get values to push onto the stack from

pushArgsMapIterator

public void pushArgsMapIterator(org.millscript.commons.util.MapIterator<?,?> it)
Pushes each of the values from the specified map iterator onto the stack. Note, this method ignores the keys from the supplied map iterator and only pushes the values.

Parameters:
it - the map iterator to push values onto the stack from

pushBoolean

public void pushBoolean(boolean b)
Pushes the specified boolean value onto the operand stack.

Parameters:
b - a boolean value to push onto the operand stack.

pushObject

public void pushObject(java.lang.Object val)
Pushes the specified object onto the operand stack.

Parameters:
val - an object to push onto the operand stack.

reset

public void reset()
Resets this machine after an error, making it ready to action new code.


restoreSaved

public void restoreSaved()
Restore all the variables in the current save set (in reverse order) and dispose of the save set.


saveRef

public void saveRef(Ref r)
Save a variable and its current value.

Parameters:
r - the reference to save

setCount

public void setCount(int n)
Sets the number of values on the stack. The new size should be less than the current size of the stack, i.e. this method cannot be used to increase the size of the stack.

Parameters:
n - the maximum number of values that should remain on the stack

startSaving

public void startSaving()
Start a new save-set.



Copyright © 2001-2007 Open World Ltd. All Rights Reserved.