lua 5.0的实现(翻译)8

综述

 

    在这篇论文中,我们论述了Lua5.0实现中各个最具创意部分:他的基于寄存器的虚拟机,使用优化后的表作为数组的新算法,和闭包的实现。

     据我们所知,Lua是头一个广泛采用基于寄存器虚拟机的语言。对表的优化,允许一个表在他被当作数组使用时,能够做为数组被分块实现(就是说,当他在1...n范围内有足够的关键字)。他对闭包的实现也是独一无二的,结合使用了一个基于数组的栈,这个栈带有一个以函数为第一顺序的词典,不需要复杂的控制流分析。

    图10中的表展示了新旧版本之间性能的简单比较。这些测试在Intel 奔腾4 、512M内存、Linux2.6系统下运行,Lua使用gcc3.3编译。Lua4.0既没有使用基于寄存器的虚拟机(他的虚拟机是基于栈的),也没有使用表格数组优化。Lua5'是Lua5.0没有使用表格优化,尾调用,和动态栈(和协程相关)的版本;Lua5.0'除了新的基于寄存器的虚拟机外,和Lua4.0是相似的。

    我们测试“The Great Computer Language Shootout”上所有的例子,除了第一个(sum)外,他只是简单将1到n的整数加起来。第一个测试花费几乎所有的时间在虚拟机中;他表明新的虚拟机比旧虚拟机快2倍左右。其他测试花费更多的时间在其他任务中(函数调用,表格/数组访问等等),所以,虚拟机在总时间上有微小的提升。在这几个使用数组(sieve/heapsort/matrix)测试中,新虚拟机和新的数组优化混合使用,能够缩短执行时间近40%。

     Lua5.0的完整代码在Lua的网站: http://www.lua.org/source/5.0 上可以得到。

 

 

program Lua 4.0 Lua 5' Lua 5.0
sum (2e7) 1.23 0.54 (44%) 0.54 (44%)
bo (30) 0.95 0.68 (72%) 0.69 (73%)
ack (8) 1.00 0.86 (86%) 0.88 (88%)
random (1e6) 1.04 0.96 (92%) 0.96 (92%)
sieve (100) 0.93 0.82 (88%) 0.57 (61%)
heapsort (5e4) 1.08 1.05 (97%) 0.70 (65%)
matrix (50) 0.84 0.82 (98%) 0.59 (70%)


Figure 10: Benchmarks (times in seconds; percentages are relative to Lua 4.0)

 

 

感谢!

 

    Edgar Toernig 为闭包的实现中,提供了关键性见解。Thatcher Ulrich在Lua4.0中完成协程上一个版本的实现,作为我们在Lua5.0实现的理论基础。通过CNPq的授权,这些作者为我们提供部分支持(grants 302608/2002-8, 300392/2003-6,
and 401109/2003-8), FINEP (CT-INFO 01/2003), and Microsoft Research (2nd
Rotor RFP)。

 

引用!

 

References
1. A. W. Appel. Empirical and analytic study of stack versus heap cost for languages
with closures. Journal of Functional Programming, 6(1):47{74, 1996.
2. D. Bagley. The great computer language shootout.
http://www.bagley.org/~doug/shootout/.
3. R. P. Brent. Reducing the retrieval time of scatter storage techniques. Communi-
cations of the ACM, 16(2):105{109, 1973.
4. A. Calpini. The great Win32 computer language shootout.
http://dada.perl.it/shootout/.
5. L. Cardelli. Compiling a functional language. In LISP and Functional Program-
ming, pages 208{217, 1984.
6. B. Davis, A. Beatty, K. Casey, D. Gregg, and J. Waldron. The case for virtual
register machines. In Proceedings of the 2003 Workshop on Interpreters, Virtual
Machines and Emulators, pages 41{49. ACM Press, 2003.
7. A. de Moura, N. Rodriguez, and R. Ierusalimschy. Coroutines in Lua. Journal of
Universal Computer Science, 10(7):910{925, July 2004.
8. M. A. Ertl and D. Gregg. The structure and performance of ecient interpreters.
Journal of Instruction-Level Parallelism, 5:1{25, Nov. 2003.
9. A. Goldberg and D. Robson. Smalltalk-80: the language and its implementation.
Addison-Wesley, 1983.
10. R. E. Griswold and M. T. Griswold. The Implementation of the Icon Programming
Language. Princeton University Press, 1986.
11. R. E. Griswold, J. F. Poage, and I. P. Polonsky. The SNOBOL 4 Programming
Language. Prentice-Hall, 1971.
12. R. Ierusalimschy, L. H. de Figueiredo, and W. Celes. The evolution of an extension
language: A history of Lua. In Proceedings of V Brazilian Symposium on
Programming Languages, pages B{14{B{28, 2001.
13. S. C. Johnson. YACC: Yet another compiler compiler. CS TR 32, Bell Labs, July
1975.
14. K.-H. Man. A no-frills introduction to Lua 5 VM instructions.
http://luaforge.net/docman/?group_id=83.

15. S. Pemberton and M. Daniels. Pascal Implementation: The P4 Compiler and In-
terpreter. Ellis Horwood, 1982.
16. I. Piumarta and F. Riccardi. Optimizing direct threaded code by selective inlining.
In ACM SIGPLAN Conference on Programming Language Design and Implemen-
tation (PLDI), pages 291{300, Montreal, Canada, June 1998.
17. A. Randal, D. Sugalski, and L. Toetsch. Perl 6 and Parrot Essentials. O'Reilly,
second edition, 2004.
18. M. L. Scott. Programming Language Pragmatics. Morgan Kaufmann, 2000.
19. M. Serrano. Control
ow analysis: a functional language compilation paradigm.
In 10th ACM Symposium on Applied Computing, pages 118{122, Nashville, TN,
Feb. 1995.

20. M. Serrano and P. Weis. Bigloo: A portable and optimizing compiler for strict
functional languages. In 2nd Static Analysis Symposium, pages 366{381, Glasgow,
Scotland, Sept. 1995. LNCS 983.
21. Z. Shao and A. W. Appel. Space-ecient closure representations. In ACM Con-
ference on Lisp and Functional Programming, pages 150{161, June 1994.
22. Z. A. Shaw. The Lua virtual machine.
http://www.zedshaw.com/writings/luas-lvm-instructions/luas_lvm_
instructions/luas_lvm_instructions.html.
23. C. Tismer. Continuations and stackless Python. In Proceedings of the 8th Inter-
national Python Conference, Arlington, VA, 2000.
24. P. Winterbottom and R. Pike. The design of the Inferno virtual machine.
http://www.herpolhode.com/rob/hotchips.html.

你可能感兴趣的:(虚拟机,Microsoft,lua,lisp,compiler,compilation)