Remove arrow functions for now
This commit is contained in:
@@ -15,7 +15,6 @@ public partial class QBEGenerator
|
||||
StructInitializerNode structInitializer => EmitStructInitializer(structInitializer),
|
||||
AddressOfNode addressOf => EmitAddressOf(addressOf),
|
||||
DereferenceNode dereference => EmitDereference(dereference),
|
||||
ArrowFuncNode arrowFunc => EmitArrowFunc(arrowFunc),
|
||||
BinaryExpressionNode binaryExpression => EmitBinaryExpression(binaryExpression),
|
||||
FuncCallNode funcCallExpression => EmitFuncCall(funcCallExpression),
|
||||
InterfaceFuncAccessNode interfaceFuncAccess => EmitInterfaceFuncAccess(interfaceFuncAccess),
|
||||
@@ -32,13 +31,6 @@ public partial class QBEGenerator
|
||||
};
|
||||
}
|
||||
|
||||
private Val EmitArrowFunc(ArrowFuncNode arrowFunc)
|
||||
{
|
||||
var name = $"$arrow_func{++_arrowFuncIndex}";
|
||||
_arrowFunctions.Enqueue((arrowFunc, name));
|
||||
return new Val(name, arrowFunc.Type, ValKind.Direct);
|
||||
}
|
||||
|
||||
private Val EmitArrayIndexAccess(ArrayIndexAccessNode arrayIndexAccess)
|
||||
{
|
||||
var array = EmitUnwrap(EmitExpression(arrayIndexAccess.Target));
|
||||
|
||||
@@ -16,11 +16,9 @@ public partial class QBEGenerator
|
||||
private readonly List<StringLiteral> _stringLiterals = [];
|
||||
private readonly Stack<string> _breakLabels = [];
|
||||
private readonly Stack<string> _continueLabels = [];
|
||||
private readonly Queue<(ArrowFuncNode Func, string Name)> _arrowFunctions = [];
|
||||
private readonly Stack<Scope> _scopes = [];
|
||||
private int _tmpIndex;
|
||||
private int _labelIndex;
|
||||
private int _arrowFuncIndex;
|
||||
private int _cStringLiteralIndex;
|
||||
private int _stringLiteralIndex;
|
||||
private bool _codeIsReachable = true;
|
||||
@@ -40,11 +38,9 @@ public partial class QBEGenerator
|
||||
_stringLiterals.Clear();
|
||||
_breakLabels.Clear();
|
||||
_continueLabels.Clear();
|
||||
_arrowFunctions.Clear();
|
||||
_scopes.Clear();
|
||||
_tmpIndex = 0;
|
||||
_labelIndex = 0;
|
||||
_arrowFuncIndex = 0;
|
||||
_cStringLiteralIndex = 0;
|
||||
_stringLiteralIndex = 0;
|
||||
_codeIsReachable = true;
|
||||
@@ -71,12 +67,6 @@ public partial class QBEGenerator
|
||||
_writer.NewLine();
|
||||
}
|
||||
|
||||
while (_arrowFunctions.TryDequeue(out var arrowFunc))
|
||||
{
|
||||
EmitFuncDefinition(arrowFunc.Name, arrowFunc.Func.Parameters, arrowFunc.Func.ReturnType, arrowFunc.Func.Body);
|
||||
_writer.NewLine();
|
||||
}
|
||||
|
||||
foreach (var structDef in _syntaxTree.Definitions.OfType<StructNode>().Where(x => x.InterfaceImplementations.Count > 0))
|
||||
{
|
||||
_writer.Write($"data {StructVtableName(structDef.Name)} = {{ ");
|
||||
|
||||
@@ -421,7 +421,6 @@ public sealed class Parser
|
||||
IdentifierToken identifier => new IdentifierSyntax(GetTokens(startIndex), identifier.Value),
|
||||
SymbolToken symbolToken => symbolToken.Symbol switch
|
||||
{
|
||||
Symbol.Func => ParseArrowFunction(),
|
||||
Symbol.OpenParen => ParseParenthesizedExpression(),
|
||||
Symbol.Minus => new UnaryExpressionSyntax(GetTokens(startIndex), UnaryOperatorSyntax.Negate, ParsePrimaryExpression()),
|
||||
Symbol.Bang => new UnaryExpressionSyntax(GetTokens(startIndex), UnaryOperatorSyntax.Invert, ParsePrimaryExpression()),
|
||||
@@ -443,36 +442,6 @@ public sealed class Parser
|
||||
return ParsePostfixOperators(expr);
|
||||
}
|
||||
|
||||
private ExpressionSyntax ParseArrowFunction()
|
||||
{
|
||||
var startIndex = _tokenIndex;
|
||||
List<ArrowFuncParameterSyntax> parameters = [];
|
||||
ExpectSymbol(Symbol.OpenParen);
|
||||
while (!TryExpectSymbol(Symbol.CloseParen))
|
||||
{
|
||||
var parameterIndex = _tokenIndex;
|
||||
var name = ExpectIdentifier();
|
||||
parameters.Add(new ArrowFuncParameterSyntax(GetTokens(parameterIndex), name.Value));
|
||||
}
|
||||
|
||||
ExpectSymbol(Symbol.Arrow);
|
||||
BlockSyntax body;
|
||||
|
||||
if (CurrentToken is SymbolToken { Symbol: Symbol.OpenBrace })
|
||||
{
|
||||
var bodyStartIndex = _tokenIndex;
|
||||
var returnValue = ParseExpression();
|
||||
var arrowExpression = new ReturnSyntax(GetTokens(bodyStartIndex), returnValue);
|
||||
body = new BlockSyntax(GetTokens(bodyStartIndex), [arrowExpression]);
|
||||
}
|
||||
else
|
||||
{
|
||||
body = ParseBlock();
|
||||
}
|
||||
|
||||
return new ArrowFuncSyntax(GetTokens(startIndex), parameters, body);
|
||||
}
|
||||
|
||||
private ExpressionSyntax ParseParenthesizedExpression()
|
||||
{
|
||||
var expression = ParseExpression();
|
||||
|
||||
@@ -81,19 +81,6 @@ public record ArrowFuncParameterSyntax(IEnumerable<Token> Tokens, string Name) :
|
||||
public override IEnumerable<SyntaxNode> GetChildren() => [];
|
||||
}
|
||||
|
||||
public record ArrowFuncSyntax(IEnumerable<Token> Tokens, IReadOnlyList<ArrowFuncParameterSyntax> Parameters, BlockSyntax Body) : ExpressionSyntax(Tokens)
|
||||
{
|
||||
public override IEnumerable<SyntaxNode> GetChildren()
|
||||
{
|
||||
foreach (var parameter in Parameters)
|
||||
{
|
||||
yield return parameter;
|
||||
}
|
||||
|
||||
yield return Body;
|
||||
}
|
||||
}
|
||||
|
||||
public record AddressOfSyntax(IEnumerable<Token> Tokens, ExpressionSyntax Expression) : ExpressionSyntax(Tokens)
|
||||
{
|
||||
public override IEnumerable<SyntaxNode> GetChildren()
|
||||
|
||||
@@ -40,8 +40,6 @@ public record ArrayInitializerNode(TypeNode Type, ExpressionNode Capacity, TypeN
|
||||
|
||||
public record ArrayIndexAccessNode(TypeNode Type, ExpressionNode Target, ExpressionNode Index) : ExpressionNode(Type);
|
||||
|
||||
public record ArrowFuncNode(TypeNode Type, IReadOnlyList<FuncParameterNode> Parameters, TypeNode ReturnType, BlockNode Body) : ExpressionNode(Type);
|
||||
|
||||
public record AddressOfNode(TypeNode Type, ExpressionNode Expression) : ExpressionNode(Type);
|
||||
|
||||
public record LiteralNode(TypeNode Type, string Value, LiteralKind Kind) : ExpressionNode(Type);
|
||||
|
||||
@@ -251,7 +251,6 @@ public sealed class TypeChecker
|
||||
var result = node switch
|
||||
{
|
||||
AddressOfSyntax expression => CheckAddressOf(expression),
|
||||
ArrowFuncSyntax expression => CheckArrowFunc(expression, expectedType),
|
||||
ArrayIndexAccessSyntax expression => CheckArrayIndexAccess(expression),
|
||||
ArrayInitializerSyntax expression => CheckArrayInitializer(expression),
|
||||
BinaryExpressionSyntax expression => CheckBinaryExpression(expression),
|
||||
@@ -293,37 +292,6 @@ public sealed class TypeChecker
|
||||
return new AddressOfNode(new PointerTypeNode(inner.Type), inner);
|
||||
}
|
||||
|
||||
private ArrowFuncNode CheckArrowFunc(ArrowFuncSyntax expression, TypeNode? expectedType = null)
|
||||
{
|
||||
if (expectedType == null)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error("Cannot infer argument types for arrow function").Build());
|
||||
}
|
||||
|
||||
if (expectedType is not FuncTypeNode funcType)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error($"Expected {expectedType}, but got arrow function").Build());
|
||||
}
|
||||
|
||||
var parameters = new List<FuncParameterNode>();
|
||||
|
||||
for (var i = 0; i < expression.Parameters.Count; i++)
|
||||
{
|
||||
if (i >= funcType.Parameters.Count)
|
||||
{
|
||||
throw new TypeCheckerException(Diagnostic.Error($"Arrow function expected a maximum of {funcType.Parameters.Count} arguments").Build());
|
||||
}
|
||||
|
||||
var expectedParameterType = funcType.Parameters[i];
|
||||
var parameter = expression.Parameters[i];
|
||||
parameters.Add(new FuncParameterNode(parameter.Name, expectedParameterType));
|
||||
}
|
||||
|
||||
var body = CheckFuncBody(expression.Body, funcType.ReturnType, parameters);
|
||||
|
||||
return new ArrowFuncNode(new FuncTypeNode(parameters.Select(x => x.Type).ToList(), funcType.ReturnType), parameters, funcType.ReturnType, body);
|
||||
}
|
||||
|
||||
private ArrayIndexAccessNode CheckArrayIndexAccess(ArrayIndexAccessSyntax expression)
|
||||
{
|
||||
var boundArray = CheckExpression(expression.Target);
|
||||
|
||||
Reference in New Issue
Block a user