TITLE ^

Status of Lua on Parrot

Introduction ^

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.

Compiler ^

This compiler is written in Perl5 :

lexer

Implemented with Perl5 regex

languages/lua/Lua/lexer.pm

parser

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

code generation

languages/lua/Lua/build.pm

symbole table

languages/lua/Lua/symbtab.pm

opcode representation

languages/lua/Lua/opcode.pm

opcode emission

languages/lua/Lua/pir.pm

KNOWN PROBLEMS ^

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.

TODO ^

Handle arguments from command line.

Try to use Parse::RecDescent (the original Lua uses a LL parser).

Lua PMC ^

There are eight basic types in Lua, each of them is implemented by a PMC.

nil

languages/lua/pmc/luanil.pmc

boolean

languages/lua/pmc/luaboolean.pmc

number

languages/lua/pmc/luanumber.pmc

string

languages/lua/pmc/luastring.pmc

function

languages/lua/pmc/luafunction.pmc

userdata

languages/lua/pmc/luauserdata.pmc

This type allows OO extension.

Currently, file in I/O library is an userdata.

thread

languages/lua/pmc/luathread.pmc

This type is used to implement coroutines.

table

languages/lua/pmc/luatable.pmc

This type is the data structure of the language.

languages/lua/pmc/luabase.pmc provides an abstract base class for some Lua types (nil, boolean, number, string, table).

languages/lua/pmc/lua.pmc is a singleton PMC what holds some static methods.

BUGS ^

Lua PMC have problems with the Parrot garbage collector : used objects are released by the GC (infant mortality ?).

So, use the option --no-gc.

TODO ^

Arguments passing in invoke method of table. Where are there ?

Weak table, weak reference.

IMPROVEMENT ^

table with a mixed array and hash.

Lua Standard Libraries ^

Lua 5.1 defines the following standard libraries:

basic library

languages/lua/lib/luabasic.pir

coroutine manipulation

languages/lua/lib/luacoroutine.pir

package library

languages/lua/lib/luapackage.pir

string manipulation

languages/lua/lib/luastring.pir

table manipulation

languages/lua/lib/luatable.pir

mathematical functions

languages/lua/lib/luamath.pir

input and output

languages/lua/lib/luaio.pir

operating system facilities

languages/lua/lib/luaos.pir

debug facilities

languages/lua/lib/luadebug.pir

languages/lua/lib/luaaux.pir is the equivalent of Auxiliary Library.

TODO ^

Except math library, all of these libraries are incomplete.

And the coroutine library does not work.

KNOWN PROBLEMS ^

Currently, these libraries are included as PIR file (not loaded as bytecode PBC) because HLL support for Sub/Closure is incomplete with PBC.

Next Milestones ^

Understand how work PGE & TGE and write an interpreter in PIR.

Related Projects ^

Klaas-Jan Stol works on 2 projects :

Monkey, an implementation of Lua on Parrot

A Lua to PIR compiler implemented in C

lua2pir

A Lua bytecode to PIR compiler

See http://members.home.nl/joeijoei/.

AUTHOR ^

Francois Perrad.


parrot