mirror of
https://github.com/ParkerTenBroeck/coroutines.git
synced 2026-06-07 05:08:51 -04:00
so many small issues all at once
This commit is contained in:
parent
21412f4670
commit
b0d6737b07
8 changed files with 167 additions and 57 deletions
|
|
@ -24,6 +24,8 @@ public class FutureSMBuilder extends StateMachineBuilder {
|
|||
public final static MethodTypeDesc MTD_Object_Waker = MethodTypeDesc.of(ConstantDescs.CD_Object, CD_Waker);
|
||||
public final static MethodTypeDesc MTD_Obj = MethodTypeDesc.of(ConstantDescs.CD_Object);
|
||||
|
||||
public final static String AWAITING_FIELD_NAME = "awaiting";
|
||||
|
||||
static class AwaitHandler implements SpecialMethodHandler{
|
||||
final int yield_state;
|
||||
final Label yield_label;
|
||||
|
|
@ -36,18 +38,19 @@ public class FutureSMBuilder extends StateMachineBuilder {
|
|||
|
||||
@Override
|
||||
public void handle(StateMachineBuilder smb, CodeBuilder cob) {
|
||||
System.out.println("Await");
|
||||
cob.aload(0).loadConstant(yield_state).putfield(smb.CD_this, STATE_NAME, TypeKind.INT.upperBound());
|
||||
var start = cob.newBoundLabel();
|
||||
cob.dup().dup()
|
||||
.aload(1)
|
||||
.invokeinterface(CD_Future, "poll", MTD_Object_Waker).dup()
|
||||
cob.dup()
|
||||
.aload(1).invokeinterface(CD_Future, "poll", MTD_Object_Waker).dup()
|
||||
.instanceOf(CD_Pending);
|
||||
cob.ifThenElse(bcb -> {
|
||||
bcb.swap().aload(0).swap().putfield(smb.CD_this, AWAITING_FIELD_NAME, CD_Future);
|
||||
smb.lt.savingLocals(smb.CD_this, bcb, () -> {
|
||||
bcb.swap().aload(0).swap().putfield(smb.CD_this, "meow", CD_Future);
|
||||
bcb.areturn().labelBinding(yield_label);
|
||||
bcb.aload(0).getfield(smb.CD_this, "meow", CD_Future);
|
||||
});
|
||||
bcb.aload(0).getfield(smb.CD_this, AWAITING_FIELD_NAME, CD_Future);
|
||||
bcb.aload(0).aconst_null().putfield(smb.CD_this, AWAITING_FIELD_NAME, CD_Future);
|
||||
bcb.goto_(start);
|
||||
}, bcb -> {
|
||||
bcb.swap().pop();
|
||||
|
|
@ -86,6 +89,7 @@ public class FutureSMBuilder extends StateMachineBuilder {
|
|||
|
||||
@Override
|
||||
public void handle(StateMachineBuilder smb, CodeBuilder cob) {
|
||||
System.out.println("Return");
|
||||
cob.aload(0).loadConstant(-1).putfield(smb.CD_this, STATE_NAME, TypeKind.INT.upperBound()).areturn();
|
||||
}
|
||||
}
|
||||
|
|
@ -102,7 +106,14 @@ public class FutureSMBuilder extends StateMachineBuilder {
|
|||
cob.localVariable(1, "waker", CD_Waker, cob.startLabel(), cob.endLabel());
|
||||
buildStateMachineMethodCode(clb, cob, 2);
|
||||
}));
|
||||
clb.withField("meow", CD_Future, ClassFile.ACC_PRIVATE);
|
||||
clb.withMethod("cancel", MethodTypeDesc.of(ConstantDescs.CD_void), ClassFile.ACC_PUBLIC, mb -> mb.withCode(cob -> {
|
||||
cob.aload(0).getfield(CD_this, AWAITING_FIELD_NAME, CD_Future).dup().ifThen(Opcode.IFNONNULL, boc -> {
|
||||
boc.invokeinterface(CD_Future, "cancel", MethodTypeDesc.of(ConstantDescs.CD_void))
|
||||
.aload(0).aconst_null().putfield(CD_this, AWAITING_FIELD_NAME, CD_Future).return_();
|
||||
});
|
||||
cob.pop().return_();
|
||||
}));
|
||||
clb.withField(AWAITING_FIELD_NAME, CD_Future, ClassFile.ACC_PRIVATE);
|
||||
}
|
||||
|
||||
public FutureSMBuilder(ClassModel src_clm, MethodModel src_mem, CodeModel src_com) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue