Monday, August 30, 2010

New Mint Release: r15716

As mentioned before, Eddy and I discovered a problem with type variables in code generated by the Mint compiler. We have now fixed this problem in the new release of Mint and DrJava with Mint: August 30, 2010 (r15716). The latest release is, as always, available from the Mint implementation page:
The problem occurred when the programmer used a type variable inside a bracket. An example of this would be a generic method like this:
public separable <X> Code<X> fun(Code<X> c1, Code<X> c2) {
return <| ( `(lfTest.eval(e,f).booleanCodeValue()) ?
`c2 : `c1 ) |>;
}
This caused Mint to generate 2nd stage code that contained the type variable X unbound. Unfortunately, the types are erased, and there is no way to find out what type X actually refers to at runtime, e.g. by writing something like X.class (this generates the Java compiler error "cannot select from a type variable").

To get around this problem, we now require a final instance of type Class<X> to be in scope for every type variable X. For example, in the generic method above, there is a type variable X that is being used in the bracket. Therefore, we now have to have a final instance of Class<X>somewhere in scope, for example as a method parameter.
public separable <X> Code<X> fun(Code<X> c1, Code<X> c2,
final Class<X> xc) {
return <| ( `(lfTest.eval(e,f).booleanCodeValue()) ?
`c2 : `c1 ) |>;
}
That's all that is necessary. The variable xc is not actually used in the code, it just needs to be in scope.

Tuesday, August 24, 2010

New Mint Release: r15707

When working on our GPCE tutorial, Eddy and I discovered a small bug in the Mint compiler which I have now fixed in the new release of Mint and DrJava with Mint: August 24, 2010 (r15707). The latest release is, as always, available from the Mint implementation page:
The only change I made was to fix the let expression pretty printer when the expression contained more than one declaration.

The problem never came up before because we only had one declaration per let expression, and it was always possible to rewrite

let int x = 1, y = 2; x+y


as

let int x = 1; let int y = 2; x+y


We are pushing the Mint compiler more, and we have discovered another problem with generic methods. Currently, Mint generates a class extending Code<X> with X occurring unbound when this method is called:

public separable abstract <X> Code<X> fun(Code<X> c1, Code<X>
c2, Object... param);


We are looking at making another bugfix soon.

Friday, August 20, 2010

New Mint Release: r15700

On Friday, I created a new release of Mint and DrJava with Mint: August 20, 2010 (r15700). The latest release is, as always, available from the Mint implementation page:
The only changes that we made were a small change to the build process on Mac OS, and the addition of the Range and Lift utility classes.

The Lift class allows the user to manually lift primitive values and strings when the compiler did not do that already, for example when working with arrays.

The Range class provides methods that allow many for loops to be written as foreach loops with a final loop variable that can be used across bracket boundaries immediately. Consider this example of a staged sparse matrix multiplication:

