From 4595583ca4bba4e318124536891702cfe81347ed Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:00:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20double64=20?= =?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81short16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/type/conversion/D2BCommand.java | 48 +++++++++++++++++++ .../commands/type/conversion/D2SCommand.java | 48 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java new file mode 100644 index 0000000..7180d2e --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java @@ -0,0 +1,48 @@ +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; + +/** + * D2BCommand Opcode: Represents the type conversion operation from double64 to byte8 in the virtual machine. + *
This opcode is implemented by the {@link D2BCommand} class, which defines its specific execution logic.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to a byte8 type for further integer-based operations.
+ */ +public class D2BCommand implements Command { + + /** + * Default constructor for creating an instance of D2BCommand. + */ + public D2BCommand() { + // Empty constructor + } + + /** + * Executes the double64 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) { + double value = (double) operandStack.pop(); + byte convertedValue = (byte) value; + operandStack.push(convertedValue); + return currentPC + 1; + } +} diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java new file mode 100644 index 0000000..ab11cf0 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java @@ -0,0 +1,48 @@ +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; + +/** + * D2SCommand Opcode: Represents the type conversion operation from double64 to short16 in the virtual machine. + *This opcode is implemented by the {@link D2SCommand} class, which defines its specific execution logic.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to an short16 type for further integer-based operations.
+ */ +public class D2SCommand implements Command { + + /** + * Default constructor for creating an instance of D2SCommand. + */ + public D2SCommand() { + // Empty constructor + } + + /** + * Executes the double64 to short16 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 value = (double) operandStack.pop(); + short convertedValue = (short) value; + operandStack.push(convertedValue); + return currentPC + 1; + } +}