feat: 补充基本数值类型转换指令

This commit is contained in:
zhangxun 2025-07-08 20:19:45 +08:00
parent eee77ea451
commit fabde0026f
2 changed files with 135 additions and 94 deletions

View File

@ -2043,34 +2043,33 @@ public class VMOpCode {
// endregion
// region Type Conversion (0x00C0-0x00DF)
/**
* I2L Opcode: Represents the type conversion operation from int32 to long64 in the virtual machine.
* <p>This opcode is implemented by the {@link I2LCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top int32 value from the operand stack.</li>
* <li>Convert the int32 value to a long64 value.</li>
* <li>Push the converted long64 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.</p>
*/
public static final int I2L = 0x00C0;
/**
* I2S Opcode: Represents the type conversion operation from int32 to short16 in the virtual machine.
* <p>This opcode is implemented by the {@link I2SCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top int32 value from the operand stack.</li>
* <li>Convert the int32 value to a short16 value (this may involve truncation).</li>
* <li>Push the converted short16 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is typically used to narrow an int32 value to a short16 type when a smaller data representation is needed.</p>
*/
public static final int I2S = 0x00C1;
// region Byte8 (0x00C0-0xC4)
public static final int B2S = 0x00C0;
public static final int B2I = 0x00C1;
public static final int B2L = 0x00C2;
public static final int B2F = 0x00C3;
public static final int B2D = 0x00C4;
// endregion Byte8
// region Short16 (0x00C5-0xC9)
public static final int S2B = 0x00C5;
public static final int S2I = 0x00C6;
public static final int S2L = 0x00C7;
public static final int S2F = 0x00C8;
public static final int S2D = 0x00C9;
// endregion Short16
// region Int32 (0x00CA-0xCE)
/**
* I2B Opcode: Represents the type conversion operation from int32 to byte8 in the virtual machine.
* <p>This opcode is implemented by the {@link I2BCommand} class, which defines its specific execution logic.</p>
@ -2084,21 +2083,37 @@ public class VMOpCode {
*
* <p>This opcode is used to narrow an int32 value to a byte8 type, suitable when a smaller numeric type is required.</p>
*/
public static final int I2B = 0x00C2;
public static final int I2B = 0x00CA;
/**
* I2D Opcode: Represents the type conversion operation from int32 to double64 in the virtual machine.
* <p>This opcode is implemented by the {@link I2DCommand} class, which defines its specific execution logic.</p>
* I2S Opcode: Represents the type conversion operation from int32 to short16 in the virtual machine.
* <p>This opcode is implemented by the {@link I2SCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top int32 value from the operand stack.</li>
* <li>Convert the int32 value to a double64 value.</li>
* <li>Push the converted double64 value back onto the operand stack for subsequent operations.</li>
* <li>Convert the int32 value to a short16 value (this may involve truncation).</li>
* <li>Push the converted short16 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.</p>
* <p>This opcode is typically used to narrow an int32 value to a short16 type when a smaller data representation is needed.</p>
*/
public static final int I2D = 0x00C3;
public static final int I2S = 0x00CB;
/**
* I2L Opcode: Represents the type conversion operation from int32 to long64 in the virtual machine.
* <p>This opcode is implemented by the {@link I2LCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top int32 value from the operand stack.</li>
* <li>Convert the int32 value to a long64 value.</li>
* <li>Push the converted long64 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.</p>
*/
public static final int I2L = 0x00CC;
/**
* I2F Opcode: Represents the type conversion operation from int32 to float32 in the virtual machine.
* <p>This opcode is implemented by the {@link I2FCommand} class, which defines its specific execution logic.</p>
@ -2112,7 +2127,29 @@ public class VMOpCode {
*
* <p>This opcode is used to convert an int32 value to a float32 type when floating-point arithmetic is required.</p>
*/
public static final int I2F = 0x00C4;
public static final int I2F = 0x00CD;
/**
* I2D Opcode: Represents the type conversion operation from int32 to double64 in the virtual machine.
* <p>This opcode is implemented by the {@link I2DCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top int32 value from the operand stack.</li>
* <li>Convert the int32 value to a double64 value.</li>
* <li>Push the converted double64 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.</p>
*/
public static final int I2D = 0x00CE;
// endregion Int32
// region Long64 (0x00CF-0xD3)
public static final int L2B = 0x00CF;
public static final int L2S = 0x00D0;
/**
* L2I Opcode: Represents the type conversion operation from long64 to int32 in the virtual machine.
* <p>This opcode is implemented by the {@link L2ICommand} class, which defines its specific execution logic.</p>
@ -2126,21 +2163,7 @@ public class VMOpCode {
*
* <p>This opcode is typically used to narrow a long64 value to an int32 type for further integer operations.</p>
*/
public static final int L2I = 0x00C5;
/**
* L2D Opcode: Represents the type conversion operation from long64 to double64 in the virtual machine.
* <p>This opcode is implemented by the {@link L2DCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top long64 value from the operand stack.</li>
* <li>Convert the long64 value to a double64 value.</li>
* <li>Push the converted double64 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.</p>
*/
public static final int L2D = 0x00C6;
public static final int L2I = 0x00D1;
/**
* L2F Opcode: Represents the type conversion operation from long64 to float32 in the virtual machine.
* <p>This opcode is implemented by the {@link L2FCommand} class, which defines its specific execution logic.</p>
@ -2154,7 +2177,29 @@ public class VMOpCode {
*
* <p>This opcode is used to convert a long64 value to a float32 type, typically for floating-point arithmetic involving long values.</p>
*/
public static final int L2F = 0x00C7;
public static final int L2F = 0x00D2;
/**
* L2D Opcode: Represents the type conversion operation from long64 to double64 in the virtual machine.
* <p>This opcode is implemented by the {@link L2DCommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top long64 value from the operand stack.</li>
* <li>Convert the long64 value to a double64 value.</li>
* <li>Push the converted double64 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.</p>
*/
public static final int L2D = 0x00D3;
// endregion Long64
// region Float32 (0x00D4-0xD8)
public static final int F2B = 0x00D4;
public static final int F2S = 0x00D5;
/**
* F2I Opcode: Represents the type conversion operation from float32 to int32 in the virtual machine.
* <p>This opcode is implemented by the {@link F2ICommand} class, which defines its specific execution logic.</p>
@ -2168,7 +2213,7 @@ public class VMOpCode {
*
* <p>This opcode is used to convert a float32 value to an int32 type for further integer-based operations or comparisons.</p>
*/
public static final int F2I = 0x00C8;
public static final int F2I = 0x00D6;
/**
* F2L Opcode: Represents the type conversion operation from float32 to long64 in the virtual machine.
* <p>This opcode is implemented by the {@link F2LCommand} class, which defines its specific execution logic.</p>
@ -2182,7 +2227,7 @@ public class VMOpCode {
*
* <p>This opcode is used to widen a float32 value to a long64 type, which is useful when operations require a larger numeric range.</p>
*/
public static final int F2L = 0x00C9;
public static final int F2L = 0x00D7;
/**
* F2D Opcode: Represents the type conversion operation from float32 to double64 in the virtual machine.
* <p>This opcode is implemented by the {@link F2DCommand} class, which defines its specific execution logic.</p>
@ -2196,7 +2241,15 @@ public class VMOpCode {
*
* <p>This opcode is used to promote a float32 value to a double64 type, thereby increasing precision for floating-point computations.</p>
*/
public static final int F2D = 0x00CA;
public static final int F2D = 0x00D8;
// endregion Float32
// region Double64 (0x00D9-0xDD)
public static final int D2B = 0x00D9;
public static final int D2S = 0x00DA;
/**
* D2I Opcode: Represents the type conversion operation from double64 to int32 in the virtual machine.
* <p>This opcode is implemented by the {@link D2ICommand} class, which defines its specific execution logic.</p>
@ -2210,7 +2263,7 @@ public class VMOpCode {
*
* <p>This opcode is used to narrow a double64 value to an int32 type for further integer-based processing.</p>
*/
public static final int D2I = 0x00CB;
public static final int D2I = 0x00DB;
/**
* D2L Opcode: Represents the type conversion operation from double64 to long64 in the virtual machine.
* <p>This opcode is implemented by the {@link D2LCommand} class, which defines its specific execution logic.</p>
@ -2224,7 +2277,7 @@ public class VMOpCode {
*
* <p>This opcode is used to narrow a double64 value to a long64 type, which can then be used for integer operations.</p>
*/
public static final int D2L = 0x00CC;
public static final int D2L = 0x00DC;
/**
* D2F Opcode: Represents the type conversion operation from double64 to float32 in the virtual machine.
* <p>This opcode is implemented by the {@link D2FCommand} class, which defines its specific execution logic.</p>
@ -2238,36 +2291,9 @@ public class VMOpCode {
*
* <p>This opcode is used to narrow a double64 value to a float32 type when lower precision floating-point arithmetic is acceptable.</p>
*/
public static final int D2F = 0x00CD;
/**
* S2I Opcode: Represents the type conversion operation from short16 to int32 in the virtual machine.
* <p>This opcode is implemented by the {@link S2ICommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top short16 value from the operand stack.</li>
* <li>Convert the short16 value to an int32 value.</li>
* <li>Push the converted int32 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is used to widen a short16 value to an int32 type, facilitating subsequent integer arithmetic or comparison operations.</p>
*/
public static final int S2I = 0x00CE;
/**
* B2I Opcode: Represents the type conversion operation from byte8 to int32 in the virtual machine.
* <p>This opcode is implemented by the {@link B2ICommand} class, which defines its specific execution logic.</p>
*
* <p>Execution Steps:</p>
* <ol>
* <li>Pop the top byte8 value from the operand stack.</li>
* <li>Convert the byte8 value to an int32 value.</li>
* <li>Push the converted int32 value back onto the operand stack for subsequent operations.</li>
* </ol>
*
* <p>This opcode is used to widen a byte8 value to an int32 type to ensure compatibility with integer-based operations.</p>
*/
public static final int B2I = 0x00CF;
// endregion
public static final int D2F = 0x00DD;
// endregion Double64
// endregion Conversion
// region Stack Control (0x0100-0x01FF)
/**

View File

@ -207,26 +207,41 @@ public class CommandFactory {
// endregion
// region Type Conversion (0x00C0-0x00DF)
COMMANDS[VMOpCode.I2L] = new I2LCommand();
COMMANDS[VMOpCode.I2S] = new I2SCommand();
COMMANDS[VMOpCode.B2S] = new B2SCommand();
COMMANDS[VMOpCode.B2I] = new B2ICommand();
COMMANDS[VMOpCode.B2L] = new B2LCommand();
COMMANDS[VMOpCode.B2F] = new B2FCommand();
COMMANDS[VMOpCode.B2D] = new B2DCommand();
COMMANDS[VMOpCode.S2B] = new S2BCommand();
COMMANDS[VMOpCode.S2I] = new S2ICommand();
COMMANDS[VMOpCode.S2L] = new S2LCommand();
COMMANDS[VMOpCode.S2F] = new S2FCommand();
COMMANDS[VMOpCode.S2D] = new S2DCommand();
COMMANDS[VMOpCode.I2B] = new I2BCommand();
COMMANDS[VMOpCode.I2D] = new I2DCommand();
COMMANDS[VMOpCode.I2S] = new I2SCommand();
COMMANDS[VMOpCode.I2L] = new I2LCommand();
COMMANDS[VMOpCode.I2F] = new I2FCommand();
COMMANDS[VMOpCode.I2D] = new I2DCommand();
COMMANDS[VMOpCode.L2B] = new L2BCommand();
COMMANDS[VMOpCode.L2S] = new L2SCommand();
COMMANDS[VMOpCode.L2I] = new L2ICommand();
COMMANDS[VMOpCode.L2D] = new L2DCommand();
COMMANDS[VMOpCode.L2F] = new L2FCommand();
COMMANDS[VMOpCode.L2D] = new L2DCommand();
COMMANDS[VMOpCode.F2B] = new F2BCommand();
COMMANDS[VMOpCode.F2S] = new F2SCommand();
COMMANDS[VMOpCode.F2I] = new F2ICommand();
COMMANDS[VMOpCode.F2L] = new F2LCommand();
COMMANDS[VMOpCode.F2D] = new F2DCommand();
COMMANDS[VMOpCode.D2B] = new D2BCommand();
COMMANDS[VMOpCode.D2S] = new D2SCommand();
COMMANDS[VMOpCode.D2I] = new D2ICommand();
COMMANDS[VMOpCode.D2L] = new D2LCommand();
COMMANDS[VMOpCode.D2F] = new D2FCommand();
COMMANDS[VMOpCode.S2I] = new S2ICommand();
COMMANDS[VMOpCode.B2I] = new B2ICommand();
// endregion
// region Stack Control (0x0100-0x01FF)