18-complr.lpt 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286
  1. PSL Manual 7 February 1983 Compiler and Loader
  2. section 18.0 page 18.1
  3. CHAPTER 18 CHAPTER 18 CHAPTER 18
  4. LOADER AND COMPILER LOADER AND COMPILER LOADER AND COMPILER
  5. 18.1. Introduction . . . . . . . . . . . . . . . 18.1
  6. 18.2. The Compiler . . . . . . . . . . . . . . . 18.2
  7. 18.2.1. Compiling Functions into Memory . . . . . . 18.2
  8. 18.2.2. Compiling Functions into FASL Files . . . . . 18.3
  9. 18.2.3. Loading FASL Files. . . . . . . . . . . 18.3
  10. 18.2.4. Functions to Control the Time When Something is Done 18.5
  11. .
  12. 18.2.5. Order of Functions for Compilation . . . . . 18.6
  13. 18.2.6. Fluid and Global Declarations . . . . . . . 18.6
  14. 18.2.7. Switches Controlling Compiler . . . . . . . 18.8
  15. 18.2.8. Differences between Compiled and Interpreted Code 18.10
  16. 18.2.9. Compiler Errors. . . . . . . . . . . . 18.11
  17. 18.3. The Loader. . . . . . . . . . . . . . . . 18.13
  18. 18.3.1. Legal LAP Format and Pseudos . . . . . . . 18.14
  19. 18.3.2. Examples of LAP for DEC-20, VAX and Apollo. . . 18.14
  20. 18.3.3. Lap Switches. . . . . . . . . . . . . 18.17
  21. 18.4. Structure and Customization of the Compiler. . . . . 18.18
  22. 18.5. First PASS of Compiler. . . . . . . . . . . . 18.19
  23. 18.5.1. Tagging Information . . . . . . . . . . 18.19
  24. 18.5.2. Source to Source Transformations . . . . . . 18.20
  25. 18.6. Second PASS - Basic Code Generation . . . . . . . 18.20
  26. 18.6.1. The Cmacros . . . . . . . . . . . . . 18.20
  27. 18.6.2. Classes of Functions . . . . . . . . . . 18.23
  28. 18.6.3. Open Functions . . . . . . . . . . . . 18.24
  29. 18.7. Third PASS - Optimizations . . . . . . . . . . 18.29
  30. 18.8. Some Structural Notes on the Compiler. . . . . . . 18.30
  31. 18.1. Introduction 18.1. Introduction 18.1. Introduction
  32. The functions and facilities in the PSL LISP/SYSLISP compiler and
  33. supporting loaders (LAP and FASL) are described in this chapter.
  34. [??? This chapter is out of date and will be rewritten soon. ???] [??? This chapter is out of date and will be rewritten soon. ???] [??? This chapter is out of date and will be rewritten soon. ???]
  35. 18.2. The Compiler 18.2. The Compiler 18.2. The Compiler
  36. The compiler is a version of the Portable LISP Compiler [Griss 81], Compiler and Loader 7 February 1983 PSL Manual
  37. page 18.2 section 18.2
  38. 1
  39. modified and extended to more efficiently support both LISP and SYSLISP
  40. compilation. See the later sections in this chapter and references [Griss
  41. 81] and [Benson 81] for more details.
  42. 18.2.1. Compiling Functions into Memory 18.2.1. Compiling Functions into Memory 18.2.1. Compiling Functions into Memory
  43. __________ ______ !*COMP [Initially: NIL] switch
  44. If the compiler is loaded (which is usually the case, otherwise
  45. on on execute LOAD COMPILER;), turning on the switch !*COMP (via on
  46. comp; in RLISP) causes all subsequent procedure definitions of
  47. appropriate type to be compiled automatically and a message of
  48. the form
  49. <function-name> COMPILED, <words> WORDS, <words> LEFT
  50. to be printed. The first number is the number of words of binary
  51. program space the compiled function took, and the second number
  52. the number of words left unused in binary program space. See
  53. !*PWRDS in Section 18.2.7.
  54. ____ _____ _____ _____ ____ _____ _____ _____ ____ _____ _____ _____ expr fexpr nexpr macro expr fexpr nexpr macro Currently, exprs, fexprs, nexprs and macros may be compiled. This is
  55. controlled by a flag ('COMPILE) on the property list of the procedure type.
  56. If desired, uncompiled functions already resident may be compiled by
  57. using
  58. Compile Compile _____ __ ____ ___ ____ (Compile NAMES:id-list): any expr
  59. 18.2.2. Compiling Functions into FASL Files 18.2.2. Compiling Functions into FASL Files 18.2.2. Compiling Functions into FASL Files
  60. Load FaslIn Load FaslIn In order to produce files that may be input using Load or FaslIn, the
  61. FaslOut FaslEnd FaslOut FaslEnd FaslOut and FaslEnd pair may be used in RLISP mode:
  62. FaslOut FaslOut ____ ______ ___ ____ (FaslOut FILE:string): NIL expr
  63. _______________
  64. 1
  65. Many of the recent extensions to the PLC were implemented by John
  66. Peterson. PSL Manual 7 February 1983 Compiler and Loader
  67. section 18.2 page 18.3
  68. FaslEnd FaslEnd ___ ____ (FaslEnd ): NIL expr
  69. FaslOut FaslOut After the command FaslOut has been given, all subsequent
  70. S-expressions and function definitions typed in or input from
  71. files are processed by the Compiler, LAP and FASL as needed, and
  72. ____ output to FILE. Functions are compiled and partially assembled,
  73. and output as in a compressed binary form, involving blocks of
  74. code and relocation bits. This activity continues until the
  75. FaslEnd FaslEnd function FaslEnd terminates this process.
  76. FaslOut FaslEnd FaslOut FaslEnd The FaslOut and FaslEnd pair also use the DFPRINT!* mechanism, turning on
  77. the switch !*DEFN, and redefining DFPRINT!* to trap the parsed input in the
  78. RLISP top-loop. Currently this is not useable from pure LISP level.
  79. [??? Fix, by adding !*DEFN mechanism to basic top-loop. ???] [??? Fix, by adding !*DEFN mechanism to basic top-loop. ???] [??? Fix, by adding !*DEFN mechanism to basic top-loop. ???]
  80. 18.2.3. Loading FASL Files 18.2.3. Loading FASL Files 18.2.3. Loading FASL Files
  81. Two convenient procedures are available for loading FASL files (.b files
  82. on the VAX); see Section 18.2.2 for information on producing FASL files.
  83. Load Load ____ ______ __ ___ _____ (Load [FILE:{string, id}]): NIL macro
  84. ____ Each FILE is converted into a file name of the form
  85. "/u/local/lib/psl/file.b" on the VAX, "pl:file.b" on the DEC-20.
  86. FaslIn FaslIn An attempt is made to execute the function FaslIn on it. Once
  87. ____ loaded, the symbol FILE is added to the GLOBAL variable
  88. OPTIONS!*.
  89. FaslIn FaslIn ________ ______ ___ ____ (FaslIn FILENAME:string): NIL expr
  90. This is an efficient binary read loop, which fetches blocks of
  91. __ code, constants and compactly stored ids. It uses a bit-table to
  92. relocate code and to identify special LISP-oriented constructs.
  93. ________ FILENAME must be a complete file name.
  94. ReLoad ReLoad ____ ______ __ ___ _____ (ReLoad [FILE:{string,id}]): NIL macro
  95. Removes the filename from the list OPTIONS!* and executes the
  96. Load Load function Load.
  97. Imports Imports ___________ ____ ___ ____ (Imports MODULENAMES:list): NIL expr
  98. LOAD ___________ __ LOAD MODULENAMES is a list of ids representing modules to be LOAD'ed
  99. after the module containing this function has been loaded.
  100. Imports Imports Imports works only in compiled code. Compiler and Loader 7 February 1983 PSL Manual
  101. page 18.4 section 18.2
  102. __________ ______ LOADDIRECTORIES!* [Initially: A list of strings] global
  103. Contains a list of strings to append to the front of file names
  104. Load Load given in Load commands. This list may be one of the following,
  105. if your system is an Apollo, Dec-20, or Vax:
  106. ("" "/utah/psl/lap/")
  107. ("" "pl:")
  108. ("" "/usr/local/src/cmd/psl/dist/lap/")
  109. __________ ______ LOADEXTENSIONS!* [Initially: An a-list] global
  110. Contains an a-list of (str . fn) in which the str is an extension
  111. to append to the end of the filename and fn is a function to
  112. apply. The a-list contains
  113. ((".b" . FaslIn)(".lap" . LapIn)(".sl" . LapIN))
  114. [??? Describe FASL format in more detail ???] [??? Describe FASL format in more detail ???] [??? Describe FASL format in more detail ???]
  115. 18.2.4. Functions to Control the Time When Something is Done 18.2.4. Functions to Control the Time When Something is Done 18.2.4. Functions to Control the Time When Something is Done
  116. Which expressions are evaluated during compilation ONLY, which output to
  117. the file for LOAD TIME evaluation, and which do both (such as macro
  118. definitions) can be controlled by the properties 'EVAL and 'IGNORE on
  119. certain function names, or the following functions.
  120. CommentOutCode CommentOutCode _ ____ ___ _____ (CommentOutCode U:form): NIL macro
  121. _ Comment out a single expression; use <<U>> to comment out a block
  122. of code.
  123. CompileTime CompileTime _ ____ ___ ____ (CompileTime U:form): NIL expr
  124. _ Evaluate the expression U at compile time only, such as defining
  125. auxiliary smacros and macros that should not go into the file.
  126. Certain functions have the FLAG 'IGNORE on their property lists
  127. to achieve the same effect. E.g. FLAG('(LAPOUT LAPEND),'IGNORE)
  128. has been done.
  129. BothTimes BothTimes _ ____ _ ____ ____ (BothTimes U:form): U:form expr
  130. Evaluate at compile and load time. This is equivalent in effect
  131. Flag Flag to executing Flag('(f1 f2),'EVAL) for certain functions. PSL Manual 7 February 1983 Compiler and Loader
  132. section 18.2 page 18.5
  133. LoadTime LoadTime _ ____ _ ____ ____ (LoadTime U:form): U:form expr
  134. Evaluate at load time only. Should not even compile code, just
  135. pass direct to file.
  136. [??? EVAL and IGNORE are for compatibility, and enable the above sort [??? EVAL and IGNORE are for compatibility, and enable the above sort [??? EVAL and IGNORE are for compatibility, and enable the above sort
  137. of functions to be easily written. The user should AVOID EVAL and of functions to be easily written. The user should AVOID EVAL and of functions to be easily written. The user should AVOID EVAL and
  138. IGNORE flags, if Possible ???] IGNORE flags, if Possible ???] IGNORE flags, if Possible ???]
  139. 18.2.5. Order of Functions for Compilation 18.2.5. Order of Functions for Compilation 18.2.5. Order of Functions for Compilation
  140. ____ ____ ____ expr expr Non-expr procedures must be defined before their use in a compiled
  141. function, since the compiler treats the various function types differently.
  142. _____ _____ _____ _____ _____ _____ Macro fexpr Macro fexpr Macros are expanded and then compiled; the argument list fexprs quoted; the
  143. _____ _____ _____ nexpr nexpr arguments of nexprs are collected into a single list. Sometimes it is
  144. convenient to define a Dummy version of the function of appropriate type,
  145. to be redefined later. This acts as an "External or Forward" declaration
  146. of the function.
  147. [??? Add such a declaration. ???] [??? Add such a declaration. ???] [??? Add such a declaration. ???]
  148. 18.2.6. Fluid and Global Declarations 18.2.6. Fluid and Global Declarations 18.2.6. Fluid and Global Declarations
  149. The FLUID and GLOBAL declarations must be used to indicate variables that
  150. are to be used as non-LOCALs in compiled code. Currently, the compiler
  151. defaults variables bound in a particular procedure to LOCAL. The effect of
  152. this is that the variable only exists as an "anonymous" stack location; its
  153. name is compiled away and called routines cannot see it (i.e. they would
  154. have to use the name). Undeclared non-LOCAL variables are automatically
  155. declared FLUID by the compiler with a warning. In many cases, this means
  156. that a previous procedure that bound this variable should have known about
  157. this as a FLUID. Declare it with FLUID, below, and recompile, since the
  158. caller cannot be automatically fixed.
  159. [??? Should we provide an !*AllFluid switch to make the default Fluid, [??? Should we provide an !*AllFluid switch to make the default Fluid, [??? Should we provide an !*AllFluid switch to make the default Fluid,
  160. or should we make Interpreter have a LOCAL variable as default, or both or should we make Interpreter have a LOCAL variable as default, or both or should we make Interpreter have a LOCAL variable as default, or both
  161. ???] ???] ???]
  162. Fluid Fluid _____ __ ____ ___ ____ (Fluid NAMES:id-list): any expr
  163. Declares each variable FLUID (if not previously declared); this
  164. Prog Prog means that it can be used as a Prog LOCAL, or as a parameter. On
  165. entry to the procedure, its current value is saved on the Binding
  166. Stack (BSTACK), and all access is always to the VALUE cell
  167. Throw Error Throw Error (SYMVAL) of the variable; on exit (or Throw or Error), the old
  168. values are restored. Compiler and Loader 7 February 1983 PSL Manual
  169. page 18.6 section 18.2
  170. Global Global _____ __ ____ ___ ____ (Global NAMES:id-list): any expr
  171. Declares each variable GLOBAL (if not previously declared); this
  172. means that it cannot be used as a LOCAL, or as a parameter.
  173. Access is always to the VALUE cell (SYMVAL) of the variable.
  174. [??? Should we eliminate GLOBALs ???] [??? Should we eliminate GLOBALs ???] [??? Should we eliminate GLOBALs ???]
  175. 18.2.7. Switches Controlling Compiler 18.2.7. Switches Controlling Compiler 18.2.7. Switches Controlling Compiler
  176. The compilation process is controlled by a number of switches, as well as
  177. the above declarations and the !*COMP switch, of course.
  178. __________ ______ !*R2I [Initially: T] switch
  179. T T If T, causes recursion removal if possible, converting recursive
  180. calls on a function into a jump to its start. If this is not
  181. possible, it uses a faster call to its own "internal" entry,
  182. rather than going via the Symbol Table function cell. The effect
  183. in both cases is that tracing this function does not show the
  184. internal or eliminated recursive calls, nor the backtrace
  185. information.
  186. __________ ______ !*NOLINKE [Initially: NIL] switch
  187. T NIL T NIL If T, inhibits use of !*LINKE cmacro. If NIL, "exit" calls on
  188. functions that would then immediately return. For example, the
  189. calls on FOO(x) and FEE(X) in
  190. PROCEDURE DUM(X,Y);
  191. IF X=Y THEN FOO(X) ELSE FEE(X+Y);
  192. can be converted into direct JUMP's to FEE or FOO's entry point.
  193. This is known as a "tail-recursive" call being converted to a
  194. jump. If this happens, there is no indication of the call of DUM
  195. on the backtrace stack if FEE or FOO cause an error.
  196. __________ ______ !*ORD [Initially: NIL] switch
  197. T T If T, forces the compiler to compile arguments in Left-Right
  198. Order, even though more optimal code can be generated.
  199. [??? !*ORD currently has a bug, and may not be fixed for some [??? !*ORD currently has a bug, and may not be fixed for some [??? !*ORD currently has a bug, and may not be fixed for some
  200. time. Thus do NOT depend on evaluation order in argument time. Thus do NOT depend on evaluation order in argument time. Thus do NOT depend on evaluation order in argument
  201. lists ???] lists ???] lists ???] PSL Manual 7 February 1983 Compiler and Loader
  202. section 18.2 page 18.7
  203. __________ ______ !*MODULE [Initially: NIL] switch
  204. Indicates block compilation (a future extension of this
  205. compiler). When implemented, even more function and variable
  206. names are "compiled away".
  207. The following switches control the printing of information during the
  208. compilation process:
  209. __________ ______ !*PWRDS [Initially: NIL] switch
  210. T T If T, causes the compiled size to be printed in the form
  211. *** NAME: base NNN, length MMM
  212. The base is in octal, the length is in current Radix.
  213. [??? more mnemonic name ???] [??? more mnemonic name ???] [??? more mnemonic name ???]
  214. __________ ______ !*PLAP [Initially: NIL] switch
  215. T T If T, causes the printing of the portable cmacros produced by the
  216. the compiler.
  217. Most of this information is printed by the resident LAP, and controlled
  218. by its switches, described below.
  219. 18.2.8. Differences between Compiled and Interpreted Code 18.2.8. Differences between Compiled and Interpreted Code 18.2.8. Differences between Compiled and Interpreted Code
  220. The following just re-iterates some of the points made above and in other
  221. Sections of the manual regarding the "obscure" differences that compilation
  222. introduces.
  223. [??? This needs some careful work, and perhaps some effort to reduce [??? This needs some careful work, and perhaps some effort to reduce [??? This needs some careful work, and perhaps some effort to reduce
  224. the list of differences ???] the list of differences ???] the list of differences ???]
  225. In the process of compilation, many functions are open-coded, and hence
  226. cannot be redefined or traced in the compiled code. Such functions are
  227. noted to be OPEN-CODED in the manual. If called from compiled code, the
  228. call on an open-compiled function is replaced by a series of online
  229. instructions. Most of these functions have some sort of indicator on their
  230. property lists: 'OPEN, 'ANYREG, 'CMACRO, 'COMPFN, etc. For example: SETQ,
  231. CAR, CDR, COND, WPLUS2, MAP functions, PROG, PROGN, etc. Also note that
  232. _____ _____ _____ macro macro some functions are defined as macros, which convert to some other form
  233. (such as PROG), which itself might compile open.
  234. Some optimizations are performed that cause inaccessible or redundant
  235. code to be removed, e.g. 0*foo(x) could cause foo(x) not to be called. Compiler and Loader 7 February 1983 PSL Manual
  236. page 18.8 section 18.2
  237. _____ ______ _____ ______ _____ ______ Fluid global Fluid global Unless variables are declared (or detected) to be Fluid or global, they
  238. _____ _____ _____ local local are compiled as local variables. This causes their names to disappear, and
  239. so are not visible on the Binding Stack. Further more, these variables are
  240. NOT available to functions called in the dynamic scope of the function
  241. containing their binding.
  242. _____ _____ _____ _____ _____ _____ _____ _____ _____ macro fexpr nexpr macro fexpr nexpr Since compiled calls on macros, fexprs and nexprs are different from the
  243. ____ ____ ____ expr expr default exprs, these functions must be declared (or defined) before
  244. _____ _____ _____ _____ _____ _____ fexpr nexpr fexpr nexpr compiling the code that uses them. While fexprs and nexprs may
  245. _____ _____ _____ macro macro subsequently be redefined (as new functions of same type), macros are
  246. executed by the compiler to get the replacement form, which is then
  247. compiled. The interpreter of course picks up the most recent definition of
  248. ANY function, and so functions can switch type as well as body.
  249. [??? If we expand macros at PUTD time, then this difference will go [??? If we expand macros at PUTD time, then this difference will go [??? If we expand macros at PUTD time, then this difference will go
  250. away. ???] away. ???] away. ???]
  251. As noted above, the !*R2I, !*NOLINKE and !*MODULE switches cause certain
  252. functions to call other functions (or themselves usually) by a faster route
  253. (JUMP or internal call). This means that the recursion or call may not be
  254. visible during tracing or backtrace.
  255. 18.2.9. Compiler Errors 18.2.9. Compiler Errors 18.2.9. Compiler Errors
  256. A number of compiler errors are listed below with possible explanations
  257. of the error.
  258. *** Function form converted to APPLY
  259. Car Car This message indicates that the Car of a form is either
  260. a. Non-atomic,
  261. b. a local variable, or
  262. c. a global or fluid variable.
  263. The compiler converts (F X1 X2 ...), where F is one of the above, to (APPLY
  264. F (LIST X1 X2 ...)).
  265. *** NAME already SYSLISP non-local
  266. This indicates that NAME is either a WVAR or WARRAY in SYSLISP mode, but is
  267. being used as a local variable in LISP mode. No special action is taken.
  268. *** WVAR NAME used as local
  269. This indicates that NAME is a WVAR, but is being used as a bound variable
  270. in SYSLISP mode. The variable is treated as an an anonymous local variable
  271. within the scope of its binding. PSL Manual 7 February 1983 Compiler and Loader
  272. section 18.2 page 18.9
  273. *** NAME already SYSLISP non-local
  274. This indicates that a variable was previously declared as a SYSLISP WVAR or
  275. WARRAY and is now being used as a LISP fluid or global. No special action
  276. is taken.
  277. *** NAME already LISP non-local
  278. This indicates that a variable was previously declared as a LISP fluid or
  279. global and is now being used as a SYSLISP WVAR or WARRAY. No special
  280. action is taken.
  281. *** Undefined symbol NAME in Syslisp, treated as WVAR
  282. A variable was encountered in SYSLISP mode which is not local nor a WVAR or
  283. WARRAY. The compiler declares it a WVAR. This is an error, all WVARs
  284. should be explicitly declared.
  285. *** NAME declared fluid
  286. A variable was encountered in LISP mode which is not local nor a previously
  287. declared fluid or global. The compiler declares it fluid. This is
  288. sometimes an error, if the variable was used strictly locally in an earlier
  289. function definition, but was intended to be bound non-locally. All fluids
  290. should be declared before being used.
  291. 18.3. The Loader 18.3. The Loader 18.3. The Loader
  292. [??? update ???] [??? update ???] [??? update ???]
  293. Currently, PSL on the DEC-20 provides a simple LISP assembler, LAP. This
  294. is modeled after the original LISP 1.6 LAP, although completely
  295. reimplemented to take advantage of PSL constructs, and to support the
  296. additional requirements of SYSLISP. In the process of implementing the VAX
  297. LAP and developing the LAP-to-ASM translator required to bootstrap PSL onto
  298. the next machine (Apollo MC68000), a much more table-driven form of LAP was
  299. designed to make all LAP's, LAP-to-ASM's and FASL's (fast loaders,
  300. sometimes called FAP) easier to maintain. This is now in use on the VAX
  301. and being used to implement Apollo PSL.
  302. [??? FASL now works ???] [??? FASL now works ???] [??? FASL now works ???]
  303. Until that is complete, we will briefly describe the available functions,
  304. and give a sample of current and future LAP; this Section will be
  305. completely rewritten in the next revision. LAP is currently a full two
  306. pass assembler; on the VAX and Apollo it also includes a pass to optimize
  307. long and short jumps. Compiler and Loader 7 February 1983 PSL Manual
  308. page 18.10 section 18.3
  309. LAP LAP ____ ____ ____ _______ ____ (LAP CODE:list): code-pointer expr
  310. ____ CODE is a list of legal LAP forms, including:
  311. a. Machine specific Mnemonics (using opcode-names from the
  312. assembler on the DEC-20, VAX or Apollo).
  313. b. Compiler cmacros (which expand in a machine specific way).
  314. These can be thought of as "generic" or LISP-oriented
  315. instructions. See the next Section on the Compiler details, and
  316. list of legal cmacros.
  317. c. LAP pseudo instructions, to declare entry points, indicate data
  318. and constants, etc.
  319. The first pass of LAP converts mnemonics into LISP integers, doing as
  320. much of the assembly as possible, allocating labels and constants. The
  321. second (and third?) pass fills in labels and completes the assembly,
  322. depositing code into the next available locations in BPS, or creating FASL
  323. or LAP files.
  324. [??? What is BPS (binary program space) ???] [??? What is BPS (binary program space) ???] [??? What is BPS (binary program space) ???]
  325. 18.3.1. Legal LAP Format and Pseudos 18.3.1. Legal LAP Format and Pseudos 18.3.1. Legal LAP Format and Pseudos
  326. [??? Describe LAP format in detail ???] [??? Describe LAP format in detail ???] [??? Describe LAP format in detail ???]
  327. 18.3.2. Examples of LAP for DEC-20, VAX and Apollo 18.3.2. Examples of LAP for DEC-20, VAX and Apollo 18.3.2. Examples of LAP for DEC-20, VAX and Apollo
  328. The following is a piece of VAX specific LAP, using the current "new"
  329. format. Apart from the VAX mnemonics, notice the extra tags around the
  330. register names, and the symbols to indicate addressing modes (essentially
  331. PREFIX syntax rather then INFIX @ etc.). This is from PV:APPLY-LAP.RED.
  332. Note they are almost ENTIRELY written in cmacros, to aid in re-coding for
  333. the next machine. PSL Manual 7 February 1983 Compiler and Loader
  334. section 18.3 page 18.11
  335. lap '((!*entry FastApply expr 0)
  336. %. Apply with arguments loaded
  337. % Called with arguments in the registers and functional form in t1
  338. (!*FIELD (reg t2) (reg t1)
  339. (WConst TagStartingBit) (WConst TagBitLength))
  340. (!*FIELD (reg t1) (reg t1)
  341. (WConst InfStartingBit) (WConst InfBitLength))
  342. (!*JUMPNOTEQ (Label NotAnID) (reg t2) (WConst ID))
  343. (!*WTIMES2 (reg t1) (WConst AddressingUnitsPerFunctionCell))
  344. (!*JUMP (MEMORY (reg t1) (WArray SymFnc)))
  345. NotAnID
  346. (!*JUMPNOTEQ (Label NotACodePointer) (reg t2) (WConst CODE))
  347. (!*JUMP (MEMORY (reg t1) (WConst 0)))
  348. NotACodePointer
  349. (!*JUMPNOTEQ (Label IllegalFunctionalForm) (reg t2) (WConst
  350. (!*MOVE (MEMORY (reg t1) (WConst 0)) (reg t2))
  351. % CAR with pair already unta
  352. (!*JUMPNOTEQ (Label IllegalFunctionalForm) (reg t2) (QUOTE L
  353. (!*MOVE (reg t1) (reg t2)) % put lambda form in t2
  354. (!*PUSH (QUOTE NIL)) % align stack
  355. (!*JCALL FastLambdaApply)
  356. IllegalFunctionalForm
  357. (!*MOVE (QUOTE "Illegal functional form in Apply") (reg 1))
  358. (!*MOVE (reg t1) (reg 2))
  359. (!*CALL List2)
  360. (!*JCALL StdError)
  361. );
  362. lap '((!*entry UndefinedFunction expr 0)
  363. %. Error Handler for non code
  364. % Called by JSB
  365. %
  366. (subl3 (immediate (plus2 (WArray SymFnc) 6))
  367. (autoincrement (reg st))
  368. (reg t1))
  369. (divl2 6 (reg t1))
  370. (!*MKITEM (reg t1) (WConst ID))
  371. (!*MOVE (reg t1) (reg 2))
  372. (!*MOVE (QUOTE "Undefined function %r called from compiled c
  373. (reg 1))
  374. (!*CALL BldMsg)
  375. (!*JCALL StdError)
  376. );
  377. The following is a piece of Apollo specific LAP, using the current NEW
  378. format. Apart from the MC68000 mnemonics, notice the extra tags around the
  379. register names, and the symbols to indicate addressing modes (essentially
  380. PREFIX syntax rather then INFIX @ etc.). This is from P68:M68K-USEFUL-
  381. LAP.RED. Compiler and Loader 7 February 1983 PSL Manual
  382. page 18.12 section 18.3
  383. % Signed multiply of 32 bits numbers in A1 and A2,
  384. % returns 64 bits in A1 and A2, low in A1 high in A2
  385. % Clobbers D1,D2,D3,D4,D5,D6,D7, no saving
  386. % [Can insert MOVEM!.L D1-D7,-(SP)
  387. % and MOVEM!.L (SP)+,D1-D7]
  388. LAP '((!*entry Mult32 expr 2) % Arguments in A1 and A2
  389. (move!.l (reg a1) (reg d1))
  390. (move!.l (reg a1) (reg d6))
  391. (move!.l (reg a2) (reg d2))
  392. (move!.l (reg a2) (reg d7)) % Need copies
  393. % Now do Unsigned Multiply
  394. (move!.l (reg d1) (reg d3))
  395. (move!.l (reg d1) (reg d4))
  396. (swap (reg d4))
  397. (move!.l (reg d2) (reg d5))
  398. (swap (reg d5)) % Swapped for partial products
  399. (mulu!.w (reg d2) (reg d1)) % partial products (pp1)
  400. (mulu!.w (reg d4) (reg d2)) % pp2
  401. (mulu!.w (reg d5) (reg d3)) % pp3
  402. (mulu!.w (reg d5) (reg d4)) % pp4
  403. (swap (reg d1)) % sum1=pp#2low+pp#1hi
  404. (add (reg d2) (reg d1))
  405. (clr!.l (reg d5))
  406. (addx!.l (reg d5) (reg d4)) % propagate carry
  407. (add (reg d3) (reg d1)) % sum2=sum1+pp#3low
  408. (addx!.l (reg d5) (reg d4)) % carry inot pp#4
  409. (swap (reg d1)) % low order product
  410. (clr (reg d2))
  411. (swap (reg d2))
  412. (clr (reg d3))
  413. (swap (reg d3))
  414. (add!.l (reg d3) (reg d2)) % Sum3=pp2low+pp3Hi
  415. (add!.l (reg d4) (reg d2)) % Sum4=Sum3+pp4
  416. % Now do adjustment
  417. (tst!.l (reg d7)) % Negative
  418. (bpl!.s chkd6) % nope
  419. (sub!.l (reg d6) (reg d2)) % Flip
  420. chkd6
  421. (tst!.l (reg d6)) % Negative
  422. (bpl!.s done) % nope
  423. (sub!.l (reg d7) (reg d2)) % Flip
  424. done
  425. (movea!.l (reg d1) (reg a1)) % low part
  426. (movea!.l (reg d2) (reg a2)) % high part
  427. (rts)); PSL Manual 7 February 1983 Compiler and Loader
  428. section 18.3 page 18.13
  429. 18.3.3. Lap Switches 18.3.3. Lap Switches 18.3.3. Lap Switches
  430. The following switches control the printing of information from LAP and
  431. other optional behavior of LAP:
  432. __________ ______ !*PLAP [Initially: NIL] switch
  433. Causes LAP forms to printed before expansion. Used mainly to see
  434. output of compiler before assembly.
  435. __________ ______ !*PGWD [Initially: NIL] switch
  436. Causes LAP to print the actual DEC-20 mnemonics and corresponding
  437. assembled instruction in octal, displaying OPCODE, REGISTER,
  438. INDIRECT, INDEX and ADDRESS fields.
  439. __________ ______ !*PWRDS [Initially: T] switch
  440. Prints a LAP message of the form
  441. *** NAME: base NNN, length MMM
  442. The base is in octal, the length is in current Radix.
  443. __________ ______ !*SAVECOM [Initially: T] switch
  444. If T, the LAP is deposited in BPS, and the returned Code-Pointer
  445. used to (re)define the procedure associated with the (!*entry
  446. name type n).
  447. __________ ______ !*SAVEDEF [Initially: NIL] switch
  448. If T, and if !*SAVECOM is T, saves any preexisting procedure
  449. definition under '!*SAVEDEF on the property list of the procedure
  450. name, "just in case".
  451. LAP also uses the following indicators on property lists:
  452. 'MC Cmacros and some mnemonics have associated PASS1 expansions in
  453. terms of simpler instructions or operations. The form (mc a1 ...
  454. an) has its associated function applied to (a1 ... an).
  455. For more details, see "P20:LAP.RED". Compiler and Loader 7 February 1983 PSL Manual
  456. page 18.14 section 18.4
  457. 18.4. Structure and Customization of the Compiler 18.4. Structure and Customization of the Compiler 18.4. Structure and Customization of the Compiler
  458. The following is a brief summary of the compiler structure and model.
  459. The purpose of this Section is to aid the user to add new compilation
  460. forms, and to understand the task of bootstrapping a new version of PSL.
  461. The original paper on the Portable LISP Compiler [Griss 81] has complete
  462. details on the original version of the compiler, and should be read in
  463. conjunction with this Section. It might be useful to also examine the
  464. paper on recent work on the compiler [Griss 82].
  465. [??? This needs a LOT of work ???] [??? This needs a LOT of work ???] [??? This needs a LOT of work ???]
  466. The compiler is basically three-pass:
  467. ______ ______ ______ macros macros a. The first pass expands ordinary macros, and compiler specific
  468. cmacros. It also uses some special purpose 'PA1REFORM and
  469. 'PA1FN functions on the property lists of certain functions to
  470. produce a simpler and more explicit LISP for the next pass.
  471. Variables and constants, x, are explicitly tagged as (FLUID x),
  472. (GLOBAL x), (QUOTE x), (WCONST x), etc.
  473. b. The second pass recursively compiles the code, using 'COMPFN's
  474. to handle special cases, and the recursive function !&COMPILE
  475. for the general case. In general, code is compiled to cause
  476. function arguments to be loaded into R1...Rn in order, a CALL to
  477. the function to be made, and the returned value to appear in R1.
  478. Temporaries and function arguments to be reused later are saved
  479. on the stack. The compiler allocates a single FRAME for the
  480. maximum stack space that might be needed, and then trims it down
  481. in the third pass. PSL requires registers R1 ... R15, though
  482. not all need be "REAL registers"; the extra are simulated as
  483. memory locations. Special cases avoid a lot of LOAD/STORES to
  484. move arguments around. The compiled code is emitted as a
  485. sequence of abstract LISP machine cmacros. The current set of
  486. cmacros is described below.
  487. c. The third pass scans the list of cmacros for patterns, removing
  488. LOADs and STOREs, redundant JUMP's and LABEL's, compressings the
  489. stack frame, and possibly mapping temporaries stored on the
  490. stack into any of the REAL registers that would otherwise be
  491. unused. This optimized cmacro list is then passed to LAP.
  492. 18.5. First PASS of Compiler 18.5. First PASS of Compiler 18.5. First PASS of Compiler PSL Manual 7 February 1983 Compiler and Loader
  493. section 18.5 page 18.15
  494. 18.5.1. Tagging Information 18.5.1. Tagging Information 18.5.1. Tagging Information
  495. This affects many parts of the compiler. The basic idea is that all
  496. information is to be tagged. These tags fit in three categories: variable
  497. tags, location (register and frame) tags, and constant tags. Tags used for
  498. variables must be flagged 'VAR; tags for constants must be flagged 'CONST.
  499. Currently, the register tag is REG and the frame tag is FRAME. Frame
  500. locations are always positive integers.
  501. These tags are used everywhere; thus, register 1 is always described by
  502. (REG 1) in both emitted cmacros and internally in the register list REGS.
  503. Pass 1 tags all variable references with a source to source transformation
  504. of the variables (suitably obscure names must be used for these tags to
  505. prevent conflicts with named functions).
  506. The purpose behind this tagging is to make the compiler easier to work
  507. with in adding new features; new notions of registers, constants, and
  508. variables can all be accommodated through new tags. Also, the components
  509. of the cmacros are more clearly identified for pass 3.
  510. 18.5.2. Source to Source Transformations 18.5.2. Source to Source Transformations 18.5.2. Source to Source Transformations
  511. A PA1REFORMFN has been provided to augment PA1FN's. The only difference
  512. between these functions is that the PA1REFORM function is passed code which
  513. has already been through PASS1. This was previously done by calling pass 1
  514. within a PA1FN.
  515. 18.6. Second PASS - Basic Code Generation 18.6. Second PASS - Basic Code Generation 18.6. Second PASS - Basic Code Generation
  516. 18.6.1. The Cmacros 18.6.1. The Cmacros 18.6.1. The Cmacros
  517. The compiler second pass compiles the input LISP into a series of
  518. abstract machine instructions, called cmacros. These are instructions for
  519. a LISP-oriented Register machine.
  520. ___ _______ ______ _______ The current DEC-20 cmacros
  521. Definitions of arguments
  522. reg: (REG n) n = 1,2,... MAXNARGS
  523. var: frame | (GLOBAL name) | (FLUID name)
  524. frame: (FRAME n) n = 0,1,2, ..
  525. const: (QUOTE value) | (WCONST value)
  526. label: (LABEL symbol)
  527. regn: reg | NIL | frame
  528. regf: reg | frame
  529. loc: reg | var | const Compiler and Loader 7 February 1983 PSL Manual
  530. page 18.16 section 18.6
  531. anyreg: (CAR anyreg) | (CDR anyreg) | loc
  532. Basic Cmacros for LISP and SYSLISP
  533. (!*ALLOC nframe)
  534. (!*DEALLOC nframe)
  535. (!*ENTRY fname ftype nargs)
  536. (!*EXIT nframe)
  537. (!*FREERSTR (NONLOCALVARS f1 f2 ...))
  538. (!*JUMP label)
  539. (!*JUMPxx label loc loc')
  540. where xx = ATOM, EQ, NOTEQ, NOTTYPE, PAIRP, TYPE
  541. (!*JUMPON lower upper (label-1 ... Label-n))
  542. (!*LINK fname ftype nargs)
  543. (!*LINKE nframe fn type nargs)
  544. (!*LINKF nargs reg) where reg contains the function name,
  545. nargs an integer
  546. (!*LINKEF nframe nargs reg) %/ ?
  547. (!*LBL label)
  548. (!*LAMBIND (REGISTERS reg1 reg2 ...) (NONLOCALVARS f1 f2 ...))
  549. where f1, f2, ... = (FLUID name )
  550. No frame location will be allocated (depends on switch)
  551. (!*LOAD reg anyreg)
  552. (!*PROGBIND (NONLOCALVARS f1 f2 ...))
  553. (!*PUSH reg)
  554. (!*RPLACA regf loc)
  555. (!*RPLACD regf loc)
  556. (!*STORE regn var) | (!*STORE regn reg)
  557. SYSLISP oriented Cmacros
  558. (!*ADDMEM loc)
  559. (!*ADJSP ?)
  560. (!*DECMEM loc)
  561. (!*INCMEM loc)
  562. (!*INTINF loc)
  563. (!*JUMPWGEQ label loc loc')
  564. (!*JUMPWGREATERP label loc loc')
  565. (!*JUMPWITHIN label loc loc')
  566. (!*JUMPWLEQ label loc loc')
  567. (!*JUMPWLESSP label loc loc')
  568. (!*MKITEM loc loc')
  569. (!*MPYMEM loc loc')
  570. (!*NEGMEM loc)
  571. (!*SUBMEM loc loc')
  572. (!*WAND loc loc')
  573. (!*WDIFFERENCE loc loc')
  574. (!*WMINUS loc)
  575. (!*WNOT loc)
  576. (!*WOR loc loc')
  577. (!*WPLUS2 loc loc')
  578. (!*WSHIFT loc loc')
  579. (!*WTIMES2 loc loc') PSL Manual 7 February 1983 Compiler and Loader
  580. section 18.6 page 18.17
  581. (!*WXOR loc loc')
  582. _____ _______ 68000 Cmacros
  583. Basic LISP and SYSLISP Cmacros
  584. (!*ALLOC nframe)
  585. (!*CALL fname)
  586. (!*DEALLOC nframe)
  587. (!*ENTRY fname ftype nargs)
  588. (!*EXIT nframe)
  589. (!*JCALL fname)
  590. (!*JUMP label)
  591. (!*JUMPEQ label loc loc')
  592. (!*JUMPINTYPE label type)
  593. (!*JUMPNOTEQ label loc loc')
  594. (!*JUMPNOTINTYPE label loc type)
  595. (!*JUMPNOTTYPE label loc type)
  596. (!*JUMPTYPE label loc type)
  597. (!*LAMBIND label loc loc')
  598. (!*LBL label)
  599. (!*LINK fname ftype nargs)
  600. (!*LINKE fname ftype nargs nframe)
  601. (!*MOVE loc loc')
  602. (!*PROGBIND label loc loc')
  603. (!*PUSH loc)
  604. SYSLISP specific Cmacros
  605. (!*APOLLOCALL label loc loc')
  606. (!*ASHIFT loc loc')
  607. (!*FIELD loc loc')
  608. (!*FOREIGNLINK loc loc')
  609. (!*INF loc loc')
  610. (!*JUMPON loc loc')
  611. (!*JUMPWGEQ loc loc')
  612. (!*JUMPWGREATERP loc loc')
  613. (!*JUMPWITHIN loc loc')
  614. (!*JUMPWLEQ loc loc')
  615. (!*JUMPWLESSP loc loc')
  616. (!*LOC loc loc')
  617. (!*MKITEM loc loc')
  618. (!*PUTFIELD loc loc')
  619. (!*PUTINF loc loc')
  620. (!*PUTTAG loc loc')
  621. (!*SIGNEDFIELD loc loc')
  622. (!*TAG loc loc')
  623. (!*WAND loc loc')
  624. (!*WDIFFERENCE loc loc')
  625. (!*WMINUS loc loc')
  626. (!*WNOT loc loc')
  627. (!*WOR loc loc') Compiler and Loader 7 February 1983 PSL Manual
  628. page 18.18 section 18.6
  629. (!*WPLUS2 loc loc')
  630. (!*WSHIFT loc loc')
  631. (!*WTIMES2 loc loc')
  632. (!*WXOR loc loc')
  633. 18.6.2. Classes of Functions 18.6.2. Classes of Functions 18.6.2. Classes of Functions
  634. The compiler groups functions into four basic classes:
  635. a. ANYREG functions. No side effects and can be done in a single
  636. register. Passed directly to CMACROs. Viewed as a form of
  637. "extended addressing" mode.
  638. b. Specially compiled or "OPEN" functions. These are functions
  639. have a special compiling function stored under a 'COMPFN
  640. indicator. While many of these functions are specially coded,
  641. many are written with the aid of supporting patterns; these are
  642. called 'OPENFN or 'OPENTST patterns. Some OPEN functions alter
  643. registers which are in use, allocate new frames or obtain unused
  644. registers. These open functions also include open compilation
  645. of tests.
  646. c. Built-in or 'stable' functions. These functions are called in
  647. the standard fashion by the compiler, but they have properties
  648. which are useful to the compiler and are assumed to always hold.
  649. Currently, a function may be flagged as NOSIDEEFFECT and have
  650. the property DESTROYS, which contains a list of registers
  651. destroyed by the function.
  652. d. All other functions are assumed to be totally random, destroying
  653. every register and causing side effects.
  654. [??? Mark non-random functions of various levels elsewhere ???] [??? Mark non-random functions of various levels elsewhere ???] [??? Mark non-random functions of various levels elsewhere ???]
  655. The most important of these categories is the OPEN function. It is hoped
  656. that improved OPEN functions will eliminate the need for temporary
  657. registers to be allocated by the assembler. Most OPEN functions emit
  658. cmacros especially tailored for each function.
  659. 18.6.3. Open Functions 18.6.3. Open Functions 18.6.3. Open Functions
  660. [??? Explain how to CODE them ???] [??? Explain how to CODE them ???] [??? Explain how to CODE them ???]
  661. There are 3 basic kinds of open function:
  662. a. Test: the destination is a LABEL. PSL Manual 7 February 1983 Compiler and Loader
  663. section 18.6 page 18.19
  664. b. Value: the result is to be placed in a particular register.
  665. c. Effect: the result is a side effect, and no destination is
  666. needed.
  667. Note that an EFFECT open function does not have a destination. It is not
  668. really a separate class of function, just a separate usage. Example:
  669. (PROGN (SETQ X 0) ... )
  670. - the SETQ is for effect only - could be implemented with a "clear"
  671. instruction.
  672. (FOO (SETQ X 0) ... )
  673. - here the 0 is also placed in a register (the destination register).
  674. The use of OPENTST is also derived from context: in
  675. (COND ((EQ A B) ...))
  676. - EQ is interpreted as a test.
  677. (RETURN (EQ A B))
  678. , though, must have a value. It should be noted that a pseudo
  679. source-source transformation occurs if an OPENTST is called for value:
  680. (RETURN (EQ A B)) ->
  681. (RETURN (COND ((EQ A B) T) (T NIL)))
  682. An OPENTST function always returns T/NIL if called for value. No separate
  683. handling for non test cases is needed (as opposed to the effect/value cases
  684. for normal OPEN funs in which two separate expansions can be supplied)
  685. Also, there are 3 basic issues encountered in generating the code:
  686. a. Bringing arguments into registers as needed.
  687. b. Emitting the actual code.
  688. c. Updating the final register contents.
  689. Initially, the arguments to an open function are removed of all but
  690. ANYREG functions. Thus, these arguments fall into four classes:
  691. a. Registers
  692. b. Memory locations (FLUID, GLOBAL, FRAME, !*MEMORY)
  693. c. Constants
  694. d. ANYREG functions (viewed as extended addressing modes) Compiler and Loader 7 February 1983 PSL Manual
  695. page 18.20 section 18.6
  696. Also, along with the arguments coming in is the destination (register or
  697. label).
  698. The first step is to replace some arguments by registers by emitting
  699. LOAD's. This step can be controlled by a function, called the adjust
  700. function, which emits LOAD's and replaces the corresponding arguments by
  701. registers. Next, cmacros are emitted. These cmacros are selected through
  702. a pattern which defines the format of the particular OPEN function call.
  703. Note that the pattern is matching the locations of the arguments to the
  704. open function. For example, assume that FOO is OPEN, and the call
  705. (FOO 'A (CDR B) C D)
  706. is encountered. Assume also that B is frame 1, C is frame 2, and D was
  707. found in reg 1.
  708. The argument list being matched is thus
  709. ('A (CDR (FRAME 1)) (FRAME 2) (REG 1))
  710. For most purposes, this would be interpreted as (const anyreg mem reg). Of
  711. course, a pattern can use the value of a constant (you might recognize
  712. (!*WPLUS2 1 X) as an increment). Also, the actual register may be
  713. important for register args, especially if one of the args is also the
  714. destination. You would probably emit different code for
  715. (REG 1) := (!*WPLUS2 (REG 2) (REG 3))
  716. than
  717. (REG 1) := (!*WPLUS2 (REG 1) (REG 2))
  718. To avoid a profusion of properties which would be associated with an OPEN
  719. function, two properties of the function name are used to hold all
  720. information associated with OPEN compiling. These properties are OPENFN
  721. and OPENTST.
  722. The OPENFN and OPENTST properties have the following format:
  723. (PATTERN MACRONAME PARAMETERS)
  724. or function name.
  725. The PATTERN field contains either the pattern itself or a pattern name.
  726. __ A pattern name is an id having the PATTERN property. In the following
  727. material, DEST refers to the destination label in an OPENTST and to the
  728. destination register in an OPENFN. If the function is being evaluated for
  729. effect only, DEST is a temporary register which need not be used.
  730. A pattern has the following format: PSL Manual 7 February 1983 Compiler and Loader
  731. section 18.6 page 18.21
  732. (ADJUST_FN
  733. REG_FN
  734. (P1 M11 M12 M13 ..)
  735. (P2 M21 M22 M23 ..)
  736. ...)
  737. The Pi are patterns and Mij are cmacros or pseudo cmacros. ADJUST_FN is a
  738. register adjustment function used to place things in registers as required,
  739. and to factor out basic properties of the function from the pattern. For
  740. example, you almost never could do anything with ANYREG stuff except load
  741. it somewhere (emitting (!*WPLUS2 X (CDR (CAR Y))) directly probably won't
  742. work - you must bring (CDR (CAR Y)) into a reg before further progress can
  743. be made). The most common adjust function is NOANYREG, which replaces
  744. ANYREG stuff with registers. This eliminates the problem of having to test
  745. for ANYREG stuff in the patterns.
  746. Some pattern elements currently supported are:
  747. ANY matches anything
  748. DEST matches the destination register or label
  749. NOTDEST matches any register except the destination
  750. REG matches any register
  751. REGN Any register or 'NIL or a frame location
  752. VAR A LOCAL, GLOBAL, or FLUID variable
  753. MEM A memory address, currently constants + vars (NOT REGS)
  754. ANYREGFN matches an ANYREG function
  755. 'literal matches the literal
  756. (p1 p2 ... pn)
  757. matches a field whose components match p1 ... pn
  758. NOVAL matches only if STATUS > 1; must be the first component of a
  759. pattern, consumes no part of the subject.
  760. The cmacros associated with the patterns fall into two classes: actual
  761. cmacros to be emitted and pseudo cmacros which are interpreted by the
  762. compiler. In either case, the components of the cmacros are handled in the
  763. same fashion. The cmacros contain:
  764. Ai replaced by the ith argument to the OPEN function (after
  765. adjustment)
  766. Ti replaced by a temporary register
  767. Li replaced by a temporary label
  768. Pi replaced by corresponding parameter from OPENFN
  769. DEST replaced by the destination register or label (depending on
  770. OPENFN or OPENTST).
  771. FN replaced by the name of the OPEN function
  772. MAC synonym for P1, by convention a cmacro name
  773. 'literal
  774. (x1 x2 ... )
  775. xi as above, forms a list Compiler and Loader 7 February 1983 PSL Manual
  776. page 18.22 section 18.6
  777. The pseudo cmacros currently supported are:
  778. !*DESTROY !*DESTROY __ __ ____ ______ (!*DESTROY R1, R2, ...): list cmacro
  779. __ __ Remove any register values from R1 ... RN.
  780. !*DO !*DO ________ ____ ____ ____ ______ (!*DO FUNCTION ARG1 ARG2 ...): list cmacro
  781. ________ Call the FUNCTION.
  782. !*SET !*SET ___ ___ ____ ______ (!*SET REG VAL): list cmacro
  783. ___ ___ Set the value in REG to VAL.
  784. The cmacros which are known to the compiler are
  785. !*LOAD !*LOAD ____ ______ (!*LOAD ): list cmacro
  786. !*STORE !*STORE ____ ______ (!*STORE ): list cmacro
  787. !*JUMP !*JUMP ____ ______ (!*JUMP ): list cmacro
  788. !*LBL !*LBL ____ ______ (!*LBL ): list cmacro
  789. These cmacros have special emit functions which are called as they are
  790. emitted; otherwise the cmacro is directly attached to CODELIST.
  791. 18.7. Third PASS - Optimizations 18.7. Third PASS - Optimizations 18.7. Third PASS - Optimizations
  792. The third pass of the compiler is responsible for doing optimizations,
  793. getting rid of extra labels and jumps, removing redundant code, adjusting
  794. the stack frame to squeeze out "holes" or even reallocating temporaries to
  795. excess registers if no "random" functions are called by this function.
  796. This pass also does "peephole" optimizations (controlled by patterns that
  797. examine the Output CMACRO list for cmacros that can be merged). These
  798. tables can be adjusted by the user. This pass also gathers information on
  799. register usage that may be accumulated to aid block compilation or
  800. recompilation of a set of functions that are NOT redefined, and so can use
  801. information about each other (i.e. become "stable").
  802. The 'OPTFN property is used to associate an optimization function with a
  803. particular CMACRO name. This function looks at the CMACRO arguments and PSL Manual 7 February 1983 Compiler and Loader
  804. section 18.7 page 18.23
  805. some subsequent CMACROs in the code-list, to see if a transformation is
  806. possible. The OPTFN takes a single argument, the code-list in reverse
  807. order starting at the associated CMACRO. The OPTFN can also examine
  808. certain parameters. Currently !*LBL, !*MOVE and !*JUMP have 'OPTFNS. For
  809. example, !&STOPT, associated with !*MOVE, checks if previous CMACRO was
  810. !*ALLOC, and that this !*MOVE moves a register to the slot just allocated.
  811. If so, it converts the !*ALLOC and !*MOVE into a single !*PUSH. Likewise,
  812. !&LBLOPT removes duplicate labels defined at one place, aliasing one with
  813. the other, and so permitting certain JUMP optimizations to take place.
  814. Tags in the cmacros are processed in a final pass through the code. At
  815. this time the compiler can do substitutions using functions attached to
  816. these tags. Currently, (!*FRAMESIZE) is converted to the frame size and
  817. holes are squeezed out (using the FRAME tag) by !&REFORMMACROS.
  818. Transformation functions are attached to tags (or any function) through the
  819. TRANFN property currently.
  820. 18.8. Some Structural Notes on the Compiler 18.8. Some Structural Notes on the Compiler 18.8. Some Structural Notes on the Compiler
  821. [??? This Section is very ROUGH, just to give some additional [??? This Section is very ROUGH, just to give some additional [??? This Section is very ROUGH, just to give some additional
  822. information in interim ???] information in interim ???] information in interim ???]
  823. External variables and properties used by the compiler:
  824. _________ ___ ________ Variables and Switches
  825. __________ ______ !*ERFG [Initially: ] switch
  826. __________ ______ !*INSTALLDESTROY [Initially: NIL] switch
  827. If true, causes the compiler to install the DESTROYS property on
  828. any function compiled which leaves one or more registers
  829. unchanged
  830. __________ ______ !*INT [Initially: T] switch
  831. __________ ______ !*NOFRAMEFLUID [Initially: T] switch
  832. If true, inhibits allocation of frame locations for FLUIDS
  833. __________ ______ !*SHOWDEST [Initially: NIL] switch
  834. If true, compiler prints out which registers a function destroys
  835. unless all are destroyed Compiler and Loader 7 February 1983 PSL Manual
  836. page 18.24 section 18.8
  837. __________ ______ !*SYSLISP [Initially: NIL] switch
  838. Switch compilation mode from default of LISP to SYSLISP. This
  839. affects constant tagging, and in RLISP also causes LISP functions
  840. to be replaced by SYSLISP equivalents. Also, non-locals default
  841. to WVAR's rather than FLUIDs. See Chapter 20.
  842. __________ ______ !*UNSAFEBINDER [Initially: NIL] switch
  843. for Don's BAKER problem...GC may be called in Binder, so regs
  844. cannot be preserved, and Binder called as regular function.
  845. __________ ______ !*USEREGFLUID [Initially: NIL] switch
  846. If true, LAMBIND and PROGBIND cmacros may contain registers as
  847. well as frame locations (through FIXFRM).
  848. _______ Globals:
  849. __________ ______ LASTACTUALREG [Initially: 5] global
  850. The number of the last real register; FIXFRM does not map stack
  851. locations into registers > LASTACTUALREG. Also, temporary
  852. registers are actual registers if possible.
  853. __________ ______ MAXNARGS [Initially: 15] global
  854. Number of registers
  855. __________ ___ _____ Properties and Flags:
  856. CONST A tag property, indicates tags for constants (WCONST and QUOTE)
  857. EXTVAR A tag property, indicates a variable type whose name is
  858. externally known (!$FLUID, !$GLOBAL, !$WVAR)
  859. MEMMOD A cmacro property, indicates in place memory operations. The
  860. first argument to the cmacro is assumed to be the memory location
  861. (var or !*MEMORY)
  862. NOSIDEEFFECT
  863. A function property, used both in dealing with !*ORD and to
  864. determine if the result should be placed in register status
  865. REG A tag property, indicates a register (REG)
  866. TERMINAL A tag property, indicates terminals (leaves) whose arguments are
  867. not tagged items (!$FLUID !$GLOBAL !$WVAR REG LABEL QUOTE WCONST
  868. FRAME !*FRAMESIZE IREG)
  869. TRANSFER A property of cmacros and functions, indicates cmacros &
  870. functions which cause unconditional transfers (!*JUMP !*EXIT
  871. !*LINKE !*LINKEF ERROR) PSL Manual 7 February 1983 Compiler and Loader
  872. section 18.8 page 18.25
  873. VAR A tag property, indicates a variable type (!$LOCAL !$FLUID
  874. !$GLOBAL !$WVAR)
  875. __________ Properties:
  876. ANYREG A function property, non-NIL indicates an ANYREG function
  877. CFNTYPE Used in compiler to relate to Recursion-to-iteration conversion.
  878. DESTROYS A function property, contains a (tagged) list of registers
  879. destroyed by the function
  880. DOFN A function property, contains the name of a compile time
  881. evaluation function for numeric arguments.
  882. EMITFN A cmacro or pseudo cmacro property, contains the name of a
  883. special function for emitting (or executing) the cmacro, such as
  884. !&ATTJMP for !*JUMP.
  885. EXITING A cmacro property, used in FIXLINKS. Contains the name of an
  886. associated exiting cmacro (!*LINK : !*LINKE, !*LINKF : !*LINKEF)
  887. FLIPTST A function property, contains the name of the opposite of a test
  888. function. All open compiled test functions must have one. (EQ :
  889. NOTEQ, ATOM : PAIRP)
  890. GROUPOPS A function property, used in constant folding. Attached to the
  891. three functions of a group, always a list of the three functions
  892. in the order +, -, MINUS. (!*WPLUS2, !*WDIFFERENCE, !*WMINUS :
  893. (!*WPLUS2 !*WDIFFERENCE !*WMINUS))
  894. MATCHFN A property attached to an atom in a pattern. Contains the name
  895. of a boolean function for use in pattern matching.
  896. NEGJMP A cmacro property, contains the inverted test jump cmacro name.
  897. (!*JUMPEQ : !*JUMPNOTEQ, !*JUMPNOTEQ : !*JUMPEQ ...)
  898. ONE A function property, contains the (numeric) value of an identity
  899. associated with the function (!*WPLUS2 : 0, !*WTIMES2 : 1, ...)
  900. PATTERN A property associated with atoms appearing in OPENFN or OPENTST
  901. properties, contains a pattern for open coding of functions.
  902. SUBSTFN A property of atoms found in cmacros which are inside patterns.
  903. Contains a function name; the function value is substituted into
  904. the cmacro as emitted.
  905. ZERO Like ONE, designates a value which acts as a 0 in a ring over *.
  906. (!*WTIMES2 : 0 , !*LOGAND : 0)