diff options
author | Mark H Weaver <mhw@netris.org> | 2014-01-28 17:44:22 -0500 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2014-02-01 01:19:16 -0500 |
commit | 58147d67806e1f54c447d7eabac35b1a5086c3a6 (patch) | |
tree | 16eaa8ff4dfa7bf364e215a1502a0336103ce207 | |
parent | e6c1c5f6cb16913eadeb8758cd817c5a58d146b8 (diff) | |
download | guile-58147d67806e1f54c447d7eabac35b1a5086c3a6.tar.gz |
Compile numerical comparisons with more than 2 arguments to VM code.
* module/language/tree-il/primitives.scm (chained-comparison-expander):
New procedure.
(*primitive-expand-table*): Add primitive expanders for '<', '>',
'<=', '>=', and '='.
-rw-r--r-- | module/language/tree-il/primitives.scm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/module/language/tree-il/primitives.scm b/module/language/tree-il/primitives.scm index f140eeca2..9901876a7 100644 --- a/module/language/tree-il/primitives.scm +++ b/module/language/tree-il/primitives.scm @@ -491,6 +491,29 @@ (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) + (let* ((prim (make-primitive-ref src prim-name)) + (b-sym (gensym "b")) + (b* (make-lexical-ref src 'b b-sym))) + (make-let src + '(b) + (list b-sym) + (list b) + (make-conditional src + (make-application src prim (list a b*)) + (make-application src prim (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 |