impc:ir:get-tuple-type-size   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/llvmir.xtm

Implementation

(define impc:ir:get-tuple-type-size
  (lambda (type)
    (let ((t (cons *impc:ir:tuple* (impc:ir:get-tuple-type-from-str (impc:ir:get-type-str type)))))
      ;; if tuple is pointer return pointer-size
      (if (> (car t) *impc:ir:pointer*) (/ (sys:pointer-size) 8)
          ;; otherwise
          (let ((et '()) ;; element type
                (size 0)
                (largest 0)
                (align 0)
                (offset 0)
                (this_size 0)
                (elmts (- (length t) 1)))
            (dotimes (i elmts)
              (set! et (list-ref t (+ i 1)))
              (set! this_size (impc:ir:get-type-size et))
              (set! align (impc:ir:get-alignment et))
              (if (> align largest) (set! largest align))
              (set! offset (modulo size align))
              (if (> offset 0) (set! offset (- align offset)))
              (set! size (+ size this_size offset)))
            ;; finally the whole struct should be aligned
            ;; to the largest internal aligment
            (if (> (modulo size largest) 0)
                (set! size (+ size (- largest (modulo size largest)))))
            size)))))


Back to Index