X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fcode%2Ftarget-load.lisp;h=55a585d7b3f6017a9e43d3e8f032c7ccede85a3e;hb=0223f43d5f199914ebceff12b6f4c60448369edd;hp=b20c4e40335a963313691235fad4ef6b6dcdcc7f;hpb=00ca0f6bd2e4e4e4c6214466c83b2f5e7c063c65;p=sbcl.git diff --git a/src/code/target-load.lisp b/src/code/target-load.lisp index b20c4e4..55a585d 100644 --- a/src/code/target-load.lisp +++ b/src/code/target-load.lisp @@ -27,18 +27,32 @@ ;;;; LOAD-AS-SOURCE -;;; Load a text file. (Note that load-as-fasl is in another file.) +;;; Load a text stream. (Note that load-as-fasl is in another file.) (defun load-as-source (stream verbose print) (maybe-announce-load stream verbose) - (do ((sexpr (read stream nil *eof-object*) - (read stream nil *eof-object*))) - ((eq sexpr *eof-object*) - t) - (if print - (let ((results (multiple-value-list (eval sexpr)))) - (load-fresh-line) - (format t "~{~S~^, ~}~%" results)) - (eval sexpr)))) + (macrolet ((do-sexprs ((sexpr stream) &body body) + (aver (symbolp sexpr)) + (with-unique-names (source-info) + (once-only ((stream stream)) + `(if (handler-case (pathname stream) + (error () nil)) + (let ((,source-info (sb!c::make-file-source-info + (pathname ,stream) + (stream-external-format ,stream)))) + (setf (sb!c::source-info-stream ,source-info) ,stream) + (sb!c::do-forms-from-info ((,sexpr) ,source-info) + ,@body)) + (do ((,sexpr (read ,stream nil *eof-object*) + (read ,stream nil *eof-object*))) + ((eq ,sexpr *eof-object*)) + ,@body)))))) + (do-sexprs (sexpr stream) + (if print + (let ((results (multiple-value-list (eval sexpr)))) + (load-fresh-line) + (format t "~{~S~^, ~}~%" results)) + (eval sexpr))) + t)) ;;;; LOAD itself @@ -67,7 +81,7 @@ #!+sb-doc "Load the file given by FILESPEC into the Lisp environment, returning T on success." - (flet ((load-stream (stream) + (flet ((load-stream (stream faslp) (let* (;; Bindings required by ANSI. (*readtable* *readtable*) (*package* (sane-package)) @@ -95,12 +109,14 @@ ;; behavior. Hmm. -- WHN 2001-04-06 (sb!c::*policy* sb!c::*policy*)) (return-from load - (if (equal (stream-element-type stream) '(unsigned-byte 8)) + (if faslp (load-as-fasl stream verbose print) (load-as-source stream verbose print)))))) + ;; Case 1: stream. (when (streamp pathspec) - (return-from load (load-stream pathspec))) + (return-from load (load-stream pathspec (fasl-header-p pathspec)))) (let ((pathname (pathname pathspec))) + ;; Case 2: Open as binary, try to process as a fasl. (with-open-stream (stream (or (open pathspec :element-type '(unsigned-byte 8) :if-does-not-exist nil) @@ -121,26 +137,17 @@ :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)))))) + (let* ((real (probe-file stream)) + (should-be-fasl-p + (and real (string-equal (pathname-type real) *fasl-file-type*)))) + ;; Don't allow empty .fasls, and assume other empty files + ;; are source files. + (when (and (or should-be-fasl-p (not (eql 0 (file-length stream)))) + (fasl-header-p stream :errorp should-be-fasl-p)) + (return-from load (load-stream stream t))))) + ;; Case 3: Open using the gived external format, process as source. (with-open-file (stream pathname :external-format external-format) - (load-stream stream))))) + (load-stream stream nil))))) ;; This implements the defaulting SBCL seems to have inherited from ;; CMU. This routine does not try to perform any loading; all it does @@ -186,7 +193,7 @@ (defun load-code (box-num code-length) (declare (fixnum box-num code-length)) (with-fop-stack t - (let ((code (%primitive sb!c:allocate-code-object box-num code-length)) + (let ((code (sb!c:allocate-code-object box-num code-length)) (index (+ sb!vm:code-trace-table-offset-slot box-num))) (declare (type index index)) (setf (%code-debug-info code) (pop-stack)) @@ -232,9 +239,7 @@ tto) (format t " loading to the dynamic space~%")) - (let ((code (%primitive sb!c:allocate-code-object - box-num - code-length)) + (let ((code (sb!c:allocate-code-object box-num code-length)) (index (+ sb!vm:code-trace-table-offset-slot box-num))) (declare (type index index)) (when *load-code-verbose*