stk/STklos/active-slot.stklos

56 lines
2.0 KiB
Plaintext

;;;;
;;;; a c t i v e - s l o t . s t k l o s -- Active slots metaclass
;;;;
;;;; Copyright © 1996-1999 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;;
;;;; Permission to use, copy, modify, distribute,and license this
;;;; software and its documentation for any purpose is hereby granted,
;;;; provided that existing copyright notices are retained in all
;;;; copies and that this notice is included verbatim in any
;;;; distributions. No written agreement, license, or royalty fee is
;;;; required for any of the authorized uses.
;;;; This software is provided ``AS IS'' without express or implied
;;;; warranty.
;;;;
;;;; Author: Erick Gallesio [eg@unice.fr]
;;;; Creation date: 17-Oct-1996 18:16
;;;; Last file update: 3-Sep-1999 20:05 (eg)
(select-module STklos)
(define-class <Active-metaclass> (<class>)
())
(define-method compute-get-n-set ((class <Active-metaclass>) slot)
(if (eq? (get-slot-allocation slot) :active)
(let* ((index (slot-ref class 'nfields))
(name (car slot))
(s (cdr slot))
(env (class-environment class))
(before-ref (make-closure (get-keyword :before-slot-ref s #f) env))
(after-ref (make-closure (get-keyword :after-slot-ref s #f) env))
(before-set! (make-closure (get-keyword :before-slot-set! s #f) env))
(after-set! (make-closure (get-keyword :after-slot-set! s #f) env))
(unbound (make-unbound)))
(slot-set! class 'nfields (+ index 1))
(list (lambda (o)
(if before-ref
(if (before-ref o)
(let ((res (%fast-slot-ref o index)))
(and after-ref (not (eqv? res unbound)) (after-ref o))
res)
(make-unbound))
(let ((res (%fast-slot-ref o index)))
(and after-ref (not (eqv? res unbound)) (after-ref o))
res)))
(lambda (o v)
(if before-set!
(when (before-set! o v)
(%fast-slot-set! o index v)
(and after-set! (after-set! o v)))
(begin
(%fast-slot-set! o index v)
(and after-set! (after-set! o v)))))))
(next-method)))