xplshn
·
2025-08-13
ref.b
B
1write(ref, val) *ref = val;
2read(ref) return (*ref);
3
4y;
5test1() {
6 extrn printf;
7 auto x;
8
9 write(&x, 69);
10 write(&y, 420);
11
12 // printf("&x: %p\n", &x);
13 // printf("&y: %p\n", &y);
14
15 printf("x: %d %d %d %d %d\n", x, *&x, &*x, &*&*&*x, *&*&*&x);
16 printf("y: %d %d %d %d %d\n", y, *&y, &*y, &*&*&*y, *&*&*&y);
17}
18
19test2() {
20 extrn printf;
21 auto a, b, c, d;
22 a = 1337;
23 b = &a;
24 c = &b;
25 d = &c;
26 printf("a: %d\n", ***d);
27}
28
29test3() {
30 extrn printf, malloc;
31 auto xs;
32
33 xs = malloc(8*2);
34 xs[0*8] = 13;
35 xs[1*8] = 42;
36
37 // "E1[E2] is identical to *(E1+E2)"
38 // "&*x is identically x"
39 // therefore `&E1[E2]` should be identical to `E1+E2`
40 // check generated IR to confirm that
41 printf(
42 "xs: [%d, %d]\n",
43 read(xs + 0*8),
44 read(&xs[1*8])
45 );
46}
47
48main() {
49 test1();
50 test2();
51 test3();
52}