Abstract
In this paper we describe an algebraic approach to construct provably correct compilers for object-oriented languages; this is illustrated for programs written in a language similar to a sequential subset of Java. It includes recursive classes, inheritance, dynamic binding, recursion, type casts and test, assignment, and class-based visibility, but a copy semantics. In our approach, we tackle the problem of compiler correctness by reducing the task of compilation to that of program refinement. Compilation is identified with the reduction of a source program to a normal form that models the execution of object code. The normal form is generated by a series of correctness-preserving transformations that are proved sound from the basic laws of the language; therefore it is correct by construction. The main advantages of our approach are the characterisation of compilation within a uniform framework, where comparisons and translations between semantics are avoided, and the modularity and extensibility of the resulting compiler.
Similar content being viewed by others
References
Aho AV, Sethi R, Ullman JD (1985) Compilers: principles, techniques, and tools. Addison-Wesley Longman Publishing Co., Inc, Reading
Back R (1980) Correct preserving program refinements: proof theory and application, volume 131 of Mathematical centre tracts. Mathematical Centre, Amsterdam
Börger E, Batory DS (2008) Coupling design and verification in software product lines. In: FoIKS, pp 1–4
Blech JO, Grégoire B (2008) Certifying code generation with Coq. In: Workshop Compiler Optimization meets Compiler Verification (COCV 2008), ENTCS. Elsevier
Blech JO, Grégoire B (2008) Certifying code generation with Coq: A tool description. In: Workshop Compiler Optimization meets Compiler Verification (COCV 2008), ENTCS. Elsevier
Bowen M (1998) Handel-C Language Reference Manual, 2.1. Embedded Solutions Limited
Börger E, Schulte W (1998) Defining the java virtual machine as platform for provably correct java compilation. In: MFCS ’98: Proceedings of the 23rd international symposium on mathematical foundations of computer science. Springer, London, pp 17–35
Borba P, Sampaio A, Cornélio M (2003) A refinement algebra for object-oriented programming. In: ECOOP 2003: European conference on object-oriented programming 2003, vol 2743. LNCS, Springer, pp 457–482
Borba P, Sampaio A, Cavalcanti A, Cornélio M (2004) Algebraic reasoning for object-oriented programming. Sci Comput Program 52(1-3): 53–100
Back R, von Wright J (1990) Refinement calculus, part I: sequential nondeterministic programs. In: REX workshop: Proceedings on stepwise refinement of distributed systems: models, formalisms, correctness, Springer, pp 42–66
Back R, von Wright J (1990) Refinement calculus: a systematic introduction. Springer, New York
Cornélio M, Cavalcanti A, Sampaio A (2002) Refactoring by Transformation. In: REFINE 2002 Workshop, Electronic notes in theoretical computer science, vol 70, Springer, pp 641–660
Cavalcanti A, Naumann D (2000) A weakest precondition semantics for refinement of object-oriented programs. IEEE Trans Softw Eng 26(08): 713–728
Cornélio M (2004) Applying object-oriented refactoring and patterns as formal refinements. PhD thesis, Universidade Federal de Pernambuco
Duran A, Cavalcanti A, Sampaio A (2002) Refinement algebra for formal bytecode generation. In: ICFEM 2002-4th international conference on formal engineering methods (LNCS), vol 2495. Springer, Shanghai, pp 347–358
Duran A, Cavalcanti A, Sampaio A (2003) A strategy for compiling classes, inheritance, and dynamic binding. In: FME 2003-International symposium of formal methods Europe, vol 2805, pp 301–320. Pisa, September 2003. LNCS, Springer
Drossopoulou S, Damiani F, Dezani-Ciancaglini M, Giannini P (2002) More dynamic object reclassification: Fickle II. ACM Trans Program Lang Syst 24(2): 153–191
Dijkstra EW (1976) A discipline of programming. Prentice-Hall, Engewood Cliffs
Duran A (2005) An algebraic approach to the design of compilers for object-oriented languages. PhD thesis, Universidade Federal de Pernambuco. Available at http://www.les.ufba.br/duranthesis/
Fowler M (1999) Refactoring: improving the design of existing code. Addison-Wesley Longman Publishing Co., Inc., Reading
Gosling J, Joy B, Steele G, Bracha G (2000) The Java Language Specification, 2nd edn. Addison-Wesley, Reading
Hayes IJ (1998) Separating timing and calculation in real-time refinement. In: Gundy J, Schwenke M, Vickers T (eds) Pacific’98: international refinement workshop and formal methods, Discrete mathematics and theoretical computer science, Springer, pp 1–16
Harwood W, Cavalcanti ALC, Woodcock JCP (2008) A theory of pointers for the UTP. In: Fitzgerald JS, Haxthausen AE, Yenigun H (eds) Theoretical aspects of computing (Lecture Notes in Computer Science), vol 5160. Springer, Berlin, pp 141–155
He J (1993) Hybrid parallel programming and implementation of synchronised communication. In: MFCS ’93: Proceedings of the 18th international symposium on mathematical foundations of computer science (LNCS), vol 711. Springer, London, pp 537–546
Hoare CAR, He J, Sampaio A (1993) Normal form approach to compiler design. Acta Inform 30: 701–739
Hoare CAR, Jifeng He (1998) Unifying theories of programming. Prentice-Hall, Englewood Cliffs
Hayes IJ, Utting M (1998) Deadlines are termination. In: Gries D, de Roever W-P (eds) PROCOMET’98: IFIP—international conference on programming concepts and methods. Chapman and Hall, pp 186–204
Klein G, Nipkow T (2006) A machine-checked model for a Java-like language, virtual machine and compiler. ACM Trans Program Lang Syst 28(4):619–695 http://doi.acm.org/10.1145/1146809.1146811
Leroy X (2009) Formal verification of a realistic compiler. Commun ACM 52(7): 107–115
Lermer K, Fidge C (2002) A formal model of real-time program compilation. Theor Comput Sci 282(1): 151–190
Lam H, Thai T (2001) NET framework essentials. O’Reilly & Associates, Inc. , Sebastopol
Lindholm T, Yellin F (1997) The Java virtual machine specification. Addison-Wesley, Reading
Müller-Olm M (1997) Modular compiler verification: a refinement-algebraic approach advocating stepwise abstraction. Springer
Morgan C (1994) Programming from specifications, 2nd edn. Prentice-Hall, Inc., Englewood Cliffs
McCarthy J, Painter J (1967) Correctness of a compiler for arithmetic expressions. In: Symposium on applied mathematics, vol 19. American Mathematical Society, pp 33–41
Nipkow T, Oheimb D (1998) Java-light is type-safe—definitely. In: POPL ’98: Proceedings of the 25th ACM SIGPLAN- SIGACT symposium on principles of programming languages. ACM Press, New York, pp 161–170
Opdyke W (1992) Refactoring object-oriented frameworks. PhD thesis, University of Illinois at Urbana-Champaign
Patterson DA, Hennessy JL (2005) Computer organization and design: The Hardware/software Interface. Morgan Kaufmann
Platt DS (2001) Introducing Microsoft .NET. Microsoft Press
Polak W (1981) Compiler specification and verification. Springer, New York
Perna JI, Woodcock J (2007) A denotational semantics for Handel-C hardware compilation. In: ICFEM, pp 266–285
Perna JI, Woodcock J (2007) Proving wire-wise correctness for Handel-C compilation in HOL. Technical Report YCS-2008-429, Computer Science Department, The University of York, December
Perna JI, Woodcock J (2008) Wire-wise correctness for handel-C synthesis in HOL. In: Pace GJ, Singh S (eds) Seventh International workshop on designing correct circuits (DCC), pp 86–100, March 2008
Sampaio A (1997) An algebraic approach to compiler design, vol 4 of AMAST Series in Computing. World Scientific
Santos TLVL, Cavalcanti ALC, Sampaio ACA (2006) Object Orientation in the UTP. In: Dunne S, Stoddart B (eds) Unifying theories of programming (Lecture Notes in Computer Science), vol 4010. Springer, pp 18–37
Serrano M (1999) Wide classes. Lecture Notes in Computer Science
Stärk R, Schmid J, Börger E (2001) Java and the Java Virtual Machine-Definition, Verification, Validation. Springer
Silva L, Sampaio A, Liu Z (2008) Laws of object-orientation with reference semantics. Software engineering and formal methods. Int Confer 0: 217–226
Tian YH (2006) Mechanically verifying correctness of CPS compilation. In: CATS ’06: Proceedings of the 12th computing: the Australasian theroy symposium, Darlinghurst, Australia, Australian Computer Society, Inc., pp 41–51
Thatcher JW, Wagner EG, Wright JB (1981) More on advice on structuring compilers and proving them correct. Theor Comput Sci 15: 223–249
Watson G (2003) Compilation by refinement for a practical assembly language. In: Formal methods and software engineering. ICFEM 2003: 5th international conference on formal engineering methods (LNCS), vol 2885. Springer, Singapore, November 2003, pp 286–305
Wildman L (2002) A formal basis for a program compilation proof tool. In: FME ’02: Proceedings of the international symposium of formal methods Europe on formal methods—getting IT right (LNCS), vol 2391. Springer, London, pp 491–510
Author information
Authors and Affiliations
Corresponding author
Additional information
Michael Butler and Cliff Jones
Rights and permissions
About this article
Cite this article
Duran, A., Cavalcanti, A. & Sampaio, A. An algebraic approach to the design of compilers for object-oriented languages. Form Asp Comp 22, 489–535 (2010). https://doi.org/10.1007/s00165-009-0124-9
Received:
Accepted:
Published:
Issue Date:
DOI: https://doi.org/10.1007/s00165-009-0124-9