boot2

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

16-enum.M1pp (783B)


      1 # %enum directive:
      2 #  - %enum NAME { l1 l2 ... } synthesizes N+1 zero-parameter macros:
      3 #      NAME.label_k -> k
      4 #      NAME.COUNT   -> N
      5 #  - same directive-handler as %struct, just stride=1 and totalizer=COUNT
      6 #  - compile-time COUNT check with %(=) proves the totalizer ties to the
      7 #    label count
      8 
      9 %enum tag { fixnum pair vector string symbol proc singleton }
     10 
     11 # Paren-less access to each label.
     12 %tag.fixnum
     13 %tag.pair
     14 %tag.vector
     15 %tag.string
     16 %tag.symbol
     17 %tag.proc
     18 %tag.singleton
     19 
     20 # Totalizer.
     21 %tag.COUNT
     22 
     23 # Compile-time sanity: COUNT must equal 7.
     24 %((= %tag.COUNT 7))
     25 
     26 # An enum value as an LI-immediate slot via the 4-byte emitter.
     27 %((+ %tag.pair 0))
     28 
     29 # Second enum, proves independent naming.
     30 %enum prim_id { add sub mul div mod }
     31 %prim_id.add
     32 %prim_id.mul
     33 %prim_id.COUNT
     34 END