parrotcode: Status of Lua on Parrot | |
Contents | Language Implementations | Lua |
Status of Lua on Parrot
Lua is an extension programming language designed to support general procedural programming with data description facilities. It also offers good support for object-oriented programming, functional programming, and data-driven programming. Lua is intended to be used as a powerful, light-weight scripting language for any program that needs one.
The homepage is http://www.lua.org/.
The reference manual is available on http://www.lua.org/manual/.
This implementation is aligned with Lua 5.1 specifications.
lua.pbc
is the interpreter/compiler,
see languages/lua/src/lua51.pir & languages/lua/lua.pir.
lua.pbc
is written in PIR and generates PIR from Lua sources.
lua.pbc
uses the following Parrot compiler toolchain components :
CodeString
.PGE
is also used by the Lua pattern compiler in languages/lua/lib/luaregex.pir.The lexicography part could be checked with languages/lua/test_lex.pir.
The code generation could be examined with languages/lua/luap.pir.
in languages/lua/t/closure.t :
a = {}
local x = 20
for i=1,10 do
local y = 0
a[i] = function () y=y+1; return x+y end
end
print(a[1]())
print(a[1]())
print(a[2]())
--[[
The loop creates ten closures (that is, ten instances of the anonymous
function). Each of these closures uses a different y variable, while all
of them share the same x.
]]
y
variable is not different.
This compiler is written in Perl5 :
Implemented with Perl5 regex
languages/lua/Lua/lexer.pm
Implemented with Parse::Yapp.
It supports the full grammar described in languages/lua/doc/lua51.bnf.
Only one error
rule, so the syntax error diagnostic is minimalist.
languages/lua/Lua/lua51.yp
languages/lua/Lua/build.pm
languages/lua/Lua/symbtab.pm
languages/lua/Lua/opcode.pm
languages/lua/Lua/pir.pm
There are eight basic types in Lua, each of them is implemented by a PMC.
This type allows OO extension.
Currently, file
in I/O library is an userdata
.
This type is used to implement coroutines. The current implementation use the library runtime/parrot/library/Parrot/Coroutine.pir.
This type is the data structure of the language.
languages/lua/pmc/luaany.pmc provides an abstract base class for all Lua types.
languages/lua/pmc/lua.pmc is a singleton PMC what holds some static methods.
Lua PMC have problems with the Parrot garbage collector : used objects are released by the GC (infant mortality ?).
So, use the option --no-gc
.
Arguments passing in invoke
method of table
. Where are there ?
table
with a mixed array and hash (like Lua 5).
Lua 5.1 defines the following standard libraries:
languages/lua/lib/luaaux.pir is the equivalent of Auxiliary Library.
languages/lua/lib/luaregex.pir implements a regex compiler using PGE.
Complete some of these libraries.
As compiled regex are not stored in Lua variable, the Regex compiler needs a Memoization mecanism (well-known optimization).
These libraries are loaded dynamically with the Lua function require
.
Debugging & stabilisation.
Add a Lua bytecode translator as a package loader.
Klaas-Jan Stol works on 2 projects :
A Lua to PIR compiler implemented in C
A Lua bytecode to PIR compiler
Francois Perrad.
|