root/trunk/lisp/sys/qcdefs.lisp @ 292

Revision 292, 19.0 KB (checked in by rjs, 3 years ago)

System 78.

Line 
1;Definitions and specials for the Lisp machine Lisp compiler -*-Mode:Lisp; Package:Compiler-*-
2
3;       ** (c) Copyright 1980 Massachusetts Institute of Technology **
4
5;;     "This is insane.  What we clearly want to do is not completely
6;;      clear, and is rooted in NCOMPLR."   -- BSG/Dissociated Press.
7
8(DECLARE (SPECIAL QC-ERROR-OUTPUT-FILE QC-BARF-P))
9
10(DECLARE (SPECIAL LAMBDA-LIST-KEYWORDS))
11
12;; This is an area used by the compiler to cons in.
13;; It is reset from time to time during the compilation.
14(DEFVAR QCOMPILE-TEMPORARY-AREA)
15
16;;; This is a list of (function expr) to be compiled after main compilation,
17;;; it is used for breakoff functions.
18(DEFVAR QC-FUNCTIONS-TO-BE-TRANSLATED)
19
20;This is T if the compiler is being used to generate macro-code
21;which will be passed to the microcompiler.
22;In that case, the code is generated a little differently
23;so as to lead to more optimal microcode.
24;(Actually, it can fail to be valid macrocode, in little ways).
25(DEFVAR GENERATING-MICRO-COMPILER-INPUT-P NIL)
26
27;FUNCTION-BEING-PROCESSED is the function name which the compiler was called on.
28;It is NOT bound for broken-off internal functions.  LAST-ERROR-FUNCTION
29;is what FUNCTION-BEING-PROCESSED was the last time we printed a warning.
30(DEFVAR FUNCTION-BEING-PROCESSED)
31(DEFVAR LAST-ERROR-FUNCTION)
32
33;If HOLDPROG is nil, the lap instructions are typed out on the terminal
34;instead of being saved up for lap.  It is normally set to T globally.
35(DEFVAR HOLDPROG T)
36
37;SPECIALFLAG is T if function binds any special variables (or BIND is called).
38;This information goes into the FEF.
39(DEFVAR SPECIALFLAG)
40
41;LOCAL-DECLARATIONS (on SYSTEM) is a list of local declarations.
42;Each local declaration is a list starting with an atom which says
43;what type of declaration it is.  The meaning of the rest of the
44;list depends on the type of declaration.
45;The compiler is interested only in SPECIAL and UNSPECIAL declarations,
46;for which the rest of the list contains the symbols being declared,
47;and MACRO declarations, which look like (DEF symbol MACRO LAMBDA args ..body...),
48;and ARGLIST declarations, which specify arglists to go in the debugging info
49;(to override the actual arglist of the function, for user information)
50;which look like (ARGLIST FOO &OPTIONAL BAR ...), etc.
51
52;Things get onto LOCAL-DECLARATIONS in two ways:
53;1) inside a LOCAL-DECLARE, the specified declarations are bound onto the front.
54;2) if UNDO-DECLARATIONS-FLAG is T, some kinds of declarations
55;   in a file being compiled into a QFASL file
56;   are consed onto the front, and not popped off until LOCAL-DECLARATIONS
57;   is unbound at the end of the whole file.
58(DEFVAR LOCAL-DECLARATIONS NIL)
59(DEFVAR UNDO-DECLARATIONS-FLAG NIL)
60
61;FILE-LOCAL-DECLARATIONS is just like LOCAL-DECLARATIONS except that it is
62;local to the file being compiled.  The reason this exists is so that if
63;you have a (LOCAL-DECLARE ((ARGLIST ...)) ...) around a (MACRO...),
64;at compile-time the macro wants to be saved on LOCAL-DECLARATIONS, but that
65;is bound by the LOCAL-DECLARE, so it uses FILE-LOCAL-DECLARATIONS instead.
66(DEFVAR FILE-LOCAL-DECLARATIONS NIL)
67
68;This is the intended lexical environment of the function being compiled.
69;For a top-level function in a file, it is NIL.
70;In general it is a list of VARS lists, to be scanned in the order listed.
71(DEFVAR COMPILER-LEXICAL-ENVIRONMENT)
72
73;BARF-SPECIAL-LIST is a list of all variables automatically declared special
74;by the compiler.  Those symbols are special merely by virtue of being on
75;this list, which is bound for the duration of the compilation
76;(for the whole file, whole editor buffer, or just the one function in COMPILE).
77;All users of QC-TRANSLATE-FUNCTION MUST bind this variable.
78;NOTE!! This list must not be CONSed in FASD-TEMPORARY-AREA!!  It lives across
79; whack boundaries.
80(DEFVAR BARF-SPECIAL-LIST)
81
82;This is like BARF-SPECIAL-LIST but only lists those symbols
83;used in the function now being compiled.
84;If a variable used free is not on this list, it gets a new warning
85;even though it may already be special because it is on BARF-SPECIAL-LIST.
86;So there is a new warning for each function that uses the symbol.
87(DEFVAR THIS-FUNCTION-BARF-SPECIAL-LIST)
88
89;SPECIAL-PKG-LIST is a list of packages all of whose symbols should be special.
90(DEFVAR SPECIAL-PKG-LIST (LIST (PKG-FIND-PACKAGE "FONTS")))
91
92;This is a list of lists; each element of each list
93;is a symbol which is a variable in the function being compiled.
94;When lap addresses are assigned, each variable which is not special
95;is RPLAC'd with NIL.
96;Further, each list is RPLACD'd with NIL after the last non-NIL element.
97(DEFVAR CLOBBER-NONSPECIAL-VARS-LISTS)
98
99;BINDP on pass 1 is T if BIND is called in the current PROG.
100;It is then consed into the internal form of the PROG, for pass 2's sake.
101(DEFVAR BINDP)
102
103;Pass 2 variables needed only in QCP2 except for binding in QCOMPILE0:
104;See the beginning of QCP2 for more information on them.
105(DECLARE (SPECIAL PDLLVL MAXPDLLVL TAGOUT DROPTHRU CALL-BLOCK-PDL-LEVELS))
106
107;QCMP-OUTPUT on the Lisp machine is an ART-Q-LIST array into which the
108;lap-instructions are stored by pass 2.  In Maclisp, it is a list onto which
109;the instructions are PUSHed;  it is NREVERSEd and sent to lap.
110(DEFVAR QCMP-OUTPUT)
111
112;TLEVEL on pass 1 is T if we are at "top level" within the function being compiled,
113;not within any actual function calls.
114;If a PROG is seen when TLEVEL is set, the locals of the prog can
115;be initialized by the entry to the function.
116(DEFVAR TLEVEL)
117
118;TLFUNINIT on pass 1 is T if we have already seen a variable initialized to the
119;result of a function call.  Such initializations can't be done except
120;by compiled code, and once we have initialized one thing that way
121;all succeeding variables must be initialized by code as well.
122;(This applies to SPROGs.  PPROGs are a little different).
123(DEFVAR TLFUNINIT)
124
125;FAST-ARGS-POSSIBLE on pass 1 is T if we haven't come across
126;any argument to this function with a non-NIL initialization.
127;If this remains T after all the arguments are processed,
128;then it is an optimization to make top-level prog vars
129;be initialized at function entry instead of by code.
130(DEFVAR FAST-ARGS-POSSIBLE)
131
132;P1VALUE is T on pass 1 when compiling a form for value, NIL if for effect.
133;On pass 2, "destinations" are used instead, with many more alternatives.
134(DEFVAR P1VALUE)
135
136;MACROLIST is an alist of macro definitions to be used only while compiling.
137;While compiling a file, macros in the file get put on MACROLIST temporarily.
138(DEFVAR MACROLIST NIL)
139
140;PEEP-ENABLE, if T, means that the peephole optimizer should be used.
141(DEFVAR PEEP-ENABLE NIL)
142
143;FUNCTIONS-DEFINED is a list of all functions defined in the file being compiled.
144(DEFVAR FUNCTIONS-DEFINED)
145
146;FUNCTIONS-REFERENCED is a list of all functions referred to in the file being
147;compiled, and not defined in the world.  Each element has as its CAR the
148;name of the function, and as its CDR a list of the names of the functions
149;which referenced it.
150(DEFVAR FUNCTIONS-REFERENCED)
151
152
153;Compiler switches:  set these with (DECLARE (SETQ ...))
154;These are initialized in QC-PROCESS-INITIALIZE
155
156;This, if T, causes MAP, etc. to be open-coded.  It is normally T.
157(DEFVAR OPEN-CODE-MAP-SWITCH)
158
159;This, if T, causes a check to be made for the use of a local variable
160;as a function to be called, meaning funcall.  This should be set to T
161;only for compiling old-fashioned Maclisp code.
162(DEFVAR ALLOW-VARIABLES-IN-FUNCTION-POSITION-SWITCH)
163
164;This, if T, makes all variabes special.
165(DEFVAR ALL-SPECIAL-SWITCH)
166
167;This, if T (as it usually is), warns the user if any obsolete
168;Maclisp functions are used.
169(DEFVAR OBSOLETE-FUNCTION-WARNING-SWITCH)
170
171;This, if T, warns the user if he does anything that clearly
172;cannot work in Maclisp.
173(DEFVAR RUN-IN-MACLISP-SWITCH)
174
175;This, if T, prevents warnings about a lot of stylistic losses.
176(DEFVAR INHIBIT-STYLE-WARNINGS-SWITCH)
177
178;Counter for breakoff functions
179(DEFVAR BREAKOFF-COUNT)
180
181;If non-null, this is the name of an editor buffer in which warnings are saved
182(DEFVAR COMPILER-WARNINGS-BUFFER "Compiler Warnings")
183;Switch to enable saving of all warnings.  Default is to flush buffer
184;each time a new compilation is started.
185(DEFVAR CONCATENATE-COMPILER-WARNINGS-P ':BY-FILE)
186
187;Flag when compiler warnings are being saved for a higher level, like MAKE-SYSTEM
188(DEFVAR COMPILER-WARNINGS-CONTEXT NIL)
189(DEFVAR COMPILER-WARNINGS-INTERVAL-STREAM)
190(DEFVAR COMPILING-WHOLE-FILE-P NIL)
191(IF-FOR-MACLISP-ELSE-LISPM
192
193 (DEFMACRO COMPILER-WARNINGS-CONTEXT-BIND (&BODY BODY)
194   `(LET ((FUNCTIONS-REFERENCED NIL)
195          (FUNCTIONS-DEFINED NIL)
196          (BARF-SPECIAL-LIST NIL))
197      . ,BODY))
198
199(DEFMACRO COMPILER-WARNINGS-CONTEXT-BIND (&BODY BODY)
200  (LET ((TOP-LEVEL-P-VAR (GENSYM)))
201    `(LET ((,TOP-LEVEL-P-VAR (NOT COMPILER-WARNINGS-CONTEXT)))
202       (LET-IF ,TOP-LEVEL-P-VAR
203               ((COMPILER-WARNINGS-CONTEXT T)
204                (STANDARD-OUTPUT STANDARD-OUTPUT)
205                (COMPILER-WARNINGS-INTERVAL-STREAM NIL)
206                (FUNCTIONS-REFERENCED NIL)
207                (FUNCTIONS-DEFINED NIL)
208                (BARF-SPECIAL-LIST NIL))
209          (AND ,TOP-LEVEL-P-VAR
210               (ENTER-COMPILER-WARNINGS-CONTEXT))
211          (PROG1 (PROGN . ,BODY)
212                 (AND ,TOP-LEVEL-P-VAR
213                      (PRINT-FUNCTIONS-REFERENCED-BUT-NOT-DEFINED)))))))
214
215  )
216
217;(ADD-OPTIMIZER FOO BAR) puts FOO on BAR's optimizers list if it isn't there already.
218;(ADD-OPTIMIZER FOO BAR BAR-1 BAR-2...) also remembers that BAR can be optimized
219; into BAR-1, BAR-2, etc. for the benefit of functions like WHO-CALLS.
220(DEFUN ADD-OPTIMIZER (&QUOTE TARGET-FUNCTION OPTIMIZER-NAME &REST OPTIMIZED-INTO)
221  (LET ((OPTS (GET TARGET-FUNCTION 'OPTIMIZERS)))
222    (OR (MEMQ OPTIMIZER-NAME OPTS)
223        (PUTPROP TARGET-FUNCTION (CONS OPTIMIZER-NAME OPTS) 'OPTIMIZERS)))
224  (LET ((OPTS (GET TARGET-FUNCTION 'OPTIMIZED-INTO)))
225    (DOLIST (INTO OPTIMIZED-INTO)
226      (OR (MEMQ INTO OPTS) (PUSH INTO OPTS)))
227    (AND OPTS
228         (PUTPROP TARGET-FUNCTION OPTS 'OPTIMIZED-INTO))))
229
230;;; Variables data bases:
231
232;Bound (local or special) variables are described by two lists of variable descriptors:
233;VARS, which describes only variables visible from the current point of compilation,
234;and ALLVARS, which describes all variables seen so far in the current compilation.
235(DEFVAR VARS)
236;ALLVARS is passed to lap to allocate slots, while VARS is used on both passes
237;for figuring out what to do with a variable.
238(DEFVAR ALLVARS)
239
240;In addition, FREEVARS is a list of all special variables referred to free.
241(DEFVAR FREEVARS)
242
243;ARG-MAP and LOCAL-MAP are given the arg map and local map for the debugging info.
244;This is done by ASSIGN-LAP-ADDRESSES, so that special vars that get a slot
245;can be put in the map even though their places in it will not be recogizable
246;from their lap addresses.
247(DEFVAR ARG-MAP)
248(DEFVAR LOCAL-MAP)
249
250;Each element of VARS or ALLVARS describes one variable, and is called a VAR or a "home".
251;A VAR has these components:
252(DEFMACRO VAR-NAME (VAR) `(CAR ,VAR))   ;NAME must be first since we use ASSQ on it.
253(DEFMACRO VAR-KIND (VAR) `(CADR ,VAR))
254(DEFMACRO VAR-TYPE (VAR) `(CADDR ,VAR))
255(DEFMACRO VAR-USE-COUNT (VAR) `(CADDDR ,VAR))
256(DEFMACRO VAR-LAP-ADDRESS (VAR) `(CAR (CDDDDR ,VAR)))
257(DEFMACRO VAR-INIT (VAR) `(CADR (CDDDDR ,VAR)))
258(DEFMACRO VAR-EVAL (VAR) `(CADDR (CDDDDR ,VAR)))
259(DEFMACRO VAR-MISC (VAR) `(CADDDR (CDDDDR ,VAR)))
260(DEFMACRO VAR-DECLARATIONS (VAR) `(CAR (CDDDDR (CDDDDR ,VAR))))
261(DEFMACRO VAR-OVERLAP-VAR (VAR) `(CADR (CDDDDR (CDDDDR ,VAR))))
262
263(DEFMACRO SETF-VAR-INIT (VAR VALUE) `(RPLACA (CDR (CDDDDR ,VAR)) ,VALUE))
264(DEFMACRO SETF-VAR-KIND (VAR VALUE) `(RPLACA (CDR ,VAR) ,VALUE))
265(DEFMACRO SETF-VAR-LAP-ADDRESS (VAR VALUE) `(RPLACA (CDDDDR ,VAR) ,VALUE))
266
267;The KIND is one of
268; (FEF-ARG-REQ FEF-ARG-OPT FEF-ARG-REST FEF-ARG-AUX FEF-ARG-INTERNAL-AUX)
269;The TYPE is either FEF-LOCAL, FEF-SPECIAL, or FEF-REMOTE.
270;The USE-COUNT is the number of times the variable is referred to (read or written),
271;  not counting the binding and initialization.
272;The LAP-ADDRESS is an instruction address for Lap to refer to this variable.
273;  It specifies the either the argument block or the local block, and an offset.
274;  For special variables, it is (SPECIAL varname).
275;For the INIT, see below.
276;The EVAL is FEF-QT-QT, FEF-QT-EVAL, etc., saying how an argument needs to be evaluated.
277;The MISC is a list of other FEF-mumble-mumble symbols for this variable.
278;  These include FEF-ARG-FUNCTIONAL meaning set the "functional" flag on this arg,
279;  and FEF-ARG-SPECIFIED-FLAG meaning this is the specified-flag of an optional arg.
280;  Lap has a tendency to eval these symbols and add them into the ADL word.
281;  So any not intended for Lap should be given the value 0, here.
282(DEFVAR FEF-ARG-SPECIFIED-FLAG 0)
283
284;VAR-DECLARATIONS is an ALIST recording declarations pertaining to this variable.
285;  It is produced by examining LOCAL-DECLARATIONS and FILE-LOCAL-DECLARATIONS
286; in the context the variable's creation, as well as static declarations
287; on the variables' PLIST.
288
289; These keys, seen in any of the above contexts, are assumed to apply to lists of
290;variables.
291(DEFVAR VARIABLE-DECLARATION-KEYS '(FIXNUM FLONUM NOTYPE))
292
293;VAR-OVERLAP-VAR is a pointer to the entry for another var whose slot
294;can be re-used for this variable.
295
296;Ordinary arguments are allocated slots in the argument portion of the pdl frame.
297;ARGN counts the number of them.
298(DEFVAR ARGN)
299;Rest args, aux variables and nonspecial variables of kind internal-aux
300;are allocated slots in the local portion of the stack frame.
301;LVCNT counts the number of them.
302(DEFVAR LVCNT)
303;Special variables, free or bound, require slots in a portion of the FEF.
304;SVCNT counts the number of them.
305(DEFVAR SVCNT)
306
307;The INIT is of the form ( <type> <data> . <arg-supplied-flag home>)
308;The arg-supplied-flag name is the home of FOOP in &OPTIONAL (FOO NIL FOOP).
309;It appears only for optional arguments which have such a flag.
310;If there is none, the cddr of INIT will be nil.
311;The type is of of several symbols starting with "FEF-INI-", that
312;signify one of the ways of initializing the variable.
313;FEF-INI-COMP-C indicates that compiled code will be used to
314;do the initialization.  It is the most general.  The other types
315;exist to make special cases more efficient.  They are:
316
317;FEF-INI-NONE           No initialization (for a local variable which should be nil).
318;FEF-INI-SELF           Initialize to self (for special variable).
319;FEF-INI-NIL            Initialize to NIL (for special variable).
320;FEF-INI-PNTR           Initialize to a constant.  <data> is that constant.
321;FEF-INI-C-PNTR         Initialize to the contents of a location.  <data> points to it.
322;FEF-INI-EFF-ADR        Initialize to the contents of an "effective address".
323;                       This is used to copy the value of a previous arg or local variable.
324;                       <data> specifies which one, using an instruction source field
325;                       which will specify the arg block or the local block, plus offset.
326;FEF-INI-OPT-SA         For an optional variable with a complicated default value.
327;                       <data> specifies a starting address inside the function
328;                       which is where to start if the argument IS supplied.
329;                       It follows the code used to compute and store the default value.
330;FEF-INI-COMP-C         Indicates that the variable will be initialized by the
331;                       compiled code of the function.
332
333;;;     - IN GENERAL -
334;;;     INTERNAL VARIABLES ARE BOUND BY INTERNAL LAMBDA'S AND PROGS
335;;;     OTHERS ARE BOUND AT ENTRY TIME
336;;;     ALL INTERNAL VARIABLES ARE INITIALIZED BY CODE
337;;;     ARG VARIABLES ARE NEVER INITIALIZED
338;;;     OPTIONAL AND AUX VARIABLES ARE INITIALIZED AT BIND TIME
339;;;     IF POSSIBLE OTHERWISE BY CODE
340;;;     THIS "POSSIBILITY" IS DETERMINED AS FOLLOWS:
341;;;             INITIALLY, IT IS POSSIBLE
342;;;             IT REMAINS POSSIBLE UNTIL YOU COME TO A VARIABLE
343;;;             INITIALIZED TO A FCTN, AT WHICH POINT IT IS NO LONGER POSSIBLE
344;;;     IF VAR TO BE INITIALIZED BY CODE, CODE 0 (SPECIAL) OR
345;;;     1 (LOCAL) IS USED IN INITIALIZATION FLD
346
347;PROG, GO and RETURN data bases.
348
349;ALLGOTAGS is a list of all prog-tags defined so far in the current function,
350;whether the progs defining them contain the current one or not.
351;ALLGOTAGS is used to determine when a new tag must be renamed.
352(DEFVAR ALLGOTAGS)
353
354;The variable GOTAGS contains an alist describing all the prog tags
355;of progs the code we are currently compiling is contained in.
356;Each element of GOTAGS is a GOTAG:
357(DEFVAR GOTAGS)
358
359;Mustn't use DEFSTRUCT, since must run in Maclisp!
360(DEFMACRO GOTAG-PROG-TAG (GOTAG) `(CAR ,GOTAG)) ;Name of prog-tag described.
361(DEFMACRO GOTAG-LAP-TAG (GOTAG) `(CADR ,GOTAG)) ;Name of corresponding lap-tag.
362(DEFMACRO GOTAG-PDL-LEVEL (GOTAG) `(CADDR ,GOTAG))  ;Pdl level to pop back to when going there.
363(DEFMACRO GOTAG-PROGDESC (GOTAG) `(CADDDR ,GOTAG))  ;Progdesc of that prog.
364
365(DEFMACRO MAKE-GOTAG (&OPTIONAL PROG-TAG LAP-TAG PDL-LEVEL PROGDESC)
366  `(LIST ,PROG-TAG ,LAP-TAG ,PDL-LEVEL ,PROGDESC))
367
368;PROGDESCS is a list of descriptors of PROGs which are active, on pass 2.
369;Each descriptor looks like (progname rettag idest m-v-target pdl-level nbinds).
370;The <progname> is the name of the prog, or NIL for an anonymous one.
371;A progname of T indicates an "invisible" compiler-generated PROG
372;which an explicit RETURN should return past.
373;The <rettag> is a gensym tag which is defined at the end of the prog body.
374;The <idest> is the destination which return's in the prog send values to.
375;That may not be the same as the ultimate destination of the prog.
376;If they are different, then there is code after the <rettag> to
377;move from <idest>, which is D-PDL, to the real destination.
378;The <m-v-target> is the M-V-TARGET of the call to PROG.
379;If it is NIL, only one value is wanted from the prog.
380;If it is MULTIPLE-VALUE-LIST, then the prog should really
381;return the list of the values that RETURN wants to return.
382;If it is a list of variables, then returning should SETQ those variables
383;and also return the first value in the ordinary way.
384;If <idest> is D-RETURN, then all this is taken care of by the
385;function calling mechanism, and isn't known at compile time, so
386;in that case <m-v-target> is ignored.
387;The <pdl-level> is the pdl level at entry to the prog,
388;which is also the level in between statements in the prog.
389;<nbinds> is the number of special bindings to undo at exit from the prog,
390;or a list containing the number of specials bound at entry to the prog,
391;if the prog contains calls to BIND which must be unbound first by
392;calling output-unbind-to-index.
393
394;The CAR of PROGDESCS describes the innermost prog.
395(DEFVAR PROGDESCS)
396
397;Mustn't use DEFSTRUCT, since must run in Maclisp!
398(DEFMACRO PROGDESC-NAME (DESC) `(CAR ,DESC))
399(DEFMACRO PROGDESC-RETTAG (DESC) `(CADR ,DESC))
400(DEFMACRO PROGDESC-IDEST (DESC) `(CADDR ,DESC))
401(DEFMACRO PROGDESC-M-V-TARGET (DESC) `(CADDDR ,DESC))
402(DEFMACRO PROGDESC-PDL-LEVEL (DESC) `(CAR (CDDDDR ,DESC)))
403(DEFMACRO PROGDESC-NBINDS (DESC) `(CADR (CDDDDR ,DESC)))
404
405(DEFMACRO MAKE-PROGDESC (PROGNAME RETTAG IDEST M-V-TARGET PDL-LEVEL NBINDS)
406          `(LIST ,PROGNAME ,RETTAG ,IDEST ,M-V-TARGET ,PDL-LEVEL ,NBINDS))
407
408;RETPROGDESC is the descriptor of the prog for RETURN, RETURN-LIST, etc.
409;to return from.  Normally, it is the descriptor of the innermost prog
410;(not counting "invisible" PROGs named T),
411;or nil if no prog is active (return is an error),
412;but (RETURN-FROM <progname> ...) binds it to the descriptor for the specified prog.
413(DEFVAR RETPROGDESC)
414
415;Several variables must be declared explicitly in Maclisp.
416;These must be special not declare (special ..), because this file is read into
417;the compiler, not compiled
418(IF-FOR-MACLISP
419 (SPECIAL FASD-TEMPORARY-AREA DEFAULT-CONS-AREA *LEXPR-ARGLIST*))
Note: See TracBrowser for help on using the browser.