nl.tudelft.simulation.dsol.interpreter
Class OperandStack

java.lang.Object
  extended by nl.tudelft.simulation.dsol.interpreter.OperandStack
All Implemented Interfaces:
Cloneable

public class OperandStack
extends Object
implements Cloneable

Each frame (�3.6) contains a last-in-first-out (LIFO) stack known as its operand stack. The maximum depth of the operand stack of a frame is determined at compile time and is supplied along with the code for the method associated with the frame (�4.7.3). Where it is clear by context, we will sometimes refer to the operand stack of the current frame as simply the operand stack.

The operand stack is empty when the frame that contains it is created. The Java virtual machine supplies instructions to load constants or values from local variables or fields onto the operand stack. Other Java virtual machine instructions take operands from the operand stack, operate on them, and push the result back onto the operand stack. The operand stack is also used to prepare parameters to be passed to methods and to receive method results.

For example, the IADD instruction adds two int values together. It requires that the int values to be added be the top two values of the operand stack, pushed there by previous instructions. Both of the int values are popped from the operand stack. They are added, and their sum is pushed back onto the operand stack. Subcomputations may be nested on the operand stack, resulting in values that can be used by the encompassing computation.

(c) copyright 2002-2005 Delft University of Technology , the Netherlands.
See for project information www.simulation.tudelft.nl
License of use: Lesser General Public License (LGPL) , no warranty.

Since:
1.4
Version:
$Revision: 1.1 $ $Date: 2007/01/06 13:25:12 $
Author:
Peter Jacobs

Constructor Summary
OperandStack(int initialSize)
          constructs a new OperandStack
 
Method Summary
 void clear()
          clears the operand stack
 Object clone()
           
 boolean isEmpty()
          is the OperandStack Empty
 Object peek()
          peeks the first object from the stack.
 Object peek(int depth)
          peeks the depth-object from the stack.
 Object pop()
          pops the first object from the operandstack.
 void push(Object object)
          pushes object on the stack
 void replace(Object oldObject, Object newObject)
          replaces all instances of oldObject by newObject
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OperandStack

public OperandStack(int initialSize)
constructs a new OperandStack

Parameters:
initialSize - the stackSize
Method Detail

clear

public void clear()
clears the operand stack


isEmpty

public boolean isEmpty()
is the OperandStack Empty

Returns:
whether the operandStack is empty

pop

public Object pop()
pops the first object from the operandstack.

Returns:
the top object from the stack

peek

public Object peek()
peeks the first object from the stack. This is a pop without remove

Returns:
Object the first object

peek

public Object peek(int depth)
peeks the depth-object from the stack.

Parameters:
depth - the depth-object
Returns:
the depth object.

push

public void push(Object object)
pushes object on the stack

Parameters:
object - the object to be pushed to the stack

replace

public void replace(Object oldObject,
                    Object newObject)
replaces all instances of oldObject by newObject

Parameters:
oldObject - the oldObject
newObject - the newObject

clone

public Object clone()
Overrides:
clone in class Object
See Also:
Object.clone()

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2002-2011 Delft University of Technology, the Netherlands. All Rights Reserved.