[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 67/87: Convert emit-linear-dispatch to use match
From: |
Andy Wingo |
Subject: |
[Guile-commits] 67/87: Convert emit-linear-dispatch to use match |
Date: |
Thu, 22 Jan 2015 17:30:19 +0000 |
wingo pushed a commit to branch wip-goops-refactor
in repository guile.
commit 4c1b045e50c45e19659033eceb12bd0361751710
Author: Andy Wingo <address@hidden>
Date: Wed Jan 14 20:43:35 2015 +0100
Convert emit-linear-dispatch to use match
* module/oop/goops.scm (emit-linear-dispatch): Convert to use `match'.
---
module/oop/goops.scm | 65 +++++++++++++++++++++++++------------------------
1 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/module/oop/goops.scm b/module/oop/goops.scm
index b60638b..ea16a24 100644
--- a/module/oop/goops.scm
+++ b/module/oop/goops.scm
@@ -951,44 +951,45 @@ followed by its associated value. If @var{l} does not
hold a value for
,(if rest?
`(cons* ,@args rest)
`(list ,@args)))))
- (cond
- ((null? methods)
+ (match methods
+ (()
(values `(,(if rest? `(,@args . rest) args)
(let ,(map (lambda (t a)
`(,t (class-of ,a)))
types args)
,exp))
free))
- (else
- ;; jeez
- (let preddy ((free free)
- (types types)
- (specs (vector-ref (car methods) 1))
- (checks '()))
- (if (null? types)
- (let ((m-sym (gensym "p")))
- (lp (cdr methods)
- (acons (vector-ref (car methods) 3)
- m-sym
- free)
- `(if (and . ,checks)
- ,(if rest?
- `(apply ,m-sym ,@args rest)
- `(,m-sym . ,args))
- ,exp)))
- (let ((var (assq-ref free (car specs))))
- (if var
- (preddy free
- (cdr types)
- (cdr specs)
- (cons `(eq? ,(car types) ,var)
- checks))
- (let ((var (gensym "c")))
- (preddy (acons (car specs) var free)
- (cdr types)
- (cdr specs)
- (cons `(eq? ,(car types) ,var)
- checks))))))))))))
+ ((#(_ specs _ cmethod) . methods)
+ (let build-dispatch ((free free)
+ (types types)
+ (specs specs)
+ (checks '()))
+ (match types
+ (()
+ (let ((m-sym (gensym "p")))
+ (lp methods
+ (acons cmethod m-sym free)
+ `(if (and . ,checks)
+ ,(if rest?
+ `(apply ,m-sym ,@args rest)
+ `(,m-sym . ,args))
+ ,exp))))
+ ((type . types)
+ (match specs
+ ((spec . specs)
+ (let ((var (assq-ref free spec)))
+ (if var
+ (build-dispatch free
+ types
+ specs
+ (cons `(eq? ,type ,var)
+ checks))
+ (let ((var (gensym "c")))
+ (build-dispatch (acons spec var free)
+ types
+ specs
+ (cons `(eq? ,type ,var)
+ checks)))))))))))))))
(define (compute-dispatch-procedure gf cache)
(define (scan)
- [Guile-commits] 49/87: Reimplement %allocate-instance in Scheme, (continued)
- [Guile-commits] 49/87: Reimplement %allocate-instance in Scheme, Andy Wingo, 2015/01/22
- [Guile-commits] 51/87: goops.c no longer knows about <class> slot allocation, Andy Wingo, 2015/01/22
- [Guile-commits] 57/87: GOOPS utils module cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 58/87: Fold (oop goops util) into (oop goops), Andy Wingo, 2015/01/22
- [Guile-commits] 61/87: scm_make cleanup, Andy Wingo, 2015/01/22
- [Guile-commits] 60/87: Add compute-cpl tests, Andy Wingo, 2015/01/22
- [Guile-commits] 35/87: goops: use computed class slot offsets; untabify and fix whitepace, Andy Wingo, 2015/01/22
- [Guile-commits] 59/87: Scheme GOOPS cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 63/87: Commenting in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 64/87: More GOOPS comments, Andy Wingo, 2015/01/22
- [Guile-commits] 67/87: Convert emit-linear-dispatch to use match,
Andy Wingo <=
- [Guile-commits] 66/87: More GOOPS cleanups, Andy Wingo, 2015/01/22
- [Guile-commits] 62/87: Narrative reordering in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 69/87: GOOPS class slot indices defined as inline values, Andy Wingo, 2015/01/22
- [Guile-commits] 70/87: Manipulate GOOPS vtable flags from Scheme, for speed, Andy Wingo, 2015/01/22
- [Guile-commits] 68/87: `match' refactor in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 65/87: when and unless for one-armed ifs in goops.scm, Andy Wingo, 2015/01/22
- [Guile-commits] 72/87: change-object-class refactor, Andy Wingo, 2015/01/22
- [Guile-commits] 74/87: The GOOPS "unbound" value is a unique pair, Andy Wingo, 2015/01/22
- [Guile-commits] 71/87: slot-ref, slot-set! et al bypass "using-class" variants, Andy Wingo, 2015/01/22
- [Guile-commits] 73/87: GOOPS: Deprecate "using-class" procs like slot-ref-using-class, Andy Wingo, 2015/01/22