public static separable
Code<Void> smmult(final double[][] a,
Code<double[][]> b,
Code<double[][]> output,
int l, int m, int n) {
Code<Void> stats = <| { } |>;
for(final int i: range(0, l)) {
for(final int j: range(0, m)) {
Code<Double> c = <| 0.0 |>;
for(final int k: range(0, n)) {
if(a[i][k] == 0.0)
continue;
else if(a[i][k] == 1.0)
c = <| `c + (`b)[k][j] |>;
else
c = <| `c + (`(lift(a[i][k])) * (`b)[k][j]) |>;
}
stats = <| { `stats; (`output)[i][j] = `c; } |>;
}
}
return stats;
}


is a lot cleaner than

public static separable
Code<Void> smmult(final double[][] a,
Code<double[][]> b,
Code<double[][]> output,
int l, int m, int n) {
Code<Void> stats = <| { } |>;
for(int i = 0; i < l; i++) {
for(int j = 0; j < m; j++) {
final int ii = i;
final int jj = j;
Code<Double> c = <| 0.0 |>;
for(int k = 0; k < n; k++) {
final int kk = k;
if(a[i][k] == 0.0)
continue;
else if(a[i][k] == 1.0)
c = <| `c + (`b)[kk][jj] |>;
else
c = <| `c + (`(lift(a[ii][kk])) * (`b)[kk][jj]) |>;
}
stats = <| { `stats; (`output)[ii][jj] = `c; } |>;
}
}
return stats;
}


The ii, jj, and kk variables aren't necessary anymore.

Monday, August 16, 2010

GPCE'10 Tutorial Lecture: Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint

Eddy, Walid, and I proposed a tutorial lecture for GPCE'10, and we're delighted to report that it has been accepted for presentation on Sunday, October 10, 2010.

Agile and Efficient Domain-Specific Languages using Multi-stage Programming in Java Mint

Domain-specific languages (DSLs) are a powerful productivity tool because they allow domain experts, who are not necessarily programming experts, to quickly develop programs. DSL implementations have unique constraints for programming languages because they must be efficient, in order to ensure high productivity, but they must also be agile, in order to meet the rapidly changing demands of their domains. In this tutorial we show how multi-stage programming (MSP) can be used to build staged interpreters, which combine the agility of interpreters with the efficiency of compilers. The tutorial is conducted in Java Mint, an multi-stage Java based on recent work incorporating MSP into imperative object-oriented languages. In the first half of the tutorial, we introduce MSP by demonstrating how to write a staged interpreter for a number of basic language constructs, such as recursive functions, conditionals, and let expressions. In the second half, we extend our staged interpreter to take advantage of several well-known compiler optimizations, including type inference, constant folding, and static parallel loop scheduling. We highlight the opportunities afforded by using MSP with object-oriented design to quickly create efficient DSL implementations.



Brief Outline of Tutorial

This tutorial uses Java Mint to introduce MSP in imperative,
object-oriented languages. We will progress as follows:


  1. Introduction to MSP, the three language constructs "bracket",
    "escape" and "run", and their use in Java Mint.
  2. Brief overview of MSP applications other than interpreters.
  3. Development of a staged interpreter for a small DSL. We incrementally add:
    1. Arithmetic expressions
    2. Conditionals
    3. Recursive functions
    4. Let expressions
  4. Application of compiler optimizations in the interpreter for our DSL. We discuss:
    1. Extending the interpreter with multiple data types
    2. Type inference
    3. Constant folding
    4. Static parallel loop scheduling


Biographies

Mathias Ricken is a doctoral candidate in the Programming Languages Team at Rice University and one of the principal developers of the DrJava integrated development environment. His research interests include concurrent programming, extending the Java language, and computer science education. He is the developer of the Concutest concurrent unit testing framework and has created various experimental extensions of Java to address, for instance, programming with meta-data. Currently, Mathias is contributing to Java Mint, a multi-stage extension of Java that allows safe and expressive statically typed program generation and specialization in an imperative language setting.

Edwin Westbrook is a post-doctoral researcher at Rice University. His primary interests are in developing techniques for implementing and verifying properties of domain-specific languages (DSLs). He has worked on a number of projects in this area, including: Cinic, a type theory for building machine-checked proofs of properties of DSLs using a new approach to higher-order abstract syntax; Java Mint, a multi-stage version of Java used for efficient implementations of DSLs; and Acumen, a DSL for designing cyber-physical systems.

Walid Taha is an professor at Halmstad University. His current interest is in modeling and simulation of cyberphysical systems. He was the principal investigator on a number of research awards and contracts from the National Science Foundation (NSF), Semi-conductor Research Consortium (SRC), and Texas Advanced Technology Program (ATP). He received an NSF CAREER award to develop Java Mint. He is the principle designer Java Mint, Acumen, MetaOCaml, and the Verilog Preprocessor. He founded the ACM Conference on Generative Programming and Component Engineering (GPCE), the IFIP Working Group on Program Generation (WG 2.11), and the Middle Earth Programming Languages Seminar (MEPLS). In 2009, he chaired the IFIP Working Conference on Domain Specific Languages (DSLs).

New Version of DrJava with Mint: drjava-r5366-mint-r15665

The DrJava team released a new stable version of DrJava today, drjava-stable-20100816-r5366.

I therefore created a new release of DrJava with Mint: August 16, 2010 (drjava-r5366-mint-r15665.jar). The latest release is available from the Mint implementation page:
Nothing has changed on the Mint language side.