top.scm 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. ;;; Ported from Scheme 48 1.9. See file COPYING for notices and license.
  2. ;;;
  3. ;;; Port Author: Andrew Whatson
  4. ;;;
  5. ;;; Original Authors: Richard Kelsey, Mike Sperber
  6. ;;;
  7. ;;; scheme48-1.9.2/ps-compiler/front/top.scm
  8. ;;;
  9. ;;; Debugging aids
  10. (define-module (ps-compiler front top)
  11. #:use-module (ice-9 format)
  12. #:use-module (prescheme scheme48)
  13. #:use-module (ps-compiler param)
  14. #:use-module (ps-compiler front jump)
  15. #:use-module (ps-compiler node node)
  16. #:use-module (ps-compiler node node-util)
  17. #:use-module (ps-compiler simp flow-values)
  18. #:use-module (ps-compiler simp remove-cells)
  19. #:use-module (ps-compiler simp simplify)
  20. #:use-module (ps-compiler util util)
  21. #:export (simplify-all
  22. debug-breakpoint
  23. add-checks add-check clear-checks clear-check
  24. add-procs add-proc clear-procs clear-proc))
  25. (define *bad-ids* '())
  26. (define *all-procs?* #f)
  27. (define *checkpoints* '())
  28. (define all-checkpoints
  29. '(node-made
  30. simplify1
  31. protocols
  32. simplify2
  33. node->vector
  34. pre-simplify-proc
  35. envs-added
  36. ))
  37. (define (debug-breakpoint loc id data)
  38. (if (and (memq? loc *checkpoints*)
  39. (or (not id)
  40. *all-procs?*
  41. (memq? id *bad-ids*)))
  42. (breakpoint "~S at ~S is ~S" id loc data)))
  43. (define (add-checks . locs)
  44. (receive (okay wrong)
  45. (partition-list (lambda (l) (memq? l all-checkpoints))
  46. locs)
  47. (set! *checkpoints* (union okay *checkpoints*))
  48. (for-each (lambda (l)
  49. (format #t '"~&~S is not a checkpoint~%" l))
  50. wrong)
  51. *checkpoints*))
  52. (define (clear-checks . locs)
  53. (set! *checkpoints*
  54. (if (null? locs)
  55. '()
  56. (set-difference *checkpoints* locs))))
  57. (define (add-procs . locs)
  58. (if (null? locs)
  59. (set! *all-procs?* #t)
  60. (set! *bad-ids* (union locs *bad-ids*))))
  61. (define (clear-procs . locs)
  62. (cond ((null? locs)
  63. (set! *all-procs?* #f)
  64. (set! *bad-ids* '()))
  65. (else
  66. (set! *bad-ids*
  67. (if (null? locs)
  68. '()
  69. (set-difference *bad-ids* locs))))))
  70. (define add-check add-checks)
  71. (define clear-check clear-checks)
  72. (define add-proc add-procs)
  73. (define clear-proc clear-procs)
  74. ;------------------------------------------------------------------------------
  75. (define *remove-cells?* #f)
  76. (define *flow-values?* #f)
  77. (define (simplify-all node id)
  78. (debug-breakpoint 'node-made id node)
  79. (simplify-node node)
  80. (debug-breakpoint 'simplify1 id node)
  81. (determine-protocols)
  82. (debug-breakpoint 'protocols id node)
  83. (if (integrate-jump-procs! node)
  84. (simplify-node node))
  85. (cond (*remove-cells?*
  86. (remove-cells-from-tree node (make-lambda-list))
  87. (simplify-node node)))
  88. (cond (*flow-values?*
  89. (flow-values node (make-lambda-list))
  90. (simplify-node node)))
  91. (debug-breakpoint 'simplify2 id node)
  92. (values))
  93. (define (determine-protocols)
  94. (walk-lambdas (lambda (l)
  95. (cond ((and (eq? 'proc (lambda-type l))
  96. (node? (node-parent l))
  97. (find-calls l))
  98. => (lambda (calls)
  99. (determine-lambda-protocol l calls)))))))