boot2

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

15-struct.M1pp (1072B)


      1 # %struct directive:
      2 #  - %struct NAME { f1 f2 ... } synthesizes N+1 zero-parameter macros:
      3 #      NAME.field_k -> k*8 (decimal word)
      4 #      NAME.SIZE    -> N*8
      5 #  - paren-less access is the natural read form: %closure.body
      6 #  - composes via a plain wrapper macro using %frame_hdr.SIZE for stack-
      7 #    frame layouts
      8 
      9 %struct closure { hdr params body env }
     10 
     11 # Paren-less access to each field and to SIZE.
     12 %closure.hdr
     13 %closure.params
     14 %closure.body
     15 %closure.env
     16 %closure.SIZE
     17 
     18 # With parens still works.
     19 %closure.body()
     20 
     21 # Inside an expression atom: loads 16+100 = 116 -> 0x74.
     22 %((+ %closure.body 100))
     23 
     24 # Compose-and-add path: %frame adds a 16-byte header prefix to every
     25 # %frame_apply.* offset. Exercises the paren-less atom inside %(...).
     26 %struct frame_hdr { retaddr caller_sp }
     27 
     28 %macro frame(field)
     29 %((+ field %frame_hdr.SIZE))
     30 %endm
     31 
     32 %struct frame_apply { callee args body env }
     33 %frame(%frame_apply.callee)
     34 %frame(%frame_apply.args)
     35 %frame(%frame_apply.body)
     36 %frame(%frame_apply.env)
     37 
     38 # Total frame size for an enter/leave pair.
     39 %frame_apply.SIZE
     40 %frame_hdr.SIZE
     41 END