Skip to content

Instantly share code, notes, and snippets.

@b-studios
Created October 10, 2017 09:02
Show Gist options
  • Save b-studios/514fc58bcf21acde7160f6b1e2a22fd6 to your computer and use it in GitHub Desktop.
Save b-studios/514fc58bcf21acde7160f6b1e2a22fd6 to your computer and use it in GitHub Desktop.
Result of bytecode instrumentation
trait AmbList[R] extends Amb with Handler[R, List[R]] {
private var coin: Boolean = true
def pure = r => List(r)
@Suspendable
def flip() = {
println("Called with coin state: " + coin)
use[Boolean](resume => {
coin = !coin
println("flip coin to " + coin)
val res = resume(coin)
println("Returned from continuation.")
res
})
}
}
24,43d23
< public boolean flip();
< Code:
< 0: getstatic #66 // Field scala/Predef$.MODULE$:Lscala/Predef$;
< 3: new #68 // class java/lang/StringBuilder
< 6: dup
< 7: invokespecial #72 // Method java/lang/StringBuilder."<init>":()V
< 10: ldc #74 // String Called with coin state:
< 12: invokevirtual #78 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
< 15: aload_0
< 16: invokeinterface #80, 1 // InterfaceMethod effekt$scala$AmbList$$coin:()Z
< 21: invokevirtual #83 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
< 24: invokevirtual #87 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
< 27: invokevirtual #91 // Method scala/Predef$.println:(Ljava/lang/Object;)V
< 30: aload_0
< 31: aload_0
< 32: invokedynamic #105, 0 // InvokeDynamic #1:apply:(Leffekt/scala/AmbList;)Leffekt/scala/CPS;
< 37: invokeinterface #109, 2 // InterfaceMethod use:(Leffekt/scala/CPS;)Ljava/lang/Object;
< 42: invokestatic #115 // Method scala/runtime/BoxesRunTime.unboxToBoolean:(Ljava/lang/Object;)Z
< 45: ireturn
<
97a78,193
>
> public boolean flip();
> Code:
> 0: aconst_null
> 1: astore_3
> 2: invokestatic #195 // Method co/paralleluniverse/fibers/Stack.getStack:()Lco/paralleluniverse/fibers/Stack;
> 5: dup
> 6: astore_1
> 7: ifnull 53
> 10: aload_1
> 11: iconst_1
> 12: istore_2
> 13: invokevirtual #199 // Method co/paralleluniverse/fibers/Stack.nextMethodEntry:()I
> 16: tableswitch { // 1 to 3
> 1: 104
> 2: 152
> 3: 190
> default: 44
> }
> 44: aload_1
> 45: invokevirtual #202 // Method co/paralleluniverse/fibers/Stack.isFirstInStackOrPushed:()Z
> 48: ifne 53
> 51: aconst_null
> 52: astore_1
> 53: iconst_0
> 54: istore_2
> 55: getstatic #66 // Field scala/Predef$.MODULE$:Lscala/Predef$;
> 58: new #68 // class java/lang/StringBuilder
> 61: dup
> 62: invokespecial #72 // Method java/lang/StringBuilder."<init>":()V
> 65: ldc #74 // String Called with coin state:
> 67: invokevirtual #78 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
> 70: aload_0
> 71: invokeinterface #80, 1 // InterfaceMethod effekt$scala$AmbList$$coin:()Z
> 76: invokevirtual #83 // Method java/lang/StringBuilder.append:(Z)Ljava/lang/StringBuilder;
> 79: invokevirtual #87 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
> 82: aload_1
> 83: ifnull 120
> 86: aload_1
> 87: iconst_1
> 88: iconst_2
> 89: invokevirtual #206 // Method co/paralleluniverse/fibers/Stack.pushMethod:(II)V
> 92: aload_1
> 93: iconst_1
> 94: invokestatic #210 // Method co/paralleluniverse/fibers/Stack.push:(Ljava/lang/Object;Lco/paralleluniverse/fibers/Stack;I)V
> 97: aload_1
> 98: iconst_0
> 99: invokestatic #210 // Method co/paralleluniverse/fibers/Stack.push:(Ljava/lang/Object;Lco/paralleluniverse/fibers/Stack;I)V
> 102: iconst_0
> 103: istore_2
> 104: aload_1
> 105: iconst_0
> 106: invokevirtual #214 // Method co/paralleluniverse/fibers/Stack.getObject:(I)Ljava/lang/Object;
> 109: checkcast #62 // class scala/Predef$
> 112: aload_1
> 113: iconst_1
> 114: invokevirtual #214 // Method co/paralleluniverse/fibers/Stack.getObject:(I)Ljava/lang/Object;
> 117: checkcast #216 // class java/lang/String
> 120: invokevirtual #91 // Method scala/Predef$.println:(Ljava/lang/Object;)V
> 123: aload_0
> 124: aload_0
> 125: invokedynamic #105, 0 // InvokeDynamic #1:apply:(Leffekt/scala/AmbList;)Leffekt/scala/CPS;
> 130: aload_1
> 131: ifnull 168
> 134: aload_1
> 135: iconst_2
> 136: iconst_2
> 137: invokevirtual #206 // Method co/paralleluniverse/fibers/Stack.pushMethod:(II)V
> 140: aload_1
> 141: iconst_1
> 142: invokestatic #210 // Method co/paralleluniverse/fibers/Stack.push:(Ljava/lang/Object;Lco/paralleluniverse/fibers/Stack;I)V
> 145: aload_1
> 146: iconst_0
> 147: invokestatic #210 // Method co/paralleluniverse/fibers/Stack.push:(Ljava/lang/Object;Lco/paralleluniverse/fibers/Stack;I)V
> 150: iconst_0
> 151: istore_2
> 152: aload_1
> 153: iconst_0
> 154: invokevirtual #214 // Method co/paralleluniverse/fibers/Stack.getObject:(I)Ljava/lang/Object;
> 157: checkcast #2 // class effekt/scala/AmbList
> 160: aload_1
> 161: iconst_1
> 162: invokevirtual #214 // Method co/paralleluniverse/fibers/Stack.getObject:(I)Ljava/lang/Object;
> 165: checkcast #218 // class effekt/scala/CPS
> 168: invokeinterface #109, 2 // InterfaceMethod use:(Leffekt/scala/CPS;)Ljava/lang/Object;
> 173: aload_1
> 174: ifnull 195
> 177: aload_1
> 178: iconst_3
> 179: iconst_1
> 180: invokevirtual #206 // Method co/paralleluniverse/fibers/Stack.pushMethod:(II)V
> 183: aload_1
> 184: iconst_0
> 185: invokestatic #210 // Method co/paralleluniverse/fibers/Stack.push:(Ljava/lang/Object;Lco/paralleluniverse/fibers/Stack;I)V
> 188: iconst_0
> 189: istore_2
> 190: aload_1
> 191: iconst_0
> 192: invokevirtual #214 // Method co/paralleluniverse/fibers/Stack.getObject:(I)Ljava/lang/Object;
> 195: invokestatic #115 // Method scala/runtime/BoxesRunTime.unboxToBoolean:(Ljava/lang/Object;)Z
> 198: aload_1
> 199: ifnull 206
> 202: aload_1
> 203: invokevirtual #221 // Method co/paralleluniverse/fibers/Stack.popMethod:()V
> 206: ireturn
> 207: aload_1
> 208: ifnull 215
> 211: aload_1
> 212: invokevirtual #221 // Method co/paralleluniverse/fibers/Stack.popMethod:()V
> 215: athrow
> Exception table:
> from to target type
> 53 207 215 Class co/paralleluniverse/fibers/SuspendExecution
> 53 207 215 Class co/paralleluniverse/fibers/RuntimeSuspendExecution
> 53 207 215 Class co/paralleluniverse/fibers/Suspend
> 53 207 207 any
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment