[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 35/42: Statically compute offsets for slots of <class> i
From: |
Andy Wingo |
Subject: |
[Guile-commits] 35/42: Statically compute offsets for slots of <class> in Scheme |
Date: |
Sat, 10 Jan 2015 00:03:16 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 9cb2da7be0fd4553f71deb160e89a8f05c5b01af
Author: Andy Wingo <address@hidden>
Date: Fri Jan 9 19:10:51 2015 +0100
Statically compute offsets for slots of <class> in Scheme
* module/oop/goops.scm (macro-fold-left): New helper.
(define-class-index): Define class-index-FOO for each slot FOO.
(fold-<class>-slots): Make the slots list have the marks of the
"visit" macro.
---
module/oop/goops.scm | 69 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 50 insertions(+), 19 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index 19e65e1..ddae623 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -206,31 +206,62 @@
(define (compute-cpl class)
(compute-std-cpl class class-direct-supers))
+(define-syntax macro-fold-left
+ (syntax-rules ()
+ ((_ folder seed ()) seed)
+ ((_ folder seed (head . tail))
+ (macro-fold-left folder (folder head seed) tail))))
+
(define-syntax macro-fold-right
(syntax-rules ()
((_ folder seed ()) seed)
((_ folder seed (head . tail))
(folder head (macro-fold-right folder seed tail)))))
-(define-syntax-rule (fold-<class>-slots fold visit seed)
- (fold visit seed
- ((layout <protected-read-only-slot>)
- (flags <hidden-slot>)
- (self <self-slot>)
- (instance-finalizer <hidden-slot>)
- (print)
- (name <protected-hidden-slot>)
- (reserved-0 <hidden-slot>)
- (reserved-1 <hidden-slot>)
- (redefined)
- (direct-supers)
- (direct-slots)
- (direct-subclasses)
- (direct-methods)
- (cpl)
- (slots)
- (getters-n-setters)
- (nfields))))
+(define-syntax fold-<class>-slots
+ (lambda (x)
+ (define slots
+ '((layout <protected-read-only-slot>)
+ (flags <hidden-slot>)
+ (self <self-slot>)
+ (instance-finalizer <hidden-slot>)
+ (print)
+ (name <protected-hidden-slot>)
+ (reserved-0 <hidden-slot>)
+ (reserved-1 <hidden-slot>)
+ (redefined)
+ (direct-supers)
+ (direct-slots)
+ (direct-subclasses)
+ (direct-methods)
+ (cpl)
+ (slots)
+ (getters-n-setters)
+ (nfields)))
+ (syntax-case x ()
+ ((_ fold visit seed)
+ ;; The datum->syntax makes it as if the identifiers in `slots'
+ ;; were present in the initial form, which allows them to be used
+ ;; as (components of) introduced identifiers.
+ #`(fold visit seed #,(datum->syntax #'visit slots))))))
+
+;; Define class-index-layout to 0, class-index-flags to 1, and so on.
+(let-syntax ((define-class-index
+ (lambda (x)
+ (define (id-append ctx a b)
+ (datum->syntax ctx (symbol-append (syntax->datum a)
+ (syntax->datum b))))
+ (define (tail-length tail)
+ (syntax-case tail ()
+ ((begin) 0)
+ ((visit head tail) (1+ (tail-length #'tail)))))
+ (syntax-case x ()
+ ((_ (name . _) tail)
+ #`(begin
+ (define #,(id-append #'name #'class-index- #'name)
+ #,(tail-length #'tail))
+ tail))))))
+ (fold-<class>-slots macro-fold-left define-class-index (begin)))
(define (build-slots-list dslots cpl)
(define (check-cpl slots class-slots)
- [Guile-commits] 02/42: Deprecate C interfaces scm_compute_applicable_methods, scm_find_method, (continued)
- [Guile-commits] 02/42: Deprecate C interfaces scm_compute_applicable_methods, scm_find_method, Andy Wingo, 2015/01/09
- [Guile-commits] 23/42: Remove unused CPP defines naming <method> slots, Andy Wingo, 2015/01/09
- [Guile-commits] 27/42: Remove scm_at_assert_bound_ref, Andy Wingo, 2015/01/09
- [Guile-commits] 28/42: Remove scm_assert_bound, Andy Wingo, 2015/01/09
- [Guile-commits] 30/42: More unused code removal in GOOPS, Andy Wingo, 2015/01/09
- [Guile-commits] 26/42: Remove hashset slots from GOOPS classes, Andy Wingo, 2015/01/09
- [Guile-commits] 29/42: Remove private var_no_applicable_method capture, Andy Wingo, 2015/01/09
- [Guile-commits] 22/42: Remove unused `default-slot-definition-class' <class> slot, Andy Wingo, 2015/01/09
- [Guile-commits] 31/42: Remove unused union scm_t_debug_info, Andy Wingo, 2015/01/09
- [Guile-commits] 33/42: Remove GOOPS random state, Andy Wingo, 2015/01/09
- [Guile-commits] 35/42: Statically compute offsets for slots of <class> in Scheme,
Andy Wingo <=
- [Guile-commits] 24/42: Generics with setters have <applicable-struct-with-setter> layout, Andy Wingo, 2015/01/09
- [Guile-commits] 11/42: Move GOOPS boot to Scheme, Andy Wingo, 2015/01/09
- [Guile-commits] 34/42: Refactor to <class> slot computation, Andy Wingo, 2015/01/09
- [Guile-commits] 42/42: Remove TEST_CHANGE_CLASS, Andy Wingo, 2015/01/09
- [Guile-commits] 41/42: Remove pure-generic?, Andy Wingo, 2015/01/09
- [Guile-commits] 40/42: Goops slot-unbound / slot-missing cleanups, Andy Wingo, 2015/01/09
- [Guile-commits] 38/42: Port method and generic accessors to Scheme, Andy Wingo, 2015/01/09
- [Guile-commits] 39/42: Move slot-ref et al to Scheme, Andy Wingo, 2015/01/09
- [Guile-commits] 37/42: <class> accessors implemented in Scheme, Andy Wingo, 2015/01/09
- [Guile-commits] 32/42: More goops.c cleanups, and fix a security issue, Andy Wingo, 2015/01/09