org.jruby.runtime
Class DynamicScope

java.lang.Object
  extended byorg.jruby.runtime.DynamicScope

public class DynamicScope
extends java.lang.Object

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


Constructor Summary
DynamicScope(StaticScope staticScope, DynamicScope parent)
           
 
Method Summary
 DynamicScope cloneScope()
           
 java.lang.String[] getAllNamesInScope()
          Get all variable names captured (visible) by this scope (sans $~ and $_).
 void getArgValues(IRubyObject[] args, int size)
          Copy variable values back for ZSuper call.
 IRubyObject getBackRef()
           
 DynamicScope getBindingScope()
           
 IRubyObject getLastLine()
           
 DynamicScope getNextCapturedScope()
          Get next 'captured' scope.
 StaticScope getStaticScope()
          Get the static scope associated with this DynamicScope.
 IRubyObject getValue(int offset, int depth)
          Get value from current scope or one of its captured scopes.
 IRubyObject[] getValues()
           
 void growIfNeeded()
          Make a larger dynamic scope if the static scope grew.
 void setArgValues(IRubyObject[] values, int size)
          Set all values which represent 'normal' parameters in a call list to this dynamic scope.
 void setBackRef(IRubyObject value)
           
 void setBindingScope(DynamicScope bindingScope)
           
 void setBlockArgValues(IRubyObject[] blockArgValues, int size)
           
 void setLastLine(IRubyObject value)
           
 void setValue(int offset, IRubyObject value, int depth)
          Set value in current dynamic scope or one of its captured scopes.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DynamicScope

public DynamicScope(StaticScope staticScope,
                    DynamicScope parent)
Method Detail

cloneScope

public DynamicScope cloneScope()

getAllNamesInScope

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

Returns:
a list of variable names

getValues

public IRubyObject[] getValues()

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.

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

setValue

public 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

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.

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

setBlockArgValues

public void setBlockArgValues(IRubyObject[] blockArgValues,
                              int size)

getArgValues

public void getArgValues(IRubyObject[] args,
                         int size)
Copy variable values back for ZSuper call.


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.


setLastLine

public void setLastLine(IRubyObject value)

getLastLine

public IRubyObject getLastLine()

setBackRef

public void setBackRef(IRubyObject value)

getBackRef

public IRubyObject getBackRef()

getBindingScope

public DynamicScope getBindingScope()

setBindingScope

public void setBindingScope(DynamicScope bindingScope)

getNextCapturedScope

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

Returns:
the scope captured by this scope for implementing closures

getStaticScope

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

Returns:
static complement to this scope

toString

public java.lang.String toString()


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