active-slot.scm 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ;;; installed-scm-file
  2. ;;;; Copyright (C) 1999, 2001, 2006, 2009, 2015 Free Software Foundation, Inc.
  3. ;;;; Copyright (C) 1993-1998 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 3 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. ;;;;
  19. ;;;;
  20. ;;;; This file was based upon active-slot.stklos from the STk distribution
  21. ;;;; version 4.0.1 by Erick Gallesio <eg@unice.fr>.
  22. ;;;;
  23. (define-module (oop goops active-slot)
  24. :use-module (oop goops internal)
  25. :export (<active-class>))
  26. (define-class <active-class> (<class>))
  27. (define-method (compute-get-n-set (class <active-class>) slot)
  28. (if (eq? (slot-definition-allocation slot) #:active)
  29. (let* ((index (slot-ref class 'nfields))
  30. (s (slot-definition-options slot))
  31. (before-ref (get-keyword #:before-slot-ref s #f))
  32. (after-ref (get-keyword #:after-slot-ref s #f))
  33. (before-set! (get-keyword #:before-slot-set! s #f))
  34. (after-set! (get-keyword #:after-slot-set! s #f))
  35. (unbound *unbound*))
  36. (slot-set! class 'nfields (+ index 1))
  37. (list (lambda (o)
  38. (if before-ref
  39. (if (before-ref o)
  40. (let ((res (struct-ref o index)))
  41. (and after-ref (not (eqv? res unbound)) (after-ref o))
  42. res)
  43. *unbound*)
  44. (let ((res (struct-ref o index)))
  45. (and after-ref (not (eqv? res unbound)) (after-ref o))
  46. res)))
  47. (lambda (o v)
  48. (if before-set!
  49. (if (before-set! o v)
  50. (begin
  51. (struct-set! o index v)
  52. (and after-set! (after-set! o v))))
  53. (begin
  54. (struct-set! o index v)
  55. (and after-set! (after-set! o v)))))))
  56. (next-method)))