oscript.data
Class Scope

java.lang.Object
  extended byoscript.data.Value
      extended byoscript.data.Scope
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
BasicScope, ForkScope

public abstract class Scope
extends Value

Scope is an internal object use to represent a scope of execution. It is used to implement nested scope, ie. if a lookup in this scope fails, the lookup will procedue in the previous scope, and so on.

Author:
Rob Clark (rob@ti.com)
See Also:
Serialized Form

Field Summary
protected  Scope previous
          Previous in object scope chain.
 
Fields inherited from class oscript.data.Value
DEBUG, MEMBER_NAMES, NULL, PARENT_TYPE_NAME, TYPE, TYPE_NAME, UNDEFINED
 
Constructor Summary
protected Scope(Scope previous)
          Class Constructor.
 
Method Summary
abstract  Value __getInstanceMember(int id)
           
 void __setJavaObject(java.lang.Object javaObject)
          Set the java-object associated with a script object...
abstract  Value createMember(int id, int attr)
          Create a member of this object with the specified value.
 Value createMember(java.lang.String name, int attr)
          Create a member of this object with the specified value.
 Value createMember(Value name, int attr)
          Create a member of this object with the specified value.
protected static java.lang.String findDesc(Scope scope)
           
abstract  void free()
          Indicate that this scope is no longer needed.
 Value getCallee()
          Lookup the "callee" within a scope.
