org.jruby.runtime
Class DynamicScope

java.lang.Object
  extended by org.jruby.runtime.DynamicScope
Direct Known Subclasses:
ManyVarsDynamicScope, NoVarsDynamicScope, OneVarDynamicScope, TwoVarDynamicScope

public abstract class DynamicScope
extends java.lang.Object


Field Summary
protected  DynamicScope evalScope
           
protected  DynamicScope parent
           
protected  StaticScope staticScope
           
 
Constructor Summary
protected DynamicScope(StaticScope staticScope)
           
protected DynamicScope(StaticScope staticScope, DynamicScope parent)
           
 
Method Summary
abstract  DynamicScope cloneScope()
           
 java.lang.String[] getAllNamesInScope()
          Get all variable names captured (visible) by this scope (sans $~ and $_).
abstract  IRubyObject[] getArgValues()
          Copy variable values back for ZSuper call.
 DynamicScope getEvalScope()
           
 DynamicScope getNextCapturedScope()
          Get next 'captured' scope.
 DynamicScope getNthParentScope(int n)
          Returns the n-th parent scope of this scope.
 StaticScope getStaticScope()
          Get the static scope associated with this DynamicScope.
abstract  IRubyObject getValue(int offset, int depth)
          Get value from current scope or one of its captured scopes.
abstract  IRubyObject getValueDepthZeroOrNil(int offset, IRubyObject nil)
          getValueOrNil for depth 0
abstract  IRubyObject getValueOneDepthZeroOrNil(IRubyObject nil)
          getValueOrNil for index 1, depth 0
abstract  IRubyObject getValueOrNil(int offset, int depth, IRubyObject nil)
          Variation of getValue that checks for nulls, returning and setting the given value (presumably nil)
abstract  IRubyObject[] getValues()
           
abstract  IRubyObject getValueZeroDepthZeroOrNil(IRubyObject nil)
          getValueOrNil for index 0, depth 0
abstract  void growIfNeeded()
           
static DynamicScope newDynamicScope(StaticScope staticScope)
           
static DynamicScope newDynamicScope(StaticScope staticScope, DynamicScope parent)
           
abstract  void setArgValues(IRubyObject[] values, int size)
          Set all values which represent 'normal' parameters in a call list to this dynamic scope.
abstract  void setValue(int offset, IRubyObject value, int depth)
          Set value in current dynamic scope or one of its captured scopes.
abstract  void setValueDepthZero(IRubyObject value, int offset)
          setValue for depth zero
abstract  void setValueOneDepthZero(IRubyObject value)
          Set value in current dynamic scope or one of its captured scopes.
abstract  void setValueZeroDepthZero(IRubyObject value)
          Set value in current dynamic scope or one of its captured scopes.
 java.lang.String toString()
           
abstract  java.lang.String toString(java.lang.StringBuffer buf, java.lang.String indent)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

staticScope

protected StaticScope staticScope

parent

protected DynamicScope parent

evalScope

protected DynamicScope evalScope
Constructor Detail

DynamicScope

protected DynamicScope(StaticScope staticScope,
                       DynamicScope parent)

DynamicScope

protected DynamicScope(StaticScope staticScope)
Method Detail

newDynamicScope

public static DynamicScope newDynamicScope(StaticScope staticScope,
                                           DynamicScope parent)

getNthParentScope

public DynamicScope getNthParentScope(int n)
Returns the n-th parent scope of this scope. May return null.

Parameters:
n - - number of levels above to look.
Returns:
The n-th parent scope or null.

newDynamicScope

public static DynamicScope newDynamicScope(StaticScope staticScope)

getEvalScope

public final DynamicScope getEvalScope()

getNextCapturedScope

public final DynamicScope getNextCapturedScope()
Get next 'captured' scope.

Returns:
the scope captured by this scope for implementing closures

getStaticScope

public final StaticScope getStaticScope()
Get the static scope associated with this DynamicScope.

Returns:
static complement to this scope

getAllNamesInScope

public final java.lang.String[] getAllNamesInScope()
Get all variable names captured (visible) by this scope (sans $~ and $_).

Returns:
a list of variable names

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

growIfNeeded

public abstract void growIfNeeded()

toString

public abstract java.lang.String toString(java.lang.StringBuffer buf,
                                          java.lang.String indent)

cloneScope

public abstract DynamicScope cloneScope()

getValues

public abstract IRubyObject[] getValues()

getValue

public abstract IRubyObject getValue(int offset,
                                     int depth)
Get value from current scope or one of its captured scopes. FIXME: block variables are not getting primed to nil so we need to null check those until we prime them properly. Also add assert back in.

Parameters:
offset - zero-indexed value that represents where variable lives
depth - how many captured scopes down this variable should be set
Returns:
the value here

getValueOrNil

public abstract IRubyObject getValueOrNil(int offset,
                                          int depth,
                                          IRubyObject nil)
Variation of getValue that checks for nulls, returning and setting the given value (presumably nil)


getValueDepthZeroOrNil

public abstract IRubyObject getValueDepthZeroOrNil(int offset,
                                                   IRubyObject nil)
getValueOrNil for depth 0


getValueZeroDepthZeroOrNil

public abstract IRubyObject getValueZeroDepthZeroOrNil(IRubyObject nil)
getValueOrNil for index 0, depth 0


getValueOneDepthZeroOrNil

public abstract IRubyObject getValueOneDepthZeroOrNil(IRubyObject nil)
getValueOrNil for index 1, depth 0


setValue

public abstract void setValue(int offset,
                              IRubyObject value,
                              int depth)
Set value in current dynamic scope or one of its captured scopes.

Parameters:
offset - zero-indexed value that represents where variable lives
value - to set
depth - how many captured scopes down this variable should be set

setValueDepthZero

public abstract void setValueDepthZero(IRubyObject value,
                                       int offset)
setValue for depth zero

Parameters:
offset - zero-indexed value that represents where variable lives
value - to set
depth - how many captured scopes down this variable should be set

setValueZeroDepthZero

public abstract void setValueZeroDepthZero(IRubyObject value)
Set value in current dynamic scope or one of its captured scopes.

Parameters:
offset - zero-indexed value that represents where variable lives
value - to set
depth - how many captured scopes down this variable should be set

setValueOneDepthZero

public abstract void setValueOneDepthZero(IRubyObject value)
Set value in current dynamic scope or one of its captured scopes.

Parameters:
offset - zero-indexed value that represents where variable lives
value - to set
depth - how many captured scopes down this variable should be set

setArgValues

public abstract void setArgValues(IRubyObject[] values,
                                  int size)
Set all values which represent 'normal' parameters in a call list to this dynamic scope. Function calls bind to local scopes by assuming that the indexes or the arg list correspond to that of the local scope (plus 2 since $_ and $~ always take the first two slots). We pass in a second argument because we sometimes get more values than we are expecting. The rest get compacted by original caller into rest args.

Parameters:
values - up to size specified to be mapped as ordinary parm values
size - is the number of values to assign as ordinary parm values

getArgValues

public abstract IRubyObject[] getArgValues()
Copy variable values back for ZSuper call.



Copyright © 2002-2007 JRuby Team. All Rights Reserved.