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).

11 comments:

  1. Only after attending the salesforce online training, I got selected for job in a multi national company in India. Thanks for support and information provided on this website..

    ReplyDelete
  2. commission express franchiseI would like to thank you for your nicely written post, its informative and your writing style encouraged me to read it till end. Thanks

    ReplyDelete

  3. Another great articles and very interesting to read,thanks for sharing that wonderful useful information,given programming coding was very excellent and easily observe all provided information.
    Oracle SQL Training in Chennai

    ReplyDelete
  4. Hadoop training institutes in hyderabad .All the basic and get the full knowledge of

    hadoop.
    hadoop training institutes in

    hyderabad

    ReplyDelete
  5. Well said ,you have furnished the right information that will be useful to anyone at all time.Thanks for sharing your Ideas.
    hadoop online training

    ReplyDelete