org.jruby.runtime.scope
Class OneVarDynamicScope

java.lang.Object
  extended by org.jruby.runtime.DynamicScope
      extended by org.jruby.runtime.scope.OneVarDynamicScope

public class OneVarDynamicScope
extends DynamicScope

Represents the the dynamic portion of scoping information. The variableValues are the values of assigned local or block variables. The staticScope identifies which sort of scope this is (block or local). Properties of Dynamic Scopes: 1. static and dynamic scopes have the same number of names to values 2. size of variables (and thus names) is determined during parsing. So those structured do not need to change FIXME: When creating dynamic scopes we sometimes accidentally pass in extra parents. This is harmless (other than wasting memory), but we should not do that. We can fix this in two ways: 1. Fix all callers 2. Check parent that is passed in and make if new instance is local, then its parent is not local


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

Constructor Detail

OneVarDynamicScope

public OneVarDynamicScope(StaticScope staticScope,
                          DynamicScope parent)

OneVarDynamicScope

public OneVarDynamicScope(StaticScope staticScope)
Method Detail

growIfNeeded

public void growIfNeeded()
Specified by:
growIfNeeded in class DynamicScope

cloneScope

public DynamicScope cloneScope()
Specified by:
cloneScope in class DynamicScope

getValues

public IRubyObject[] getValues()
Specified by:
getValues in class DynamicScope

getValue

public 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.

Specified by:
getValue in class DynamicScope
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 IRubyObject getValueOrNil(int offset,
                                 int depth,
                                 IRubyObject nil)
Variation of getValue that checks for nulls, returning and setting the given value (presumably nil)

Specified by:
getValueOrNil in class DynamicScope

getValueDepthZeroOrNil

public IRubyObject getValueDepthZeroOrNil(int offset,
                                          IRubyObject nil)
Description copied from class: DynamicScope
getValueOrNil for depth 0

Specified by:
getValueDepthZeroOrNil in class DynamicScope

getValueZeroDepthZeroOrNil

public IRubyObject getValueZeroDepthZeroOrNil(IRubyObject nil)
Description copied from class: DynamicScope
getValueOrNil for index 0, depth 0

Specified by:
getValueZeroDepthZeroOrNil in class DynamicScope

getValueOneDepthZeroOrNil

public IRubyObject getValueOneDepthZeroOrNil(IRubyObject nil)
Description copied from class: DynamicScope
getValueOrNil for index 1, depth 0

Specified by:
getValueOneDepthZeroOrNil in class DynamicScope

setValue

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

Specified by:
setValue in class DynamicScope
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 void setValueDepthZero(IRubyObject value,
                              int offset)
Description copied from class: DynamicScope
setValue for depth zero

Specified by:
setValueDepthZero in class DynamicScope
Parameters:
value - to set
offset - zero-indexed value that represents where variable lives

setValueZeroDepthZero

public void setValueZeroDepthZero(IRubyObject value)
Description copied from class: DynamicScope
Set value in current dynamic scope or one of its captured scopes.

Specified by:
setValueZeroDepthZero in class DynamicScope
Parameters:
value - to set

setValueOneDepthZero

public void setValueOneDepthZero(IRubyObject value)
Description copied from class: DynamicScope
Set value in current dynamic scope or one of its captured scopes.

Specified by:
setValueOneDepthZero in class DynamicScope
Parameters:
value - to set

setArgValues

public 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.

Specified by:
setArgValues in class DynamicScope
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 IRubyObject[] getArgValues()
Description copied from class: DynamicScope
Copy variable values back for ZSuper call.

Specified by:
getArgValues in class DynamicScope

toString

public java.lang.String toString(java.lang.StringBuffer buf,
                                 java.lang.String indent)
Specified by:
toString in class DynamicScope


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