Advertisement

Formal Aspects of Computing

, Volume 22, Issue 5, pp 489–535 | Cite as

An algebraic approach to the design of compilers for object-oriented languages

  • Adolfo DuranEmail author
  • Ana Cavalcanti
  • Augusto Sampaio
Original Article

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.

Keywords

Algebraic transformation Refinement Compiler correctness 

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. ASU85.
    Aho AV, Sethi R, Ullman JD (1985) Compilers: principles, techniques, and tools. Addison-Wesley Longman Publishing Co., Inc, ReadingGoogle Scholar
  2. Bac80.
    Back R (1980) Correct preserving program refinements: proof theory and application, volume 131 of Mathematical centre tracts. Mathematical Centre, AmsterdamGoogle Scholar
  3. BB08.
    Börger E, Batory DS (2008) Coupling design and verification in software product lines. In: FoIKS, pp 1–4Google Scholar
  4. BG08a.
    Blech JO, Grégoire B (2008) Certifying code generation with Coq. In: Workshop Compiler Optimization meets Compiler Verification (COCV 2008), ENTCS. ElsevierGoogle Scholar
  5. BG08b.
    Blech JO, Grégoire B (2008) Certifying code generation with Coq: A tool description. In: Workshop Compiler Optimization meets Compiler Verification (COCV 2008), ENTCS. ElsevierGoogle Scholar
  6. Bow98.
    Bowen M (1998) Handel-C Language Reference Manual, 2.1. Embedded Solutions LimitedGoogle Scholar
  7. BS98.
    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–35Google Scholar
  8. BSC03.
    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–482Google Scholar
  9. BSCC04.
    Borba P, Sampaio A, Cavalcanti A, Cornélio M (2004) Algebraic reasoning for object-oriented programming. Sci Comput Program 52(1-3): 53–100zbMATHCrossRefGoogle Scholar
  10. BvW90.
    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–66Google Scholar
  11. BvW98.
    Back R, von Wright J (1990) Refinement calculus: a systematic introduction. Springer, New YorkGoogle Scholar
  12. CCS02.
    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–660Google Scholar
  13. CN00.
    Cavalcanti A, Naumann D (2000) A weakest precondition semantics for refinement of object-oriented programs. IEEE Trans Softw Eng 26(08): 713–728CrossRefGoogle Scholar
  14. Cor04.
    Cornélio M (2004) Applying object-oriented refactoring and patterns as formal refinements. PhD thesis, Universidade Federal de PernambucoGoogle Scholar
  15. DCS02.
    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–358Google Scholar
  16. DCS03.
    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, SpringerGoogle Scholar
  17. DDDCG02.
    Drossopoulou S, Damiani F, Dezani-Ciancaglini M, Giannini P (2002) More dynamic object reclassification: Fickle II. ACM Trans Program Lang Syst 24(2): 153–191CrossRefGoogle Scholar
  18. Dij76.
    Dijkstra EW (1976) A discipline of programming. Prentice-Hall, Engewood CliffszbMATHGoogle Scholar
  19. Dur05.
    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/
  20. Fow99.
    Fowler M (1999) Refactoring: improving the design of existing code. Addison-Wesley Longman Publishing Co., Inc., ReadingGoogle Scholar
  21. GJSB00.
    Gosling J, Joy B, Steele G, Bracha G (2000) The Java Language Specification, 2nd edn. Addison-Wesley, ReadingGoogle Scholar
  22. 1.
    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–16Google Scholar
  23. HCW08.
    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–155Google Scholar
  24. He93.
    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–546Google Scholar
  25. HHS93.
    Hoare CAR, He J, Sampaio A (1993) Normal form approach to compiler design. Acta Inform 30: 701–739zbMATHCrossRefMathSciNetGoogle Scholar
  26. HJ98.
    Hoare CAR, Jifeng He (1998) Unifying theories of programming. Prentice-Hall, Englewood CliffsGoogle Scholar
  27. HU98.
    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–204Google Scholar
  28. KN06.
    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
  29. Ler09.
    Leroy X (2009) Formal verification of a realistic compiler. Commun ACM 52(7): 107–115CrossRefGoogle Scholar
  30. LF02.
    Lermer K, Fidge C (2002) A formal model of real-time program compilation. Theor Comput Sci 282(1): 151–190zbMATHCrossRefMathSciNetGoogle Scholar
  31. LT01.
    Lam H, Thai T (2001) NET framework essentials. O’Reilly & Associates, Inc. , SebastopolGoogle Scholar
  32. LY97.
    Lindholm T, Yellin F (1997) The Java virtual machine specification. Addison-Wesley, ReadingGoogle Scholar
  33. MO97.
    Müller-Olm M (1997) Modular compiler verification: a refinement-algebraic approach advocating stepwise abstraction. SpringerGoogle Scholar
  34. Mor94.
    Morgan C (1994) Programming from specifications, 2nd edn. Prentice-Hall, Inc., Englewood CliffszbMATHGoogle Scholar
  35. MP67.
    McCarthy J, Painter J (1967) Correctness of a compiler for arithmetic expressions. In: Symposium on applied mathematics, vol 19. American Mathematical Society, pp 33–41Google Scholar
  36. NO98.
    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–170Google Scholar
  37. Opd92.
    Opdyke W (1992) Refactoring object-oriented frameworks. PhD thesis, University of Illinois at Urbana-ChampaignGoogle Scholar
  38. PH05.
    Patterson DA, Hennessy JL (2005) Computer organization and design: The Hardware/software Interface. Morgan KaufmannGoogle Scholar
  39. Pla01.
    Platt DS (2001) Introducing Microsoft .NET. Microsoft PressGoogle Scholar
  40. Pol81.
    Polak W (1981) Compiler specification and verification. Springer, New YorkzbMATHGoogle Scholar
  41. PW07a.
    Perna JI, Woodcock J (2007) A denotational semantics for Handel-C hardware compilation. In: ICFEM, pp 266–285Google Scholar
  42. PW07b.
    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, DecemberGoogle Scholar
  43. PW08.
    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 2008Google Scholar
  44. Sam97.
    Sampaio A (1997) An algebraic approach to compiler design, vol 4 of AMAST Series in Computing. World ScientificGoogle Scholar
  45. SCS06.
    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–37Google Scholar
  46. Ser99.
    Serrano M (1999) Wide classes. Lecture Notes in Computer ScienceGoogle Scholar
  47. SSB01.
    Stärk R, Schmid J, Börger E (2001) Java and the Java Virtual Machine-Definition, Verification, Validation. SpringerGoogle Scholar
  48. SSL08.
    Silva L, Sampaio A, Liu Z (2008) Laws of object-orientation with reference semantics. Software engineering and formal methods. Int Confer 0: 217–226CrossRefGoogle Scholar
  49. Tia06.
    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–51Google Scholar
  50. TWW81.
    Thatcher JW, Wagner EG, Wright JB (1981) More on advice on structuring compilers and proving them correct. Theor Comput Sci 15: 223–249zbMATHCrossRefGoogle Scholar
  51. Wat03.
    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–305Google Scholar
  52. Wil02.
    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–510Google Scholar

Copyright information

© British Computer Society 2009

Authors and Affiliations

  1. 1.Universidade Federal da Bahia, Centro de Processamento de Dados MEFES Research GroupSalvadorBrazil
  2. 2.Department of Computer ScienceUniversity of YorkYorkUK
  3. 3.Universidade Federal de Pernambuco, Centro de InformáticaRecifeBrazil

Personalised recommendations