Advertisement

Marco: Safe, Expressive Macros for Any Language

  • Byeongcheol Lee
  • Robert Grimm
  • Martin Hirzel
  • Kathryn S. McKinley
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7313)

Abstract

Macros improve expressiveness, concision, abstraction, and language interoperability without changing the programming language itself. They are indispensable for building increasingly prevalent multilingual applications. Unfortunately, existing macro systems are well-encapsulated but unsafe (e.g., the C preprocessor) or are safe but tightly-integrated with the language implementation (e.g., Scheme macros). This paper introduces Marco, the first macro system that seeks both encapsulation and safety. Marco is based on the observation that the macro system need not know all the syntactic and semantic rules of the target language but must only directly enforce some rules, such as variable name binding. Using this observation, Marco off-loads most rule checking to unmodified target-language compilers and interpreters and thus becomes language-scalable. We describe the Marco language, its language-independent safety analysis, and how it uses two example target-language analysis plug-ins, one for C++ and one for SQL. This approach opens the door to safe and expressive macros for any language.

Keywords

Target Language Error Message Semantic Error Code Type Program Language Design 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Artzi, S., Kiezun, A., Dolby, J., Tip, F., Dig, D., Paradkar, A., Ernst, M.D.: Finding bugs in dynamic web applications. In: ACM International Symposium on Software Testing and Analysis, ISSTA (2008)Google Scholar
  2. 2.
    Bachrach, J., Playford, K.: The Java syntactic extender (JSE). In: ACM Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2001)Google Scholar
  3. 3.
    Brabrand, C., Schwartzbach, M.I., Vanggaard, M.: The metafront system: Extensible parsing and transformation. Electronic Notes in Theoretical Computer Science 82(3) (December 2003)Google Scholar
  4. 4.
    Chlipala, A.: Ur: Statically-typed metaprogramming with type-level record computation. In: ACM Conference on Programming Language Design and Implementation, PLDI (2010)Google Scholar
  5. 5.
    Clinger, W., Rees, J.: Macros that work. In: ACM Symposium on Principles of Programming Languages, POPL (1991)Google Scholar
  6. 6.
    Ernst, M.D., Badros, G.J., Notkin, D.: An empirical analysis of C preprocessor use. IEEE Transactions on Software Engineering (TSE) 28(12) (December 2002)Google Scholar
  7. 7.
    Gregor, D., Järvi, J., Siek, J., Stroustrup, B., Reis, G.D., Lumsdaine, A.: Concepts: Linguistic support for generic programming in C++. In: ACM Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2006)Google Scholar
  8. 8.
    Grimm, R.: Better extensibility through modular syntax. In: ACM Conference on Programming Language Design and Implementation, PLDI (2006)Google Scholar
  9. 9.
    Hartmann, B., MacDougall, D., Brandt, J., Klemmer, S.R.: What would other programmers do? Suggesting solutions to error messages. In: ACM Conference on Human Factors in Computing Systems, CHI (2010)Google Scholar
  10. 10.
    Hirzel, M., Grimm, R.: Jeannie: Granting Java native interface developers their wishes. In: ACM Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2007)Google Scholar
  11. 11.
    Huang, S.S., Smaragdakis, Y.: Expressive and safe static reflection with MorphJ. In: ACM Conference on Programming Language Design and Implementation, PLDI (2008)Google Scholar
  12. 12.
    Kim, I.-S., Yi, K., Calcagno, C.: A polymorphic modal type system for LISP-like multi-staged languages. In: ACM Symposium on Principles of Programming Languages, POPL (2006)Google Scholar
  13. 13.
    Kohlbecker, E., Friedman, D.P., Felleisen, M., Duba, B.: Hygienic macro expansion. In: ACM Conference on LISP and Functional Programming, LFP (1986)Google Scholar
  14. 14.
    Lerner, B.S., Flower, M., Grossman, D., Chambers, C.: Searching for type-error messages. In: ACM Conference on Programming Language Design and Implementation, PLDI (2007)Google Scholar
  15. 15.
  16. 16.
    Mendell, M., Nasgaard, H., Bouillet, E., Hirzel, M., Gedik, B.: Extending a general-purpose streaming system for XML. In: International Conference on Extending Database Technology, EDBT (2012)Google Scholar
  17. 17.
    Moggi, E., Taha, W., Benaissa, Z.-E.-A., Sheard, T.: An Idealized MetaML: Simpler, and More Expressive (Includes Proofs). In: Swierstra, S.D. (ed.) ESOP 1999. LNCS, vol. 1576, pp. 193–207. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  18. 18.
    Nystrom, N., Clarkson, M.R., Myers, A.C.: Polyglot: An Extensible Compiler Framework for Java. In: Hedin, G. (ed.) CC 2003. LNCS, vol. 2622, pp. 138–152. Springer, Heidelberg (2003)CrossRefGoogle Scholar
  19. 19.
    Roskind, J.: Parsing C, the last word. The comp.compilers newgroup (January 1992), http://groups.google.com/group/comp.compilers/msg/c0797b5b668605b4
  20. 20.
    Shalit, A.: The Dylan Reference Manual. Addison-Wesley (1996)Google Scholar
  21. 21.
    Sheard, T., Peyton Jones, S.: Template meta-programming for Haskell. ACM SIGPLAN Notices 37(12) (December 2002)Google Scholar
  22. 22.
    Strachey, C.: A general purpose macrogenerator. The Computer Journal (1965)Google Scholar
  23. 23.
    Stroustrup, B.: The C++ Programming Language. Addison Wesley (2000)Google Scholar
  24. 24.
    Tatlock, Z., Tucker, C., Shuffelton, D., Jhala, R., Lerner, S.: Deep typechecking and refactoring. In: ACM Conference on Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2008)Google Scholar
  25. 25.
    van den Brand, M.G.J., Heering, J., Klint, P., Olivier, P.A.: Compiling language definitions: The ASF+SDF compiler. ACM Transactions on Programming Languages and Systems (TOPLAS) 24(4) (July 2002)Google Scholar
  26. 26.
    Weise, D., Crew, R.: Programmable syntax macros. In: ACM Conference on Programming Language Design and Implementation, PLDI (1993)Google Scholar
  27. 27.
    Westbrook, E., Ricken, M., Inoue, J., Yao, Y., Abdelatif, T., Taha, W.: Mint: Java multi-stage programming using weak separability. In: ACM Conference on Programming Language Design and Implementation, PLDI (2010)Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Byeongcheol Lee
    • 1
  • Robert Grimm
    • 2
  • Martin Hirzel
    • 3
  • Kathryn S. McKinley
    • 4
    • 5
  1. 1.Gwangju Institute of Science and TechnologySouth Korea
  2. 2.New York UniversityUSA
  3. 3.IBM Watson Research CenterUSA
  4. 4.Microsoft ResearchUSA
  5. 5.The University of Texas at AustinUSA

Personalised recommendations