 ;;; VM Instructions
 ;;; ===============
 
-(defn make-prim [symbol n-args opcode always? side-effect?]
+(defn make-prim
   "Create a new primitive instruction."
+  [symbol n-args opcode always? side-effect?]
   {:type :primitive-instruction
    :symbol symbol
    :n-args n-args

  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)))
                    :env (->Env [(:stack vm-state)])
                    :name '%cc
                    :args '[fun])))

    'OP))


(defn step
  "Run a single step of the VM starting in `vm-state`.  If the VM is
  stopped, i.e., `(:stopped? vm-state)` is true, then return the state
  unchanged."
  [vm-state]
  (if (:stopped? vm-state)
    vm-state
    (let [instr (nth (:code vm-state) (:pc vm-state))]
      (-step instr (assoc vm-state
                     :pc (inc (:pc vm-state))
                     :instr instr)))))


;;; The Assembler
;;; =============

(defn assemble [])

;;; The VM Proper
;;; =============
