Skip to content

Instantly share code, notes, and snippets.

@xuwei-k
Last active June 6, 2020 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xuwei-k/27eaadbb29f5b1198a24553636dce1a1 to your computer and use it in GitHub Desktop.
Save xuwei-k/27eaadbb29f5b1198a24553636dce1a1 to your computer and use it in GitHub Desktop.
$ scala -version
Scala code runner version 2.13.2 -- Copyright 2002-2020, LAMP/EPFL and Lightbend, Inc.
$ scala -Xprint:jvm -e 'if (util.Random.nextInt == 1) 2 else "3"'
[[syntax trees at end of jvm]] // scalacmd6816512509873541389.scala
package <empty> {
object Main extends Object {
def main(args: Array[String]): Unit = {
new <$anon: Object>();
()
};
def <init>(): Main.type = {
Main.super.<init>();
()
}
};
final class anon$1 extends Object {
def <init>(): <$anon: Object> = {
anon$1.super.<init>();
if (scala.util.Random.nextInt().==(1))
scala.Int.box(2)
else
"3";
()
}
}
}
$ scala -Xprint:jvm -e "def foo = { var x = 0 ; Some(1).foreach{ x = _ } ; x }"
[[syntax trees at end of jvm]] // scalacmd4840721111041760550.scala
package <empty> {
object Main extends Object {
def main(args: Array[String]): Unit = {
new <$anon: Object>();
()
};
def <init>(): Main.type = {
Main.super.<init>();
()
}
};
final class anon$1 extends Object {
private def foo(): Int = {
var x: runtime.IntRef = scala.runtime.IntRef.create(0);
new Some(scala.Int.box(1)).foreach({
$anonfun(x)
});
x.elem
};
final <static> <artifact> def $anonfun$foo$1(x$2: runtime.IntRef, x$1: Int): Unit = x$2.elem = x$1;
def <init>(): <$anon: Object> = {
anon$1.super.<init>();
()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment