{"title":"一个非常简单的Lua编译器——扩展版","authors":"Hugo Musso Gualandi, Roberto Ierusalimschy","doi":"10.1016/j.cola.2022.101151","DOIUrl":null,"url":null,"abstract":"<div><p>Dynamically-typed programming languages are often implemented using interpreters, which offer several advantages in terms of portability and flexibility of the implementation. However, as a language matures and its programs get bigger, programmers may seek compilers, to avoid the interpretation overhead.</p><p>In this study, we present LuaAOT, a simple ahead-of-time compiler for Lua derived from the reference Lua interpreter. We describe two alternative compilation strategies. The first one exemplifies an old idea of using partial evaluation to produce a compiler based on an existing interpreter. Its contribution is to apply this idea to a well-established programming language. We show that with a quite modest effort it is possible to implement an efficient compiler that covers the entirety of Lua, including coroutines and tail calls. The whole implementation required less than 500 lines of new code. For this effort, we reduced the running time of our benchmarks from 20% to 60%.</p><p>The second compilation strategy is based on function “outlining”, where each bytecode is implemented by a small subroutine. This strategy reduces executable sizes and compilation times, at the cost of not speeding up the running times as much as the first compilation method.</p></div>","PeriodicalId":48552,"journal":{"name":"Journal of Computer Languages","volume":"72 ","pages":"Article 101151"},"PeriodicalIF":1.7000,"publicationDate":"2022-10-01","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":"{\"title\":\"A surprisingly simple Lua compiler—Extended version\",\"authors\":\"Hugo Musso Gualandi, Roberto Ierusalimschy\",\"doi\":\"10.1016/j.cola.2022.101151\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"<div><p>Dynamically-typed programming languages are often implemented using interpreters, which offer several advantages in terms of portability and flexibility of the implementation. However, as a language matures and its programs get bigger, programmers may seek compilers, to avoid the interpretation overhead.</p><p>In this study, we present LuaAOT, a simple ahead-of-time compiler for Lua derived from the reference Lua interpreter. We describe two alternative compilation strategies. The first one exemplifies an old idea of using partial evaluation to produce a compiler based on an existing interpreter. Its contribution is to apply this idea to a well-established programming language. We show that with a quite modest effort it is possible to implement an efficient compiler that covers the entirety of Lua, including coroutines and tail calls. The whole implementation required less than 500 lines of new code. For this effort, we reduced the running time of our benchmarks from 20% to 60%.</p><p>The second compilation strategy is based on function “outlining”, where each bytecode is implemented by a small subroutine. This strategy reduces executable sizes and compilation times, at the cost of not speeding up the running times as much as the first compilation method.</p></div>\",\"PeriodicalId\":48552,\"journal\":{\"name\":\"Journal of Computer Languages\",\"volume\":\"72 \",\"pages\":\"Article 101151\"},\"PeriodicalIF\":1.7000,\"publicationDate\":\"2022-10-01\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"0\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Journal of Computer Languages\",\"FirstCategoryId\":\"94\",\"ListUrlMain\":\"https://www.sciencedirect.com/science/article/pii/S259011842200048X\",\"RegionNum\":3,\"RegionCategory\":\"计算机科学\",\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"Q3\",\"JCRName\":\"COMPUTER SCIENCE, SOFTWARE ENGINEERING\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Journal of Computer Languages","FirstCategoryId":"94","ListUrlMain":"https://www.sciencedirect.com/science/article/pii/S259011842200048X","RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q3","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
A surprisingly simple Lua compiler—Extended version
Dynamically-typed programming languages are often implemented using interpreters, which offer several advantages in terms of portability and flexibility of the implementation. However, as a language matures and its programs get bigger, programmers may seek compilers, to avoid the interpretation overhead.
In this study, we present LuaAOT, a simple ahead-of-time compiler for Lua derived from the reference Lua interpreter. We describe two alternative compilation strategies. The first one exemplifies an old idea of using partial evaluation to produce a compiler based on an existing interpreter. Its contribution is to apply this idea to a well-established programming language. We show that with a quite modest effort it is possible to implement an efficient compiler that covers the entirety of Lua, including coroutines and tail calls. The whole implementation required less than 500 lines of new code. For this effort, we reduced the running time of our benchmarks from 20% to 60%.
The second compilation strategy is based on function “outlining”, where each bytecode is implemented by a small subroutine. This strategy reduces executable sizes and compilation times, at the cost of not speeding up the running times as much as the first compilation method.