From 9812f88a9a612144bea02c7acf499867eb0cbeb9 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 13 Oct 2025 19:06:52 +0200 Subject: implement most of preprocessor - concatenation (##) - builtin macros (__FILE__ etc) - fails in some edge cases, and code needs cleanup - add embedded system include files (stddef.h, stdarg.h for now) - can handle stdio.h now --- test/hello.c | 2 +- test/pp.c | 14 +++++++++++++- test/pp.h | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/hello.c b/test/hello.c index 9d21323..e27be8d 100644 --- a/test/hello.c +++ b/test/hello.c @@ -1,4 +1,4 @@ -int printf(char *, ...); +#include int main(int argc, char **argv) { printf("hello world\n"); } diff --git a/test/pp.c b/test/pp.c index 1c1549f..0aa5287 100644 --- a/test/pp.c +++ b/test/pp.c @@ -1,12 +1,24 @@ #include "pp.h" #include "pp.h" +#include +#include +// +#define CATl(a) a##bar +#define CATr(a) foo##a +#define CAT(a,b) a##b + int main(void) { + int CATl(foo); + ++foobar; + --CATr(bar); + CAT(foo,bar) += 3; printf("%s %s\n",STR ( ok /1 "\n"n ;.& 05.5), STR(ADD(1,2))); hi(ADD(Foo, SQR(Bar+1))); - printf("%s %s\n", str(Foo), xstr(Foo)); + int foo123 = 77; + printf("%s %s %g\n", str(Foo,5), xstr(Foo), CAT(1.5,e3f) + CAT(7,)-CAT(1,)); } diff --git a/test/pp.h b/test/pp.h index 029c6ee..63de6f5 100644 --- a/test/pp.h +++ b/test/pp.h @@ -17,7 +17,7 @@ void hi(int x) { #define STR(h) #h #define xstr(s1) str(s1) -#define str(s) #s +#define str(...) #__VA_ARGS__ #endif -- cgit v1.2.3