aspoev.interpreter.runtime
Class ExecutionEnvironment

java.lang.Object
  extended byaspoev.interpreter.runtime.ExecutionEnvironment
Direct Known Subclasses:
CommandLineEnvironment

public class ExecutionEnvironment
extends java.lang.Object

The runtime environment of the interpreter - this includes variable resolution, scoping, maintianing the 'this' object, etc.. If the interpreter ever has a question concerning the state of program execution, it queries this object. The execution environment also stores variables that are passed as arguments. Runtime stack structure: [ ] <- scope ( '{, }' delineated) (holds HashMaps for [ ] variable storage /lookup) [ ] [ ][ ][ ][ ] <- methodStack (delineated by method invocation, return) [ ] [ ] <- objectStack (delineated by object control flow)


Field Summary
protected  java.util.Stack argumentStack
           
protected static java.util.HashMap globalFrame
           
protected static java.util.HashMap knownClasses
           
protected  aspoev.interpreter.runtime.ObjectStack objectStack
           
protected  java.util.HashMap staticFrame
           
 
Constructor Summary
ExecutionEnvironment()
           
 
Method Summary
 boolean cflow(MetaObject object)
          If this object is somewhere in the call stack.
 boolean cflow(MetaObject object, java.lang.String methodName)
          If this object calls this method somewhere in the call stack.
 boolean cflow(java.lang.String methodName)
          If this method is somewhere in the callstack.
 boolean cflow(TypeReferenceElement type)
          If this type is somewhere in the call stack.
 boolean cflow(TypeReferenceElement type, java.lang.String methodName)
          If this type calls this method somewhere in the call stack.
 void declareGlobalVariable(TypeReferenceElement type, java.lang.String handle)
          Declares a variable of the specified type and handle that is globally visible.
 void declareGlobalVariable(TypeReferenceElement type, VariableReferenceElement reference)
          Declares a variable of the specified type and handle that is globally visible.
 void declareGlobalVariable(VariableDeclarationElement varDecl)
          Declares a variable of the specified type and handle that is globally visible.
 void declareStaticVariable(TypeReferenceElement type, VariableReferenceElement reference)
          Declares a variable which is static in this execution environment.
 void declareStaticVariable(VariableDeclarationElement variable)
           
 VariableDeclarationElement declareVariable(TypeReferenceElement type, java.lang.String variableName)
          Declares a variable of the specified type and name.
 VariableDeclarationElement declareVariable(TypeReferenceElement type, VariableReferenceElement reference)
          Declares a variable of the specified type and name.
 void declareVariable(VariableDeclarationElement localVariable)
          Adds the newly declared variable to the current stack frame.
 java.lang.String getCurrentNameSpace()
          Returns the name space of the currently executing object.
 aspoev.interpreter.runtime.MethodStackFrame getCurrentStackFrame()
          Returns the current method frame.
protected  VariableDeclarationElement getLocalVariable(VariableReferenceElement handle)
           
 java.lang.String getNextNameSpace(java.lang.String nameSpace)
          Returns the next name space in teh execution stack.
 int getNumArguments()
          Returns the number of arguments currently in the argument stack.
 TypeReferenceElement getVariableType(VariableReferenceElement reference)
          Returns the type of the most visible variable with the given handle.
 java.lang.Object getVariableValue(java.lang.String variableName)
          Returns the vale of the value of the given name.
 java.lang.Object getVariableValue(VariableReferenceElement reference)
           
protected  void initEnvironment()
           
 DatabaseObject peekCurrent()
          Basically getThis().
 java.lang.Object popArgument()
          Removes an argument from the argument stack.
 DatabaseObject popCurrent()
          Push current and pop current methods maintain the 'this' object in the call stack.
 aspoev.interpreter.runtime.MethodStackFrame popMethodFrame()
          Method return - pops a method frame from the method execution stack.
 ScopeFrame popScope()
           
 void printEnvironment()
          Prints a visual of the object stack and method stack.
 void pushArgument(java.lang.Object args)
          Semantics of passing arguments - push them onto the argument stack, the executing method will then pop them off.
 void pushCurrent(DatabaseObject current)
          Makes the specified object the currently executing object.
 void pushMethodFrame(java.lang.String methodName)
          Method invocation - pushes a method frame on the method execution stack.
 void pushScope()
          Pushes scope.
 void pushScope(ScopeFrame scope)
          Pushes the specified scope.
protected  java.lang.Object setClassVariable(VariableReferenceElement reference, java.lang.Object newValue)
           
protected  java.lang.Object setLocalVariable(VariableDeclarationElement decl, java.lang.Object newValue)
           
 java.lang.Object setStaticVariableValue(VariableReferenceElement reference, java.lang.Object newValue)
          Sets the value of a statically declared variable to the specified value.
 java.lang.Object setVariableValue(java.lang.String variableName, java.lang.Object newValue)
          Sets the variable specified to the value specified.
 java.lang.Object setVariableValue(VariableReferenceElement reference, java.lang.Object newValue)
          Sets the variable specified to the value specified.
protected  void typeCheck(TypeReferenceElement varType, java.lang.Object newValue)
           
 boolean within(MetaObject object)
          If this object is currently executing.
 boolean within(MetaObject object, java.lang.String methodName)
          If this object is executing this method.
 boolean within(java.lang.String methodName)
          If this method is currently executing.
 boolean within(TypeReferenceElement type)
          If any object of this type is currently executing.
 boolean within(TypeReferenceElement type, java.lang.String methodName)
          If this type is executing this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

knownClasses

protected static java.util.HashMap knownClasses

staticFrame

protected java.util.HashMap staticFrame

globalFrame

protected static java.util.HashMap globalFrame

