Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vietj/yield-transpiler
A transpiler for generator function
https://github.com/vietj/yield-transpiler
Last synced: 5 days ago
JSON representation
A transpiler for generator function
- Host: GitHub
- URL: https://github.com/vietj/yield-transpiler
- Owner: vietj
- Created: 2016-01-22T22:55:12.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-26T12:29:49.000Z (over 8 years ago)
- Last Synced: 2024-11-08T20:49:59.762Z (about 2 months ago)
- Language: Java
- Size: 54.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Yield transpiler
A proof of concept of a `yield` transpiler based on annotation processor integrated in the Java compiler providing
a transparent compile-time transpilation.Benefits:
- 100% compile time
- no external dependencies
- lighweight
- transpiled source is available and can be debugged### Example
```
@Transpile
public void myMethod() {
SyncTest.output.add("before");
for (int i = 0;i < 3;i++) {
SyncTest.output.add("<-" + i);
if (i == 1) {
Helper.yield();
}
SyncTest.output.add("->" + i);
}
SyncTest.output.add("after");
}
```transpiles to a new class :
```
public class MyClass {
int i;
public synctest.Generator myMethod() {
class GeneratorImpl extends synctest.Generator {
public Object next(synctest.Context context) {
while(true) {
switch(context.status) {
case 0: {
SyncTest.output.add("before");
i = 0;
context.status = 1;
break;
}
case 1: {
if (!(i < 3)) {
context.status = 4;
break;
}
SyncTest.output.add("<-" + i);
if (!(i == 1)) {
context.status = 3;
break;
};
context.status = 2;
return null;
}
case 2: {
context.status = 3;
break;
}
case 3: {
SyncTest.output.add("->" + i);
i++;;
context.status = 1;
break;
}
case 4: {
SyncTest.output.add("after");
return null;
}
}
}
}
}
return new GeneratorImpl();
}
}
```### Todo
- function parameters
- while