edu.rice.cs.dynamicjava.interpreter
Class TreeCompiler

java.lang.Object
  extended by edu.rice.cs.dynamicjava.interpreter.TreeCompiler

public class TreeCompiler
extends Object

Compiles an AST class declaration by producing a stub class, where each method consists of forwarding calls to the interpreter. To preserve enclosing context (since all DynamicJava class declarations appear in a local context), all constructors and static methods are parameterized by an additional RuntimeBindings argument (the exception is inner classes, where constructors are instead parameterized, as are standard javac compiled inner classes, by an enclosing object). A compiled class looks something like the following:

 class CompiledClass extends SuperClass {
   private static final TreeCompiler.EvaluationAdapter $adapter;
   final TreeCompiler.BindingsFactory $bindingsFactory;
 
   static String STATIC_FIELD;
   Number instanceField;
 
   static {
     $adapter = ((TreeClassLoader) CompiledClass.class.getClassLoader()).getAdapter("CompiledClass");
     STATIC_FIELD = $adapter.evaluateExpression("STATIC_FIELD", RuntimeBindings.EMPTY);
   }
 
   public CompiledClass(RuntimeBindings $bindings, int x, int y) {
     $bindingsFactory = $adapter.makeBindingsFactory($bindings);
     Object[] $args = new Object[]{ x, y };
     super($adapter.evaluateConstructorCallArg("(II)V", 0, $bindings, $args),
           $adapter.evaluateConstructorCallArg("(II)V", 1, $bindings, $args));
     instanceField = $adapter.evaluateExpression("instanceField", $bindingsFactory.value(this));
     $adapter.evaluateConstructorBody("(II)V", $bindingsFactory.value(this), $args);
   }
 
   public Number getInstanceField() {
     Object[] $args = new Object[]{};
     return $adapter.evaluateMethodBody("getInstance()Ljava/lang/Number;",
                                        $bindingsFactory.value(this), $args);
   }
 
   public static String staticMethod(RuntimeBindings $bindings, String arg) {
     Object[] $args = new Object[]{ arg };
     return $adapter.evaluateMethod("staticMethod(Ljava/lang/String;)Ljava/lang/String;",
                                    $bindings, $args);
   }
 
 }
 


Nested Class Summary
static class TreeCompiler.BindingsFactory
          A simple factory mapping an object to a RuntimeBindings in which that object is defined as "this".
 class TreeCompiler.EvaluationAdapter
          Provides an interface through which compiled classes can invoke the interpreter.
 
Constructor Summary
TreeCompiler(TreeClass treeClass, Options opt)
           
 
Method Summary
 byte[] bytecode()
           
 TreeCompiler.EvaluationAdapter evaluationAdapter()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeCompiler

public TreeCompiler(TreeClass treeClass,
                    Options opt)
Method Detail

bytecode

public byte[] bytecode()

evaluationAdapter

public TreeCompiler.EvaluationAdapter evaluationAdapter()