lua-users home
lua-l archive

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


Hi John,


On Tue, Dec 10, 2013 at 12:48 PM, John Hind <john.hind@zen.co.uk> wrote:
This is interesting:

http://micropython.org/

I saw that, it is a really awesome project.
 


If only it was Lua! I know there has been some work on this sort of thing (i.e. http://www.eluaproject.net/) but nothing as elegant as this hardware implementation of Python. Just plug it into any USB host computer and edit the scripts as if on a flash drive, whilst a virtual com port gives you a console channel over the same USB.

The main issue for these single chip systems is RAM - typically at the highest end you are working with 100-200KiB of RAM and 1-2MiB of Flash. This is plenty for a basic "bare metal" Lua implementation running a test script, but not enough RAM to do really serious work. Problem is there is a huge complexity step between the top end of on-chip RAM and boards with separate RAM chips such as the Raspberry Pi and Beaglebone Black - the RAM interface requires a lot of chip pins reducing the IO availability, and much more complex PCB routing. In practice a large RAM approach only becomes cost effective with very big production runs.

I have been wondering how difficult it would be to modify the Lua memory allocator so it could split the Lua State between Flash and RAM. This way, most of the less volatile memory such as strings, function bytecodes and library tables could be located in more plentiful flash memory reserving RAM for what really needs it. Damian George (of MicroPython) has a very clear view of the priorities:

"When design decisions were made, the first priority was to minimise RAM usage, then minimise code size, and, finally, to execute quickly."

I realise that Lua was not designed with precisely these priorities, but neither was Python. I'm interested in views of the feasibility of adapting Lua in the same direction that Damian has adapted Python.

I've actually been working quite a bit on this myself. A few examples:

https://github.com/elua/elua/commit/f729155fcefe15d5c424d323a36183ec0a37e7a1
https://github.com/elua/elua/commit/d54659b5723bcd2b1e3900362398c72c18a9aa0b

These patches allow for read-only tables and partial (for now) strings in ROM (full strings in ROM should also be posible). As you can see, it is much more than just modifying the allocator, you also have to change the language implementation quite a bit. And eLua does have the same goals as Damian's, although they are not explicitly stated: RAM is always at a prime. I'll keep on looking for other ways to make Lua more RAM-friendly, although there's only so much I can do while keeping compatibility with the core language.

Best,
Bogdan
 

- John Hind.


---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com