     (`jmp (let* ((lap-op (ir--info-data op-info))
                  (tag (ir--tag-ref tags arg)))
             (cons lap-op tag)))
-    (`comb2 (if (= arg 1)
-                (car (ir--info-data op-info))
-                (cons (cdr (ir--info-data op-info)) arg)))
+    (`stack-ref (if (= arg 0)
+                    (ir--info-data op-info)
+                  (cons 'byte-stack-ref arg)))
+    (`discard (if (= arg 1)
+                  (ir--info-data op-info)
+                (cons 'byte-discardN arg)))
     (`comb5 (if (<= arg 4)
                 (aref (ir--info-data op-info) arg)
               (cons (aref (ir--info-data op-info) 5) arg)))


;; ir -- Go.el intermediate format that is converted to Emacs lapcode.

;; { IR package }
;; Output of Go.el compiler.

(defsubst ir--pkg-name (pkg) (aref pkg 0))
(defsubst ir--pkg-vars (pkg) (aref pkg 1))
(defsubst ir--pkg-funcs (pkg) (aref pkg 2))

;; Output compiled package to temp buffer.
;; Caller can decide to inspect/eval/save generated contents.
(defun ir--pkg-compile (pkg)
  (with-output-to-temp-buffer "*IR compile*"
    ;; Header.
    (princ ";;; -*- lexical-binding: t -*-\n")
    (princ ";; THIS CODE IS GENERATED, AVOID MANUAL EDITING!\n")
    (princ (format ";; Go package %s:\n" (ir--pkg-name pkg)))
    ;; Functions.
    (dolist (f (ir--pkg-funcs pkg))
      (let* ((name (pop f))
             (bytecode (apply #'ir--make-bytecode f)))
        (prin1 `(defalias ',name ,bytecode))
        (terpri)))
    ;; TODO: global variables.
    (dolist (v (ir--pkg-vars pkg))
      (ignore v))))

;; { Bytecode generation }

;; Like `make-byte-code', but CODE argument is IR encoded instruction list.
(defun ir--make-bytecode (signature cvec stack-cap doc-string code)
  (make-byte-code signature
                  (byte-compile-lapcode
                   (byte-optimize-lapcode
                    (ir--to-lapcode code)))
                  cvec
                  stack-cap
                  doc-string))

(defsubst ir--make-info (kind data) (cons kind data))
(defsubst ir--info-kind (info) (car info))

        (puthash instr (ir--make-info kind data) table)))
    table))

(defun ir--to-lapcode (pkg)
  (let ((tags (make-hash-table :test #'eq))
        op
        op-info
        arg
        output)
    (while (not-eq 'end (setq op (pop! pkg)))
      (setq op-info (gethash op ir--table)
            arg (if (eq 'op0 (ir--info-kind op-info))
                    nil
                  (pop! pkg)))
      (push (ir--lap-instr tags op-info op arg) output))
    (nreverse output)))

