*/
public class CmpJumpGenerator implements InstructionGenerator {
/**
- * 返回该生成器所支持的指令类型。
+ * 返回本生成器支持的 IR 指令类型。
*
- * @return {@link IRCompareJumpInstruction} 的类对象
+ * @return IRCompareJumpInstruction 的类对象
*/
@Override
public Class supportedClass() {
@@ -29,7 +37,19 @@ public class CmpJumpGenerator implements InstructionGenerator类型宽度优先级:D > F > L > I > S > B
+ *
If the two integers are not equal, jumps to the target command.
+ *
Pops two int32 from the virtual machine stack.
+ *
If the two int32 are not equal, jumps to the target command.
*
Otherwise, the program continues with the next command.
*
*/
From a0fad7f642d0df9071068a6cb82c8870f85849f0 Mon Sep 17 00:00:00 2001
From: Luke
Date: Wed, 25 Jun 2025 16:48:57 +0800
Subject: [PATCH 16/23] =?UTF-8?q?feat=EF=BC=9Avm=20=E5=A2=9E=E5=8A=A0=20by?=
=?UTF-8?q?te8=20=E6=AF=94=E8=BE=83=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../vm/commands/control/byte8/BCECommand.java | 76 ++++++++++++++++++
.../vm/commands/control/byte8/BCGCommand.java | 76 ++++++++++++++++++
.../commands/control/byte8/BCGECommand.java | 76 ++++++++++++++++++
.../vm/commands/control/byte8/BCLCommand.java | 76 ++++++++++++++++++
.../commands/control/byte8/BCLECommand.java | 76 ++++++++++++++++++
.../commands/control/byte8/BCNECommand.java | 77 +++++++++++++++++++
6 files changed, 457 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCNECommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCECommand.java
new file mode 100644
index 0000000..f7ccc5b
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.byte8;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The BCECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if they are equal, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two byte8 from the virtual machine stack.
+ *
If the two byte8 are equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class BCECommand implements Command {
+ /**
+ * Default constructor for creating an instance of BCECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public BCECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ byte b = (byte) operandStack.pop();
+ byte a = (byte) operandStack.pop();
+
+ // If the operands are equal, jump to the target command
+ if (a == b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGCommand.java
new file mode 100644
index 0000000..92fb765
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.byte8;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The BCGCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two byte8 from the virtual machine stack.
+ *
If the first byte8 is greater than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class BCGCommand implements Command {
+ /**
+ * Default constructor for creating an instance of BCGCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public BCGCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ byte b = (byte) operandStack.pop();
+ byte a = (byte) operandStack.pop();
+
+ // If the first operand is greater than the second, jump to the target command
+ if (a > b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGECommand.java
new file mode 100644
index 0000000..16f468e
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCGECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.byte8;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The BCGECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two byte8 from the virtual machine stack.
+ *
If the first byte8 is greater than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class BCGECommand implements Command {
+ /**
+ * Default constructor for creating an instance of BCGECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public BCGECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ byte b = (byte) operandStack.pop();
+ byte a = (byte) operandStack.pop();
+
+ // If the first operand is greater than or equal to the second, jump to the target command
+ if (a >= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLCommand.java
new file mode 100644
index 0000000..1753865
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.byte8;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The BCLCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two byte8 from the virtual machine stack.
+ *
If the first byte8 is less than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class BCLCommand implements Command {
+ /**
+ * Default constructor for creating an instance of BCLCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public BCLCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ byte b = (byte) operandStack.pop();
+ byte a = (byte) operandStack.pop();
+
+ // If the first operand is less than the second, jump to the target command
+ if (a < b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLECommand.java
new file mode 100644
index 0000000..bb90118
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCLECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.byte8;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The BCLECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two byte8 from the virtual machine stack.
+ *
If the first byte8 is less than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class BCLECommand implements Command {
+ /**
+ * Default constructor for creating an instance of BCLECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public BCLECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ byte b = (byte) operandStack.pop();
+ byte a = (byte) operandStack.pop();
+
+ // If the first operand is less than or equal to the second, jump to the target command
+ if (a <= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCNECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCNECommand.java
new file mode 100644
index 0000000..a474570
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/byte8/BCNECommand.java
@@ -0,0 +1,77 @@
+package org.jcnc.snow.vm.commands.control.byte8;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The BCNECommand class implements the {@link Command} interface and represents a conditional jump command
+ * in the virtual machine that triggers if two values are not equal.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two byte8 from the virtual machine stack.
+ *
If the two byte8 are not equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class BCNECommand implements Command {
+ /**
+ * Default constructor for creating an instance of BCNECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public BCNECommand() {
+
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ byte b = (byte) operandStack.pop();
+ byte a = (byte) operandStack.pop();
+
+ // If the operands are not equal, jump to the target command
+ if (a != b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
From d3af0e39731d42b69546de50da160c02bf0483ae Mon Sep 17 00:00:00 2001
From: Luke
Date: Wed, 25 Jun 2025 16:56:18 +0800
Subject: [PATCH 17/23] =?UTF-8?q?feat=EF=BC=9Avm=20=E5=A2=9E=E5=8A=A0=20sh?=
=?UTF-8?q?ort16=20=E6=AF=94=E8=BE=83=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/control/short16/SCECommand.java | 76 ++++++++++++++++++
.../commands/control/short16/SCGCommand.java | 76 ++++++++++++++++++
.../commands/control/short16/SCGECommand.java | 76 ++++++++++++++++++
.../commands/control/short16/SCLCommand.java | 76 ++++++++++++++++++
.../commands/control/short16/SCLECommand.java | 76 ++++++++++++++++++
.../commands/control/short16/SCNECommand.java | 77 +++++++++++++++++++
6 files changed, 457 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/short16/SCECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/short16/SCNECommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCECommand.java
new file mode 100644
index 0000000..d1715a9
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.short16;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The SCECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if they are equal, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two short16 from the virtual machine stack.
+ *
If the two short16 are equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class SCECommand implements Command {
+ /**
+ * Default constructor for creating an instance of SCECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public SCECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
+
+ // If the operands are equal, jump to the target command
+ if (a == b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGCommand.java
new file mode 100644
index 0000000..42cc70a
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.short16;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The SCGCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two short16 from the virtual machine stack.
+ *
If the first short16 is greater than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class SCGCommand implements Command {
+ /**
+ * Default constructor for creating an instance of SCGCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public SCGCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
+
+ // If the first operand is greater than the second, jump to the target command
+ if (a > b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGECommand.java
new file mode 100644
index 0000000..78e8add
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCGECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.short16;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The SCGECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two short16 from the virtual machine stack.
+ *
If the first short16 is greater than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class SCGECommand implements Command {
+ /**
+ * Default constructor for creating an instance of SCGECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public SCGECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
+
+ // If the first operand is greater than or equal to the second, jump to the target command
+ if (a >= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLCommand.java
new file mode 100644
index 0000000..96c7a24
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.short16;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The SCLCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two short16 from the virtual machine stack.
+ *
If the first short16 is less than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class SCLCommand implements Command {
+ /**
+ * Default constructor for creating an instance of SCLCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public SCLCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
+
+ // If the first operand is less than the second, jump to the target command
+ if (a < b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLECommand.java
new file mode 100644
index 0000000..33de323
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCLECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.short16;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The SCLECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two short16 from the virtual machine stack.
+ *
If the first short16 is less than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class SCLECommand implements Command {
+ /**
+ * Default constructor for creating an instance of SCLECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public SCLECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
+
+ // If the first operand is less than or equal to the second, jump to the target command
+ if (a <= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCNECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCNECommand.java
new file mode 100644
index 0000000..9bb3f51
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/short16/SCNECommand.java
@@ -0,0 +1,77 @@
+package org.jcnc.snow.vm.commands.control.short16;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The SCNECommand class implements the {@link Command} interface and represents a conditional jump command
+ * in the virtual machine that triggers if two values are not equal.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two short16 from the virtual machine stack.
+ *
If the two short16 are not equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class SCNECommand implements Command {
+ /**
+ * Default constructor for creating an instance of SCNECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public SCNECommand() {
+
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
+
+ // If the operands are not equal, jump to the target command
+ if (a != b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
From 26a77da955417121fc62bc2691491c77de50b806 Mon Sep 17 00:00:00 2001
From: Luke
Date: Wed, 25 Jun 2025 17:08:12 +0800
Subject: [PATCH 18/23] =?UTF-8?q?feat=EF=BC=9Avm=20=E5=A2=9E=E5=8A=A0=20do?=
=?UTF-8?q?uble64=20=E6=AF=94=E8=BE=83=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/control/double64/DCECommand.java | 76 ++++++++++++++++++
.../commands/control/double64/DCGCommand.java | 76 ++++++++++++++++++
.../control/double64/DCGECommand.java | 76 ++++++++++++++++++
.../commands/control/double64/DCLCommand.java | 76 ++++++++++++++++++
.../control/double64/DCLECommand.java | 76 ++++++++++++++++++
.../control/double64/DCNECommand.java | 77 +++++++++++++++++++
6 files changed, 457 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/double64/DCECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/double64/DCNECommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCECommand.java
new file mode 100644
index 0000000..0153626
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.double64;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The DCECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if they are equal, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two double64 from the virtual machine stack.
+ *
If the two double64 are equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class DCECommand implements Command {
+ /**
+ * Default constructor for creating an instance of DCECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public DCECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ double b = (double) operandStack.pop();
+ double a = (double) operandStack.pop();
+
+ // If the operands are equal, jump to the target command
+ if (a == b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGCommand.java
new file mode 100644
index 0000000..fd48bff
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.double64;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The DCGCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two double64 from the virtual machine stack.
+ *
If the first double64 is greater than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class DCGCommand implements Command {
+ /**
+ * Default constructor for creating an instance of DCGCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public DCGCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ double b = (double) operandStack.pop();
+ double a = (double) operandStack.pop();
+
+ // If the first operand is greater than the second, jump to the target command
+ if (a > b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGECommand.java
new file mode 100644
index 0000000..03dad61
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCGECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.double64;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The DCGECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two double64 from the virtual machine stack.
+ *
If the first double64 is greater than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class DCGECommand implements Command {
+ /**
+ * Default constructor for creating an instance of DCGECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public DCGECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ double b = (double) operandStack.pop();
+ double a = (double) operandStack.pop();
+
+ // If the first operand is greater than or equal to the second, jump to the target command
+ if (a >= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLCommand.java
new file mode 100644
index 0000000..344df6c
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.double64;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The DCLCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two double64 from the virtual machine stack.
+ *
If the first double64 is less than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class DCLCommand implements Command {
+ /**
+ * Default constructor for creating an instance of DCLCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public DCLCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ double b = (double) operandStack.pop();
+ double a = (double) operandStack.pop();
+
+ // If the first operand is less than the second, jump to the target command
+ if (a < b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLECommand.java
new file mode 100644
index 0000000..3d87f1a
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCLECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.double64;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The DCLECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two double64 from the virtual machine stack.
+ *
If the first double64 is less than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class DCLECommand implements Command {
+ /**
+ * Default constructor for creating an instance of DCLECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public DCLECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ double b = (double) operandStack.pop();
+ double a = (double) operandStack.pop();
+
+ // If the first operand is less than or equal to the second, jump to the target command
+ if (a <= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCNECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCNECommand.java
new file mode 100644
index 0000000..1da0475
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/double64/DCNECommand.java
@@ -0,0 +1,77 @@
+package org.jcnc.snow.vm.commands.control.double64;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The DCNECommand class implements the {@link Command} interface and represents a conditional jump command
+ * in the virtual machine that triggers if two values are not equal.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two double64 from the virtual machine stack.
+ *
If the two double64 are not equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class DCNECommand implements Command {
+ /**
+ * Default constructor for creating an instance of DCNECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public DCNECommand() {
+
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ double b = (double) operandStack.pop();
+ double a = (double) operandStack.pop();
+
+ // If the operands are not equal, jump to the target command
+ if (a != b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
From 63fab9f028bf9b6e27c85cd9fc2b3948ccaa4b7a Mon Sep 17 00:00:00 2001
From: Luke
Date: Wed, 25 Jun 2025 17:29:52 +0800
Subject: [PATCH 19/23] =?UTF-8?q?feat=EF=BC=9Avm=20=E5=A2=9E=E5=8A=A0=20fl?=
=?UTF-8?q?oat32=20=E6=AF=94=E8=BE=83=E6=8C=87=E4=BB=A4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/control/float32/FCECommand.java | 76 ++++++++++++++++++
.../commands/control/float32/FCGCommand.java | 76 ++++++++++++++++++
.../commands/control/float32/FCGECommand.java | 76 ++++++++++++++++++
.../commands/control/float32/FCLCommand.java | 76 ++++++++++++++++++
.../commands/control/float32/FCLECommand.java | 76 ++++++++++++++++++
.../commands/control/float32/FCNECommand.java | 77 +++++++++++++++++++
6 files changed, 457 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/float32/FCECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLECommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/control/float32/FCNECommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCECommand.java
new file mode 100644
index 0000000..6c8620d
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.float32;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The FCECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if they are equal, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two float32 from the virtual machine stack.
+ *
If the two float32 are equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class FCECommand implements Command {
+ /**
+ * Default constructor for creating an instance of FCECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public FCECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ float b = (float) operandStack.pop();
+ float a = (float) operandStack.pop();
+
+ // If the operands are equal, jump to the target command
+ if (a == b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGCommand.java
new file mode 100644
index 0000000..2b9b71f
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.float32;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The FCGCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two float32 from the virtual machine stack.
+ *
If the first float32 is greater than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class FCGCommand implements Command {
+ /**
+ * Default constructor for creating an instance of FCGCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public FCGCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ float b = (float) operandStack.pop();
+ float a = (float) operandStack.pop();
+
+ // If the first operand is greater than the second, jump to the target command
+ if (a > b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGECommand.java
new file mode 100644
index 0000000..45d5fc1
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCGECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.float32;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The FCGECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is greater than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two float32 from the virtual machine stack.
+ *
If the first float32 is greater than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class FCGECommand implements Command {
+ /**
+ * Default constructor for creating an instance of FCGECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public FCGECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ float b = (float) operandStack.pop();
+ float a = (float) operandStack.pop();
+
+ // If the first operand is greater than or equal to the second, jump to the target command
+ if (a >= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLCommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLCommand.java
new file mode 100644
index 0000000..26cc4bb
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLCommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.float32;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The FCLCommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two float32 from the virtual machine stack.
+ *
If the first float32 is less than the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class FCLCommand implements Command {
+ /**
+ * Default constructor for creating an instance of FCLCommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public FCLCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ float b = (float) operandStack.pop();
+ float a = (float) operandStack.pop();
+
+ // If the first operand is less than the second, jump to the target command
+ if (a < b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLECommand.java
new file mode 100644
index 0000000..becc5d5
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCLECommand.java
@@ -0,0 +1,76 @@
+package org.jcnc.snow.vm.commands.control.float32;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The FCLECommand class implements the {@link Command} interface and represents a conditional jump command in the virtual machine.
+ * This class compares two values from the stack, and if the first value is less than or equal to the second, it jumps to the specified target command.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two float32 from the virtual machine stack.
+ *
If the first float32 is less than or equal to the second, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class FCLECommand implements Command {
+ /**
+ * Default constructor for creating an instance of FCLECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public FCLECommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ float b = (float) operandStack.pop();
+ float a = (float) operandStack.pop();
+
+ // If the first operand is less than or equal to the second, jump to the target command
+ if (a <= b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCNECommand.java b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCNECommand.java
new file mode 100644
index 0000000..d75ac57
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/control/float32/FCNECommand.java
@@ -0,0 +1,77 @@
+package org.jcnc.snow.vm.commands.control.float32;
+
+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;
+import org.jcnc.snow.vm.utils.LoggingUtils;
+
+/**
+ * The FCNECommand class implements the {@link Command} interface and represents a conditional jump command
+ * in the virtual machine that triggers if two values are not equal.
+ *
+ *
Specific behavior:
+ *
+ *
Pops two float32 from the virtual machine stack.
+ *
If the two float32 are not equal, jumps to the target command.
+ *
Otherwise, the program continues with the next command.
+ *
+ */
+public class FCNECommand implements Command {
+ /**
+ * Default constructor for creating an instance of FCNECommand.
+ * This constructor is empty as no specific initialization is required.
+ */
+ public FCNECommand() {
+
+ // Empty constructor
+ }
+
+ /**
+ * Executes the virtual machine instruction's operation.
+ *
+ *
This method retrieves the necessary data from the virtual machine stack and local variable store based on the instruction's
+ * specific implementation, performs the operation, and updates the program counter (PC) to reflect the next instruction
+ * to be executed.
+ *
+ *
The parameters provided allow the command to manipulate the operand stack, modify the local variables, and control the flow
+ * of execution by updating the program counter.
+ *
+ *
The exact behavior of this method will depend on the specific instruction being executed (e.g., arithmetic, branching,
+ * function calls, etc.). For example, a `CALL` instruction will modify the call stack by pushing a new frame,
+ * while a `POP` instruction will remove an item from the operand stack.
+ *
+ * @param parts The array of instruction parameters, which usually includes the operator and related arguments
+ * (such as target addresses, values, or function names). These parameters may vary based on
+ * the instruction being executed.
+ * @param currentPC The current program counter-value, indicating the address of the instruction being executed.
+ * This value is typically incremented after the execution of each instruction to point to the next one.
+ * @param operandStack The virtual machine's operand stack manager, responsible for performing operations on the operand stack,
+ * such as pushing, popping, and peeking values.
+ * @param localVariableStore The local variable store, typically used to manage method-local variables during instruction execution.
+ * The store may not be used in every command but can be leveraged by instructions that require access
+ * to local variables.
+ * @param callStack The virtual machine's call stack, which keeps track of the method invocation hierarchy. It is used by
+ * instructions that involve method calls or returns (such as `CALL` and `RETURN` instructions).
+ * @return The updated program counter-value, typically the current program counter-value incremented by 1, unless the
+ * instruction modifies control flow (such as a `JUMP` or `CALL`), in which case it may return a new address
+ * corresponding to the target of the jump or the subroutine to call.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
+ // Parse the target command address
+ int target = Integer.parseInt(parts[1]);
+
+ // Pop the two operands from the stack
+ float b = (float) operandStack.pop();
+ float a = (float) operandStack.pop();
+
+ // If the operands are not equal, jump to the target command
+ if (a != b) {
+ LoggingUtils.logInfo("Jumping to command", String.valueOf(target));
+ return target;
+ }
+
+ return currentPC + 1;
+ }
+}
From e53ebeba335f3507042958b6b53f61d22768ad40 Mon Sep 17 00:00:00 2001
From: Luke
Date: Wed, 25 Jun 2025 18:21:44 +0800
Subject: [PATCH 20/23] =?UTF-8?q?feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=20region?=
=?UTF-8?q?=20=E6=8A=98=E5=8F=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../org/jcnc/snow/vm/engine/VMOpCode.java | 85 ++++++++++---------
1 file changed, 47 insertions(+), 38 deletions(-)
diff --git a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java
index 1b2f458..5080fee 100644
--- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java
+++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java
@@ -47,8 +47,8 @@ import org.jcnc.snow.vm.module.LocalVariableStore;
*
Each opcode represents a specific operation executed by the virtual machine.
*/
public class VMOpCode {
- // 1 Arithmetic Operations (1–80)
- // 1.1 int32 (1-10)
+ // region 1. Arithmetic Operations (1–80)
+ // region 1.1 int32 (1-10)
/**
* I_ADD Opcode: Represents the int32 addition operation in the virtual machine.
*
This opcode is implemented by the {@link IAddCommand} class, which defines its specific execution logic.
@@ -158,7 +158,9 @@ public class VMOpCode {
*
This opcode is typically used to negate an int32 value, making it a fundamental operation for arithmetic logic within the virtual machine.
*/
public static final int I_NEG = 7;
- // 1.2 long64 (11-20)
+
+ // endregion
+ // region 1.2 long64 (11-20)
/**
* L_ADD Opcode: Represents the long64 addition operation in the virtual machine.
*
This opcode is implemented by the {@link LAddCommand} class, which defines its specific execution logic.
@@ -275,7 +277,8 @@ public class VMOpCode {
*/
public static final int L_NEG = 17;
- // 1.3 short16 (21-30)
+ // endregion
+ // region 1.3 short16 (21-30)
/**
* S_ADD Opcode: Represents the short16 addition operation in the virtual machine.
*
This opcode is implemented by the {@link SAddCommand} class, which defines its specific execution logic.
@@ -392,7 +395,8 @@ public class VMOpCode {
*/
public static final int S_NEG = 27;
- // 1.4 byte8 (31-40)
+ // endregion
+ // region 1.4 byte8 (31-40)
/**
* B_ADD Opcode: Represents the byte8 addition operation in the virtual machine.
*
This opcode is implemented by the {@link BAddCommand} class, which defines its specific execution logic.
@@ -509,7 +513,8 @@ public class VMOpCode {
*/
public static final int B_NEG = 37;
- // 1.5 double64 (41-50)
+ // endregion
+ // region 1.5 double64 (41-50)
/**
* D_ADD Opcode: Represents the double64 precision floating-point addition operation in the virtual machine.
*
This opcode is implemented by the {@link DAddCommand} class, which defines its specific execution logic.
@@ -625,7 +630,8 @@ public class VMOpCode {
*/
public static final int D_NEG = 47;
- // 1.6 float32 (51-60)
+ // endregion
+ // region 1.6 float32 (51-60)
/**
* F_ADD Opcode: Represents the float32 addition operation in the virtual machine.
*
This opcode is implemented by the {@link FAddCommand} class, which defines its specific execution logic.
@@ -976,10 +982,10 @@ public class VMOpCode {
*/
public static final int B2I = 76;
-
-
- // 2. Bitwise Operations (81–90)
- // 2.1 int32 (81-85)
+ // endregion
+ // endregion
+ // region 2. Bitwise Operations (81–90)
+ // region 2.1 int32 (81-85)
/**
* I_AND Opcode: Represents the int32 bitwise AND operation in the virtual machine.
*
This opcode is implemented by the {@link IAndCommand} class, which defines its specific execution logic.
@@ -1039,7 +1045,8 @@ public class VMOpCode {
*/
public static final int I_XOR = 83;
- // 2.2 Long64 (86-90)
+ // endregion
+ // region 2.2 Long64 (86-90)
/**
* L_AND Opcode: Represents the long64 bitwise AND operation in the virtual machine.
*
This opcode is implemented by the {@link LAndCommand} class, which defines its specific execution logic.
@@ -1100,8 +1107,10 @@ public class VMOpCode {
public static final int L_XOR = 88;
- // 3. Control Flow Operations (91–110)
- // 3.1 JUMP (91-91)
+ // endregion
+ // endregion
+ // region 3. Control Flow Operations (91–110)
+ // region 3.1 JUMP (91-91)
/**
* JUMP Opcode: Represents an unconditional jump to a target instruction address.
*
This opcode is implemented by the {@link JumpCommand} class, which defines its specific execution logic.
@@ -1121,7 +1130,9 @@ public class VMOpCode {
*
*/
public static final int JUMP = 91;
- // 3.2 int32 (92-97)
+
+ // endregion
+ // region 3.2 int32 (92-97)
/**
* IC_E Opcode: Represents a conditional jump based on int32 equality.
*
This opcode is implemented by the {@link ICECommand} class, which defines its specific execution logic.
@@ -1248,7 +1259,9 @@ public class VMOpCode {
*
*/
public static final int IC_LE = 97;
- // 3.3 long64 (98-103)
+
+ // endregion
+ // region 3.3 long64 (98-103)
/**
* LC_E Opcode: Represents a conditional jump based on long64 equality.
*
This opcode is implemented by the {@link ICECommand} class, which defines its specific execution logic.
@@ -1376,8 +1389,10 @@ public class VMOpCode {
*/
public static final int LC_LE = 103;
- // 4. Stack Operations (111–150)
- // 4.1 PUSH (111-120)
+ // endregion
+ // endregion
+ // region 4. Stack Operations (111–150)
+ // region 4.1 PUSH (111-120)
/**
* I_PUSH Opcode: Represents a stack operation that pushes an int32 value onto the operand stack.
*
This opcode is implemented by the {@link IPushCommand} class, which defines its specific execution logic.
@@ -1510,7 +1525,9 @@ public class VMOpCode {
*
Ensuring stack balance during function calls or control flow transitions.
*
*/
- // 4.2 POP (121-125)
+
+ // endregion
+ // region 4.2 POP (121-125)
public static final int POP = 121;
/**
* DUP Opcode: Represents a stack operation that duplicates the top element of the operand stack.
@@ -1530,7 +1547,8 @@ public class VMOpCode {
*
Managing stack balance when performing operations that require repeated access to the same data.
*
*/
- // 4.3 DUP (126-130)
+ // endregion
+ // region 4.3 DUP (126-130)
public static final int DUP = 126;
/**
* SWAP Opcode: Represents a stack operation that swaps the top two values of the operand stack.
@@ -1551,10 +1569,14 @@ public class VMOpCode {
*
Ensuring proper operand placement for later instructions that depend on the order of stack elements.
*
*/
- // 4.4 SWAP (131-135)
+
+ // endregion
+ // region 4.4 SWAP (131-135)
public static final int SWAP = 131;
- // 5. Memory Operations (151–)
+ // endregion
+ // endregion
+ // region 5. Memory Operations (151–166)
/**
* I_STORE Opcode: Represents a store operation that saves an int32 value from the operand stack into the local variable store.
*
@@ -1576,8 +1598,6 @@ public class VMOpCode {
*
*/
public static final int I_STORE = 151;
-
-
/**
* L_STORE Opcode: Represents a store operation that stores a long64 value from the operand stack into the local variable store.
*
This opcode is implemented by the {@link LStoreCommand} class, which defines its specific execution logic.
@@ -1598,8 +1618,6 @@ public class VMOpCode {
*
*/
public static final int L_STORE = 152;
-
-
/**
* S_STORE Opcode: Represents a store operation that stores a short16 value from the operand stack into the local variable store.
*
This opcode is implemented by the {@link SStoreCommand} class, which defines its specific execution logic.
@@ -1620,8 +1638,6 @@ public class VMOpCode {
*
*/
public static final int S_STORE = 153;
-
-
/**
* B_STORE Opcode: Represents a store operation that stores a byte8 value from the operand stack into the local variable store.
*
This opcode is implemented by the {@link BStoreCommand} class, which defines its specific execution logic.
@@ -1642,8 +1658,6 @@ public class VMOpCode {
*
*/
public static final int B_STORE = 154;
-
-
/**
* D_STORE Opcode: Represents a store operation that stores a double64 value from the operand stack into the local variable store.
*
This opcode is implemented by the {@link DStoreCommand} class, which defines its specific execution logic.
@@ -1664,7 +1678,6 @@ public class VMOpCode {
*
*/
public static final int D_STORE = 155;
-
/**
* F_STORE Opcode: Represents a store operation that stores a float32 value from the operand stack into the local variable store.
*
This opcode is implemented by the {@link FStoreCommand} class, which defines its specific execution logic.
@@ -1685,8 +1698,6 @@ public class VMOpCode {
*
*/
public static final int F_STORE = 156;
-
-
/**
* I_LOAD Opcode: Represents a load operation that retrieves an int32 value from the local variable store and pushes it onto the operand stack.
*
This opcode is implemented by the {@link ILoadCommand} class, which defines its specific execution logic.
@@ -1807,7 +1818,7 @@ public class VMOpCode {
*
*/
public static final int F_LOAD = 166;
-
+ // endregion
/**
* MOV Opcode: Represents a move operation that transfers a value from one local variable to another within the local variable store.
*
This opcode is implemented by the {@link MovCommand} class, which defines its specific execution logic.
@@ -1828,6 +1839,7 @@ public class VMOpCode {
*
*/
public static final int MOV = 171;
+ // region 6. function call
/**
* CALL Opcode: Represents a function or subroutine call operation that transfers control to a specified function address.
*
This opcode is implemented by the {@link CallCommand} class, which defines its specific execution logic.
@@ -1885,10 +1897,7 @@ public class VMOpCode {
*
*/
public static final int HALT = 255;
-
-
- // VI. Function Operations (50–59)
-
+ // endregion
/**
* Default constructor for creating an instance of VMOpCode.
* This constructor is empty as no specific initialization is required.
From 3f5dd92af982a3d78af6d453d3ed564bb8979517 Mon Sep 17 00:00:00 2001
From: Luke
Date: Thu, 26 Jun 2025 12:14:47 +0800
Subject: [PATCH 21/23] =?UTF-8?q?style=EF=BC=9A=E8=B0=83=E6=95=B4=E9=97=B4?=
=?UTF-8?q?=E8=B7=9D=20VMOpCode.java?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../org/jcnc/snow/vm/engine/VMOpCode.java | 124 +++++++-----------
1 file changed, 47 insertions(+), 77 deletions(-)
diff --git a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java
index 5080fee..f5e8762 100644
--- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java
+++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java
@@ -47,8 +47,8 @@ import org.jcnc.snow.vm.module.LocalVariableStore;
*
Each opcode represents a specific operation executed by the virtual machine.
*/
public class VMOpCode {
- // region 1. Arithmetic Operations (1–80)
- // region 1.1 int32 (1-10)
+ // region 1. Arithmetic Operations (1–100)
+ // region 1.1 int32 (0-9)
/**
* I_ADD Opcode: Represents the int32 addition operation in the virtual machine.
*
This opcode is implemented by the {@link IAddCommand} class, which defines its specific execution logic.
@@ -63,7 +63,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic int32 addition tasks.
*/
- public static final int I_ADD = 1;
+ public static final int I_ADD = 0;
/**
* I_SUB Opcode: Represents the int32 subtraction operation in the virtual machine.
*
This opcode is implemented by the {@link ISubCommand} class, which defines its specific execution logic.
@@ -78,7 +78,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic int32 subtraction tasks.
*/
- public static final int I_SUB = 2;
+ public static final int I_SUB = 1;
/**
* I_MUL Opcode: Represents the int32 multiplication operation in the virtual machine.
*
This opcode is implemented by the {@link IMulCommand} class, which defines its specific execution logic.
@@ -93,7 +93,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic int32 multiplication tasks.
*/
- public static final int I_MUL = 3;
+ public static final int I_MUL = 2;
/**
* I_DIV Opcode: Represents the int32 division operation in the virtual machine.
*
This opcode is implemented by the {@link IDivCommand} class, which defines its specific execution logic.
@@ -109,7 +109,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic int32 division tasks.
*/
- public static final int I_DIV = 4;
+ public static final int I_DIV = 3;
/**
* I_MOD Opcode: Represents the int32 modulus (remainder) operation in the virtual machine.
*
This opcode is implemented by the {@link IModCommand} class, which defines its specific execution logic.
@@ -125,7 +125,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic int32 modulus (remainder) tasks.
*/
- public static final int I_MOD = 5;
+ public static final int I_MOD = 4;
/**
* I_INC Opcode: Represents the int32 increment operation for a local variable in the virtual machine.
*
This opcode is implemented by the {@link IIncCommand} class, which defines its specific execution logic.
@@ -142,8 +142,7 @@ public class VMOpCode {
*
*
This opcode is particularly useful for optimizing scenarios where a local variable, such as a counter or loop index, is frequently incremented.
*/
- public static final int I_INC = 6;
-
+ public static final int I_INC = 5;
/**
* I_NEG Opcode: Represents the int32 negation operation in the virtual machine.
*
This opcode is implemented by the {@link INegCommand} class, which defines its specific execution logic.
@@ -157,10 +156,10 @@ public class VMOpCode {
*
*
This opcode is typically used to negate an int32 value, making it a fundamental operation for arithmetic logic within the virtual machine.
*/
- public static final int I_NEG = 7;
-
+ public static final int I_NEG = 6;
// endregion
- // region 1.2 long64 (11-20)
+
+ // region 1.2 long64 (10-19)
/**
* L_ADD Opcode: Represents the long64 addition operation in the virtual machine.
*
This opcode is implemented by the {@link LAddCommand} class, which defines its specific execution logic.
@@ -175,8 +174,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic long64 addition tasks.
*/
- public static final int L_ADD = 11;
-
+ public static final int L_ADD = 10;
/**
* L_SUB Opcode: Represents the long64 subtraction operation in the virtual machine.
*
This opcode is implemented by the {@link LSubCommand} class, which defines its specific execution logic.
@@ -191,8 +189,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic long64 subtraction tasks.
*/
- public static final int L_SUB = 12;
-
+ public static final int L_SUB = 11;
/**
* L_MUL Opcode: Represents the long64 multiplication operation in the virtual machine.
*
This opcode is implemented by the {@link LMulCommand} class, which defines its specific execution logic.
@@ -207,8 +204,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic long64 multiplication tasks.
*/
- public static final int L_MUL = 13;
-
+ public static final int L_MUL = 12;
/**
* L_DIV Opcode: Represents the long64 division operation in the virtual machine.
*
This opcode is implemented by the {@link LDivCommand} class, which defines its specific execution logic.
@@ -224,8 +220,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic long64 division tasks.
*/
- public static final int L_DIV = 14;
-
+ public static final int L_DIV = 13;
/**
* L_MOD Opcode: Represents the long64 modulus (remainder) operation in the virtual machine.
*
This opcode is implemented by the {@link LModCommand} class, which defines its specific execution logic.
@@ -241,8 +236,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic long64 modulus (remainder) tasks.
*/
- public static final int L_MOD = 15;
-
+ public static final int L_MOD = 14;
/**
* L_INC Opcode: Represents the long64 increment operation for a local variable in the virtual machine.
*
This opcode is implemented by the {@link LIncCommand} class, which defines its specific execution logic.
@@ -259,9 +253,7 @@ public class VMOpCode {
*
*
This opcode is particularly useful for optimizing scenarios where a local `long64` variable, such as a counter or loop index, is frequently incremented.
*/
- public static final int L_INC = 16;
-
-
+ public static final int L_INC = 15;
/**
* L_NEG Opcode: Represents the long64 negation operation in the virtual machine.
*
This opcode is implemented by the {@link LNegCommand} class, which defines its specific execution logic.
@@ -275,10 +267,10 @@ public class VMOpCode {
*
*
This opcode is typically used to negate a long64 value, making it a fundamental operation for arithmetic logic within the virtual machine.
*/
- public static final int L_NEG = 17;
-
+ public static final int L_NEG = 16;
// endregion
- // region 1.3 short16 (21-30)
+
+ // region 1.3 short16 (20-29)
/**
* S_ADD Opcode: Represents the short16 addition operation in the virtual machine.
*
This opcode is implemented by the {@link SAddCommand} class, which defines its specific execution logic.
@@ -293,8 +285,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic short16 addition tasks.
*/
- public static final int S_ADD = 21;
-
+ public static final int S_ADD = 20;
/**
* S_SUB Opcode: Represents the short16 subtraction operation in the virtual machine.
*
This opcode is implemented by the {@link SSubCommand} class, which defines its specific execution logic.
@@ -309,8 +300,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic short16 subtraction tasks.
*/
- public static final int S_SUB = 22;
-
+ public static final int S_SUB = 21;
/**
* S_MUL Opcode: Represents the short16 multiplication operation in the virtual machine.
*
This opcode is implemented by the {@link SMulCommand} class, which defines its specific execution logic.
@@ -325,8 +315,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic short16 multiplication tasks.
*/
- public static final int S_MUL = 23;
-
+ public static final int S_MUL = 22;
/**
* S_DIV Opcode: Represents the short16 division operation in the virtual machine.
*
This opcode is implemented by the {@link SDivCommand} class, which defines its specific execution logic.
@@ -342,8 +331,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic short16 division tasks.
*/
- public static final int S_DIV = 24;
-
+ public static final int S_DIV = 23;
/**
* S_MOD Opcode: Represents the short16 modulus (remainder) operation in the virtual machine.
*
This opcode is implemented by the {@link SModCommand} class, which defines its specific execution logic.
@@ -359,8 +347,7 @@ public class VMOpCode {
*
This opcode is a fundamental arithmetic operation within the virtual machine's instruction set,
* primarily used to handle basic short16 modulus (remainder) tasks.
*/
- public static final int S_MOD = 25;
-
+ public static final int S_MOD = 24;
/**
* S_INC Opcode: Represents the short16 increment operation in the virtual machine.
*
This opcode is implemented by the {@link SIncCommand} class, which defines its specific execution logic.
@@ -378,8 +365,7 @@ public class VMOpCode {
*
This opcode is useful for scenarios where a local variable needs to be incremented, such as counters within loops,
* or for optimizing the modification of variables in tight loops.
*/
- public static final int S_INC = 26;
-
+ public static final int S_INC = 25;
/**
* S_NEG Opcode: Represents the short16 negation operation in the virtual machine.
*
This opcode is implemented by the {@link SNegCommand} class, which defines its specific execution logic.
@@ -393,9 +379,9 @@ public class VMOpCode {
*
*
This opcode is typically used to negate a short16 value, making it a fundamental operation for arithmetic logic within the virtual machine.
*/
- public static final int S_NEG = 27;
-
+ public static final int S_NEG = 26;
// endregion
+
// region 1.4 byte8 (31-40)
/**
* B_ADD Opcode: Represents the byte8 addition operation in the virtual machine.
@@ -412,7 +398,6 @@ public class VMOpCode {
* primarily used to handle basic byte8 addition tasks.
*/
public static final int B_ADD = 31;
-
/**
* B_SUB Opcode: Represents the byte8 subtraction operation in the virtual machine.
*
This opcode is implemented by the {@link BSubCommand} class, which defines its specific execution logic.
@@ -428,7 +413,6 @@ public class VMOpCode {
* primarily used to handle basic byte8 subtraction tasks.
*/
public static final int B_SUB = 32;
-
/**
* B_MUL Opcode: Represents the byte8 multiplication operation in the virtual machine.
*
This opcode is implemented by the {@link BMulCommand} class, which defines its specific execution logic.
@@ -444,7 +428,6 @@ public class VMOpCode {
* primarily used to handle basic byte8 multiplication tasks.
*/
public static final int B_MUL = 33;
-
/**
* B_DIV Opcode: Represents the byte8 division operation in the virtual machine.
*
This opcode is implemented by the {@link BDivCommand} class, which defines its specific execution logic.
@@ -461,7 +444,6 @@ public class VMOpCode {
* primarily used to handle basic byte8 division tasks.
*/
public static final int B_DIV = 34;
-
/**
* B_MOD Opcode: Represents the byte8 modulus (remainder) operation in the virtual machine.
*
This opcode is implemented by the {@link BModCommand} class, which defines its specific execution logic.
@@ -478,7 +460,6 @@ public class VMOpCode {
* primarily used to handle basic byte8 modulus (remainder) tasks.
*/
public static final int B_MOD = 35;
-
/**
* B_INC Opcode: Represents the byte8 increment operation for a local variable in the virtual machine.
*
This opcode is implemented by the {@link BIncCommand} class, which defines its specific execution logic.
@@ -496,8 +477,6 @@ public class VMOpCode {
*
This opcode is particularly useful for optimizing scenarios where a local `byte8` variable, such as a counter or loop index, is frequently incremented.
*/
public static final int B_INC = 36;
-
-
/**
* B_NEG Opcode: Represents the byte8 negation operation in the virtual machine.
*
This opcode is implemented by the {@link BNegCommand} class, which defines its specific execution logic.
@@ -512,8 +491,8 @@ public class VMOpCode {
*
This opcode is typically used to negate a byte8 value, making it a fundamental operation for arithmetic logic within the virtual machine.
*/
public static final int B_NEG = 37;
-
// endregion
+
// region 1.5 double64 (41-50)
/**
* D_ADD Opcode: Represents the double64 precision floating-point addition operation in the virtual machine.
@@ -530,7 +509,6 @@ public class VMOpCode {
* primarily used to handle basic double64 precision floating-point addition tasks.
*/
public static final int D_ADD = 41;
-
/**
* D_SUB Opcode: Represents the double64 precision floating-point subtraction operation in the virtual machine.
*
This opcode is implemented by the {@link DSubCommand} class, which defines its specific execution logic.
@@ -546,7 +524,6 @@ public class VMOpCode {
* primarily used to handle basic double64 precision floating-point subtraction tasks.
*/
public static final int D_SUB = 42;
-
/**
* D_MUL Opcode: Represents the double64 precision floating-point multiplication operation in the virtual machine.
*
This opcode is implemented by the {@link DMulCommand} class, which defines its specific execution logic.
@@ -562,7 +539,6 @@ public class VMOpCode {
* primarily used to handle basic double64 precision floating-point multiplication tasks.
*/
public static final int D_MUL = 43;
-
/**
* D_DIV Opcode: Represents the double64 precision floating-point division operation in the virtual machine.
*
This opcode is implemented by the {@link DDivCommand} class, which defines its specific execution logic.
@@ -579,7 +555,6 @@ public class VMOpCode {
* primarily used to handle basic double64 precision floating-point division tasks.
*/
public static final int D_DIV = 44;
-
/**
* D_MOD Opcode: Represents the double64 precision floating-point modulus (remainder) operation in the virtual machine.
*
This opcode is implemented by the {@link DModCommand} class, which defines its specific execution logic.
@@ -596,7 +571,6 @@ public class VMOpCode {
* primarily used to handle basic double64 precision floating-point modulus (remainder) tasks.
*/
public static final int D_MOD = 45;
-
/**
* D_INC Opcode: Represents the double64 increment operation for a local variable in the virtual machine.
*
This opcode is implemented by the {@link DIncCommand} class, which defines its specific execution logic.
@@ -614,7 +588,6 @@ public class VMOpCode {
*
This opcode is particularly useful for optimizing scenarios where a local `double64` variable, such as a counter or loop index, is frequently incremented.
*/
public static final int D_INC = 46;
-
/**
* D_NEG Opcode: Represents the double64 precision floating-point negation operation in the virtual machine.
*
This opcode is implemented by the {@link DNegCommand} class, which defines its specific execution logic.
@@ -629,8 +602,8 @@ public class VMOpCode {
*
This opcode is typically used to negate a double64 precision floating-point value, making it a fundamental operation for double64 precision arithmetic logic within the virtual machine.
*/
public static final int D_NEG = 47;
-
// endregion
+
// region 1.6 float32 (51-60)
/**
* F_ADD Opcode: Represents the float32 addition operation in the virtual machine.
@@ -726,7 +699,6 @@ public class VMOpCode {
*
This opcode is particularly useful for optimizing scenarios where a local `float32` variable, such as a counter or loop index, is frequently incremented.
*/
public static final int F_INC = 56;
-
/**
* F_NEG Opcode: Represents the float32 negation operation in the virtual machine.
*
This opcode is implemented by the {@link FNegCommand} class, which defines its specific execution logic.
@@ -741,7 +713,10 @@ public class VMOpCode {
*
This opcode is typically used to negate a float32 value, making it a fundamental operation for float32 arithmetic logic within the virtual machine.
*/
public static final int F_NEG = 57;
+ // endregion
+ // endregion
+ // region 2. Type Conversion Operation
/**
* I2L Opcode: Represents the type conversion operation from int32 to long64 in the virtual machine.
*
This opcode is implemented by the {@link I2LCommand} class, which defines its specific execution logic.
@@ -756,7 +731,6 @@ public class VMOpCode {
*
This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.
*/
public static final int I2L = 61;
-
/**
* I2S Opcode: Represents the type conversion operation from int32 to short16 in the virtual machine.
*
This opcode is implemented by the {@link I2SCommand} class, which defines its specific execution logic.
@@ -771,7 +745,6 @@ public class VMOpCode {
*
This opcode is typically used to narrow an int32 value to a short16 type when a smaller data representation is needed.
*/
public static final int I2S = 62;
-
/**
* I2B Opcode: Represents the type conversion operation from int32 to byte8 in the virtual machine.
*
This opcode is implemented by the {@link I2BCommand} class, which defines its specific execution logic.
@@ -786,7 +759,6 @@ public class VMOpCode {
*
This opcode is used to narrow an int32 value to a byte8 type, suitable when a smaller numeric type is required.
*/
public static final int I2B = 63;
-
/**
* I2D Opcode: Represents the type conversion operation from int32 to double64 in the virtual machine.
*
This opcode is implemented by the {@link I2DCommand} class, which defines its specific execution logic.
@@ -801,7 +773,6 @@ public class VMOpCode {
*
This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.
*/
public static final int I2D = 64;
-
/**
* I2F Opcode: Represents the type conversion operation from int32 to float32 in the virtual machine.
*
This opcode is implemented by the {@link I2FCommand} class, which defines its specific execution logic.
@@ -816,7 +787,6 @@ public class VMOpCode {
*
This opcode is used to convert an int32 value to a float32 type when floating-point arithmetic is required.
*/
public static final int I2F = 65;
-
/**
* L2I Opcode: Represents the type conversion operation from long64 to int32 in the virtual machine.
*
This opcode is implemented by the {@link L2ICommand} class, which defines its specific execution logic.
@@ -831,7 +801,6 @@ public class VMOpCode {
*
This opcode is typically used to narrow a long64 value to an int32 type for further integer operations.
*/
public static final int L2I = 66;
-
/**
* L2D Opcode: Represents the type conversion operation from long64 to double64 in the virtual machine.
*
This opcode is implemented by the {@link L2DCommand} class, which defines its specific execution logic.
@@ -981,9 +950,8 @@ public class VMOpCode {
*
This opcode is used to widen a byte8 value to an int32 type to ensure compatibility with integer-based operations.
*/
public static final int B2I = 76;
+ // endregion
- // endregion
- // endregion
// region 2. Bitwise Operations (81–90)
// region 2.1 int32 (81-85)
/**
@@ -1507,6 +1475,8 @@ public class VMOpCode {
*
*/
public static final int F_PUSH = 116;
+ // endregion
+ // region 4.2 POP (121-125)
/**
* I_POP Opcode: Represents a stack operation that removes the top element from the operand stack.
*
This opcode is implemented by the {@link PopCommand} class, which defines its specific execution logic.
@@ -1525,10 +1495,9 @@ public class VMOpCode {
*
Ensuring stack balance during function calls or control flow transitions.
*
*/
-
- // endregion
- // region 4.2 POP (121-125)
public static final int POP = 121;
+ // endregion
+ // region 4.3 DUP (126-130)
/**
* DUP Opcode: Represents a stack operation that duplicates the top element of the operand stack.
*
This opcode is implemented by the {@link DupCommand} class, which defines its specific execution logic.
@@ -1547,9 +1516,11 @@ public class VMOpCode {
*
Managing stack balance when performing operations that require repeated access to the same data.
*
*/
- // endregion
- // region 4.3 DUP (126-130)
+
public static final int DUP = 126;
+ // endregion
+
+ // region 4.4 SWAP (131-135)
/**
* SWAP Opcode: Represents a stack operation that swaps the top two values of the operand stack.
*
This opcode is implemented by the {@link SwapCommand} class, which defines its specific execution logic.
@@ -1569,12 +1540,9 @@ public class VMOpCode {
*
Ensuring proper operand placement for later instructions that depend on the order of stack elements.
*
*/
-
- // endregion
- // region 4.4 SWAP (131-135)
public static final int SWAP = 131;
-
// endregion
+
// endregion
// region 5. Memory Operations (151–166)
/**
@@ -1818,7 +1786,7 @@ public class VMOpCode {
*
*/
public static final int F_LOAD = 166;
- // endregion
+
/**
* MOV Opcode: Represents a move operation that transfers a value from one local variable to another within the local variable store.
*
This opcode is implemented by the {@link MovCommand} class, which defines its specific execution logic.
@@ -1839,7 +1807,8 @@ public class VMOpCode {
*
*/
public static final int MOV = 171;
- // region 6. function call
+ // endregion
+ // region 6. Function Call
/**
* CALL Opcode: Represents a function or subroutine call operation that transfers control to a specified function address.
*
This opcode is implemented by the {@link CallCommand} class, which defines its specific execution logic.
@@ -1898,6 +1867,7 @@ public class VMOpCode {
*/
public static final int HALT = 255;
// endregion
+
/**
* Default constructor for creating an instance of VMOpCode.
* This constructor is empty as no specific initialization is required.
From c17ccc7540c791e4f9a585f533bb66387aa1cc47 Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Thu, 26 Jun 2025 19:03:51 +0800
Subject: [PATCH 22/23] =?UTF-8?q?style:=20=E5=8C=85=E5=90=8D=20org.jcnc.sn?=
=?UTF-8?q?ow.compiler.backend.util=20=E5=90=8E=E9=9D=A2=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=20s?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../snow/compiler/backend/generator/BinaryOpGenerator.java | 4 ++--
.../jcnc/snow/compiler/backend/generator/CallGenerator.java | 2 +-
.../snow/compiler/backend/generator/CmpJumpGenerator.java | 4 ++--
.../jcnc/snow/compiler/backend/generator/JumpGenerator.java | 2 +-
.../snow/compiler/backend/generator/LoadConstGenerator.java | 2 +-
.../jcnc/snow/compiler/backend/generator/ReturnGenerator.java | 2 +-
.../snow/compiler/backend/generator/UnaryOpGenerator.java | 4 ++--
.../snow/compiler/backend/{util => utils}/IROpCodeMapper.java | 2 +-
.../jcnc/snow/compiler/backend/{util => utils}/OpHelper.java | 2 +-
9 files changed, 12 insertions(+), 12 deletions(-)
rename src/main/java/org/jcnc/snow/compiler/backend/{util => utils}/IROpCodeMapper.java (99%)
rename src/main/java/org/jcnc/snow/compiler/backend/{util => utils}/OpHelper.java (99%)
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/BinaryOpGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/BinaryOpGenerator.java
index 91a4d91..0d0a983 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/BinaryOpGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/BinaryOpGenerator.java
@@ -2,8 +2,8 @@ package org.jcnc.snow.compiler.backend.generator;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
-import org.jcnc.snow.compiler.backend.util.IROpCodeMapper;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.IROpCodeMapper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.ir.core.IRValue;
import org.jcnc.snow.compiler.ir.instruction.BinaryOperationInstruction;
import org.jcnc.snow.compiler.ir.value.IRConstant;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/CallGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/CallGenerator.java
index ff6961b..d455a4b 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/CallGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/CallGenerator.java
@@ -2,7 +2,7 @@ package org.jcnc.snow.compiler.backend.generator;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.ir.instruction.CallInstruction;
import org.jcnc.snow.compiler.ir.value.IRVirtualRegister;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/CmpJumpGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/CmpJumpGenerator.java
index e6a3e28..57437b4 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/CmpJumpGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/CmpJumpGenerator.java
@@ -1,7 +1,7 @@
package org.jcnc.snow.compiler.backend.generator;
-import org.jcnc.snow.compiler.backend.util.IROpCodeMapper;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.IROpCodeMapper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
import org.jcnc.snow.compiler.ir.instruction.IRCompareJumpInstruction;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/JumpGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/JumpGenerator.java
index 85d2907..c8426b3 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/JumpGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/JumpGenerator.java
@@ -1,6 +1,6 @@
package org.jcnc.snow.compiler.backend.generator;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
import org.jcnc.snow.compiler.ir.instruction.IRJumpInstruction;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/LoadConstGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/LoadConstGenerator.java
index 9e75f22..760422a 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/LoadConstGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/LoadConstGenerator.java
@@ -2,7 +2,7 @@ package org.jcnc.snow.compiler.backend.generator;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.ir.instruction.LoadConstInstruction;
import org.jcnc.snow.compiler.ir.value.IRConstant;
import org.jcnc.snow.compiler.ir.value.IRVirtualRegister;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/ReturnGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/ReturnGenerator.java
index a58af50..6a48847 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/ReturnGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/ReturnGenerator.java
@@ -2,7 +2,7 @@ package org.jcnc.snow.compiler.backend.generator;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.ir.instruction.ReturnInstruction;
import org.jcnc.snow.compiler.ir.value.IRVirtualRegister;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/generator/UnaryOpGenerator.java b/src/main/java/org/jcnc/snow/compiler/backend/generator/UnaryOpGenerator.java
index 46d1f53..a3de573 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/generator/UnaryOpGenerator.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/generator/UnaryOpGenerator.java
@@ -1,7 +1,7 @@
package org.jcnc.snow.compiler.backend.generator;
-import org.jcnc.snow.compiler.backend.util.IROpCodeMapper;
-import org.jcnc.snow.compiler.backend.util.OpHelper;
+import org.jcnc.snow.compiler.backend.utils.IROpCodeMapper;
+import org.jcnc.snow.compiler.backend.utils.OpHelper;
import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder;
import org.jcnc.snow.compiler.backend.core.InstructionGenerator;
import org.jcnc.snow.compiler.ir.instruction.UnaryOperationInstruction;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/util/IROpCodeMapper.java b/src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java
similarity index 99%
rename from src/main/java/org/jcnc/snow/compiler/backend/util/IROpCodeMapper.java
rename to src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java
index f2d2997..31c0033 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/util/IROpCodeMapper.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java
@@ -1,4 +1,4 @@
-package org.jcnc.snow.compiler.backend.util;
+package org.jcnc.snow.compiler.backend.utils;
import org.jcnc.snow.compiler.ir.core.IROpCode;
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/util/OpHelper.java b/src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java
similarity index 99%
rename from src/main/java/org/jcnc/snow/compiler/backend/util/OpHelper.java
rename to src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java
index 8c7bba9..9328218 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/util/OpHelper.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java
@@ -1,4 +1,4 @@
-package org.jcnc.snow.compiler.backend.util;
+package org.jcnc.snow.compiler.backend.utils;
import org.jcnc.snow.vm.engine.VMOpCode;
From c03761ed610fa6df9502091b08ce0a2f87102224 Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Thu, 26 Jun 2025 20:39:54 +0800
Subject: [PATCH 23/23] =?UTF-8?q?fix:=20byte=E3=80=81short=20=E8=BF=90?=
=?UTF-8?q?=E7=AE=97=E5=90=8E=E4=BC=9A=E5=8F=98=E4=B8=BA=20int=20=E7=9A=84?=
=?UTF-8?q?=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../jcnc/snow/vm/commands/arithmetic/byte8/BAddCommand.java | 2 +-
.../jcnc/snow/vm/commands/arithmetic/byte8/BDivCommand.java | 2 +-
.../jcnc/snow/vm/commands/arithmetic/byte8/BModCommand.java | 2 +-
.../jcnc/snow/vm/commands/arithmetic/byte8/BMulCommand.java | 2 +-
.../jcnc/snow/vm/commands/arithmetic/byte8/BSubCommand.java | 2 +-
.../snow/vm/commands/arithmetic/short16/SAddCommand.java | 6 +++---
.../snow/vm/commands/arithmetic/short16/SDivCommand.java | 2 +-
.../snow/vm/commands/arithmetic/short16/SModCommand.java | 2 +-
.../snow/vm/commands/arithmetic/short16/SMulCommand.java | 2 +-
.../snow/vm/commands/arithmetic/short16/SSubCommand.java | 2 +-
10 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BAddCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BAddCommand.java
index b05f809..f2a42ca 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BAddCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BAddCommand.java
@@ -50,7 +50,7 @@ public class BAddCommand implements Command {
byte a = (byte) operandStack.pop();
// Perform the addition and push the result back onto the stack
- operandStack.push(a + b);
+ operandStack.push((byte)(a + b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BDivCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BDivCommand.java
index ad24912..582951b 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BDivCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BDivCommand.java
@@ -56,7 +56,7 @@ public class BDivCommand implements Command {
}
// Perform the division and push the result back onto the stack
- operandStack.push(a / b);
+ operandStack.push((byte)(a / b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BModCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BModCommand.java
index 88b12bd..dd5892f 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BModCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BModCommand.java
@@ -50,7 +50,7 @@ public class BModCommand implements Command {
byte a = (byte) operandStack.pop();
// Perform the modulus operation and push the result back onto the stack
- operandStack.push(a % b);
+ operandStack.push((byte)(a % b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BMulCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BMulCommand.java
index e5de63a..0c6d9c3 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BMulCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BMulCommand.java
@@ -50,7 +50,7 @@ public class BMulCommand implements Command {
byte a = (byte) operandStack.pop();
// Perform the multiplication and push the result back onto the stack
- operandStack.push(a * b);
+ operandStack.push((byte)(a * b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BSubCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BSubCommand.java
index 091cafd..4c7957e 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BSubCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/byte8/BSubCommand.java
@@ -50,7 +50,7 @@ public class BSubCommand implements Command {
byte a = (byte) operandStack.pop();
// Perform the subtraction and push the result back onto the stack
- operandStack.push(a - b);
+ operandStack.push((byte)(a - b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SAddCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SAddCommand.java
index 4137a01..b4b1290 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SAddCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SAddCommand.java
@@ -46,11 +46,11 @@ public class SAddCommand implements Command {
@Override
public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) {
// Pop the top two operands from the stack
- Short b = (Short) operandStack.pop();
- Short a = (Short) operandStack.pop();
+ short b = (short) operandStack.pop();
+ short a = (short) operandStack.pop();
// Perform the addition and push the result back onto the stack
- operandStack.push(a + b);
+ operandStack.push((short)(a + b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SDivCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SDivCommand.java
index f14cefa..9c71b8c 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SDivCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SDivCommand.java
@@ -56,7 +56,7 @@ public class SDivCommand implements Command {
}
// Perform the division and push the result back onto the stack
- operandStack.push(a / b);
+ operandStack.push((short)(a / b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SModCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SModCommand.java
index 0047449..105b5bc 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SModCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SModCommand.java
@@ -50,7 +50,7 @@ public class SModCommand implements Command {
short a = (short) operandStack.pop();
// Perform the modulus operation and push the result back onto the stack
- operandStack.push(a % b);
+ operandStack.push((short)(a % b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SMulCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SMulCommand.java
index 1a2ac4e..f6c022d 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SMulCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SMulCommand.java
@@ -50,7 +50,7 @@ public class SMulCommand implements Command {
short a = (short) operandStack.pop();
// Perform the multiplication and push the result back onto the stack
- operandStack.push(a * b);
+ operandStack.push((short)(a * b));
// Return the updated program counter (next instruction)
return currentPC + 1;
diff --git a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SSubCommand.java b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SSubCommand.java
index 66c3295..53953b3 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SSubCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/arithmetic/short16/SSubCommand.java
@@ -50,7 +50,7 @@ public class SSubCommand implements Command {
short a = (short) operandStack.pop();
// Perform the subtraction and push the result back onto the stack
- operandStack.push(a - b);
+ operandStack.push((short)(a - b));
// Return the updated program counter (next instruction)
return currentPC + 1;