org.concord.util.script
Class NameStack

java.lang.Object
  |
  +--org.concord.util.script.ScriptObject
        |
        +--org.concord.util.script.NameStack
All Implemented Interfaces:
java.beans.BeanInfo

public class NameStack
extends ScriptObject

The NameStack class implements a stack frame mechanism for the script interpreter. It is responsible for storing and finding variables and varible values. Each time a script method is invoked a new NameStack stack frame is created and linked to the previous one. All values calculated by the interpreter are pushed on and popped off the current instance of the NameStack. This makes it easier to provide global, script and method variables scope.

The NameStack consists of two Java Stack objects, one for names and one for values. Name-value pairs can be pushed and popped, and in addition, name lookup and enter methods are provided to make it easy to read and write variable values.

Version:
$Revision: 1.2 $ $Date: 2001/11/08 20:51:36 $
Author:
$Author: ed $

Field Summary
 boolean finished
           
protected  int frameSize
           
protected  NameStack globals
           
protected  NameStack imports
           
protected static java.lang.String indent
           
 boolean isWhen
           
protected  NameStack members
           
protected  java.util.Stack names
           
 ScriptObject node
           
 java.lang.Object result
           
 boolean returned
           
 boolean skipped
           
 boolean throwUp
           
protected  java.util.Stack values
           
 
Fields inherited from class org.concord.util.script.ScriptObject
beginColumn, beginLine, debug, deleted, doConversion, endColumn, endLine, name, nil, runtimeTable, script
 
Fields inherited from interface java.beans.BeanInfo
ICON_COLOR_16x16, ICON_COLOR_32x32, ICON_MONO_16x16, ICON_MONO_32x32
 
Constructor Summary
NameStack()
           
NameStack(boolean doThrow)
           
NameStack(NameStack previous)
           
 
Method Summary
 int addLocals(java.util.Stack nameStack, java.lang.Object[] args)
          Add parameters and locals to stack frame.
 void delete()
           
 void deleteAll()
           
 void enter(java.lang.String varName, java.lang.Object objValue)
          Set a variable value in the stack frame.
 void enter(java.lang.String varName, java.lang.Object objValue, boolean doThrow)
           
 NameStack getGlobals()
           
 NameStack getImports()
           
 NameStack getMembers()
           
 java.util.Stack getNames()
           
 NameStack getParent()
          This method is used to pop a stack frame.
 int getSize()
           
 java.util.Stack getValues()
           
protected  void init(NameStack previous, boolean doThrow)
           
 java.lang.Object lookup(java.lang.String varName)
          Find a variable value in the stack frame.
 java.lang.Object lookup(java.lang.String varName, boolean doThrow)
           
 java.lang.Object pop()
           
 void print()
           
 void push(java.lang.Object objValue)
           
 void push(java.lang.String varName, java.lang.Object objValue)
           
 boolean remove(java.lang.String objName)
           
 void removeLocals(int n)
           
 void setGlobals(NameStack stack)
           
 void setImports(NameStack stack)
           
 void setMembers(NameStack stack)
           
 
Methods inherited from class org.concord.util.script.ScriptObject
findConstructor, findMethod, getAdditionalBeanInfo, getArrayValue, getAtom, getBeanDescriptor, getCurrentFrame, getDefaultEventIndex, getDefaultPropertyIndex, getEventSetDescriptors, getField, getFieldValue, getIcon, getMethodDescriptors, getName, getPropertyDescriptors, getScript, interpret, popFrame, pushFrame, setArrayValue, setCurrentFrame, setFieldValue, setName, setScript, setSourceBounds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

frameSize

protected int frameSize

globals

protected NameStack globals

members

protected NameStack members

imports

protected NameStack imports

values

protected java.util.Stack values

names

protected java.util.Stack names

indent

protected static java.lang.String indent

skipped

public boolean skipped

finished

public boolean finished

returned

public boolean returned

throwUp

public boolean throwUp

isWhen

public boolean isWhen

result

public java.lang.Object result

node

public ScriptObject node
Constructor Detail

NameStack

public NameStack()

NameStack

public NameStack(boolean doThrow)

NameStack

public NameStack(NameStack previous)
Method Detail

delete

public void delete()
Overrides:
delete in class ScriptObject

deleteAll

public void deleteAll()

init

protected void init(NameStack previous,
                    boolean doThrow)

getNames

public java.util.Stack getNames()

getValues

public java.util.Stack getValues()

lookup

public java.lang.Object lookup(java.lang.String varName)
Find a variable value in the stack frame.

Parameters:
String - varName - name of the variable
Returns:
Object objValue - value of the variable
Throws:
NoSuchElementException - (RuntimeException)

lookup

public java.lang.Object lookup(java.lang.String varName,
                               boolean doThrow)

enter

public void enter(java.lang.String varName,
                  java.lang.Object objValue)
Set a variable value in the stack frame.

Parameters:
String - varName - name of the variable
Object - objValue - value of the variable
Throws:
NoSuchElementException - (RuntimeException)

enter

public void enter(java.lang.String varName,
                  java.lang.Object objValue,
                  boolean doThrow)

addLocals

public int addLocals(java.util.Stack nameStack,
                     java.lang.Object[] args)
Add parameters and locals to stack frame.

This method is used to set up the stack frame context so that the method statements can be interpreted and have access to the parameters and locals.

Parameters:
Stack - parameters - formal parameters name list
Stack - actuals - actual parameters value list
Stack - locals - local variables name list

removeLocals

public void removeLocals(int n)

getParent

public NameStack getParent()
This method is used to pop a stack frame. When a acript method is done it calls this to restore the getCurrentFrame() variable.

getSize

public int getSize()

setMembers

public void setMembers(NameStack stack)

getMembers

public NameStack getMembers()

setGlobals

public void setGlobals(NameStack stack)

getGlobals

public NameStack getGlobals()

setImports

public void setImports(NameStack stack)

getImports

public NameStack getImports()

push

public void push(java.lang.String varName,
                 java.lang.Object objValue)

push

public void push(java.lang.Object objValue)

pop

public java.lang.Object pop()

remove

public boolean remove(java.lang.String objName)

print

public void print()