From f3f8a8de70bf41155851b6489631d0a6323833e4 Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 20:23:54 +0800
Subject: [PATCH 01/62] refactor: OpHelper.java
---
.../java/org/jcnc/snow/compiler/backend/utils/OpHelper.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java b/src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java
index de873b8..8dc5529 100644
--- a/src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java
+++ b/src/main/java/org/jcnc/snow/compiler/backend/utils/OpHelper.java
@@ -135,7 +135,6 @@ public final class OpHelper {
Map revmap = new HashMap<>(); // reverse map
OPCODE_MAP.forEach((key, value) -> revmap.put(Integer.parseInt(value), key));
-
OPCODE_NAME_MAP = Collections.unmodifiableMap(revmap);
}
@@ -197,7 +196,7 @@ public final class OpHelper {
public static String opcodeName(int code) {
String name = OPCODE_NAME_MAP.get(code);
if (name == null) {
- throw new IllegalStateException("Unknown opcode: " + name);
+ throw new IllegalStateException("Unknown opcode: " + code);
}
return name;
}
From 8340e2bacce510c15f51516ec1e5cce86e8b65e6 Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 20:28:12 +0800
Subject: [PATCH 02/62] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20byte8=20?=
=?UTF-8?q?=E8=BD=AC=20short16=E3=80=81long64=E3=80=81float32=E3=80=81doub?=
=?UTF-8?q?le64?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/type/conversion/B2DCommand.java | 47 +++++++++++++++++++
.../commands/type/conversion/B2FCommand.java | 47 +++++++++++++++++++
.../commands/type/conversion/B2LCommand.java | 47 +++++++++++++++++++
.../commands/type/conversion/B2SCommand.java | 47 +++++++++++++++++++
4 files changed, 188 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java
new file mode 100644
index 0000000..1ca0655
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2DCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * B2DCommand Opcode: Represents the type conversion operation from byte8 to double64 in the virtual machine.
+ *
This opcode is implemented by the {@link B2DCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a double64 value.
+ *
Push the converted double64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a double64 type to ensure compatibility with integer-based operations.
+ */
+public class B2DCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of B2DCommand.
+ */
+ public B2DCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the byte8 to double64 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ double convertedValue = (byte) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java
new file mode 100644
index 0000000..c61891b
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2FCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * B2FCommand Opcode: Represents the type conversion operation from byte8 to float32 in the virtual machine.
+ *
This opcode is implemented by the {@link B2FCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a float32 value.
+ *
Push the converted float32 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a float32 type to ensure compatibility with integer-based operations.
+ */
+public class B2FCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of B2FCommand.
+ */
+ public B2FCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the byte8 to float32 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ float convertedValue = (byte) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java
new file mode 100644
index 0000000..344b49d
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2LCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * B2LCommand Opcode: Represents the type conversion operation from byte8 to long64 in the virtual machine.
+ *
This opcode is implemented by the {@link B2LCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a long64 type to ensure compatibility with integer-based operations.
+ */
+public class B2LCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of B2LCommand.
+ */
+ public B2LCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the byte8 to long64 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ long convertedValue = (byte) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java
new file mode 100644
index 0000000..1f09ff9
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2SCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * B2SCommand Opcode: Represents the type conversion operation from byte8 to short16 in the virtual machine.
+ *
This opcode is implemented by the {@link B2SCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a short16 value.
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a short16 type to ensure compatibility with integer-based operations.
+ */
+public class B2SCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of B2SCommand.
+ */
+ public B2SCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the byte8 to short16 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ short convertedValue = (byte) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
From 9d7d03e91cf7dee327948268e8c2139196dd64ea Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 20:31:16 +0800
Subject: [PATCH 03/62] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20short16=20?=
=?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81long64=E3=80=81float32=E3=80=81double?=
=?UTF-8?q?64?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/type/conversion/S2BCommand.java | 47 +++++++++++++++++++
.../commands/type/conversion/S2DCommand.java | 47 +++++++++++++++++++
.../commands/type/conversion/S2FCommand.java | 47 +++++++++++++++++++
.../commands/type/conversion/S2LCommand.java | 47 +++++++++++++++++++
4 files changed, 188 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java
new file mode 100644
index 0000000..fa86e5f
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * S2BCommand Opcode: Represents the type conversion operation from short16 to byte8 in the virtual machine.
+ *
This opcode is implemented by the {@link S2BCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a byte8 value.
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to a byte8 type, facilitating subsequent integer arithmetic or comparison operations.
+ */
+public class S2BCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of S2BCommand.
+ */
+ public S2BCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the short16 to byte8 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ byte convertedValue = (byte) ((short) operandStack.pop());
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java
new file mode 100644
index 0000000..2f3381f
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * S2DCommand Opcode: Represents the type conversion operation from short16 to double64 in the virtual machine.
+ *
This opcode is implemented by the {@link S2DCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to an double64 value.
+ *
Push the converted double64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to an double64 type, facilitating subsequent integer arithmetic or comparison operations.
+ */
+public class S2DCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of S2DCommand.
+ */
+ public S2DCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the short16 to double64 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ double convertedValue = (short) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java
new file mode 100644
index 0000000..78fbb4a
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * S2FCommand Opcode: Represents the type conversion operation from short16 to float32 in the virtual machine.
+ *
This opcode is implemented by the {@link S2FCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to an float32 value.
+ *
Push the converted float32 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to an float32 type, facilitating subsequent integer arithmetic or comparison operations.
+ */
+public class S2FCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of S2FCommand.
+ */
+ public S2FCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the short16 to float32 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ float convertedValue = (short) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java
new file mode 100644
index 0000000..cec58e6
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java
@@ -0,0 +1,47 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * S2LCommand Opcode: Represents the type conversion operation from short16 to long64 in the virtual machine.
+ *
This opcode is implemented by the {@link S2LCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to a long64 type, facilitating subsequent integer arithmetic or comparison operations.
+ */
+public class S2LCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of S2LCommand.
+ */
+ public S2LCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the short16 to long64 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ long convertedValue = (short) operandStack.pop();
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
From ccc9e3e50f6f2942d045bb06a806b5a8613845dd Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 21:00:09 +0800
Subject: [PATCH 04/62] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20double64=20?=
=?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81short16?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/type/conversion/D2BCommand.java | 48 +++++++++++++++++++
.../commands/type/conversion/D2SCommand.java | 48 +++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java
new file mode 100644
index 0000000..7180d2e
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java
@@ -0,0 +1,48 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * D2BCommand Opcode: Represents the type conversion operation from double64 to byte8 in the virtual machine.
+ *
This opcode is implemented by the {@link D2BCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a double64 value to a byte8 type for further integer-based operations.
+ */
+public class D2BCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of D2BCommand.
+ */
+ public D2BCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the double64 to byte8 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ double value = (double) operandStack.pop();
+ byte convertedValue = (byte) value;
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java
new file mode 100644
index 0000000..ab11cf0
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java
@@ -0,0 +1,48 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * D2SCommand Opcode: Represents the type conversion operation from double64 to short16 in the virtual machine.
+ *
This opcode is implemented by the {@link D2SCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to an short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a double64 value to an short16 type for further integer-based operations.
+ */
+public class D2SCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of D2SCommand.
+ */
+ public D2SCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the double64 to short16 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ double value = (double) operandStack.pop();
+ short convertedValue = (short) value;
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
From ec94191153e0ec2233548b824c7328e5e5b59caa Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 21:02:30 +0800
Subject: [PATCH 05/62] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20float32=20?=
=?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81short16?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/type/conversion/F2BCommand.java | 48 +++++++++++++++++++
.../commands/type/conversion/F2SCommand.java | 48 +++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2BCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2SCommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2BCommand.java
new file mode 100644
index 0000000..5240f86
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2BCommand.java
@@ -0,0 +1,48 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * F2BCommand Opcode: Represents the type conversion operation from float32 to byte8 in the virtual machine.
+ *
This opcode is implemented by the {@link F2BCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to convert a float32 value to a byte8 type for further integer operations or comparisons.
+ */
+public class F2BCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of F2BCommand.
+ */
+ public F2BCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the float32 to byte8 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ float value = (float) operandStack.pop();
+ byte convertedValue = (byte) value;
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2SCommand.java
new file mode 100644
index 0000000..83a79b5
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2SCommand.java
@@ -0,0 +1,48 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * F2SCommand Opcode: Represents the type conversion operation from float32 to short16 in the virtual machine.
+ *
This opcode is implemented by the {@link F2SCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to convert a float32 value to a short16 type for further integer operations or comparisons.
+ */
+public class F2SCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of F2SCommand.
+ */
+ public F2SCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the float32 to short16 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ float value = (float) operandStack.pop();
+ short convertedValue = (short) value;
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
From fe9a8e750550617484b133a2c36e705397c1af48 Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 21:04:23 +0800
Subject: [PATCH 06/62] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20long64=20?=
=?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81short16?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../commands/type/conversion/L2BCommand.java | 48 +++++++++++++++++++
.../commands/type/conversion/L2SCommand.java | 48 +++++++++++++++++++
2 files changed, 96 insertions(+)
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2BCommand.java
create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2SCommand.java
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2BCommand.java
new file mode 100644
index 0000000..cde429c
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2BCommand.java
@@ -0,0 +1,48 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * L2BCommand Opcode: Represents the type conversion operation from long64 to byte8 in the virtual machine.
+ *
This opcode is implemented by the {@link L2BCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a byte8 value.
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a long64 value to a byte8 type for high-precision floating-point computations.
+ */
+public class L2BCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of L2BCommand.
+ */
+ public L2BCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the long64 to byte8 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ long value = (long) operandStack.pop();
+ byte convertedValue = (byte) value;
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2SCommand.java
new file mode 100644
index 0000000..54652d6
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2SCommand.java
@@ -0,0 +1,48 @@
+package org.jcnc.snow.vm.commands.type.conversion;
+
+import org.jcnc.snow.vm.interfaces.Command;
+import org.jcnc.snow.vm.module.CallStack;
+import org.jcnc.snow.vm.module.LocalVariableStore;
+import org.jcnc.snow.vm.module.OperandStack;
+
+/**
+ * L2SCommand Opcode: Represents the type conversion operation from long64 to short16 in the virtual machine.
+ *
This opcode is implemented by the {@link L2SCommand} class, which defines its specific execution logic.
+ *
+ *
Execution Steps:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a short16 value.
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a long64 value to a short16 type for high-precision floating-point computations.
+ */
+public class L2SCommand implements Command {
+
+ /**
+ * Default constructor for creating an instance of L2SCommand.
+ */
+ public L2SCommand() {
+ // Empty constructor
+ }
+
+ /**
+ * Executes the long64 to short16 conversion operation.
+ *
+ * @param parts The array of instruction parameters, which is not used in this operation.
+ * @param currentPC The current program counter, representing the instruction address.
+ * @param operandStack The operand stack of the virtual machine.
+ * @param localVariableStore The local variable store for managing method-local variables.
+ * @param callStack The call stack of the virtual machine.
+ * @return The updated program counter after execution.
+ */
+ @Override
+ public int execute(String[] parts, int currentPC, OperandStack operandStack,
+ LocalVariableStore localVariableStore, CallStack callStack) {
+ long value = (long) operandStack.pop();
+ short convertedValue = (short) value;
+ operandStack.push(convertedValue);
+ return currentPC + 1;
+ }
+}
From 3466c27c9e7ac081ff22b6b9bbe34876549305c0 Mon Sep 17 00:00:00 2001
From: zhangxun <1958638841@qq.com>
Date: Sat, 28 Jun 2025 21:07:07 +0800
Subject: [PATCH 07/62] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9=E6=8B=BC?=
=?UTF-8?q?=E5=86=99=E9=94=99=E8=AF=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java | 4 ++--
.../org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java | 4 ++--
.../org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java
index ab11cf0..41a8cec 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java
@@ -12,11 +12,11 @@ import org.jcnc.snow.vm.module.OperandStack;
*
Execution Steps:
*
*
Pop the top double64 value from the operand stack.
- *
Convert the double64 value to an short16 value (this may involve truncation).
+ *
Convert the double64 value to a short16 value (this may involve truncation).
*
Push the converted short16 value back onto the operand stack for subsequent operations.
*
*
- *
This opcode is used to narrow a double64 value to an short16 type for further integer-based operations.
+ *
This opcode is used to narrow a double64 value to a short16 type for further integer-based operations.
*/
public class D2SCommand implements Command {
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java
index 2f3381f..7703f26 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java
@@ -12,11 +12,11 @@ import org.jcnc.snow.vm.module.OperandStack;
*
Execution Steps:
*
*
Pop the top short16 value from the operand stack.
- *
Convert the short16 value to an double64 value.
+ *
Convert the short16 value to a double64 value.
*
Push the converted double64 value back onto the operand stack for subsequent operations.
*
*
- *
This opcode is used to widen a short16 value to an double64 type, facilitating subsequent integer arithmetic or comparison operations.
+ *
This opcode is used to widen a short16 value to a double64 type, facilitating subsequent integer arithmetic or comparison operations.
*/
public class S2DCommand implements Command {
diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java
index 78fbb4a..478e397 100644
--- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java
+++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java
@@ -12,11 +12,11 @@ import org.jcnc.snow.vm.module.OperandStack;
*
Execution Steps:
*
*
Pop the top short16 value from the operand stack.
- *
Convert the short16 value to an float32 value.
+ *
Convert the short16 value to a float32 value.
*
Push the converted float32 value back onto the operand stack for subsequent operations.
*
*
- *
This opcode is used to widen a short16 value to an float32 type, facilitating subsequent integer arithmetic or comparison operations.
+ *
This opcode is used to widen a short16 value to a float32 type, facilitating subsequent integer arithmetic or comparison operations.