* 该类实现了 {@link InstructionGenerator} 接口, * 负责将 IR 中的 {@link IRCompareJumpInstruction}(条件比较并跳转指令) * 转换为目标虚拟机(VM)可执行的指令序列。 *
* - * 主要功能 + * 主要功能 *- * 仅覆盖目前常见的整数与浮点类型提升与转换,后续有新类型可补充。 - *
- * - * @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 指令序列。 *+ * 在进行数值类型运算、比较等操作时,低优先级的类型会被提升为高优先级类型参与运算。 + * 例如 int + long 运算,int 会被提升为 long,最终运算结果类型为 long。 + *
+ * 类型优先级从高到低依次为: + * D(double):6 + * F(float) :5 + * L(long) :4 + * I(int) :3 + * S(short) :2 + * B(byte) :1 + * 未识别类型 :0 + */ +public class TypePromoteUtils { + + /** + * 返回数值类型的宽度优先级,数值越大类型越宽。 + * 类型及优先级映射如下: + * D(double): 6 + * F(float) : 5 + * L(long) : 4 + * I(int) : 3 + * S(short) : 2 + * B(byte) : 1 + * 未知类型 : 0 + * + * @param p 类型标记字符(B/S/I/L/F/D) + * @return 优先级数值(0 表示未知类型) + */ + 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); + } + + /** + * 获取类型转换指令名(例如 "I2L", "F2D"),表示从源类型到目标类型的转换操作。 + * 如果源类型和目标类型相同,则返回 null,表示无需转换。 + *
+ * 支持的类型标记字符包括:B(byte)、S(short)、I(int)、L(long)、F(float)、D(double)。 + * 所有可能的类型转换均已覆盖,如下所示: + * B → S/I/L/F/D + * S → B/I/L/F/D + * I → B/S/L/F/D + * L → B/S/I/F/D + * F → B/S/I/L/D + * D → B/S/I/L/F + * + * @param from 源类型标记字符 + * @param to 目标类型标记字符 + * @return 类型转换指令名(如 "L2I"),如无须转换则返回 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; + }; + } +} 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; *
L/l 判定)选择
- * 正确的 IR 比较指令,保证 int/long 均能正常运行。
+ * 工具类,用于比较运算相关的类型推断和指令选择。
+ * + * 该类主要用于根据左右操作数的静态类型,自动选择正确的 IR 层比较操作码。 + * 支持自动类型提升,保证 int、long、float、double 等类型的比较均能得到正确的 IR 指令。 + *
+ * + * 类型判定支持: + *主要功能:
- *
+ * 主要功能:
+ * - 解析字面量常量,自动推断类型
+ * - 自动匹配并选择适合的算术/比较操作码
+ * - 表达式类型的合并与类型提升
+ * - 支持线程隔离的函数级默认类型后缀
*/
public final class ExpressionUtils {
private ExpressionUtils() {}
- /* ────────────────── 线程级默认类型后缀 ────────────────── */
+ // ───────────── 线程级默认类型后缀 ─────────────
- /** 默认类型后缀(如当前函数返回类型),线程隔离。 */
+ /**
+ * 当前线程的默认类型后缀(如当前函数返回类型等),用于类型推断兜底。
+ */
private static final ThreadLocal
+ * 支持的字面量后缀有 b/s/l/f/d(大小写均可)。
+ * 无后缀时,优先参考 IRContext 当前变量类型,否则根据字面量格式(含'.'或'e'等)判断为 double,否则为 int。
+ *
+ * @param ctx IRContext,允许参考变量声明类型
+ * @param value 数字字面量字符串
+ * @return 对应类型的 IRConstant 常量
*/
public static IRConstant buildNumberConstant(IRContext ctx, String value) {
char suffix = value.isEmpty() ? '\0'
@@ -56,7 +75,7 @@ public final class ExpressionUtils {
String digits = switch (suffix) {
case 'b','s','l','f','d' -> value.substring(0, value.length() - 1);
default -> {
- /* 如果字面量本身没有后缀,则回退到变量目标类型(如声明语句左值) */
+ // 无后缀,优先参考变量类型
if (ctx.getVarType() != null) {
String t = ctx.getVarType();
suffix = switch (t) {
@@ -73,7 +92,7 @@ public final class ExpressionUtils {
}
};
- /* 创建常量 */
+ // 生成常量对象
return switch (suffix) {
case 'b' -> new IRConstant(Byte.parseByte(digits));
case 's' -> new IRConstant(Short.parseShort(digits));
@@ -86,10 +105,13 @@ public final class ExpressionUtils {
};
}
- /* ────────────────────── 一元运算 ────────────────────── */
+ // ───────────── 一元运算指令匹配 ─────────────
/**
- * 推断一元取负(-)运算应使用的 {@link IROpCode}。
+ * 根据表达式节点的类型后缀,选择对应的取负(-)运算操作码。
+ *
+ * @param operand 操作数表达式
+ * @return 匹配类型的 IROpCode
*/
public static IROpCode negOp(ExpressionNode operand) {
char t = typeChar(operand);
@@ -99,34 +121,54 @@ public final class ExpressionUtils {
case 'l' -> IROpCode.NEG_L64;
case 'f' -> IROpCode.NEG_F32;
case 'd' -> IROpCode.NEG_D64;
- default -> IROpCode.NEG_I32; // '\0' 或 'i'
+ default -> IROpCode.NEG_I32; // 无法推断或为 int
};
}
- /* ────────────────── 比较运算(已适配 long) ────────────────── */
+ // ───────────── 比较运算相关 ─────────────
- /** 判断给定字符串是否是比较运算符(==, !=, <, >, <=, >=)。 */
+ /**
+ * 判断给定字符串是否为支持的比较运算符(==, !=, <, >, <=, >=)。
+ *
+ * @param op 操作符字符串
+ * @return 若为比较运算符返回 true,否则返回 false
+ */
public static boolean isComparisonOperator(String op) {
return ComparisonUtils.isComparisonOperator(op);
}
/**
- * 兼容旧调用:仅凭操作符返回 int32 比较指令。
+ * 兼容旧逻辑:仅凭操作符直接返回 int32 比较指令。
+ *
+ * @param op 比较操作符
+ * @return int32 类型的比较操作码
*/
public static IROpCode cmpOp(String op) {
- return IROpCodeMappings.CMP_I32.get(op); // 旧逻辑:一律 i32
+ return IROpCodeMappings.CMP_I32.get(op);
}
/**
- * 推荐调用:根据左右表达式类型自动选择 int / long 比较指令。
+ * 推荐调用:根据左右表达式类型自动选择 int/long/float/double 等合适的比较操作码。
+ *
+ * @param variables 变量名到类型的映射
+ * @param op 比较符号
+ * @param left 左操作数表达式
+ * @param right 右操作数表达式
+ * @return 匹配类型的比较操作码
*/
- public static IROpCode cmpOp(String op, ExpressionNode left, ExpressionNode right) {
- return ComparisonUtils.cmpOp(op, left, right);
+ public static IROpCode cmpOp(Map
+ * 类型推断优先使用左右表达式的类型后缀,推断失败时回退为线程级默认类型后缀,再失败则默认为 int32。
+ *
+ * @param op 算术操作符
+ * @param left 左表达式
+ * @param right 右表达式
+ * @return 匹配类型的 IROpCode
*/
public static IROpCode resolveOpCode(String op,
ExpressionNode left,
ExpressionNode right) {
-
- /* 1. 尝试根据字面量推断 */
+ // 1. 优先根据表达式类型推断
char suffix = resolveSuffix(left, right);
-
- /* 2. 若失败则使用函数级默认类型 */
+ // 2. 推断失败则使用线程默认类型
if (suffix == '\0') suffix = DEFAULT_SUFFIX.get();
-
- /* 3. 仍失败则默认为 int32 */
+ // 3. 仍失败则默认为 int32
Map This opcode is implemented by the {@link B2DCommand} class, which defines its specific execution logic. Execution Steps: This opcode is used to widen a byte8 value to a double64 type. This opcode is implemented by the {@link B2FCommand} class, which defines its specific execution logic. Execution Steps: This opcode is used to widen a byte8 value to a float32 type.
+ *
+ *
+ *
+ *
+ *
+ *
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 new file mode 100644 index 0000000..3bcff86 --- /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:
+ *This opcode is used to widen a byte8 value to a long64 type.
+ */ +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..167d318 --- /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:
+ *This opcode is used to widen a byte8 value to a short16 type.
+ */ +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; + } +} 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..8106ae8 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2BCommand.java @@ -0,0 +1,48 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * D2BCommand Opcode: Represents the type conversion operation from double64 to byte8 in the virtual machine. + *This opcode is implemented by the {@link D2BCommand} class, which defines its specific execution logic.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to a byte8 type.
+ */ +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/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; *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; *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; *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 new file mode 100644 index 0000000..49da2f1 --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/D2SCommand.java @@ -0,0 +1,48 @@ +package org.jcnc.snow.vm.commands.type.conversion; + +import org.jcnc.snow.vm.interfaces.Command; +import org.jcnc.snow.vm.module.CallStack; +import org.jcnc.snow.vm.module.LocalVariableStore; +import org.jcnc.snow.vm.module.OperandStack; + +/** + * D2SCommand Opcode: Represents the type conversion operation from double64 to short16 in the virtual machine. + *This opcode is implemented by the {@link D2SCommand} class, which defines its specific execution logic.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to a short16 type.
+ */ +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; + } +} 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..3277271 --- /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:
+ *This opcode is used to convert a float32 value to a byte8 type.
+ */ +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/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; *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; *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; *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 new file mode 100644 index 0000000..312c828 --- /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:
+ *This opcode is used to convert a float32 value to a short16 type.
+ */ +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; + } +} 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; *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; *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; *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; *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; *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 new file mode 100644 index 0000000..b005ca2 --- /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:
+ *This opcode is used to widen a long64 value to a byte8 type.
+ */ +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/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; *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; *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; *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 new file mode 100644 index 0000000..70c5e2a --- /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:
+ *This opcode is used to widen a long64 value to a short16 type.
+ */ +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; + } +} 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..159504f --- /dev/null +++ b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2BCommand.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; + +/** + * 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:
+ *This opcode is used to widen a short16 value to a byte8 type.
+ */ +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) { + short value = (short) 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/S2DCommand.java b/src/main/java/org/jcnc/snow/vm/commands/type/conversion/S2DCommand.java new file mode 100644 index 0000000..50c6e4e --- /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:
+ *This opcode is used to widen a short16 value to a double64 type.
+ */ +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..9493a55 --- /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:
+ *This opcode is used to widen a short16 value to a float32 type.
+ */ +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/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; *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 new file mode 100644 index 0000000..194344f --- /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:
+ *This opcode is used to widen a short16 value to a long64 type.
+ */ +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; + } +} 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..73d8ed5 100644 --- a/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java +++ b/src/main/java/org/jcnc/snow/vm/engine/VMOpCode.java @@ -2043,216 +2043,21 @@ public class VMOpCode { // endregion // region Type Conversion (0x00C0-0x00DF) + // region Byte8 (0x00C0-0xC4) /** - * 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.
+ * 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:
*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:
- *This opcode is typically used to narrow an int32 value to a short16 type when a smaller data representation is needed.
+ *This opcode is commonly used to widen a byte8 value to a short16 type.
*/ - public static final int I2S = 0x00C1; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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:
- *This opcode is used to widen an int32 value to a double64 type, providing high-precision floating-point calculations.
- */ - public static final int I2D = 0x00C3; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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.
- * - *Execution Steps:
- *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:
- *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; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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.
- * - *Execution Steps:
- *This opcode is used to narrow a double64 value to an int32 type for further integer-based processing.
- */ - public static final int D2I = 0x00CB; - /** - * 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.
- * - *Execution Steps:
- *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; - /** - * 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.
- * - *Execution Steps:
- *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:
- *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; + 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.
@@ -2264,10 +2069,418 @@ public class VMOpCode { *This opcode is used to widen a byte8 value to an int32 type to ensure compatibility with integer-based operations.
+ *This opcode is commonly used to widen a byte8 value to an int32 type.
*/ - public static final int B2I = 0x00CF; - // endregion + 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:
+ *This opcode is commonly used to widen a byte8 value to a long64 type.
+ */ + 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:
+ *This opcode is used to convert a byte8 value to a float32 type.
+ */ + 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:
+ *This opcode is used to widen a byte8 value to a double64 type.
+ */ + public static final int B2D = 0x00C4; + // 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:
+ *This opcode is used to narrow a short16 value to a byte8 type.
+ */ + 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:
+ *This opcode is commonly used to widen a short16 value to an int32 type.
+ */ + 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:
+ *This opcode is commonly used to widen a short16 value to a long64 type.
+ */ + 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:
+ *This opcode is used to convert a short16 value to a float32 type.
+ */ + 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:
+ *This opcode is used to widen a short16 value to a double64 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to narrow an int32 value to a byte8 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is typically used to narrow an int32 value to a short16 type.
+ */ + 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:
+ *This opcode is commonly used to widen an int32 value to a long64 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to convert an int32 value to a float32 type.
+ */ + 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:
+ *This opcode is used to widen an int32 value to a double64 type.
+ */ + public static final int I2D = 0x00CE; + // 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:
+ *This opcode is used to narrow a long64 value to a byte8 type.
+ */ + 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:
+ *This opcode is used to narrow a long64 value to a short16 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is typically used to narrow a long64 value to an int32 type .
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to convert a long64 value to a float32 type.
+ */ + 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:
+ *This opcode is used to widen a long64 value to a double64 type.
+ */ + public static final int L2D = 0x00D3; + // 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:
+ *This opcode is used to convert a float32 value to a byte8 type.
+ */ + 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:
+ *This opcode is used to convert a float32 value to a short16 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to convert a float32 value to an int32 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to widen a float32 value to a long64 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to promote a float32 value to a double64 type.
+ */ + public static final int F2D = 0x00D8; + // 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:
+ *This opcode is used to narrow a double64 value to a byte8 type.
+ */ + public static final int D2B = 0x00D9; + /** + * 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:
+ *This opcode is used to narrow a double64 value to a short16 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to an int32 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to a long64 type.
+ */ + 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.
+ * + *Execution Steps:
+ *This opcode is used to narrow a double64 value to a float32 type.
+ */ + 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)