*
* @param condition 控制分支执行的条件表达式
* @param thenBranch 条件为 true 时执行的语句块
* @param elseBranch 条件为 false 时执行的语句块(可为空)
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record IfNode(
ExpressionNode condition,
List thenBranch,
List elseBranch,
- int line,
- int column,
- String file
+ NodeContext context
) implements StatementNode {
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/ImportNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/ImportNode.java
index c6b65e9..a45c751 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/ImportNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/ImportNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.Node;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
/**
* {@code ImportNode} 表示抽象语法树(AST)中的 import 语句节点。
@@ -14,14 +15,10 @@ import org.jcnc.snow.compiler.parser.ast.base.Node;
*
*
* @param moduleName 被导入的模块名称,通常为点分层次结构(如 "core.utils")
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record ImportNode(
String moduleName,
- int line,
- int column,
- String file
+ NodeContext context
) implements Node {
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/LoopNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/LoopNode.java
index a8ddbe1..2ba283e 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/LoopNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/LoopNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
import java.util.List;
@@ -17,17 +18,13 @@ import java.util.List;
* @param condition 每次迭代前评估的条件表达式,控制循环是否继续
* @param update 每轮迭代完成后执行的更新语句
* @param body 循环体语句列表,表示循环主体执行逻辑
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点的上下文信息(包含行号、列号、文件名等)
*/
public record LoopNode(
StatementNode initializer,
ExpressionNode condition,
StatementNode update,
List body,
- int line,
- int column,
- String file
+ NodeContext context
) implements StatementNode {
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/MemberExpressionNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/MemberExpressionNode.java
index d0ac38e..8ab233b 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/MemberExpressionNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/MemberExpressionNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
/**
* {@code MemberExpressionNode} 表示抽象语法树(AST)中的成员访问表达式节点。
@@ -9,18 +10,14 @@ import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
* 成员访问常见于结构体、模块、对象导入等上下文中,是表达式链中常见的构件之一。
*
*
- * @param object 左侧对象表达式,表示成员所属的作用域或容器
- * @param member 要访问的成员名称(字段名或方法名)
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param object 左侧对象表达式,表示成员所属的作用域或容器
+ * @param member 要访问的成员名称(字段名或方法名)
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record MemberExpressionNode(
ExpressionNode object,
String member,
- int line,
- int column,
- String file
+ NodeContext context
) implements ExpressionNode {
/**
@@ -35,4 +32,4 @@ public record MemberExpressionNode(
public String toString() {
return object + "." + member;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/ModuleNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/ModuleNode.java
index 05d47de..84262dd 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/ModuleNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/ModuleNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.Node;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import java.util.List;
import java.util.StringJoiner;
@@ -8,22 +9,17 @@ import java.util.StringJoiner;
/**
* 表示模块定义的 AST 节点。
* 一个模块通常由模块名、导入语句列表和函数定义列表组成。
- * }
*
* @param name 模块名称。
* @param imports 模块导入列表,每个导入是一个 {@link ImportNode}。
* @param functions 模块中的函数列表,每个函数是一个 {@link FunctionNode}。
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record ModuleNode(
String name,
List imports,
List functions,
- int line,
- int column,
- String file
+ NodeContext context
) implements Node {
/**
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/NumberLiteralNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/NumberLiteralNode.java
index 9f253e2..6806112 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/NumberLiteralNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/NumberLiteralNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
/**
* {@code NumberLiteralNode} 表示抽象语法树(AST)中的数字字面量表达式节点。
@@ -11,15 +12,11 @@ import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
*
*
* @param value 数字字面量的原始字符串表示
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record NumberLiteralNode(
String value,
- int line,
- int column,
- String file
+ NodeContext context
) implements ExpressionNode {
/**
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/ParameterNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/ParameterNode.java
index 0fbdc18..593d46f 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/ParameterNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/ParameterNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.Node;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
/**
* {@code ParameterNode} 表示抽象语法树(AST)中的函数参数定义节点。
@@ -9,18 +10,14 @@ import org.jcnc.snow.compiler.parser.ast.base.Node;
* 用于构成函数签名并参与类型检查与函数调用匹配。
*
*
- * @param name 参数名称标识符
- * @param type 参数类型字符串(如 "int"、"string")
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param name 参数名称标识符
+ * @param type 参数类型字符串(如 "int"、"string")
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record ParameterNode(
String name,
String type,
- int line,
- int column,
- String file
+ NodeContext context
) implements Node {
/**
@@ -35,4 +32,4 @@ public record ParameterNode(
public String toString() {
return name + ":" + type;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/ReturnNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/ReturnNode.java
index 0fc2254..b6d17e1 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/ReturnNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/ReturnNode.java
@@ -2,6 +2,7 @@ package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import java.util.Optional;
@@ -23,25 +24,18 @@ public class ReturnNode implements StatementNode {
/** 可选的返回值表达式 */
private final Optional expression;
- /** 当前节点所在的行号 **/
- private final int line;
-
- /** 当前节点所在的列号 **/
- private final int column;
-
- /** 当前节点所在的文件 **/
- private final String file;
+ /** 节点上下文信息(包含行号、列号等) */
+ private final NodeContext context;
/**
* 构造一个 {@code ReturnNode} 实例。
*
* @param expression 返回值表达式,如果无返回值则可为 {@code null}
+ * @param context 节点上下文信息(包含行号、列号等)
*/
- public ReturnNode(ExpressionNode expression, int line, int column, String file) {
+ public ReturnNode(ExpressionNode expression, NodeContext context) {
this.expression = Optional.ofNullable(expression);
- this.line = line;
- this.column = column;
- this.file = file;
+ this.context = context;
}
/**
@@ -54,27 +48,12 @@ public class ReturnNode implements StatementNode {
}
/**
- * 获取当前表达式所在的行号。
+ * 获取节点上下文信息(包含行号、列号等)。
*
- * @return 当前表达式的行号。
+ * @return NodeContext 实例
*/
- public int line() {
- return line;
+ @Override
+ public NodeContext context() {
+ return context;
}
-
- /**
- * 获取当前表达式所在的列号。
- *
- * @return 当前表达式的列号。
- */
- public int column() {
- return column;
- }
-
- /**
- * 获取当前表达式所在的文件名。
- *
- * @return 当前表达式所在的文件名。
- */
- public String file() { return file; }
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/StringLiteralNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/StringLiteralNode.java
index daa9f42..dd0e61f 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/StringLiteralNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/StringLiteralNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
/**
* {@code StringLiteralNode} 表示抽象语法树(AST)中的字符串字面量表达式节点。
@@ -10,15 +11,11 @@ import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
*
*
* @param value 字符串常量的内容,原始值中不包含双引号
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record StringLiteralNode(
String value,
- int line,
- int column,
- String file
+ NodeContext context
) implements ExpressionNode {
/**
@@ -33,4 +30,4 @@ public record StringLiteralNode(
public String toString() {
return "\"" + value + "\"";
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/UnaryExpressionNode.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/UnaryExpressionNode.java
index 7e38ebc..cc22e6a 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/UnaryExpressionNode.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/UnaryExpressionNode.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.ast;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
/**
* {@code UnaryExpressionNode} —— 前缀一元运算 AST 节点。
@@ -15,16 +16,12 @@ import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
*
* @param operator 一元运算符(仅 "-" 或 "!")
* @param operand 运算对象 / 右操作数
- * @param line 当前节点所在的行号
- * @param column 当前节点所在的列号
- * @param file 当前节点所在的文件
+ * @param context 节点上下文信息(包含行号、列号等)
*/
public record UnaryExpressionNode(
String operator,
ExpressionNode operand,
- int line,
- int column,
- String file
+ NodeContext context
) implements ExpressionNode {
/**
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/base/Node.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/base/Node.java
index 5cba805..8b1e906 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/ast/base/Node.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/base/Node.java
@@ -17,23 +17,7 @@ package org.jcnc.snow.compiler.parser.ast.base;
*/
public interface Node {
/**
- * 获取当前表达式所在的行号。
- *
- * @return 当前表达式的行号。
+ * 获取节点的上下文(行/列/文件等信息)。
*/
- int line();
-
- /**
- * 获取当前表达式所在的列号。
- *
- * @return 当前表达式的列号。
- */
- int column();
-
- /**
- * 获取当前表达式所在的文件名。
- *
- * @return 当前表达式所在的文件名。
- */
- String file();
+ NodeContext context();
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/ast/base/NodeContext.java b/src/main/java/org/jcnc/snow/compiler/parser/ast/base/NodeContext.java
new file mode 100644
index 0000000..e73ce21
--- /dev/null
+++ b/src/main/java/org/jcnc/snow/compiler/parser/ast/base/NodeContext.java
@@ -0,0 +1,11 @@
+package org.jcnc.snow.compiler.parser.ast.base;
+
+/**
+ * NodeContext 记录 AST 节点的位置信息(文件、行、列)。
+ */
+public record NodeContext(int line, int column, String file) {
+ @Override
+ public String toString() {
+ return file + ":" + line + ":" + column;
+ }
+}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/BinaryOperatorParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/BinaryOperatorParselet.java
index adee8bd..973b81a 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/BinaryOperatorParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/BinaryOperatorParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.parser.ast.BinaryExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.InfixParselet;
@@ -46,12 +47,9 @@ public record BinaryOperatorParselet(Precedence precedence, boolean leftAssoc) i
int prec = precedence.ordinal();
// 右侧表达式根据结合性确定优先级绑定
- ExpressionNode right = new PrattExpressionParser().parseExpression(
- ctx,
- leftAssoc ? Precedence.values()[prec] : Precedence.values()[prec - 1]
- );
+ ExpressionNode right = new PrattExpressionParser().parseExpression(ctx, leftAssoc ? Precedence.values()[prec] : Precedence.values()[prec - 1]);
- return new BinaryExpressionNode(left, op.getLexeme(), right, line, column, file);
+ return new BinaryExpressionNode(left, op.getLexeme(), right, new NodeContext(line, column, file));
}
/**
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/BoolLiteralParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/BoolLiteralParselet.java
index cfd49db..677896d 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/BoolLiteralParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/BoolLiteralParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.parser.ast.BoolLiteralNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.PrefixParselet;
@@ -28,6 +29,6 @@ public class BoolLiteralParselet implements PrefixParselet {
*/
@Override
public ExpressionNode parse(ParserContext ctx, Token token) {
- return new BoolLiteralNode(token.getLexeme(), token.getLine(), token.getCol(), ctx.getSourceName());
+ return new BoolLiteralNode(token.getLexeme(), new NodeContext(token.getLine(), token.getCol(), ctx.getSourceName()));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/CallParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/CallParselet.java
index 9f5478a..6fd7f4a 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/CallParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/CallParselet.java
@@ -2,6 +2,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.parser.ast.CallExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.InfixParselet;
@@ -45,7 +46,8 @@ public class CallParselet implements InfixParselet {
ctx.getTokens().expect(")"); // 消费并验证 ")"
// 创建 CallExpressionNode 并传递位置信息
- return new CallExpressionNode(left, args, line, column, file);
+ return new CallExpressionNode(left, args, new NodeContext(line, column, file));
+
}
/**
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/IdentifierParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/IdentifierParselet.java
index 7e46337..f0b9a34 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/IdentifierParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/IdentifierParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.parser.ast.IdentifierNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.PrefixParselet;
@@ -29,6 +30,6 @@ public class IdentifierParselet implements PrefixParselet {
int column = ctx.getTokens().peek(-1).getCol();
String file = ctx.getSourceName();
- return new IdentifierNode(token.getLexeme(), line, column, file);
+ return new IdentifierNode(token.getLexeme(), new NodeContext(line, column, file));
}
}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/MemberParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/MemberParselet.java
index ed3cd58..76f1c7f 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/MemberParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/MemberParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.MemberExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.context.TokenStream;
import org.jcnc.snow.compiler.parser.expression.base.InfixParselet;
@@ -34,7 +35,7 @@ public class MemberParselet implements InfixParselet {
String file = ctx.getSourceName();
String member = ts.expectType(TokenType.IDENTIFIER).getLexeme();
- return new MemberExpressionNode(left, member, line, column, file);
+ return new MemberExpressionNode(left, member, new NodeContext(line, column, file));
}
/**
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/NumberLiteralParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/NumberLiteralParselet.java
index 4b75174..69ac8d7 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/NumberLiteralParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/NumberLiteralParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.Token;
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;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.PrefixParselet;
@@ -24,6 +25,6 @@ public class NumberLiteralParselet implements PrefixParselet {
*/
@Override
public ExpressionNode parse(ParserContext ctx, Token token) {
- return new NumberLiteralNode(token.getLexeme(), token.getLine(), token.getCol(), ctx.getSourceName());
+ return new NumberLiteralNode(token.getLexeme(), new NodeContext(token.getLine(), token.getCol(), ctx.getSourceName()));
}
}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/StringLiteralParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/StringLiteralParselet.java
index b4eb3b3..542a097 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/StringLiteralParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/StringLiteralParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
import org.jcnc.snow.compiler.parser.ast.StringLiteralNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.PrefixParselet;
@@ -27,6 +28,6 @@ public class StringLiteralParselet implements PrefixParselet {
public ExpressionNode parse(ParserContext ctx, Token token) {
String raw = token.getRaw();
String content = raw.substring(1, raw.length() - 1);
- return new StringLiteralNode(content, token.getLine(), token.getCol(), ctx.getSourceName());
+ return new StringLiteralNode(content, new NodeContext(token.getLine(), token.getCol(), ctx.getSourceName()));
}
}
\ No newline at end of file
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/expression/UnaryOperatorParselet.java b/src/main/java/org/jcnc/snow/compiler/parser/expression/UnaryOperatorParselet.java
index 5aedf93..113ab94 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/expression/UnaryOperatorParselet.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/expression/UnaryOperatorParselet.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.expression;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.parser.ast.UnaryExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.base.PrefixParselet;
@@ -55,6 +56,6 @@ public class UnaryOperatorParselet implements PrefixParselet {
/* ------------------------------------------------------------
* 2. 封装成 AST 节点并返回。
* ------------------------------------------------------------ */
- return new UnaryExpressionNode(token.getLexeme(), operand, line, column, file);
+ return new UnaryExpressionNode(token.getLexeme(), operand, new NodeContext(line, column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/function/ASTPrinter.java b/src/main/java/org/jcnc/snow/compiler/parser/function/ASTPrinter.java
index 75ffbca..c12edb3 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/function/ASTPrinter.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/function/ASTPrinter.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.function;
import org.jcnc.snow.compiler.parser.ast.*;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.Node;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
import org.jcnc.snow.compiler.parser.utils.ASTJsonSerializer;
import org.jcnc.snow.compiler.parser.utils.JsonFormatter;
@@ -66,8 +67,8 @@ public class ASTPrinter {
}
}
case FunctionNode(
- String name, List parameters, String returnType, List body
- , int _, int _, String _
+ String name, List parameters, String returnType, List body,
+ NodeContext _
) -> {
System.out.println(pad + "function " + name
+ "(params=" + parameters + ", return=" + returnType + ")");
@@ -82,11 +83,10 @@ public class ASTPrinter {
.orElse("");
System.out.println(pad + "declare " + d.getName() + ":" + d.getType() + init);
}
- case AssignmentNode(String variable, ExpressionNode value, int _, int _, String _) ->
+ case AssignmentNode(String variable, ExpressionNode value, NodeContext _) ->
System.out.println(pad + variable + " = " + value);
case IfNode(
- ExpressionNode condition, List thenBranch, List elseBranch, int _,
- int _, String _
+ ExpressionNode condition, List thenBranch, List elseBranch, NodeContext _
) -> {
System.out.println(pad + "if " + condition);
for (StatementNode stmt : thenBranch) {
@@ -100,8 +100,8 @@ public class ASTPrinter {
}
}
case LoopNode(
- StatementNode initializer, ExpressionNode condition, StatementNode update, List body
- , int _, int _, String _
+ StatementNode initializer, ExpressionNode condition, StatementNode update, List body,
+ NodeContext _
) -> {
System.out.println(pad + "loop {");
print(initializer, indent + 1);
@@ -116,7 +116,7 @@ public class ASTPrinter {
}
case ReturnNode r -> System.out.println(pad + "return" +
r.getExpression().map(e -> " " + e).orElse(""));
- case ExpressionStatementNode(ExpressionNode expression, int _, int _, String _) ->
+ case ExpressionStatementNode(ExpressionNode expression, NodeContext _) ->
System.out.println(pad + expression);
case null, default -> System.out.println(pad + n); // 回退处理
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/function/FunctionParser.java b/src/main/java/org/jcnc/snow/compiler/parser/function/FunctionParser.java
index a7a3449..17597c0 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/function/FunctionParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/function/FunctionParser.java
@@ -2,20 +2,20 @@ package org.jcnc.snow.compiler.parser.function;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.lexer.token.TokenType;
+import org.jcnc.snow.compiler.parser.ast.ReturnNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.base.TopLevelParser;
import org.jcnc.snow.compiler.parser.ast.FunctionNode;
import org.jcnc.snow.compiler.parser.ast.ParameterNode;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
+import org.jcnc.snow.compiler.parser.context.ParseException;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.context.TokenStream;
import org.jcnc.snow.compiler.parser.factory.StatementParserFactory;
import org.jcnc.snow.compiler.parser.utils.FlexibleSectionParser;
import org.jcnc.snow.compiler.parser.utils.FlexibleSectionParser.SectionDefinition;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
/**
* {@code FunctionParser} 是顶层函数定义的语法解析器,
@@ -55,26 +55,55 @@ public class FunctionParser implements TopLevelParser {
*/
@Override
public FunctionNode parse(ParserContext ctx) {
+ // 获取当前解析上下文中的 token 流
TokenStream ts = ctx.getTokens();
- // 获取当前 token 的行号、列号和文件名
+ // 记录当前 token 的行号、列号和源文件名,用于错误报告或生成节点上下文
int line = ctx.getTokens().peek().getLine();
int column = ctx.getTokens().peek().getCol();
String file = ctx.getSourceName();
+ // 解析函数头(例如可能是 `function` 关键字等)
parseFunctionHeader(ts);
+
+ // 解析函数名
String functionName = parseFunctionName(ts);
+ // 用于存放解析出来的参数列表
List parameters = new ArrayList<>();
+ // 用于存放返回类型,这里用数组是为了在闭包中修改其值
String[] returnType = new String[1];
+ // 用于存放函数体语句列表
List body = new ArrayList<>();
+ // 获取函数可以包含的可选节(如参数、返回类型、主体等)的定义映射
Map sections = getSectionDefinitions(parameters, returnType, body);
+
+ // 调用通用的多节解析器,实际根据 sections 中注册的规则解析各部分内容
FlexibleSectionParser.parse(ctx, ts, sections);
+ // 如果函数体为空且返回类型为 void,自动补充一个空的 return 语句
+ if (body.isEmpty() && returnType[0].equals("void")) {
+ body.add(new ReturnNode(null, new NodeContext(line, column, file)));
+ }
+
+ // 检查参数名称是否重复
+ Set set = new HashSet<>();
+ parameters.forEach((node) -> {
+ final String name = node.name();
+ if (set.contains(name)) {
+ // 如果参数名重复,抛出带具体行列信息的解析异常
+ throw new ParseException(String.format("参数 `%s` 重定义", name),
+ node.context().line(), node.context().column());
+ }
+ set.add(name);
+ });
+
+ // 解析函数的尾部(例如右大括号或者 end 标志)
parseFunctionFooter(ts);
- return new FunctionNode(functionName, parameters, returnType[0], body, line, column, file);
+ // 返回完整的函数节点,包含函数名、参数、返回类型、函数体以及源位置信息
+ return new FunctionNode(functionName, parameters, returnType[0], body, new NodeContext(line, column, file));
}
/**
@@ -194,7 +223,7 @@ public class FunctionParser implements TopLevelParser {
String ptype = ts.expectType(TokenType.TYPE).getLexeme();
skipComments(ts);
ts.expectType(TokenType.NEWLINE);
- list.add(new ParameterNode(pname, ptype, line, column, file));
+ list.add(new ParameterNode(pname, ptype, new NodeContext(line, column, file)));
}
return list;
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/module/ImportParser.java b/src/main/java/org/jcnc/snow/compiler/parser/module/ImportParser.java
index d5443ac..10ca4d5 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/module/ImportParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/module/ImportParser.java
@@ -1,6 +1,7 @@
package org.jcnc.snow.compiler.parser.module;
import org.jcnc.snow.compiler.lexer.token.TokenType;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.ast.ImportNode;
@@ -57,7 +58,7 @@ public class ImportParser {
.getLexeme();
// 创建 ImportNode 节点并加入列表
- imports.add(new ImportNode(mod, line, column, file));
+ imports.add(new ImportNode(mod, new NodeContext(line, column, file)));
} while (ctx.getTokens().match(",")); // 如果匹配到逗号,继续解析下一个模块名
// 最后必须匹配换行符,标志 import 语句的结束
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/module/ModuleParser.java b/src/main/java/org/jcnc/snow/compiler/parser/module/ModuleParser.java
index 8a21e70..fc8ff02 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/module/ModuleParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/module/ModuleParser.java
@@ -4,6 +4,7 @@ import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.FunctionNode;
import org.jcnc.snow.compiler.parser.ast.ImportNode;
import org.jcnc.snow.compiler.parser.ast.ModuleNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.base.TopLevelParser;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.context.TokenStream;
@@ -93,6 +94,6 @@ public class ModuleParser implements TopLevelParser {
ts.expect("end");
ts.expect("module");
- return new ModuleNode(name, imports, functions, line, column, file);
+ return new ModuleNode(name, imports, functions, new NodeContext(line, column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/statement/DeclarationStatementParser.java b/src/main/java/org/jcnc/snow/compiler/parser/statement/DeclarationStatementParser.java
index 2323ada..a7e6fa3 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/statement/DeclarationStatementParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/statement/DeclarationStatementParser.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.statement;
import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.DeclarationNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.PrattExpressionParser;
@@ -74,6 +75,6 @@ public class DeclarationStatementParser implements StatementParser {
ctx.getTokens().expectType(TokenType.NEWLINE);
// 返回构建好的声明语法树节点
- return new DeclarationNode(name, type, init, line, column, file);
+ return new DeclarationNode(name, type, init, new NodeContext(line, column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/statement/ExpressionStatementParser.java b/src/main/java/org/jcnc/snow/compiler/parser/statement/ExpressionStatementParser.java
index f824b6b..36af619 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/statement/ExpressionStatementParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/statement/ExpressionStatementParser.java
@@ -4,6 +4,7 @@ import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.AssignmentNode;
import org.jcnc.snow.compiler.parser.ast.ExpressionStatementNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.context.TokenStream;
@@ -56,12 +57,12 @@ public class ExpressionStatementParser implements StatementParser {
ts.expect("=");
ExpressionNode value = new PrattExpressionParser().parse(ctx);
ts.expectType(TokenType.NEWLINE);
- return new AssignmentNode(varName, value, line, column, file);
+ return new AssignmentNode(varName, value, new NodeContext(line, column, file));
}
// 普通表达式语句
ExpressionNode expr = new PrattExpressionParser().parse(ctx);
ts.expectType(TokenType.NEWLINE);
- return new ExpressionStatementNode(expr, line, column, file);
+ return new ExpressionStatementNode(expr, new NodeContext(line, column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/statement/IfStatementParser.java b/src/main/java/org/jcnc/snow/compiler/parser/statement/IfStatementParser.java
index eda8bb1..24d6556 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/statement/IfStatementParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/statement/IfStatementParser.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.statement;
import org.jcnc.snow.compiler.lexer.token.Token;
import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.IfNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.PrattExpressionParser;
@@ -125,6 +126,6 @@ public class IfStatementParser implements StatementParser {
ts.expectType(TokenType.NEWLINE);
// 构建并返回 IfNode,包含条件、then 分支和 else 分支
- return new IfNode(condition, thenBranch, elseBranch, line, column, file);
+ return new IfNode(condition, thenBranch, elseBranch, new NodeContext(line, column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/statement/LoopStatementParser.java b/src/main/java/org/jcnc/snow/compiler/parser/statement/LoopStatementParser.java
index 4422636..c1a9c66 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/statement/LoopStatementParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/statement/LoopStatementParser.java
@@ -4,6 +4,7 @@ import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.AssignmentNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
import org.jcnc.snow.compiler.parser.ast.LoopNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.ast.base.StatementNode;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.context.TokenStream;
@@ -116,7 +117,7 @@ public class LoopStatementParser implements StatementParser {
ts1.expect("=");
ExpressionNode expr = new PrattExpressionParser().parse(ctx1);
ts1.expectType(TokenType.NEWLINE);
- update[0] = new AssignmentNode(varName, expr, line, column, file);
+ update[0] = new AssignmentNode(varName, expr, new NodeContext(line, column, file));
ParserUtils.skipNewlines(ts1);
}
));
@@ -150,6 +151,6 @@ public class LoopStatementParser implements StatementParser {
ParserUtils.matchFooter(ts, "loop");
// 返回构造完成的 LoopNode
- return new LoopNode(initializer[0], condition[0], update[0], body, loop_line, loop_column, file);
+ return new LoopNode(initializer[0], condition[0], update[0], body, new NodeContext(loop_line, loop_column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/statement/ReturnStatementParser.java b/src/main/java/org/jcnc/snow/compiler/parser/statement/ReturnStatementParser.java
index 080f1e6..3b4c6c1 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/statement/ReturnStatementParser.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/statement/ReturnStatementParser.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.statement;
import org.jcnc.snow.compiler.lexer.token.TokenType;
import org.jcnc.snow.compiler.parser.ast.ReturnNode;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import org.jcnc.snow.compiler.parser.context.ParserContext;
import org.jcnc.snow.compiler.parser.expression.PrattExpressionParser;
@@ -54,6 +55,6 @@ public class ReturnStatementParser implements StatementParser {
ctx.getTokens().expectType(TokenType.NEWLINE);
// 构建并返回 ReturnNode(可能为空表达式)
- return new ReturnNode(expr, line, column, file);
+ return new ReturnNode(expr, new NodeContext(line, column, file));
}
}
diff --git a/src/main/java/org/jcnc/snow/compiler/parser/utils/ASTJsonSerializer.java b/src/main/java/org/jcnc/snow/compiler/parser/utils/ASTJsonSerializer.java
index 231d9af..278a42c 100644
--- a/src/main/java/org/jcnc/snow/compiler/parser/utils/ASTJsonSerializer.java
+++ b/src/main/java/org/jcnc/snow/compiler/parser/utils/ASTJsonSerializer.java
@@ -3,6 +3,7 @@ package org.jcnc.snow.compiler.parser.utils;
import org.jcnc.snow.compiler.parser.ast.*;
import org.jcnc.snow.compiler.parser.ast.base.ExpressionNode;
import org.jcnc.snow.compiler.parser.ast.base.Node;
+import org.jcnc.snow.compiler.parser.ast.base.NodeContext;
import java.util.*;
@@ -82,8 +83,7 @@ public class ASTJsonSerializer {
return switch (n) {
// 模块节点
case ModuleNode(
- String name, List imports, List functions, _, int _,
- String _
+ String name, List imports, List functions, NodeContext _
) -> {
Map map = newNodeMap("Module");
map.put("name", name);
@@ -181,34 +181,34 @@ public class ASTJsonSerializer {
return switch (expr) {
// 二元表达式
case BinaryExpressionNode(
- ExpressionNode left, String operator, ExpressionNode right, int _, int _, String _
+ ExpressionNode left, String operator, ExpressionNode right, NodeContext _
) -> exprMap("BinaryExpression",
"left", exprToMap(left),
"operator", operator,
"right", exprToMap(right)
);
// 一元表达式
- case UnaryExpressionNode(String operator, ExpressionNode operand, int _, int _, String _) ->
+ case UnaryExpressionNode(String operator, ExpressionNode operand, NodeContext _) ->
exprMap("UnaryExpression",
"operator", operator,
"operand", exprToMap(operand)
);
// 布尔字面量
- case BoolLiteralNode(boolean value, int _, int _, String _) -> exprMap("BoolLiteral", "value", value);
+ case BoolLiteralNode(boolean value, NodeContext _) -> exprMap("BoolLiteral", "value", value);
// 标识符
- case IdentifierNode(String name, int _, int _, String _) -> exprMap("Identifier", "name", name);
+ case IdentifierNode(String name, NodeContext _) -> exprMap("Identifier", "name", name);
// 数字字面量
- case NumberLiteralNode(String value, int _, int _, String _) -> exprMap("NumberLiteral", "value", value);
+ case NumberLiteralNode(String value, NodeContext _) -> exprMap("NumberLiteral", "value", value);
// 字符串字面量
- case StringLiteralNode(String value, int _, int _, String _) -> exprMap("StringLiteral", "value", value);
+ case StringLiteralNode(String value, NodeContext _) -> exprMap("StringLiteral", "value", value);
// 调用表达式
- case CallExpressionNode(ExpressionNode callee, List arguments, int _, int _, String _) -> {
+ case CallExpressionNode(ExpressionNode callee, List arguments, NodeContext _) -> {
List
*
- *
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:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a long64 type.
+ */
+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:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a short16 value.
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a short16 type.
+ */
+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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a double64 value to a byte8 type.
+ */
+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;
*
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
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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a double64 value to 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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to convert a float32 value to a byte8 type.
+ */
+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;
*
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
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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to convert a float32 value to a short16 type.
+ */
+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;
*
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
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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a byte8 value.
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a long64 value to a byte8 type.
+ */
+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;
*
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
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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a short16 value.
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a long64 value to a short16 type.
+ */
+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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a byte8 value.
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to a byte8 type.
+ */
+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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a double64 value.
+ *
Push the converted double64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to 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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a float32 value.
+ *
Push the converted float32 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to 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;
*
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
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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to a long64 type.
+ */
+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:
*
- *
Pop the top int32 value from the operand stack.
- *
Convert the int32 value to a long64 value.
- *
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.
- */
- 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:
- *
- *
Pop the top int32 value from the operand stack.
- *
Convert the int32 value to a short16 value (this may involve truncation).
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a short16 value.
*
Push the converted short16 value back onto the operand stack for subsequent operations.
*
*
- *
This opcode is 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:
- *
- *
Pop the top int32 value from the operand stack.
- *
Convert the int32 value to a byte8 value (this may involve truncation).
- *
Push the converted byte8 value back onto the operand stack for subsequent operations.
- *
- *
- *
This opcode is used to narrow 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:
- *
- *
Pop the top int32 value from the operand stack.
- *
Convert the int32 value to a double64 value.
- *
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.
- */
- 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:
- *
- *
Pop the top int32 value from the operand stack.
- *
Convert the int32 value to a float32 value.
- *
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.
- */
- 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:
- *
- *
Pop the top long64 value from the operand stack.
- *
Convert the long64 value to an int32 value (this may involve truncation).
- *
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.
- */
- 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:
- *
- *
Pop the top long64 value from the operand stack.
- *
Convert the long64 value to a double64 value.
- *
Push the converted double64 value back onto the operand stack for subsequent operations.
- *
- *
- *
This opcode is used to widen a 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:
- *
- *
Pop the top long64 value from the operand stack.
- *
Convert the long64 value to a float32 value.
- *
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.
- */
- 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:
- *
- *
Pop the top float32 value from the operand stack.
- *
Convert the float32 value to an int32 value (this may involve truncation).
- *
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.
- */
- 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:
- *
- *
Pop the top float32 value from the operand stack.
- *
Convert the float32 value to a long64 value.
- *
Push the converted long64 value back onto the operand stack for subsequent operations.
- *
- *
- *
This opcode is used to widen a 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:
- *
- *
Pop the top float32 value from the operand stack.
- *
Convert the float32 value to a double64 value.
- *
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.
- */
- 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:
- *
- *
Pop the top double64 value from the operand stack.
- *
Convert the double64 value to an int32 value (this may involve truncation).
- *
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.
- */
- 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:
- *
- *
Pop the top double64 value from the operand stack.
- *
Convert the double64 value to a long64 value (this may involve truncation).
- *
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.
- */
- 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:
- *
- *
Pop the top double64 value from the operand stack.
- *
Convert the double64 value to a float32 value.
- *
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.
- */
- 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:
- *
- *
Pop the top short16 value from the operand stack.
- *
Convert the short16 value to an int32 value.
- *
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.
- */
- 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 {
*
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 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:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is 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:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a float32 value.
+ *
Push the converted float32 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to 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:
+ *
+ *
Pop the top byte8 value from the operand stack.
+ *
Convert the byte8 value to a double64 value.
+ *
Push the converted double64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a byte8 value to a double64 type.
+ */
+ 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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a 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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to an int32 value.
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is 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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a float32 value.
+ *
Push the converted float32 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to 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:
+ *
+ *
Pop the top short16 value from the operand stack.
+ *
Convert the short16 value to a double64 value.
+ *
Push the converted double64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a short16 value to 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:
+ *
+ *
Pop the top int32 value from the operand stack.
+ *
Convert the int32 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow 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:
+ *
+ *
Pop the top int32 value from the operand stack.
+ *
Convert the int32 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is 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:
+ *
+ *
Pop the top int32 value from the operand stack.
+ *
Convert the int32 value to a long64 value.
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top int32 value from the operand stack.
+ *
Convert the int32 value to a float32 value.
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top int32 value from the operand stack.
+ *
Convert the int32 value to a double64 value.
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a 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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a 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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to an int32 value (this may involve truncation).
+ *
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 .
+ */
+ 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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a float32 value.
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top long64 value from the operand stack.
+ *
Convert the long64 value to a double64 value.
+ *
Push the converted double64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a 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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to convert a float32 value to a byte8 type.
+ */
+ 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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to convert a float32 value to a short16 type.
+ */
+ 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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to an int32 value (this may involve truncation).
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a long64 value.
+ *
Push the converted long64 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to widen a 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:
+ *
+ *
Pop the top float32 value from the operand stack.
+ *
Convert the float32 value to a double64 value.
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a byte8 value (this may involve truncation).
+ *
Push the converted byte8 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a double64 value to a byte8 type.
+ */
+ 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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a short16 value (this may involve truncation).
+ *
Push the converted short16 value back onto the operand stack for subsequent operations.
+ *
+ *
+ *
This opcode is used to narrow a double64 value to 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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to an int32 value (this may involve truncation).
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a long64 value (this may involve truncation).
+ *
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.
+ */
+ 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:
+ *
+ *
Pop the top double64 value from the operand stack.
+ *
Convert the double64 value to a float32 value.
+ *
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.
+ */
+ 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)