impc:ir:compiler:pointer-ref-ptr   scheme


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

Implementation

(define impc:ir:compiler:pointer-ref-ptr
  (lambda (ast types)
    (let* ((os (make-string 0))
           (index-str (impc:ir:compiler (caddr ast) types))
           (idx (impc:ir:gname))
           (var-str (impc:ir:compiler (cadr ast) types))
           (var (impc:ir:gname))
           (ttype (impc:ir:get-type-from-str (cadr var))))
      ;; type tests
      (if (not (impc:ir:pointer? ttype))
          (impc:compiler:print-bad-type-error-with-ast ttype "must be a pointer" ast))
      (if (and (= 1 (impc:ir:get-ptr-depth ttype))
               (or (impc:ir:closure? ttype)))
          (impc:compiler:print-bad-type-error-with-ast ttype "must be a pointer" ast))
      (if (not (impc:ir:fixed-point? (impc:ir:get-type-from-str (cadr idx))))
          (impc:compiler:print-bad-type-error-with-ast (cadr idx) "index must be an integer" ast))
      (emit index-str os)
      (emit var-str os)
      (emit "; pointer ref\n" os)
      (emit (string-append (impc:ir:gname "val" (cadr var)) " = getelementptr "
                           (impc:ir:pointer-- (cadr var))
                           ", " (cadr var) " " (car var) ", "
                           (cadr idx) " " (car idx) "\n") os)
      (impc:ir:strip-space os))))


Back to Index

Similar Entries