Thursday, September 30, 2010

New Mint Release: r15858

I made a new release of Mint and DrJava with Mint yesterday: September 29, 2010 (r15858). The latest release is, as always, available from the Mint implementation page:

We have added the edu.rice.cs.mint.runtime.CodeFree interface and the edu.rice.cs.mint.runtime.CheckedExceptionInCode exception class.

The CodeFree interface provides a different, more transparent way of specifying separable classes that can be used for non-local assignments and CSP. When a class is declared to implement the CodeFree interface, the class is guaranteed to be code-free, provided a number of static checks are passed:
  1. All field types and method return types are code-free, either using the old definition that required the types to be final, or by themselves implementing the CodeFree interface.
  2. The same applies to all subtypes of types implementing the CodeFree interface. It is an error to extend a class declared to be code-free using the CodeFree interface and then to add a field containing or a method returning code.
This new rule makes it simpler to work with non-primitive types since the classes do not have to be final anymore. In the past, lifting had to be done instead of using CSP; that is not necessary anymore. Consider the old code with the required lift method and its application instead of straight-forward CSP:

public abstract class Value {
public separable int intValue() { throw new WrongTypeException(); }
public separable boolean booleanValue() { throw new WrongTypeException(); }
public separable abstract boolean valueEq(Value other);
public separable abstract Code<Value> lift();
}

public class IntValue extends Value {
private int _data;
// ...
public separable Code<Value> lift() {
final int lfData = _data; // hack to help the Mint compiler
return <| (Value) new IntValue(lfData) |>;
}
}

public class BooleanValue extends Value {
private boolean _data;
// ...
public separable Code<Value> lift() {
final boolean lfData = _data; // hack to help the Mint compiler
return <| (Value) new BooleanValue(lfData) |>;
}
}

// ...

public class Val implements Exp {
private Code<Value> _value;
public Val(final Value value) {
_value = value.lift(); // lifting here
}
// ...
}
and the new code that doesn't require the lift method anymore:

public abstract class Value implements CodeFree, Serializable {
public separable int intValue() { throw new WrongTypeException(); }
public separable boolean booleanValue() { throw new WrongTypeException(); }
public separable abstract boolean valueEq(Value other);
}

public class IntValue extends Value {
private int _data;
// ...
}

public class BooleanValue extends Value {
private boolean _data;
// ...
}

// ...

public class Val implements Exp {
private Code<Value> _value;
public Val(final Value value) {
_value = <| value |>; // straight-forward CSP
}
// ...
}


Please note that a class used in CSP still needs to be serializable if the code object it is used in is to be saved using MintSerializer.save. That means that whenever you implement CodeFree, you should consider also implementing the java.io.Serializable interface.

The second change involves the way checked exceptions are thrown inside a code object. In the past, checked exceptions were not allowed, because the Code.run() method did not have a throws Throwable clause.

We still didn't add such a clause, because it would essentially require a try-catch construct around every call to Code.run(). Instead, checked exceptions are caught and rethrown wrapped in a edu.rice.cs.mint.runtime.CheckedExceptionInCode unchecked exception. Here is an example:

public static separable void m() throws IOException {
new File("/this/is/a/bad/path").createNewFile(); // throws IOException
}

// ...

SafeCode<Void> c = <| { m(); } |>;
try {
c.run();
}
catch(CheckedExceptionInCode ce) {
Throwable cause = ce.getCause();
// ...
}
We also improved error checking for calls to separable methods and fixed a bug that required SafeCode<T> in too many places.

The version of DrJava with Mint is based on the current trunk (and therefore is newer than the updated stable release of DrJava that was recently made available).

Thursday, September 16, 2010

New Mint Release: r15772

We have just made a new release of Mint and DrJava with Mint: September 16, 2010 (r15772). The latest release is, as always, available from the Mint implementation page:


We have added the edu.rice.cs.mint.runtime.MintSerializer class to it that can write code object, including CSP data, to a jar file (or whatever stream you like), and then restore it again. Here is a very simple example:

Code c = <|123|>;
File f = new File(dir, "IntegerCode1.jar");
MintSerializer.save(c, "IntegerCode1", f);

Integer s = MintSerializer.load(f);
System.out.println(s);


The version of DrJava with Mint is based on the current trunk (and not on updated stable release of DrJava that was made available this week).

Wednesday, September 1, 2010

Mint on the Mac

I guess I'm a bit behind the technology curve. The MacBook that I'm using as one of my development machines is one of the original white Intel MacBooks with a Core Duo CPU (not Core 2 Duo). It's a 32-bit machine, and Apple doesn't offer Java 6 for 32-bit computers.

Mint, however, requires a version of Java 6, which is why we recommended using SoyLatte to run Mint. That comes with all kinds of inconveniences because SoyLatte uses X11 for its GUIs, which means DrJava needs to run under X11.

Yesterday I tested Mint and DrJava with Mint using Apple's Java SE 6.0 Release 1 Developer Preview 6 (file name: javase6release1dp6.dmg), which I still had floating around and which is the last version of Apple's Java 6 that still runs on 32-bit Macs. It works! SoyLatte is only required if you don't have a version of Java 6 (either Apple's official version on 64-bit Macs, or Apple's Java SE 6.0 Release 1 Developer Preview 6 on 32-bit Macs) on your Mac.

I have updated the instructions on how to install Java Mint on the Mac and how to run DrJava with Mint accordingly.