objectStack

protected aspoev.interpreter.runtime.ObjectStack objectStack

argumentStack

protected java.util.Stack argumentStack
Constructor Detail

ExecutionEnvironment

public ExecutionEnvironment()
Method Detail

initEnvironment

protected void initEnvironment()

within

public boolean within(MetaObject object)
If this object is currently executing.


within

public boolean within(TypeReferenceElement type)
If any object of this type is currently executing.


within

public boolean within(java.lang.String methodName)
If this method is currently executing.


within

public boolean within(MetaObject object,
                      java.lang.String methodName)
If this object is executing this method.


within

public boolean within(TypeReferenceElement type,
                      java.lang.String methodName)
If this type is executing this method.


cflow

public boolean cflow(MetaObject object)
If this object is somewhere in the call stack.


cflow

public boolean cflow(TypeReferenceElement type)
If this type is somewhere in the call stack.


cflow

public boolean cflow(java.lang.String methodName)
If this method is somewhere in the callstack.


cflow

public boolean cflow(MetaObject object,
                     java.lang.String methodName)
If this object calls this method somewhere in the call stack.


cflow

public boolean cflow(TypeReferenceElement type,
                     java.lang.String methodName)
If this type calls this method somewhere in the call stack.


declareVariable

public VariableDeclarationElement declareVariable(TypeReferenceElement type,
                                                  java.lang.String variableName)
Declares a variable of the specified type and name.


declareVariable

public VariableDeclarationElement declareVariable(TypeReferenceElement type,
                                                  VariableReferenceElement reference)
Declares a variable of the specified type and name.


declareVariable

public void declareVariable(VariableDeclarationElement localVariable)
Adds the newly declared variable to the current stack frame. If a variable of the same name has already been declared in this stack frame, and exception is thrown (equivalent of a runtime compilation error ;).


declareGlobalVariable

public void declareGlobalVariable(TypeReferenceElement type,
                                  java.lang.String handle)
Declares a variable of the specified type and handle that is globally visible.


declareGlobalVariable

public void declareGlobalVariable(TypeReferenceElement type,
                                  VariableReferenceElement reference)
Declares a variable of the specified type and handle that is globally visible.


declareGlobalVariable

public void declareGlobalVariable(VariableDeclarationElement varDecl)
Declares a variable of the specified type and handle that is globally visible. (In every execution environment).


declareStaticVariable

public void declareStaticVariable(TypeReferenceElement type,
                                  VariableReferenceElement reference)
Declares a variable which is static in this execution environment.


declareStaticVariable

public void declareStaticVariable(VariableDeclarationElement variable)

getCurrentNameSpace

public java.lang.String getCurrentNameSpace()
Returns the name space of the currently executing object.


getCurrentStackFrame

public aspoev.interpreter.runtime.MethodStackFrame getCurrentStackFrame()
Returns the current method frame.


getNextNameSpace

public java.lang.String getNextNameSpace(java.lang.String nameSpace)
Returns the next name space in teh execution stack.


getNumArguments

public int getNumArguments()
Returns the number of arguments currently in the argument stack.


getVariableType

public TypeReferenceElement getVariableType(VariableReferenceElement reference)
Returns the type of the most visible variable with the given handle.


getVariableValue

public java.lang.Object getVariableValue(java.lang.String variableName)
Returns the vale of the value of the given name.


getVariableValue

public java.lang.Object getVariableValue(VariableReferenceElement reference)
Returns:
Object - a Java-object (database), Metaobject, Boolean, Double, or String referenced by @param reference

getLocalVariable

protected VariableDeclarationElement getLocalVariable(VariableReferenceElement handle)

pushCurrent

public void pushCurrent(DatabaseObject current)
Makes the specified object the currently executing object.


popCurrent

public DatabaseObject popCurrent()
Push current and pop current methods maintain the 'this' object in the call stack.


peekCurrent

public DatabaseObject peekCurrent()
Basically getThis().


pushArgument

public void pushArgument(java.lang.Object args)
Semantics of passing arguments - push them onto the argument stack, the executing method will then pop them off.


popArgument

public java.lang.Object popArgument()
Removes an argument from the argument stack.


pushMethodFrame

public void pushMethodFrame(java.lang.String methodName)
Method invocation - pushes a method frame on the method execution stack.


popMethodFrame

public aspoev.interpreter.runtime.MethodStackFrame popMethodFrame()
Method return - pops a method frame from the method execution stack.


pushScope

public void pushScope(ScopeFrame scope)
Pushes the specified scope. Lower scopes remain visible.


pushScope

public void pushScope()
Pushes scope. Lower scopes remain visible.


popScope

public ScopeFrame popScope()

setStaticVariableValue

public java.lang.Object setStaticVariableValue(VariableReferenceElement reference,
                                               java.lang.Object newValue)
Sets the value of a statically declared variable to the specified value. Note that static variables do not need to be set in this way.


setVariableValue

public java.lang.Object setVariableValue(java.lang.String variableName,
                                         java.lang.Object newValue)
Sets the variable specified to the value specified.


setVariableValue

public java.lang.Object setVariableValue(VariableReferenceElement reference,
                                         java.lang.Object newValue)
Sets the variable specified to the value specified.


setClassVariable

protected java.lang.Object setClassVariable(VariableReferenceElement reference,
                                            java.lang.Object newValue)

setLocalVariable

protected java.lang.Object setLocalVariable(VariableDeclarationElement decl,
                                            java.lang.Object newValue)

typeCheck

protected void typeCheck(TypeReferenceElement varType,
                         java.lang.Object newValue)

printEnvironment

public void printEnvironment()
Prints a visual of the object stack and method stack.