net.sf.jauvm
Class Interpreter

java.lang.Object
  extended by net.sf.jauvm.Interpreter
All Implemented Interfaces:
Runnable

public class Interpreter
extends Object
implements Runnable

A JVM byte code interpreter.

An Interpreter object wraps a given Runnable object, interpreting that object's run() method when its own run() method is invoked.

This class also holds this library's main(String[] args) method, that receives a fully qualified class name as its first argument and interprets that class's main(String[] args) method, passing it the remainder of its arguments.

Only methods tagged as interpretable are interpreted by an Interpreter.

See Also:
interpretable

Constructor Summary
Interpreter(Continuation cont)
          Constructs a new Interpreter object to return to the specified Continuation object's stored execution point.
Interpreter(Runnable run)
          Constructs a new Interpreter object to interpret the specified Runnable object.
 
Method Summary
static void main(String... args)
          The framework's main(String[] args) method.
 void run()
          Runs this Interpreter object, interpreting the underlying Runnable object's run() method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter(Runnable run)
Constructs a new Interpreter object to interpret the specified Runnable object.

Parameters:
run - the Runnable object whose run() method is to be interpreted
Throws:
NullPointerException - if run is null

Interpreter

public Interpreter(Continuation cont)
Constructs a new Interpreter object to return to the specified Continuation object's stored execution point.

Invoking this constructor has the same effect as:

  new Interpreter(new Runnable() {
      public @interpretable void run() {
          cont.returnTo();
      }
  });

The given Continuation must be of void return type.

Parameters:
cont - the Continuation object to which to return to
Throws:
NullPointerException - if cont is null
IllegalArgumentException - if cont is not of void return type
See Also:
Continuation.getReturnType()
Method Detail

run

public final void run()
Runs this Interpreter object, interpreting the underlying Runnable object's run() method.

Specified by:
run in interface Runnable
Throws:
UndeclaredThrowableException - if the underlying Runnable object's run() method throws a checked exception

main

public static void main(String... args)
                 throws Throwable
The framework's main(String[] args) method.

Loads the class specified by the first argument and interprets that class's main(String[] args) method, passing it the remainder of the arguments.

Alternatively, loads a serialized continuation from a file and returns to it, through the use of the Interpreter(Continuation) constructor.

Parameters:
args - the first argument is the fully qualified name of the class to interpret, and the remainder of the arguments are passed to that class's main(String[] args) method; alternatively, the first argument is -ser and the second argument is the file from which to load the continuation
Throws:
Throwable - any exception thrown as the result of trying to execute the classe's main(String[] args) method, or returning to the continuation
See Also:
Interpreter(Continuation)