build: compile directly for Java 8

Keep modern java out of that for now, it make build script too complicated as long as scala still here to force J8 path
This commit is contained in:
Algent committed 2026-09-15 22:48:00 +02:00
1 parent d3f1b561a3
commit 12eb146d02
14 files changed
+376 -330

No files matched your search

@@ -75,7 +75,8 @@ final class HollowMicroblockClientLogic {
int slot = part.getSlot();
int internalMask = 0;
switch (slot) {
case 0, 1 -> {
case 0:
case 1:
if (face) internalMask = 0x3c;
f.apply(pos, material, pass, new Cuboid6(d1, y1, d2, d2, y2, z2), 0x3b | internalMask);
f.apply(pos, material, pass, new Cuboid6(d1, y1, z1, d2, y2, d1), 0x37 | internalMask);
@@ -83,8 +84,9 @@ final class HollowMicroblockClientLogic {
f.apply(pos, material, pass, new Cuboid6(x1, y1, d1, d1, y2, d2), sideMask & 0x13 | 0xc | internalMask);
f.apply(pos, material, pass, new Cuboid6(x1, y1, d2, x2, y2, z2), sideMask & 0x3b | 4 | internalMask);
f.apply(pos, material, pass, new Cuboid6(x1, y1, z1, x2, y2, d1), sideMask & 0x37 | 8 | internalMask);
}
case 2, 3 -> {
break;
case 2:
case 3:
if (face) internalMask = 0x33;
f.apply(pos, material, pass, new Cuboid6(d2, d1, z1, x2, d2, z2), 0x2f | internalMask);
f.apply(pos, material, pass, new Cuboid6(x1, d1, z1, d1, d2, z2), 0x1f | internalMask);
@@ -102,8 +104,9 @@ final class HollowMicroblockClientLogic {
pass,
new Cuboid6(x1, y1, z1, d1, y2, z2),
sideMask & 0x1f | 0x20 | internalMask);
}
case 4, 5 -> {
break;
case 4:
case 5:
if (face) internalMask = 0xf;
f.apply(pos, material, pass, new Cuboid6(x1, d2, d1, x2, y2, d2), 0x3e | internalMask);
f.apply(pos, material, pass, new Cuboid6(x1, y1, d1, x2, d1, d2), 0x3d | internalMask);
@@ -111,8 +114,9 @@ final class HollowMicroblockClientLogic {
f.apply(pos, material, pass, new Cuboid6(x1, d1, z1, x2, d2, d1), sideMask & 0x34 | 3 | internalMask);
f.apply(pos, material, pass, new Cuboid6(x1, d2, z1, x2, y2, z2), sideMask & 0x3e | 1 | internalMask);
f.apply(pos, material, pass, new Cuboid6(x1, y1, z1, x2, d1, z2), sideMask & 0x3d | 2 | internalMask);
}
default -> throw new MatchError(slot);
break;
default:
throw new MatchError(slot);
}
}
@@ -42,8 +42,8 @@ final class HollowMicroblockTraitLogic {
}
// The second virtual lookup is observable when a part overrides tile().
TMultiPart center = ((TMultiPart) part).tile().partMap(6);
if (center instanceof ISidedHollowConnect connection) {
return connection.getHollowSize(part.getSlot());
if (center instanceof ISidedHollowConnect) {
return ((ISidedHollowConnect) center).getHollowSize(part.getSlot());
}
return 8;
}
@@ -60,15 +60,26 @@ final class HollowMicroblockTraitLogic {
double z1 = c.min.z;
double z2 = c.max.z;
int slot = part.getSlot();
Cuboid6[] boxes = switch (slot) {
case 0, 1 -> new Cuboid6[] { new Cuboid6(d2, y1, d1, x2, y2, d2), new Cuboid6(x1, y1, d1, d1, y2, d2),
new Cuboid6(x1, y1, d2, x2, y2, z2), new Cuboid6(x1, y1, z1, x2, y2, d1) };
case 2, 3 -> new Cuboid6[] { new Cuboid6(d1, d2, z1, d2, y2, z2), new Cuboid6(d1, y1, z1, d2, d1, z2),
new Cuboid6(d2, y1, z1, x2, y2, z2), new Cuboid6(x1, y1, z1, d1, y2, z2) };
case 4, 5 -> new Cuboid6[] { new Cuboid6(x1, d1, d2, x2, d2, z2), new Cuboid6(x1, d1, z1, x2, d2, d1),
new Cuboid6(x1, d2, z1, x2, y2, z2), new Cuboid6(x1, y1, z1, x2, d1, z2) };
default -> throw new MatchError(slot);
};
Cuboid6[] boxes;
switch (slot) {
case 0:
case 1:
boxes = new Cuboid6[] { new Cuboid6(d2, y1, d1, x2, y2, d2), new Cuboid6(x1, y1, d1, d1, y2, d2),
new Cuboid6(x1, y1, d2, x2, y2, z2), new Cuboid6(x1, y1, z1, x2, y2, d1) };
break;
case 2:
case 3:
boxes = new Cuboid6[] { new Cuboid6(d1, d2, z1, d2, y2, z2), new Cuboid6(d1, y1, z1, d2, d1, z2),
new Cuboid6(d2, y1, z1, x2, y2, z2), new Cuboid6(x1, y1, z1, d1, y2, z2) };
break;
case 4:
case 5:
boxes = new Cuboid6[] { new Cuboid6(x1, d1, d2, x2, d2, z2), new Cuboid6(x1, d1, z1, x2, d2, d1),
new Cuboid6(x1, d2, z1, x2, y2, z2), new Cuboid6(x1, y1, z1, x2, d1, z2) };
break;
default:
throw new MatchError(slot);
}
return JavaConversions.seqAsJavaList(sequence(boxes));
}
@@ -74,8 +74,8 @@ final class PostMicroblockClientLogic {
@Override
public BoxedUnit apply(TMultiPart other) {
if (other instanceof PostMicroblock post && !other.equals(part)) {
part.shrinkPost(post);
if (other instanceof PostMicroblock && !other.equals(part)) {
part.shrinkPost((PostMicroblock) other);
}
return BoxedUnit.UNIT;
}
@@ -9,9 +9,10 @@ final class TMicroOcclusionLogic {
private TMicroOcclusionLogic() {}
static boolean occlusionTest(TMicroOcclusion part, TMultiPart next) {
if (!(next instanceof TMicroOcclusion other)) {
if (!(next instanceof TMicroOcclusion)) {
return true;
}
TMicroOcclusion other = (TMicroOcclusion) next;
int shape1 = MicroOcclusion$.MODULE$.shapePriority(part.getSlot());
int shape2 = MicroOcclusion$.MODULE$.shapePriority(other.getSlot());
if (other.getSize() + part.getSize() > 8) {
@@ -191,7 +191,7 @@ final class ClassInfoLookup {
// Preserve the compiler's argument-count indexing, including its behavior for wide stack values.
StackEntry receiver = stack.peek(Type.getType(call.desc).getArgumentTypes().length);
if (!(receiver instanceof Load load) || !(load.e() instanceof This)) return Option.empty();
if (!(receiver instanceof Load) || !(((Load) receiver).e() instanceof This)) return Option.empty();
return ASMMixinCompiler$.MODULE$.getClassInfo(stack.owner().getInternalName()).superClass()
.flatMap(new AbstractFunction1<ClassInfo, Option<MethodInfo>>() {
@@ -189,7 +189,8 @@ final class JavaTraitRegistration {
InsnList instructions = method.instructions;
AbstractInsnNode instruction = instructions.getFirst();
while (instruction != null) {
if (instruction instanceof FieldInsnNode field) {
if (instruction instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) instruction;
if (instruction.getOpcode() == GETFIELD) instruction = replace(
instructions,
instruction,
@@ -208,7 +209,8 @@ final class JavaTraitRegistration {
fieldName(field.name) + "_$eq",
"(" + field.desc + ")V",
true));
} else if (instruction instanceof MethodInsnNode call) {
} else if (instruction instanceof MethodInsnNode) {
MethodInsnNode call = (MethodInsnNode) instruction;
if (instruction.getOpcode() == INVOKESPECIAL) {
if (ASMMixinCompiler$.MODULE$.getSuper(call, stack).isDefined())
instruction = replace(instructions, instruction, superInstruction(call));
@@ -284,12 +286,14 @@ final class JavaTraitRegistration {
StackAnalyser stack = new StackAnalyser(Type.getObjectType(input.name), source);
AbstractInsnNode instruction = constructor.instructions.getFirst();
while (instruction != null) {
if (instruction.getOpcode() == INVOKESPECIAL && instruction instanceof MethodInsnNode call) {
if (instruction.getOpcode() == INVOKESPECIAL && instruction instanceof MethodInsnNode) {
MethodInsnNode call = (MethodInsnNode) instruction;
if (Objects.equals(call.owner, input.superName) && Objects.equals(call.name, "<init>")) {
int argumentWidth = 0;
for (Type argument : Type.getArgumentTypes(call.desc)) argumentWidth += argument.getSize();
StackAnalyser.StackEntry receiver = stack.peek(argumentWidth);
if (receiver instanceof StackAnalyser.Load load && load.e() instanceof StackAnalyser.This) {
if (receiver instanceof StackAnalyser.Load
&& ((StackAnalyser.Load) receiver).e() instanceof StackAnalyser.This) {
removeRange(constructor.instructions, receiver.insn(), instruction);
return;
}
@@ -157,18 +157,22 @@ final class ScalaSignatureParser {
Bytes bytes = entry.bytes();
ByteCodeReader reader = bytes.reader();
byte id = entry.id();
return switch (id) {
case 1, 2 -> reader.readString(bytes.len());
case 3 -> sig.NoSymbol().full();
case 9, 10 -> {
switch (id) {
case 1:
case 2:
return reader.readString(bytes.len());
case 3:
return sig.NoSymbol().full();
case 9:
case 10:
String name = sig.evalS(reader.readNat());
if (bytes.pos() + bytes.len() > reader.pos()) {
name = sig.evalS(reader.readNat()) + "." + name;
}
yield name;
}
default -> throw new MatchError(Byte.valueOf(id));
};
return name;
default:
throw new MatchError(Byte.valueOf(id));
}
}
static List<?> evalList(ScalaSignature sig, ByteCodeReader reader) {
@@ -181,36 +185,61 @@ final class ScalaSignatureParser {
static Object eval(ScalaSignature sig, int index, Object entry, ByteCodeReader reader, byte id) {
// The Scala optimizer constructs case classes directly, without initializing their companions.
return switch (id) {
case 1, 2 -> sig.evalS(index);
case 3 -> sig.NoSymbol();
case 6 -> sig.new ClassSymbol(sig.evalS(reader.readNat()), sig.evalT(reader.readNat()), reader.readNat(),
reader.readNat());
case 7 -> sig.new ObjectSymbol(sig.evalS(reader.readNat()), sig.evalT(reader.readNat()), reader.readNat(),
reader.readNat());
case 8 -> sig.new MethodSymbol(sig.evalS(reader.readNat()), sig.evalT(reader.readNat()), reader.readNat(),
reader.readNat());
case 9, 10 -> sig.new ExternalSymbol(sig.evalS(index));
// NoPrefixType is treated as NoType in the reference.
case 11, 12 -> sig.NoType();
case 13 -> sig.new ThisType(sig.evalT(reader.readNat()));
case 14 -> sig.new SingleType(sig.evalT(reader.readNat()), sig.evalT(reader.readNat()));
// Retain the reference's parameterless interpretation of a bounded super type.
case 21, 48 -> sig.new ParameterlessType(sig.evalT(reader.readNat()));
case 25 -> sig.new BooleanLiteral(reader.readLong() != 0);
case 26 -> sig.new ByteLiteral((byte) reader.readLong());
case 27 -> sig.new ShortLiteral((short) reader.readLong());
case 28 -> sig.new CharLiteral((char) reader.readLong());
case 29 -> sig.new IntLiteral((int) reader.readLong());
case 30 -> sig.new LongLiteral(reader.readLong());
case 31 -> sig.new FloatLiteral(Float.intBitsToFloat((int) reader.readLong()));
case 32 -> sig.new DoubleLiteral(Double.longBitsToDouble(reader.readLong()));
case 33 -> sig.new StringLiteral(sig.evalS(reader.readNat()));
case 34 -> sig.NullLiteral();
case 35 -> sig.new TypeLiteral(sig.evalT(reader.readNat()));
case 36 -> sig.new EnumLiteral(sig.evalT(reader.readNat()));
default -> entry;
};
switch (id) {
case 1:
case 2:
return sig.evalS(index);
case 3:
return sig.NoSymbol();
case 6:
return sig.new ClassSymbol(sig.evalS(reader.readNat()), sig.evalT(reader.readNat()), reader.readNat(),
reader.readNat());
case 7:
return sig.new ObjectSymbol(sig.evalS(reader.readNat()), sig.evalT(reader.readNat()), reader.readNat(),
reader.readNat());
case 8:
return sig.new MethodSymbol(sig.evalS(reader.readNat()), sig.evalT(reader.readNat()), reader.readNat(),
reader.readNat());
case 9:
case 10:
return sig.new ExternalSymbol(sig.evalS(index));
case 11:
case 12: // NoPrefixType is treated as NoType in the reference.
return sig.NoType();
case 13:
return sig.new ThisType(sig.evalT(reader.readNat()));
case 14:
return sig.new SingleType(sig.evalT(reader.readNat()), sig.evalT(reader.readNat()));
case 21:
case 48: // Retain the reference's parameterless interpretation of a bounded super type.
return sig.new ParameterlessType(sig.evalT(reader.readNat()));
case 25:
return sig.new BooleanLiteral(reader.readLong() != 0);
case 26:
return sig.new ByteLiteral((byte) reader.readLong());
case 27:
return sig.new ShortLiteral((short) reader.readLong());
case 28:
return sig.new CharLiteral((char) reader.readLong());
case 29:
return sig.new IntLiteral((int) reader.readLong());
case 30:
return sig.new LongLiteral(reader.readLong());
case 31:
return sig.new FloatLiteral(Float.intBitsToFloat((int) reader.readLong()));
case 32:
return sig.new DoubleLiteral(Double.longBitsToDouble(reader.readLong()));
case 33:
return sig.new StringLiteral(sig.evalS(reader.readNat()));
case 34:
return sig.NullLiteral();
case 35:
return sig.new TypeLiteral(sig.evalT(reader.readNat()));
case 36:
return sig.new EnumLiteral(sig.evalT(reader.readNat()));
default:
return entry;
}
}
static <T> IndexedSeq<T> collect(ScalaSignature sig, int id) {
@@ -56,20 +56,18 @@ final class StackAnalyserLogic {
static Type constType(Const constant) {
Object value = constant.c();
return switch (value) {
case Byte ignored -> BYTE_TYPE;
case Short ignored -> SHORT_TYPE;
case Integer ignored -> INT_TYPE;
case Long ignored -> LONG_TYPE;
case Float ignored -> FLOAT_TYPE;
case Double ignored -> DOUBLE_TYPE;
case Character ignored -> CHAR_TYPE;
case Boolean ignored -> BOOLEAN_TYPE;
case String ignored -> getObjectType("java/lang/String");
case null -> getObjectType("java/lang/Object");
// The failure message rereads the virtual accessor after classification.
default -> throw new IllegalArgumentException("Unknown const " + constant.c());
};
if (value instanceof Byte) return BYTE_TYPE;
if (value instanceof Short) return SHORT_TYPE;
if (value instanceof Integer) return INT_TYPE;
if (value instanceof Long) return LONG_TYPE;
if (value instanceof Float) return FLOAT_TYPE;
if (value instanceof Double) return DOUBLE_TYPE;
if (value instanceof Character) return CHAR_TYPE;
if (value instanceof Boolean) return BOOLEAN_TYPE;
if (value instanceof String) return getObjectType("java/lang/String");
if (value == null) return getObjectType("java/lang/Object");
// The failure message rereads the virtual accessor after classification.
throw new IllegalArgumentException("Unknown const " + constant.c());
}
static void initialize(StackAnalyser a, Type owner, MethodNode method,
@@ -126,167 +124,256 @@ final class StackAnalyserLogic {
}
static void visitInsn(StackAnalyser a, AbstractInsnNode insn) {
switch (insn) {
case InsnNode ignored -> {
int op = insn.getOpcode();
switch (op) {
case ACONST_NULL -> a.push(new Const(null, insn));
case ICONST_M1 -> a.push(new Const(-1, insn));
case ICONST_0 -> a.push(new Const(0, insn));
case ICONST_1 -> a.push(new Const(1, insn));
case ICONST_2 -> a.push(new Const(2, insn));
case ICONST_3 -> a.push(new Const(3, insn));
case ICONST_4 -> a.push(new Const(4, insn));
case ICONST_5 -> a.push(new Const(5, insn));
case LCONST_0 -> a.push(new Const(0L, insn));
case LCONST_1 -> a.push(new Const(1L, insn));
case FCONST_0 -> a.push(new Const(0f, insn));
case FCONST_1 -> a.push(new Const(1f, insn));
case FCONST_2 -> a.push(new Const(2f, insn));
case DCONST_0 -> a.push(new Const(0d, insn));
case DCONST_1 -> a.push(new Const(1d, insn));
case POP -> rawPop(a);
case POP2 -> {
rawPop(a);
rawPop(a);
}
case DUP -> a.push(peek(a));
case DUP_X1 -> a.insert(2, peek(a));
case DUP_X2 -> a.insert(3, peek(a));
case DUP2 -> {
a.push(a.peek(1));
a.push(a.peek(1));
}
case DUP2_X1 -> {
a.insert(3, a.peek(1));
a.insert(3, peek(a));
}
case DUP2_X2 -> {
a.insert(4, a.peek(1));
a.insert(4, peek(a));
}
case SWAP -> a.push(a.pop(1));
// Preserve the reference's inferred types, including conversions to int reporting double.
case L2I, F2I, D2I -> a.push(new PrimitiveCast(pop(a), DOUBLE_TYPE, insn));
case I2L, F2L, D2L -> a.push(new PrimitiveCast(pop(a), LONG_TYPE, insn));
case I2F, L2F, D2F -> a.push(new PrimitiveCast(pop(a), FLOAT_TYPE, insn));
case I2D, L2D, F2D -> a.push(new PrimitiveCast(pop(a), DOUBLE_TYPE, insn));
case I2B -> a.push(new PrimitiveCast(pop(a), BYTE_TYPE, insn));
case I2C -> a.push(new PrimitiveCast(pop(a), CHAR_TYPE, insn));
case I2S -> a.push(new PrimitiveCast(pop(a), SHORT_TYPE, insn));
case ARRAYLENGTH -> a.push(new ArrayLength(pop(a), insn));
case ATHROW, MONITORENTER, MONITOREXIT -> pop(a);
default -> {
if (op >= IALOAD && op <= SALOAD) {
a.push(new ArrayLoad(pop(a), pop(a), insn));
} else if (op >= IASTORE && op <= SASTORE) {
pop(a);
pop(a);
pop(a);
} else if (op >= IADD && op <= DREM || op >= ISHL && op <= LXOR || op >= LCMP && op <= DCMPG) {
a.push(new BinaryOp(op, pop(a), pop(a), insn));
} else if (op >= INEG && op <= DNEG) {
a.push(new UnaryOp(op, pop(a), insn));
} else if (op >= IRETURN && op <= ARETURN) {
pop(a);
}
}
}
}
case IntInsnNode intInsn -> {
switch (insn.getOpcode()) {
case BIPUSH -> a.push(new Const((byte) intInsn.operand, insn));
case SIPUSH -> a.push(new Const((short) intInsn.operand, insn));
default -> throw new MatchError(insn.getOpcode());
}
}
case LdcInsnNode ldc -> {
if (insn.getOpcode() != LDC) throw new MatchError(insn.getOpcode());
a.push(new Const(ldc.cst, insn));
}
case VarInsnNode varInsn -> {
int op = insn.getOpcode();
if (op >= ILOAD && op <= ALOAD) {
a.push(new Load(a.locals().apply(varInsn.var), insn));
} else if (op >= ISTORE && op <= ASTORE) {
a.setL(varInsn.var, new Store(pop(a), insn));
} else {
throw new MatchError(op);
}
}
case IincInsnNode incInsn -> {
if (insn.getOpcode() != IINC) throw new MatchError(insn.getOpcode());
a.setL(
incInsn.var,
new Store(
new BinaryOp(
IINC,
new Const(incInsn.incr, insn),
new Load(a.locals().apply(incInsn.var), insn),
insn),
insn));
}
case JumpInsnNode ignored -> {
int op = insn.getOpcode();
if (op >= IFEQ && op <= IFLE || op == IFNULL || op == IFNONNULL) {
if (insn instanceof InsnNode) {
int op = insn.getOpcode();
switch (op) {
case ACONST_NULL:
a.push(new Const(null, insn));
break;
case ICONST_M1:
a.push(new Const(-1, insn));
break;
case ICONST_0:
a.push(new Const(0, insn));
break;
case ICONST_1:
a.push(new Const(1, insn));
break;
case ICONST_2:
a.push(new Const(2, insn));
break;
case ICONST_3:
a.push(new Const(3, insn));
break;
case ICONST_4:
a.push(new Const(4, insn));
break;
case ICONST_5:
a.push(new Const(5, insn));
break;
case LCONST_0:
a.push(new Const(0L, insn));
break;
case LCONST_1:
a.push(new Const(1L, insn));
break;
case FCONST_0:
a.push(new Const(0f, insn));
break;
case FCONST_1:
a.push(new Const(1f, insn));
break;
case FCONST_2:
a.push(new Const(2f, insn));
break;
case DCONST_0:
a.push(new Const(0d, insn));
break;
case DCONST_1:
a.push(new Const(1d, insn));
break;
case POP:
rawPop(a);
break;
case POP2:
rawPop(a);
rawPop(a);
break;
case DUP:
a.push(peek(a));
break;
case DUP_X1:
a.insert(2, peek(a));
break;
case DUP_X2:
a.insert(3, peek(a));
break;
case DUP2:
a.push(a.peek(1));
a.push(a.peek(1));
break;
case DUP2_X1:
a.insert(3, a.peek(1));
a.insert(3, peek(a));
break;
case DUP2_X2:
a.insert(4, a.peek(1));
a.insert(4, peek(a));
break;
case SWAP:
a.push(a.pop(1));
break;
// Preserve the reference's inferred types, including conversions to int reporting double.
case L2I:
case F2I:
case D2I:
a.push(new PrimitiveCast(pop(a), DOUBLE_TYPE, insn));
break;
case I2L:
case F2L:
case D2L:
a.push(new PrimitiveCast(pop(a), LONG_TYPE, insn));
break;
case I2F:
case L2F:
case D2F:
a.push(new PrimitiveCast(pop(a), FLOAT_TYPE, insn));
break;
case I2D:
case L2D:
case F2D:
a.push(new PrimitiveCast(pop(a), DOUBLE_TYPE, insn));
break;
case I2B:
a.push(new PrimitiveCast(pop(a), BYTE_TYPE, insn));
break;
case I2C:
a.push(new PrimitiveCast(pop(a), CHAR_TYPE, insn));
break;
case I2S:
a.push(new PrimitiveCast(pop(a), SHORT_TYPE, insn));
break;
case ARRAYLENGTH:
a.push(new ArrayLength(pop(a), insn));
break;
case ATHROW:
case MONITORENTER:
case MONITOREXIT:
pop(a);
} else if (op >= IF_ICMPEQ && op <= IF_ACMPNE) {
pop(a);
pop(a);
} else if (op == JSR) {
a.push(new ReturnAddress(insn));
} else if (op != GOTO) {
throw new MatchError(op);
}
}
case TableSwitchInsnNode ignored -> pop(a);
case LookupSwitchInsnNode ignored -> pop(a);
case FieldInsnNode field -> {
switch (insn.getOpcode()) {
case GETSTATIC -> a.push(new GetField(null, field, insn));
case PUTSTATIC -> pop(a);
case GETFIELD -> a.push(new GetField(pop(a), field, insn));
case PUTFIELD -> {
break;
default:
if (op >= IALOAD && op <= SALOAD) {
a.push(new ArrayLoad(pop(a), pop(a), insn));
} else if (op >= IASTORE && op <= SASTORE) {
pop(a);
pop(a);
pop(a);
} else if (op >= IADD && op <= DREM || op >= ISHL && op <= LXOR || op >= LCMP && op <= DCMPG) {
a.push(new BinaryOp(op, pop(a), pop(a), insn));
} else if (op >= INEG && op <= DNEG) {
a.push(new UnaryOp(op, pop(a), insn));
} else if (op >= IRETURN && op <= ARETURN) {
pop(a);
}
default -> throw new MatchError(insn.getOpcode());
}
}
case MethodInsnNode method -> {
switch (insn.getOpcode()) {
case INVOKEVIRTUAL, INVOKESPECIAL, INVOKEINTERFACE ->
a.push(new Invoke(insn.getOpcode(), a.popArgs(method.desc), pop(a), method, insn));
case INVOKESTATIC ->
a.push(new Invoke(insn.getOpcode(), a.popArgs(method.desc), null, method, insn));
default -> throw new MatchError(insn.getOpcode());
}
} else if (insn instanceof IntInsnNode) {
IntInsnNode intInsn = (IntInsnNode) insn;
switch (insn.getOpcode()) {
case BIPUSH:
a.push(new Const((byte) intInsn.operand, insn));
break;
case SIPUSH:
a.push(new Const((short) intInsn.operand, insn));
break;
default:
throw new MatchError(insn.getOpcode());
}
case TypeInsnNode typeInsn -> {
switch (insn.getOpcode()) {
case NEW -> a.push(new New(getObjectType(typeInsn.desc), insn));
case NEWARRAY -> a.push(new NewArray(pop(a), getObjectType(typeInsn.desc), insn));
case ANEWARRAY -> a.push(new NewArray(pop(a), getObjectType("[" + typeInsn.desc), insn));
case CHECKCAST -> a.push(new Cast(pop(a), getObjectType(typeInsn.desc), insn));
case INSTANCEOF -> a.push(new UnaryOp(INSTANCEOF, pop(a), insn));
default -> throw new MatchError(insn.getOpcode());
}
} else if (insn instanceof LdcInsnNode) {
if (insn.getOpcode() != LDC) throw new MatchError(insn.getOpcode());
a.push(new Const(((LdcInsnNode) insn).cst, insn));
} else if (insn instanceof VarInsnNode) {
VarInsnNode varInsn = (VarInsnNode) insn;
int op = insn.getOpcode();
if (op >= ILOAD && op <= ALOAD) {
a.push(new Load(a.locals().apply(varInsn.var), insn));
} else if (op >= ISTORE && op <= ASTORE) {
a.setL(varInsn.var, new Store(pop(a), insn));
} else {
throw new MatchError(op);
}
case MultiANewArrayInsnNode multi -> {
StackEntry[] sizes = new StackEntry[multi.dims];
for (int i = 0; i < sizes.length; i++) sizes[i] = pop(a);
a.push(new NewMultiArray(sizes, getType(multi.desc), insn));
} else if (insn instanceof IincInsnNode) {
IincInsnNode incInsn = (IincInsnNode) insn;
if (insn.getOpcode() != IINC) throw new MatchError(insn.getOpcode());
a.setL(
incInsn.var,
new Store(
new BinaryOp(
IINC,
new Const(incInsn.incr, insn),
new Load(a.locals().apply(incInsn.var), insn),
insn),
insn));
} else if (insn instanceof JumpInsnNode) {
int op = insn.getOpcode();
if (op >= IFEQ && op <= IFLE || op == IFNULL || op == IFNONNULL) {
pop(a);
} else if (op >= IF_ICMPEQ && op <= IF_ACMPNE) {
pop(a);
pop(a);
} else if (op == JSR) {
a.push(new ReturnAddress(insn));
} else if (op != GOTO) {
throw new MatchError(op);
}
case LabelNode label -> {
Option<TryCatchBlockNode> handler = a.codechicken$multipart$asm$StackAnalyser$$catchHandlers()
.get(label);
if (handler instanceof Some) {
a.push(new CaughtException(Type.getType(((Some<TryCatchBlockNode>) handler).x().type), insn));
} else if (!None$.MODULE$.equals(handler)) {
throw new MatchError(handler);
}
} else if (insn instanceof TableSwitchInsnNode || insn instanceof LookupSwitchInsnNode) {
pop(a);
} else if (insn instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) insn;
switch (insn.getOpcode()) {
case GETSTATIC:
a.push(new GetField(null, field, insn));
break;
case PUTSTATIC:
pop(a);
break;
case GETFIELD:
a.push(new GetField(pop(a), field, insn));
break;
case PUTFIELD:
pop(a);
pop(a);
break;
default:
throw new MatchError(insn.getOpcode());
}
} else if (insn instanceof MethodInsnNode) {
MethodInsnNode method = (MethodInsnNode) insn;
switch (insn.getOpcode()) {
case INVOKEVIRTUAL:
case INVOKESPECIAL:
case INVOKEINTERFACE:
a.push(new Invoke(insn.getOpcode(), a.popArgs(method.desc), pop(a), method, insn));
break;
case INVOKESTATIC:
a.push(new Invoke(insn.getOpcode(), a.popArgs(method.desc), null, method, insn));
break;
default:
throw new MatchError(insn.getOpcode());
}
} else if (insn instanceof TypeInsnNode) {
TypeInsnNode typeInsn = (TypeInsnNode) insn;
switch (insn.getOpcode()) {
case NEW:
a.push(new New(getObjectType(typeInsn.desc), insn));
break;
case NEWARRAY:
a.push(new NewArray(pop(a), getObjectType(typeInsn.desc), insn));
break;
case ANEWARRAY:
a.push(new NewArray(pop(a), getObjectType("[" + typeInsn.desc), insn));
break;
case CHECKCAST:
a.push(new Cast(pop(a), getObjectType(typeInsn.desc), insn));
break;
case INSTANCEOF:
a.push(new UnaryOp(INSTANCEOF, pop(a), insn));
break;
default:
throw new MatchError(insn.getOpcode());
}
} else if (insn instanceof MultiANewArrayInsnNode) {
MultiANewArrayInsnNode multi = (MultiANewArrayInsnNode) insn;
StackEntry[] sizes = new StackEntry[multi.dims];
for (int i = 0; i < sizes.length; i++) sizes[i] = pop(a);
a.push(new NewMultiArray(sizes, getType(multi.desc), insn));
} else if (insn instanceof LabelNode) {
Option<TryCatchBlockNode> handler = a.codechicken$multipart$asm$StackAnalyser$$catchHandlers()
.get((LabelNode) insn);
if (handler instanceof Some) {
a.push(new CaughtException(Type.getType(((Some<TryCatchBlockNode>) handler).x().type), insn));
} else if (!None$.MODULE$.equals(handler)) {
throw new MatchError(handler);
}
case null, default -> {}
}
}
}