lua-users home
lua-l archive

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


When I thought once about adding support for cross-compilation in luac,
I intended to do it via a string like this one:
          "I2,S4,NR4,EB"
which means that the target machine has 2-byte integers, 4-byte size_t,
number is 4-byte real, endianness is big-endian. A 32-bit machine with
longs could be
          "I4,S4,NI4,EN"
Endianness here is "native", but any omitted spec means "native".
You get the idea...

This would simplify the interface between luac.c and ldump.c because luac.c could simply hand that string to ldump.c and the DumpTargetInfo would not
have to be exposed. The DumpState would contain all that info.

I don't like this because ldump.c would have to parse the string. What if there were syntax errors in the string? If ldump's parser had good error handling, it would be bulkier than the current system. If it didn't, then compiler users would have to deal with cryptic "bad target machine info" messages. The current system builds a DumpTargetInfo from command-line arguments to luac, which works very well. The option parser is only about twenty lines long and it produces informative error messages. I don't see how it could be done so easily if ldump.c parsed format strings. ldump would have to hand parse error codes back to luac, which would be messy. Furthermore, when the parser is in luac the Lua core doesn't have to carry the extra code.

I don't think it's a bad thing for DumpTargetInfo to be exposed. Like luaU_print, it's only exposed to luac. Perhaps it should be called "lua_DumpTargetInfo"?

Furthermore, we'd be able to collect a list of cross-compilation strings
for common platforms. And the strings are self-documented.

The same works for command-line flags. The default build on Mac OS Intel is "-cci 32 -ccn float 64 -cce little".

Now, do you intend to be able to load cross-compiled chunks in luac as
well, so that luac could output native chunks from those?

That would only be useful if people had compiled binaries but no source code for some reason. I don't think that's a very common use case.

I'd call it luaU_xdump...

Sure.

Old DOS compilers used to have medium and large models, in which
sizeof(int) was different from sizeof(size_t), I guess, because
in large models one would be able to address "far" data.

Are we supporting cross-compilation to old DOS compilers? That's the only case where it would make a difference. If luac itself is running on the old DOS compiler it will produce the correct code. In any case, a "-ccs" flag could be added in about five lines of code.

Tim