active-slot.scm 2.3 KB

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