- no longer generate CONSTANT lines for #defined constants
- "#define FOO 1" turns "return FOO;" into "return 1;"
- Macros expanding into a macro is not supported:
#define FOO 1
#define BAR FOO
will expand BAR to FOO, not to 1
- Expansion inside #if conditions is not supported.
- Function-like macros are not supported.
- // and # lines always appear in the result of read_all_tokens
- in bootstrap mode, // tokens (but not the subsequent lines) and #
lines are stripped. no preprocessing happens.
- in non-bootstrap mode, // lines are stripped and # lines stay for the
preprocessing phase
- updates tests to pass --bootstrap-mode when necessary
- support for #if, #elif, #else, #endif, but no macro expansion just
yet. Any macro is treated as undefined and expands to 0.
for example:
./bin/M2-Planet -E test.c
#if 1 == FOO
foo
#else
bar
#endif
results in
bar
- change the lexer to not remove preprocessor directives
- preprocess() removes any lines starting with a macro directive that it
doesn't understand (which is currently all of them)
- needed to determine start and end of macro directives
- the main parser doesn't need them, so strip out the newline tokens
before parsing to avoid changing it
Note that this is a backwards incompatible change: Unlike POSIX, exit()
will not flush all open streams, so you are responsible for flushing or
closing all your streams before successful exit.
Also, file.c will now also require calloc.c (and malloc.c).
Updated the test cases accordingly.
Only implemented and tested for x86.
Paraphrasing OriansJ's IRC message while working on kaem:
GCC needs fflush(stdout) to get matching behavior, as M2-Planet doesn't
buffer. I guess we will need to make a fflush function (it'll do nothing
but return 0).