impc:ir:compiler:make-array   scheme


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

Implementation

;; makes an array 'literal'
(define impc:ir:compiler:make-array
  (lambda (ast types hint?)
    ;; (println 'make-array-literal: hint?)
    (let* ((os (make-string 0))
           (tt #f))
      (let* ((elts (map (lambda (x t)
                          (let ((res (cons (impc:ir:compiler x types (if tt tt t))
                                           (impc:ir:gname))))
                            (if (and (not tt) (not t))
                                (set! tt (impc:ir:get-type-from-str (cadr (impc:ir:gname)))))
                            res))
                        (cdr ast)
                        (if (and (not (null? hint?))
                                 (list? hint?)
                                 (list? (car hint?))
                                 (equal? (caar hint?) 15))
                            (make-list (length (cdr ast)) (caddr (car hint?)))
                            (make-list (length (cdr ast)) #f))))
             (num-elts (length elts))
             (fullt (string-append "[" (number->string num-elts) " x " (cadr (cdar elts)) "]")))
        (emit "; stack alloc array literal")
        (emit (caar elts) os)
        (emit (impc:ir:gname "arrayl" fullt) " = insertvalue " fullt " undef, " (cadr (cdar elts)) " " (car (cdar elts)) ", 0\n" os)
        (emit "; set array literal elts")
        (for-each (lambda (x idx)
                    (emit (car x) os)
                    (let ((last (impc:ir:gname "arrayl")))
                      (emit (impc:ir:gname "arrayl" 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