In: Computer Science
When languages allow separate compilation, the compiler must decide on the compilation order. How does the Java compiler make that decision?
In practice, attening function arguments yields a substantial speedup for SML code and signi cantly reduces allocation. Much of the improvement claimed by Shao and Appel for their implementation of Leroy-style representation analysis is due to argument attening [110]. In particular, they reduced total execution time by 11% on average and allocation by 30% on average. I found similar performance advantages with argument attening in the context of the TIL compilerAfter demonstrating how multi-argument functions and polymorphic equality may be implemented in ML i , I sketch how other language constructs, notably C-style structsHaskell-style type classes, and polymorphic communication primitives, can be coded using dynamic type dispatch. The rest of this chapter proceeds as follows: I define the target language, Ximi-Rep.
Translation of Types I translate Mini-ML monotypes to ML i -Rep constructors via the function j j, which is de ned by induction on as follows: jtj = t jintj = Int j oatj = Float junitj = Unit jh1 2ij = hj1jj2ji j1 ! 2j = Vararg j1j j2j
Translation of Terms I specify the translation of Mini-ML expressions as a deductive system using judgments of the form ; ` e : ) e 0 where ; ` e : is a Mini-ML typing judgment and e 0 is the ML i -Rep translation of e. The axioms and inference rules that allow us to conclude this judgment
Translation of Equality The translation uses an auxiliary function, peq, that can be coded in the target language using typerec. Here, I use the pattern-matching syntax to de ne such a function Operationally, peq takes a constructor as an argument and selects the appropriate comparison function according to that constructor. For a product Prod(ta; tb), the appropriate function is constructed by using the inductive arguments peq[ta] and peq[tb] to compare the components of the product.
Translation of Functions There are three cases to consider when translating a -expression:
1. the argument type is known to be a tuple;
2. the argument type is int, oat, unit, or an arrow type;
3. the argument type is a type variable.
In the first case, the argument is a tuple. I need to produce a function that takes the components of the tuple directly as arguments. I translate the body of the function under the assumption that the argument was passed as a tuple. Then, I abstract the arguments appropriately. However, before executing the body of the function, I allocate a tuple and bind it to the original parameter, x.