1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Introduce <slot> objects in GOOPS

* module/oop/goops.scm (fold-class-slots): Change format to use proper
  slot specifications.
  (fold-slot-slots): Flesh out with all needed slots.
  (<class>): Update cons-layout to deal with new fold-class-slots form.
  Don't create slots; we do that later.
  (is-a?, get-keyword, *unbound, unbound?, %allocate-instance): Move
  definitions up.
  (<slot>, slot?): New definitions.
  (slot-definition-name, slot-definition-allocation)
  (slot-definition-init-keyword, slot-definition-init-form)
  (slot-definition-init-value, slot-definition-init-thunk)
  (slot-definition-options, slot-definition-getter)
  (slot-definition-setter, slot-definition-accessor)
  (slot-definition-slot-ref, slot-definition-slot-set!)
  (slot-definition-index, slot-definition-size): New definitions as
  accessors on <slot> objects.
  (class-slot-definition): Adapt to class-slots change.
  (direct-slot-definition-class, make-slot): New definitions.
  (make): Define a boot version that can allocate <slot> instances.
  (compute-direct-slot-definition)
  (compute-direct-slot-definition-initargs)
  (effective-slot-definition-class, compute-effective-slot-definition):
  New definitions.
  (build-slots-list): Adapt to slots being <slot> objects.
  (compute-get-n-set): New boot definition.
  (allocate-slots): New definition.  Replaces
  compute-getters-n-setters.
  (%compute-layout, %prep-layout): Adapt to changes.
  (make-standard-class): Make <slot> objects for direct-slots, and
  handle the allocate-slots protocol.
  (<foreign-slot>): Inherit from <slot>.
  (get-slot-value-using-name, set-slot-value-using-name!)
  (test-slot-existence): Adapt to using slot definition objects.
  (make-class): Allow slot specs or <slot> objects as the `slots'
  argument.
  (write): New method on <slot>.
  (class-slot-ref, class-slot-set!): Reimplement.
  (compute-slot-accessors, compute-getter-method)
  (compute-setter-method): Adapt to changes.
  (compute-getters-n-setters): Remove.  Yay!
  (compute-get-n-set): Adapt to use effective slot definitions instead
  of the getters-n-setters for #:class / #:each-subclass allocation.
  (%initialize-object): Adapt.
  (initialize): New method for <slot>.  Adapt method for <class>.

* module/oop/goops/active-slot.scm (compute-get-n-set):
* module/oop/goops/composite-slot.scm (compute-propagated-get-n-set):
  Use slot-definition-options to access options of slot.

* test-suite/tests/goops.test ("bad init-thunk"): Fix to be a "pass-if"
  instead of an "expect-fail".
This commit is contained in:
Andy Wingo 2015-01-18 20:53:19 +01:00
parent 26a6aaefac
commit 568174d173
5 changed files with 544 additions and 411 deletions

View file

@ -128,6 +128,7 @@ static SCM class_hashtable;
static SCM class_fluid; static SCM class_fluid;
static SCM class_dynamic_state; static SCM class_dynamic_state;
static SCM class_frame; static SCM class_frame;
static SCM class_keyword;
static SCM class_vm_cont; static SCM class_vm_cont;
static SCM class_bytevector; static SCM class_bytevector;
static SCM class_uvec; static SCM class_uvec;
@ -973,6 +974,7 @@ SCM_DEFINE (scm_sys_goops_early_init, "%goops-early-init", 0, 0, 0,
class_fluid = scm_variable_ref (scm_c_lookup ("<fluid>")); class_fluid = scm_variable_ref (scm_c_lookup ("<fluid>"));
class_dynamic_state = scm_variable_ref (scm_c_lookup ("<dynamic-state>")); class_dynamic_state = scm_variable_ref (scm_c_lookup ("<dynamic-state>"));
class_frame = scm_variable_ref (scm_c_lookup ("<frame>")); class_frame = scm_variable_ref (scm_c_lookup ("<frame>"));
class_keyword = scm_variable_ref (scm_c_lookup ("<keyword>"));
class_vm_cont = scm_variable_ref (scm_c_lookup ("<vm-continuation>")); class_vm_cont = scm_variable_ref (scm_c_lookup ("<vm-continuation>"));
class_bytevector = scm_variable_ref (scm_c_lookup ("<bytevector>")); class_bytevector = scm_variable_ref (scm_c_lookup ("<bytevector>"));
class_uvec = scm_variable_ref (scm_c_lookup ("<uvec>")); class_uvec = scm_variable_ref (scm_c_lookup ("<uvec>"));

File diff suppressed because it is too large Load diff

View file

@ -33,7 +33,7 @@
(define-method (compute-get-n-set (class <active-class>) slot) (define-method (compute-get-n-set (class <active-class>) slot)
(if (eq? (slot-definition-allocation slot) #:active) (if (eq? (slot-definition-allocation slot) #:active)
(let* ((index (slot-ref class 'nfields)) (let* ((index (slot-ref class 'nfields))
(s (cdr slot)) (s (slot-definition-options slot))
(before-ref (get-keyword #:before-slot-ref s #f)) (before-ref (get-keyword #:before-slot-ref s #f))
(after-ref (get-keyword #:after-slot-ref s #f)) (after-ref (get-keyword #:after-slot-ref s #f))
(before-set! (get-keyword #:before-slot-set! s #f)) (before-set! (get-keyword #:before-slot-set! s #f))

View file

@ -1,6 +1,6 @@
;;; installed-scm-file ;;; installed-scm-file
;;;; Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc. ;;;; Copyright (C) 1999, 2000, 2001, 2006, 2015 Free Software Foundation, Inc.
;;;; Copyright (C) 1993-1998 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr> ;;;; Copyright (C) 1993-1998 Erick Gallesio - I3S-CNRS/ESSI <eg@unice.fr>
;;;; ;;;;
;;;; This library is free software; you can redistribute it and/or ;;;; This library is free software; you can redistribute it and/or
@ -53,7 +53,9 @@
(next-method))) (next-method)))
(define (compute-propagated-get-n-set s) (define (compute-propagated-get-n-set s)
(let ((prop (get-keyword #:propagate-to (cdr s) #f)) (let ((prop (get-keyword #:propagate-to
(slot-definition-options s)
#f))
(s-name (slot-definition-name s))) (s-name (slot-definition-name s)))
(if (not prop) (if (not prop)

View file

@ -167,16 +167,15 @@
(eval '(define-class <foo> ()) (current-module)) (eval '(define-class <foo> ()) (current-module))
(eval '(is-a? <foo> <class>) (current-module))) (eval '(is-a? <foo> <class>) (current-module)))
(expect-fail "bad init-thunk" (pass-if "bad init-thunk"
(begin (catch #t
(catch #t (lambda ()
(lambda () (eval '(define-class <foo> ()
(eval '(define-class <foo> () (x #:init-thunk (lambda (x) 1)))
(x #:init-thunk (lambda (x) 1))) (current-module))
(current-module)) #f)
#t) (lambda args
(lambda args #t)))
#f))))
(pass-if "interaction with `struct-ref'" (pass-if "interaction with `struct-ref'"
(eval '(define-class <class-struct> () (eval '(define-class <class-struct> ()