mini-trace.red 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. %
  2. % MINI-TRACE.RED - Simple trace and BreakFn package
  3. %
  4. % Author: Martin Griss and Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 18 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.INTERP>MINI-TRACE.RED.4, 3-May-82 11:26:12, Edit by BENSON
  12. % Bug fix in BR.PRC, changed VV to MkQuote VV
  13. % Non-Standard Lisp functions used:
  14. % PrintF, ErrorPrintF, BldMsg, EqCar, Atsoc, MkQuote, SubSeq
  15. % -------- Simple TRACE package -----------
  16. fluid '(ArgLst!* % Default names for args in traced code
  17. TrSpace!* % Number spaces to indent
  18. !*NoTrArgs % Control arg-trace
  19. );
  20. CompileTime flag('(TrMakeArgList), 'InternalFunction);
  21. lisp procedure Tr!.Prc(PN, B, A); % Called in place of Traced code
  22. %
  23. % Called by TRACE for proc nam PN, body B, args A;
  24. %
  25. begin scalar K, SvArgs, VV, Numb;
  26. TrSpace!* := TrSpace!* + 1;
  27. Numb := Min(TrSpace!*, 15);
  28. Tab Numb;
  29. PrintF("%p %w:", PN, TrSpace!*);
  30. if not !*NoTrArgs then
  31. << SvArgs := A;
  32. K := 1;
  33. while SvArgs do
  34. << PrintF(" Arg%w:=%p, ", K, car SvArgs);
  35. SvArgs := cdr SvArgs;
  36. K := K + 1 >> >>;
  37. TerPri();
  38. VV := Apply(B, A);
  39. Tab Numb;
  40. PrintF("%p %w:=%p%n", PN, TrSpace!*, VV);
  41. TrSpace!* := TrSpace!* - 1;
  42. return VV
  43. end;
  44. fluid '(!*Comp !*RedefMSG PromptString!*);
  45. lisp procedure Tr!.1 Nam; % Called To Trace a single function
  46. begin scalar PN, X, Y, Bod, Args, N, OldIn, OldPrompt, !*Comp, !*RedefMSG;
  47. if not (Y:=GetD Nam) then
  48. << ErrorPrintF("*** %r is not a defined function and cannot be traced",
  49. Nam);
  50. return >>;
  51. PN := GenSym();
  52. PutD(PN, car Y, cdr Y);
  53. put(Nam, 'OldCod, Y . get(Nam, 'OldCod));
  54. if EqCar(cdr Y, 'LAMBDA) then Args := cadr cdr Y else
  55. << OldPrompt := PromptString!*;
  56. PromptString!* := BldMsg("How many arguments for %r?", Nam);
  57. OldIn := RDS NIL;
  58. while not NumberP(N := Read()) or N < 0 or N > 15 do ;
  59. PromptString!* := OldPrompt;
  60. RDS OldIn;
  61. Args := TrMakeArgList N >>;
  62. Bod:= list('LAMBDA, Args,
  63. list('Tr!.prc, MkQuote Nam,
  64. MkQuote PN, 'LIST . Args));
  65. PutD(Nam, car Y, Bod);
  66. put(Nam, 'TraceCode, cdr GetD Nam);
  67. end;
  68. lisp procedure UnTr!.1 Nam;
  69. begin scalar X, Y, !*Comp;
  70. if not IDP Nam or not PairP(X := get(Nam, 'OldCod))
  71. or not PairP(Y := GetD Nam)
  72. or not (cdr Y eq get(Nam, 'TraceCode)) then
  73. << ErrorPrintF("*** %r cannot be untraced", Nam);
  74. return >>;
  75. PutD(Nam, caar X, cdar X);
  76. put(Nam, 'OldCod, cdr X)
  77. end;
  78. macro procedure TR L; %. Trace functions in L
  79. list('EvTR, MkQuote cdr L);
  80. expr procedure EvTR L;
  81. for each X in L do Tr!.1 X;
  82. macro procedure UnTr L; %. Untrace Function in L
  83. list('EvUnTr, MkQuote cdr L);
  84. expr procedure EvUnTr L;
  85. for each X in L do UnTr!.1 X;
  86. lisp procedure TrMakeArgList N; % Get Arglist for N args
  87. cdr Assoc(N, ArgLst!*);
  88. lisp procedure TrClr(); %. Called to setup or fix trace
  89. << TrSpace!* := 0;
  90. !*NoTrArgs := NIL >>;
  91. LoadTime
  92. << ArgLst!* := '((0 . ())
  93. (1 . (X1))
  94. (2 . (X1 X2))
  95. (3 . (X1 X2 X3))
  96. (4 . (X1 X2 X3 X4))
  97. (5 . (X1 X2 X3 X4 X5))
  98. (6 . (X1 X2 X3 X4 X5 X6))
  99. (7 . (X1 X2 X3 X4 X5 X6 X7))
  100. (8 . (X1 X2 X3 X4 X5 X6 X7 X8))
  101. (9 . (X1 X2 X3 X4 X5 X6 X7 X8 X9))
  102. (10 . (X1 X2 X3 X4 X5 X6 X7 X8 X9 X10))
  103. (11 . (X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11))
  104. (12 . (X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12))
  105. (13 . (X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13))
  106. (14 . (X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14))
  107. (15 . (X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15)));
  108. TrSpace!* := 0;
  109. !*NoTrArgs := NIL >>;
  110. Fluid '(ErrorForm!* !*ContinuableError);
  111. lisp procedure Br!.Prc(PN, B, A); % Called in place of "Broken" code
  112. %
  113. % Called by BREAKFN for proc nam PN, body B, args A;
  114. %
  115. begin scalar K, SvArgs, VV, Numb;
  116. TrSpace!* := TrSpace!* + 1;
  117. Numb := Min(TrSpace!*, 15);
  118. Tab Numb;
  119. PrintF("%p %w:", PN, TrSpace!*);
  120. if not !*NoTrArgs then
  121. << SvArgs := A;
  122. K := 1;
  123. while SvArgs do
  124. << PrintF(" Arg%w:=%p, ", K, car SvArgs);
  125. SvArgs := cdr SvArgs;
  126. K := K + 1 >> >>;
  127. TerPri();
  128. ErrorForm!* := NIL;
  129. PrintF(" BREAK before entering %r%n",PN);
  130. !*ContinuableError:=T;
  131. Break();
  132. VV := Apply(B, A);
  133. PrintF(" BREAK after call %r, value %r%n",PN,VV);
  134. ErrorForm!* := MkQuote VV;
  135. !*ContinuableError:=T;
  136. Break();
  137. Tab Numb;
  138. PrintF("%p %w:=%p%n", PN, TrSpace!*, ErrorForm!*);
  139. TrSpace!* := TrSpace!* - 1;
  140. return ErrorForm!*
  141. end;
  142. fluid '(!*Comp PromptString!*);
  143. lisp procedure Br!.1 Nam; % Called To Trace a single function
  144. begin scalar PN, X, Y, Bod, Args, N, OldIn, OldPrompt, !*Comp;
  145. if not (Y:=GetD Nam) then
  146. << ErrorPrintF("*** %r is not a defined function and cannot be BROKEN",
  147. Nam);
  148. return >>;
  149. PN := GenSym();
  150. PutD(PN, car Y, cdr Y);
  151. put(Nam, 'OldCod, Y . get(Nam, 'OldCod));
  152. if EqCar(cdr Y, 'LAMBDA) then Args := cadr cdr Y else
  153. << OldPrompt := PromptString!*;
  154. PromptString!* := BldMsg("How many arguments for %r?", Nam);
  155. OldIn := RDS NIL;
  156. while not NumberP(N := Read()) or N < 0 or N > 15 do ;
  157. PromptString!* := OldPrompt;
  158. RDS OldIn;
  159. Args := TrMakeArgList N >>;
  160. Bod:= list('LAMBDA, Args,
  161. list('Br!.prc, MkQuote Nam,
  162. MkQuote PN, 'LIST . Args));
  163. PutD(Nam, car Y, Bod);
  164. put(Nam, 'BreakCode, cdr GetD Nam);
  165. end;
  166. lisp procedure UnBr!.1 Nam;
  167. begin scalar X, Y, !*Comp;
  168. if not IDP Nam or not PairP(X := get(Nam, 'OldCod))
  169. or not PairP(Y := GetD Nam)
  170. or not (cdr Y eq get(Nam, 'BreakCode)) then
  171. << ErrorPrintF("*** %r cannot be unbroken", Nam);
  172. return >>;
  173. PutD(Nam, caar X, cdar X);
  174. put(Nam, 'OldCod, cdr X)
  175. end;
  176. macro procedure Br L; %. Break functions in L
  177. list('EvBr, MkQuote cdr L);
  178. expr procedure EvBr L;
  179. for each X in L do Br!.1 X;
  180. macro procedure UnBr L; %. Unbreak functions in L
  181. list('EvUnBr, MkQuote cdr L);
  182. expr procedure EvUnBr L;
  183. for each X in L do UnBr!.1 X;
  184. END;