10.1145/1363686.1363743acmconferencesArticle/Chapter ViewAbstractPublication PagessacConference Proceedingsconference-collections
research-article

Efficient compilation of Lua for the CLR

Published:16 March 2008Publication History

ABSTRACT

Microsoft's Common Language Runtime offers a target environment for compiler writers that provides a managed execution environment and type system, garbage collection, access to OS services, multithreading, and a Just-In-Time compiler. But the CLR uses a statically typed intermediate language, which is a problem for efficient compilation of dynamically typed languages in general, and the Lua language in particular.

This paper presents a way to implement a Lua compiler for the CLR that generates efficient code. The code this compiler generates outperforms the same code executed by the Lua interpreter and similar code generated by Microsoft's IronPython compiler. It approaches the performance of Lua code compiled to native code by LuaJIT.

References

  1. A. L. de Moura, N. Rodriguez, and R. Ierusalimschy. Coroutines in lua. Journal of Universal Computer Science, 10(7):910--925, 2004.Google ScholarGoogle Scholar
  2. M. Hammond. Python for .NET: Lessons Learned, 2000. Technical report by ActiveState, not available online at the time of this paper's writing.Google ScholarGoogle Scholar
  3. U. Hölzle and D. Ungar. Optimizing dynamically-dispatched calls with run-time type feedback. In PLDI '94: Proceedings of the ACM SIGPLAN 1994 conference on Programming language design and implementation, pages 326--336, New York, NY, USA, 1994. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. J. Hugunin. Ironpython: A fast python implementation for .net and mono. In Proceedings of PyCon DC 2004, 2004. Available at http://www.python.org/pycon/dc2004/papers/9.Google ScholarGoogle Scholar
  5. J. Hugunin. A Dynamic Language Runtime (DLR), 2007. Available at http://blogs.msdn.com/hugunin/archive/2007/04/30/a-dynamic-language-runtime-dlr.aspx.Google ScholarGoogle Scholar
  6. R. Ierusalimschy, L. H. de Figueiredo, and W. Celes. The evolution of lua. In HOPL III: Proceedings of the third ACM SIGPLAN conference on History of programming languages, pages 2-1--2-26, New York, NY, USA, 2007. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. R. Ierusalimschy, L. H. Figueiredo, and W. Celes. Lua 5.1 Reference Manual. Technical Report 14/03, PUC-Rio, 2006. Available at http://www.lua.org/manual/5.1.Google ScholarGoogle Scholar
  8. F. Mascarenhas and R. Ierusalimschy. Luainterface: Scripting the .net clr with lua. Journal of Universal Computer Science, 10(7):892--909, 2004.Google ScholarGoogle Scholar
  9. F. Mascarenhas and R. Ierusalimschy. Running lua scripts on the clr through bytecode translation. Journal of Universal Computer Science, 11(7):1275--1290, 2005.Google ScholarGoogle Scholar
  10. Microsoft. ECMA C# and Common Language Infrastructure Standards, 2005. Available at http://msdn.microsoft.com/net/ecma/.Google ScholarGoogle Scholar
  11. M. Pall. The LuaJIT project, 2007. Available at http://luajit.org/.Google ScholarGoogle Scholar
  12. G. Pettyjohn, J. Clements, J. Marshall, S. Krishnamurthi, and M. Felleisen. Continuations from generalized stack inspection. In ICFP '05: Proceedings of the tenth ACM SIGPLAN international conference on Functional programming, pages 216--227, New York, NY, USA, 2005. ACM Press. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Efficient compilation of Lua for the CLR

    Reviews

    Arthur Gittleman

    Lua is a simple, small, dynamically typed language used in industrial applications and game development. Since 1993, Ierusalimschy has been a principal developer of Lua. This paper presents a way to implement a compiler for Microsoft's common language runtime (CLR) virtual-machine (VM) component that generates efficient code. The introduction notes that despite Lua's simplicity, it has a number of advanced features, including extensible semantics, anonymous functions with full lexical scoping, tail-call optimization, and full asymmetric coroutines. Mascarenhas and Ierusalimschy's previous compiler performs similarly to the Lua interpreter. Section 2 describes the basic compiler and the issues it addresses in relation to the CLR. Mascarenhas and Ierusalimschy use three microbenchmarks: a straightforward recursive implementation that stresses function calls and returns, a memoized implementation that stresses array access and closures, and an iterative implementation that stresses loops and simple arithmetic. The simple compiler performance is worse than the Lua interpreter, but Section 3 describes compiler optimizations, the third set of which produces a compiler that runs significantly better than the Lua interpreter, and approaches performance of code compiled directly to native code by the just-in-time compiler for Lua (LuaJIT). The fourth section discusses related work. The dynamic language runtime (DLR) extends the CLR. Mascarenhas and Ierusalimschy note that Lua, unlike Python, is not suited to the DLR. On their benchmarks, Lua code performs better than similar Python code compiled using the DLR. In conclusion, this paper presents some very interesting problems arising in the compilation of dynamic languages for the CLR and Lua. Online Computing Reviews Service

    Access critical reviews of Computing literature here

    Become a reviewer for Computing Reviews.

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!