active-slot.scm 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ;;; installed-scm-file
  2. ;;;; Copyright (C) 1999, 2001, 2006 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 2.1 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. (name (car slot))
  32. (s (cdr slot))
  33. (env (class-environment class))
  34. (before-ref (get-keyword #:before-slot-ref s #f))
  35. (after-ref (get-keyword #:after-slot-ref s #f))
  36. (before-set! (get-keyword #:before-slot-set! s #f))
  37. (after-set! (get-keyword #:after-slot-set! s #f))
  38. (unbound (make-unbound)))
  39. (slot-set! class 'nfields (+ index 1))
  40. (list (lambda (o)
  41. (if before-ref
  42. (if (before-ref o)
  43. (let ((res (%fast-slot-ref o index)))
  44. (and after-ref (not (eqv? res unbound)) (after-ref o))
  45. res)
  46. (make-unbound))
  47. (let ((res (%fast-slot-ref o index)))
  48. (and after-ref (not (eqv? res unbound)) (after-ref o))
  49. res)))
  50. (lambda (o v)
  51. (if before-set!
  52. (if (before-set! o v)
  53. (begin
  54. (%fast-slot-set! o index v)
  55. (and after-set! (after-set! o v))))
  56. (begin
  57. (%fast-slot-set! o index v)
  58. (and after-set! (after-set! o v)))))))
  59. (next-method)))