修改为记录模型
This commit is contained in:
parent
a14373b986
commit
b26ff57f4e
@ -19,18 +19,22 @@ public class StatementBuilder {
|
||||
this.exprBuilder = new ExpressionBuilder(ctx);
|
||||
}
|
||||
|
||||
/** 入口:根据不同语句类型分发 */
|
||||
/**
|
||||
* 入口:根据不同语句类型分发
|
||||
*/
|
||||
public void build(StatementNode stmt) {
|
||||
if (stmt instanceof ExpressionStatementNode es) {
|
||||
exprBuilder.build(es.expression());
|
||||
if (stmt instanceof ExpressionStatementNode(org.jcnc.snow.compiler.parser.ast.base.ExpressionNode expression)) {
|
||||
exprBuilder.build(expression);
|
||||
return;
|
||||
}
|
||||
if (stmt instanceof AssignmentNode an) {
|
||||
IRVirtualRegister vr = exprBuilder.build(an.value());
|
||||
if (ctx.getScope().lookup(an.variable()) == null) {
|
||||
ctx.getScope().declare(an.variable(), vr);
|
||||
if (stmt instanceof AssignmentNode(
|
||||
String variable, org.jcnc.snow.compiler.parser.ast.base.ExpressionNode value
|
||||
)) {
|
||||
IRVirtualRegister vr = exprBuilder.build(value);
|
||||
if (ctx.getScope().lookup(variable) == null) {
|
||||
ctx.getScope().declare(variable, vr);
|
||||
} else {
|
||||
ctx.getScope().put(an.variable(), vr);
|
||||
ctx.getScope().put(variable, vr);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user