symbol.scm 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; The symbol table, which is just a string table full of symbols.
  3. (define *the-symbol-table*)
  4. (define-consing-primitive intern (string->)
  5. (lambda (ignore)
  6. (+ vm-symbol-size
  7. hash-table-entry-size))
  8. (let ((searcher (table-searcher vm-symbol->string
  9. vm-symbol-next
  10. vm-make-symbol)))
  11. (lambda (string key)
  12. (searcher *the-symbol-table* string key)))
  13. return)
  14. ; Using the regular set-...-next! procedures in the cleanup procedure is
  15. ; unfortunate, because they go through the write barrier. Of course, we
  16. ; could disable that for these setters, since the symbol table has to be
  17. ; checked every GC anyway.
  18. ; Copy the table and remove any unreachable symbols.
  19. (let ((cleaner (table-cleaner vm-symbol-next
  20. vm-set-symbol-next!
  21. s48-extant?
  22. s48-trace-value)))
  23. (add-post-gc-cleanup!
  24. (lambda (major? in-trouble?)
  25. (set! *the-symbol-table* (cleaner *the-symbol-table*)))))
  26. ; For the image writer.
  27. (define (s48-symbol-table)
  28. *the-symbol-table*)
  29. ; There is no symbol table in images created by the static linker.
  30. (define (install-symbols!+gc symbol-table)
  31. (if (eq? symbol-table false)
  32. (build-symbol-table+gc)
  33. (set! *the-symbol-table* symbol-table)))
  34. ; Create the symbol table and then add to it all currently-extant symbols.
  35. (define (build-symbol-table+gc)
  36. (set! *the-symbol-table* (make-hash-table+gc))
  37. (let ((symbols (let ((maybe (s48-find-all (enum stob symbol))))
  38. (if (eq? maybe false)
  39. (begin
  40. (s48-collect #t)
  41. (let ((maybe (s48-find-all (enum stob symbol))))
  42. (if (eq? maybe false)
  43. (error "insufficient heap space to build symbol table"))
  44. maybe))
  45. maybe))))
  46. (natural-for-each (lambda (i)
  47. (symbol-table-add! *the-symbol-table*
  48. (vm-vector-ref symbols i)))
  49. (vm-vector-length symbols))))
  50. (define symbol-table-add! (table-adder vm-symbol->string vm-set-symbol-next!))