Skip to main content
Erschienen in: Journal of Automated Reasoning 4/2022

11.08.2022

From Specification to Testing: Semantics Engineering for Lua 5.2

verfasst von: Mallku Soldevila, Beta Ziliani, Bruno Silvestre

Erschienen in: Journal of Automated Reasoning | Ausgabe 4/2022

Einloggen

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

search-config
loading …

Abstract

We provide a formal semantics for a large subset of the Lua programming language, in its version 5.2. The semantics is a major part of an ongoing effort to construct reliable tools to analyze Lua code. In this work, we present the details of several key aspects of the language, like the semantics of its only structured data-type (tables), its meta-programming mechanism (metatables), error handling, and how these mechanisms are used to define a complex dynamic semantics that must deal with several possible erroneous situations during run time, given the nature of the language. The semantics is mechanized in Redex, a DSL specially designed to specify and debug operational semantics. We validated the mechanization in two ways: first, by executing within Redex the test suite of the reference interpreter of Lua, and second, by specifying and performing random testing of its fundamental properties using the redex-check tool. Together, they evidence that our model soundly captures the semantics of the selected fragment of the language. Additionally, we address some of the performance problems that typically arise when testing a mechanization in Redex, by using a simple implementation of a reachability-based garbage collector that captures key aspects of Lua’s. By collecting syntactic garbage, we reduce the size of configurations during run time. Finally, we briefly discuss this avenue of development of our semantics, together with the implementation of a prototype tool to perform static analysis of Lua programs.

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 "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!

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!

Fußnoten
3
Our definition enforces left-to-right evaluation of expressions. Even if this is left unspecified in Lua’s reference manual, that is how expressions are evaluated in the two most popular implementations of Lua, the reference interpreter and LuaJIT (luajit.org).
 
5
This distinction helped simplify the model, as we do not need to define new notions of evaluation contexts to distinguish among either case—a task that proved to be cumbersome and difficult to maintain through the evolution of the model.
 
6
We thank the reviewers for inviting us to enrich our model with this and other features.
 
7
Note that LuaJIT 2.0, the other major implementation of (part of) Lua 5.2, does not perform caching of closures.
 
8
We do not include the value store since our subset implemented so far does not require it, but this may change in the future.
 
9
The language of patterns from Redex is expressive enough to be able to impose, for example, the expected representation invariant for a term that describes a finite functional mapping.
 
10
The first set of references from which reachability is computed.
 
11
While we do model tail calls, the actual testing of the mechanism in the official test suite consists in performing several recursive calls, beyond the stack limit, to actually test if the mechanism is being used. Given that performing such amount of recursive calls is not feasible within our mechanization (because of the time required), we do not include such tests.
 
12
On a system running Arch Linux updated to May, 2022, Racket v8.3, and 12 parallel processes on an Intel Core i7-10870H CPU @ 4GHz \(\times \) 8, with 16GB of RAM.
 
13
Remember that, at each iteration, a new local variable https://static-content.springer.com/image/art%3A10.1007%2Fs10817-022-09638-y/MediaObjects/10817_2022_9638_Figbz_HTML.gif is created, to contain the corresponding value in the interval [1, 100].
 
14
Note about numeric representations: The official interpreter follows the IEEE 754 standard, while Racket has a richer set of numbers and behaviors, even including complex numbers. Therefore, it is required to convert to the required representation of numbers in order to correctly emulate the behavior of Lua.
 
15
To obtain these measures we added custom Racket code to our module Tests/RandomTesting/soundness/soundness_rand_test.rkt. We do not include it in the provided source code, tough the code reduces to counting well-formed configurations and recognizing the biggest configurations generated.
 
