+ (flet ((load-stream (stream)
+ (let* (;; Bindings required by ANSI.
+ (*readtable* *readtable*)
+ (*package* (sane-package))
+ ;; FIXME: we should probably document the circumstances
+ ;; where *LOAD-PATHNAME* and *LOAD-TRUENAME* aren't
+ ;; pathnames during LOAD. ANSI makes no exceptions here.
+ (*load-pathname* (handler-case (pathname stream)
+ ;; FIXME: it should probably be a type
+ ;; error to try to get a pathname for a
+ ;; stream that doesn't have one, but I
+ ;; don't know if we guarantee that.
+ (error () nil)))
+ (*load-truename* (when *load-pathname*
+ (handler-case (truename stream)
+ (file-error () nil))))
+ ;; Bindings used internally.
+ (*load-depth* (1+ *load-depth*))
+ ;; KLUDGE: I can't find in the ANSI spec where it says
+ ;; that DECLAIM/PROCLAIM of optimization policy should
+ ;; have file scope. CMU CL did this, and it seems
+ ;; reasonable, but it might not be right; after all,
+ ;; things like (PROCLAIM '(TYPE ..)) don't have file
+ ;; scope, and I can't find anything under PROCLAIM or
+ ;; COMPILE-FILE or LOAD or OPTIMIZE which justifies this
+ ;; behavior. Hmm. -- WHN 2001-04-06
+ (sb!c::*policy* sb!c::*policy*))
+ (return-from load
+ (if (equal (stream-element-type stream) '(unsigned-byte 8))
+ (load-as-fasl stream verbose print)
+ (load-as-source stream verbose print))))))
+ (when (streamp pathspec)
+ (return-from load (load-stream pathspec)))
+ (let ((pathname (pathname pathspec)))
+ (with-open-stream
+ (stream (or (open pathspec :element-type '(unsigned-byte 8)
+ :if-does-not-exist nil)
+ (when (null (pathname-type pathspec))
+ (let ((defaulted-pathname
+ (probe-load-defaults pathspec)))
+ (if defaulted-pathname
+ (progn (setq pathname defaulted-pathname)
+ (open pathname
+ :if-does-not-exist
+ (if if-does-not-exist :error nil)
+ :element-type '(unsigned-byte 8))))))
+ (if if-does-not-exist
+ (error 'simple-file-error
+ :pathname pathspec
+ :format-control
+ "~@<Couldn't load ~S: file does not exist.~@:>"
+ :format-arguments (list pathspec)))))
+ (unless stream
+ (return-from load nil))
+
+ (let* ((header-line (make-array
+ (length *fasl-header-string-start-string*)
+ :element-type '(unsigned-byte 8))))
+ (read-sequence header-line stream)
+ (if (mismatch header-line *fasl-header-string-start-string*
+ :test #'(lambda (code char) (= code (char-code char))))
+ (let ((truename (probe-file stream)))
+ (when (and truename
+ (string= (pathname-type truename) *fasl-file-type*))
+ (error 'fasl-header-missing
+ :stream (namestring truename)
+ :fhsss header-line
+ :expected *fasl-header-string-start-string*)))
+ (progn
+ (file-position stream :start)
+ (return-from load
+ (load-stream stream))))))
+ (with-open-file (stream pathname :external-format external-format)
+ (load-stream stream)))))