[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 50/61: Beginnings of <slot> slot definition class
From: |
Andy Wingo |
Subject: |
[Guile-commits] 50/61: Beginnings of <slot> slot definition class |
Date: |
Thu, 22 Jan 2015 18:53:19 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 34ade88debfdf7dfe4e3e900fa6715bd4955a358
Author: Andy Wingo <address@hidden>
Date: Fri Jan 16 15:44:48 2015 +0100
Beginnings of <slot> slot definition class
* module/oop/goops.scm (define-macro-folder): Factor out this helper.
(fold-class-slots): Implement using define-macro-folder.
(fold-slot-slots): New definition, for slots of <slot-definition>.
(define-slot-indexer): New helper. Use to define indexes for slots of
<class> and of <slot>.
---
module/oop/goops.scm | 115 +++++++++++++++++++++++++++++--------------------
1 files changed, 68 insertions(+), 47 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index 62b5f5a..67467ed 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -150,11 +150,12 @@
;;;
;;; We then define the slots that must appear in all classes (<class>
-;;; objects). These slots must appear in order. We'll use this list to
-;;; statically compute offsets for the various fields, to compute the
-;;; struct layout for <class> instances, and to compute the slot
-;;; definition lists for <class>. Because the list is needed at
-;;; expansion-time, we define it as a macro.
+;;; objects) and slot definitions (<slot> objects). These slots must
+;;; appear in order. We'll use this list to statically compute offsets
+;;; for the various fields, to compute the struct layout for <class>
+;;; instances, and to compute the slot definition lists for <class>.
+;;; Because the list is needed at expansion-time, we define it as a
+;;; macro.
;;;
(define-syntax macro-fold-left
(syntax-rules ()
@@ -168,52 +169,72 @@
((_ folder seed (head . tail))
(folder head (macro-fold-right folder seed tail)))))
-(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>)
- (nfields <hidden-slot>)
- (%reserved <hidden-slot>)
- (redefined)
- (direct-supers)
- (direct-slots)
- (direct-subclasses)
- (direct-methods)
- (cpl)
- (slots)
- (getters-n-setters)))
- (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-syntax-rule (define-macro-folder macro-folder value ...)
+ (define-syntax macro-folder
+ (lambda (x)
+ (syntax-case x ()
+ ((_ fold visit seed)
+ ;; The datum->syntax makes it as if each `value' were present
+ ;; in the initial form, which allows them to be used as
+ ;; (components of) introduced identifiers.
+ #`(fold visit seed #,(datum->syntax #'visit '(value ...))))))))
+
+(define-macro-folder fold-class-slots
+ (layout <protected-read-only-slot>)
+ (flags <hidden-slot>)
+ (self <self-slot>)
+ (instance-finalizer <hidden-slot>)
+ (print)
+ (name <protected-hidden-slot>)
+ (nfields <hidden-slot>)
+ (%reserved <hidden-slot>)
+ (redefined)
+ (direct-supers)
+ (direct-slots)
+ (direct-subclasses)
+ (direct-methods)
+ (cpl)
+ (slots)
+ (getters-n-setters))
+
+(define-macro-folder fold-slot-slots
+ (name #:init-keyword #:name)
+ (allocation #:init-keyword #:allocation #:init-value #:instance)
+ (init-form #:init-keyword #:init-form)
+ (init-thunk #:init-keyword #:init-thunk #:init-value #f)
+ (options)
+ (getter #:init-keyword #:getter)
+ (setter #:init-keyword #:setter)
+ (index #:init-keyword #:index)
+ (size #:init-keyword #:size))
;;;
;;; Statically define variables for slot offsets: `class-index-layout'
-;;; will be 0, `class-index-flags' will be 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-syntax #,(id-append #'name #'class-index-
#'name)
- (identifier-syntax #,(tail-length #'tail)))
- tail))))))
- (fold-class-slots macro-fold-left define-class-index (begin)))
+;;; will be 0, `class-index-flags' will be 1, and so on, and the same
+;;; for `slot-index-name' and such for <slot>.
+;;;
+(let-syntax ((define-slot-indexer
+ (syntax-rules ()
+ ((_ define-index prefix)
+ (define-syntax define-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-syntax #,(id-append #'name #'prefix
#'name)
+ (identifier-syntax #,(tail-length #'tail)))
+ tail)))))))))
+ (define-slot-indexer define-class-index class-index-)
+ (define-slot-indexer define-slot-index slot-index-)
+ (fold-class-slots macro-fold-left define-class-index (begin))
+ (fold-slot-slots macro-fold-left define-slot-index (begin)))
;;;
;;; Structs that are vtables have a "flags" slot, which corresponds to
- [Guile-commits] 42/61: Convert emit-linear-dispatch to use match, (continued)
- [Guile-commits] 42/61: Convert emit-linear-dispatch to use match, Andy Wingo, 2015/01/22
- [Guile-commits] 38/61: Commenting in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 43/61: `match' refactor in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 40/61: when and unless for one-armed ifs in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 44/61: GOOPS class slot indices defined as inline values, Andy Wingo, 2015/01/22
- [Guile-commits] 47/61: change-object-class refactor, Andy Wingo, 2015/01/22
- [Guile-commits] 45/61: Manipulate GOOPS vtable flags from Scheme, for speed, Andy Wingo, 2015/01/22
- [Guile-commits] 41/61: More GOOPS cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 48/61: GOOPS: Deprecate "using-class" procs like slot-ref-using-class, Andy Wingo, 2015/01/22
- [Guile-commits] 46/61: slot-ref, slot-set! et al bypass "using-class" variants, Andy Wingo, 2015/01/22
- [Guile-commits] 50/61: Beginnings of <slot> slot definition class,
Andy Wingo <=
- [Guile-commits] 52/61: Use a vtable bit to mark <slot> instances, Andy Wingo, 2015/01/22
- [Guile-commits] 56/61: Minor GOOPS cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 55/61: Optimize %initialize-object, Andy Wingo, 2015/01/22
- [Guile-commits] 49/61: The GOOPS "unbound" value is a unique pair, Andy Wingo, 2015/01/22
- [Guile-commits] 53/61: Inline helpers into slot-ref, slot-set!, etc, Andy Wingo, 2015/01/22
- [Guile-commits] 58/61: Update (oop goops save) for <slot> objects, Andy Wingo, 2015/01/22
- [Guile-commits] 60/61: Fast generic function dispatch without calling `compile' at runtime, Andy Wingo, 2015/01/22
- [Guile-commits] 57/61: Fix foreign objects for removal of getters-n-setters, Andy Wingo, 2015/01/22
- [Guile-commits] 54/61: Inline internal slot accessors, Andy Wingo, 2015/01/22
- [Guile-commits] 61/61: Simplify GOOPS effective method cache format, Andy Wingo, 2015/01/22