debug.red 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. COMMENT MODULE DEBUG;
  2. COMMENT TRACE FUNCTIONS;
  3. COMMENT functions defined in REDUCE but not Standard LISP;
  4. SYMBOLIC PROCEDURE LPRI U;
  5. BEGIN
  6. A: IF NULL U THEN RETURN NIL;
  7. PRIN2 CAR U;
  8. PRIN2 " ";
  9. U := CDR U;
  10. GO TO A
  11. END;
  12. SYMBOLIC PROCEDURE LPRIW (U,V);
  13. BEGIN SCALAR X;
  14. U := U . IF V AND ATOM V THEN LIST V ELSE V;
  15. IF OFL!* AND (!*FORT OR NOT !*NAT OR !*DEFN) THEN GO TO C;
  16. TERPRI();
  17. A: LPRI U;
  18. TERPRI();
  19. IF NULL X THEN GO TO B;
  20. WRS CDR X;
  21. RETURN NIL;
  22. B: IF NULL OFL!* THEN RETURN NIL;
  23. C: X := OFL!*;
  24. WRS NIL;
  25. GO TO A
  26. END;
  27. SYMBOLIC PROCEDURE LPRIM U;
  28. !*MSG AND LPRIW("***",U);
  29. SYMBOLIC PROCEDURE LPRIE U;
  30. BEGIN SCALAR X;
  31. IF !*INT THEN GO TO A;
  32. X:= !*DEFN;
  33. !*DEFN := NIL;
  34. A: ERFG!* := T;
  35. LPRIW ("*****",U);
  36. IF NULL !*INT THEN !*DEFN := X
  37. END;
  38. SYMBOLIC PROCEDURE MKQUOTE U;
  39. LIST('QUOTE,U);
  40. SYMBOLIC PROCEDURE REVERSIP U;
  41. BEGIN SCALAR X,Y;
  42. WHILE U DO <<X := CDR U; Y := RPLACD(U,Y); U := X>>;
  43. RETURN Y
  44. END;
  45. COMMENT if we knew how many arguments a function had we could use
  46. EMBED mechanism;
  47. GLOBAL '(TRACEFLAG!* !*COMP !*MODE);
  48. TRACEFLAG!* := T;
  49. SYMBOLIC FEXPR PROCEDURE TRACE L;
  50. BEGIN SCALAR COMP,FN,G1,G2,LST,DEFN;
  51. COMP := !*COMP;
  52. !*COMP := NIL; %we don't want TRACE FEXPR compiled;
  53. WHILE L DO BEGIN
  54. FN := CAR L;
  55. L := CDR L;
  56. G1 := GENSYM(); %trace counter;
  57. G2 := GENSYM(); %used to hold original definition;
  58. DEFN := GETD FN;
  59. IF GET(FN,'TRACE) THEN RETURN LPRIM LIST(FN,"ALREADY TRACED")
  60. ELSE IF NOT DEFN THEN RETURN LPRIM LIST(FN,"UNDEFINED");
  61. LST := FN . LST;
  62. TR!-PUTD(G2,CAR DEFN,CDR DEFN);
  63. REMD FN;
  64. TR!-PUTD(FN,'FEXPR,LIST('LAMBDA,'(!-L),
  65. LIST('TRACE1,'!-L,MKQUOTE G1,
  66. MKQUOTE(CAR DEFN . G2),MKQUOTE FN)));
  67. PUT(FN,'TRACE,G1 . DEFN);
  68. SET(G1,0);
  69. PUT('TRACE,'CNTRS,G1 . GET('TRACE,'CNTRS));
  70. END;
  71. !*COMP := COMP;
  72. RETURN REVERSIP LST
  73. END;
  74. SYMBOLIC PROCEDURE TR!-PUTD(U,V,W);
  75. %PUTD even if U is flagged LOSE;
  76. BEGIN SCALAR BOOL;
  77. IF FLAGP(U,'LOSE) THEN <<BOOL := T; REMFLAG(LIST U,'LOSE)>>;
  78. PUTD(U,V,W);
  79. IF BOOL THEN FLAG(LIST U,'LOSE)
  80. END;
  81. SYMBOLIC PROCEDURE TRACE1(ARGS,CNTR,DEFN,NAME);
  82. BEGIN SCALAR BOOL,COUNT,VAL,X;
  83. SET(CNTR,EVAL CNTR+1); %update counter;
  84. COUNT := EVAL CNTR;
  85. IF TRACEFLAG!*
  86. THEN <<PRIN2 "*** ENTERING ";
  87. IF NOT COUNT=1 THEN <<PRIN2 COUNT; PRINC " ">>;
  88. PRIN2 NAME;
  89. PRIN2 ": ">>;
  90. BOOL := CAR DEFN MEMQ '(FEXPR FSUBR);
  91. IF NULL BOOL THEN ARGS := EVAL('LIST . ARGS);
  92. IF TRACEFLAG!* THEN PRINT ARGS;
  93. VAL :=
  94. IF BOOL THEN EVAL(CDR DEFN . ARGS) ELSE APPLY(CDR DEFN,ARGS);
  95. IF TRACEFLAG!*
  96. THEN <<PRIN2 "*** LEAVING ";
  97. IF NOT COUNT=1 THEN <<PRIN2 COUNT; PRINC " ">>;
  98. PRIN2 NAME;
  99. PRIN2 ": ";
  100. PRINT VAL>>;
  101. SET(CNTR,COUNT-1);
  102. RETURN VAL
  103. END;
  104. SYMBOLIC FEXPR PROCEDURE UNTRACE L;
  105. BEGIN SCALAR COMP,FN,LST,DEFN;
  106. COMP := !*COMP;
  107. !*COMP := NIL;
  108. WHILE L DO BEGIN
  109. FN := CAR L;
  110. L := CDR L;
  111. DEFN := GET(FN,'TRACE);
  112. IF NULL DEFN THEN RETURN LPRIM LIST(FN,"NOT TRACED");
  113. REMD FN;
  114. TR!-PUTD(FN,CADR DEFN,CDDR DEFN);
  115. REMPROP(FN,'TRACE);
  116. LST := FN . LST;
  117. PUT('TRACE,'CNTRS,DELETE(CAR DEFN,GET('TRACE,'CNTRS)))
  118. END;
  119. !*COMP := COMP;
  120. RETURN REVERSIP LST
  121. END;
  122. SYMBOLIC PROCEDURE TR U; TR1(U,'TRACE);
  123. SYMBOLIC PROCEDURE UNTR U; TR1(U,'UNTRACE);
  124. FLUID '(!*NOUUO);
  125. SYMBOLIC PROCEDURE TR1(U,V);
  126. BEGIN SCALAR X;
  127. !*NOUUO := T;
  128. X := EVAL (V . U);
  129. IF NOT !*MODE EQ 'SYMBOLIC THEN <<TERPRI(); PRINT X>> ELSE RETURN X
  130. END;
  131. DEFLIST ('((TR RLIS) (UNTR RLIS)),'STAT);
  132. FLAG('(TR UNTR),'IGNORE);
  133. %PUT('TR,'ARGMODE,'(((ARB!-NO SYMBOLIC) TR . NOVAL)));
  134. %PUT('UNTR,'ARGMODE,'(((ARB!-NO SYMBOLIC) UNTR . NOVAL)));
  135. COMMENT TRACESET FUNCTIONS;
  136. SYMBOLIC PROCEDURE TRSET1(U,V);
  137. FOR EACH X IN U DO
  138. BEGIN DCL Y:SYMBOLIC;
  139. Y := GETD X;
  140. IF NULL Y OR NOT CAR Y MEMQ '(EXPR FEXPR MACRO)
  141. THEN LPRIM LIST(X,"CANNOT BE TRACESET")
  142. ELSE IF V AND FLAGP(X,'TRST)
  143. THEN LPRIM LIST(X,"ALREADY TRACESET")
  144. ELSE IF NULL V AND NOT FLAGP(X,'TRST)
  145. THEN LPRIM LIST(X,"NOT TRACESET")
  146. ELSE <<IF V THEN FLAG(LIST X,'TRST)
  147. ELSE REMFLAG(LIST X,'TRST);
  148. TRSET2(CDR Y,V)>>
  149. END;
  150. SYMBOLIC PROCEDURE TRSET2(U,!*S!*);
  151. IF ATOM U THEN NIL
  152. ELSE IF CAR U EQ 'QUOTE THEN NIL
  153. ELSE IF CAR U EQ 'SETQ
  154. THEN RPLACD(CDR U,
  155. IF !*S!*
  156. THEN LIST SUBLIS(LIST('VBL . CADR U,
  157. 'X . GENSYM(),
  158. 'EXP . CADDR U),
  159. '((LAMBDA
  160. (X)
  161. (PROG
  162. NIL
  163. (SETQ VBL X)
  164. (PRIN2 (QUOTE VBL))
  165. (PRIN2 (QUOTE ! !=! ))
  166. (PRIN2 X)
  167. (TERPRI)
  168. (RETURN X)))
  169. EXP))
  170. ELSE CDADDR U)
  171. ELSE FOR EACH J IN U COLLECT TRSET2(J,!*S!*);
  172. SYMBOLIC PROCEDURE TRST U; TRSET1(U,T);
  173. SYMBOLIC PROCEDURE UNTRST U; TRSET1(U,NIL);
  174. DEFLIST('((TRST RLIS) (UNTRST RLIS)),'STAT);
  175. FLAG('(TRST UNTRST),'IGNORE);
  176. %PUT('TRST,'ARGMODE,'(((ARB!-NO SYMBOLIC) TRST . NOVAL)));
  177. %PUT('UNTRST,'ARGMODE,'(((ARB!-NO SYMBOLIC) UNTRST . NOVAL)));
  178. COMMENT EMBED FUNCTIONS;
  179. SYMBOLIC PROCEDURE EMBFN(U,V,W);
  180. BEGIN SCALAR NNAME,X,Y;
  181. IF !*DEFN THEN OUTDEF LIST('EMBFN,MKQUOTE U,MKQUOTE V,MKQUOTE W);
  182. X := GETD U;
  183. IF NULL X THEN REDERR LIST(U,"NOT DEFINED")
  184. ELSE IF NOT CAR X MEMQ '(FEXPR FSUBR EXPR SUBR)
  185. THEN REDERR LIST(U,"NOT EMBEDDABLE");
  186. NNAME := GENSYM();
  187. Y := NNAME . X . LIST('LAMBDA,V,SUBST(NNAME,U,W));
  188. PUT(U,'EMB,Y);
  189. RETURN MKQUOTE U
  190. END;
  191. SYMBOLIC PROCEDURE EMBED U;
  192. %U is a list of function names;
  193. WHILE U DO
  194. BEGIN SCALAR TYPE,X,Y;
  195. X := CAR U;
  196. U := CDR U;
  197. Y := GET(X,'EMB);
  198. IF NULL Y THEN RETURN LPRIM LIST(X,"NOT EMBEDDED");
  199. PUT(X,'UNEMB,Y);
  200. REMPROP(X,'EMB);
  201. TR!-PUTD(CAR Y,CAADR Y,CDADR Y);
  202. TYPE := IF CAADR Y MEMQ '(FSUBR FEXPR) THEN 'FEXPR ELSE 'EXPR;
  203. TR!-PUTD(X,TYPE,CDDR Y)
  204. END;
  205. SYMBOLIC PROCEDURE UNEMBED U;
  206. WHILE U DO
  207. BEGIN SCALAR X,Y;
  208. X := CAR U;
  209. U := CDR U;
  210. Y := GET(X,'UNEMB);
  211. IF NULL Y THEN RETURN LPRIM LIST(X,"NOT EMBEDDED");
  212. PUT(X,'EMB,Y);
  213. REMPROP(X,'UNEMB);
  214. REMD CAR Y;
  215. TR!-PUTD(X,CAADR Y,CDADR Y)
  216. END;
  217. DEFLIST('((EMBED RLIS) (UNEMBED RLIS)),'STAT);
  218. END;