[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 17/25: slot-ref, slot-set! et al bypass "using-class" va
From: |
Andy Wingo |
Subject: |
[Guile-commits] 17/25: slot-ref, slot-set! et al bypass "using-class" variants |
Date: |
Mon, 19 Jan 2015 10:41:13 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 8969ba9b7208e6e275d0aaa3ab3374571b49130c
Author: Andy Wingo <address@hidden>
Date: Fri Jan 16 12:55:48 2015 +0100
slot-ref, slot-set! et al bypass "using-class" variants
* module/oop/goops.scm (slot-ref, slot-set!, slot-bound?, slot-exists?):
Bypass slot-ref-using-class, slot-set-using-class!, and so on. Those
interfaces are public and have to check that the class is indeed a
class, they should check that the object is an instance of the class,
and so on, whereas if we get the class via class-of we know that the
invariant holds.
---
module/oop/goops.scm | 24 ++++++++++++++++++++----
1 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index 471f168..434d6be 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -895,19 +895,35 @@ followed by its associated value. If @var{l} does not
hold a value for
(define (slot-ref obj slot-name)
"Return the value from @var{obj}'s slot with the nam var{slot_name}."
- (slot-ref-using-class (class-of obj) obj slot-name))
+ (unless (symbol? slot-name)
+ (scm-error 'wrong-type-arg #f "Not a symbol: ~S"
+ (list slot-name) #f))
+ (let* ((class (class-of obj))
+ (val (get-slot-value-using-name class obj slot-name)))
+ (if (unbound? val)
+ (slot-unbound class obj slot-name)
+ val)))
(define (slot-set! obj slot-name value)
"Set the slot named @var{slot_name} of @var{obj} to @var{value}."
- (slot-set-using-class! (class-of obj) obj slot-name value))
+ (unless (symbol? slot-name)
+ (scm-error 'wrong-type-arg #f "Not a symbol: ~S"
+ (list slot-name) #f))
+ (set-slot-value-using-name! (class-of obj) obj slot-name value))
(define (slot-bound? obj slot-name)
"Return the value from @var{obj}'s slot with the nam var{slot_name}."
- (slot-bound-using-class? (class-of obj) obj slot-name))
+ (unless (symbol? slot-name)
+ (scm-error 'wrong-type-arg #f "Not a symbol: ~S"
+ (list slot-name) #f))
+ (not (unbound? (get-slot-value-using-name (class-of obj) obj slot-name))))
(define (slot-exists? obj slot-name)
"Return @code{#t} if @var{obj} has a slot named @var{slot_name}."
- (slot-exists-using-class? (class-of obj) obj slot-name))
+ (unless (symbol? slot-name)
+ (scm-error 'wrong-type-arg #f "Not a symbol: ~S"
+ (list slot-name) #f))
+ (test-slot-existence (class-of obj) obj slot-name))
- [Guile-commits] 05/25: Scheme GOOPS cleanups, (continued)
- [Guile-commits] 05/25: Scheme GOOPS cleanups, Andy Wingo, 2015/01/19
- [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 <=
- [Guile-commits] 18/25: change-object-class refactor, Andy Wingo, 2015/01/19
- [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