lua-users home
lua-l archive

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

Ivan Kolev wrote:
1. Static (compile-time) asserts
2. Functions which need to be evaluated at compile-time
3. Issuing diagnostic messages containing location (file/line number) info
4. Executing different code in different configurations of the code
5. Supporting different compilers
6. Defining constants to be used in Windows resource files (.rc)
7. Rare cases to avoid code duplication
8. Creating new syntax where the language doesn't have the needed facilities

In my previous message I forgot to mention that case 4 will appear in any large-scale production code in any programming language, IMO. For example, I've done very little programming in Java (J2ME games), and even in that small project we found the C preprocessor to be the only solution to add/remove some code in Debug/Release builds. Maybe I haven't done enough production code in Lua yet to encounter the same case (but I know that others have, namely Ivan-Assen Ivanov who has complained here about the lack of Debug-build-only asserts in Lua).

From the above list, it seems that compile-time code preprocessing can fall into 3 major cases:
- support for different code configurations (where runtime distinguishing between them is not appropriate, most likely for performance)
- compile-time optimization (or "reduction")
- compile-time code generation (or "expansion")

I begin to suspect that this list of compile-time (or actually pre-compile time) code transformation needs is valid for any large-scale production code in any programming language. But I don't have that much cross-language experience so I may be wrong.