Skip to content

Commit

Permalink
Fix bug when feeding strings
Browse files Browse the repository at this point in the history
  • Loading branch information
phischu committed Nov 25, 2024
1 parent b541ce7 commit b69033d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion effekt/jvm/src/test/scala/effekt/StdlibTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ abstract class StdlibChezTests extends StdlibTests {
override def ignored: List[File] = List(
// Not implemented yet
examplesDir / "stdlib" / "bytearray",
examplesDir / "stdlib" / "io"
examplesDir / "stdlib" / "io",
examplesDir / "stdlib" / "stream" / "characters.effekt"
)
}
class StdlibChezSchemeMonadicTests extends StdlibChezTests {
Expand All @@ -44,6 +45,7 @@ class StdlibLLVMTests extends StdlibTests {

// Valgrind leak/failure
examplesDir / "stdlib" / "bytearray" / "bytearray.effekt",
examplesDir / "stdlib" / "stream" / "characters.effekt",
examplesDir / "stdlib" / "io" / "filesystem" / "async_file_io.effekt",
examplesDir / "stdlib" / "io" / "filesystem" / "files.effekt",
examplesDir / "stdlib" / "io" / "filesystem" / "wordcount.effekt",
Expand Down
6 changes: 6 additions & 0 deletions examples/stdlib/stream/characters.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
H (72)
e (101)
l (108)
l (108)
o (111)
Cons(H, Cons(e, Cons(l, Cons(l, Cons(o, Nil())))))
11 changes: 11 additions & 0 deletions examples/stdlib/stream/characters.effekt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import stream

def main() = {
for[Char] { each("Hello") } { c =>
println(show(c) ++ " (" ++ show(c.toInt) ++ ")")
}

val list = collectList[Char] { each("Hello") }
println(list.map { c => c.show })
}

8 changes: 6 additions & 2 deletions libraries/common/stream.effekt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ def feed[T, R](array: Array[T]) { reader: () => R / read[T] }: R = {
} with read[T] {
resume {
if (i < array.size) {
array.unsafeGet(i)
val c = i
i = c + 1
array.unsafeGet(c)
} else {
do stop()
}
Expand All @@ -259,7 +261,9 @@ def feed[R](bytes: ByteArray) { reader: () => R / read[Byte] }: R = {
} with read[Byte] {
resume {
if (i < bytes.size) {
bytes.unsafeGet(i)
val c = i
i = c + 1
bytes.unsafeGet(c)
} else {
do stop()
}
Expand Down

0 comments on commit b69033d

Please sign in to comment.