;; adds make-closure and make-env tags
(define impc:ti:closure:convert
(lambda (ast esyms)
(cond ((pair? ast)
(if (member (car ast) *impc:lambdaslist*)
(let (;(env (impc:ti:block:check-for-free-syms ast esyms))
(allocate-mem-for-vars? (impc:ti:allocate-var? (cdr ast))))
(list (cond ((eq? (car ast) 'lambdah) '__make-closure-h)
((eq? (car ast) 'lambdas) '__make-closure-s)
(else '__make-closure-z))
allocate-mem-for-vars?
;; name of compiled function is always last
;; so we can remove it by dropping it off the end
(cdr (reverse (cl:remove-duplicates esyms))) ;env
(cadr ast)
(impc:ti:closure:convert (caddr ast) (append (cadr ast) esyms))))
(if (member (car ast) *impc:letslist*)
(let* ((allocate-mem-for-vars? (impc:ti:allocate-var? ast))
(bindings (map (lambda (binding)
(car binding))
(cadr ast))))
;(free-syms (impc:ti:block:check-for-free-syms (cddr ast) (append bindings esyms))))
(cons '__make-env
(cons allocate-mem-for-vars?
(list (impc:ti:closure:convert (cadr ast) (append bindings esyms))
(impc:ti:closure:convert (caddr ast) (append bindings esyms))))))
(cons (impc:ti:closure:convert (car ast) esyms)
(impc:ti:closure:convert (cdr ast) esyms)))))
((atom? ast) ast))))