Traits
This commit is contained in:
@@ -37,6 +37,43 @@ public class DefinitionTable
|
||||
return Optional.OfNullable(definition);
|
||||
}
|
||||
|
||||
public Optional<TraitDefinitionNode> LookupTrait(string @namespace, string name)
|
||||
{
|
||||
var definition = _syntaxTrees
|
||||
.Where(c => c.Namespace == @namespace)
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<TraitDefinitionNode>()
|
||||
.SingleOrDefault(f => f.Name == name);
|
||||
|
||||
return Optional.OfNullable(definition);
|
||||
}
|
||||
|
||||
public Optional<Tuple<TraitImplementationDefinitionNode, ImplementationFuncNode>> LookupTraitImplementationForType(NubType type, string funcName)
|
||||
{
|
||||
var implementations = _syntaxTrees
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<TraitImplementationDefinitionNode>()
|
||||
.Where(c => c.ForType.Equals(type));
|
||||
|
||||
var implementation = implementations.SingleOrDefault(c => c.Functions.Any(x => x.Name == funcName));
|
||||
|
||||
var value = implementation == null ? null : new Tuple<TraitImplementationDefinitionNode, ImplementationFuncNode>(implementation, implementation.Functions.First(x => x.Name == funcName));
|
||||
|
||||
return Optional.OfNullable(value);
|
||||
}
|
||||
|
||||
public Optional<TraitFunc> LookupFunctionOnTrait(string @namespace, string name, string funcName)
|
||||
{
|
||||
var traitDef = LookupTrait(@namespace, name);
|
||||
if (traitDef.HasValue)
|
||||
{
|
||||
var function = traitDef.Value.Functions.SingleOrDefault(x => x.Name == funcName);
|
||||
return Optional.OfNullable(function);
|
||||
}
|
||||
|
||||
return Optional<TraitFunc>.Empty();
|
||||
}
|
||||
|
||||
public IEnumerable<StructDefinitionNode> GetStructs()
|
||||
{
|
||||
return _syntaxTrees
|
||||
@@ -65,18 +102,18 @@ public class DefinitionTable
|
||||
.OfType<ExternFuncDefinitionNode>();
|
||||
}
|
||||
|
||||
public IEnumerable<InterfaceDefinitionNode> GetInterfaces()
|
||||
public IEnumerable<TraitDefinitionNode> GetTraits()
|
||||
{
|
||||
return _syntaxTrees
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<InterfaceDefinitionNode>();
|
||||
.OfType<TraitDefinitionNode>();
|
||||
}
|
||||
|
||||
public IEnumerable<ImplementationDefinitionNode> GetImplementations()
|
||||
public IEnumerable<TraitImplementationDefinitionNode> GetTraitImplementations()
|
||||
{
|
||||
return _syntaxTrees
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<ImplementationDefinitionNode>();
|
||||
.OfType<TraitImplementationDefinitionNode>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +148,43 @@ public class BoundDefinitionTable
|
||||
return Optional.OfNullable(definition);
|
||||
}
|
||||
|
||||
public Optional<BoundTraitDefinitionNode> LookupTrait(string @namespace, string name)
|
||||
{
|
||||
var definition = _syntaxTrees
|
||||
.Where(c => c.Namespace == @namespace)
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<BoundTraitDefinitionNode>()
|
||||
.SingleOrDefault(f => f.Name == name);
|
||||
|
||||
return Optional.OfNullable(definition);
|
||||
}
|
||||
|
||||
public Optional<Tuple<BoundTraitImplementationDefinitionNode, BoundImplementationFuncNode>> LookupTraitImplementationForType(NubType type, string funcName)
|
||||
{
|
||||
var implementations = _syntaxTrees
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<BoundTraitImplementationDefinitionNode>()
|
||||
.Where(c => c.ForType.Equals(type));
|
||||
|
||||
var implementation = implementations.SingleOrDefault(c => c.Functions.Any(x => x.Name == funcName));
|
||||
|
||||
var value = implementation == null ? null : new Tuple<BoundTraitImplementationDefinitionNode, BoundImplementationFuncNode>(implementation, implementation.Functions.First(x => x.Name == funcName));
|
||||
|
||||
return Optional.OfNullable(value);
|
||||
}
|
||||
|
||||
public Optional<BountTraitFunc> LookupFunctionOnTrait(string @namespace, string name, string funcName)
|
||||
{
|
||||
var traitDef = LookupTrait(@namespace, name);
|
||||
if (traitDef.HasValue)
|
||||
{
|
||||
var function = traitDef.Value.Functions.SingleOrDefault(x => x.Name == funcName);
|
||||
return Optional.OfNullable(function);
|
||||
}
|
||||
|
||||
return Optional<BountTraitFunc>.Empty();
|
||||
}
|
||||
|
||||
public IEnumerable<BoundStructDefinitionNode> GetStructs()
|
||||
{
|
||||
return _syntaxTrees
|
||||
@@ -139,17 +213,17 @@ public class BoundDefinitionTable
|
||||
.OfType<BoundExternFuncDefinitionNode>();
|
||||
}
|
||||
|
||||
public IEnumerable<BoundInterfaceDefinitionNode> GetInterfaces()
|
||||
public IEnumerable<BoundTraitDefinitionNode> GetTraits()
|
||||
{
|
||||
return _syntaxTrees
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<BoundInterfaceDefinitionNode>();
|
||||
.OfType<BoundTraitDefinitionNode>();
|
||||
}
|
||||
|
||||
public IEnumerable<BoundImplementationDefinitionNode> GetImplementations()
|
||||
public IEnumerable<BoundTraitImplementationDefinitionNode> GetTraitImplementations()
|
||||
{
|
||||
return _syntaxTrees
|
||||
.SelectMany(c => c.Definitions)
|
||||
.OfType<BoundImplementationDefinitionNode>();
|
||||
.OfType<BoundTraitImplementationDefinitionNode>();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Common;
|
||||
using Syntax.Tokenization;
|
||||
using Syntax.Typing;
|
||||
using Syntax.Typing.BoundNode;
|
||||
|
||||
namespace Syntax.Parsing.Node;
|
||||
|
||||
@@ -14,8 +15,8 @@ public record ExternFuncDefinitionNode(IEnumerable<Token> Tokens, Optional<strin
|
||||
public record StructField(string Name, NubType Type, Optional<ExpressionNode> Value);
|
||||
public record StructDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, string Name, List<StructField> Fields) : DefinitionNode(Tokens, Documentation, Namespace);
|
||||
|
||||
public record InterfaceFunc(string Name, List<FuncParameter> Parameters, NubType ReturnType);
|
||||
public record InterfaceDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, string Name, List<InterfaceFunc> Functions) : DefinitionNode(Tokens, Documentation, Namespace);
|
||||
public record TraitFunc(string Name, List<FuncParameter> Parameters, NubType ReturnType);
|
||||
public record TraitDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, string Name, List<TraitFunc> Functions) : DefinitionNode(Tokens, Documentation, Namespace);
|
||||
|
||||
public record ImplementationFunc(string Name, List<FuncParameter> Parameters, NubType ReturnType, BlockNode Body);
|
||||
public record ImplementationDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, NubType Type, NubType Interface, List<ImplementationFunc> Functions) : DefinitionNode(Tokens, Documentation, Namespace);
|
||||
public record ImplementationFuncNode(IEnumerable<Token> Tokens, string Name, List<FuncParameter> Parameters, NubType ReturnType, BlockNode Body) : BoundNode(Tokens);
|
||||
public record TraitImplementationDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, NubType TraitType, NubType ForType, List<ImplementationFuncNode> Functions) : DefinitionNode(Tokens, Documentation, Namespace);
|
||||
@@ -38,5 +38,5 @@ public record AnonymousFuncNode(IEnumerable<Token> Tokens, List<FuncParameter> P
|
||||
public record AddressOfNode(IEnumerable<Token> Tokens, ExpressionNode Expression) : ExpressionNode(Tokens);
|
||||
public record LiteralNode(IEnumerable<Token> Tokens, string Literal, LiteralKind Kind) : ExpressionNode(Tokens);
|
||||
public record MemberAccessNode(IEnumerable<Token> Tokens, ExpressionNode Expression, string Member) : ExpressionNode(Tokens);
|
||||
public record StructInitializerNode(IEnumerable<Token> Tokens, NubStructType StructType, Dictionary<string, ExpressionNode> Initializers) : ExpressionNode(Tokens);
|
||||
public record StructInitializerNode(IEnumerable<Token> Tokens, NubType StructType, Dictionary<string, ExpressionNode> Initializers) : ExpressionNode(Tokens);
|
||||
public record DereferenceNode(IEnumerable<Token> Tokens, ExpressionNode Expression) : ExpressionNode(Tokens);
|
||||
|
||||
@@ -17,21 +17,13 @@ public static class Parser
|
||||
public static SyntaxTree? ParseFile(IEnumerable<Token> tokens, out IEnumerable<Diagnostic> diagnostics)
|
||||
{
|
||||
_tokens = tokens;
|
||||
_namespace = null!;
|
||||
_namespace = "global";
|
||||
_diagnostics = [];
|
||||
_index = 0;
|
||||
|
||||
try
|
||||
if (TryExpectSymbol(Symbol.Namespace))
|
||||
{
|
||||
ExpectSymbol(Symbol.Namespace);
|
||||
var @namespace = ExpectIdentifier();
|
||||
_namespace = @namespace.Value;
|
||||
}
|
||||
catch (ParseException ex)
|
||||
{
|
||||
_diagnostics.Add(ex.Diagnostic);
|
||||
diagnostics = _diagnostics;
|
||||
return null;
|
||||
_namespace = ExpectIdentifier().Value;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -81,7 +73,7 @@ public static class Parser
|
||||
{
|
||||
Symbol.Func => ParseFuncDefinition(startIndex, modifiers, Optional.OfNullable(documentation)),
|
||||
Symbol.Struct => ParseStruct(startIndex, modifiers, Optional.OfNullable(documentation)),
|
||||
Symbol.Interface => ParseInterface(startIndex, modifiers, Optional.OfNullable(documentation)),
|
||||
Symbol.Trait => ParseTrait(startIndex, modifiers, Optional.OfNullable(documentation)),
|
||||
Symbol.Impl => ParseImplementation(startIndex, modifiers, Optional.OfNullable(documentation)),
|
||||
_ => throw new ParseException(Diagnostic
|
||||
.Error($"Expected 'func' or 'struct', but found '{keyword.Symbol}'")
|
||||
@@ -187,13 +179,13 @@ public static class Parser
|
||||
return new StructDefinitionNode(GetTokensForNode(startIndex), documentation, _namespace, name, variables);
|
||||
}
|
||||
|
||||
private static InterfaceDefinitionNode ParseInterface(int startIndex, List<ModifierToken> modifiers, Optional<string> documentation)
|
||||
private static TraitDefinitionNode ParseTrait(int startIndex, List<ModifierToken> modifiers, Optional<string> documentation)
|
||||
{
|
||||
var name = ExpectIdentifier().Value;
|
||||
|
||||
ExpectSymbol(Symbol.OpenBrace);
|
||||
|
||||
List<InterfaceFunc> functions = [];
|
||||
List<TraitFunc> functions = [];
|
||||
|
||||
while (!TryExpectSymbol(Symbol.CloseBrace))
|
||||
{
|
||||
@@ -222,34 +214,35 @@ public static class Parser
|
||||
if (modifiers.Count != 0)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Invalid modifiers for interface: {modifiers[0].Modifier}")
|
||||
.WithHelp($"Interface cannot use the '{modifiers[0].Modifier}' modifier")
|
||||
.Error($"Invalid modifiers for trait: {modifiers[0].Modifier}")
|
||||
.WithHelp($"Traits cannot use the '{modifiers[0].Modifier}' modifier")
|
||||
.At(modifiers[0])
|
||||
.Build());
|
||||
}
|
||||
|
||||
functions.Add(new InterfaceFunc(funcName, parameters, returnType));
|
||||
functions.Add(new TraitFunc(funcName, parameters, returnType));
|
||||
}
|
||||
|
||||
return new InterfaceDefinitionNode(GetTokensForNode(startIndex), documentation, _namespace, name, functions);
|
||||
return new TraitDefinitionNode(GetTokensForNode(startIndex), documentation, _namespace, name, functions);
|
||||
}
|
||||
|
||||
private static ImplementationDefinitionNode ParseImplementation(int startIndex, List<ModifierToken> modifiers, Optional<string> documentation)
|
||||
private static TraitImplementationDefinitionNode ParseImplementation(int startIndex, List<ModifierToken> modifiers, Optional<string> documentation)
|
||||
{
|
||||
var type = ParseType();
|
||||
ExpectSymbol(Symbol.Colon);
|
||||
var @interface = ParseType();
|
||||
var traitType = ParseType();
|
||||
ExpectSymbol(Symbol.For);
|
||||
var forType = ParseType();
|
||||
|
||||
List<ImplementationFunc> functions = [];
|
||||
List<ImplementationFuncNode> functions = [];
|
||||
|
||||
ExpectSymbol(Symbol.OpenBrace);
|
||||
while (!TryExpectSymbol(Symbol.CloseBrace))
|
||||
{
|
||||
var funcStartIndex = _index;
|
||||
ExpectSymbol(Symbol.Func);
|
||||
var functionName = ExpectIdentifier().Value;
|
||||
var parameters = new List<FuncParameter>
|
||||
{
|
||||
new("this", type)
|
||||
new("this", forType)
|
||||
};
|
||||
|
||||
ExpectSymbol(Symbol.OpenParen);
|
||||
@@ -272,10 +265,19 @@ public static class Parser
|
||||
|
||||
var body = ParseBlock();
|
||||
|
||||
functions.AddRange(new ImplementationFunc(functionName, parameters, returnType, body));
|
||||
functions.AddRange(new ImplementationFuncNode(GetTokensForNode(funcStartIndex), functionName, parameters, returnType, body));
|
||||
}
|
||||
|
||||
return new ImplementationDefinitionNode(GetTokensForNode(startIndex), documentation, _namespace, type, @interface, functions);
|
||||
if (modifiers.Count != 0)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Invalid modifiers for implementation: {modifiers[0].Modifier}")
|
||||
.WithHelp($"Implementations cannot use the '{modifiers[0].Modifier}' modifier")
|
||||
.At(modifiers[0])
|
||||
.Build());
|
||||
}
|
||||
|
||||
return new TraitImplementationDefinitionNode(GetTokensForNode(startIndex), documentation, _namespace, traitType, forType, functions);
|
||||
}
|
||||
|
||||
private static FuncParameter ParseFuncParameter()
|
||||
@@ -580,15 +582,7 @@ public static class Parser
|
||||
initializers.Add(name, value);
|
||||
}
|
||||
|
||||
if (type is not NubStructType structType)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Cannot alloc type '{type}'")
|
||||
.At(symbolToken)
|
||||
.Build());
|
||||
}
|
||||
|
||||
expr = new StructInitializerNode(GetTokensForNode(startIndex), structType, initializers);
|
||||
expr = new StructInitializerNode(GetTokensForNode(startIndex), type, initializers);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -729,16 +723,7 @@ public static class Parser
|
||||
@namespace = ExpectIdentifier().Value;
|
||||
}
|
||||
|
||||
if (@namespace == null)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Struct '{name.Value}' does not belong to a namespace")
|
||||
.WithHelp("Make sure you have specified a namespace at the top of the file")
|
||||
.At(name)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return new NubStructType(@namespace, name.Value);
|
||||
return new NubCustomType(@namespace, name.Value);
|
||||
}
|
||||
|
||||
if (TryExpectSymbol(Symbol.Caret))
|
||||
|
||||
@@ -44,6 +44,7 @@ public enum Symbol
|
||||
Let,
|
||||
Alloc,
|
||||
Calls,
|
||||
Interface,
|
||||
Impl
|
||||
Trait,
|
||||
Impl,
|
||||
For
|
||||
}
|
||||
@@ -19,8 +19,9 @@ public static class Tokenizer
|
||||
["struct"] = Symbol.Struct,
|
||||
["let"] = Symbol.Let,
|
||||
["calls"] = Symbol.Calls,
|
||||
["interface"] = Symbol.Interface,
|
||||
["trait"] = Symbol.Trait,
|
||||
["impl"] = Symbol.Impl,
|
||||
["for"] = Symbol.For,
|
||||
};
|
||||
|
||||
private static readonly Dictionary<string, Modifier> Modifiers = new()
|
||||
|
||||
@@ -41,18 +41,18 @@ public static class Binder
|
||||
return node switch
|
||||
{
|
||||
ExternFuncDefinitionNode definition => BindExternFuncDefinition(definition),
|
||||
ImplementationDefinitionNode definition => BindImplementation(definition),
|
||||
InterfaceDefinitionNode definition => BindInterfaceDefinition(definition),
|
||||
TraitImplementationDefinitionNode definition => BindTraitImplementation(definition),
|
||||
TraitDefinitionNode definition => BindTraitDefinition(definition),
|
||||
LocalFuncDefinitionNode definition => BindLocalFuncDefinition(definition),
|
||||
StructDefinitionNode definition => BindStruct(definition),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(node))
|
||||
};
|
||||
}
|
||||
|
||||
private static BoundImplementationDefinitionNode BindImplementation(ImplementationDefinitionNode node)
|
||||
private static BoundTraitImplementationDefinitionNode BindTraitImplementation(TraitImplementationDefinitionNode node)
|
||||
{
|
||||
_variables.Clear();
|
||||
var functions = new List<BoundImplementationFunc>();
|
||||
var functions = new List<BoundImplementationFuncNode>();
|
||||
|
||||
foreach (var function in node.Functions)
|
||||
{
|
||||
@@ -63,15 +63,15 @@ public static class Binder
|
||||
_variables[parameter.Name] = parameter.Type;
|
||||
}
|
||||
|
||||
functions.Add(new BoundImplementationFunc(function.Name, parameters, function.ReturnType, BindBlock(function.Body)));
|
||||
functions.Add(new BoundImplementationFuncNode(function.Tokens, function.Name, parameters, function.ReturnType, BindBlock(function.Body)));
|
||||
}
|
||||
|
||||
return new BoundImplementationDefinitionNode(node.Tokens, node.Documentation, node.Namespace, node.Type, node.Interface, functions);
|
||||
return new BoundTraitImplementationDefinitionNode(node.Tokens, node.Documentation, node.Namespace, node.TraitType, node.ForType, functions);
|
||||
}
|
||||
|
||||
private static BoundInterfaceDefinitionNode BindInterfaceDefinition(InterfaceDefinitionNode node)
|
||||
private static BoundTraitDefinitionNode BindTraitDefinition(TraitDefinitionNode node)
|
||||
{
|
||||
var functions = new List<BoundInterfaceFunc>();
|
||||
var functions = new List<BountTraitFunc>();
|
||||
|
||||
foreach (var func in node.Functions)
|
||||
{
|
||||
@@ -82,10 +82,10 @@ public static class Binder
|
||||
parameters.Add(new BoundFuncParameter(parameter.Name, parameter.Type));
|
||||
}
|
||||
|
||||
functions.Add(new BoundInterfaceFunc(func.Name, parameters, func.ReturnType));
|
||||
functions.Add(new BountTraitFunc(func.Name, parameters, func.ReturnType));
|
||||
}
|
||||
|
||||
return new BoundInterfaceDefinitionNode(node.Tokens, node.Documentation, node.Namespace, node.Name, functions);
|
||||
return new BoundTraitDefinitionNode(node.Tokens, node.Documentation, node.Namespace, node.Name, functions);
|
||||
}
|
||||
|
||||
private static BoundStructDefinitionNode BindStruct(StructDefinitionNode node)
|
||||
@@ -393,51 +393,55 @@ public static class Binder
|
||||
{
|
||||
var boundExpression = BindExpression(expression.Expression);
|
||||
|
||||
NubType? type = null;
|
||||
|
||||
switch (boundExpression.Type)
|
||||
var implementation = _definitionTable.LookupTraitImplementationForType(boundExpression.Type, expression.Member);
|
||||
if (implementation.HasValue)
|
||||
{
|
||||
case NubArrayType:
|
||||
case NubStringType:
|
||||
case NubCStringType:
|
||||
{
|
||||
if (expression.Member == "count")
|
||||
{
|
||||
type = NubPrimitiveType.U64;
|
||||
}
|
||||
var type = new NubFuncType(implementation.Value.Item2.ReturnType, implementation.Value.Item2.Parameters.Select(p => p.Type).ToList());
|
||||
return new BoundMemberAccessNode(expression.Tokens, type, boundExpression, expression.Member);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NubStructType structType:
|
||||
if (boundExpression.Type is NubCustomType customType)
|
||||
{
|
||||
var function = _definitionTable.LookupFunctionOnTrait(customType.Namespace, customType.Name, expression.Member);
|
||||
if (function.HasValue)
|
||||
{
|
||||
var defOpt = _definitionTable.LookupStruct(structType.Namespace, structType.Name);
|
||||
if (!defOpt.TryGetValue(out var definition))
|
||||
var type = new NubFuncType(function.Value.ReturnType, function.Value.Parameters.Select(p => p.Type).ToList());
|
||||
return new BoundMemberAccessNode(expression.Tokens, type, boundExpression, expression.Member);
|
||||
}
|
||||
|
||||
var structDef = _definitionTable.LookupStruct(customType.Namespace, customType.Name);
|
||||
if (structDef.HasValue)
|
||||
{
|
||||
var matchingFields = structDef.Value.Fields.Where(f => f.Name == expression.Member).ToList();
|
||||
|
||||
if (matchingFields.Count > 1)
|
||||
{
|
||||
throw new NotImplementedException("Diagnostics not implemented");
|
||||
}
|
||||
|
||||
var field = definition.Fields.FirstOrDefault(f => f.Name == expression.Member);
|
||||
if (field == null)
|
||||
if (matchingFields.Count == 1)
|
||||
{
|
||||
throw new NotImplementedException("Diagnostics not implemented");
|
||||
return new BoundMemberAccessNode(expression.Tokens, matchingFields[0].Type, boundExpression, expression.Member);
|
||||
}
|
||||
|
||||
type = field.Type;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == null)
|
||||
if (boundExpression.Type is NubStringType or NubCStringType or NubArrayType && expression.Member == "count")
|
||||
{
|
||||
throw new NotImplementedException("Diagnostics not implemented");
|
||||
return new BoundMemberAccessNode(expression.Tokens, NubPrimitiveType.I64, boundExpression, expression.Member);
|
||||
}
|
||||
|
||||
return new BoundMemberAccessNode(expression.Tokens, type, boundExpression, expression.Member);
|
||||
throw new NotImplementedException("Diagnostics not implemented");
|
||||
}
|
||||
|
||||
private static BoundStructInitializerNode BindStructInitializer(StructInitializerNode expression)
|
||||
{
|
||||
var defOpt = _definitionTable.LookupStruct(expression.StructType.Namespace, expression.StructType.Name);
|
||||
if (expression.StructType is not NubCustomType structType)
|
||||
{
|
||||
throw new NotImplementedException("Diagnostics not implemented");
|
||||
}
|
||||
|
||||
var defOpt = _definitionTable.LookupStruct(structType.Namespace, structType.Name);
|
||||
if (!defOpt.TryGetValue(out var definition))
|
||||
{
|
||||
throw new NotImplementedException("Diagnostics not implemented");
|
||||
@@ -456,7 +460,7 @@ public static class Binder
|
||||
initializers[member] = BindExpression(initializer, definitionField.Type);
|
||||
}
|
||||
|
||||
return new BoundStructInitializerNode(expression.Tokens, expression.StructType, expression.StructType, initializers);
|
||||
return new BoundStructInitializerNode(expression.Tokens, structType, structType, initializers);
|
||||
}
|
||||
|
||||
private static BoundUnaryExpressionNode BindUnaryExpression(UnaryExpressionNode expression)
|
||||
|
||||
@@ -13,8 +13,8 @@ public record BoundExternFuncDefinitionNode(IEnumerable<Token> Tokens, Optional<
|
||||
public record BoundStructField(string Name, NubType Type, Optional<BoundExpressionNode> Value);
|
||||
public record BoundStructDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, string Name, List<BoundStructField> Fields) : BoundDefinitionNode(Tokens, Documentation, Namespace);
|
||||
|
||||
public record BoundInterfaceFunc(string Name, List<BoundFuncParameter> Parameters, NubType ReturnType);
|
||||
public record BoundInterfaceDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, string Name, List<BoundInterfaceFunc> Functions) : BoundDefinitionNode(Tokens, Documentation, Namespace);
|
||||
public record BountTraitFunc(string Name, List<BoundFuncParameter> Parameters, NubType ReturnType);
|
||||
public record BoundTraitDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, string Name, List<BountTraitFunc> Functions) : BoundDefinitionNode(Tokens, Documentation, Namespace);
|
||||
|
||||
public record BoundImplementationFunc(string Name, List<BoundFuncParameter> Parameters, NubType ReturnType, BoundBlockNode Body);
|
||||
public record BoundImplementationDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, NubType Type, NubType Interface, List<BoundImplementationFunc> Functions) : BoundDefinitionNode(Tokens, Documentation, Namespace);
|
||||
public record BoundImplementationFuncNode(IEnumerable<Token> Tokens, string Name, List<BoundFuncParameter> Parameters, NubType ReturnType, BoundBlockNode Body) : BoundNode(Tokens);
|
||||
public record BoundTraitImplementationDefinitionNode(IEnumerable<Token> Tokens, Optional<string> Documentation, string Namespace, NubType TraitType, NubType ForType, List<BoundImplementationFuncNode> Functions) : BoundDefinitionNode(Tokens, Documentation, Namespace);
|
||||
@@ -15,5 +15,5 @@ public record BoundAnonymousFuncNode(IEnumerable<Token> Tokens, NubType Type, Li
|
||||
public record BoundAddressOfNode(IEnumerable<Token> Tokens, NubType Type, BoundExpressionNode Expression) : BoundExpressionNode(Tokens, Type);
|
||||
public record BoundLiteralNode(IEnumerable<Token> Tokens, NubType Type, string Literal, LiteralKind Kind) : BoundExpressionNode(Tokens, Type);
|
||||
public record BoundMemberAccessNode(IEnumerable<Token> Tokens, NubType Type, BoundExpressionNode Expression, string Member) : BoundExpressionNode(Tokens, Type);
|
||||
public record BoundStructInitializerNode(IEnumerable<Token> Tokens, NubType Type, NubStructType StructType, Dictionary<string, BoundExpressionNode> Initializers) : BoundExpressionNode(Tokens, Type);
|
||||
public record BoundStructInitializerNode(IEnumerable<Token> Tokens, NubType Type, NubType StructType, Dictionary<string, BoundExpressionNode> Initializers) : BoundExpressionNode(Tokens, Type);
|
||||
public record BoundDereferenceNode(IEnumerable<Token> Tokens, NubType Type, BoundExpressionNode Expression) : BoundExpressionNode(Tokens, Type);
|
||||
|
||||
@@ -89,14 +89,14 @@ public class NubFuncType(NubType returnType, List<NubType> parameters) : NubSimp
|
||||
}
|
||||
}
|
||||
|
||||
public class NubStructType(string @namespace, string name) : NubComplexType
|
||||
public class NubCustomType(string @namespace, string name) : NubComplexType
|
||||
{
|
||||
public string Namespace { get; } = @namespace;
|
||||
public string Name { get; } = name;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is NubStructType other && other.Namespace == Namespace && other.Name == Name;
|
||||
return obj is NubCustomType other && other.Namespace == Namespace && other.Name == Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
|
||||
Reference in New Issue
Block a user