Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/satabin/gnieh-coroutines
Scala compiler plugin to support coroutines
https://github.com/satabin/gnieh-coroutines
Last synced: 11 days ago
JSON representation
Scala compiler plugin to support coroutines
- Host: GitHub
- URL: https://github.com/satabin/gnieh-coroutines
- Owner: satabin
- License: apache-2.0
- Created: 2010-10-16T22:14:16.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2010-12-03T16:56:20.000Z (about 14 years ago)
- Last Synced: 2023-03-11T05:22:21.965Z (almost 2 years ago)
- Language: Scala
- Homepage:
- Size: 129 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Gnieh Coroutines
================Introduction
------------Gnieh Coroutines is a [Scala][1] library and a compiler plugin which makes it possible to use coroutines in Scala.
The design is based on coroutines in LUA ([Revisiting Coroutines][2], [Coroutines in LUA][3]) and natively implements asymmetric coroutines.This project is still at an really early stage and is not finished yet. Any comments are welcome.
Usage
-----There are two to create and use coroutines:
* coroutines.create: create and consume the coroutine object itself
* coroutines.wrap: create the coroutine and wrap it into a closure that takes the same parameter as the resume methodFor example
import gnieh._
val co = coroutines.create {
(i: Int) => {
println("first time: " + i)
val j: Int = coroutines.yld(i + 5)
println("second time: " + j)
j - 7
}
}
println(co.resume(2))
println(co.resume(5))is equivalent to
import gnieh._
val co = coroutines.wrap {
(i: Int) => {
println("first time: " + i)
val j: Int = coroutines.yld(i + 5)
println("second time: " + j)
j - 7
}
}
println(co(2))
println(co(5))Gnieh Coroutines is based on Scala continuations, so you need to enable the Scala continuations to compile the code above:
scalac -Xplugin:/path/to/gnieh-coroutines-plugin.jar -cp /path/to/gnieh.coroutines-library.jar -P:continuations:enable cor.scalaLimitations
-----------There are currently different limitations:
* coroutines.yld is only allowed in the function wrapped in the coroutine
* recursive calls to the function wrapped in the coroutine are not supportedImplementation
--------------*TBD*
TODOs
-----* Support for coroutines.yld in method not directly wrapped in the coroutine:
* add an implicit parameter to the method passing the current coroutine
* Support recursive calls?[1]: http://www.scala-lang.org
[2]: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.58.4017 "Revisiting Coroutines, Ana Lúcia de Moura and Roberto Ierusalimschy"
[3]: http://www.inf.puc-rio.br/~roberto/docs/corosblp.pdf "Coroutines in LUA, Ana Lúcia de Moura, Noemi Rodriguez, Roberto Ierusalimschy"