mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-22 18:40:29 +00:00
Add chibicc
This program popped up on Hacker News recently. It's the only modern compiler I've ever seen that doesn't have dependencies and is easily modified. So I added all of the missing GNU extensions I like to use which means it might be possible soon to build on non-Linux and have third party not vendor gcc binaries.
This commit is contained in:
parent
e44a0cf6f8
commit
8da931a7f6
298 changed files with 19493 additions and 11950 deletions
52
third_party/chibicc/test/varargs_test.c
vendored
Normal file
52
third_party/chibicc/test/varargs_test.c
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int sum1(int x, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, x);
|
||||
|
||||
for (;;) {
|
||||
int y = va_arg(ap, int);
|
||||
if (y == 0) return x;
|
||||
x += y;
|
||||
}
|
||||
}
|
||||
|
||||
int sum2(int x, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, x);
|
||||
|
||||
for (;;) {
|
||||
double y = va_arg(ap, double);
|
||||
x += y;
|
||||
|
||||
int z = va_arg(ap, int);
|
||||
if (z == 0) return x;
|
||||
x += z;
|
||||
}
|
||||
}
|
||||
|
||||
void fmt(char *buf, char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
va_list ap2;
|
||||
va_copy(ap2, ap);
|
||||
vsprintf(buf, fmt, ap2);
|
||||
va_end(buf);
|
||||
}
|
||||
|
||||
int main() {
|
||||
ASSERT(6, sum1(1, 2, 3, 0));
|
||||
ASSERT(55, sum1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0));
|
||||
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
||||
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
||||
ASSERT(210, sum2(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, 12.0, 13, 14.0,
|
||||
15, 16.0, 17, 18.0, 19, 20.0, 0));
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
fmt(buf, "%d %d", 2, 3);
|
||||
strcmp(buf, "2 3");
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue