binding.scm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees, Mike Sperber
  3. ; Bindings: used to store bindings in packages.
  4. ; Representation is type place operator-or-transform-or-#f.
  5. ; PLACE is a unique (to EQ?) value, usually a location.
  6. (define-record-type binding :binding
  7. (really-make-binding type place static)
  8. binding?
  9. (type binding-type set-binding-type!)
  10. (place binding-place set-binding-place!)
  11. (static binding-static set-binding-static!))
  12. (define-record-discloser :binding
  13. (lambda (b)
  14. (list 'binding
  15. (binding-type b)
  16. (binding-place b)
  17. (binding-static b))))
  18. (define (make-binding type place static)
  19. (really-make-binding type place static))
  20. ; Used when updating a package binding.
  21. (define (clobber-binding! binding type place static)
  22. (set-binding-type! binding type)
  23. (if place
  24. (set-binding-place! binding place))
  25. (set-binding-static! binding static))
  26. ; Return a binding that's similar to the given one, but has its type
  27. ; replaced with the given type.
  28. (define (impose-type type binding integrate?)
  29. (if (or (eq? type syntax-type)
  30. (not (binding? binding)))
  31. binding
  32. (make-binding (if (eq? type undeclared-type)
  33. (let ((type (binding-type binding)))
  34. (if (variable-type? type)
  35. (variable-value-type type)
  36. type))
  37. type)
  38. (binding-place binding)
  39. (if integrate?
  40. (binding-static binding)
  41. #f))))
  42. ; Return a binding that's similar to the given one, but has any
  43. ; procedure integration or other unnecesary static information
  44. ; removed. But don't remove static information for macros (or
  45. ; structures, interfaces, etc.)
  46. (define (forget-integration binding)
  47. (if (and (binding-static binding)
  48. (subtype? (binding-type binding) any-values-type))
  49. (make-binding (binding-type binding)
  50. (binding-place binding)
  51. #f)
  52. binding))
  53. ; Do X and Y denote the same thing?
  54. (define (same-denotation? x y)
  55. (or (eq? x y) ; was EQUAL? because of names, now just for nodes
  56. (and (binding? x)
  57. (binding? y)
  58. (eq? (binding-place x)
  59. (binding-place y)))))
  60. ; Special kludge for shadowing and package mutation.
  61. ; Ignore this on first reading. See env/shadow.scm.
  62. (define (maybe-fix-place! binding)
  63. (let ((place (binding-place binding)))
  64. (if (and (location? place)
  65. (vector? (location-id place)))
  66. (set-binding-place! binding (follow-forwarding-pointers place))))
  67. binding)
  68. (define (follow-forwarding-pointers place)
  69. (let ((id (location-id place)))
  70. (if (vector? id)
  71. (follow-forwarding-pointers (vector-ref id 0))
  72. place)))