impc:ir:compiler:make-tuple   scheme


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

Implementation

;; makes a tuple 'literal'
(define impc:ir:compiler:make-tuple
  (lambda (ast types hint?)
    ;; (println 'make-tuple-ir hint?)
    (let* ((os (make-string 0)))
      (let* ((elts (map (lambda (x t)
                          (cons (impc:ir:compiler x types t)
                                (impc:ir:gname)))
                        (cdr ast)
                        (if (and (not (null? hint?))
                                 (list? hint?)
                                 (list? (car hint?))
                                 (equal? (caar hint?) 14))
                            (cdr (car hint?))
                            (make-list (length (cdr ast)) #f))))
             (num-elts (length elts))
             (fullt (string-append "{" (caddr (car elts))
                                   (apply string-append (map (lambda (x) (string-append ", " (caddr x))) (cdr elts)))
                                   "}")))
        (emit "; stack alloc tuple literal")
        (emit (caar elts) os)
        (emit (impc:ir:gname "tuplel" fullt) " = insertvalue " fullt " undef, " (cadr (cdar elts)) " " (car (cdar elts)) ", 0\n" os)
        (emit "; set tuple literal elts")
        (for-each (lambda (x idx)
                    (emit (car x) os)
                    (let ((last (impc:ir:gname "tuplel")))
                      (emit (impc:ir:gname "tuplel" fullt)
                            " = insertvalue " fullt " " (car last)
                            ", " (caddr x) " " (cadr x) ", " (number->string idx) "\n" os)))
                  (cdr elts)
                  (range 1 (+ 1 num-elts)))
        (impc:ir:strip-space os)))))


Back to Index

Similar Entries