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 01/37] =?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:

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

This opcode is used to widen a 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:

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

This opcode is used to widen a 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:

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

This opcode is used to widen a 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:

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

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 02/37] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20short16=20?= =?UTF-8?q?=E8=BD=AC=20byte8=E3=80=81long64=E3=80=81float32=E3=80=81double?= =?UTF-8?q?64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commands/type/conversion/S2BCommand.java | 47 +++++++++++++++++++ .../commands/type/conversion/S2DCommand.java | 47 +++++++++++++++++++ .../commands/type/conversion/S2FCommand.java | 47 +++++++++++++++++++ .../commands/type/conversion/S2LCommand.java | 47 +++++++++++++++++++ 4 files changed, 188 insertions(+) create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2FCommand.java create mode 100644 src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2LCommand.java diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java new file mode 100644 index 0000000..fa86e5f --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java @@ -0,0 +1,47 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * S2BCommand Opcode: Represents the type conversion operation from short16 to byte8 in the virtual machine. + *

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

+ * + *

Execution Steps:

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

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

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

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

+ * + *

Execution Steps:

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

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

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

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

+ * + *

Execution Steps:

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

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

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

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

+ * + *

Execution Steps:

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

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

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

+ *
    + *
  1. Pop the top double64 value from the operand stack.
  2. + *
  3. Convert the double64 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

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:

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

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 04/37] =?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:

+ *
    + *
  1. Pop the top float32 value from the operand stack.
  2. + *
  3. Convert the float32 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

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:

+ *
    + *
  1. Pop the top float32 value from the operand stack.
  2. + *
  3. Convert the float32 value to a short16 value (this may involve truncation).
  4. + *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

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 05/37] =?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:

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

This opcode is used to widen a 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:

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

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 06/37] =?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:

*
    *
  1. Pop the top double64 value from the operand stack.
  2. - *
  3. Convert the double64 value to an short16 value (this may involve truncation).
  4. + *
  5. Convert the double64 value to a short16 value (this may involve truncation).
  6. *
  7. Push the converted short16 value back onto the operand stack for subsequent operations.
  8. *
* - *

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:

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

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:

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

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.

