07-rescan.M1pp (694B)
1 # Rescan / nesting parity: 2 # - macro body contains a macro call (rescanned via stream push) 3 # - macro arg contains a macro call (parse_args walks tokens raw, 4 # expansion happens after substitution + rescan on the new stream) 5 # - macro-in-expression: builtin arg invokes a macro that produces 6 # an integer expression atom 7 8 %macro ID(x) 9 x 10 %endm 11 12 %macro WRAP(x) 13 [ %ID(x) ] 14 %endm 15 16 %macro ADD2(a, b) 17 (+ a b) 18 %endm 19 20 %macro SHL(x, n) 21 (<< x n) 22 %endm 23 24 # expansion that resolves through ID then back to top 25 %WRAP(payload) 26 27 # macro arg holding another call 28 %WRAP(%ID(inner)) 29 30 # macro-in-expression composition: %SHL evaluates to an atom inside $() 31 $(%SHL(1, 8)) 32 $((+ %SHL(1, 4) %ADD2(2, 3))) 33 END