From 9d7d03e91cf7dee327948268e8c2139196dd64ea Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 20:31:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20short16=20?= =?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81long64=E3=80=81float32=E3=80=81double?= =?UTF-8?q?64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/type/conversion/S2BCommand.java | 47 +++++++++++++++++++ .../commands/type/conversion/S2DCommand.java | 47 +++++++++++++++++++ .../commands/type/conversion/S2FCommand.java | 47 +++++++++++++++++++ .../commands/type/conversion/S2LCommand.java | 47 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java new file mode 100644 index 0000000..fa86e5f --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * S2BCommand Opcode: Represents the type conversion operation from short16 to byte8 in the virtual machine. + *

This opcode is implemented by the {@link S2BCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top short16 value from the operand stack.
  2. + *
  3. Convert the short16 value to a byte8 value.
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a short16 value to a byte8 type, facilitating subsequent integer arithmetic or comparison operations.

+ */ +public class S2BCommand implements Command { + + /** + * Default constructor for creating an instance of S2BCommand. + */ + public S2BCommand() { + // Empty constructor + } + + /** + * Executes the short16 to byte8 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + byte convertedValue = (byte) ((short) operandStack.pop()); + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java new file mode 100644 index 0000000..2f3381f --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * S2DCommand Opcode: Represents the type conversion operation from short16 to double64 in the virtual machine. + *

This opcode is implemented by the {@link S2DCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top short16 value from the operand stack.
  2. + *
  3. Convert the short16 value to an double64 value.
  4. + *
  5. Push the converted double64 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a short16 value to an double64 type, facilitating subsequent integer arithmetic or comparison operations.

+ */ +public class S2DCommand implements Command { + + /** + * Default constructor for creating an instance of S2DCommand. + */ + public S2DCommand() { + // Empty constructor + } + + /** + * Executes the short16 to double64 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + double convertedValue = (short) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java new file mode 100644 index 0000000..78fbb4a --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * S2FCommand Opcode: Represents the type conversion operation from short16 to float32 in the virtual machine. + *

This opcode is implemented by the {@link S2FCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top short16 value from the operand stack.
  2. + *
  3. Convert the short16 value to an float32 value.
  4. + *
  5. Push the converted float32 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a short16 value to an float32 type, facilitating subsequent integer arithmetic or comparison operations.

+ */ +public class S2FCommand implements Command { + + /** + * Default constructor for creating an instance of S2FCommand. + */ + public S2FCommand() { + // Empty constructor + } + + /** + * Executes the short16 to float32 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + float convertedValue = (short) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java new file mode 100644 index 0000000..cec58e6 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * S2LCommand Opcode: Represents the type conversion operation from short16 to long64 in the virtual machine. + *

This opcode is implemented by the {@link S2LCommand} class, which defines its specific execution logic.

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top short16 value from the operand stack.
  2. + *
  3. Convert the short16 value to a long64 value.
  4. + *
  5. Push the converted long64 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to widen a short16 value to a long64 type, facilitating subsequent integer arithmetic or comparison operations.

+ */ +public class S2LCommand implements Command { + + /** + * Default constructor for creating an instance of S2LCommand. + */ + public S2LCommand() { + // Empty constructor + } + + /** + * Executes the short16 to long64 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + long convertedValue = (short) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +}