boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

11-local-labels.M1pp (731B)


      1 # Local labels: `:@name` / `&@name` inside macro bodies rewrite to
      2 # `:name__NN` / `&name__NN` where NN is a fresh monotonic id per expansion.
      3 # Scoping: body-native only; param-substituted tokens pass through untouched.
      4 #
      5 # Covers:
      6 #   1) a single macro using `:@end` called twice -> end__1, end__2 distinct
      7 #   2) nested macros each using `:@done` -> outer/inner get separate ids
      8 #   3) `&@label` address form rewrites the same way
      9 #   4) a `:@name` literal passed as an argument is NOT rewritten
     10 
     11 %macro ONCE()
     12     jne &@end
     13     :@end
     14 %endm
     15 
     16 %macro OUTER()
     17     :@done
     18     %INNER()
     19     jmp &@done
     20 %endm
     21 
     22 %macro INNER()
     23     :@done
     24     body
     25 %endm
     26 
     27 %macro ARGPASS(lbl)
     28     lbl
     29 %endm
     30 
     31 %ONCE()
     32 %ONCE()
     33 
     34 %OUTER()
     35 
     36 %ARGPASS(:@kept)
     37 END