org.jruby.runtime.scope
Class ManyVarsDynamicScope

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

public class ManyVarsDynamicScope
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
ManyVarsDynamicScope(StaticScope staticScope)
           
ManyVarsDynamicScope(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 getValueThreeDepthZeroOrNil(IRubyObject nil)
          getValueOrNil for index 3, depth 0
 IRubyObject getValueTwoDepthZeroOrNil(IRubyObject nil)
          getValueOrNil for index 2, depth 0
 IRubyObject getValueZeroDepthZeroOrNil(IRubyObject nil)
          getValueOrNil for index 0, depth 0
 void growIfNeeded()
          Make a larger dynamic scope if the static scope grew.
 void setArgValues(IRubyObject arg0)
           
 void setArgValues(IRubyObject[] values, int size)
          Set all values which represent 'normal' parameters in a call list to this dynamic scope.
 void setArgValues(IRubyObject arg0, IRubyObject arg1)
           
 void setArgValues(IRubyObject arg0, IRubyObject arg1, IRubyObject arg2)
           
 void setEndArgValues(IRubyObject[] values, int index, int size)
           
 IRubyObject setValue(int offset, IRubyObject value, int depth)
          Set value in current dynamic scope or one of its captured scopes.
 IRubyObject setValueDepthZero(IRubyObject value, int offset)
          setValue for depth zero
 IRubyObject setValueOneDepthZero(IRubyObject value)
          Set value one in this scope.
 IRubyObject setValueThreeDepthZero(IRubyObject value)
          Set value three in this scope.
 IRubyObject setValueTwoDepthZero(IRubyObject value)
          Set value two in this scope.
 IRubyObject setValueZeroDepthZero(IRubyObject value)
          Set value zero in this scope;
 java.lang.String toString(java.lang.StringBuffer buf, java.lang.String indent)
           
 
Methods inherited from class org.jruby.runtime.DynamicScope
getAllNamesInScope, getEvalScope, getFlipScope, getNextCapturedScope, getNthParentScope, getStaticScope, newDummyScope, newDynamicScope, newDynamicScope, setValue, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ManyVarsDynamicScope

public ManyVarsDynamicScope(StaticScope staticScope,
                            DynamicScope parent)

ManyVarsDynamicScope

public ManyVarsDynamicScope(StaticScope staticScope)
Method Detail

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

getValueTwoDepthZeroOrNil

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

Specified by:
getValueTwoDepthZeroOrNil in class DynamicScope

getValueThreeDepthZeroOrNil

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

Specified by:
getValueThreeDepthZeroOrNil in class DynamicScope

setValue

public IRubyObject 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 IRubyObject 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 IRubyObject setValueZeroDepthZero(IRubyObject value)
Description copied from class: DynamicScope
Set value zero in this scope;

Specified by:
setValueZeroDepthZero in class DynamicScope

setValueOneDepthZero

public IRubyObject setValueOneDepthZero(IRubyObject value)
Description copied from class: DynamicScope
Set value one in this scope.

Specified by:
setValueOneDepthZero in class DynamicScope

setValueTwoDepthZero

public IRubyObject setValueTwoDepthZero(IRubyObject value)
Description copied from class: DynamicScope
Set value two in this scope.

Specified by:
setValueTwoDepthZero in class DynamicScope

setValueThreeDepthZero

public IRubyObject setValueThreeDepthZero(IRubyObject value)
Description copied from class: DynamicScope
Set value three in this scope.

Specified by:
setValueThreeDepthZero in class DynamicScope

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

setArgValues

public void setArgValues(IRubyObject arg0)
Specified by:
setArgValues in class DynamicScope

setArgValues

public void setArgValues(IRubyObject arg0,
                         IRubyObject arg1)
Specified by:
setArgValues in class DynamicScope

setArgValues

public void setArgValues(IRubyObject arg0,
                         IRubyObject arg1,
                         IRubyObject arg2)
Specified by:
setArgValues in class DynamicScope

setEndArgValues

public void setEndArgValues(IRubyObject[] values,
                            int index,
                            int size)
Specified by:
setEndArgValues in class DynamicScope
Parameters:
values - group where last n(size) values are used
index - index in the dynamic scope to start setting these values
size - which of the last size arguments of values parameter to set

getArgValues

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

Specified by:
getArgValues in class DynamicScope

growIfNeeded

public void growIfNeeded()
Make a larger dynamic scope if the static scope grew. Eval's with bindings require us to possibly change the size of the dynamic scope if things like 'eval "b = 2", binding' happens.

Specified by:
growIfNeeded 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.