Skip to content

Commit 7bfbb06

Browse files
committed
Comment out implementation of take
1 parent 83f8ed2 commit 7bfbb06

File tree

1 file changed

+76
-3
lines changed

1 file changed

+76
-3
lines changed

tests/run-with-compiler/staged-streams_1.scala

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ object Test {
5454
}
5555
}
5656

57-
def fold_raw[A](consumer: A => Expr[Unit], s: StagedStream[A]): Expr[Unit] = {
57+
private def fold_raw[A](consumer: A => Expr[Unit], s: StagedStream[A]): Expr[Unit] = {
5858
s match {
5959
case Linear(producer) => {
6060
producer.card match {
@@ -82,7 +82,7 @@ object Test {
8282
Stream(mapRaw[Expr[A], Expr[B]](a => k => '{ ~k(f(a)) }, stream))
8383
}
8484

85-
def mapRaw[A, B](f: (A => (B => Expr[Unit]) => Expr[Unit]), s: StagedStream[A]): StagedStream[B] = {
85+
private def mapRaw[A, B](f: (A => (B => Expr[Unit]) => Expr[Unit]), s: StagedStream[A]): StagedStream[B] = {
8686
s match {
8787
case Linear(producer) => {
8888
val prod = new Producer[B] {
@@ -116,7 +116,7 @@ object Test {
116116
Stream(flatMapRaw[Expr[A], Expr[B]]((a => { val Stream (nested) = f(a); nested }), stream))
117117
}
118118

119-
def flatMapRaw[A, B](f: (A => StagedStream[B]), stream: StagedStream[A]): StagedStream[B] = {
119+
private def flatMapRaw[A, B](f: (A => StagedStream[B]), stream: StagedStream[A]): StagedStream[B] = {
120120
stream match {
121121
case Linear(producer) => Nested(producer, f)
122122
case nested: Nested[a, bt] =>
@@ -142,6 +142,79 @@ object Test {
142142

143143
Stream(flatMapRaw[Expr[A], Expr[A]]((a => { Linear(filterStream(a)) }), stream))
144144
}
145+
146+
// def moreTermination[A](f: Rep[Boolean] => Rep[Boolean], stream: StagedStream[A]): StagedStream[A] = {
147+
// def addToProducer[A](f: Rep[Boolean] => Rep[Boolean], producer: Producer[A]): Producer[A] = {
148+
// producer.card match {
149+
// case Many =>
150+
// new Producer[A] {
151+
// type St = producer.St
152+
153+
// val card = producer.card
154+
// def init(k: St => Rep[Unit]): Rep[Unit] =
155+
// producer.init(k)
156+
// def step(st: St, k: (A => Rep[Unit])): Rep[Unit] =
157+
// producer.step(st, el => k(el))
158+
// def hasNext(st: St): Rep[Boolean] =
159+
// f(producer.hasNext(st))
160+
// }
161+
// case AtMost1 => producer
162+
// }
163+
// }
164+
// stream match {
165+
// case Linear(producer) => Linear(addToProducer(f, producer))
166+
// case Nested(producer, nestedf) =>
167+
// Nested(addToProducer(f, producer), (a: Id[_]) => moreTermination(f, nestedf(a)))
168+
// }
169+
// }
170+
171+
// private def addCounter[A](n: Expr[Int], producer: Producer[A]): Producer[(Expr[Int], A)] =
172+
// new Producer[(Var[Int], A)] {
173+
// type St = (Var[Int], producer.St)
174+
175+
// val card = producer.card
176+
// def init(k: St => Rep[Unit]): Rep[Unit] = {
177+
// producer.init(st => {
178+
// var counter: Var[Int] = n
179+
// k(counter, st)
180+
// })
181+
// }
182+
// def step(st: St, k: (((Var[Int], A)) => Rep[Unit])): Rep[Unit] = {
183+
// val (counter, nst) = st
184+
// producer.step(nst, el => {
185+
// k((counter, el))
186+
// })
187+
// }
188+
// def hasNext(st: St): Rep[Boolean] = {
189+
// val (counter, nst) = st
190+
// producer.card match {
191+
// case Many => counter > 0 && producer.hasNext(nst)
192+
// case AtMost1 => producer.hasNext(nst)
193+
// }
194+
// }
195+
// }
196+
197+
// def takeRaw[A](n: Rep[Int], stream: StagedStream[A]): StagedStream[A] = {
198+
// stream match {
199+
// case Linear(producer) => {
200+
// mapRaw[(Var[Int], A), A]((t => k => {
201+
// t._1 = t._1 - 1
202+
// k(t._2)
203+
// }), Linear(addCounter(n, producer)))
204+
// }
205+
// case Nested(producer, nestedf) => {
206+
// Nested(addCounter(n, producer), (t: (Var[Int], Id[_])) => {
207+
// mapRaw[A, A]((el => k => {
208+
// t._1 = t._1 - 1
209+
// k(el)
210+
// }), moreTermination(b => t._1 > 0 && b, nestedf(t._2)))
211+
// })
212+
// }
213+
// }
214+
// }
215+
216+
// def take(n: Rep[Int]): Stream[A] = Stream(takeRaw(n, stream))
217+
145218
}
146219

147220
object Stream {

0 commit comments

Comments
 (0)