protected  Value getMemberImpl(int id)
           
 Scope getPreviousScope()
          Get the previous scope in the scope chain.
 Scope getSafeCopy()
          In case a scope has any resource allocated from a source which will no long be valid after a stack frame has returned (ie.
 Value getThis()
          Lookup the "this" within a scope.
abstract  boolean isSafe()
           
abstract  Value lookupInScope(int id)
          Get a member from this scope.
 Value lookupInScope(java.lang.String name)
          Get a member from this scope.
 Value lookupInScope(Value name)
          Get a member from this scope.
abstract  void mixin(Value val)
          "mixin" the specified variable into the current scope.
 
Methods inherited from class oscript.data.Value
_getTypeMember, _populateTypeMemberSet, bopBitwiseAnd, bopBitwiseAndR, bopBitwiseOr, bopBitwiseOrR, bopBitwiseXor, bopBitwiseXorR, bopCast, bopCastR, bopDivide, bopDivideR, bopEquals, bopEqualsR, bopGreaterThan, bopGreaterThanOrEquals, bopGreaterThanOrEqualsR, bopGreaterThanR, bopInstanceOf, bopInstanceOfR, bopLeftShift, bopLeftShiftR, bopLessThan, bopLessThanOrEquals, bopLessThanOrEqualsR, bopLessThanR, bopLogicalAnd, bopLogicalAndR, bopLogicalOr, bopLogicalOrR, bopMinus, bopMinusR, bopMultiply, bopMultiplyR, bopNotEquals, bopNotEqualsR, bopPlus, bopPlusR, bopRemainder, bopRemainderR, bopSignedRightShift, bopSignedRightShiftR, bopUnsignedRightShift, bopUnsignedRightShiftR, callAsConstructor, callAsConstructor, callAsConstructor, callAsExtends, callAsExtends, callAsExtends, callAsFunction, callAsFunction, callAsFunction, castToBoolean, castToExactNumber, castToInexactNumber, castToJavaObject, castToString, elementAt, elementsAt, getMember, getMember, getMember, getMember, getMember, getMember, getMonitor, getType, getTypeImpl, getTypeMember, getTypeMember, isA, length, memberSet, noSuchMember, opAssign, populateMemberSet, populateTypeMemberSet, readExternal, toString, unhand, uopBitwiseNot, uopDecrement, uopIncrement, uopLogicalNot, uopMinus, uopPlus, writeExternal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

previous

protected Scope previous
Previous in object scope chain. This is used to lookupInScope, when the member being looked-up doesn't exist in this object (ie scope chain node)

Constructor Detail

Scope

protected Scope(Scope previous)
Class Constructor. Construct a element in the scope chain. This constructs a "function" element in the scope chain. This is called from the Function class when a function is evaluateded.

Parameters:
previous - previous in environment scope chain
Method Detail

getPreviousScope

public Scope getPreviousScope()
Get the previous scope in the scope chain.

Returns:
the parent scope, or null if this is the global- scope (ie. topmost scope in the scope chain)

__setJavaObject

public void __setJavaObject(java.lang.Object javaObject)
Set the java-object associated with a script object... this is used when a script type subclasses a java type.

Parameters:
javaObject - the java-object

getThis

public Value getThis()
Lookup the "this" within a scope. The "this" is the first scope chain node that is an object, rather than a regular scope chain node.

Returns:
the "this" ScriptObject within this scope

getCallee

public Value getCallee()
Lookup the "callee" within a scope. The "callee" is the first scope chain node that is a function-scope, rather than a regular scope chain node.

Returns:
the "callee" Function within callee scope

createMember

public final Value createMember(java.lang.String name,
                                int attr)
Create a member of this object with the specified value. This method is provided for convenience.

Parameters:
name - the name of the member
attr - the attributes of the object (see Reference.)
See Also:
Reference

createMember

public final Value createMember(Value name,
                                int attr)
Create a member of this object with the specified value.

Parameters:
name - the name of the member
attr - the attributes of the object (see Reference.)
See Also:
Reference

createMember

public abstract Value createMember(int id,
                                   int attr)
Create a member of this object with the specified value.

Parameters:
id - the id of the symbol that maps to the member
attr - the attributes of the object (see Reference.)
See Also:
Reference

mixin

public abstract void mixin(Value val)
"mixin" the specified variable into the current scope. When a object is mixed in, all of it's members are mixed in to the current scope. Members created within this scope will take precedence over a member of a mixed in object. The following script code example gives an idea of how this works:
   mixin java.lang.Math;  // defines "min", "max", etc
   var c = min( a, b );
   var d = max( a, b );
 
Mixins can also be used to implement OO composition, so a constructor function can mixin members of another object. (Note that this will not make the resulting object an instanceof this mixed in object's type... this could be made to work at some point in the future for script code, but not for java code, if that was deemed a good thing..)
   function ListAndStuff()
   {
     public function foo() { ... }
     var list = new java.util.LinkedList();
     mixin list;
   }
   var obj = new ListAndStuff();
   obj.foo();
   obj.add(1);
   obj.add("two");
   for( var o : obj )
     writeln("list member: " + o);
 

Parameters:
val - the value to mixin to this scope

getMemberImpl

protected Value getMemberImpl(int id)

__getInstanceMember

public abstract Value __getInstanceMember(int id)

lookupInScope

public final Value lookupInScope(java.lang.String name)
                          throws PackagedScriptObjectException
Get a member from this scope. This is used to access local variables and object attributes from methods of the object. If the attribute isn't in this node in the scope chain, then the previous node in the scope chain is checked. This method is provided for convenience.

Parameters:
name - the name of the member
Throws:
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

lookupInScope

public final Value lookupInScope(Value name)
                          throws PackagedScriptObjectException
Get a member from this scope. This is used to access local variables and object attributes from methods of the object. If the attribute isn't in this node in the scope chain, then the previous node in the scope chain is checked.

Parameters:
name - the name of the member
Throws:
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

lookupInScope

public abstract Value lookupInScope(int id)
                             throws PackagedScriptObjectException
Get a member from this scope. This is used to access local variables and object attributes from methods of the object. If the attribute isn't in this node in the scope chain, then the previous node in the scope chain is checked.

Parameters:
id - the id of the symbol that maps to the member
Throws:
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

getSafeCopy

public Scope getSafeCopy()
In case a scope has any resource allocated from a source which will no long be valid after a stack frame has returned (ie. resource allocated from stack), return a copy of the scope that is safe to keep after the stack frame returns.


isSafe

public abstract boolean isSafe()

free

public abstract void free()
Indicate that this scope is no longer needed. This should only be called in cases of scopes allocated from the stack.


findDesc

protected static final java.lang.String findDesc(Scope scope)