Translating Smalltalk blocks to Java

Roelof Lourens Engelbrecht, D.G. Kourie · IEE Proceedings - Software · 2003

The translational semantics of Smalltalk blocks are provided in Java. The focus is thus on ensuring that the translated Java code has precisely the same functionality as the Smalltalk code. Anonymous inner classes are used. In such a class, a value( ) method is defined that embodies the Java translation of the block's contents. Static scoping references have to be communicated to the inner class by means of an array parameter whose indices are declared as final. Smalltalk block evaluation in the presence of a nonlocal return is mimicked in Java by defining and throwing block exceptions. The proposed approach can translate nested Smalltalk blocks. Minor adjustments have to be made for Smalltalk references to self. Results of performance and conformance tests are provided. The former quantifies the penalty incurred by using block exceptions. The latter were applied to the two most significant Smalltalk to Java commercial translators, and verified the accuracy of block semantics in one case but exposed deficiencies in the other.

Read the paper · More papers on PaperTik