Yueliang


Introduction

The goal of Yueliang is to implement Lua 5 in Lua 5. Such a codebase, if well documented, can be a useful prototyping and educational tool. Initially, the focus is on the front end of Lua, i.e. the lexical analyzer, the parser and the code generator, in order to generate binary chunks. A port of the back end (the VM) is being considered. Yueliang is moon in Mandarin.

The codebase is currently a no-brainer port of the Lua 5.0.3 front end and the Lua 5.1.3 front end. C source code was ported to Lua code in a brain dead manner, and the C heritage is retained as much as possible to allow for easy comparison. Due to certain implementation methods, processing might be slow (especially if the source file causes a lot of string processing.) The initial version is not meant to be fast. Even unused arguments are retained. Asserts are currently enabled. While the Lua code itself is portable, portions of the code is hard-coded to generate output for an x86-type platform (32-bit ints, doubles, little-endian.)

There is an automatic tester script to exercise the front end. Both the lexer and the parser have test suites, for both front end versions. There isn't any test suite for a back end yet because the back end is currently being ported, but much of Lua's test suite can be utilized for that. Yueliang currently produces the exact binary chunk as the original Lua 5 itself for hundreds of KB of various Lua scripts that I have on my machine. Performance (not currently a consideration) is 28 seconds on an Athlon 2500+, or about 29.5KB/sec, for Yueliang 0.1.0. (Native C is virtually instantaneous, so a comparison is pointless, really.)


Features

Yueliang includes the following:


Users of Yueliang

A practical use of Yueliang's native 5.1.x parser skeleton is in LuaSrcDiet version 0.11.0, for the powerful local variable renaming feature. The native parser skeleton is used to provide a table of local and global variable "liveness", or in detail, when they are declared, activated, accessed or removed. The parser behaves in exactly the same way as a normal Lua front end. This allows LuaSrcDiet to reassign local variable names in a general way, including dealing with upvalue accesses and renaming function parameters. Furthermore, by avoiding name collisions, short names can be reused more often, possibly further reducing code size for large scripts.

Portions of Yueliang is also used in Metalua.


Download

Project Links on LuaForge: Yueliang project page | File releases

Latest version: yueliang-0.4.1 (170KB tar.gz)

What's new?

Current work being done:


Acknowledgements

Thanks to the LuaForge team for hosting this material. This page was written on SeaMonkey. Yueliang was developed using the SciTE editor on Cygwin, and managed using SVN. Much of Yueliang is based on the Lua sources.


This page Copyright © 2006-2008 KHMan. Last Revised: 2008-05-31.
Canonical URL: http://yueliang.luaforge.net/