heap.scm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; Variables shared by various parts of the BIBOP code
  3. (define *max-heap-size* 0)
  4. (define (s48-max-heap-size)
  5. *max-heap-size*)
  6. (define (s48-set-max-heap-size! size)
  7. (set! *max-heap-size* size))
  8. (define *min-heap-size* 0)
  9. (define (s48-min-heap-size)
  10. *min-heap-size*)
  11. ; addresses of the new allocated heap areas
  12. ; <= s48_initialize_heap()
  13. (define *new-small-start-addr* null-address)
  14. (define *new-large-start-addr* null-address)
  15. (define *new-weaks-start-addr* null-address)
  16. (define (s48-get-new-small-start-addr) *new-small-start-addr*)
  17. (define (s48-get-new-large-start-addr) *new-large-start-addr*)
  18. (define (s48-get-new-weaks-start-addr) *new-weaks-start-addr*)
  19. (define (s48-set-new-small-start-addr! addr)
  20. (set! *new-small-start-addr* addr))
  21. (define (s48-set-new-large-start-addr! addr)
  22. (set! *new-large-start-addr* addr))
  23. (define (s48-set-new-weaks-start-addr! addr)
  24. (set! *new-weaks-start-addr* addr))
  25. ;; ** Availability ***************************************************
  26. (define (s48-available? cells)
  27. (>= (s48-available) cells))
  28. (define (bytes-available? bytes)
  29. (>= (s48-available) (bytes->cells bytes)))
  30. ;; ** Initialization *************************************************
  31. ; the bibop-gc doesn't look at these areas at all yet... TODO?!
  32. ;; (initial values for the type-checker)
  33. (define *pure-areas*)
  34. (define *impure-areas*)
  35. (define *pure-sizes*)
  36. (define *impure-sizes*)
  37. (define *pure-area-count* 0)
  38. (define *impure-area-count* 0)
  39. (define (s48-initialize-heap max-heap-size image-start-address image-size)
  40. (address= image-start-address null-address) ; for the type checker
  41. (= image-size 0) ; for the type checker
  42. (set! *max-heap-size* max-heap-size)
  43. (set! *min-heap-size* (* 4 image-size))
  44. (s48-initialize-bibop-heap)
  45. ;; just some silly things for the type-checker...
  46. (set! *pure-areas* (make-vector 0 (integer->address 0)))
  47. (set! *impure-areas* *pure-areas*)
  48. (set! *pure-sizes* (make-vector 0 0))
  49. (set! *impure-sizes* *pure-sizes*))
  50. ;----------------
  51. ; Keeping track of all the areas.
  52. (define (s48-register-static-areas pure-count pure-areas pure-sizes
  53. impure-count impure-areas impure-sizes)
  54. (set! *pure-area-count* pure-count)
  55. (set! *pure-areas* pure-areas)
  56. (set! *pure-sizes* pure-sizes)
  57. (set! *impure-area-count* impure-count)
  58. (set! *impure-areas* impure-areas)
  59. (set! *impure-sizes* impure-sizes))
  60. (define (walk-areas proc areas sizes count)
  61. (let loop ((i 0))
  62. (cond ((>= i count)
  63. #t)
  64. ((proc (vector-ref areas i)
  65. (address+ (vector-ref areas i)
  66. (vector-ref sizes i)))
  67. (loop (+ i 1)))
  68. (else
  69. #f))))
  70. (define (walk-pure-areas proc)
  71. (if (< 0 *pure-area-count*)
  72. (walk-areas proc *pure-areas* *pure-sizes* *pure-area-count*)
  73. #t))
  74. (define (walk-impure-areas proc)
  75. (if (< 0 *impure-area-count*)
  76. (walk-areas proc *impure-areas* *impure-sizes* *impure-area-count*)
  77. #t))