Home | History | Annotate | Download | only in HelloWorldLambda
      1 .class public LHelloWorldLambda;
      2 
      3 #Ye olde hello world application (with lambdas!)
      4 #To assemble and run this on a phone or emulator:
      5 #
      6 #java -jar smali.jar -o classes.dex HelloWorldLambda.smali HelloWorldFunctionalInterface.smali
      7 #zip HelloWorld.zip classes.dex
      8 #adb push HelloWorld.zip /data/local
      9 #adb shell dalvikvm -cp /data/local/HelloWorld.zip HelloWorld
     10 #
     11 #if you get out of memory type errors when running smali.jar, try
     12 #java -Xmx512m -jar smali.jar HelloWorldLambda.smali
     13 #instead
     14 
     15 .super Ljava/lang/Object;
     16 
     17 .method public static main([Ljava/lang/String;)V
     18     .registers 9 # 1 parameter, 8 locals
     19 
     20     sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
     21 
     22     const-string v1, "Hello World!"
     23     const-string v2, "How" # vD
     24     const-string v3, "are" # vE
     25     const-string v4, "you" # vF
     26     const-string v5, "doing?" # vG
     27 
     28     capture-variable v1, "helloworld"
     29 
     30     # TODO: do I need to pass the type of the lambda's functional interface here as a type id?
     31     create-lambda v1, LHelloWorldLambda;->doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     32     # Method descriptor is not required here, because only the single-abstract method is ever invoked.
     33     invoke-lambda v1, {v2, v3, v4, v5}
     34 
     35     box-lambda v6, v1  # The type of v6 is now 'LHelloWorldFunctionalInterface;'
     36     invoke-virtual {v6, v2, v3, v4, v5}, LHelloWorldFunctionalInterface;->applyFourStrings(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     37 
     38     # FIXME: should be \HelloWorldFunctionalInterface; instead of L...;
     39 
     40     # TODO: do we really need the type descriptor here at all?
     41     unbox-lambda v7, v6, LHelloWorldFunctionalInterface;  # The type of v7 is now \HelloWorldFunctionalInterface;
     42     invoke-lambda v7, {v2, v3, v4, v5}
     43 
     44     return-void
     45 .end method
     46 
     47 .method public static doHelloWorld(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
     48     .registers 6 # 4 parameters, 2 locals
     49 
     50     # This helloworld variable is brought to you by the variable liberation front
     51     liberate-variable v0, p0, "helloworld"
     52 
     53     sget-object v1, Ljava/lang/System;->out:Ljava/io/PrintStream;
     54     invoke-virtual {v1, v0}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
     55 
     56     return-void
     57 .end method
     58