Skip to main content

2015 | OriginalPaper | Buchkapitel

Preserving Lexical Scoping When Dynamically Embedding Languages

verfasst von : Félix Ribeiro, Hisham Muhammad, André Murbach Maidl, Roberto Ierusalimschy

Erschienen in: Programming Languages

Verlag: Springer International Publishing

Aktivieren Sie unsere intelligente Suche, um passende Fachinhalte oder Patente zu finden.

search-config
loading …

Abstract

There are various situations in which one may want to embed source code from one language into another, for example when combining relational query languages with application code or when performing staged meta-programming. Typically, one will want to transfer data between these languages. We propose an approach in which the embedded code shares variables with the host language, preserving lexical scoping rules even after the code is converted into an intermediate representation. We demonstrate this approach through a module for meta-programming using Lua as both embedded and host languages. Our technique supports dynamically generated code, requires no special annotation of functions to be translated and is implemented as a library, requiring no source pre-processing or changes to the host language execution environment.

Sie haben noch keine Lizenz? Dann Informieren Sie sich jetzt über unsere Produkte:

Springer Professional "Wirtschaft+Technik"

Online-Abonnement

Mit Springer Professional "Wirtschaft+Technik" erhalten Sie Zugriff auf:

  • über 102.000 Bücher
  • über 537 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Maschinenbau + Werkstoffe
  • Versicherung + Risiko

Jetzt Wissensvorsprung sichern!

Springer Professional "Technik"

Online-Abonnement

Mit Springer Professional "Technik" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 390 Zeitschriften

aus folgenden Fachgebieten:

  • Automobil + Motoren
  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Elektrotechnik + Elektronik
  • Energie + Nachhaltigkeit
  • Maschinenbau + Werkstoffe




 

Jetzt Wissensvorsprung sichern!

Springer Professional "Wirtschaft"

Online-Abonnement

Mit Springer Professional "Wirtschaft" erhalten Sie Zugriff auf:

  • über 67.000 Bücher
  • über 340 Zeitschriften

aus folgenden Fachgebieten:

  • Bauwesen + Immobilien
  • Business IT + Informatik
  • Finance + Banking
  • Management + Führung
  • Marketing + Vertrieb
  • Versicherung + Risiko




Jetzt Wissensvorsprung sichern!

Fußnoten
1
Note that in C# parlance, lambda expression is a more general term that can refer to both single-expression anonymous functions called expression lambdas and multi-statement functions called statement lambdas. Conversion to expression trees is only supported for expression lambdas.
 
2
The semantics of Lua Core in [4] is based on an environment \(\varSigma =(\varGamma ,S,F)\) where F is specific to Terra functions. In our presentation, we removed F. Rules reused from [4] were adapted accordingly.
 
