Created
August 14, 2011 02:47
-
-
Save kmizu/1144506 to your computer and use it in GitHub Desktop.
Confirm compiled code that uses return expression inside anonymous function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Compiled from "ReturnFromAnymousFunction.scala" | |
public final class ReturnFromAnonymousFunction$$anonfun$main$1 extends scala.runtime.AbstractFunction1$mcVI$sp implement | |
s scala.Serializable{ | |
//... | |
public final void apply(int); | |
Code: | |
0: aload_0 | |
1: iload_1 | |
2: invokevirtual #19; //Method apply$mcVI$sp:(I)V | |
5: return | |
//It is specilazed version of Function1#apply | |
public void apply$mcVI$sp(int); | |
Code: | |
0: getstatic #30; //Field scala/Predef$.MODULE$:Lscala/Predef$; | |
3: iload_1 | |
4: invokestatic #36; //Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer; | |
7: invokevirtual #40; //Method scala/Predef$.println:(Ljava/lang/Object;)V | |
10: iload_1 | |
11: iconst_5 | |
12: if_icmpge 30 | |
15: new #42; //class scala/runtime/NonLocalReturnControl | |
18: dup | |
19: aload_0 | |
20: getfield #44; //Field nonLocalReturnKey1$1:Ljava/lang/Object; | |
23: getstatic #50; //Field scala/runtime/BoxedUnit.UNIT:Lscala/runtime/BoxedUnit; | |
26: invokespecial #54; //Method scala/runtime/NonLocalReturnControl."<init>":(Ljava/lang/Object;Ljava/lang/Object; | |
)V | |
29: athrow // NonLocalReturnControl execption is thrown | |
30: return | |
//... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ReturnFromAnonymousFunction$ extends java.lang.Object implements scala.ScalaObject{ | |
public static final ReturnFromAnonymousFunction$ MODULE$; | |
public static {}; | |
Code: | |
0: new #9; //class ReturnFromAnonymousFunction$ | |
3: invokespecial #12; //Method "<init>":()V | |
6: return | |
public void main(java.lang.String[]); | |
Code: | |
0: new #16; //class java/lang/Object | |
3: dup | |
4: invokespecial #18; //Method java/lang/Object."<init>":()V | |
7: astore_2 | |
8: getstatic #23; //Field scala/Predef$.MODULE$:Lscala/Predef$; | |
11: iconst_1 | |
12: invokevirtual #27; //Method scala/Predef$.intWrapper:(I)Lscala/runtime/RichInt; | |
15: bipush 10 | |
17: invokevirtual #33; //Method scala/runtime/RichInt.to:(I)Lscala/collection/immutable/Range$Inclusive; | |
20: new #35; //class ReturnFromAnonymousFunction$$anonfun$main$1 | |
23: dup | |
24: aload_2 | |
25: invokespecial #38; //Method ReturnFromAnonymousFunction$$anonfun$main$1."<init>":(Ljava/lang/Object;)V | |
28: invokevirtual #44; //Method scala/collection/immutable/Range$Inclusive.foreach$mVc$sp:(Lscala/Function1;)V | |
31: goto 51 | |
34: astore_3 // catch clause start | |
35: aload_3 | |
36: invokevirtual #50; //Method scala/runtime/NonLocalReturnControl.key:()Ljava/lang/Object; | |
39: aload_2 | |
40: if_acmpne 52 // throwされたNonLocalReturn#key()と「同じ」オブジェクトで無ければ再throw (see 52) | |
43: aload_3 | |
44: invokevirtual #53; //Method scala/runtime/NonLocalReturnControl.value:()Ljava/lang/Object; | |
47: checkcast #55; //class scala/runtime/BoxedUnit | |
50: pop | |
51: return | |
52: aload_3 | |
53: athrow | |
Exception table: | |
from to target type | |
8 34 34 Class scala/runtime/NonLocalReturnControl //To catch NonLocalReturnControl | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ReturnFromAnonymousFunction { | |
def main(args: Array[String]) { | |
(1 to 10).foreach{i => | |
println(i) | |
if(i < 5) return | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment