impc:ti:specialize-generictype   scheme


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

Implementation

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; specialize generic type!
;;
(define impc:ti:specialize-generictype
  (lambda (sym . types)
    ;; (println 'impc:ti:specialize-generictype 'sym: sym types)
    (if (not (impc:ti:get-generictype-candidate-types (string->symbol sym)))
        (impc:compiler:print-missing-generic-type-error sym)
        (let ((printspec *impc:ti:print-code-specialization-compiles*))
          (set! *impc:ti:print-code-specialization-compiles* #t)
          (for-each
           (lambda (t)
             (if (regex:match? t ":")
                 (set! t (cadr (regex:type-split t ":"))))
             (let ((newname (string-append sym "_poly_" (cname-encode t))))
               (if (llvm:compile-ir (string-append "%" newname " = type " (impc:ir:get-type-str (impc:ir:get-type-from-pretty-str t))))
                   (impc:ti:compile-type-dataconstructors (string->symbol newname) t #f #t #t #t)
                   (impc:compiler:print-compiler-error "failed to compile IR in impc:ti:specialize-generictype" sym))))
           types)
          (set! *impc:ti:print-code-specialization-compiles* printspec)
          #t))))


Back to Index

Similar Entries