修复
This commit is contained in:
parent
a67ac422bc
commit
b2e5665bf6
@ -50,7 +50,7 @@ public final class BasicIRBuilder {
|
||||
*/
|
||||
public IRProgram buildProgram(List<Node> roots) {
|
||||
IRProgram prog = new IRProgram(); // 创建新的 IRProgram
|
||||
for (Node n : roots) dispatchTop(n, prog); // 依次处理所有顶层节点
|
||||
for (Node node : roots) dispatchTop(node, prog); // 依次处理所有顶层节点
|
||||
return prog;
|
||||
}
|
||||
|
||||
@ -60,18 +60,18 @@ public final class BasicIRBuilder {
|
||||
* 处理单个顶层节点。
|
||||
* 可能是:模块(ModuleNode)、函数(FunctionNode)、单条语句(StatementNode)。
|
||||
*
|
||||
* @param n AST 顶层节点
|
||||
* @param prog 正在构建的 IRProgram
|
||||
* @param node AST 顶层节点
|
||||
* @param irProgram 正在构建的 IRProgram
|
||||
*/
|
||||
private void dispatchTop(Node n, IRProgram prog) {
|
||||
switch (n) {
|
||||
case ModuleNode m -> m.functions().forEach(f -> dispatchTop(f, prog)); // 递归处理模块内的函数
|
||||
case FunctionNode f -> prog.add(buildFunction(f)); // 将函数编译成 IRFunction 并加入 IRProgram
|
||||
case StatementNode s -> { // 单条语句(如脚本式 main)
|
||||
FunctionNode fake = new FunctionNode("main", List.of(), "void", List.of(s));
|
||||
prog.add(buildFunction(fake));
|
||||
private void dispatchTop(Node node, IRProgram irProgram) {
|
||||
switch (node) {
|
||||
case ModuleNode moduleNode -> moduleNode.functions().forEach(f -> dispatchTop(f, irProgram)); // 递归处理模块内的函数
|
||||
case FunctionNode functionNode -> irProgram.add(buildFunction(functionNode)); // 将函数编译成 IRFunction 并加入 IRProgram
|
||||
case StatementNode statementNode -> { // 单条语句(如脚本式 main)
|
||||
FunctionNode fake = new FunctionNode("main", List.of(), "void", List.of(statementNode));
|
||||
irProgram.add(buildFunction(fake));
|
||||
}
|
||||
default -> throw new IllegalStateException("Unsupported top-level node: " + n);
|
||||
default -> throw new IllegalStateException("Unsupported top-level node: " + node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user