org.jruby.compiler.ir
Class IRScopeImpl

java.lang.Object
  extended by org.jruby.compiler.ir.IRScopeImpl
All Implemented Interfaces:
IRScope
Direct Known Subclasses:
IRExecutionScope, IRModule, IRScript

public abstract class IRScopeImpl
extends java.lang.Object
implements IRScope

Right now, this class abstracts 5 different scopes: Script, Module, Class, Method, and Closure. Script, Module, and Class are containers and "non-execution" scopes. Method and Closure are the only two "execution" scopes. In the compiler-land, IR_* versions of these scopes encapsulate only as much information as is required to convert Ruby code into equivalent Java code. But, in the non-compiler land, there will be a corresponding java object for each of these scopes which encapsulates the runtime semantics and data needed for implementing them. In the case of Module, Class, and Method, they also happen to be instances of the corresponding Ruby classes -- so, in addition to providing code that help with this specific ruby implementation, they also have code that let them behave as ruby instances of their corresponding classes. Script and Closure have no such Ruby companions, as far as I can tell. Examples: - the runtime class object might have refs. to the runtime method objects. - the runtime method object might have a slot for a heap frame (for when it has closures that need access to the method's local variables), it might have version information, it might have references to other methods that were optimized with the current version number, etc. - the runtime closure object will have a slot for a heap frame (for when it has closures within) and might get reified as a method in the java land (but inaccessible in ruby land). So, passing closures in Java land might be equivalent to passing around the method handles. and so on ...


Constructor Summary
IRScopeImpl(IRScope lexicalParent, Operand container, java.lang.String name, StaticScope staticScope)
           
 
Method Summary
 void addInstr(Instr i)
          methods and closures
 Operand getContainer()
          Returns the containing parent scope
 RubyModule getContainerModule()
           
 java.util.List<Instr> getInstrs()
           
 IRScope getLexicalParent()
          Returns the lexical scope that contains this scope definition
 java.lang.String getName()
           
 IRModule getNearestModule()
          Returns the nearest module/class from this scope which may be itself.
 Variable getNewInlineVariable()
           
 Label getNewLabel()
          Get a new label using a generic prefix
 Label getNewLabel(java.lang.String prefix)
          Get a new label using the provided label prefix
 Variable getNewTemporaryClosureVariable(int closureId)
           
 Variable getNewTemporaryVariable()
          create a new temporary variable
 int getNextClosureId()
          Get the next available unique closure id for closures in this scope
protected  int getPrefixCountSize(java.lang.String prefix)
           
 int getRenamedVariableSize()
          How many renamed variables are in this scope?
abstract  java.lang.String getScopeName()
           
 StaticScope getStaticScope()
           
 int getTemporaryVariableSize()
          How many temporary variables are in this scope?
 void prepareForInterpretation()
           
 void recordMethodAlias(java.lang.String newName, java.lang.String oldName)
          Record that newName is a new method name for method with oldName This is for the 'alias' keyword which resolves method names in the static compile/parse-time context
 void runCompilerPass(CompilerPass p)
          Run the passed in compiler pass on this scope!
 void runCompilerPassOnNestedScopes(CompilerPass p)
           
 void setContainer(Operand o)
           
 void setName(java.lang.String name)
           
 java.lang.String toString()
           
 java.lang.String toStringInstrs()
           
 java.lang.String toStringVariables()
           
 java.lang.String unaliasMethodName(java.lang.String name)
          Unalias 'name' and return new name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jruby.compiler.ir.IRScope
getLocalVariable
 

Constructor Detail

IRScopeImpl

public IRScopeImpl(IRScope lexicalParent,
                   Operand container,
                   java.lang.String name,
                   StaticScope staticScope)
Method Detail

setContainer

public void setContainer(Operand o)

getContainer

public Operand getContainer()
Description copied from interface: IRScope
Returns the containing parent scope

Specified by:
getContainer in interface IRScope

getContainerModule

public RubyModule getContainerModule()

getLexicalParent

public IRScope getLexicalParent()
Description copied from interface: IRScope
Returns the lexical scope that contains this scope definition

Specified by:
getLexicalParent in interface IRScope

getNearestModule

public IRModule getNearestModule()
Description copied from interface: IRScope
Returns the nearest module/class from this scope which may be itself.

Specified by:
getNearestModule in interface IRScope

getNextClosureId

public int getNextClosureId()
Description copied from interface: IRScope
Get the next available unique closure id for closures in this scope

Specified by:
getNextClosureId in interface IRScope

getNewTemporaryClosureVariable

public Variable getNewTemporaryClosureVariable(int closureId)

getNewTemporaryVariable

public Variable getNewTemporaryVariable()
Description copied from interface: IRScope
create a new temporary variable

Specified by:
getNewTemporaryVariable in interface IRScope

getNewInlineVariable

public Variable getNewInlineVariable()

getTemporaryVariableSize

public int getTemporaryVariableSize()
Description copied from interface: IRScope
How many temporary variables are in this scope?

Specified by:
getTemporaryVariableSize in interface IRScope

getRenamedVariableSize

public int getRenamedVariableSize()
Description copied from interface: IRScope
How many renamed variables are in this scope?

Specified by:
getRenamedVariableSize in interface IRScope

getName

public java.lang.String getName()
Specified by:
getName in interface IRScope

setName

public void setName(java.lang.String name)

getScopeName

public abstract java.lang.String getScopeName()

getNewLabel

public Label getNewLabel(java.lang.String prefix)
Description copied from interface: IRScope
Get a new label using the provided label prefix

Specified by:
getNewLabel in interface IRScope

getNewLabel

public Label getNewLabel()
Description copied from interface: IRScope
Get a new label using a generic prefix

Specified by:
getNewLabel in interface IRScope

getPrefixCountSize

protected int getPrefixCountSize(java.lang.String prefix)

getStaticScope

public StaticScope getStaticScope()
Specified by:
getStaticScope in interface IRScope

addInstr

public void addInstr(Instr i)
Description copied from interface: IRScope
methods and closures

Specified by:
addInstr in interface IRScope

recordMethodAlias

public void recordMethodAlias(java.lang.String newName,
                              java.lang.String oldName)
Description copied from interface: IRScope
Record that newName is a new method name for method with oldName This is for the 'alias' keyword which resolves method names in the static compile/parse-time context

Specified by:
recordMethodAlias in interface IRScope

unaliasMethodName

public java.lang.String unaliasMethodName(java.lang.String name)
Description copied from interface: IRScope
Unalias 'name' and return new name

Specified by:
unaliasMethodName in interface IRScope

getInstrs

public java.util.List<Instr> getInstrs()

toString

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

runCompilerPassOnNestedScopes

public void runCompilerPassOnNestedScopes(CompilerPass p)

runCompilerPass

public void runCompilerPass(CompilerPass p)
Description copied from interface: IRScope
Run the passed in compiler pass on this scope!

Specified by:
runCompilerPass in interface IRScope

prepareForInterpretation

public void prepareForInterpretation()
Specified by:
prepareForInterpretation in interface IRScope

toStringInstrs

public java.lang.String toStringInstrs()

toStringVariables

public java.lang.String toStringVariables()


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