   VmInst
   (-step [this vm-state]
     (assoc vm-state :stack
-           (make-fn :code (assemble '((args 1)
-                                      (lvar 1 0 stack)
-                                      (set-cc)
-                                      (lvar 0 0 fun)
-                                      (return)))
+           (make-fn :code (assemble '((ARGS 1)
+                                      (LVAR 1 0 stack)
+                                      (SET-CC)
+                                      (LVAR 0 0 fun)
+                                      (RETURN)))
                     :env (->Env [(:stack vm-state)])
                     :name '%cc
                     :args '[fun])))

;;; The Global Environment
;;; ======================

(defn make-global-env []
  "Create a hash table that serves as the global environment."
  {})

;;; The VM State
;;; ============

(defn make-return-address [{:keys [function pc env]}]
  {:type :return-address
   :function function
   :pc pc
   :env env})

(defn make-fn [{:keys [code env name args]}]
  {:type :bytecode-function
   :code code
   :env env
   :name name
   :args args})

(defn initial-state [f]
  "Create a new state for a VM, initially executing function `f`"
  {:type :vm-state
   :function f
   :code (:code f)

(defmethod print-method Env [env writer]
  (.write writer (str "#" (print-str (class env)) "{:frames " (frames env) "}")))

(defn env-value
  "Return the value at position `[frame slot]` in `vm-state`'s
  environment.  This is similar to `(get-in env [frame slot])` but
  throws if the index is out of bounds (which can only result from a
  compiler error)."
  [vm-state {:keys [frame slot]}]
  (let [env (:env vm-state)
        frame-vector (nth env frame)]
    (nth frame-vector slot)))

(defn set-local-var-from-stack
  "Set the value at position `[frame slot]` in `vm-state`'s
  environment to `new-value`."
  [{:keys [env stack] :as vm-state} {:keys [frame slot]}]
  (assoc vm-state
    :env (assoc-in (:env vm-state) [frame slot] (peek stack))
    :stack (pop (:stack vm-state))))
