 (defmethod emit-seq 'lambda
   [env context ^GeneratorAdapter gen [_ params & body :as lambda]]
   (when-not (= context :context/statement)
-    (let [[dotname bytecode closed-overs] (binding [*top-level* false]
+    (let [[dotname bytecode closed-overs] (binding [*top-level* nil]
                                             (compile lambda))]
       (. *class-loader* defineClass dotname bytecode lambda)
       (let [slashname (.replace dotname "." "/")]

      (. gen returnValue)
      (. gen endMethod))))

(defn validate-params!
  [params]
  (when (and (some #{rest-token} params)
             (not= (count (drop-while (complement #{rest-token}) params)) 2))
    (throw (IllegalArgumentException. "#!rest may only be followed by one symbol!"))))

(def ^:dynamic *compiled-lambdas*)

(defmulti compile

      (swap! *compiled-lambdas* conj lambda)
      [dotname (.toByteArray cw) fv])))

(defmethod compile 'case-lambda
  [[_ & methods :as case-lambda]]
  (debug "Compiling:" case-lambda)
  (let [fv (vec (free-vars case-lambda))
        cw (ClassWriter. ClassWriter/COMPUTE_FRAMES)
        lname (str (dotmunge (str (or *lambda-name* 'lambda))) "_" (next-id))
        fqname (str "wombat/" lname)
        dotname (.replace fqname "/" ".")
        ifaces (into-array String ["wombat/ILambda"])]))

(defn emit
  [env context gen form]
  (cond
