lua-users home
lua-l archive

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

David Given wrote:
> For reference: my 'application' is a shell script that compiles an
> embedded Lua interpreter and runs a Lua program with it. Works very
> nicely. I'm currently crunching the C side of things with cobfusc, and
> LuaSrcDiet crunches the Lua side of things as well as is effective
> (there's no point trying to get that any smaller since the C side is so
> large; I'm now looking for a better C cruncher).

I just thought you'd be interested to know that having now *written* a
better C cruncher, I've managed to squash the entire interpreter source
code into a single 154kB source file, which is 40% of the original 389kB

Admittedly, it's 154kB of this gibberish:


Yes, that is actually *valid* C source.

I've done this by renaming all the non-C-specific symbols in the source.
(Did you know that there's over 6.5kB of 'lua_State' strings *alone*?) I
think I might be able to get it a bit smaller by also renaming C
keywords and Posix reserved symbols, but doing that would involve having
to #define them back to their real values so that the compiler can
understand them, and that may not be worth it.

I partially avoided the how-do-I-generate-unused-short-symbol-names
problem by making symbols using the [letter][number][letter or number]
template, as you can see above; there are very few symbols that clash
with those (the only ones I've found are the Bessel functions in the GNU
libm). However, I'm still not entirely sure that the resulting source is
truly portable and need to do some tests. It does at least pass my unit
tests on Linux.

The crunching process involves a manual stage where I have to go through
a big list of all the tokens used by the program and remove all the ones
that the cruncher's not allowed to touch (like 'break' or 'stat'), and
it's currently a rather messy collection of small tools in Lua, but if
anyone wants something like this, look at the 'build' script here:

I can now fit the entire Prime Mover executable, which is 5000 lines of
Lua, a patched Lua interpreter source and lposix, into under 64kB of
bzipped data. That's not bad...

┌─── ───── ─────
│ "Wizards get cranky, / Dark days dawn, / Riders smell manky, / The
│ road goes on. / Omens are lowering, / Elves go West; / The Shire needs
│ scouring, / You may as well quest." - John M. Ford

Attachment: signature.asc
Description: OpenPGP digital signature