Abstract
Program transformations in terms of abstract syntax trees compromise referential integrity by introducing variable capture. Variable capture occurs when in the generated program a variable declaration accidentally shadows the intended target of a variable reference. Existing transformation systems either do not guarantee the avoidance of variable capture or impair the implementation of transformations.
We present an algorithm called name-fix that automatically eliminates variable capture from a generated program by systematically renaming variables. name-fix is guided by a graph representation of the binding structure of a program, and requires name-resolution algorithms for the source language and the target language of a transformation. name-fix is generic and works for arbitrary transformations in any transformation system that supports origin tracking for names. We verify the correctness of name-fix and identify an interesting class of transformations for which name-fix provides hygiene. We demonstrate the applicability of name-fix for implementing capture-avoiding substitution, inlining, lambda lifting, and compilers for two domain-specific languages.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Similar content being viewed by others
References
Barzilay, E., Culpepper, R., Flatt, M.: Keeping it clean with syntax parameters. In: Scheme (2011)
Bawden, A., Rees, J.: Syntactic closures. In: LFP, pp. 86–95. ACM (1988)
Clinger, W., Rees, J.: Macros that work. In: POPL, pp. 155–162. ACM (1991)
Czarnecki, K., Helsen, S.: Feature-based survey of model transformation approaches. IBM Systems Journal 45(3), 621–645 (2006)
de Bruijn, N.G.: Lambda calculus notation with nameless dummies, a tool for automatic formula manipulation, with application to the Church-Rosser theorem. Indagationes Mathematicae 75(5), 381–392 (1972)
de Jonge, M., Visser, E.: A language generic solution for name binding preservation in refactorings. In: LDTA. ACM (2012)
Dybvig, R.K., Hieb, R., Bruggeman, C.: Syntactic abstraction in scheme. Lisp and Symbolic Computation 5(4), 295–326 (1992)
Erdweg, S.: Extensible Languages for Flexible and Principled Domain Abstraction. PhD thesis, Philipps-Universität Marburg (2013)
Erdweg, S., van der Storm, T., Dai, Y.: Capture-avoiding and hygienic program transformations (incl. proofs). CoRR, abs/1404.5770 (2014)
Erdweg, S., et al.: The state of the art in language workbenches. In: Erwig, M., Paige, R.F., Van Wyk, E. (eds.) SLE 2013. LNCS, vol. 8225, pp. 197–217. Springer, Heidelberg (2013)
Herman, D.: A Theory of Typed Hygienic Macros. PhD thesis, Northeastern University, Boston, Massachusetts (2012)
Izmaylova, A., Klint, P., Shahi, A., Vinju, J.: M3: An open model for measuring source code artifacts. arXiv:1312.1188, BENEVOL 2013 (2013)
Johnsson, T.: Lambda lifting: Transforming programs to recursive equations. In: Jouannaud, J.-P. (ed.) FPCA 1985. LNCS, vol. 201, pp. 190–203. Springer, Heidelberg (1985)
Klint, P., van der Storm, T., Vinju, J.: Rascal: A domain-specific language for source code analysis and manipulation. In: SCAM, pp. 168–177 (2009)
Kohlbecker, E., Friedman, D.P., Felleisen, M., Duba, B.: Hygienic macro expansion. In: LFP, pp. 151–161. ACM (1986)
Lee, B., Grimm, R., Hirzel, M., McKinley, K.S.: Marco: Safe, expressive macros for any language. In: Noble, J. (ed.) ECOOP 2012. LNCS, vol. 7313, pp. 589–613. Springer, Heidelberg (2012)
B.C.: d. S. Oliveira and A. Löh. Abstract syntax graphs for domain specific languages. In: PEPM, pp. 87–96. ACM (2013)
Paige, R.F., Kolovos, D.S., Polack, F.A.C.: Metamodelling for grammarware researchers. In: Czarnecki, K., Hedin, G. (eds.) SLE 2012. LNCS, vol. 7745, pp. 64–82. Springer, Heidelberg (2013)
Pfenning, F., Elliott, C.: Higher-order abstract syntax. In: PLDI, pp. 199–208. ACM (1988)
Reps, T., Teitelbaum, T., Demers, A.: Incremental context-dependent analysis for language-based editors. TOPLAS 5(3), 449–477 (1983)
Schäfer, M., Ekman, T., de Moor, O.: Sound and extensible renaming for Java. In: OOPSLA, pp. 227–294. ACM (2008)
Sheard, T.: Accomplishments and research challenges in meta-programming. In: Taha, W. (ed.) SAIG 2001. LNCS, vol. 2196, pp. 2–44. Springer, Heidelberg (2001)
Shinwell, M.R., Pitts, A.M., Gabbay, M.J.: FreshML: Programming with binders made simple. In: ICFP, pp. 263–274. ACM (2003)
Macko, M., Batory, D.: Scoping constructs for software generators. In: Czarnecki, K. (ed.) GCSE 1999. LNCS, vol. 1799, pp. 65–78. Springer, Heidelberg (2000)
Valdera, P.I., van der Storm, T., Erdweg, S.: Tracing model transformations with string origins. In: ICMT. Springer (to appear, 2014)
van den Bos, J., van der Storm, T.: Bringing domain-specific languages to digital forensics. In: ICSE, pp. 671–680. ACM (2011)
van Deursen, A., Klint, P., Tip, F.: Origin tracking. Symbolic Computation 15, 523–545 (1993)
Wachsmuth, G., Konat, G.D.P., Vergu, V.A., Groenewegen, D.M., Visser, E.: A language independent task engine for incremental name and type analysis. In: Erwig, M., Paige, R.F., Van Wyk, E. (eds.) SLE 2013. LNCS, vol. 8225, pp. 260–280. Springer, Heidelberg (2013)
Author information
Authors and Affiliations
Editor information
Editors and Affiliations
1 Electronic Supplementary Material
Rights and permissions
Copyright information
© 2014 Springer-Verlag Berlin Heidelberg
About this paper
Cite this paper
Erdweg, S., van der Storm, T., Dai, Y. (2014). Capture-Avoiding and Hygienic Program Transformations. In: Jones, R. (eds) ECOOP 2014 – Object-Oriented Programming. ECOOP 2014. Lecture Notes in Computer Science, vol 8586. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-662-44202-9_20
Download citation
DOI: https://doi.org/10.1007/978-3-662-44202-9_20
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-662-44201-2
Online ISBN: 978-3-662-44202-9
eBook Packages: Computer ScienceComputer Science (R0)