From fdae0442878efb258a48e1326f899c5b404ad75c Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 13 Mar 2024 14:38:26 +0300 Subject: [PATCH] feat(#488): handle all opcodes up to 53 instruction --- .../src/main/java/org/eolang/jeo/Bar.java | 5 +++++ src/it/spring-fat/pom.xml | 2 +- .../bytecode/BytecodeInstructionEntry.java | 7 +++++++ .../representation/bytecode/BytecodeClassTest.java | 13 +++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/it/custom-transformations/src/main/java/org/eolang/jeo/Bar.java b/src/it/custom-transformations/src/main/java/org/eolang/jeo/Bar.java index 8719670b7..2fd8b3f97 100644 --- a/src/it/custom-transformations/src/main/java/org/eolang/jeo/Bar.java +++ b/src/it/custom-transformations/src/main/java/org/eolang/jeo/Bar.java @@ -7,4 +7,9 @@ public int foo(int x) { } return 2; } + + public void sipush() { + short s = 256; + System.out.println(s); + } } \ No newline at end of file diff --git a/src/it/spring-fat/pom.xml b/src/it/spring-fat/pom.xml index f512d15a0..971b0db05 100644 --- a/src/it/spring-fat/pom.xml +++ b/src/it/spring-fat/pom.xml @@ -90,7 +90,7 @@ SOFTWARE. support many java features. We need to implement them and enable the test. --> - true + false diff --git a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeInstructionEntry.java b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeInstructionEntry.java index d00c68284..c8b8b75f7 100644 --- a/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeInstructionEntry.java +++ b/src/main/java/org/eolang/jeo/representation/bytecode/BytecodeInstructionEntry.java @@ -225,6 +225,13 @@ private enum Instruction { visitor.visitIntInsn(Opcodes.BIPUSH, (int) arguments.get(0)) ), + /** + * Push a short onto the stack as an integer value. + */ + SIPUSH(Opcodes.SIPUSH, (visitor, arguments) -> + visitor.visitIntInsn(Opcodes.SIPUSH, (int) arguments.get(0)) + ), + /** * Push a constant #index from a constant pool onto the stack. */ diff --git a/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeClassTest.java b/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeClassTest.java index dcb970563..71fb2a3bc 100644 --- a/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeClassTest.java +++ b/src/test/java/org/eolang/jeo/representation/bytecode/BytecodeClassTest.java @@ -193,4 +193,17 @@ void failsBecauseBytecodeIsBroken() { "We expect an exception here because the bytecode is broken" ); } + + @Test + void returnsShortValue() { + Assertions.assertDoesNotThrow( + () -> new BytecodeClass("ShortValue") + .withMethod("j$foo", "()S", Opcodes.ACC_PUBLIC) + .opcode(Opcodes.SIPUSH, 256) + .opcode(Opcodes.IRETURN) + .up() + .bytecode(), + "We expect no exception here because all instructions are valid" + ); + } }