-;;; FIXME: Is it really a win to have this permanently bound?
-;;; Couldn't we just bind it on entry to LOAD-AS-FASL?
-(defvar *free-fop-tables* (list (make-array 1000)))
-
-;;; the current fop table
-(defvar *current-fop-table*)
-(declaim (simple-vector *current-fop-table*))
-
-;;; the length of the current fop table
-(defvar *current-fop-table-size*)
-(declaim (type index *current-fop-table-size*))
-
-;;; the index in the fop-table of the next entry to be used
-(defvar *current-fop-table-index*)
-(declaim (type index *current-fop-table-index*))
-
-(defun grow-fop-table ()
- (let* ((new-size (* *current-fop-table-size* 2))
- (new-table (make-array new-size)))
- (declare (fixnum new-size) (simple-vector new-table))
- (replace new-table (the simple-vector *current-fop-table*))
- (setq *current-fop-table* new-table)
- (setq *current-fop-table-size* new-size)))
-
-(defmacro push-fop-table (thing)
- (let ((n-index (gensym)))
- `(let ((,n-index *current-fop-table-index*))
- (declare (fixnum ,n-index))
- (when (= ,n-index (the fixnum *current-fop-table-size*))
- (grow-fop-table))
- (setq *current-fop-table-index* (1+ ,n-index))
- (setf (svref *current-fop-table* ,n-index) ,thing))))
+;;; FOPs use the table to save stuff, other FOPs refer to the table by
+;;; direct indexes via REF-FOP-TABLE.
+
+(defvar *fop-table*)
+(declaim (simple-vector *fop-table*))
+
+(declaim (inline ref-fop-table))
+(defun ref-fop-table (index)
+ (declare (index index))
+ (svref *fop-table* (the index (+ index 1))))
+
+(defun get-fop-table-index ()
+ (svref *fop-table* 0))
+
+(defun reset-fop-table ()
+ (setf (svref *fop-table* 0) 0))
+
+(defun push-fop-table (thing)
+ (let* ((table *fop-table*)
+ (index (+ (the index (aref table 0)) 1)))
+ (declare (fixnum index)
+ (simple-vector table))
+ (when (eql index (length table))
+ (setf table (grow-fop-vector table index)
+ *fop-table* table))
+ (setf (aref table 0) index
+ (aref table index) thing)))
+
+;;; These three routines are used for both the stack and the table.
+(defun make-fop-vector (size)
+ (declare (index size))
+ (let ((vector (make-array size)))
+ (setf (aref vector 0) 0)
+ vector))
+
+(defun grow-fop-vector (old-vector old-size)
+ (declare (simple-vector old-vector)
+ (index old-size))
+ (let* ((new-size (* old-size 2))
+ (new-vector (make-array new-size)))
+ (declare (fixnum new-size)
+ (simple-vector new-vector old-vector))
+ (replace new-vector old-vector)
+ (nuke-fop-vector old-vector)
+ new-vector))
+
+(defun nuke-fop-vector (vector)
+ (declare (simple-vector vector)
+ (optimize speed))
+ ;; Make sure we don't keep any garbage.
+ #!+gencgc
+ (fill vector 0))
+