anchor.diff:                          last-slot-aligned-offset
                           last-slot-machine-size
                           type)))
  +
  +(defun calc-layout (name
  +                    parent-type-base-offset
  +                    parent-type-aligned-offset
  +                    last-slot-base-offset
  +                    last-slot-aligned-offset
  +                    last-slot-machine-size
  +                    type)
  +  (cond
  +    ((scalar-type-p type)
  +     (calc-scalar-layout name
  +                         parent-type-aligned-offset
  +                         last-slot-base-offset
  +                         last-slot-aligned-offset
  +                         last-slot-machine-size
  +                         type))
  +    ((v-typep type 'v-vector)
  +     (calc-vector-layout name
  +                         parent-type-aligned-offset
  +                         last-slot-base-offset
  +                         last-slot-aligned-offset
  +                         last-slot-machine-size
  +                         type))
  +    ((v-typep type 'v-matrix)
  +     (calc-col-mat-layout name
  +                          parent-type-base-offset
  +                          parent-type-aligned-offset
  +                          last-slot-base-offset
  +                          last-slot-aligned-offset
  +                          last-slot-machine-size
  +                          type))
  +    ((v-typep type 'v-struct)
  +     (calc-struct-layout name
  +                         parent-type-aligned-offset
  +                         last-slot-base-offset
  +                         last-slot-aligned-offset
  +                         last-slot-machine-size
  +                         type))
  +    ((and (v-typep type 'v-array)
  +          (v-typep (v-element-type type) 'v-matrix))
  +     (calc-array-of-col-mat-layout name
  +                                   parent-type-base-offset
  +                                   parent-type-aligned-offset
  +                                   last-slot-base-offset
  +                                   last-slot-aligned-offset
  +                                   last-slot-machine-size
  +                                   type))
  +    ((and (v-typep type 'v-array)
  +          (v-typep (v-element-type type) 'v-struct))
  +     (calc-array-of-structs-layout name
  +                                   parent-type-base-offset
  +                                   parent-type-aligned-offset
  +                                   last-slot-base-offset
  +                                   last-slot-aligned-offset
  +                                   last-slot-machine-size
  +                                   type))
  +
  +    ((v-typep type 'v-array)
  +     (calc-array-of-scalar-or-vectors-layout name
  +                                             parent-type-base-offset
  +                                             parent-type-aligned-offset
  +                                             last-slot-base-offset
  +                                             last-slot-aligned-offset
  +                                             last-slot-machine-size
  +                                             type))
  +    ;;
  +    (t (error "shiit"))))
  +
  +(defun calc-scalar-layout (name
  +                           parent-type-aligned-offset
  +                           last-slot-base-offset
  +                           last-slot-aligned-offset
  +                           last-slot-machine-size
  +                           type)
  +  ;; 1. If the member is a scalar consuming N basic machine units, the
  +  ;;    base alignment is N.
  +  (let ((n (machine-unit-size type))
  +        (base-offset (calc-base-offset parent-type-aligned-offset
  +                                       last-slot-base-offset
  +                                       last-slot-aligned-offset
  +                                       last-slot-machine-size)))
  +    (make-instance
  +     'std-140
  +     :name name
  +     :type type
  +     :base-offset base-offset
  +     :aligned-offset (calc-aligned-offset base-offset n)
  +     :base-alignment n
  +     :machine-unit-size n)))
   
   (defun calc-struct-layout (name
                              parent-type-aligned-offset
  
positive.code:      :machine-unit-size size
       :members members)))
  
  (defun calc-base-offset (parent-type-aligned-offset
                           last-slot-base-offset
                           last-slot-aligned-offset
                           last-slot-machine-size)
    (if (not last-slot-base-offset)
        ;; The base offset of the first member of a structure is taken from the
        ;; aligned offset of the structure itself
        parent-type-aligned-offset
      ;; The base offset of all other structure members is derived by taking
      ;; the offset of the last basic machine unit consumed by the previous
      ;; member and adding one
      ;;
      ;; {TODO} see rule 4 second paragraph, sounds relevent
      ;; {TODO} see rule 9 second paragraph, sounds relevent
      (+ last-slot-aligned-offset ;; which offset?
         last-slot-machine-size
         1)))
  
  (defun calc-scalar-layout (name
                             parent-type-aligned-offset
                             last-slot-base-offset
                             last-slot-aligned-offset
                             last-slot-machine-size
                             type)
    ;; 1. If the member is a scalar consuming N basic machine units, the
    ;;    base alignment is N.
    (let ((n (machine-unit-size type))
          (base-offset (calc-base-offset parent-type-aligned-offset
                                         last-slot-base-offset
                                         last-slot-aligned-offset
                                         last-slot-machine-size)))
      (make-instance
       'std-140
       :name name
       :type type
       :base-offset base-offset
       :aligned-offset (calc-aligned-offset base-offset n)
       :base-alignment n
       :machine-unit-size n)))
  
  (defun calc-vector-base-alignment (type)
    ;; 2. If the member is a two or four-component vector with components
    ;;    consuming N basic machine units, the base alignment is 2N or 4N,
    ;;    respectively.
    ;; 3. If the member is a three-component vector with components
    ;;    consuming N basic machine units, the base alignment is 4N.
    (let ((elem-type (v-element-type type)))
      (ecase= (first (v-dimensions type))
        (2 (* 2 (machine-unit-size elem-type)))
        (3 (* 4 (machine-unit-size elem-type))) ;; ← (* 4 …) is not a typo
        (4 (* 4 (machine-unit-size elem-type))))))
  
  (defun calc-vector-layout (name
                             parent-type-aligned-offset
                             last-slot-base-offset
  
negative.code:   (or (v-typep type 'v-number)
        (v-typep type 'v-bool)))
  
  (defun calc-aligned-offset (base-offset base-alignment)
    ;; A structure and each structure member have a base offset and a base
    ;; alignment, from which an aligned offset is computed by rounding the
    ;; base offset up to a multiple of the base alignment
    (round-to-next-multiple base-offset base-alignment))
  
  (defun calc-base-offset (parent-type-aligned-offset
                           last-slot-base-offset
                           last-slot-aligned-offset
                           last-slot-machine-size)
    (if (not last-slot-base-offset)
        ;; The base offset of the first member of a structure is taken from the
        ;; aligned offset of the structure itself
        parent-type-aligned-offset
      ;; The base offset of all other structure members is derived by taking
      ;; the offset of the last basic machine unit consumed by the previous
      ;; member and adding one
      ;;
      ;; {TODO} see rule 4 second paragraph, sounds relevent
      ;; {TODO} see rule 9 second paragraph, sounds relevent
      (+ last-slot-aligned-offset ;; which offset?
         last-slot-machine-size
         1)))
  
  (defun calc-vector-base-alignment (type)
    ;; 2. If the member is a two or four-component vector with components
    ;;    consuming N basic machine units, the base alignment is 2N or 4N,
    ;;    respectively.
    ;; 3. If the member is a three-component vector with components
    ;;    consuming N basic machine units, the base alignment is 4N.
    (let ((elem-type (v-element-type type)))
      (ecase= (first (v-dimensions type))
        (2 (* 2 (machine-unit-size elem-type)))
        (3 (* 4 (machine-unit-size elem-type))) ;; ← (* 4 …) is not a typo
        (4 (* 4 (machine-unit-size elem-type))))))
  
  ;;----------------------------------------------------------------------
  