state.scm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees
  3. ; Compiler state, including flags controlling debug data retention.
  4. ; Package and location uids and the location name table should be here
  5. ; as well...
  6. ; Will the use of a fluid variable significantly degrade performance?
  7. (define (new-template-uid)
  8. (let ((uid *template-uid*))
  9. (set! *template-uid* (+ *template-uid* 1))
  10. uid))
  11. (define *template-uid* 5000) ; 1548 in initial system as of 1/22/94
  12. (define (template-uid) *template-uid*)
  13. (define (set-template-uid! uid) (set! *template-uid* uid))
  14. ; These variables really ought to be dynamically scoped, not global.
  15. ; Fix this some day.
  16. (define debug-flag-names '(names maps files source tabulate table))
  17. (define type/debug-flags
  18. (make-record-type 'debug-flags debug-flag-names))
  19. (define make-debug-flags
  20. (record-constructor type/debug-flags debug-flag-names))
  21. (define $debug-flags
  22. (make-fluid (make-debug-flags #t ;proc names
  23. #f ;env maps
  24. #f ;no file names
  25. #f ;no cont source
  26. #f ;no tabulate
  27. (make-table))))
  28. (define (debug-flag-accessor name)
  29. (let ((access (record-accessor type/debug-flags name)))
  30. (lambda () (access (fluid $debug-flags)))))
  31. (define (debug-flag-modifier name)
  32. (let ((modify (record-modifier type/debug-flags name)))
  33. (lambda (new) (modify (fluid $debug-flags) new))))
  34. (define keep-source-code? (debug-flag-accessor 'source))
  35. (define keep-environment-maps? (debug-flag-accessor 'maps))
  36. (define keep-procedure-names? (debug-flag-accessor 'names))
  37. (define keep-file-names? (debug-flag-accessor 'files))
  38. (define tabulate-debug-data? (debug-flag-accessor 'tabulate))
  39. (define debug-data-table (debug-flag-accessor 'table))
  40. ; Kludge for static linker.
  41. (define (with-fresh-compiler-state template-uid-origin thunk)
  42. (let-fluid $debug-flags (make-debug-flags #t ;proc names
  43. #f ;env maps
  44. #f ;no file names
  45. #f ;no cont source
  46. #t ;tabulate ***
  47. (make-table))
  48. (lambda ()
  49. (saving-and-restoring (lambda () *template-uid*)
  50. (lambda (s) (set! *template-uid* s))
  51. template-uid-origin
  52. thunk))))
  53. (define (saving-and-restoring fetch store! other thunk)
  54. (let ((swap (lambda ()
  55. (let ((temp (fetch)))
  56. (store! other)
  57. (set! other temp)))))
  58. (dynamic-wind swap thunk swap)))
  59. ; --------------------
  60. ; Debug-data stuff
  61. ; "Info" means either a debug data record or an integer index into a
  62. ; table of same. An "info" is stored in a reserved place in every
  63. ; template.
  64. (define (debug-data->info debug-data)
  65. (make-immutable! debug-data)
  66. (if (tabulate-debug-data?)
  67. (begin (note-debug-data! debug-data)
  68. (debug-data-uid debug-data))
  69. debug-data))
  70. (define (get-debug-data info) ;info->debug-data
  71. (cond ((debug-data? info) info)
  72. ((integer? info)
  73. (table-ref (debug-data-table) info))
  74. (else #f)))
  75. (define (note-debug-data! dd)
  76. (table-set! (debug-data-table) (debug-data-uid dd) dd))
  77. (define (new-debug-data name parent)
  78. (make-debug-data (new-template-uid) name parent '() '() '()))