一个非常简单的Lua编译器——扩展版

IF 1.7 3区 计算机科学 Q3 COMPUTER SCIENCE, SOFTWARE ENGINEERING
Hugo Musso Gualandi, Roberto Ierusalimschy
{"title":"一个非常简单的Lua编译器——扩展版","authors":"Hugo Musso Gualandi,&nbsp;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,&nbsp;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}
引用次数: 0

摘要

动态类型编程语言通常使用解释器来实现,解释器在实现的可移植性和灵活性方面提供了一些优势。然而,随着一种语言的成熟和程序的庞大,程序员可能会寻求编译器,以避免解释开销。在这项研究中,我们提出了LuaAOT,这是一个简单的Lua提前编译器,源于参考Lua解释器。我们描述了两种可供选择的编译策略。第一个示例了一个旧的想法,即使用部分求值来生成基于现有解释器的编译器。它的贡献是将这一思想应用于一种成熟的编程语言。我们表明,只要付出相当小的努力,就可以实现一个覆盖整个Lua的高效编译器,包括协程和尾部调用。整个实现只需要不到500行的新代码。为此,我们将基准测试的运行时间从20%减少到60%。第二种编译策略基于函数“outlineing”,其中每个字节码都由一个小型子例程实现。这种策略减少了可执行文件的大小和编译时间,代价是没有像第一种编译方法那样加快运行时间。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
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.

求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
Journal of Computer Languages
Journal of Computer Languages Computer Science-Computer Networks and Communications
CiteScore
5.00
自引率
13.60%
发文量
36
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术官方微信