Style improvements and minor bugfix from sb-fasteval integration.
[sbcl.git] / src / code / early-fasl.lisp
blob71456012563bf5c7941dcf12cf87fd57b2c07419
1 ;;;; needed-early, or at least meaningful-early, stuff for FASL files
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!FASL")
14 ;;;; various constants and essentially-constants
16 ;;; a string which appears at the start of a fasl file header
17 ;;;
18 ;;; This value is used to identify fasl files. Even though this is not
19 ;;; declared as a constant (because ANSI Common Lisp has no facility
20 ;;; for declaring values which are constant under EQUAL but not EQL),
21 ;;; obviously you shouldn't mess with it lightly. If you do set a new
22 ;;; value for some reason, keep these things in mind:
23 ;;; * To avoid confusion with the similar but incompatible CMU CL
24 ;;; fasl file format, the value should not be "FASL FILE", which
25 ;;; is what CMU CL used for the same purpose.
26 ;;; * Since its presence at the head of a file is used by LOAD to
27 ;;; decide whether a file is to be fasloaded or just loaded
28 ;;; ordinarily (as source), the value should be something which
29 ;;; can't legally appear at the head of a Lisp source file.
30 ;;; * The value should not contain any line-terminating characters,
31 ;;; because they're hard to express portably and because the LOAD
32 ;;; code might reasonably use READ-LINE to get the value to compare
33 ;;; against.
34 (defparameter *fasl-header-string-start-string* "# FASL")
36 (macrolet ((define-fasl-format-features ()
37 (let (;; master value for *F-P-A-F-F*
38 (fpaff '(:sb-thread :sb-package-locks :sb-unicode :gencgc :ud2-breakpoints)))
39 `(progn
40 ;; a list of *(SHEBANG-)FEATURES* flags which affect
41 ;; binary compatibility, i.e. which must be the same
42 ;; between the SBCL which compiles the code and the
43 ;; SBCL which executes the code
45 ;; This is a property of SBCL executables in the
46 ;; abstract, not of this particular SBCL executable,
47 ;; so any flag in this list may or may not be present
48 ;; in the *FEATURES* list of this particular build.
49 (defparameter *features-potentially-affecting-fasl-format*
50 ',fpaff)
51 ;; a string representing flags of *F-P-A-F-F* which
52 ;; are in this particular build
54 ;; (A list is the natural logical representation for
55 ;; this, but we represent it as a string because
56 ;; that's physically convenient for writing to and
57 ;; reading from fasl files, and because we don't
58 ;; need to do anything sophisticated with its
59 ;; logical structure, just test it for equality.)
60 (defparameter *features-affecting-fasl-format*
61 ,(let ((*print-pretty* nil))
62 (prin1-to-string
63 (sort
64 (copy-seq
65 (intersection sb-cold:*shebang-features* fpaff))
66 #'string<
67 :key #'symbol-name))))))))
68 (define-fasl-format-features))
70 ;;; the code for a character which terminates a fasl file header
71 (def!constant +fasl-header-string-stop-char-code+ 255)
73 ;;; This value should be incremented when the system changes in such a
74 ;;; way that it will no longer work reliably with old fasl files. In
75 ;;; practice, I (WHN) have often forgotten to increment it for CVS
76 ;;; versions which break binary compatibility. But it certainly should
77 ;;; be incremented for release versions which break binary
78 ;;; compatibility.
79 (def!constant +fasl-file-version+ 78)
80 ;;; (description of versions before 0.9.0.1 deleted in 0.9.17)
81 ;;; 56: (2005-05-22) Something between 0.9.0.1 and 0.9.0.14. My money is
82 ;;; on 0.9.0.6 (MORE CASE CONSISTENCY).
83 ;;; 57: (2005-06-12) Raw slot rearrangement in 0.9.1.38
84 ;;; 58: (2005-08-16) Multiple incompatible changes between 0.9.3 and 0.9.3.60
85 ;;; 59: (2005-09-18) METAOBJECT implementation, removal of INSTANCE and
86 ;;; FUNCALLABLE-INSTANCE classes.
87 ;;; 60: (2005-10-24) Bumped for 0.9.6
88 ;;; 61: (2005-11-06) Improved source location recording added extra parameters
89 ;;; to multiple %DEFMUMBLE functions.
90 ;;; 62: (2005-12-30) Make the count of FASL header counted strings
91 ;;; a 32-bit value also on 64-bit platforms.
92 ;;; 63: (2006-01-27) Shuffle storage classes around to reduce the error
93 ;;; trap information size on RISCy platforms.
94 ;;; 64: (2006-03-24) New calling convention for unknown-values on x86 and
95 ;;; x86-64. Also (belatedly) PPC/gencgc, including :gencgc on FPAFF.
96 ;;; 65: (2006-04-11) Package locking interface changed.
97 ;;; 66: (2006-05-13) Fopcompiler
98 ;;; 67: (2006-07-25) Reports on #lisp about 0.9.13 fasls being invalid on
99 ;;; 0.9.14.something
100 ;;; 68: (2006-08-14) changed number of arguments of LOAD-DEFMETHOD
101 ;;; 69: (2006-08-17) changed validity of various initargs for methods
102 ;;; 70: (2006-09-13) changes to *PSEUDO-ATOMIC* on x86 and x86-64
103 ;;; 71: (2006-11-19) CLOS calling convention changes
104 ;;; 72: (2006-12-05) Added slot to the primitive function type
105 ;;; 73: (2007-04-13) Changed a hash function
106 ;;; 74: (2007-06-05) UNWIND-TO-FRAME-AND-CALL
107 ;;; 75: (2007-08-06) FD-STREAM layout changes
108 ;;; 76: (2007-10-05) MUTEX layout changes
109 ;;; 77: (2007-11-08) Essentially obsolete fasl-file-version, fasls are now
110 ;;; considered compatible only when the version numbers of the compiling
111 ;;; SBCL instance is exactly the same as the one of the loading instance.
112 ;;; Further fasl-file-version bumps should only be done for real changes
113 ;;; in the fasl format, not for changes in function/macro signatures or
114 ;;; lisp data structures.
115 ;;; 78: (2010-04-02) Add FOP-{SMALL-,}NAMED-PACKAGE, remove FOP-NORMAL-LOAD
116 ;;; and FOP-MAYBE-COLD-LOAD.
118 ;;; the conventional file extension for our fasl files
119 (declaim (type simple-string *fasl-file-type*))
120 (defvar *fasl-file-type* "fasl")
122 ;;;; information about below-Lisp-level linkage
124 ;;; Note:
125 ;;; Assembler routines are named by full Lisp symbols: they
126 ;;; have packages and that sort of native Lisp stuff associated
127 ;;; with them. We can compare them with EQ.
128 (declaim (type hash-table *assembler-routines*))
129 (defvar *assembler-routines* (make-hash-table :test 'eq))
132 ;;;; the FOP database
134 (declaim (simple-vector **fop-names** **fop-funs**))
136 ;;; a vector indexed by a FaslOP that yields the FOP's name
137 (defglobal **fop-names** (make-array 256 :initial-element nil))
139 ;;; a vector indexed by a FaslOP that yields a function which performs
140 ;;; the operation. Most functions take 0 arguments - they only manipulate
141 ;;; the fop stack. But if the fop is defined to receive an argument (or two)
142 ;;; then loader's main loop is responsible for supplying it.
143 (defglobal **fop-funs** (make-array 256 :initial-element 0))
145 ;; Two bitmaps indicate function signature. One tells whether the fop takes
146 ;; operands (other than from the stack). Each consecutive block of 4 opcodes
147 ;; either does or doesn't, so the array is 1/4th the size of the opcode space.
148 ;; The other tells whether the fop wants its result pushed on the stack.
149 (declaim (type (cons (simple-bit-vector 64) (simple-bit-vector 256))
150 **fop-signatures**))
151 (defglobal **fop-signatures**
152 (cons (make-array 64 :element-type 'bit :initial-element 0)
153 (make-array 256 :element-type 'bit :initial-element 0)))
155 ;;;; variables
157 (defvar *load-depth* 0
158 #!+sb-doc
159 "the current number of recursive LOADs")
160 (declaim (type index *load-depth*))
162 (defun make-fop-vector (size)
163 (declare (type index size))
164 (let ((vector (make-array size)))
165 (setf (aref vector 0) 0)
166 vector))
168 ;;; a holder for the FASL file we're reading from
169 (defstruct (fasl-input (:conc-name %fasl-input-)
170 (:constructor make-fasl-input (stream))
171 (:predicate nil)
172 (:copier nil))
173 (stream nil :type ansi-stream :read-only t)
174 (table (make-fop-vector 1000) :type simple-vector)
175 (stack (make-fop-vector 100) :type simple-vector)
176 (deprecated-stuff nil :type list)
177 ;; Sometimes we want to skip over any FOPs with side-effects (like
178 ;; function calls) while executing other FOPs. SKIP-UNTIL will
179 ;; either contain the position where the skipping will stop, or
180 ;; NIL if we're executing normally.
181 (skip-until nil))
182 (declaim (freeze-type fasl-input))