Literatur
2.
Zurück zum Zitat Bodin, M., Chargueraud, A., Filaretti, D., Gardner, P., Maffeis, S., Naudziuniene, D., Schmitt, A., Smith, G.: A trusted mechanised JavaScript specification. In: POPL ’14 (2014) Bodin, M., Chargueraud, A., Filaretti, D., Gardner, P., Maffeis, S., Naudziuniene, D., Schmitt, A., Smith, G.: A trusted mechanised JavaScript specification. In: POPL ’14 (2014)
3.
Zurück zum Zitat Donnelly, K., Hallett, J.J., Kfoury, A.: Formal semantics of weak references. In: ISMM ’06 Proceedings of the 5th international symposium on Memory management, pp. 126–137 (2006) Donnelly, K., Hallett, J.J., Kfoury, A.: Formal semantics of weak references. In: ISMM ’06 Proceedings of the 5th international symposium on Memory management, pp. 126–137 (2006)
4.
Zurück zum Zitat Felleisen, M.: The calculi of lambda-v-cs conversion: a syntactic theory of control and state in imperative higher-order programming languages. PhD thesis, Indiana University (1987) Felleisen, M.: The calculi of lambda-v-cs conversion: a syntactic theory of control and state in imperative higher-order programming languages. PhD thesis, Indiana University (1987)
5.
Zurück zum Zitat Felleisen, M., Finlder, R.B., Flatt, M.: Semantics Engineering with PLT Redex. The MIT Press, Cambridge (2009)MATH Felleisen, M., Finlder, R.B., Flatt, M.: Semantics Engineering with PLT Redex. The MIT Press, Cambridge (2009)MATH
8.
Zurück zum Zitat Guha, A., Saftoiu, C., Krishnamurthi, S.: The essence of JavaScript. In: ECOOP ’10 (2010) Guha, A., Saftoiu, C., Krishnamurthi, S.: The essence of JavaScript. In: ECOOP ’10 (2010)
9.
Zurück zum Zitat Haas, A., Rossberg, A., Schuff, D.L., Titzer, B.L., Holman, M., Gohman, D., Wagner, L., Zakai, A., Bastien, J.: Bringing the web up to speed with WebAssembly. In: Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, Association for Computing Machinery, New York, NY, USA, PLDI 2017, pp. 185–200. https://doi.org/10.1145/3062341.3062363 (2017) Haas, A., Rossberg, A., Schuff, D.L., Titzer, B.L., Holman, M., Gohman, D., Wagner, L., Zakai, A., Bastien, J.: Bringing the web up to speed with WebAssembly. In: Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, Association for Computing Machinery, New York, NY, USA, PLDI 2017, pp. 185–200. https://​doi.​org/​10.​1145/​3062341.​3062363 (2017)
10.
Zurück zum Zitat Ierusalimschy, R.: Programming in Lua. Lua.org (2003) Ierusalimschy, R.: Programming in Lua. Lua.org (2003)
11.
Zurück zum Zitat Ierusalimschy, R., de Figueiredo, L.H., Celes, W.: Lua—an extensible extension language. Software 26(6), 635–652 (1996) Ierusalimschy, R., de Figueiredo, L.H., Celes, W.: Lua—an extensible extension language. Software 26(6), 635–652 (1996)
12.
Zurück zum Zitat Ierusalimschy, R., de Figueiredo, L.H., Celes, W.: The evolution of an extension language: a history of lua. In: Brazilian Symposium on Programming Languages (2001) Ierusalimschy, R., de Figueiredo, L.H., Celes, W.: The evolution of an extension language: a history of lua. In: Brazilian Symposium on Programming Languages (2001)
14.
Zurück zum Zitat Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: a minimal core calculus for Java and GJ. TOPLAS 23, 396–450 (2001)CrossRef Igarashi, A., Pierce, B.C., Wadler, P.: Featherweight Java: a minimal core calculus for Java and GJ. TOPLAS 23, 396–450 (2001)CrossRef
15.
Zurück zum Zitat Klein, C.: Randomized testing in PLT Redex. In: Proc. Scheme and Functional Programming, pp. 26–36 (2009) Klein, C.: Randomized testing in PLT Redex. In: Proc. Scheme and Functional Programming, pp. 26–36 (2009)
16.
Zurück zum Zitat Klein, C., McCarthy, J., Jaconette, S., Findler, R.B.: A semantics for context-sensitive reduction semantics. In: APLAS’11 (2011) Klein, C., McCarthy, J., Jaconette, S., Findler, R.B.: A semantics for context-sensitive reduction semantics. In: APLAS’11 (2011)
17.
Zurück zum Zitat Klein, C., Clements, J., Dimoulas, C., Eastlund, C., Felleisen, M., Flatt, M., McCarthy, J.A., Rafkind, J., Tobin-Hochstadt, S., Findler, R.B.: Run your research: On the effectiveness of lightweight mechanization. In: Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, ACM, New York, NY, USA, POPL ’12, pp 285–296, https://doi.org/10.1145/2103656.2103691 (2012) Klein, C., Clements, J., Dimoulas, C., Eastlund, C., Felleisen, M., Flatt, M., McCarthy, J.A., Rafkind, J., Tobin-Hochstadt, S., Findler, R.B.: Run your research: On the effectiveness of lightweight mechanization. In: Proceedings of the 39th Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, ACM, New York, NY, USA, POPL ’12, pp 285–296, https://​doi.​org/​10.​1145/​2103656.​2103691 (2012)
20.
Zurück zum Zitat Lin, H.: Operational Semantics for Featherweight Lua. Master’s thesis, San José State University (2015) Lin, H.: Operational Semantics for Featherweight Lua. Master’s thesis, San José State University (2015)
29.
Zurück zum Zitat Maffeis, S., Mitchell, J.C., Taly, A.: An operational semantics for JavaScript. In: APLAS ’08 (2008) Maffeis, S., Mitchell, J.C., Taly, A.: An operational semantics for JavaScript. In: APLAS ’08 (2008)
31.
Zurück zum Zitat Mascarenhas de Queiroz, F.: Optimized compilation of a dynamic language to a managed runtime environment. PhD thesis, Pontifícia Universidade Católica do Rio de Janeiro (2009) Mascarenhas de Queiroz, F.: Optimized compilation of a dynamic language to a managed runtime environment. PhD thesis, Pontifícia Universidade Católica do Rio de Janeiro (2009)
32.
Zurück zum Zitat Moura, A., Rodriguez, N., Ierusalimschy, R.: Coroutines in lua. J. Univers. Comput. Sci. 10(7), 910–25 (2004) Moura, A., Rodriguez, N., Ierusalimschy, R.: Coroutines in lua. J. Univers. Comput. Sci. 10(7), 910–25 (2004)
33.
Zurück zum Zitat Pierce, B.C.: Types and Programming Languages, 1st edn. The MIT Press, Cambridge (2002)MATH Pierce, B.C.: Types and Programming Languages, 1st edn. The MIT Press, Cambridge (2002)MATH
34.
Zurück zum Zitat Politz, J.G., Carroll, M.J., Lerner, B.S., Pombrio, J., Krishnamurthi, S.: A tested semantics for getters, setters, and eval in JavaScript. In: DLS ’12 (2012) Politz, J.G., Carroll, M.J., Lerner, B.S., Pombrio, J., Krishnamurthi, S.: A tested semantics for getters, setters, and eval in JavaScript. In: DLS ’12 (2012)
35.
Zurück zum Zitat Politz, J.G., Martinez, A., Milano, M., Warren, S., Patterson, D., Li, J., Chitipothu, A., Krishnamurthi, S.: Python: the full monty: a tested semantics for the Python programming language. In: OOPSLA ’13 (2013) Politz, J.G., Martinez, A., Milano, M., Warren, S., Patterson, D., Li, J., Chitipothu, A., Krishnamurthi, S.: Python: the full monty: a tested semantics for the Python programming language. In: OOPSLA ’13 (2013)
37.
Zurück zum Zitat Soldevila, M., Ziliani, B., Silvestre, B., Fridlender, D., Mascarenhas, F.: Decoding Lua: Formal semantics for the developer and the semanticist. In: Proceedings of the 13th ACM SIGPLAN Dynamic Languages Symposium, DLS 2017 (2017) Soldevila, M., Ziliani, B., Silvestre, B., Fridlender, D., Mascarenhas, F.: Decoding Lua: Formal semantics for the developer and the semanticist. In: Proceedings of the 13th ACM SIGPLAN Dynamic Languages Symposium, DLS 2017 (2017)
38.
Zurück zum Zitat Soldevila, M., Ziliani, B., Fridlender, D.: Understanding Lua’s garbage collection: Towards a formalized static analyzer. In: Proceedings of the 22nd International Symposium on Principles and Practice of Declarative Programming, PPDP 2020 (2020) Soldevila, M., Ziliani, B., Fridlender, D.: Understanding Lua’s garbage collection: Towards a formalized static analyzer. In: Proceedings of the 22nd International Symposium on Principles and Practice of Declarative Programming, PPDP 2020 (2020)
Metadaten
Titel
From Specification to Testing: Semantics Engineering for Lua 5.2
verfasst von
Mallku Soldevila
Beta Ziliani
Bruno Silvestre
Publikationsdatum
11.08.2022
Verlag
Springer Netherlands
Erschienen in
Journal of Automated Reasoning / Ausgabe 4/2022
Print ISSN: 0168-7433
Elektronische ISSN: 1573-0670
DOI
https://doi.org/10.1007/s10817-022-09638-y

Weitere Artikel der Ausgabe 4/2022

Journal of Automated Reasoning 4/2022 Zur Ausgabe