xplshn
·
2025-08-13
stack_alloc.b
B
1// TODO(2025-06-05 17:45:36): Ken Thompson, Users' Reference to B, 9.3
2// printf implementation implies that the autovars are layed out in the memory from left to right,
3// but our IR assumes right to left, due to how the stack works on the majority of modern platforms
4// Consider making this more historically accurate.
5
6variadic(a, b, c) {
7 auto args, i;
8 args = &c;
9 extrn printf;
10 i = 3; while (i > 0) printf("%d\n", args[--i]);
11}
12
13structure(args) {
14 args[0] = 1;
15 args[1] = 2;
16 args[2] = 3;
17}
18
19main() {
20 auto c, b, a;
21 structure(&a);
22 extrn printf;
23 printf("a = %d\n", a);
24 printf("b = %d\n", b);
25 printf("c = %d\n", c);
26 variadic(69, 420, 1337);
27}