0.pre8.108:
[sbcl.git] / src / code / early-fasl.lisp
1 ;;;; needed-early, or at least meaningful-early, stuff for FASL files
2
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.
11
12 (in-package "SB!FASL")
13 \f
14 ;;;; various constants and essentially-constants
15
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")
35
36 (macrolet ((define-fasl-format-features ()
37              (let (;; master value for *F-P-A-F-F*
38                    (fpaff '(:sb-thread)))
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
44                   ;;
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
53                   ;;
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))
69            
70 ;;; the code for a character which terminates a fasl file header
71 (def!constant +fasl-header-string-stop-char-code+ 255)
72
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+ 41)
80 ;;; (record of versions before 2003 deleted in 2003-04-26/0.pre8.107 or so)
81 ;;; 38: (2003-01-05) changed names of internal SORT machinery
82 ;;; 39: (2003-02-20) in 0.7.12.1 a slot was added to
83 ;;;     DEFSTRUCT-SLOT-DESCRIPTION
84 ;;; 40: (2003-03-11) changed value of (SXHASH NIL)
85 ;;; 41: (2003-04-26) enforced binary incompatibility between +SB-THREAD
86 ;;;     and -SB-THREAD builds
87
88 ;;; the conventional file extension for our fasl files
89 (declaim (type simple-string *fasl-file-type*))
90 (defvar *fasl-file-type* "fasl")
91 \f
92 ;;;; information about below-Lisp-level linkage
93
94 ;;; Note:
95 ;;;   Assembler routines are named by full Lisp symbols: they
96 ;;;     have packages and that sort of native Lisp stuff associated
97 ;;;     with them. We can compare them with EQ.
98 ;;;   Foreign symbols are named by Lisp STRINGs: the Lisp package
99 ;;;     system doesn't extend out to symbols in languages like C.
100 ;;;     We want to use EQUAL to compare them.
101 ;;;   *STATIC-FOREIGN-SYMBOLS* are static as opposed to "dynamic" (not
102 ;;;     as opposed to C's "extern"). The table contains symbols known at 
103 ;;;     the time that the program was built, but not symbols defined
104 ;;;     in object files which have been loaded dynamically since then.
105 (declaim (type hash-table *assembler-routines* *static-foreign-symbols*))
106 (defvar *assembler-routines* (make-hash-table :test 'eq))
107 (defvar *static-foreign-symbols* (make-hash-table :test 'equal))
108 \f
109 ;;;; the FOP database
110
111 (declaim (simple-vector *fop-names* *fop-funs*))
112
113 ;;; a vector indexed by a FaslOP that yields the FOP's name
114 (defvar *fop-names* (make-array 256 :initial-element nil))
115
116 ;;; a vector indexed by a FaslOP that yields a function of 0 arguments
117 ;;; which will perform the operation
118 (defvar *fop-funs*
119   (make-array 256
120               :initial-element (lambda ()
121                                  (error "corrupt fasl file: losing FOP"))))
122 \f
123 ;;;; other miscellaneous loading-related stuff
124
125 \f
126 ;;;; variables
127
128 (defvar *load-depth* 0
129   #!+sb-doc
130   "the current number of recursive LOADs")
131 (declaim (type index *load-depth*))
132
133 ;;; the FASL file we're reading from
134 (defvar *fasl-input-stream*)
135 (declaim (type ansi-stream *fasl-input-stream*))
136
137 (defvar *load-print* nil
138   #!+sb-doc
139   "the default for the :PRINT argument to LOAD")
140 (defvar *load-verbose* nil
141   ;; Note that CMU CL's default for this was T, and ANSI says it's
142   ;; implementation-dependent. We choose NIL on the theory that it's
143   ;; a nicer default behavior for Unix programs.
144   #!+sb-doc
145   "the default for the :VERBOSE argument to LOAD")
146
147 (defvar *load-code-verbose* nil)
148