1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

Primitive expand numerical comparisons with more than 2 arguments.

* module/language/tree-il/primitives.scm (chained-comparison-expander):
  New procedure.
  (*primitive-expand-table*): Add primitive expanders for '<', '>',
  '<=', '>=', and '='.
This commit is contained in:
Mark H Weaver 2014-01-28 17:44:22 -05:00
parent ca5e0414e9
commit 4dc4b86e85

View file

@ -491,6 +491,26 @@
(define-primitive-expander f64vector-set! (vec i x)
(bytevector-ieee-double-native-set! vec (* i 8) x))
(define (chained-comparison-expander prim-name)
(case-lambda
((src) (make-const src #t))
((src a) #f)
((src a b) #f)
((src a b . rest)
(make-conditional src
(make-application src
(make-primitive-ref src prim-name)
(list a b))
(make-application src
(make-primitive-ref src prim-name)
(cons b rest))
(make-const src #f)))))
(for-each (lambda (prim-name)
(hashq-set! *primitive-expand-table* prim-name
(chained-comparison-expander prim-name)))
'(< > <= >= =))
;; Appropriate for use with either 'eqv?' or 'equal?'.
(define maybe-simplify-to-eq
(case-lambda