User Guide - Part One
As I promised yesterday, today, I'll start a series of entries with a very rough first user guide for the JauVM.
Lets start with the interpreter itself.
In the proposal text there's a brief description on what Interpreter
objects should look like. Lets elaborate a bit on that:
Interpreter.java
package net.sf.jauvm;
public class Interpreter implements Runnable {
private final Runnable r;
public Interpreter(final Runnable r) {
this.r = r;
}
public Interpreter(final Continuation c) {
this.r = new Runnable() {
public @interpretable void run() {
c.continueFrom();
}
};
}
public void run() {
// interpret r.run()
}
}
This is pretty much what I had already described, though there are some new things.
As you can see, I've “added” a second constructor that takes a
Continuation
which is then continued when the interpreter is run. This is handy when you wish to call a continuation you've just deserialized on a new Interpreter
object.It also serves the purpose of showing you how to write an interpretable method: just tag it with the
@interpretable
annotation. Here is the code for this annotation:interpretable.java
package net.sf.jauvm;
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface interpretable {}
The fact that an
Interpreter
implements Runnable
facilitates the creation of an interpreter on a new thread, look:new Thread(new Interpreter(new Runnable() {
public @interpretable void run() {
// ...
}
})).start();
Tomorrow, I'll shed some light what tail-calls look like.
No comments:
Post a Comment