mirror of
https://github.com/ParkerTenBroeck/coroutines.git
synced 2026-06-07 05:08:51 -04:00
precomputed frames, better local state saving
This commit is contained in:
parent
b0d6737b07
commit
989c807aac
10 changed files with 355 additions and 176 deletions
|
|
@ -1,10 +1,7 @@
|
|||
package generator.runtime.gen;
|
||||
|
||||
import generator.gen.Gen;
|
||||
import generator.runtime.ReplacementKind;
|
||||
import generator.runtime.SpecialMethod;
|
||||
import generator.runtime.SpecialMethodHandler;
|
||||
import generator.runtime.StateMachineBuilder;
|
||||
import generator.runtime.*;
|
||||
|
||||
import java.lang.classfile.*;
|
||||
import java.lang.constant.ClassDesc;
|
||||
|
|
@ -23,12 +20,13 @@ public class GenSMBuilder extends StateMachineBuilder {
|
|||
public final static MethodTypeDesc MTD_Gen = MethodTypeDesc.of(CD_Gen);
|
||||
public final static MethodTypeDesc MTD_Obj = MethodTypeDesc.of(ConstantDescs.CD_Object);
|
||||
|
||||
static class YieldHandler implements SpecialMethodHandler {
|
||||
static class YieldHandler extends SpecialMethodHandler {
|
||||
final int resume_state;
|
||||
final Label resume_label;
|
||||
final boolean is_void;
|
||||
|
||||
public YieldHandler(StateMachineBuilder smb, CodeBuilder cob, boolean is_void) {
|
||||
super(smb, cob);
|
||||
resume_state = smb.add_state(resume_label = cob.newLabel());
|
||||
this.is_void = is_void;
|
||||
}
|
||||
|
|
@ -36,32 +34,33 @@ public class GenSMBuilder extends StateMachineBuilder {
|
|||
public ReplacementKind replacementKind(){return ReplacementKind.ImmediateReplacingPop;}
|
||||
|
||||
@Override
|
||||
public void handle(StateMachineBuilder smb, CodeBuilder cob) {
|
||||
public void buildHandler(StateMachineBuilder smb, CodeBuilder cob, Frame frame) {
|
||||
if(is_void)cob.aconst_null();
|
||||
|
||||
smb.lt.savingLocals(smb.CD_this, cob, () -> {
|
||||
cob.aload(0).loadConstant(resume_state).putfield(smb.CD_this, STATE_NAME, TypeKind.INT.upperBound())
|
||||
.new_(CD_Yield)
|
||||
.dup_x1()
|
||||
.swap()
|
||||
.invokespecial(CD_Yield, ConstantDescs.INIT_NAME, MethodTypeDesc.of(ConstantDescs.CD_void, ConstantDescs.CD_Object))
|
||||
.areturn();
|
||||
cob.labelBinding(resume_label);
|
||||
});
|
||||
// smb.lt.savingLocals(smb.CD_this, cob, () -> {
|
||||
// cob.aload(0).loadConstant(resume_state).putfield(smb.CD_this, STATE_NAME, TypeKind.INT.upperBound())
|
||||
// .new_(CD_Yield)
|
||||
// .dup_x1()
|
||||
// .swap()
|
||||
// .invokespecial(CD_Yield, ConstantDescs.INIT_NAME, MethodTypeDesc.of(ConstantDescs.CD_void, ConstantDescs.CD_Object))
|
||||
// .areturn();
|
||||
// cob.labelBinding(resume_label);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
static class RetHandler implements SpecialMethodHandler {
|
||||
static class RetHandler extends SpecialMethodHandler {
|
||||
final boolean is_void;
|
||||
|
||||
public RetHandler(boolean is_void) {
|
||||
public RetHandler(StateMachineBuilder smb, CodeBuilder cob, boolean is_void) {
|
||||
super(smb, cob);
|
||||
this.is_void = is_void;
|
||||
}
|
||||
|
||||
public ReplacementKind replacementKind(){return ReplacementKind.ReplacingNextReturn;}
|
||||
|
||||
@Override
|
||||
public void handle(StateMachineBuilder smb, CodeBuilder cob) {
|
||||
public void buildHandler(StateMachineBuilder smb, CodeBuilder cob, Frame frame) {
|
||||
if(is_void)cob.aconst_null();
|
||||
|
||||
cob.aload(0).loadConstant(-1).putfield(smb.CD_this, STATE_NAME, TypeKind.INT.upperBound())
|
||||
|
|
@ -77,8 +76,8 @@ public class GenSMBuilder extends StateMachineBuilder {
|
|||
super(src_clm, src_mem, src_com);
|
||||
smmap.put(new SpecialMethod(CD_Gen, "yield", MTD_Gen_Obj),(smb, cob) -> new YieldHandler(smb, cob, false));
|
||||
smmap.put(new SpecialMethod(CD_Gen, "yield", MTD_Gen),(smb, cob) -> new YieldHandler(smb, cob, true));
|
||||
smmap.put(new SpecialMethod(CD_Gen, "ret", MTD_Gen_Obj),(_, _) -> new RetHandler(false));
|
||||
smmap.put(new SpecialMethod(CD_Gen, "ret", MTD_Gen),(_, _) -> new RetHandler(true));
|
||||
smmap.put(new SpecialMethod(CD_Gen, "ret", MTD_Gen_Obj),(smb, cob) -> new RetHandler(smb, cob, false));
|
||||
smmap.put(new SpecialMethod(CD_Gen, "ret", MTD_Gen),(smb, cob) -> new RetHandler(smb, cob, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue