lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I haven't done too much with the lua VM, so don't assume these answers
to be correct.

1) Each function/prototype defines the number of registers that it
requires, which can be anything from 2 up to 255. The function, when
executed, will then expect and utilise exactly that many registers.
However, when you start doing things with variable number of
arguments, then each argument requires a register, and this limit can
be exceeded.

2) If the function to call is in r6 (and thus the arguments in r7
through rN), then everything below r6 is preserved across the call.
The return values of the function are stored in r6, r7 ... rN, with rN
being set as the new stack/register top. Hence function calls are
usually done at the top of the registers, as to preserve things.

3) not sure

4) lvm.c is the implementation of the VM. I would also read
http://luaforge.net/docman/index.php?group_id=83&selected_doc_group_id=102&language_id=1
, as it is a very good introduction to the VM instructions and their
behaviour.

Peter

On 19/12/2007, gtkelly@dialectronics.com <gtkelly@dialectronics.com> wrote:
> Luiz and Taj have posted two great links.  This is really great stuff.  I've been looking for BSD-licensed RISC-centric solutions to compiling and JIT, and have had to face writing the stuff myself.  I have some questions about the register-based VM in Lua.
>
> 1) Do you use an infinite number of virtual registers?
>
> 2) Are there volatile and non-volatile registers (across function calls)?
>
> 3) Can the VM layer be completely replaced with RISC object code?
>
> 4) Where would I look in the source code to start poking around?
>
>
> I wrote a Lua-based PowerPC disassembler some months back, but got hung up trying to accomodate too many different file formats (MachO and PEF use containers within containers, XCOFF and ELF do not) so while the core is written I haven't released it.  To some extent, I think Lua would make a good interpreting layer for a compiler, and if Lua itself is register-based, it might be an excellent basis for a RISC-centric programming language (I particularly like the ability to return multiple values from a function call, line'em up r3-r9).
>
> thanks,
> tim
>
> --
>
> "Anything war can do, peace can do better."  --  Desmond Tutu
>
>