Literatur
1.
Zurück zum Zitat Bawden, A.: Quasiquotation in Lisp. In: Danvy, O. (ed.) Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (PEPM 1999). Number NS-99-1 in BRICS Note Series, pp. 4–12, San Antonio, Texas (1999) Bawden, A.: Quasiquotation in Lisp. In: Danvy, O. (ed.) Proceedings of the ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation (PEPM 1999). Number NS-99-1 in BRICS Note Series, pp. 4–12, San Antonio, Texas (1999)
2.
Zurück zum Zitat Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using ASTs, gensym, and reflection. In: Pfenning, F., Macko, M. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003) CrossRef Calcagno, C., Taha, W., Huang, L., Leroy, X.: Implementing multi-stage languages using ASTs, gensym, and reflection. In: Pfenning, F., Macko, M. (eds.) GPCE 2003. LNCS, vol. 2830, pp. 57–76. Springer, Heidelberg (2003) CrossRef
3.
Zurück zum Zitat Czarnecki, K., O’Donnell, J.T., Striegnitz, J., Taha, W.: DSL implementation in MetaOCaml, template haskell, and C++. In: Lengauer, C., Batory, D., Blum, A., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 51–72. Springer, Heidelberg (2004) CrossRef Czarnecki, K., O’Donnell, J.T., Striegnitz, J., Taha, W.: DSL implementation in MetaOCaml, template haskell, and C++. In: Lengauer, C., Batory, D., Blum, A., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 51–72. Springer, Heidelberg (2004) CrossRef
4.
Zurück zum Zitat DeVito, Z., Hegarty, J., Aiken, A., Hanrahan, P., Vitek, J.: Terra: a multi-stage language for high-performance computing. In: Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, pp. 105–116, New York, NY, USA, ACM (2013) DeVito, Z., Hegarty, J., Aiken, A., Hanrahan, P., Vitek, J.: Terra: a multi-stage language for high-performance computing. In: Proceedings of the 34th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2013, pp. 105–116, New York, NY, USA, ACM (2013)
6.
Zurück zum Zitat Fleutot, F., Tratt, L.: Contrasting compile-time meta-programming in Metalua and converge. In: Proceedings of the Workshop on Dynamic Languages and Applications (2007) Fleutot, F., Tratt, L.: Contrasting compile-time meta-programming in Metalua and converge. In: Proceedings of the Workshop on Dynamic Languages and Applications (2007)
7.
Zurück zum Zitat Fowler, M.: Domain Specific Languages, 1st edn. Addison-Wesley Professional, Boston (2010) Fowler, M.: Domain Specific Languages, 1st edn. Addison-Wesley Professional, Boston (2010)
8.
Zurück zum Zitat Ierusalimschy, R.: Programming in Lua, 2nd edn. Lua.Org (2006) Ierusalimschy, R.: Programming in Lua, 2nd edn. Lua.Org (2006)
9.
Zurück zum Zitat Kameyama, Y., Kiselyov, O., Shan, C.C.: Closing the stage: from staged code to typed closures. In: Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, PEPM 2008, pp. 147–157, New York, NY, USA, ACM (2008) Kameyama, Y., Kiselyov, O., Shan, C.C.: Closing the stage: from staged code to typed closures. In: Proceedings of the 2008 ACM SIGPLAN Symposium on Partial Evaluation and Semantics-based Program Manipulation, PEPM 2008, pp. 147–157, New York, NY, USA, ACM (2008)
11.
Zurück zum Zitat McCarthy, J.: Recursive functions of symbolic expressions and their computation by machine, part I. Commun. ACM 3(4), 184–195 (1960)CrossRefMATH McCarthy, J.: Recursive functions of symbolic expressions and their computation by machine, part I. Commun. ACM 3(4), 184–195 (1960)CrossRefMATH
14.
Zurück zum Zitat Taha, W.: Multi-stage programming: its theory and applications. Ph.D thesis, Oregon Graduate Institute of Science and Technology (1999) Taha, W.: Multi-stage programming: its theory and applications. Ph.D thesis, Oregon Graduate Institute of Science and Technology (1999)
15.
Zurück zum Zitat Taha, W.: A gentle introduction to multi-stage programming. In: Lengauer, C., Batory, D., Blum, A., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 30–50. Springer, Heidelberg (2004) CrossRef Taha, W.: A gentle introduction to multi-stage programming. In: Lengauer, C., Batory, D., Blum, A., Odersky, M. (eds.) Domain-Specific Program Generation. LNCS, vol. 3016, pp. 30–50. Springer, Heidelberg (2004) CrossRef
16.
Zurück zum Zitat Taha, W.: A gentle introduction to multi-stage programming, part II. In: Lämmel, R., Visser, J., Saraiva, J. (eds.) Generative and Transformational Techniques in Software Engineering II. LNCS, vol. 5235, pp. 260–290. Springer, Heidelberg (2008) CrossRef Taha, W.: A gentle introduction to multi-stage programming, part II. In: Lämmel, R., Visser, J., Saraiva, J. (eds.) Generative and Transformational Techniques in Software Engineering II. LNCS, vol. 5235, pp. 260–290. Springer, Heidelberg (2008) CrossRef
17.
Zurück zum Zitat Westbrook, E., Ricken, M., Inoue, J., Yao, Y., Abdelatif, T., Taha, W.: Mint: java multi-stage programming using weak separability. In: Proceedings of the 2010 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2010, pp. 400–411, New York, NY, USA, ACM (2010) Westbrook, E., Ricken, M., Inoue, J., Yao, Y., Abdelatif, T., Taha, W.: Mint: java multi-stage programming using weak separability. In: Proceedings of the 2010 ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2010, pp. 400–411, New York, NY, USA, ACM (2010)
Metadaten
Titel
Preserving Lexical Scoping When Dynamically Embedding Languages
verfasst von
Félix Ribeiro
Hisham Muhammad
André Murbach Maidl
Roberto Ierusalimschy
Copyright-Jahr
2015
DOI
https://doi.org/10.1007/978-3-319-24012-1_3