nx_concat_probe.nx source
↩ module page · 40 lines · 1336 B
1// nx_concat_probe.nx -- minimal @concat / @stringify repro, isolated from v7's ${$$counter} case.
2//
3// ORDERING IS THE POINT: @concat(prefix, _double_x) must see `prefix` ALREADY replaced by `foo`, or it
4// pastes the PARAMETER NAME and emits `prefix_double_x` -- a function nobody called. The fixed-point
5// loop provides that for free: pass N substitutes, pass N+1 splices.
6// expect_exit: 0 license_tier: ORIGINAL
7
8import "nx_syscalls.nx"
9
10func cp_w(s: *u8) -> i64 {
11 var n: i64 = 0
12 while s[n] != (0 as u8) { n = n + 1 }
13 sys_write(1, s, n)
14 return 0
15}
16
17@macro DEFINE_DOUBLE(prefix) {
18 func @concat(prefix, _double_x)(x: i64) -> i64 { return x * 2 }
19}
20
21DEFINE_DOUBLE(foo)
22DEFINE_DOUBLE(bar)
23
24@macro TRIPLE_NAME(a, b, c) {
25 func @concat(a, b, c)() -> i64 { return 42 }
26}
27
28TRIPLE_NAME(hello, _, world)
29
30func cp_label() -> *u8 { return @stringify(my_symbol) as *u8 }
31
32func main() -> i64 {
33 if foo_double_x(3) != 6 { cp_w("FOO FAIL\n" as *u8); return 1 }
34 if bar_double_x(5) != 10 { cp_w("BAR FAIL\n" as *u8); return 2 }
35 if hello_world() != 42 { cp_w("TRIPLE FAIL\n" as *u8); return 3 }
36 let s: *u8 = cp_label()
37 if s[0] != (109 as u8) { cp_w("STRINGIFY FAIL\n" as *u8); return 4 }
38 cp_w("CONCAT-PROBE OK: foo_double_x, bar_double_x, hello_world, @stringify -> m...\n" as *u8)
39 return 0
40}