do
(do exprs*)
Source docstring:
Evaluates the expressions in order and returns the value of
the last. If no expressions are supplied, returns nil.
(defmethod parse 'do
[op env [_ & exprs :as form] _ _]
(let [statements (analyze-do-statements env exprs)]
(if (<= (count exprs) 1)
(let [ret (analyze env (first exprs))
children [:statements :ret]]
{:op :do
:env env
:form form
:statements statements :ret ret
:children children})
(let [ret-env (if (= :statement (:context env))
(assoc env :context :statement)
(assoc env :context :return))
ret (analyze ret-env (last exprs))
children [:statements :ret]]
{:op :do
:env env
:form form
:statements statements
:ret ret
:children children}))))
(defmethod emit* :do
[{:keys [statements ret env]}]
(let [context (:context env)]
(when (and (seq statements) (= :expr context)) (emitln "(function (){"))
(doseq [s statements] (emitln s))
(emit ret)
(when (and (seq statements) (= :expr context)) (emitln "})()"))))