From f1925d74f61fe71b1d8398f6013df552602dae00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sun, 5 Nov 2023 21:59:53 +0100 Subject: [PATCH] Full support for range fusion. --- qi-lib/flow/core/compiler.rkt | 4 ++-- qi-lib/flow/core/impl.rkt | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/qi-lib/flow/core/compiler.rkt b/qi-lib/flow/core/compiler.rkt index 4b6f84ff..dccb2918 100644 --- a/qi-lib/flow/core/compiler.rkt +++ b/qi-lib/flow/core/compiler.rkt @@ -54,7 +54,7 @@ (pattern (~and (esc (#%host-expression (~literal range))) stx) #:attr next #'range->cstream-next - #:attr prepare #'range->cstream-args) + #:attr prepare #'range->cstream-prepare) (pattern (~and ((#%partial-application (#%host-expression (~literal range))) (#%host-expression arg) ...) @@ -64,7 +64,7 @@ #'curry #'curryr) #:attr next #'range->cstream-next - #:attr prepare #'(vindaloo range->cstream-args arg ...))) + #:attr prepare #'(vindaloo range->cstream-prepare arg ...))) (define-syntax-class fusable-stream-transformer #:attributes (f next) diff --git a/qi-lib/flow/core/impl.rkt b/qi-lib/flow/core/impl.rkt index 5535570b..c0306a83 100644 --- a/qi-lib/flow/core/impl.rkt +++ b/qi-lib/flow/core/impl.rkt @@ -23,7 +23,7 @@ cstream->list list->cstream-next range->cstream-next - range->cstream-args + range->cstream-prepare map-cstream-next filter-cstream-next foldr-cstream @@ -282,14 +282,16 @@ (define-inline (range->cstream-next done skip yield) (λ (state) - (match-define (cons l h) state) + (match-define (list l h s) state) (cond [(< l h) - (yield l (cons (add1 l) h))] + (yield l (cons (+ l s) (cdr state)))] [else (done)]))) -(define-inline (range->cstream-args h/l (maybe-h #f)) - (cons (if maybe-h h/l 0) - (or maybe-h h/l))) +(define range->cstream-prepare + (case-lambda + [(h) (list 0 h 1)] + [(l h) (list l h 1)] + [(l h s) (list l h s)])) (define-inline (map-cstream-next f next) (λ (done skip yield)