impc:ti:completely-unwrap-named-type   scheme


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

Implementation

;; this takes a type like
;; "%List--PFBhaXI6PGk2NCxpNjQ_KixMaXN0Kj4*"
;; which decodes to: "<Pair:<i64,i64>*,List*>"
;; and unwraps it into (114 (114 2 2) (114 !a List*))
;; it must be recursive because a naive unwrap gives
;; (114 "%Pair--..." "%List--...")
(define impc:ti:completely-unwrap-named-type
  (lambda (x)
    (if (and (string? x)
             (regex:match? x "^%")
             (string-contains? x "_poly_")
             (if (null? (impc:ti:get-named-type x))
                 (impc:compiler:print-missing-identifier-error x 'type)
                 #t))
        (let* ((gpolyname (regex:replace-all x "^%(.*)_poly_.*$" "$1"))
               (ptrdepth (impc:ir:get-ptr-depth x))
               (gpoly (cons (+ *impc:ir:tuple* (* *impc:ir:pointer* ptrdepth))
                            (map (lambda (x)
                                   (string->symbol x))
                                 (impc:ir:get-pretty-tuple-arg-strings
                                  (symbol->string (impc:ti:get-generictype-candidate-types gpolyname)))))))
          (impc:ti:completely-unwrap-named-type
           (replace-all (impc:ir:get-type-from-str (impc:ti:get-named-type x)) (list (cons x gpoly)))))
        (if (list? x)
            (map (lambda (y)
                   (impc:ti:completely-unwrap-named-type y))
                 x)
            x))))


Back to Index