mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-11 23:17:34 +02:00
Using cond-expand for faster match-check-ellipsis and match-check-identifier in Chibi.
This commit is contained in:
parent
242ab2c8e6
commit
dcd65cc9da
1 changed files with 59 additions and 43 deletions
|
@ -863,12 +863,30 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Otherwise COND-EXPANDed bits.
|
||||
|
||||
(cond-expand
|
||||
(chibi
|
||||
(define-syntax match-check-ellipsis
|
||||
(er-macro-transformer
|
||||
(lambda (expr rename compare)
|
||||
(if (compare '... (cadr expr))
|
||||
(car (cddr expr))
|
||||
(cadr (cddr expr))))))
|
||||
(define-syntax match-check-identifier
|
||||
(er-macro-transformer
|
||||
(lambda (expr rename compare)
|
||||
(if (identifier? (cadr expr))
|
||||
(car (cddr expr))
|
||||
(cadr (cddr expr)))))))
|
||||
|
||||
(else
|
||||
;; Portable versions
|
||||
;;
|
||||
;; This *should* work, but doesn't :(
|
||||
;; (define-syntax match-check-ellipsis
|
||||
;; (syntax-rules (...)
|
||||
;; ((_ ... sk fk) sk)
|
||||
;; ((_ x sk fk) fk)))
|
||||
|
||||
;;
|
||||
;; This is a little more complicated, and introduces a new let-syntax,
|
||||
;; but should work portably in any R[56]RS Scheme. Taylor Campbell
|
||||
;; originally came up with the idea.
|
||||
|
@ -888,10 +906,8 @@
|
|||
;; above if `id' is `...'
|
||||
(ellipsis? (a b c) success-k failure-k)))))
|
||||
|
||||
|
||||
;; This is portable but can be more efficient with non-portable
|
||||
;; extensions. This trick was originally discovered by Oleg Kiselyov.
|
||||
|
||||
(define-syntax match-check-identifier
|
||||
(syntax-rules ()
|
||||
;; fast-case failures, lists and vectors are not identifiers
|
||||
|
@ -907,4 +923,4 @@
|
|||
((sym? x sk fk) sk)
|
||||
;; otherwise x is a non-symbol datum
|
||||
((sym? y sk fk) fk))))
|
||||
(sym? abracadabra success-k failure-k)))))
|
||||
(sym? abracadabra success-k failure-k)))))))
|
||||
|
|
Loading…
Add table
Reference in a new issue