   [fns vars name]
   {:post [(vector? %)
           (not (some vector? %))]}
-  (if-let [load-stmt (or (load-var vars name) (load-fn name))]
+  (if-let [load-stmt (or (load-local name) (load-var vars name) (load-fn name))]
     load-stmt
     (throw (IllegalArgumentException. (format "Could not find symbol %s" name)))))
 

  (let [labeled (conj stmt (format "; #%s" label))]
    (vec (concat [labeled] stmts))))

(defn load-var
  [vars name]
  (let [index (.indexOf vars name)]
    (if-not (neg? index)
      [:ld 0 index (format "; load var %s" name)])))

(defn load-fn
  ([name]
   (load-fn 1 name))
  ([frame name]
   [:ld frame (format "^%s" name) (format "; load fn %s" name)]))


  {:pre [(list? code)]
   :post [(vector? (:code %))
          (every? vector? (:code %))]}
  (binding [locals (atom [])]
    (let [localname (format "%s_body" name)
          code (->> body
                    (mapcat #(compile-form args fns %))
                    (tag-with localname))
          code (concat code [[:rtn]])
          num-locals (count @locals)
          local-scope (concat [[:dum num-locals]]
                       (vec (repeatedly num-locals #(identity [:ldc 0])))
                       [[:ldf (format "@%s" localname)]
                        [:trap num-locals]])
          local-scope (tag-with name local-scope)
          code (concat local-scope code)]
      {:name name
       :code (vec code)
       :length (count code)})))

(defn compile-ai
  [file]
