[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 18/25: change-object-class refactor
From: |
Andy Wingo |
Subject: |
[Guile-commits] 18/25: change-object-class refactor |
Date: |
Mon, 19 Jan 2015 10:41:14 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 5945f3d9a483a369b1e7470d3cb824a18898128b
Author: Andy Wingo <address@hidden>
Date: Fri Jan 16 13:02:31 2015 +0100
change-object-class refactor
* module/oop/goops.scm (change-object-class): Refactor to use slot-ref,
slot-bound?, and slot-set! instead of the using-class? variants.
---
module/oop/goops.scm | 35 ++++++++++++++---------------------
1 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index 434d6be..898964e 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -2659,27 +2659,20 @@ var{initargs}."
(define (change-object-class old-instance old-class new-class)
(let ((new-instance (allocate-instance new-class '())))
;; Initialize the slots of the new instance
- (for-each (lambda (slot)
- (if (and (slot-exists-using-class? old-class old-instance slot)
- (eq? (slot-definition-allocation
- (class-slot-definition old-class slot))
- #:instance)
- (slot-bound-using-class? old-class old-instance slot))
- ;; Slot was present and allocated in old instance; copy it
- (slot-set-using-class!
- new-class
- new-instance
- slot
- (slot-ref-using-class old-class old-instance slot))
- ;; slot was absent; initialize it with its default value
- (let ((init (slot-init-function new-class slot)))
- (if init
- (slot-set-using-class!
- new-class
- new-instance
- slot
- (apply init '()))))))
- (map slot-definition-name (class-slots new-class)))
+ (for-each
+ (lambda (slot)
+ (if (and (slot-exists? old-instance slot)
+ (eq? (slot-definition-allocation
+ (class-slot-definition old-class slot))
+ #:instance)
+ (slot-bound? old-instance slot))
+ ;; Slot was present and allocated in old instance; copy it
+ (slot-set! new-instance slot (slot-ref old-instance slot))
+ ;; slot was absent; initialize it with its default value
+ (let ((init (slot-init-function new-class slot)))
+ (when init
+ (slot-set! new-instance slot (init))))))
+ (map slot-definition-name (class-slots new-class)))
;; Exchange old and new instance in place to keep pointers valid
(%modify-instance old-instance new-instance)
;; Allow class specific updates of instances (which now are swapped)
- [Guile-commits] 07/25: scm_make cleanup, (continued)
- [Guile-commits] 07/25: scm_make cleanup, Andy Wingo, 2015/01/19
- [Guile-commits] 06/25: Add compute-cpl tests, Andy Wingo, 2015/01/19
- [Guile-commits] 09/25: Commenting in goops.scm, Andy Wingo, 2015/01/19
- [Guile-commits] 08/25: Narrative reordering in goops.scm, Andy Wingo, 2015/01/19
- [Guile-commits] 11/25: when and unless for one-armed ifs in goops.scm, Andy Wingo, 2015/01/19
- [Guile-commits] 13/25: Convert emit-linear-dispatch to use match, Andy Wingo, 2015/01/19
- [Guile-commits] 14/25: `match' refactor in goops.scm, Andy Wingo, 2015/01/19
- [Guile-commits] 15/25: GOOPS class slot indices defined as inline values, Andy Wingo, 2015/01/19
- [Guile-commits] 10/25: More GOOPS comments, Andy Wingo, 2015/01/19
- [Guile-commits] 17/25: slot-ref, slot-set! et al bypass "using-class" variants, Andy Wingo, 2015/01/19
- [Guile-commits] 18/25: change-object-class refactor,
Andy Wingo <=
- [Guile-commits] 19/25: GOOPS: Deprecate "using-class" procs like slot-ref-using-class, Andy Wingo, 2015/01/19
- [Guile-commits] 12/25: More GOOPS cleanups, Andy Wingo, 2015/01/19
- [Guile-commits] 20/25: The GOOPS "unbound" value is a unique pair, Andy Wingo, 2015/01/19
- [Guile-commits] 16/25: Manipulate GOOPS vtable flags from Scheme, for speed, Andy Wingo, 2015/01/19
- [Guile-commits] 21/25: Beginnings of <slot> slot definition class, Andy Wingo, 2015/01/19
- [Guile-commits] 23/25: Use a vtable bit to mark <slot> instances, Andy Wingo, 2015/01/19
- [Guile-commits] 24/25: Add allocate-struct, struct-ref, struct-set! instructions, Andy Wingo, 2015/01/19
- [Guile-commits] 25/25: Inline helpers into slot-ref, slot-set!, etc, Andy Wingo, 2015/01/19
- [Guile-commits] 22/25: Introduce <slot> objects in GOOPS, Andy Wingo, 2015/01/19