0.pre7.33:
[sbcl.git] / src / code / byte-interp.lisp
index cda6006..5cad9c5 100644 (file)
@@ -1,5 +1,6 @@
 ;;;; the byte code interpreter
 
+;;; FIXME: should really be in SB!BYTECODE
 (in-package "SB!C")
 
 ;;;; This software is part of the SBCL system. See the README file for
          ((nil)))
        `(function ,(res) *))))))
 \f
-;;;; the evaluation stack
+;;;; the 'evaluation stack'
+;;;;
+;;;; (The name dates back to CMU CL, when it was used for the IR1
+;;;; interpreted implementation of EVAL. In SBCL >=0.7.0, it's just
+;;;; the byte interpreter stack.)
 
-;;; the interpreter's evaluation stack
 (defvar *eval-stack* (make-array 100)) ; will grow as needed
-;;; FIXME: This seems to be used by the ordinary (non-byte) interpreter
-;;; too, judging from a crash I had when I removed byte-interp.lisp from
-;;; the cold build sequence. It would probably be clearer to pull the
-;;; shared interpreter machinery out of the byte interpreter and ordinary
-;;; interpreter files and put them into their own file shared-interp.lisp
-;;; or something.
 
 ;;; the index of the next free element of the interpreter's evaluation stack
 (defvar *eval-stack-top* 0)
 #!-sb-fluid (declaim (inline eval-stack-ref))
 (defun eval-stack-ref (offset)
   (declare (type stack-pointer offset))
-  (svref sb!eval::*eval-stack* offset))
+  (svref sb!bytecode::*eval-stack* offset))
 
 #!-sb-fluid (declaim (inline (setf eval-stack-ref)))
 (defun (setf eval-stack-ref) (new-value offset)
   (declare (type stack-pointer offset))
-  (setf (svref sb!eval::*eval-stack* offset) new-value))
+  (setf (svref sb!bytecode::*eval-stack* offset) new-value))
 
 (defun push-eval-stack (value)
-  (let ((len (length (the simple-vector sb!eval::*eval-stack*)))
+  (let ((len (length (the simple-vector sb!bytecode::*eval-stack*)))
        (sp *eval-stack-top*))
     (when (= len sp)
       (let ((new-stack (make-array (ash len 1))))
-       (replace new-stack sb!eval::*eval-stack* :end1 len :end2 len)
-       (setf sb!eval::*eval-stack* new-stack)))
+       (replace new-stack sb!bytecode::*eval-stack* :end1 len :end2 len)
+       (setf sb!bytecode::*eval-stack* new-stack)))
     (setf *eval-stack-top* (1+ sp))
     (setf (eval-stack-ref sp) value)))
 
 (defun allocate-eval-stack (amount)
-  (let* ((len (length (the simple-vector sb!eval::*eval-stack*)))
+  (let* ((len (length (the simple-vector sb!bytecode::*eval-stack*)))
         (sp *eval-stack-top*)
         (new-sp (+ sp amount)))
     (declare (type index sp new-sp))
     (when (>= new-sp len)
       (let ((new-stack (make-array (ash new-sp 1))))
-       (replace new-stack sb!eval::*eval-stack* :end1 len :end2 len)
-       (setf sb!eval::*eval-stack* new-stack)))
+       (replace new-stack sb!bytecode::*eval-stack* :end1 len :end2 len)
+       (setf sb!bytecode::*eval-stack* new-stack)))
     (setf *eval-stack-top* new-sp)
-    (let ((stack sb!eval::*eval-stack*))
-      (do ((i sp (1+ i))) ; FIXME: DOTIMES? or just :INITIAL-ELEMENT in MAKE-ARRAY?
+    (let ((stack sb!bytecode::*eval-stack*))
+      (do ((i sp (1+ i))) ; FIXME: Use CL:FILL.
          ((= i new-sp))
-       (setf (svref stack i) '#:uninitialized))))
+       (setf (svref stack i) '#:uninitialized-eval-stack-element))))
   (values))
 
 (defun pop-eval-stack ()
        (new-sp-var (gensym "NEW-SP-"))
        (decls nil))
     (loop
-      (unless (and (consp body) (consp (car body)) (eq (caar body) 'declare))
+      (unless (and (consp body)
+                  (consp (car body))
+                  (eq (caar body) 'declare))
        (return))
       (push (pop body) decls))
     `(let ((,new-sp-var (- *eval-stack-top* ,num-vars)))
 \f
 ;;;; miscellaneous primitive stubs
 
-(macrolet ((frob (name &optional (args '(x)))
+(macrolet ((def-frob (name &optional (args '(x)))
             `(defun ,name ,args (,name ,@args))))
-  (frob %CODE-CODE-SIZE)
-  (frob %CODE-DEBUG-INFO)
-  (frob %CODE-ENTRY-POINTS)
-  (frob %FUNCALLABLE-INSTANCE-FUNCTION)
-  (frob %FUNCALLABLE-INSTANCE-LAYOUT)
-  (frob %FUNCALLABLE-INSTANCE-LEXENV)
-  (frob %FUNCTION-NEXT)
-  (frob %FUNCTION-SELF)
-  (frob %SET-FUNCALLABLE-INSTANCE-FUNCTION (fin new-val)))
+  (def-frob %code-code-size)
+  (def-frob %code-debug-info)
+  (def-frob %code-entry-points)
+  (def-frob %funcallable-instance-function)
+  (def-frob %funcallable-instance-layout)
+  (def-frob %funcallable-instance-lexenv)
+  (def-frob %function-next)
+  (def-frob %function-self)
+  (def-frob %set-funcallable-instance-function (fin new-val)))
 \f
 ;;;; funny functions
 
           (type pc pc))
   pc)
 
-;;; This is exactly like THROW, except that the tag is the last thing on
-;;; the stack instead of the first. This is used for RETURN-FROM (hence the
-;;; name).
+;;; This is exactly like THROW, except that the tag is the last thing
+;;; on the stack instead of the first. This is used for RETURN-FROM
+;;; (hence the name).
 (define-xop return-from (component old-pc pc fp)
   (declare (type code-component component)
           (type pc old-pc)
        (format *trace-output*
                "pc=~D, fp=~D, sp=~D, byte=#b~,'0X, frame:~%    ~S~%"
                pc fp *eval-stack-top* byte
-               (subseq sb!eval::*eval-stack* fp *eval-stack-top*)))))
+               (subseq sb!bytecode::*eval-stack* fp *eval-stack-top*)))))
   (if (zerop (logand byte #x80))
       ;; Some stack operation. No matter what, we need the operand,
       ;; so compute it.
                      (funcall function ,@(args))))))
       (frob))))
 
+;;; Note: negative RET-PC is a convention for "we need multiple return
+;;; values".
 (defun do-call (old-component call-pc ret-pc old-fp num-args named)
   (declare (type code-component old-component)
           (type pc call-pc)