Compiling 5.2 Work 2 for Small Micros

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Compiling 5.2 Work 2 for Small Micros

Ralph Hempel-2
I was just getting back into working on pbLua (Lua for the
LEGO MINDSTORMS NXT) and noticed that 5.2 Work 2 is available.


OK, it was a couple of months ago, but I've now got some time
to work on it.

Actually, I am having a problem with 5.1.4 and I think it has
to do with slow but steady memory creeps during high volume
coroutine switches. As you can imagine, I'm quite happy to see
the emergency garbage collection feature finally in the flesh!

As a first rough hack, I took the user-configured part of my luaconf.h
from 5.1.4 and pasted it into the same area in the new project.

The first major problem I hit is that the #define for luai_hashnum
requires floating point math, which I have, but may turn off.

Can I ask for (or supply if needed) a patch to make this work on
integer only builds of Lua?

Ralph

PS. I'm glad to be back into this!
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Luiz Henrique de Figueiredo
> The first major problem I hit is that the #define for luai_hashnum
> requires floating point math, which I have, but may turn off.

If lua_Number is int then just use

#define luai_hashnum(i,d) i=d

If lua_Number is long and long is not the same size as int then you'll
probably want to mixed its bytes into something that fits an int.
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Ralph Hempel-2
Luiz Henrique de Figueiredo wrote:
>> The first major problem I hit is that the #define for luai_hashnum
>> requires floating point math, which I have, but may turn off.
>
> If lua_Number is int then just use
>
> #define luai_hashnum(i,d) i=d
>
> If lua_Number is long and long is not the same size as int then you'll
> probably want to mixed its bytes into something that fits an int.

I understand that, what I was getting at was that maybe this is a
an issue that can be fixed (if it's actually a problem) luaconf.h

Can we submit proposed patches here?

Ralph
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Luiz Henrique de Figueiredo
> I understand that, what I was getting at was that maybe this is a
> an issue that can be fixed (if it's actually a problem) luaconf.h

It's not a problem because luaconf.h does not cater automatically for
other lua_Number types: it just has the macros that need to be changed
in case you want to change lua_Number.
 
> Can we submit proposed patches here?

Sure, it'll help others. Thanks.
--lhf
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Ralph Hempel-2
Luiz Henrique de Figueiredo wrote:

>> Can we submit proposed patches here?
>
> Sure, it'll help others. Thanks.
> --lhf

Progress!

Lua 5.2 Work 2 is now compiling clean on bare metal for the LEGO
MINDSTORMS NXT.

I had one user that had an issue with 5.1.4 that thought it would
be a good idea to do something like this:

co = coroutine.create( function( n ) )
        while n>0 do
          n = n-1
          coroutine.yield(true,n)
        end
        return(false,0)
      end )

The main loop basically called the function with some arbitrary
value for n and then control was passed back and forth to the coroutine
until n was 0.

Simplest thing that could possibly work - but it broke. And I ended
up doing a ton of research on setjmp() and friends and finally concluded
that the heap was exhausted and I needed emergency garbage collection.

SO then I jumped ahead and got the Work 2 code, spent a grand total
of about 2 hours getting things plugged into my environment and
fixing compiler/linker errors, and now I have this case working
with no problems at all!!!

Great job, everyone! Especially for the emergency garbage collection.

Code size is a bit bigger than the old Lua, but not too horribly
bloated.

I'll post more notes as I learn more about this build. So far, so good.

Ralph
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Robert G. Jakabosky
On Friday 19, Ralph Hempel wrote:
> Simplest thing that could possibly work - but it broke. And I ended
> up doing a ton of research on setjmp() and friends and finally concluded
> that the heap was exhausted and I needed emergency garbage collection.

There is a Emergency GC patch for Lua 5.1.4:
http://lua-users.org/wiki/EmergencyGarbageCollector

It is even being used by eLua 0.7 release.
http://www.eluaproject.net/

--
Robert G. Jakabosky
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Ralph Hempel-2
Robert G. Jakabosky wrote:

> On Friday 19, Ralph Hempel wrote:
>> Simplest thing that could possibly work - but it broke. And I ended
>> up doing a ton of research on setjmp() and friends and finally concluded
>> that the heap was exhausted and I needed emergency garbage collection.
>
> There is a Emergency GC patch for Lua 5.1.4:
> http://lua-users.org/wiki/EmergencyGarbageCollector
>
> It is even being used by eLua 0.7 release.
> http://www.eluaproject.net/

I'm aware of that project, and the patch for 5.1.4 - I just got so
excited that there was a 5.2 to try with everything built in that
I could not resist.

The Emergency patch has been around for a year or so, right. I really
should have picked it up sooner to try out, but that extra load user
case did not come up until a few weeks ago, so I had no real need
to use it then.

Now that we have 5.2 to try - I say move forward!

Ralph
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Tony Finch
In reply to this post by Robert G. Jakabosky
On Fri, 19 Mar 2010, Robert G. Jakabosky wrote:
>
> There is a Emergency GC patch for Lua 5.1.4:
> http://lua-users.org/wiki/EmergencyGarbageCollector

That's built-in to 5.2.

Tony.
--
f.anthony.n.finch  <[hidden email]>  http://dotat.at/
GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
MODERATE OR GOOD.
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

jbsnyder
Administrator
This is a question I've actually had, that I'm wondering if perhaps
Robert or someone else can comment on, what are the effective
differences between these two EGC implementations?

It looks as if Robert's patch has a few more configurable options (gc
on memory limit vs gc on alloc failure), but I haven't dug into any of
the implementation differences yet.

FWIW, the EGC patch has been working quite well in eLua :-)

-jsnyder

On Sat, Mar 20, 2010 at 4:49 PM, Tony Finch <[hidden email]> wrote:

> On Fri, 19 Mar 2010, Robert G. Jakabosky wrote:
>>
>> There is a Emergency GC patch for Lua 5.1.4:
>> http://lua-users.org/wiki/EmergencyGarbageCollector
>
> That's built-in to 5.2.
>
> Tony.
> --
> f.anthony.n.finch  <[hidden email]>  http://dotat.at/
> GERMAN BIGHT HUMBER: SOUTHWEST 5 TO 7. MODERATE OR ROUGH. SQUALLY SHOWERS.
> MODERATE OR GOOD.
>



--
James Snyder
Biomedical Engineering
Northwestern University
[hidden email]
PGP: http://fanplastic.org/key.txt
Phone: (847) 448-0386
Reply | Threaded
Open this post in threaded view
|

Re: Compiling 5.2 Work 2 for Small Micros

Robert G. Jakabosky
On Saturday 20, James Snyder wrote:
> This is a question I've actually had, that I'm wondering if perhaps
> Robert or someone else can comment on, what are the effective
> differences between these two EGC implementations?

I haven't had time to look into how Lua 5.2 implements it's EGC.  I plan on
taking the time, once the new environment changes settle down.

> It looks as if Robert's patch has a few more configurable options (gc
> on memory limit vs gc on alloc failure), but I haven't dug into any of
> the implementation differences yet.

I think the extra features the patch has, should be possible with a custom
allocator function in Lua 5.2.  If it is not possible to implement those
features with a simple allocator, then I will be creating a patch for Lua 5.2
at some point.

> FWIW, the EGC patch has been working quite well in eLua :-)

Good to hear.  I will continue to maintain the patch for Lua 5.1.x, for anyone
that needs the EGC feature but can't upgrade to Lua 5.2 (which is still in
flux and not an official release yet).

--
Robert G. Jakabosky