11-interp.lpt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. PSL Manual 7 February 1983 The Interpreter
  2. section 11.0 page 11.1
  3. CHAPTER 11 CHAPTER 11 CHAPTER 11
  4. THE INTERPRETER THE INTERPRETER THE INTERPRETER
  5. 11.1. Evaluator Functions Eval and Apply. . . . . . . . 11.1
  6. 11.2. Support Functions for Eval and Apply . . . . . . . 11.5
  7. 11.3. Special Evaluator Functions, Quote, and Function . . . 11.6
  8. 11.4. Support Functions for Macro Evaluation . . . . . . 11.6
  9. 11.1. Evaluator Functions Eval and Apply 11.1. Evaluator Functions Eval and Apply 11.1. Evaluator Functions Eval and Apply
  10. The PSL evaluator uses an identifier's function cell (SYMFNC(id#) which
  11. is directly accessible from kernel functions only) to access the address of
  12. the code for executing the identifier's function definition, as described
  13. in chapter 10. The function cell contains either the entry address of a
  14. compiled function, or the address of a support routine that either signals
  15. an undefined function or calls the lambda interpreter. The PSL model of a
  16. function call is to place the arguments (after treatment appropriate to
  17. function type) in "registers", and then to jump to or call the code in the
  18. function cell.
  19. ____ Expressions which can be legally evaluated are called forms. They are
  20. restricted S-expressions:
  21. ____ __ form ::= id
  22. ________ | constant
  23. __ ____ ____ | (id form ... form)
  24. ___ | (special . any) % Special cases: COND, PROG, etc.
  25. _____ _____ _____ _____ _____ _____ fexpr macro fexpr macro % usually fexprs or macros.
  26. Eval Apply Eval Apply ____ The definitions of Eval and Apply may clarify which expressions are forms.
  27. Eval Apply ContinuableError Eval Apply ContinuableError In Eval, Apply, and the support functions below, ContinuableError is used
  28. ______ to indicate malformed lambda expressions, undefined functions or mismatched
  29. argument numbers; the user is permitted to correct the offending expression
  30. Break Break or to define a missing function inside a Break loop.
  31. Eval Apply Eval Apply The functions Eval and Apply are central to the PSL interpreter. Since
  32. their efficiency is important, some of the support functions they use are
  33. LambdaApply LambdaEvalApply CodeApply LambdaApply LambdaEvalApply CodeApply hand-coded in LAP. The functions LambdaApply, LambdaEvalApply, CodeApply,
  34. CodeEvalApply IDApply1 Eval Apply CodeEvalApply IDApply1 Eval Apply CodeEvalApply, and IDApply1 are support functions for Eval and Apply.
  35. CodeApply CodeEvalApply IDApply1 CodeApply CodeEvalApply IDApply1 CodeApply and CodeEvalApply are coded in LAP. IDApply1 is handled by the
  36. compiler. The Interpreter 7 February 1983 PSL Manual
  37. page 11.2 section 11.1
  38. Eval Eval _ ____ ___ ____ (Eval U:form): any expr
  39. _ The value of the form U is computed. The following is an
  40. approximation of the real code, leaving out some implementation
  41. details. PSL Manual 7 February 1983 The Interpreter
  42. section 11.1 page 11.3
  43. (DE EVAL (U)
  44. (PROG (FN)
  45. (COND
  46. ((IDP U) (RETURN (VALUECELL U))))
  47. % ValueCell returns the contents of Value Cell if ID
  48. % BoundP, else signals unbound error.
  49. (COND ((NOT (PAIRP U)) (RETURN U)))
  50. % This is a "constant" which EVAL's to itself
  51. (COND
  52. ((EQCAR (CAR U) 'LAMBDA)
  53. (RETURN
  54. (LAMBDAEVALAPPLY (CAR U) (CDR U)))))
  55. % LambdaEvalApply applies the lambda- expression Car U
  56. % list containing the evaluation of each argument in C
  57. (COND
  58. ((CODEP (CAR U))
  59. (RETURN (CODEEVALAPPLY (CAR U) (CDR U)))))
  60. % CodeEvalApply applies the function with code-pointer
  61. % to the list containing the evaluation of each argume
  62. % Cdr U.
  63. (COND
  64. ((NOT (IDP (CAR U)))
  65. (RETURN
  66. % permit user to correct U, and reevaluate.
  67. (CONTINUABLEERROR 1101
  68. "Ill-formed expression in EVAL" U))))
  69. (SETQ FN (GETD (CAR U)))
  70. (COND
  71. ((NULL FN)
  72. % user might define missing function and retry
  73. (RETURN
  74. (CONTINUABLEERROR 1001 "Undefined function EVAL
  75. (COND
  76. ((EQ (CAR FN) 'EXPR)
  77. (RETURN
  78. (COND
  79. ((CODEP (CDR FN))
  80. % CodeEvalApply applies the function with
  81. % codepointer Cdr FN to the list containing
  82. % evaluation of each argument in Cdr U.
  83. (CODEEVALAPPLY (CDR FN) (CDR U)))
  84. (T
  85. (LAMBDAEVALAPPLY
  86. (CDR FN) (CDR U)))))))
  87. % LambdaEvalApply applies the lambda-expression Cdr FN The Interpreter 7 February 1983 PSL Manual
  88. page 11.4 section 11.1
  89. % list containing the evaluation of each argument in C
  90. (COND
  91. ((EQ (CAR FN) 'FEXPR)
  92. % IDApply1 applies the fexpr Car U to the list of
  93. % unevaluated arguments.
  94. (RETURN (IDAPPLY1 (CDR U) (CAR U))))
  95. ((EQ (CAR FN) 'MACRO)
  96. % IDApply1 first expands the macro call U and then
  97. % evaluates the result.
  98. (RETURN (EVAL (IDAPPLY1 U (CAR U)))))
  99. ((EQ (CAR FN) 'NEXPR)
  100. % IDApply1 applies the nexpr Car U to the list obt
  101. % by evaluating the arguments in Cdr U.
  102. (RETURN (IDAPPLY1 (EVLIS (CDR U)) (CAR U)))))))
  103. Apply Apply __ __ ________ ____ ____ ____ ___ ____ (Apply FN:{id,function} ARGS:form-list): any expr
  104. Apply Apply Apply allows one to make an indirect function call. It returns
  105. __ ____ the value of FN with actual parameters ARGS. The actual
  106. ____ parameters in ARGS are already in the form required for binding
  107. __ to the formal parameters of FN. PSL permits the application of
  108. _____ ______ _____ _____ ______ _____ _____ ______ _____ macro nexprs fexpr Apply Cdr macro nexprs fexpr Apply Cdr macros, nexprs and fexprs; the effect is the same as (Apply (Cdr
  109. GetD GetD __ ____ (GetD FN)) ARGS); i.e. no fix-up is done to quote arguments, etc.
  110. Apply List Apply List as in some LISPs. A call to Apply using List on the second
  111. Apply List Apply List argument [e.g. (Apply F (List X Y))] is compiled so that the
  112. ____ list is not actually constructed.
  113. The following is an approximation of the real code, leaving out
  114. implementation details. PSL Manual 7 February 1983 The Interpreter
  115. section 11.1 page 11.5
  116. (DE APPLY (FN ARGS)
  117. (PROG (DEFN)
  118. (COND
  119. ((CODEP FN)
  120. % Spread the ARGS into the registers and transfer
  121. % entry point of the function.
  122. (RETURN (CODEAPPLY FN ARGS)))
  123. ((EQCAR FN 'LAMBDA)
  124. % Bind the actual parameters in ARGS to the formal
  125. % parameters of the lambda expression If the two l
  126. % are not of equal length then signal
  127. % (CONTINUABLEERROR 1204
  128. % "Number of parameters do not match"
  129. % (CONS FN ARGS))
  130. (RETURN (LAMBDAAPPLY FN ARGS)))
  131. ((NOT (IDP FN))
  132. (RETURN (CONTINUABLEERROR 1104
  133. "Ill-formed function in APPLY"
  134. (CONS FN ARG))))
  135. ((NULL (SETQ DEFN (GETD FN)))
  136. (RETURN (CONTINUABLEERROR 1004
  137. "Undefined function in Apply"
  138. (CONS FN ARGS))))
  139. (T
  140. % Do EXPR's, NEXPR's, FEXPR's and MACRO's alike, a
  141. % EXPR's
  142. (RETURN (APPLY (CDR DEFN) ARGS))))))
  143. [??? Instead, could check for specific function types in Apply ???] [??? Instead, could check for specific function types in Apply ???] [??? Instead, could check for specific function types in Apply ???]
  144. 11.2. Support Functions for Eval and Apply 11.2. Support Functions for Eval and Apply 11.2. Support Functions for Eval and Apply
  145. EvLis EvLis _ ___ ____ ___ ____ ____ (EvLis U:any-list): any-list expr
  146. EvLis EvLis ____ _ EvLis returns a list of the evaluation of each element of U.
  147. LambdaApply LambdaApply __ ______ _ ___ ____ ___ ____ (LambdaApply FN:lambda, U:any-list): any expr
  148. __ ______ ______ Checks that FN is a legal lambda, binds the formals of the lambda
  149. LBind1 EvProgN LBind1 _ EvProgN using LBind1 to the arguments in U, and then uses EvProgN to
  150. ______ evaluate the forms in the lambda body. Finally the formals are
  151. UnBindN UnBindN unbound, using UnBindN, and the result returned. The Interpreter 7 February 1983 PSL Manual
  152. page 11.6 section 11.2
  153. LambdaEvalApply LambdaEvalApply __ ______ _ ____ ____ ___ ____ (LambdaEvalApply FN:lambda, U:form-list): any expr
  154. LambdaApply EvLis LambdaApply __ EvLis _ Essentially LambdaApply(FN,EvLis(U)), though done more
  155. efficiently.
  156. CodeApply CodeApply __ ____ _______ _ ___ ____ ___ ____ (CodeApply FN:code-pointer, U:any-list): any expr
  157. _ Efficiently spreads the arguments in U into the "registers", and
  158. __ then transfers to the starting address referred to by FN
  159. CodeEvalApply CodeEvalApply __ ____ _______ _ ___ ____ ___ ____ (CodeEvalApply FN:code-pointer, U:any-list): any expr
  160. CodeApply EvLis CodeApply __ EvLis _ Essentially CodeApply(FN,EvLis(U)), though more efficient.
  161. The following entry points are used to get efficient calls on named
  162. functions, and are open compiled.
  163. IdApply0 IdApply0 __ __ ___ ____ (IdApply0 FN:id): any expr
  164. IdApply1 IdApply1 __ ____ __ __ ___ ____ (IdApply1 A1:form, FN:id): any expr
  165. IdApply2 IdApply2 __ ____ __ ____ __ __ ___ ____ (IdApply2 A1:form, A2:form, FN:id): any expr
  166. IdApply3 IdApply3 __ ____ __ ____ __ ____ __ __ ___ ____ (IdApply3 A1:form, A2:form, A3:form, FN:id): any expr
  167. IdApply4 IdApply4 __ ____ __ ____ __ ____ __ ____ __ __ ___ ____ (IdApply4 A1:form, A2:form, A3:form, A4:form, FN:id): any expr
  168. EvProgN EvProgN _ ____ ____ ___ ____ (EvProgN U:form-list): any expr
  169. _ Evaluates each form in U in turn, returning the value of the
  170. ProgN ProgN last. Used for various implied ProgNs.
  171. 11.3. Special Evaluator Functions, Quote, and Function 11.3. Special Evaluator Functions, Quote, and Function 11.3. Special Evaluator Functions, Quote, and Function
  172. Quote Quote _ ___ ___ _____ (Quote U:any): any fexpr
  173. Eval _ Eval Returns U. Thus the argument is not evaluated by Eval. PSL Manual 7 February 1983 The Interpreter
  174. section 11.3 page 11.7
  175. MkQuote MkQuote _ ___ ____ ____ (MkQuote U:any): list expr
  176. MkQuote List MkQuote _ List (MkQuote U) returns (List 'QUOTE U)
  177. Function Function __ ________ ________ _____ (Function FN:function): function fexpr
  178. __ __ The function FN is to be passed to another function. If FN is to
  179. have side effects its free variables must be FLUID or GLOBAL.
  180. Function Quote Function Quote Function is like Quote but its argument may be affected by
  181. compilation.
  182. [??? Add FQUOTE, and make FUNCTION become CLOSURE ???] [??? Add FQUOTE, and make FUNCTION become CLOSURE ???] [??? Add FQUOTE, and make FUNCTION become CLOSURE ???]
  183. Closure Closure See also the discussion of Closure and related functions in Section 10.3.
  184. 11.4. Support Functions for Macro Evaluation 11.4. Support Functions for Macro Evaluation 11.4. Support Functions for Macro Evaluation
  185. Expand Expand _ ____ __ ________ ____ ____ (Expand L:list, FN:function): list expr
  186. __ FN is a defined function of two arguments to be used in the
  187. _____ _____ _____ macro Expand macro Expand ____ expansion of a macro. Expand returns a list in the form:
  188. (FN L[0] (FN L[1] ... (FN L[n-1] L[n]) ... ))
  189. _ "n" is the number of elements in L, L[i] is the i'th element of
  190. _ L.
  191. (DE EXPAND (L FN)
  192. (COND ((NULL (CDR L)) (CAR L))
  193. (T (LIST FN (CAR L) (EXPAND (CDR L) FN)))))
  194. [??? Add RobustExpand (sure!) (document) ???] [??? Add RobustExpand (sure!) (document) ???] [??? Add RobustExpand (sure!) (document) ???]
  195. [??? Add an Evalhook and Apply hook for CMU toplevel (document) ???] [??? Add an Evalhook and Apply hook for CMU toplevel (document) ???] [??? Add an Evalhook and Apply hook for CMU toplevel (document) ???]