impc:ir:compiler:obj-size   scheme


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

Implementation

;; returns the size of the object (first argument)
;; optional second argument is a dereference object
;; which should be an number starting at 0 (for no dereference) and increasing for each level of dereference...
;; returns the size as an i64
(define impc:ir:compiler:obj-size
  (lambda (ast types)
    (let* ((d (if (null? (cddr ast)) 0 (caddr ast)))
           (t (assoc-strcmp (cadr ast) types)))
       (if (null? t)
            (impc:compiler:print-compiler-error "first argument to obj-size must be a valid variable"))
       (if (not (integer? d))
            (impc:compiler:print-compiler-error "second argument to obj-size must be an integer number of dereferences"))
       (if (= d 0)
           (impc:ir:gname (number->string (impc:ir:get-type-size (cdr t))) "i64")
           (impc:ir:gname (number->string (impc:ir:get-type-size (impc:ir:pointer-- (cdr t) d))) "i64"))
       "")))


Back to Index

Similar Entries