This commit is contained in:
Parker TenBroeck 2025-04-03 00:22:50 -04:00
commit bce3396cf5
9 changed files with 695 additions and 0 deletions

28
src/generator/Gen.java Normal file
View file

@ -0,0 +1,28 @@
package generator;
public interface Gen<Y, R> {
Res<Y, R> next();
static <Y, R> Gen<Y, R> yield(Y y) {
throw new RuntimeException();
}
static <Y, R> Gen<Void, R> yield() {
throw new RuntimeException();
}
static <Y, R> Gen<Y, R> ret(R r) {throw new RuntimeException();}
static <Y, R> Gen<Y, Void> ret() {
throw new RuntimeException();
}
default R await(){
while(true){
var res = next();
if(res instanceof Ret(R r))return r;
Gen.yield();
}
}
sealed interface Res<Y, R>{}
record Yield<Y, R>(Y v) implements Res<Y, R>{}
record Ret<Y, R>(R v) implements Res<Y, R>{}
}