   {:pre [(list? code)]
    :post [(vector? (:code %))
           (every? vector? (:code %))]}
-  (let [fns (conj fns {:name name})
-        code (->> body
-                  (mapcat #(compile-form args fns %))
-                  (tag-with name))
-        code (concat code [[:rtn]])]
-    {:name name
-     :code (vec code)
-     :length (count 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]

      (= (first form) 'quote)
      (concat (mapcat #(compile-form vars fns %) (second form))
              (repeat (dec (count form)) [:cons]))

      ;; function call
      :else

  [fns vars name]
  {:post [(vector? %)
          (not (some vector? %))]}
  (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)))))

