Skip to content

Commit

Permalink
Full support for range fusion.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzoep committed Nov 5, 2023
1 parent 47c23cd commit f1925d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions qi-lib/flow/core/compiler.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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) ...)
Expand All @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions qi-lib/flow/core/impl.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f1925d7

Please sign in to comment.