Skip to content

Commit

Permalink
Tweak JVM bytecode generation - use constant bytecodes where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Donald Hunter committed Jan 19, 2015
1 parent a702d5a commit ae6e8e4
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/vm/jvm/runtime/org/perl6/nqp/jast2bc/JASTCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,13 @@ private void compileInstruction(SixModelObject insn, JastMethod method, MethodVi
}
else if (istype(insn, jastPushI, tc) != 0) {
long value = getattr_i(insn, jastPushI, "$!value", 0, tc);
m.visitLdcInsn(value);
if (value == 0) {
m.visitInsn(Opcodes.LCONST_0);
} else if (value == 1) {
m.visitInsn(Opcodes.LCONST_1);
} else {
m.visitLdcInsn(value);
}
}
else if (istype(insn, jastPushN, tc) != 0) {
double value = getattr_n(insn, jastPushN, "$!value", 0, tc);
Expand All @@ -244,7 +250,10 @@ else if (istype(insn, jastPushC, tc) != 0) {
}
else if (istype(insn, jastPushIdx, tc) != 0) {
int value = (int) getattr_i(insn, jastPushIdx, "$!value", 0, tc);
if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
if (value >= 0 && value <= 5) {
m.visitInsn(Opcodes.ICONST_0 + value);
}
else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE) {
m.visitIntInsn(Opcodes.BIPUSH, value);
}
else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE) {
Expand Down

0 comments on commit ae6e8e4

Please sign in to comment.