...
This commit is contained in:
@@ -501,8 +501,11 @@ public class QBEGenerator
|
||||
case ReturnNode @return:
|
||||
EmitReturn(@return);
|
||||
break;
|
||||
case StatementExpressionNode statementExpression:
|
||||
EmitExpression(statementExpression.Expression);
|
||||
case StatementFuncCallNode statementFuncCall:
|
||||
EmitFuncCall(statementFuncCall.FuncCall);
|
||||
break;
|
||||
case StatementStructFuncCallNode statementStructFuncCall:
|
||||
EmitStructFuncCall(statementStructFuncCall.StructFuncCall);
|
||||
break;
|
||||
case VariableDeclarationNode variableDeclaration:
|
||||
EmitVariableDeclaration(variableDeclaration);
|
||||
|
||||
@@ -211,6 +211,8 @@ public sealed class Parser
|
||||
|
||||
private StatementSyntax ParseStatement()
|
||||
{
|
||||
var startIndex = _tokenIndex;
|
||||
|
||||
if (CurrentToken is SymbolToken symbol)
|
||||
{
|
||||
switch (symbol.Symbol)
|
||||
@@ -236,12 +238,6 @@ public sealed class Parser
|
||||
}
|
||||
}
|
||||
|
||||
return ParseStatementExpression();
|
||||
}
|
||||
|
||||
private StatementSyntax ParseStatementExpression()
|
||||
{
|
||||
var startIndex = _tokenIndex;
|
||||
var expr = ParseExpression();
|
||||
|
||||
if (TryExpectSymbol(Symbol.Assign))
|
||||
|
||||
@@ -6,7 +6,9 @@ public abstract record TerminalStatementNode : StatementNode;
|
||||
|
||||
public record BlockNode(List<StatementNode> Statements) : StatementNode;
|
||||
|
||||
public record StatementExpressionNode(ExpressionNode Expression) : StatementNode;
|
||||
public record StatementFuncCallNode(FuncCallNode FuncCall) : StatementNode;
|
||||
|
||||
public record StatementStructFuncCallNode(StructFuncCallNode StructFuncCall) : StatementNode;
|
||||
|
||||
public record ReturnNode(Optional<ExpressionNode> Value) : TerminalStatementNode;
|
||||
|
||||
|
||||
@@ -203,9 +203,16 @@ public sealed class TypeChecker
|
||||
return new ReturnNode(value);
|
||||
}
|
||||
|
||||
private StatementExpressionNode CheckStatementExpression(StatementExpressionSyntax statement)
|
||||
private StatementNode CheckStatementExpression(StatementExpressionSyntax statement)
|
||||
{
|
||||
return new StatementExpressionNode(CheckExpression(statement.Expression));
|
||||
var expression = CheckExpression(statement.Expression);
|
||||
|
||||
return expression switch
|
||||
{
|
||||
FuncCallNode funcCall => new StatementFuncCallNode(funcCall),
|
||||
StructFuncCallNode structFuncCall => new StatementStructFuncCallNode(structFuncCall),
|
||||
_ => throw new TypeCheckerException(Diagnostic.Error("Expressions statements can only be function calls").At(statement).Build())
|
||||
};
|
||||
}
|
||||
|
||||
private VariableDeclarationNode CheckVariableDeclaration(VariableDeclarationSyntax statement)
|
||||
|
||||
Reference in New Issue
Block a user