On the use of LISP in implementing denotational semantics

Automatic compiler generators and semantics systems typically produce compilers which depend heavily on the mechanism of ~-reduction. This is particularly true of them systems based on denotational romant ic , since their descriptive notatious are bMmd on the A-calculus. Performing/kroductious is expeus/ve, however, and this is a primary reason for the extreme inefficiency of automaticaUy-pnerated compilers and the code they produce. Since LISP is in many respects sim~ar to the A-calculus, it seems a reasonable idea to generate compilers which rely on the LISP EVAL function rather than a ~-reducer. Then, the expensive simulation of p-reductious is avoided, and the efficiency of LISP is obtained. Unfortunately, moving to LISP is complicated by the fact that the generated compilers quite often depend on t jS-reducer's ability to part/a/It, evaluate an e x p r e s s i o n a capability lacking in LISP. We have implemented s compiler generator called MESS which produces realistic and efficient compilers written in SGHEME. MESS proceues modtdar denotational dcmcriptionm, and exploits this modularity in order to avoid the dependence on partial evaluation. An added benefit of our approach is that the output of the generated compilem can be directly processed by an automatically-generated table-driven code generator. This makes it possible to obtain object code which compares favorably with that produced by hand-crafted compilers. Our results thub far are quite encouraging, as we are finding that the compilers generated by MESS are significantly more efficient and realistic than those produced by other systems. Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the tide of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specfic permission. I n t r o d u c t i o n Several compiler generators end semantics systems have been developed [Mos79,Pan82,Wan84] based on the direct implementation of denotational semantics [Sto77]. The compilers generated by these systems work in a rather strange way. Given t source program, they typically derive its A-expression *meaning" by performing a eynta.xdirected translation based on the semantic equations. This A-expression is then usually simplified, through ~-reduction, as much as possible at compile time. The resultant A-expreuion is taken as the object code and can be %xecuted" by performing further ~-reductions in the presence of an input file. Unfortunately, these compilers are not very practical. This is due in large part to their inefficiency, which stems from the expense of performing fl-reductious. Since LISP is in many respects similar to the A-calculus (particularly lexically-scoped, full-funarg LISP dialects such as SCHEME [StS78]), it seems reasonable to allow the generated compilers to derive LISP programs instead of A-expressions. This would allow the use of a LISP implementation's compiler or EVAL function in executing the "object" code. Then, the explicit simulation of/~-reductions is avoided, and the efficiency of LISP is obtained. The problem with this approach is that LISP programs are evaluated in one fell swoop m there is no concept of "partial" evaluation as there is when considering the ~O-reduction of A-expressions. This is particularly crippling at compile time, when certain runtime entiti . es, such as the program input file, may be "unbound. " Since most LISP implementations treat the evaluation of unbound entities as fatal errors, a generated compiler based on LISP would often fail during compilation. On the other hand, a ~-reduction mechanism in the same situation simply stops evaluation, and re. turns the partially-reduced expression as the "answer. " Furthermore, this "answer" expression has the desirable property that only/runtime compurations are left to do all compile time computations have at this point been reduced away. In order for compiler generation based on denotational semantics to become feasible for realistic and useful languages, we believe the generated © 1986 ACM 0-89791-200-4/86/0800-0233 75¢ 233