*/ public class S2FCommand implements Command { From eee77ea45183276bebadcb8ebff22afdf77939b9 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:08:49 +0800 Subject: [PATCH 07/37] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index fa86e5f..d94eb8a 100644 --- 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 @@ -40,7 +40,8 @@ public class S2BCommand implements Command { @Override public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) { - byte convertedValue = (byte) ((short) operandStack.pop()); + short value = (short) operandStack.pop(); + byte convertedValue = (byte) value; operandStack.push(convertedValue); return currentPC + 1; } From fabde0026f79d5a8d88e11fbad1a119b2994e5f3 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Tue, 8 Jul 2025 20:19:45 +0800 Subject: [PATCH 08/37] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 200 ++++++++++-------- .../snow/vm/factories/CommandFactory.java | 29 ++- 2 files changed, 135 insertions(+), 94 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 c53f511..8b634ca 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2043,34 +2043,33 @@ public class VMOpCode { // endregion // region Type Conversion (0x00C0-0x00DF) - /** - * I2L Opcode: Represents the type conversion operation from int32 to long64 in the virtual machine. - *

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

- * - *

Execution Steps:

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

This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.

- */ - public static final int I2L = 0x00C0; - /** - * 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.

- * - *

Execution Steps:

- *
    - *
  1. Pop the top int32 value from the operand stack.
  2. - *
  3. Convert the int32 value to a short16 value (this may involve truncation).
  4. - *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. - *
- * - *

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 = 0x00C1; + // region Byte8 (0x00C0-0xC4) + + public static final int B2S = 0x00C0; + + public static final int B2I = 0x00C1; + + public static final int B2L = 0x00C2; + + public static final int B2F = 0x00C3; + + public static final int B2D = 0x00C4; + // endregion Byte8 + + // region Short16 (0x00C5-0xC9) + + public static final int S2B = 0x00C5; + + public static final int S2I = 0x00C6; + + public static final int S2L = 0x00C7; + + public static final int S2F = 0x00C8; + + public static final int S2D = 0x00C9; + // endregion Short16 + + // region Int32 (0x00CA-0xCE) /** * I2B Opcode: Represents the type conversion operation from int32 to byte8 in the virtual machine. *

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

@@ -2084,21 +2083,37 @@ 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 = 0x00C2; + public static final int I2B = 0x00CA; + /** - * 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.

+ * 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.

* *

Execution Steps:

*
    *
  1. Pop the top int32 value from the operand stack.
  2. - *
  3. Convert the int32 value to a double64 value.
  4. - *
  5. Push the converted double64 value back onto the operand stack for subsequent operations.
  6. + *
  7. Convert the int32 value to a short16 value (this may involve truncation).
  8. + *
  9. Push the converted short16 value back onto the operand stack for subsequent operations.
  10. *
* - *

This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.

+ *

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 I2D = 0x00C3; + public static final int I2S = 0x00CB; + + /** + * 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.

+ * + *

Execution Steps:

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

This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.

+ */ + public static final int I2L = 0x00CC; /** * 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.

@@ -2112,7 +2127,29 @@ 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 = 0x00C4; + public static final int I2F = 0x00CD; + /** + * 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.

+ * + *

Execution Steps:

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

This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.

+ */ + public static final int I2D = 0x00CE; + // endregion Int32 + + // region Long64 (0x00CF-0xD3) + + public static final int L2B = 0x00CF; + + public static final int L2S = 0x00D0; + /** * L2I Opcode: Represents the type conversion operation from long64 to int32 in the virtual machine. *

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

@@ -2126,21 +2163,7 @@ 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 = 0x00C5; - /** - * 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.

- * - *

Execution Steps:

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

This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.

- */ - public static final int L2D = 0x00C6; + public static final int L2I = 0x00D1; /** * L2F Opcode: Represents the type conversion operation from long64 to float32 in the virtual machine. *

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

@@ -2154,7 +2177,29 @@ public class VMOpCode { * *

This opcode is used to convert a long64 value to a float32 type, typically for floating-point arithmetic involving long values.

*/ - public static final int L2F = 0x00C7; + public static final int L2F = 0x00D2; + /** + * L2D Opcode: Represents the type conversion operation from long64 to double64 in the virtual machine. + *

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

+ * + *

Execution Steps:

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

This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.

+ */ + public static final int L2D = 0x00D3; + // endregion Long64 + + // region Float32 (0x00D4-0xD8) + + public static final int F2B = 0x00D4; + + public static final int F2S = 0x00D5; + /** * F2I Opcode: Represents the type conversion operation from float32 to int32 in the virtual machine. *

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

@@ -2168,7 +2213,7 @@ public class VMOpCode { * *

This opcode is used to convert a float32 value to an int32 type for further integer-based operations or comparisons.

*/ - public static final int F2I = 0x00C8; + public static final int F2I = 0x00D6; /** * F2L Opcode: Represents the type conversion operation from float32 to long64 in the virtual machine. *

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

@@ -2182,7 +2227,7 @@ public class VMOpCode { * *

This opcode is used to widen a float32 value to a long64 type, which is useful when operations require a larger numeric range.

*/ - public static final int F2L = 0x00C9; + public static final int F2L = 0x00D7; /** * F2D Opcode: Represents the type conversion operation from float32 to double64 in the virtual machine. *

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

@@ -2196,7 +2241,15 @@ public class VMOpCode { * *

This opcode is used to promote a float32 value to a double64 type, thereby increasing precision for floating-point computations.

*/ - public static final int F2D = 0x00CA; + public static final int F2D = 0x00D8; + // endregion Float32 + + // region Double64 (0x00D9-0xDD) + + public static final int D2B = 0x00D9; + + public static final int D2S = 0x00DA; + /** * D2I Opcode: Represents the type conversion operation from double64 to int32 in the virtual machine. *

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

@@ -2210,7 +2263,7 @@ public class VMOpCode { * *

This opcode is used to narrow a double64 value to an int32 type for further integer-based processing.

*/ - public static final int D2I = 0x00CB; + public static final int D2I = 0x00DB; /** * D2L Opcode: Represents the type conversion operation from double64 to long64 in the virtual machine. *

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

@@ -2224,7 +2277,7 @@ public class VMOpCode { * *

This opcode is used to narrow a double64 value to a long64 type, which can then be used for integer operations.

*/ - public static final int D2L = 0x00CC; + public static final int D2L = 0x00DC; /** * D2F Opcode: Represents the type conversion operation from double64 to float32 in the virtual machine. *

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

@@ -2238,36 +2291,9 @@ public class VMOpCode { * *

This opcode is used to narrow a double64 value to a float32 type when lower precision floating-point arithmetic is acceptable.

*/ - public static final int D2F = 0x00CD; - /** - * S2I Opcode: Represents the type conversion operation from short16 to int32 in the virtual machine. - *

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

- * - *

Execution Steps:

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

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

- */ - public static final int S2I = 0x00CE; - /** - * B2I Opcode: Represents the type conversion operation from byte8 to int32 in the virtual machine. - *

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

- * - *

Execution Steps:

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

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 = 0x00CF; - // endregion + public static final int D2F = 0x00DD; + // endregion Double64 + // endregion Conversion // region Stack Control (0x0100-0x01FF) /** diff --git a/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java b/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java index a5af00b..4054a11 100644 --- a/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java +++ b/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java @@ -207,26 +207,41 @@ public class CommandFactory { // endregion // region Type Conversion (0x00C0-0x00DF) - COMMANDS[VMOpCode.I2L] = new I2LCommand(); - COMMANDS[VMOpCode.I2S] = new I2SCommand(); + COMMANDS[VMOpCode.B2S] = new B2SCommand(); + COMMANDS[VMOpCode.B2I] = new B2ICommand(); + COMMANDS[VMOpCode.B2L] = new B2LCommand(); + COMMANDS[VMOpCode.B2F] = new B2FCommand(); + COMMANDS[VMOpCode.B2D] = new B2DCommand(); + + COMMANDS[VMOpCode.S2B] = new S2BCommand(); + COMMANDS[VMOpCode.S2I] = new S2ICommand(); + COMMANDS[VMOpCode.S2L] = new S2LCommand(); + COMMANDS[VMOpCode.S2F] = new S2FCommand(); + COMMANDS[VMOpCode.S2D] = new S2DCommand(); + COMMANDS[VMOpCode.I2B] = new I2BCommand(); - COMMANDS[VMOpCode.I2D] = new I2DCommand(); + COMMANDS[VMOpCode.I2S] = new I2SCommand(); + COMMANDS[VMOpCode.I2L] = new I2LCommand(); COMMANDS[VMOpCode.I2F] = new I2FCommand(); + COMMANDS[VMOpCode.I2D] = new I2DCommand(); + COMMANDS[VMOpCode.L2B] = new L2BCommand(); + COMMANDS[VMOpCode.L2S] = new L2SCommand(); COMMANDS[VMOpCode.L2I] = new L2ICommand(); - COMMANDS[VMOpCode.L2D] = new L2DCommand(); COMMANDS[VMOpCode.L2F] = new L2FCommand(); + COMMANDS[VMOpCode.L2D] = new L2DCommand(); + COMMANDS[VMOpCode.F2B] = new F2BCommand(); + COMMANDS[VMOpCode.F2S] = new F2SCommand(); COMMANDS[VMOpCode.F2I] = new F2ICommand(); COMMANDS[VMOpCode.F2L] = new F2LCommand(); COMMANDS[VMOpCode.F2D] = new F2DCommand(); + COMMANDS[VMOpCode.D2B] = new D2BCommand(); + COMMANDS[VMOpCode.D2S] = new D2SCommand(); COMMANDS[VMOpCode.D2I] = new D2ICommand(); COMMANDS[VMOpCode.D2L] = new D2LCommand(); COMMANDS[VMOpCode.D2F] = new D2FCommand(); - - COMMANDS[VMOpCode.S2I] = new S2ICommand(); - COMMANDS[VMOpCode.B2I] = new B2ICommand(); // endregion // region Stack Control (0x0100-0x01FF) From 2289cf3ee4b0c6a9fbcd88dbd733ff7092a5577d Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 20:28:12 +0800 Subject: [PATCH 09/37] =?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:

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

This opcode is used to widen a 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:

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

This opcode is used to widen a 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:

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

This opcode is used to widen a 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:

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

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

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

+ * + *

Execution Steps:

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

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

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

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

+ * + *

Execution Steps:

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

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

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

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

+ * + *

Execution Steps:

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

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

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

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

+ * + *

Execution Steps:

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

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

+ */ +public class S2LCommand implements Command { + + /** + * Default constructor for creating an instance of S2LCommand. + */ + public S2LCommand() { + // Empty constructor + } + + /** + * Executes the short16 to long64 conversion operation. + * + * @param parts The array of instruction parameters, which is not used in this operation. + * @param currentPC The current program counter, representing the instruction address. + * @param operandStack The operand stack of the virtual machine. + * @param localVariableStore The local variable store for managing method-local variables. + * @param callStack The call stack of the virtual machine. + * @return The updated program counter after execution. + */ + @Override + public int execute(String[] parts, int currentPC, OperandStack operandStack, + LocalVariableStore localVariableStore, CallStack callStack) { + long convertedValue = (short) operandStack.pop(); + operandStack.push(convertedValue); + return currentPC + 1; + } +} From 4595583ca4bba4e318124536891702cfe81347ed Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:00:09 +0800 Subject: [PATCH 11/37] =?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:

+ *
    + *
  1. Pop the top double64 value from the operand stack.
  2. + *
  3. Convert the double64 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

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:

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

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 85fae69c971dabe06a3cebdd7276496d9b115252 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:02:30 +0800 Subject: [PATCH 12/37] =?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:

+ *
    + *
  1. Pop the top float32 value from the operand stack.
  2. + *
  3. Convert the float32 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

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:

+ *
    + *
  1. Pop the top float32 value from the operand stack.
  2. + *
  3. Convert the float32 value to a short16 value (this may involve truncation).
  4. + *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

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 9c69c1f37ba6cd5f718ec1a639e0d6781bc1f0a0 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:04:23 +0800 Subject: [PATCH 13/37] =?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:

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

This opcode is used to widen a 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:

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

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 872865268b2db68422c0bfc3d8ccb91ae4ca4d65 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:07:07 +0800 Subject: [PATCH 14/37] =?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:

*
    *
  1. Pop the top double64 value from the operand stack.
  2. - *
  3. Convert the double64 value to an short16 value (this may involve truncation).
  4. + *
  5. Convert the double64 value to a short16 value (this may involve truncation).
  6. *
  7. Push the converted short16 value back onto the operand stack for subsequent operations.
  8. *
* - *

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:

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

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:

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

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.

*/ public class S2FCommand implements Command { From f382b2bc5455f680867e49235793e1bb8fce755c Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Sat, 28 Jun 2025 21:08:49 +0800 Subject: [PATCH 15/37] =?UTF-8?q?style:=20=E7=BB=9F=E4=B8=80=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/commands/type/conversion/S2BCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index fa86e5f..d94eb8a 100644 --- 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 @@ -40,7 +40,8 @@ public class S2BCommand implements Command { @Override public int execute(String[] parts, int currentPC, OperandStack operandStack, LocalVariableStore localVariableStore, CallStack callStack) { - byte convertedValue = (byte) ((short) operandStack.pop()); + short value = (short) operandStack.pop(); + byte convertedValue = (byte) value; operandStack.push(convertedValue); return currentPC + 1; } From 4f63f88b400de03baf0e47f09e5fb608960068dc Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Tue, 8 Jul 2025 20:19:45 +0800 Subject: [PATCH 16/37] =?UTF-8?q?feat:=20=E8=A1=A5=E5=85=85=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E6=95=B0=E5=80=BC=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 200 ++++++++++-------- .../snow/vm/factories/CommandFactory.java | 29 ++- 2 files changed, 135 insertions(+), 94 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 c53f511..8b634ca 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2043,34 +2043,33 @@ public class VMOpCode { // endregion // region Type Conversion (0x00C0-0x00DF) - /** - * I2L Opcode: Represents the type conversion operation from int32 to long64 in the virtual machine. - *

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

- * - *

Execution Steps:

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

This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.

- */ - public static final int I2L = 0x00C0; - /** - * 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.

- * - *

Execution Steps:

- *
    - *
  1. Pop the top int32 value from the operand stack.
  2. - *
  3. Convert the int32 value to a short16 value (this may involve truncation).
  4. - *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. - *
- * - *

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 = 0x00C1; + // region Byte8 (0x00C0-0xC4) + + public static final int B2S = 0x00C0; + + public static final int B2I = 0x00C1; + + public static final int B2L = 0x00C2; + + public static final int B2F = 0x00C3; + + public static final int B2D = 0x00C4; + // endregion Byte8 + + // region Short16 (0x00C5-0xC9) + + public static final int S2B = 0x00C5; + + public static final int S2I = 0x00C6; + + public static final int S2L = 0x00C7; + + public static final int S2F = 0x00C8; + + public static final int S2D = 0x00C9; + // endregion Short16 + + // region Int32 (0x00CA-0xCE) /** * I2B Opcode: Represents the type conversion operation from int32 to byte8 in the virtual machine. *

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

@@ -2084,21 +2083,37 @@ 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 = 0x00C2; + public static final int I2B = 0x00CA; + /** - * 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.

+ * 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.

* *

Execution Steps:

*
    *
  1. Pop the top int32 value from the operand stack.
  2. - *
  3. Convert the int32 value to a double64 value.
  4. - *
  5. Push the converted double64 value back onto the operand stack for subsequent operations.
  6. + *
  7. Convert the int32 value to a short16 value (this may involve truncation).
  8. + *
  9. Push the converted short16 value back onto the operand stack for subsequent operations.
  10. *
* - *

This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.

+ *

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 I2D = 0x00C3; + public static final int I2S = 0x00CB; + + /** + * 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.

+ * + *

Execution Steps:

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

This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.

+ */ + public static final int I2L = 0x00CC; /** * 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.

@@ -2112,7 +2127,29 @@ 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 = 0x00C4; + public static final int I2F = 0x00CD; + /** + * 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.

+ * + *

Execution Steps:

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

This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.

+ */ + public static final int I2D = 0x00CE; + // endregion Int32 + + // region Long64 (0x00CF-0xD3) + + public static final int L2B = 0x00CF; + + public static final int L2S = 0x00D0; + /** * L2I Opcode: Represents the type conversion operation from long64 to int32 in the virtual machine. *

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

@@ -2126,21 +2163,7 @@ 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 = 0x00C5; - /** - * 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.

- * - *

Execution Steps:

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

This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.

- */ - public static final int L2D = 0x00C6; + public static final int L2I = 0x00D1; /** * L2F Opcode: Represents the type conversion operation from long64 to float32 in the virtual machine. *

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

@@ -2154,7 +2177,29 @@ public class VMOpCode { * *

This opcode is used to convert a long64 value to a float32 type, typically for floating-point arithmetic involving long values.

*/ - public static final int L2F = 0x00C7; + public static final int L2F = 0x00D2; + /** + * L2D Opcode: Represents the type conversion operation from long64 to double64 in the virtual machine. + *

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

+ * + *

Execution Steps:

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

This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.

+ */ + public static final int L2D = 0x00D3; + // endregion Long64 + + // region Float32 (0x00D4-0xD8) + + public static final int F2B = 0x00D4; + + public static final int F2S = 0x00D5; + /** * F2I Opcode: Represents the type conversion operation from float32 to int32 in the virtual machine. *

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

@@ -2168,7 +2213,7 @@ public class VMOpCode { * *

This opcode is used to convert a float32 value to an int32 type for further integer-based operations or comparisons.

*/ - public static final int F2I = 0x00C8; + public static final int F2I = 0x00D6; /** * F2L Opcode: Represents the type conversion operation from float32 to long64 in the virtual machine. *

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

@@ -2182,7 +2227,7 @@ public class VMOpCode { * *

This opcode is used to widen a float32 value to a long64 type, which is useful when operations require a larger numeric range.

*/ - public static final int F2L = 0x00C9; + public static final int F2L = 0x00D7; /** * F2D Opcode: Represents the type conversion operation from float32 to double64 in the virtual machine. *

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

@@ -2196,7 +2241,15 @@ public class VMOpCode { * *

This opcode is used to promote a float32 value to a double64 type, thereby increasing precision for floating-point computations.

*/ - public static final int F2D = 0x00CA; + public static final int F2D = 0x00D8; + // endregion Float32 + + // region Double64 (0x00D9-0xDD) + + public static final int D2B = 0x00D9; + + public static final int D2S = 0x00DA; + /** * D2I Opcode: Represents the type conversion operation from double64 to int32 in the virtual machine. *

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

@@ -2210,7 +2263,7 @@ public class VMOpCode { * *

This opcode is used to narrow a double64 value to an int32 type for further integer-based processing.

*/ - public static final int D2I = 0x00CB; + public static final int D2I = 0x00DB; /** * D2L Opcode: Represents the type conversion operation from double64 to long64 in the virtual machine. *

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

@@ -2224,7 +2277,7 @@ public class VMOpCode { * *

This opcode is used to narrow a double64 value to a long64 type, which can then be used for integer operations.

*/ - public static final int D2L = 0x00CC; + public static final int D2L = 0x00DC; /** * D2F Opcode: Represents the type conversion operation from double64 to float32 in the virtual machine. *

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

@@ -2238,36 +2291,9 @@ public class VMOpCode { * *

This opcode is used to narrow a double64 value to a float32 type when lower precision floating-point arithmetic is acceptable.

*/ - public static final int D2F = 0x00CD; - /** - * S2I Opcode: Represents the type conversion operation from short16 to int32 in the virtual machine. - *

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

- * - *

Execution Steps:

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

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

- */ - public static final int S2I = 0x00CE; - /** - * B2I Opcode: Represents the type conversion operation from byte8 to int32 in the virtual machine. - *

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

- * - *

Execution Steps:

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

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 = 0x00CF; - // endregion + public static final int D2F = 0x00DD; + // endregion Double64 + // endregion Conversion // region Stack Control (0x0100-0x01FF) /** diff --git a/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java b/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java index a5af00b..4054a11 100644 --- a/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java +++ b/src/main/java/org/jcnc/snow/vm/factories/CommandFactory.java @@ -207,26 +207,41 @@ public class CommandFactory { // endregion // region Type Conversion (0x00C0-0x00DF) - COMMANDS[VMOpCode.I2L] = new I2LCommand(); - COMMANDS[VMOpCode.I2S] = new I2SCommand(); + COMMANDS[VMOpCode.B2S] = new B2SCommand(); + COMMANDS[VMOpCode.B2I] = new B2ICommand(); + COMMANDS[VMOpCode.B2L] = new B2LCommand(); + COMMANDS[VMOpCode.B2F] = new B2FCommand(); + COMMANDS[VMOpCode.B2D] = new B2DCommand(); + + COMMANDS[VMOpCode.S2B] = new S2BCommand(); + COMMANDS[VMOpCode.S2I] = new S2ICommand(); + COMMANDS[VMOpCode.S2L] = new S2LCommand(); + COMMANDS[VMOpCode.S2F] = new S2FCommand(); + COMMANDS[VMOpCode.S2D] = new S2DCommand(); + COMMANDS[VMOpCode.I2B] = new I2BCommand(); - COMMANDS[VMOpCode.I2D] = new I2DCommand(); + COMMANDS[VMOpCode.I2S] = new I2SCommand(); + COMMANDS[VMOpCode.I2L] = new I2LCommand(); COMMANDS[VMOpCode.I2F] = new I2FCommand(); + COMMANDS[VMOpCode.I2D] = new I2DCommand(); + COMMANDS[VMOpCode.L2B] = new L2BCommand(); + COMMANDS[VMOpCode.L2S] = new L2SCommand(); COMMANDS[VMOpCode.L2I] = new L2ICommand(); - COMMANDS[VMOpCode.L2D] = new L2DCommand(); COMMANDS[VMOpCode.L2F] = new L2FCommand(); + COMMANDS[VMOpCode.L2D] = new L2DCommand(); + COMMANDS[VMOpCode.F2B] = new F2BCommand(); + COMMANDS[VMOpCode.F2S] = new F2SCommand(); COMMANDS[VMOpCode.F2I] = new F2ICommand(); COMMANDS[VMOpCode.F2L] = new F2LCommand(); COMMANDS[VMOpCode.F2D] = new F2DCommand(); + COMMANDS[VMOpCode.D2B] = new D2BCommand(); + COMMANDS[VMOpCode.D2S] = new D2SCommand(); COMMANDS[VMOpCode.D2I] = new D2ICommand(); COMMANDS[VMOpCode.D2L] = new D2LCommand(); COMMANDS[VMOpCode.D2F] = new D2FCommand(); - - COMMANDS[VMOpCode.S2I] = new S2ICommand(); - COMMANDS[VMOpCode.B2I] = new B2ICommand(); // endregion // region Stack Control (0x0100-0x01FF) From 9026b2deb336dfb888016faf79008d3cb22dc702 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 16:04:35 +0800 Subject: [PATCH 17/37] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20long64=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 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 8b634ca..2bf7ec5 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2145,11 +2145,34 @@ public class VMOpCode { // endregion Int32 // region Long64 (0x00CF-0xD3) - + /** + * L2B 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:

+ *
    + *
  1. Pop the top long64 value from the operand stack.
  2. + *
  3. Convert the long64 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to narrow a long64 value to a byte8 type, suitable when a smaller numeric type is required.

+ */ public static final int L2B = 0x00CF; - + /** + * L2S 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:

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

This opcode is used to narrow a long64 value to a short16 type, suitable when a smaller numeric type is required.

+ */ public static final int L2S = 0x00D0; - /** * 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.

From efc88b33e3672435a0ef188f0236e60572d3ce2b Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 16:08:21 +0800 Subject: [PATCH 18/37] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20double64=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 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 2bf7ec5..fcf9e49 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2268,9 +2268,33 @@ public class VMOpCode { // endregion Float32 // region Double64 (0x00D9-0xDD) - + /** + * D2B 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:

+ *
    + *
  1. Pop the top double64 value from the operand stack.
  2. + *
  3. Convert the double64 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to narrow a double64 value to a byte8 type for further integer-based processing.

+ */ public static final int D2B = 0x00D9; - + /** + * D2I Opcode: Represents the type conversion operation from double64 to short16 in the virtual machine. + *

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

+ * + *

Execution Steps:

+ *
    + *
  1. Pop the top double64 value from the operand stack.
  2. + *
  3. Convert the double64 value to a short16 value (this may involve truncation).
  4. + *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to narrow a double64 value to a short16 type for further integer-based processing.

+ */ public static final int D2S = 0x00DA; /** From cd61fdf295b2679d7643bddca0b2644071b1575e Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 16:10:35 +0800 Subject: [PATCH 19/37] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20float32=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 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 fcf9e49..3fa44e2 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2218,11 +2218,34 @@ public class VMOpCode { // endregion Long64 // region Float32 (0x00D4-0xD8) - + /** + * F2B 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:

+ *
    + *
  1. Pop the top float32 value from the operand stack.
  2. + *
  3. Convert the float32 value to a byte8 value (this may involve truncation).
  4. + *
  5. Push the converted byte8 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to convert a float32 value to a byte8 type for further integer-based operations or comparisons.

+ */ public static final int F2B = 0x00D4; - + /** + * F2S 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:

+ *
    + *
  1. Pop the top float32 value from the operand stack.
  2. + *
  3. Convert the float32 value to a short16 value (this may involve truncation).
  4. + *
  5. Push the converted short16 value back onto the operand stack for subsequent operations.
  6. + *
+ * + *

This opcode is used to convert a float32 value to a short16 type for further integer-based operations or comparisons.

+ */ public static final int F2S = 0x00D5; - /** * F2I Opcode: Represents the type conversion operation from float32 to int32 in the virtual machine. *

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

@@ -2296,7 +2319,6 @@ public class VMOpCode { *

This opcode is used to narrow a double64 value to a short16 type for further integer-based processing.

*/ public static final int D2S = 0x00DA; - /** * D2I Opcode: Represents the type conversion operation from double64 to int32 in the virtual machine. *

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

From c5810bce7b6c6437a5092ffe55a2a2e8d6ae07a8 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 16:11:41 +0800 Subject: [PATCH 20/37] =?UTF-8?q?docs:=20=E4=BF=AE=E6=AD=A3=20double64=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java | 4 ++-- 1 file changed, 2 insertions(+), 2 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 3fa44e2..46430d8 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2306,8 +2306,8 @@ public class VMOpCode { */ public static final int D2B = 0x00D9; /** - * D2I Opcode: Represents the type conversion operation from double64 to short16 in the virtual machine. - *

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

+ * D2S 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:

*
    From f6780194a51e36c38f4baebc9d01f157aa61ef4a Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 16:19:27 +0800 Subject: [PATCH 21/37] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20short16=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 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 46430d8..f92c83d 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2057,15 +2057,75 @@ public class VMOpCode { // endregion Byte8 // region Short16 (0x00C5-0xC9) - + /** + * S2B Opcode: Represents the type conversion operation from short16 to byte8 in the virtual machine. + *

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

    + * + *

    Execution Steps:

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

    This opcode is used to narrow a short16 value to a byte8 type, suitable when a smaller numeric type is required.

    + */ public static final int S2B = 0x00C5; - + /** + * S2I Opcode: Represents the type conversion operation from short16 to int32 in the virtual machine. + *

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

    + * + *

    Execution Steps:

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

    This opcode is commonly used to widen a short16 value to an int32 type to accommodate larger numeric ranges.

    + */ public static final int S2I = 0x00C6; - + /** + * S2L Opcode: Represents the type conversion operation from short16 to long64 in the virtual machine. + *

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

    + * + *

    Execution Steps:

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

    This opcode is commonly used to widen a short16 value to a long64 type to accommodate larger numeric ranges.

    + */ public static final int S2L = 0x00C7; - + /** + * S2F Opcode: Represents the type conversion operation from short16 to float32 in the virtual machine. + *

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

    + * + *

    Execution Steps:

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

    This opcode is used to convert a short16 value to a float32 type when floating-point arithmetic is required.

    + */ public static final int S2F = 0x00C8; - + /** + * S2D Opcode: Represents the type conversion operation from short16 to double64 in the virtual machine. + *

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

    + * + *

    Execution Steps:

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

    This opcode is used to widen a short16 value to a double64 type, providing high-precision floating-point calculations.

    + */ public static final int S2D = 0x00C9; // endregion Short16 @@ -2099,7 +2159,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 = 0x00CB; - /** * 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.

    From 9cfd3ba29a50d2319df7d5776f029c1436013219 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 16:26:06 +0800 Subject: [PATCH 22/37] =?UTF-8?q?docs:=20=E8=A1=A5=E5=85=85=20byte8=20?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 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 f92c83d..4f2cd1a 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2044,15 +2044,75 @@ public class VMOpCode { // region Type Conversion (0x00C0-0x00DF) // region Byte8 (0x00C0-0xC4) - + /** + * B2S 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:

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

    This opcode is commonly used to widen a byte8 value to a short16 type to accommodate larger numeric ranges.

    + */ public static final int B2S = 0x00C0; - + /** + * B2I Opcode: Represents the type conversion operation from byte8 to int32 in the virtual machine. + *

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

    + * + *

    Execution Steps:

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

    This opcode is commonly used to widen a byte8 value to an int32 type to accommodate larger numeric ranges.

    + */ public static final int B2I = 0x00C1; - + /** + * B2L 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:

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

    This opcode is commonly used to widen a byte8 value to a long64 type to accommodate larger numeric ranges.

    + */ public static final int B2L = 0x00C2; - + /** + * B2F 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:

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

    This opcode is used to convert a byte8 value to a float32 type when floating-point arithmetic is required.

    + */ public static final int B2F = 0x00C3; - + /** + * B2D 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:

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

    This opcode is used to widen a byte8 value to a double64 type, providing high-precision floating-point calculations.

    + */ public static final int B2D = 0x00C4; // endregion Byte8 @@ -2144,7 +2204,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 = 0x00CA; - /** * 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.

    From 609e3806644fc72c495bd2a5aa97dc0a1dbe6817 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 17:13:16 +0800 Subject: [PATCH 23/37] =?UTF-8?q?refactor:=20=E5=90=8C=E6=AD=A5=20VMOpCode?= =?UTF-8?q?=20=E6=8C=87=E4=BB=A4=E5=88=B0=20OpHelper=20=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../snow/compiler/backend/utils/OpHelper.java | 192 +++++++++++------- 1 file changed, 119 insertions(+), 73 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 8dc5529..42c29ff 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 @@ -29,108 +29,154 @@ public final class OpHelper { static { Map map = new HashMap<>(); - map.put("I_ADD", Integer.toString(VMOpCode.I_ADD)); - map.put("I_SUB", Integer.toString(VMOpCode.I_SUB)); - map.put("I_MUL", Integer.toString(VMOpCode.I_MUL)); - map.put("I_DIV", Integer.toString(VMOpCode.I_DIV)); - map.put("I_MOD", Integer.toString(VMOpCode.I_MOD)); - map.put("I_INC", Integer.toString(VMOpCode.I_INC)); - map.put("I_NEG", Integer.toString(VMOpCode.I_NEG)); - map.put("L_ADD", Integer.toString(VMOpCode.L_ADD)); - map.put("L_SUB", Integer.toString(VMOpCode.L_SUB)); - map.put("L_MUL", Integer.toString(VMOpCode.L_MUL)); - map.put("L_DIV", Integer.toString(VMOpCode.L_DIV)); - map.put("L_MOD", Integer.toString(VMOpCode.L_MOD)); - map.put("L_INC", Integer.toString(VMOpCode.L_INC)); - map.put("L_NEG", Integer.toString(VMOpCode.L_NEG)); - map.put("S_ADD", Integer.toString(VMOpCode.S_ADD)); - map.put("S_SUB", Integer.toString(VMOpCode.S_SUB)); - map.put("S_MUL", Integer.toString(VMOpCode.S_MUL)); - map.put("S_DIV", Integer.toString(VMOpCode.S_DIV)); - map.put("S_MOD", Integer.toString(VMOpCode.S_MOD)); - map.put("S_INC", Integer.toString(VMOpCode.S_INC)); - map.put("S_NEG", Integer.toString(VMOpCode.S_NEG)); map.put("B_ADD", Integer.toString(VMOpCode.B_ADD)); map.put("B_SUB", Integer.toString(VMOpCode.B_SUB)); map.put("B_MUL", Integer.toString(VMOpCode.B_MUL)); map.put("B_DIV", Integer.toString(VMOpCode.B_DIV)); map.put("B_MOD", Integer.toString(VMOpCode.B_MOD)); - map.put("B_INC", Integer.toString(VMOpCode.B_INC)); map.put("B_NEG", Integer.toString(VMOpCode.B_NEG)); - map.put("D_ADD", Integer.toString(VMOpCode.D_ADD)); - map.put("D_SUB", Integer.toString(VMOpCode.D_SUB)); - map.put("D_MUL", Integer.toString(VMOpCode.D_MUL)); - map.put("D_DIV", Integer.toString(VMOpCode.D_DIV)); - map.put("D_MOD", Integer.toString(VMOpCode.D_MOD)); - map.put("D_NEG", Integer.toString(VMOpCode.D_NEG)); + map.put("B_INC", Integer.toString(VMOpCode.B_INC)); + map.put("B_AND", Integer.toString(VMOpCode.B_AND)); + map.put("B_OR", Integer.toString(VMOpCode.B_OR)); + map.put("B_XOR", Integer.toString(VMOpCode.B_XOR)); + map.put("B_PUSH", Integer.toString(VMOpCode.B_PUSH)); + map.put("B_LOAD", Integer.toString(VMOpCode.B_LOAD)); + map.put("B_STORE", Integer.toString(VMOpCode.B_STORE)); + map.put("B_CE", Integer.toString(VMOpCode.B_CE)); + map.put("B_CNE", Integer.toString(VMOpCode.B_CNE)); + map.put("B_CG", Integer.toString(VMOpCode.B_CG)); + map.put("B_CGE", Integer.toString(VMOpCode.B_CGE)); + map.put("B_CL", Integer.toString(VMOpCode.B_CL)); + map.put("B_CLE", Integer.toString(VMOpCode.B_CLE)); + map.put("S_ADD", Integer.toString(VMOpCode.S_ADD)); + map.put("S_SUB", Integer.toString(VMOpCode.S_SUB)); + map.put("S_MUL", Integer.toString(VMOpCode.S_MUL)); + map.put("S_DIV", Integer.toString(VMOpCode.S_DIV)); + map.put("S_MOD", Integer.toString(VMOpCode.S_MOD)); + map.put("S_NEG", Integer.toString(VMOpCode.S_NEG)); + map.put("S_INC", Integer.toString(VMOpCode.S_INC)); + map.put("S_AND", Integer.toString(VMOpCode.S_AND)); + map.put("S_OR", Integer.toString(VMOpCode.S_OR)); + map.put("S_XOR", Integer.toString(VMOpCode.S_XOR)); + map.put("S_PUSH", Integer.toString(VMOpCode.S_PUSH)); + map.put("S_LOAD", Integer.toString(VMOpCode.S_LOAD)); + map.put("S_STORE", Integer.toString(VMOpCode.S_STORE)); + map.put("S_CE", Integer.toString(VMOpCode.S_CE)); + map.put("S_CNE", Integer.toString(VMOpCode.S_CNE)); + map.put("S_CG", Integer.toString(VMOpCode.S_CG)); + map.put("S_CGE", Integer.toString(VMOpCode.S_CGE)); + map.put("S_CL", Integer.toString(VMOpCode.S_CL)); + map.put("S_CLE", Integer.toString(VMOpCode.S_CLE)); + map.put("I_ADD", Integer.toString(VMOpCode.I_ADD)); + map.put("I_SUB", Integer.toString(VMOpCode.I_SUB)); + map.put("I_MUL", Integer.toString(VMOpCode.I_MUL)); + map.put("I_DIV", Integer.toString(VMOpCode.I_DIV)); + map.put("I_MOD", Integer.toString(VMOpCode.I_MOD)); + map.put("I_NEG", Integer.toString(VMOpCode.I_NEG)); + map.put("I_INC", Integer.toString(VMOpCode.I_INC)); + map.put("I_AND", Integer.toString(VMOpCode.I_AND)); + map.put("I_OR", Integer.toString(VMOpCode.I_OR)); + map.put("I_XOR", Integer.toString(VMOpCode.I_XOR)); + map.put("I_PUSH", Integer.toString(VMOpCode.I_PUSH)); + map.put("I_LOAD", Integer.toString(VMOpCode.I_LOAD)); + map.put("I_STORE", Integer.toString(VMOpCode.I_STORE)); + map.put("I_CE", Integer.toString(VMOpCode.I_CE)); + map.put("I_CNE", Integer.toString(VMOpCode.I_CNE)); + map.put("I_CG", Integer.toString(VMOpCode.I_CG)); + map.put("I_CGE", Integer.toString(VMOpCode.I_CGE)); + map.put("I_CL", Integer.toString(VMOpCode.I_CL)); + map.put("I_CLE", Integer.toString(VMOpCode.I_CLE)); + map.put("L_ADD", Integer.toString(VMOpCode.L_ADD)); + map.put("L_SUB", Integer.toString(VMOpCode.L_SUB)); + map.put("L_MUL", Integer.toString(VMOpCode.L_MUL)); + map.put("L_DIV", Integer.toString(VMOpCode.L_DIV)); + map.put("L_MOD", Integer.toString(VMOpCode.L_MOD)); + map.put("L_NEG", Integer.toString(VMOpCode.L_NEG)); + map.put("L_INC", Integer.toString(VMOpCode.L_INC)); + map.put("L_AND", Integer.toString(VMOpCode.L_AND)); + map.put("L_OR", Integer.toString(VMOpCode.L_OR)); + map.put("L_XOR", Integer.toString(VMOpCode.L_XOR)); + map.put("L_PUSH", Integer.toString(VMOpCode.L_PUSH)); + map.put("L_LOAD", Integer.toString(VMOpCode.L_LOAD)); + map.put("L_STORE", Integer.toString(VMOpCode.L_STORE)); + map.put("L_CE", Integer.toString(VMOpCode.L_CE)); + map.put("L_CNE", Integer.toString(VMOpCode.L_CNE)); + map.put("L_CG", Integer.toString(VMOpCode.L_CG)); + map.put("L_CGE", Integer.toString(VMOpCode.L_CGE)); + map.put("L_CL", Integer.toString(VMOpCode.L_CL)); + map.put("L_CLE", Integer.toString(VMOpCode.L_CLE)); map.put("F_ADD", Integer.toString(VMOpCode.F_ADD)); map.put("F_SUB", Integer.toString(VMOpCode.F_SUB)); map.put("F_MUL", Integer.toString(VMOpCode.F_MUL)); map.put("F_DIV", Integer.toString(VMOpCode.F_DIV)); map.put("F_MOD", Integer.toString(VMOpCode.F_MOD)); map.put("F_NEG", Integer.toString(VMOpCode.F_NEG)); - map.put("D_INC", Integer.toString(VMOpCode.D_INC)); map.put("F_INC", Integer.toString(VMOpCode.F_INC)); - map.put("I2L", Integer.toString(VMOpCode.I2L)); - map.put("I2S", Integer.toString(VMOpCode.I2S)); + map.put("F_PUSH", Integer.toString(VMOpCode.F_PUSH)); + map.put("F_LOAD", Integer.toString(VMOpCode.F_LOAD)); + map.put("F_STORE", Integer.toString(VMOpCode.F_STORE)); + map.put("F_CE", Integer.toString(VMOpCode.F_CE)); + map.put("F_CNE", Integer.toString(VMOpCode.F_CNE)); + map.put("F_CG", Integer.toString(VMOpCode.F_CG)); + map.put("F_CGE", Integer.toString(VMOpCode.F_CGE)); + map.put("F_CL", Integer.toString(VMOpCode.F_CL)); + map.put("F_CLE", Integer.toString(VMOpCode.F_CLE)); + map.put("D_ADD", Integer.toString(VMOpCode.D_ADD)); + map.put("D_SUB", Integer.toString(VMOpCode.D_SUB)); + map.put("D_MUL", Integer.toString(VMOpCode.D_MUL)); + map.put("D_DIV", Integer.toString(VMOpCode.D_DIV)); + map.put("D_MOD", Integer.toString(VMOpCode.D_MOD)); + map.put("D_NEG", Integer.toString(VMOpCode.D_NEG)); + map.put("D_INC", Integer.toString(VMOpCode.D_INC)); + map.put("D_PUSH", Integer.toString(VMOpCode.D_PUSH)); + map.put("D_LOAD", Integer.toString(VMOpCode.D_LOAD)); + map.put("D_STORE", Integer.toString(VMOpCode.D_STORE)); + map.put("D_CE", Integer.toString(VMOpCode.D_CE)); + map.put("D_CNE", Integer.toString(VMOpCode.D_CNE)); + map.put("D_CG", Integer.toString(VMOpCode.D_CG)); + map.put("D_CGE", Integer.toString(VMOpCode.D_CGE)); + map.put("D_CL", Integer.toString(VMOpCode.D_CL)); + map.put("D_CLE", Integer.toString(VMOpCode.D_CLE)); + map.put("B2S", Integer.toString(VMOpCode.B2S)); + map.put("B2I", Integer.toString(VMOpCode.B2I)); + map.put("B2L", Integer.toString(VMOpCode.B2L)); + map.put("B2F", Integer.toString(VMOpCode.B2F)); + map.put("B2D", Integer.toString(VMOpCode.B2D)); + map.put("S2B", Integer.toString(VMOpCode.S2B)); + map.put("S2I", Integer.toString(VMOpCode.S2I)); + map.put("S2L", Integer.toString(VMOpCode.S2L)); + map.put("S2F", Integer.toString(VMOpCode.S2F)); + map.put("S2D", Integer.toString(VMOpCode.S2D)); map.put("I2B", Integer.toString(VMOpCode.I2B)); - map.put("I2D", Integer.toString(VMOpCode.I2D)); + map.put("I2S", Integer.toString(VMOpCode.I2S)); + map.put("I2L", Integer.toString(VMOpCode.I2L)); map.put("I2F", Integer.toString(VMOpCode.I2F)); + map.put("I2D", Integer.toString(VMOpCode.I2D)); + map.put("L2B", Integer.toString(VMOpCode.L2B)); + map.put("L2S", Integer.toString(VMOpCode.L2S)); map.put("L2I", Integer.toString(VMOpCode.L2I)); - map.put("L2D", Integer.toString(VMOpCode.L2D)); map.put("L2F", Integer.toString(VMOpCode.L2F)); + map.put("L2D", Integer.toString(VMOpCode.L2D)); + map.put("F2B", Integer.toString(VMOpCode.F2B)); + map.put("F2S", Integer.toString(VMOpCode.F2S)); map.put("F2I", Integer.toString(VMOpCode.F2I)); map.put("F2L", Integer.toString(VMOpCode.F2L)); map.put("F2D", Integer.toString(VMOpCode.F2D)); + map.put("D2B", Integer.toString(VMOpCode.D2B)); + map.put("D2S", Integer.toString(VMOpCode.D2S)); map.put("D2I", Integer.toString(VMOpCode.D2I)); map.put("D2L", Integer.toString(VMOpCode.D2L)); map.put("D2F", Integer.toString(VMOpCode.D2F)); - map.put("S2I", Integer.toString(VMOpCode.S2I)); - map.put("B2I", Integer.toString(VMOpCode.B2I)); - map.put("I_AND", Integer.toString(VMOpCode.I_AND)); - map.put("I_OR", Integer.toString(VMOpCode.I_OR)); - map.put("I_XOR", Integer.toString(VMOpCode.I_XOR)); - map.put("L_AND", Integer.toString(VMOpCode.L_AND)); - map.put("L_OR", Integer.toString(VMOpCode.L_OR)); - map.put("L_XOR", Integer.toString(VMOpCode.L_XOR)); - map.put("JUMP", Integer.toString(VMOpCode.JUMP)); - map.put("IC_E", Integer.toString(VMOpCode.I_CE)); - map.put("IC_NE", Integer.toString(VMOpCode.I_CNE)); - map.put("IC_G", Integer.toString(VMOpCode.I_CG)); - map.put("IC_GE", Integer.toString(VMOpCode.I_CGE)); - map.put("IC_L", Integer.toString(VMOpCode.I_CL)); - map.put("IC_LE", Integer.toString(VMOpCode.I_CLE)); - map.put("LC_E", Integer.toString(VMOpCode.L_CE)); - map.put("LC_NE", Integer.toString(VMOpCode.L_CNE)); - map.put("LC_G", Integer.toString(VMOpCode.L_CG)); - map.put("LC_GE", Integer.toString(VMOpCode.L_CGE)); - map.put("LC_L", Integer.toString(VMOpCode.L_CL)); - map.put("LC_LE", Integer.toString(VMOpCode.L_CLE)); - map.put("I_PUSH", Integer.toString(VMOpCode.I_PUSH)); - map.put("L_PUSH", Integer.toString(VMOpCode.L_PUSH)); - map.put("S_PUSH", Integer.toString(VMOpCode.S_PUSH)); - map.put("B_PUSH", Integer.toString(VMOpCode.B_PUSH)); - map.put("D_PUSH", Integer.toString(VMOpCode.D_PUSH)); - map.put("F_PUSH", Integer.toString(VMOpCode.F_PUSH)); map.put("POP", Integer.toString(VMOpCode.POP)); map.put("DUP", Integer.toString(VMOpCode.DUP)); map.put("SWAP", Integer.toString(VMOpCode.SWAP)); - map.put("I_STORE", Integer.toString(VMOpCode.I_STORE)); - map.put("L_STORE", Integer.toString(VMOpCode.L_STORE)); - map.put("S_STORE", Integer.toString(VMOpCode.S_STORE)); - map.put("B_STORE", Integer.toString(VMOpCode.B_STORE)); - map.put("D_STORE", Integer.toString(VMOpCode.D_STORE)); - map.put("F_STORE", Integer.toString(VMOpCode.F_STORE)); - map.put("I_LOAD", Integer.toString(VMOpCode.I_LOAD)); - map.put("L_LOAD", Integer.toString(VMOpCode.L_LOAD)); - map.put("S_LOAD", Integer.toString(VMOpCode.S_LOAD)); - map.put("B_LOAD", Integer.toString(VMOpCode.B_LOAD)); - map.put("D_LOAD", Integer.toString(VMOpCode.D_LOAD)); - map.put("F_LOAD", Integer.toString(VMOpCode.F_LOAD)); - map.put("MOV", Integer.toString(VMOpCode.MOV)); + map.put("JUMP", Integer.toString(VMOpCode.JUMP)); map.put("CALL", Integer.toString(VMOpCode.CALL)); map.put("RET", Integer.toString(VMOpCode.RET)); + map.put("MOV", Integer.toString(VMOpCode.MOV)); map.put("HALT", Integer.toString(VMOpCode.HALT)); + map.put("SYSCALL", Integer.toString(VMOpCode.SYSCALL)); + map.put("DEBUG_TRAP", Integer.toString(VMOpCode.DEBUG_TRAP)); OPCODE_MAP = Collections.unmodifiableMap(map); Map revmap = new HashMap<>(); // reverse map From e66a5a30782341fa6e49f22c90a80ae310f1822a Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 17:31:44 +0800 Subject: [PATCH 24/37] =?UTF-8?q?refactor:=20=E9=87=8D=E5=A4=8D=E7=9A=84?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E6=8F=90=E5=8D=87=E9=80=BB=E8=BE=91=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E5=88=B0=20TypePromoteUtils=20=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/generator/BinaryOpGenerator.java | 72 ++---------- .../backend/generator/CmpJumpGenerator.java | 90 +-------------- .../backend/utils/TypePromoteUtils.java | 105 ++++++++++++++++++ 3 files changed, 122 insertions(+), 145 deletions(-) create mode 100644 src/main/java/org/jcnc/snow/compiler/backend/utils/TypePromoteUtils.java 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 0d0a983..83c1747 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 @@ -4,6 +4,7 @@ import org.jcnc.snow.compiler.backend.builder.VMProgramBuilder; import org.jcnc.snow.compiler.backend.core.InstructionGenerator; import org.jcnc.snow.compiler.backend.utils.IROpCodeMapper; import org.jcnc.snow.compiler.backend.utils.OpHelper; +import org.jcnc.snow.compiler.backend.utils.TypePromoteUtils; import org.jcnc.snow.compiler.ir.core.IRValue; import org.jcnc.snow.compiler.ir.instruction.BinaryOperationInstruction; import org.jcnc.snow.compiler.ir.value.IRConstant; @@ -41,38 +42,12 @@ public class BinaryOpGenerator implements InstructionGenerator 6; - case 'F' -> 5; - case 'L' -> 4; - case 'I' -> 3; - case 'S' -> 2; - case 'B' -> 1; - default -> 0; - }; - } - - /** - * 返回优先级更高的类型字符 - */ - private static char promote(char a, char b) { - return rank(a) >= rank(b) ? a : b; - } - - /** - * 单字符转字符串 - */ - private static String str(char p) { - return String.valueOf(p); - } - /** * 判断常量值是否等于 0。 * 仅支持 Java 原生数值类型。 + * + * @param v 常量值 + * @return 等于 0 返回 true,否则 false */ private static boolean isZero(Object v) { if (v == null) return false; @@ -87,31 +62,6 @@ public class BinaryOpGenerator implements InstructionGenerator "I2L"; - case "ID" -> "I2D"; - case "IF" -> "I2F"; - case "LI" -> "L2I"; - case "LD" -> "L2D"; - case "LF" -> "L2F"; - case "FI" -> "F2I"; - case "FL" -> "F2L"; - case "FD" -> "F2D"; - case "DI" -> "D2I"; - case "DL" -> "D2L"; - case "DF" -> "D2F"; - case "SI" -> "S2I"; - case "BI" -> "B2I"; - default -> null; - }; - } - /* -------------------- 接口实现 -------------------- */ @Override @@ -161,16 +111,16 @@ public class BinaryOpGenerator implements InstructionGenerator类型宽度优先级:D > F > L > I > S > B - *
      - *
    • D(double):6
    • - *
    • F(float):5
    • - *
    • L(long):4
    • - *
    • I(int):3
    • - *
    • S(short):2
    • - *
    • B(byte):1
    • - *
    • 未识别类型:0
    • - *
    - * - * @param p 类型标记字符 - * @return 优先级数值(越大类型越宽) - */ - private static int rank(char p) { - return switch (p) { - case 'D' -> 6; - case 'F' -> 5; - case 'L' -> 4; - case 'I' -> 3; - case 'S' -> 2; - case 'B' -> 1; - default -> 0; - }; - } - - /** - * 返回更“宽”的公共类型(即优先级高的类型)。 - * - * @param a 类型标记字符 1 - * @param b 类型标记字符 2 - * @return 宽度更高的类型标记字符 - */ - private static char promote(char a, char b) { - return rank(a) >= rank(b) ? a : b; - } - - /** - * 单字符类型标记转字符串。 - * - * @param p 类型标记字符 - * @return 类型字符串 - */ - private static String str(char p) { - return String.valueOf(p); - } - - /** - * 获取 {@code from → to} 的类型转换指令名(如不需转换则返回 {@code null})。 - *

    - * 仅覆盖目前常见的整数与浮点类型提升与转换,后续有新类型可补充。 - *

    - * - * @param from 源类型标记字符 - * @param to 目标类型标记字符 - * @return 转换指令名,如“L2I”;无转换返回 {@code null} - */ - private static String convert(char from, char to) { - if (from == to) return null; - return switch ("" + from + to) { - case "IL" -> "I2L"; - case "ID" -> "I2D"; - case "IF" -> "I2F"; - case "LI" -> "L2I"; - case "LD" -> "L2D"; - case "LF" -> "L2F"; - case "FI" -> "F2I"; - case "FL" -> "F2L"; - case "FD" -> "F2D"; - case "DI" -> "D2I"; - case "DL" -> "D2L"; - case "DF" -> "D2F"; - case "SI" -> "S2I"; - case "BI" -> "B2I"; - default -> null; - }; - } - /** * 生成 IR 条件比较跳转指令的 VM 指令序列。 *
      @@ -140,19 +62,19 @@ public class CmpJumpGenerator implements InstructionGenerator类型宽度优先级:D > F > L > I > S > B + *
        + *
      • D(double):6
      • + *
      • F(float):5
      • + *
      • L(long):4
      • + *
      • I(int):3
      • + *
      • S(short):2
      • + *
      • B(byte):1
      • + *
      • 未识别类型:0
      • + *
      + * + * @param p 类型标记字符 + * @return 优先级数值(越大类型越宽) + */ + private static int rank(char p) { + return switch (p) { + case 'D' -> 6; + case 'F' -> 5; + case 'L' -> 4; + case 'I' -> 3; + case 'S' -> 2; + case 'B' -> 1; + default -> 0; + }; + } + + /** + * 返回更“宽”的公共类型(即优先级高的类型)。 + * + * @param a 类型标记字符 1 + * @param b 类型标记字符 2 + * @return 宽度更高的类型标记字符 + */ + public static char promote(char a, char b) { + return rank(a) >= rank(b) ? a : b; + } + + /** + * 单字符类型标记转字符串。 + * + * @param p 类型标记字符 + * @return 类型字符串 + */ + public static String str(char p) { + return String.valueOf(p); + } + + /** + * 获取 {@code from → to} 的类型转换指令名(如不需转换则返回 {@code null})。 + * + * @param from 源类型标记字符 + * @param to 目标类型标记字符 + * @return 转换指令名,如“L2I”;无转换返回 {@code null} + */ + public static String convert(char from, char to) { + if (from == to) return null; + return switch ("" + from + to) { + case "BS" -> "B2S"; + case "BI" -> "B2I"; + case "BL" -> "B2L"; + case "BF" -> "B2F"; + case "BD" -> "B2D"; + + case "SB" -> "S2B"; + case "SI" -> "S2I"; + case "SL" -> "S2L"; + case "SF" -> "S2F"; + case "SD" -> "S2D"; + + case "IB" -> "I2B"; + case "IS" -> "I2S"; + case "IL" -> "I2L"; + case "IF" -> "I2F"; + case "ID" -> "I2D"; + + case "LB" -> "L2B"; + case "LS" -> "L2S"; + case "LI" -> "L2I"; + case "LF" -> "L2F"; + case "LD" -> "L2D"; + + case "FB" -> "F2B"; + case "FS" -> "F2S"; + case "FI" -> "F2I"; + case "FL" -> "F2L"; + case "FD" -> "F2D"; + + case "DB" -> "D2B"; + case "DS" -> "D2S"; + case "DI" -> "D2I"; + case "DL" -> "D2L"; + case "DF" -> "D2F"; + default -> null; + }; + } +} From 61a2fda6fad99084707a526fc54bdd31eb665616 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 17:32:40 +0800 Subject: [PATCH 25/37] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=20IR=20?= =?UTF-8?q?=E5=AF=B9=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/utils/IROpCodeMapper.java | 74 +++++++++++++------ .../jcnc/snow/compiler/ir/core/IROpCode.java | 56 +++++++++++--- .../compiler/ir/core/IROpCodeMappings.java | 40 +++++++++- 3 files changed, 136 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java b/src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java index 31c0033..393e8a5 100644 --- a/src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java +++ b/src/main/java/org/jcnc/snow/compiler/backend/utils/IROpCodeMapper.java @@ -82,34 +82,66 @@ public final class IROpCodeMapper { opcodeMap.put(IROpCode.NEG_D64, "D_NEG"); // 比较运算映射 - // 整形32位比较运算映射 - opcodeMap.put(IROpCode.CMP_IEQ, "IC_E"); // 相等 - opcodeMap.put(IROpCode.CMP_INE, "IC_NE"); // 不等 - opcodeMap.put(IROpCode.CMP_ILT, "IC_L"); // 小于 - opcodeMap.put(IROpCode.CMP_IGT, "IC_G"); // 大于 - opcodeMap.put(IROpCode.CMP_ILE, "IC_LE"); // 小于等于 - opcodeMap.put(IROpCode.CMP_IGE, "IC_GE"); // 大于等于 + // 8位整数比较运算映射 + opcodeMap.put(IROpCode.CMP_BEQ, "B_CE"); // 相等 + opcodeMap.put(IROpCode.CMP_BNE, "B_CNE"); // 不等 + opcodeMap.put(IROpCode.CMP_BLT, "B_CL"); // 小于 + opcodeMap.put(IROpCode.CMP_BGT, "B_CG"); // 大于 + opcodeMap.put(IROpCode.CMP_BLE, "B_CLE"); // 小于等于 + opcodeMap.put(IROpCode.CMP_BGE, "B_CGE"); // 大于等于 - // 整形64位比较运算映射 - opcodeMap.put(IROpCode.CMP_LEQ, "LC_E"); // 相等 - opcodeMap.put(IROpCode.CMP_LNE, "LC_NE"); // 不等 - opcodeMap.put(IROpCode.CMP_LLT, "LC_L"); // 小于 - opcodeMap.put(IROpCode.CMP_LGT, "LC_G"); // 大于 - opcodeMap.put(IROpCode.CMP_LLE, "LC_LE"); // 小于等于 - opcodeMap.put(IROpCode.CMP_LGE, "LC_GE"); // 大于等于 + // 16位整数比较运算映射 + opcodeMap.put(IROpCode.CMP_SEQ, "S_CE"); // 相等 + opcodeMap.put(IROpCode.CMP_SNE, "S_CNE"); // 不等 + opcodeMap.put(IROpCode.CMP_SLT, "S_CL"); // 小于 + opcodeMap.put(IROpCode.CMP_SGT, "S_CG"); // 大于 + opcodeMap.put(IROpCode.CMP_SLE, "S_CLE"); // 小于等于 + opcodeMap.put(IROpCode.CMP_SGE, "S_CGE"); // 大于等于 + + // 32位整数比较运算映射 + opcodeMap.put(IROpCode.CMP_IEQ, "I_CE"); // 相等 + opcodeMap.put(IROpCode.CMP_INE, "I_CNE"); // 不等 + opcodeMap.put(IROpCode.CMP_ILT, "I_CL"); // 小于 + opcodeMap.put(IROpCode.CMP_IGT, "I_CG"); // 大于 + opcodeMap.put(IROpCode.CMP_ILE, "I_CLE"); // 小于等于 + opcodeMap.put(IROpCode.CMP_IGE, "I_CGE"); // 大于等于 + + // 64位整数比较运算映射 + opcodeMap.put(IROpCode.CMP_LEQ, "L_CE"); // 相等 + opcodeMap.put(IROpCode.CMP_LNE, "L_CNE"); // 不等 + opcodeMap.put(IROpCode.CMP_LLT, "L_CL"); // 小于 + opcodeMap.put(IROpCode.CMP_LGT, "L_CG"); // 大于 + opcodeMap.put(IROpCode.CMP_LLE, "L_CLE"); // 小于等于 + opcodeMap.put(IROpCode.CMP_LGE, "L_CGE"); // 大于等于 + + // 32位浮点比较运算映射 + opcodeMap.put(IROpCode.CMP_FEQ, "F_CE"); // 相等 + opcodeMap.put(IROpCode.CMP_FNE, "F_CNE"); // 不等 + opcodeMap.put(IROpCode.CMP_FLT, "F_CL"); // 小于 + opcodeMap.put(IROpCode.CMP_FGT, "F_CG"); // 大于 + opcodeMap.put(IROpCode.CMP_FLE, "F_CLE"); // 小于等于 + opcodeMap.put(IROpCode.CMP_FGE, "F_CGE"); // 大于等于 + + // 64位浮点比较运算映射 + opcodeMap.put(IROpCode.CMP_DEQ, "D_CE"); // 相等 + opcodeMap.put(IROpCode.CMP_DNE, "D_CNE"); // 不等 + opcodeMap.put(IROpCode.CMP_DLT, "D_CL"); // 小于 + opcodeMap.put(IROpCode.CMP_DGT, "D_CG"); // 大于 + opcodeMap.put(IROpCode.CMP_DLE, "D_CLE"); // 小于等于 + opcodeMap.put(IROpCode.CMP_DGE, "D_CGE"); // 大于等于 // 加载与存储 - opcodeMap.put(IROpCode.LOAD, "I_LOAD"); // 加载 - opcodeMap.put(IROpCode.STORE, "I_STORE"); // 存储 - opcodeMap.put(IROpCode.CONST, "I_PUSH"); // 常量入栈 + opcodeMap.put(IROpCode.LOAD, "I_LOAD"); // 加载 + opcodeMap.put(IROpCode.STORE, "I_STORE"); // 存储 + opcodeMap.put(IROpCode.CONST, "I_PUSH"); // 常量入栈 // 跳转与标签 - opcodeMap.put(IROpCode.JUMP, "JMP"); // 无条件跳转 - opcodeMap.put(IROpCode.LABEL, "LABEL"); // 标签 + opcodeMap.put(IROpCode.JUMP, "JMP"); // 无条件跳转 + opcodeMap.put(IROpCode.LABEL, "LABEL"); // 标签 // 函数相关 - opcodeMap.put(IROpCode.CALL, "CALL"); // 调用 - opcodeMap.put(IROpCode.RET, "RET"); // 返回 + opcodeMap.put(IROpCode.CALL, "CALL"); // 调用 + opcodeMap.put(IROpCode.RET, "RET"); // 返回 } /** diff --git a/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCode.java b/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCode.java index c45a454..1e6b3e7 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCode.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCode.java @@ -66,21 +66,53 @@ public enum IROpCode { DIV_D64, // 64位浮点除法 NEG_D64, // 64位浮点取负 + /* ───── 逻辑与比较运算指令(8位整数:byte) ───── */ + CMP_BEQ, // 8位整数相等比较:a == b + CMP_BNE, // 8位整数不等比较:a != b + CMP_BLT, // 8位整数小于比较:a < b + CMP_BGT, // 8位整数大于比较:a > b + CMP_BLE, // 8位整数小于等于:a <= b + CMP_BGE, // 8位整数大于等于:a >= b + + /* ───── 逻辑与比较运算指令(16位整数:int) ───── */ + CMP_SEQ, // 16位整数相等比较:a == b + CMP_SNE, // 16位整数不等比较:a != b + CMP_SLT, // 16位整数小于比较:a < b + CMP_SGT, // 16位整数大于比较:a > b + CMP_SLE, // 16位整数小于等于:a <= b + CMP_SGE, // 16位整数大于等于:a >= b + /* ───── 逻辑与比较运算指令(32位整数:int) ───── */ - CMP_IEQ, // 32位相等比较:a == b - CMP_INE, // 32位不等比较:a != b - CMP_ILT, // 32位小于比较:a < b - CMP_IGT, // 32位大于比较:a > b - CMP_ILE, // 32位小于等于:a <= b - CMP_IGE, // 32位大于等于:a >= b + CMP_IEQ, // 32位整数相等比较:a == b + CMP_INE, // 32位整数不等比较:a != b + CMP_ILT, // 32位整数小于比较:a < b + CMP_IGT, // 32位整数大于比较:a > b + CMP_ILE, // 32位整数小于等于:a <= b + CMP_IGE, // 32位整数大于等于:a >= b /* ───── 逻辑与比较运算指令(64位整数:long) ───── */ - CMP_LEQ, // 64位相等比较:a == b - CMP_LNE, // 64位不等比较:a != b - CMP_LLT, // 64位小于比较:a < b - CMP_LGT, // 64位大于比较:a > b - CMP_LLE, // 64位小于等于:a <= b - CMP_LGE, // 64位大于等于:a >= b + CMP_LEQ, // 64位整数相等比较:a == b + CMP_LNE, // 64位整数不等比较:a != b + CMP_LLT, // 64位整数小于比较:a < b + CMP_LGT, // 64位整数大于比较:a > b + CMP_LLE, // 64位整数小于等于:a <= b + CMP_LGE, // 64位整数大于等于:a >= b + + /* ───── 逻辑与比较运算指令(32位浮点数:float) ───── */ + CMP_FEQ, // 32位浮点相等比较:a == b + CMP_FNE, // 32位浮点不等比较:a != b + CMP_FLT, // 32位浮点小于比较:a < b + CMP_FGT, // 32位浮点大于比较:a > b + CMP_FLE, // 32位浮点小于等于:a <= b + CMP_FGE, // 32位浮点大于等于:a >= b + + /* ───── 逻辑与比较运算指令(64位浮点数:double) ───── */ + CMP_DEQ, // 64位浮点相等比较:a == b + CMP_DNE, // 64位浮点不等比较:a != b + CMP_DLT, // 64位浮点小于比较:a < b + CMP_DGT, // 64位浮点大于比较:a > b + CMP_DLE, // 64位浮点小于等于:a <= b + CMP_DGE, // 64位浮点大于等于:a >= b /* ───── 数据访问与常量操作 ───── */ LOAD, // 从内存加载数据至寄存器 diff --git a/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCodeMappings.java b/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCodeMappings.java index 32593d9..92677a6 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCodeMappings.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/core/IROpCodeMappings.java @@ -40,6 +40,26 @@ public final class IROpCodeMappings { ); /* ────── 比较运算符映射 ────── */ + /** 8-bit(byte)比较 */ + public static final Map CMP_B8 = Map.of( + "==", IROpCode.CMP_BEQ, + "!=", IROpCode.CMP_BNE, + "<", IROpCode.CMP_BLT, + ">", IROpCode.CMP_BGT, + "<=", IROpCode.CMP_BLE, + ">=", IROpCode.CMP_BGE + ); + + /** 16-bit(short)比较 */ + public static final Map CMP_S16 = Map.of( + "==", IROpCode.CMP_SEQ, + "!=", IROpCode.CMP_SNE, + "<", IROpCode.CMP_SLT, + ">", IROpCode.CMP_SGT, + "<=", IROpCode.CMP_SLE, + ">=", IROpCode.CMP_SGE + ); + /** 32-bit(int)比较 */ public static final Map CMP_I32 = Map.of( "==", IROpCode.CMP_IEQ, @@ -60,5 +80,23 @@ public final class IROpCodeMappings { ">=", IROpCode.CMP_LGE ); - + /** 32-bit(float)比较 */ + public static final Map CMP_F32 = Map.of( + "==", IROpCode.CMP_FEQ, + "!=", IROpCode.CMP_FNE, + "<", IROpCode.CMP_FLT, + ">", IROpCode.CMP_FGT, + "<=", IROpCode.CMP_FLE, + ">=", IROpCode.CMP_FGE + ); + + /** 64-bit(double)比较 */ + public static final Map CMP_D64 = Map.of( + "==", IROpCode.CMP_DEQ, + "!=", IROpCode.CMP_DNE, + "<", IROpCode.CMP_DLT, + ">", IROpCode.CMP_DGT, + "<=", IROpCode.CMP_DLE, + ">=", IROpCode.CMP_DGE + ); } From 9d21eeace93a489024d9dceb3e60cb4eec53a5a4 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 17:44:28 +0800 Subject: [PATCH 26/37] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=20CmpJumpGenera?= =?UTF-8?q?tor=20=E9=83=A8=E5=88=86=E9=80=BB=E8=BE=91=EF=BC=8C=E5=90=91?= =?UTF-8?q?=E6=96=B0=20VMOpCode=20=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../compiler/backend/generator/CmpJumpGenerator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 906e346..232879e 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 @@ -82,12 +82,12 @@ public class CmpJumpGenerator implements InstructionGenerator Date: Thu, 10 Jul 2025 19:14:37 +0800 Subject: [PATCH 27/37] =?UTF-8?q?feat:=20=E5=9F=BA=E6=9C=AC=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=85=A8=E7=B1=BB=E5=9E=8B=E6=AF=94=E8=BE=83=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ir/builder/ExpressionBuilder.java | 4 +- .../compiler/ir/builder/IRBuilderScope.java | 10 +- .../compiler/ir/builder/StatementBuilder.java | 2 +- .../compiler/ir/utils/ComparisonUtils.java | 103 ++++++++++++++++-- .../compiler/ir/utils/ExpressionUtils.java | 4 +- 5 files changed, 107 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jcnc/snow/compiler/ir/builder/ExpressionBuilder.java b/src/main/java/org/jcnc/snow/compiler/ir/builder/ExpressionBuilder.java index f53d8cc..bb8c32e 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/builder/ExpressionBuilder.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/builder/ExpressionBuilder.java @@ -145,7 +145,7 @@ public record ExpressionBuilder(IRContext ctx) { if (ComparisonUtils.isComparisonOperator(op)) { return InstructionFactory.binOp( ctx, - ComparisonUtils.cmpOp(op, bin.left(), bin.right()), + ComparisonUtils.cmpOp(ctx.getScope().getVarTypes(), op, bin.left(), bin.right()), left, right); } @@ -171,7 +171,7 @@ public record ExpressionBuilder(IRContext ctx) { if (ComparisonUtils.isComparisonOperator(op)) { InstructionFactory.binOpInto( ctx, - ComparisonUtils.cmpOp(op, bin.left(), bin.right()), + ComparisonUtils.cmpOp(ctx.getScope().getVarTypes(), op, bin.left(), bin.right()), a, b, dest); } else { IROpCode code = ExpressionUtils.resolveOpCode(op, bin.left(), bin.right()); diff --git a/src/main/java/org/jcnc/snow/compiler/ir/builder/IRBuilderScope.java b/src/main/java/org/jcnc/snow/compiler/ir/builder/IRBuilderScope.java index e0fd4cf..3cd5deb 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/builder/IRBuilderScope.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/builder/IRBuilderScope.java @@ -13,7 +13,7 @@ import java.util.Map; *
        *
      • 维护在当前作用域中已声明变量的寄存器分配信息;
      • *
      • 支持将已有虚拟寄存器与变量名重新绑定;
      • - *
      • 根据变量名查找对应的虚拟寄存器实例。
      • + *
      • 根据变量名查找对应的虚拟寄存器实例或类型。
      • *
      */ final class IRBuilderScope { @@ -104,4 +104,12 @@ final class IRBuilderScope { String lookupType(String name) { return varTypes.get(name); } + + /** + * 获取 变量->类型的映射 的不可变副本 + * @return 变量->类型的映射 的不可变副本 + */ + Map getVarTypes() { + return Map.copyOf(varTypes); + } } diff --git a/src/main/java/org/jcnc/snow/compiler/ir/builder/StatementBuilder.java b/src/main/java/org/jcnc/snow/compiler/ir/builder/StatementBuilder.java index 78e42fa..30d672a 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/builder/StatementBuilder.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/builder/StatementBuilder.java @@ -218,7 +218,7 @@ public class StatementBuilder { IRVirtualRegister b = expr.build(right); // 使用适配后位宽正确的比较指令 - IROpCode cmp = ComparisonUtils.cmpOp(operator, left, right); + IROpCode cmp = ComparisonUtils.cmpOp(ctx.getScope().getVarTypes(), operator, left, right); IROpCode falseOp = IROpCodeUtils.invert(cmp); InstructionFactory.cmpJump(ctx, falseOp, a, b, falseLabel); diff --git a/src/main/java/org/jcnc/snow/compiler/ir/utils/ComparisonUtils.java b/src/main/java/org/jcnc/snow/compiler/ir/utils/ComparisonUtils.java index 70ac8f5..3cc8e37 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/utils/ComparisonUtils.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/utils/ComparisonUtils.java @@ -2,6 +2,7 @@ package org.jcnc.snow.compiler.ir.utils; import org.jcnc.snow.compiler.ir.core.IROpCode; import org.jcnc.snow.compiler.ir.core.IROpCodeMappings; +import org.jcnc.snow.compiler.parser.ast.IdentifierNode; import org.jcnc.snow.compiler.parser.ast.NumberLiteralNode; import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode; import org.jcnc.snow.compiler.parser.ast.base.NodeContext; @@ -25,26 +26,108 @@ public final class ComparisonUtils { return IROpCodeMappings.CMP_I32.containsKey(op); } + /** + * 类型宽度优先级:D > F > L > I > S > B + *
        + *
      • D(double):6
      • + *
      • F(float):5
      • + *
      • L(long):4
      • + *
      • I(int):3
      • + *
      • S(short):2
      • + *
      • B(byte):1
      • + *
      • 未识别类型:0
      • + *
      + * + * @param p 类型标记字符 + * @return 优先级数值(越大类型越宽) + */ + private static int rank(char p) { + return switch (p) { + case 'D' -> 6; + case 'F' -> 5; + case 'L' -> 4; + case 'I' -> 3; + case 'S' -> 2; + case 'B' -> 1; + default -> 0; + }; + } + + /** + * 返回更“宽”的公共类型(即优先级高的类型)。 + * + * @param a 类型标记字符 1 + * @param b 类型标记字符 2 + * @return 宽度更高的类型标记字符 + */ + public static char promote(char a, char b) { + return rank(a) >= rank(b) ? a : b; + } + /** * 返回符合操作数位宽的比较 IROpCode。 * - * @param op 比较符号(==, !=, <, >, <=, >=) - * @param left 左操作数 AST - * @param right 右操作数 AST + * @param variables 变量->类型的映射 + * @param op 比较符号(==, !=, <, >, <=, >=) + * @param left 左操作数 AST + * @param right 右操作数 AST */ - public static IROpCode cmpOp(String op, ExpressionNode left, ExpressionNode right) { - boolean useLong = isLongLiteral(left) || isLongLiteral(right); - Map table = useLong ? IROpCodeMappings.CMP_L64 - : IROpCodeMappings.CMP_I32; + public static IROpCode cmpOp(Map variables, String op, ExpressionNode left, ExpressionNode right) { + char typeLeft = analysisType(variables, left); + char typeRight = analysisType(variables, right); + char type = promote(typeLeft, typeRight); + + Map table = switch (type) { + case 'B' -> IROpCodeMappings.CMP_B8; + case 'S' -> IROpCodeMappings.CMP_S16; + case 'I' -> IROpCodeMappings.CMP_I32; + case 'L' -> IROpCodeMappings.CMP_L64; + case 'F' -> IROpCodeMappings.CMP_F32; + case 'D' -> IROpCodeMappings.CMP_D64; + default -> throw new IllegalStateException("Unexpected value: " + type); + }; + return table.get(op); } /* ------------ 内部工具 ------------ */ - private static boolean isLongLiteral(ExpressionNode node) { + private static char analysisType(Map variables, ExpressionNode node) { if (node instanceof NumberLiteralNode(String value, NodeContext _)) { - return value.endsWith("L") || value.endsWith("l"); + char suffix = Character.toUpperCase(value.charAt(value.length() - 1)); + if ("BSILFD".indexOf(suffix) != -1) { + return suffix; + } + if (value.indexOf('.') != -1) { + return 'D'; + } + + return 'I'; // 默认为 'I' } - return false; // 变量暂不处理(后续可扩展符号表查询) + if (node instanceof IdentifierNode(String name, NodeContext _)) { + final String type = variables.get(name); + switch (type) { + case "byte" -> { + return 'B'; + } + case "short" -> { + return 'S'; + } + case "int" -> { + return 'I'; + } + case "long" -> { + return 'L'; + } + case "float" -> { + return 'F'; + } + case "double" -> { + return 'D'; + } + } + } + + return 'I'; // 默认为 'I' } } diff --git a/src/main/java/org/jcnc/snow/compiler/ir/utils/ExpressionUtils.java b/src/main/java/org/jcnc/snow/compiler/ir/utils/ExpressionUtils.java index 2eed575..ba6f663 100644 --- a/src/main/java/org/jcnc/snow/compiler/ir/utils/ExpressionUtils.java +++ b/src/main/java/org/jcnc/snow/compiler/ir/utils/ExpressionUtils.java @@ -120,8 +120,8 @@ public final class ExpressionUtils { /** * 推荐调用:根据左右表达式类型自动选择 int / long 比较指令。 */ - public static IROpCode cmpOp(String op, ExpressionNode left, ExpressionNode right) { - return ComparisonUtils.cmpOp(op, left, right); + public static IROpCode cmpOp(Map variables, String op, ExpressionNode left, ExpressionNode right) { + return ComparisonUtils.cmpOp(variables, op, left, right); } /* ──────────────── 类型推断 & 算术操作码匹配 ──────────────── */ From e33ad1547548d80c95a508b9af6f6c850f302375 Mon Sep 17 00:00:00 2001 From: zhangxun <1958638841@qq.com> Date: Thu, 10 Jul 2025 19:18:19 +0800 Subject: [PATCH 28/37] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=20Demo13?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .run/Demo11.run.xml | 2 +- .run/Demo13.run.xml | 10 +++++ .run/测试.run.xml | 1 + playground/Demo/Demo13/Main.snow | 69 ++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 .run/Demo13.run.xml create mode 100644 playground/Demo/Demo13/Main.snow diff --git a/.run/Demo11.run.xml b/.run/Demo11.run.xml index 07d914d..ea7c1fc 100644 --- a/.run/Demo11.run.xml +++ b/.run/Demo11.run.xml @@ -3,7 +3,7 @@
    * - *

    This opcode is used to widen a byte8 value to a double64 type to ensure compatibility with integer-based operations.

    + *

    This opcode is used to widen a byte8 value to a double64 type.

    */ public class B2DCommand implements Command { 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 index c61891b..c62a202 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  1. Push the converted float32 value back onto the operand stack for subsequent operations.
  2. *
* - *

This opcode is used to widen a byte8 value to a float32 type to ensure compatibility with integer-based operations.

+ *

This opcode is used to widen a byte8 value to a float32 type.

*/ public class B2FCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2ICommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2ICommand.java index c5c18a6..2ba6649 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2ICommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/B2ICommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen a byte8 value to an int32 type to ensure compatibility with integer-based operations.

    + *

    This opcode is used to widen a byte8 value to an int32 type.

    */ public class B2ICommand implements Command { 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 index 344b49d..3bcff86 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to widen a byte8 value to a long64 type.

    */ public class B2LCommand implements Command { 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 index 1f09ff9..167d318 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to widen a byte8 value to a short16 type.

    */ public class B2SCommand implements Command { 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 index 7180d2e..8106ae8 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to narrow a double64 value to a byte8 type.

    */ public class D2BCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2FCommand.java index 7f4bcc0..49d14eb 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2FCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2FCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to a float32 type when lower precision floating-point arithmetic is acceptable.

    + *

    This opcode is used to narrow a double64 value to a float32 type.

    */ public class D2FCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2ICommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2ICommand.java index 903f6dc..b99dd0a 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2ICommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2ICommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to an int32 type for further integer-based operations.

    + *

    This opcode is used to narrow a double64 value to an int32 type.

    */ public class D2ICommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2LCommand.java index 78d558a..c825d09 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2LCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2LCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to a long64 type, which can then be used for integer operations.

    + *

    This opcode is used to narrow a double64 value to a long64 type.

    */ public class D2LCommand implements Command { 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 41a8cec..49da2f1 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted short16 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to a short16 type for further integer-based operations.

    + *

    This opcode is used to narrow a double64 value to a short16 type.

    */ public class D2SCommand implements Command { 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 index 5240f86..3277271 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to convert a float32 value to a byte8 type.

    */ public class F2BCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2DCommand.java index 7f4dba7..88c1075 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2DCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2DCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to promote a float32 value to a double64 type, thereby increasing precision for floating-point computations.

    + *

    This opcode is used to promote a float32 value to a double64 type.

    */ public class F2DCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2ICommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2ICommand.java index 24f9192..ced0b27 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2ICommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2ICommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert a float32 value to an int32 type for further integer operations or comparisons.

    + *

    This opcode is used to convert a float32 value to an int32 type.

    */ public class F2ICommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2LCommand.java index b4bcb6b..5471c14 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2LCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/F2LCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen a float32 value to a long64 type for operations requiring a larger numeric range.

    + *

    This opcode is used to widen a float32 value to a long64 type.

    */ public class F2LCommand implements Command { 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 index 83a79b5..312c828 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to convert a float32 value to a short16 type.

    */ public class F2SCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2BCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2BCommand.java index 76ef29c..3ab1503 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2BCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2BCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted byte8 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow an int32 value to a byte8 type when a smaller numeric representation is required.

    + *

    This opcode is used to narrow an int32 value to a byte8 type.

    */ public class I2BCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2DCommand.java index 0147f5b..07a3c9b 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2DCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2DCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.

    + *

    This opcode is used to widen an int32 value to a double64 type.

    */ public class I2DCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2FCommand.java index 22182dc..6b85e06 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2FCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2FCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert an int32 value to a float32 type when floating-point arithmetic is required.

    + *

    This opcode is used to convert an int32 value to a float32 type.

    */ public class I2FCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2LCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2LCommand.java index a9d1aae..069fc52 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2LCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2LCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen an int32 value to a long64 type.

    */ public class I2LCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2SCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2SCommand.java index ca5987a..b948a8d 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2SCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/I2SCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted short16 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is typically used to narrow an int32 value to a short16 type when a smaller data representation is required.

    + *

    This opcode is typically used to narrow an int32 value to a short16 type.

    */ public class I2SCommand implements Command { 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 index cde429c..b005ca2 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to widen a long64 value to a byte8 type.

    */ public class L2BCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2DCommand.java index 06426ae..2fd9a21 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2DCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2DCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.

    + *

    This opcode is used to widen a long64 value to a double64 type.

    */ public class L2DCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2FCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2FCommand.java index 5cf6a67..b790255 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2FCommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2FCommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert a long64 value to a float32 type, typically for floating-point arithmetic involving long values.

    + *

    This opcode is used to convert a long64 value to a float32 type.

    */ public class L2FCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2ICommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2ICommand.java index f4f4b41..b96442d 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2ICommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/L2ICommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is typically used to narrow a long64 value to an int32 type for further integer operations.

    + *

    This opcode is typically used to narrow a long64 value to an int32 typ.

    */ public class L2ICommand implements Command { 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 index 54652d6..70c5e2a 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to widen a long64 value to a short16 type.

    */ public class L2SCommand implements Command { 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 index d94eb8a..159504f 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to widen a short16 value to a byte8 type.

    */ public class S2BCommand 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 7703f26..50c6e4e 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

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

    + *

    This opcode is used to widen a short16 value to a double64 type.

    */ 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 478e397..9493a55 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

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

    + *

    This opcode is used to widen a short16 value to a float32 type.

    */ public class S2FCommand implements Command { diff --git a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2ICommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2ICommand.java index fa3ee74..c980d3b 100644 --- a/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2ICommand.java +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2ICommand.java @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

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

    + *

    This opcode is used to widen a short16 value to an int32 type.

    */ public class S2ICommand implements Command { 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 index cec58e6..194344f 100644 --- 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 @@ -16,7 +16,7 @@ import org.jcnc.snow.vm.module.OperandStack; *
  • 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.

    + *

    This opcode is used to widen a short16 value to a long64 type.

    */ public class S2LCommand implements Command { From aa96fc89ab4836e70b2c1e21f9c12f639160d87d Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 11 Jul 2025 10:25:52 +0800 Subject: [PATCH 35/37] =?UTF-8?q?docs:=20=E7=BB=9F=E4=B8=80=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=B1=BB=E5=9E=8B=E8=BD=AC=E6=8D=A2=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=E6=B6=88=E9=99=A4=E6=AD=A7=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/jcnc/snow/vm/engine/VMOpCode.java | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 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 4f2cd1a..8654d2e 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2055,7 +2055,7 @@ public class VMOpCode { *
  • Push the converted short16 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen a byte8 value to a short16 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen a byte8 value to a short16 type.

    */ public static final int B2S = 0x00C0; /** @@ -2069,7 +2069,7 @@ public class VMOpCode { *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen a byte8 value to an int32 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen a byte8 value to an int32 type.

    */ public static final int B2I = 0x00C1; /** @@ -2083,7 +2083,7 @@ public class VMOpCode { *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen a byte8 value to a long64 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen a byte8 value to a long64 type.

    */ public static final int B2L = 0x00C2; /** @@ -2097,7 +2097,7 @@ public class VMOpCode { *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert a byte8 value to a float32 type when floating-point arithmetic is required.

    + *

    This opcode is used to convert a byte8 value to a float32 type.

    */ public static final int B2F = 0x00C3; /** @@ -2111,7 +2111,7 @@ public class VMOpCode { *
  • 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, providing high-precision floating-point calculations.

    + *

    This opcode is used to widen a byte8 value to a double64 type.

    */ public static final int B2D = 0x00C4; // endregion Byte8 @@ -2128,7 +2128,7 @@ public class VMOpCode { *
  • Push the converted byte8 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a short16 value to a byte8 type, suitable when a smaller numeric type is required.

    + *

    This opcode is used to narrow a short16 value to a byte8 type.

    */ public static final int S2B = 0x00C5; /** @@ -2142,7 +2142,7 @@ public class VMOpCode { *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen a short16 value to an int32 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen a short16 value to an int32 type.

    */ public static final int S2I = 0x00C6; /** @@ -2156,7 +2156,7 @@ public class VMOpCode { *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen a short16 value to a long64 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen a short16 value to a long64 type.

    */ public static final int S2L = 0x00C7; /** @@ -2170,7 +2170,7 @@ public class VMOpCode { *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert a short16 value to a float32 type when floating-point arithmetic is required.

    + *

    This opcode is used to convert a short16 value to a float32 type.

    */ public static final int S2F = 0x00C8; /** @@ -2184,7 +2184,7 @@ public class VMOpCode { *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen a short16 value to a double64 type, providing high-precision floating-point calculations.

    + *

    This opcode is used to widen a short16 value to a double64 type.

    */ public static final int S2D = 0x00C9; // endregion Short16 @@ -2201,7 +2201,7 @@ public class VMOpCode { *
  • Push the converted byte8 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow an int32 value to a byte8 type, suitable when a smaller numeric type is required.

    + *

    This opcode is used to narrow an int32 value to a byte8 type.

    */ public static final int I2B = 0x00CA; /** @@ -2215,7 +2215,7 @@ public class VMOpCode { *
  • Push the converted short16 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is typically used to narrow an int32 value to a short16 type when a smaller data representation is needed.

    + *

    This opcode is typically used to narrow an int32 value to a short16 type.

    */ public static final int I2S = 0x00CB; /** @@ -2229,7 +2229,7 @@ public class VMOpCode { *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is commonly used to widen an int32 value to a long64 type to accommodate larger numeric ranges.

    + *

    This opcode is commonly used to widen an int32 value to a long64 type.

    */ public static final int I2L = 0x00CC; /** @@ -2243,7 +2243,7 @@ public class VMOpCode { *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert an int32 value to a float32 type when floating-point arithmetic is required.

    + *

    This opcode is used to convert an int32 value to a float32 type.

    */ public static final int I2F = 0x00CD; /** @@ -2257,7 +2257,7 @@ public class VMOpCode { *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.

    + *

    This opcode is used to widen an int32 value to a double64 type.

    */ public static final int I2D = 0x00CE; // endregion Int32 @@ -2274,7 +2274,7 @@ public class VMOpCode { *
  • Push the converted byte8 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a long64 value to a byte8 type, suitable when a smaller numeric type is required.

    + *

    This opcode is used to narrow a long64 value to a byte8 type.

    */ public static final int L2B = 0x00CF; /** @@ -2288,7 +2288,7 @@ public class VMOpCode { *
  • Push the converted short16 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a long64 value to a short16 type, suitable when a smaller numeric type is required.

    + *

    This opcode is used to narrow a long64 value to a short16 type.

    */ public static final int L2S = 0x00D0; /** @@ -2302,7 +2302,7 @@ public class VMOpCode { *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is typically used to narrow a long64 value to an int32 type for further integer operations.

    + *

    This opcode is typically used to narrow a long64 value.

    */ public static final int L2I = 0x00D1; /** @@ -2316,7 +2316,7 @@ public class VMOpCode { *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert a long64 value to a float32 type, typically for floating-point arithmetic involving long values.

    + *

    This opcode is used to convert a long64 value to a float32 type.

    */ public static final int L2F = 0x00D2; /** @@ -2330,7 +2330,7 @@ public class VMOpCode { *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen a long64 value to a double64 type for high-precision floating-point computations.

    + *

    This opcode is used to widen a long64 value to a double64 type.

    */ public static final int L2D = 0x00D3; // endregion Long64 @@ -2347,7 +2347,7 @@ public class VMOpCode { *
  • 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-based operations or comparisons.

    + *

    This opcode is used to convert a float32 value to a byte8 type.

    */ public static final int F2B = 0x00D4; /** @@ -2361,7 +2361,7 @@ public class VMOpCode { *
  • 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-based operations or comparisons.

    + *

    This opcode is used to convert a float32 value to a short16 type.

    */ public static final int F2S = 0x00D5; /** @@ -2375,7 +2375,7 @@ public class VMOpCode { *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to convert a float32 value to an int32 type for further integer-based operations or comparisons.

    + *

    This opcode is used to convert a float32 value to an int32 type.

    */ public static final int F2I = 0x00D6; /** @@ -2389,7 +2389,7 @@ public class VMOpCode { *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to widen a float32 value to a long64 type, which is useful when operations require a larger numeric range.

    + *

    This opcode is used to widen a float32 value to a long64 type.

    */ public static final int F2L = 0x00D7; /** @@ -2403,7 +2403,7 @@ public class VMOpCode { *
  • Push the converted double64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to promote a float32 value to a double64 type, thereby increasing precision for floating-point computations.

    + *

    This opcode is used to promote a float32 value to a double64 type.

    */ public static final int F2D = 0x00D8; // endregion Float32 @@ -2420,7 +2420,7 @@ public class VMOpCode { *
  • 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 processing.

    + *

    This opcode is used to narrow a double64 value to a byte8 type.

    */ public static final int D2B = 0x00D9; /** @@ -2434,7 +2434,7 @@ public class VMOpCode { *
  • Push the converted short16 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to a short16 type for further integer-based processing.

    + *

    This opcode is used to narrow a double64 value to a short16 type.

    */ public static final int D2S = 0x00DA; /** @@ -2448,7 +2448,7 @@ public class VMOpCode { *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to an int32 type for further integer-based processing.

    + *

    This opcode is used to narrow a double64 value to an int32 type.

    */ public static final int D2I = 0x00DB; /** @@ -2462,7 +2462,7 @@ public class VMOpCode { *
  • Push the converted long64 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to a long64 type, which can then be used for integer operations.

    + *

    This opcode is used to narrow a double64 value to a long64 type.

    */ public static final int D2L = 0x00DC; /** @@ -2476,7 +2476,7 @@ public class VMOpCode { *
  • Push the converted float32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is used to narrow a double64 value to a float32 type when lower precision floating-point arithmetic is acceptable.

    + *

    This opcode is used to narrow a double64 value to a float32 type.

    */ public static final int D2F = 0x00DD; // endregion Double64 From 68c1e3a4121bfa479be72565d7eb2d47f5daf9c6 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 11 Jul 2025 10:29:32 +0800 Subject: [PATCH 36/37] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E8=BF=90=E8=A1=8C=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 Demo11 和 Demo12 应用到测试运行列表- 现有应用顺序不变,新增应用放在末尾 --- .run/测试.run.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.run/测试.run.xml b/.run/测试.run.xml index 08ceacd..5000363 100644 --- a/.run/测试.run.xml +++ b/.run/测试.run.xml @@ -3,6 +3,8 @@ + + From 93f65585e0bf5c3f05ab2844e9a56a4b39fa1804 Mon Sep 17 00:00:00 2001 From: Luke Date: Fri, 11 Jul 2025 10:33:46 +0800 Subject: [PATCH 37/37] =?UTF-8?q?docs:=20=E5=AE=8C=E5=96=84=20L2I=20?= =?UTF-8?q?=E6=8C=87=E4=BB=A4=E7=9A=84=E6=B3=A8=E9=87=8A=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8654d2e..73d8ed5 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2302,7 +2302,7 @@ public class VMOpCode { *
  • Push the converted int32 value back onto the operand stack for subsequent operations.
  • * * - *

    This opcode is typically used to narrow a long64 value.

    + *

    This opcode is typically used to narrow a long64 value to an int32 type .

    */ public static final int L2I = 0x00D1; /**