[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 36/88: Statically compute offsets for slots of <class> i
From: |
Andy Wingo |
Subject: |
[Guile-commits] 36/88: Statically compute offsets for slots of <class> in Scheme |
Date: |
Fri, 23 Jan 2015 15:25:36 +0000 |
wingo pushed a commit to branch master
in repository guile.
commit ebca094b50d4885866cc1c3c3f3d6e2ed600aeac
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 7ebe0c0..d00ce67 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -207,31 +207,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] 27/88: Remove hashset slots from GOOPS classes, (continued)
- [Guile-commits] 27/88: Remove hashset slots from GOOPS classes, Andy Wingo, 2015/01/23
- [Guile-commits] 25/88: Generics with setters have <applicable-struct-with-setter> layout, Andy Wingo, 2015/01/23
- [Guile-commits] 13/88: Move GOOPS boot to Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 31/88: More unused code removal in GOOPS, Andy Wingo, 2015/01/23
- [Guile-commits] 29/88: Remove scm_assert_bound, Andy Wingo, 2015/01/23
- [Guile-commits] 19/88: Remove unused scm_t_method and SCM_METHOD, Andy Wingo, 2015/01/23
- [Guile-commits] 32/88: Remove unused union scm_t_debug_info, Andy Wingo, 2015/01/23
- [Guile-commits] 28/88: Remove scm_at_assert_bound_ref, Andy Wingo, 2015/01/23
- [Guile-commits] 33/88: More goops.c cleanups, and fix a security issue, Andy Wingo, 2015/01/23
- [Guile-commits] 34/88: Remove GOOPS random state, Andy Wingo, 2015/01/23
- [Guile-commits] 36/88: Statically compute offsets for slots of <class> in Scheme,
Andy Wingo <=
- [Guile-commits] 21/88: Remove unreachable code in scm_setter, Andy Wingo, 2015/01/23
- [Guile-commits] 18/88: Fold GOOPS compile and dispatch modules into main GOOPS module, Andy Wingo, 2015/01/23
- [Guile-commits] 39/88: Port method and generic accessors to Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 35/88: Refactor to <class> slot computation, Andy Wingo, 2015/01/23
- [Guile-commits] 38/88: <class> accessors implemented in Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 30/88: Remove private var_no_applicable_method capture, Andy Wingo, 2015/01/23
- [Guile-commits] 26/88: Deprecate C exports of GOOPS classes., Andy Wingo, 2015/01/23
- [Guile-commits] 41/88: Goops slot-unbound / slot-missing cleanups, Andy Wingo, 2015/01/23
- [Guile-commits] 40/88: Move slot-ref et al to Scheme, Andy Wingo, 2015/01/23
- [Guile-commits] 44/88: No more concept of "pure generics", Andy Wingo, 2015/01/23