;; makes an array 'literal'
(define impc:ir:compiler:make-vector
(lambda (ast types hint?)
;; (println 'make-vector-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?) 16))
(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 vector literal")
(emit (caar elts) os)
(emit (impc:ir:gname "vecl" fullt) " = insertelement " fullt " undef, " (cadr (cdar elts)) " " (car (cdar elts)) ", i32 0\n" os)
(emit "; set array literal elts")
(for-each (lambda (x idx)
(emit (car x) os)
(let ((last (impc:ir:gname "vecl")))
(emit (impc:ir:gname "vecl" fullt)
" = insertelement " fullt " " (car last)
", " (caddr x) " " (cadr x) ", i32 " (number->string idx) "\n" os)))
(cdr elts)
(range 1 (+ 1 num-elts)))
(impc:ir:strip-space os)))))