diff --git a/src/compiler/NubLang/Generation/QBE/QBEGenerator.Expression.cs b/src/compiler/NubLang/Generation/QBE/QBEGenerator.Expression.cs index dacdcad..9f1e007 100644 --- a/src/compiler/NubLang/Generation/QBE/QBEGenerator.Expression.cs +++ b/src/compiler/NubLang/Generation/QBE/QBEGenerator.Expression.cs @@ -24,7 +24,6 @@ public partial class QBEGenerator LiteralNode literal => EmitLiteral(literal), UnaryExpressionNode unaryExpression => EmitUnaryExpression(unaryExpression), StructFieldAccessNode structFieldAccess => EmitStructFieldAccess(structFieldAccess), - InterfaceFuncAccessNode traitFuncAccess => EmitTraitFuncAccess(traitFuncAccess), ArrayIndexAccessNode arrayIndex => EmitArrayIndexAccess(arrayIndex), _ => throw new ArgumentOutOfRangeException(nameof(expression)) }; @@ -414,11 +413,6 @@ public partial class QBEGenerator return new Val(output, structFieldAccess.Type, ValKind.Pointer); } - private Val EmitTraitFuncAccess(InterfaceFuncAccessNode interfaceFuncAccess) - { - throw new NotImplementedException(); - } - private Val EmitFuncCall(FuncCallNode funcCall) { var expression = EmitExpression(funcCall.Expression); diff --git a/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs b/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs index d7698da..bd760f5 100644 --- a/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs +++ b/src/compiler/NubLang/Generation/QBE/QBEGenerator.cs @@ -55,12 +55,6 @@ public partial class QBEGenerator _writer.NewLine(); } - foreach (var trait in _definitionTable.GetTraits()) - { - EmitTraitVTable(trait); - _writer.NewLine(); - } - foreach (var funcDef in _syntaxTree.Definitions.OfType()) { EmitFuncDefinition(LocalFuncName(funcDef), funcDef.Signature.Parameters, funcDef.Signature.ReturnType, funcDef.Body); @@ -411,18 +405,6 @@ public partial class QBEGenerator } } - private void EmitTraitVTable(TraitNode traitDef) - { - _writer.WriteLine($"type {CustomTypeName(traitDef.Name)} = {{"); - - foreach (var func in traitDef.Functions) - { - _writer.Indented($"l, # func {func.Name}({string.Join(", ", func.Signature.Parameters.Select(x => $"{x.Name}: {x.Type}"))}): {func.Signature.ReturnType}"); - } - - _writer.WriteLine("}"); - } - private void EmitBlock(BlockNode block, Scope? scope = null) { _scopes.Push(scope ?? Scope.SubScope()); diff --git a/src/compiler/NubLang/Generation/TypedDefinitionTable.cs b/src/compiler/NubLang/Generation/TypedDefinitionTable.cs index 55151d2..6bfac39 100644 --- a/src/compiler/NubLang/Generation/TypedDefinitionTable.cs +++ b/src/compiler/NubLang/Generation/TypedDefinitionTable.cs @@ -37,8 +37,8 @@ public sealed class TypedDefinitionTable return _definitions.OfType(); } - public IEnumerable GetTraits() + public IEnumerable GetInterfaces() { - return _definitions.OfType(); + return _definitions.OfType(); } } \ No newline at end of file diff --git a/src/compiler/NubLang/TypeChecking/DefinitionTable.cs b/src/compiler/NubLang/TypeChecking/DefinitionTable.cs index e1bcc1d..37e5c63 100644 --- a/src/compiler/NubLang/TypeChecking/DefinitionTable.cs +++ b/src/compiler/NubLang/TypeChecking/DefinitionTable.cs @@ -38,14 +38,14 @@ public class DefinitionTable return structNode.Fields.Where(x => x.Name == field); } - public IEnumerable LookupTrait(CustomTypeNode type) + public IEnumerable LookupInterface(CustomTypeNode type) { return _definitions .OfType() .Where(x => x.Name == type.Name); } - public IEnumerable LookupTraitFunc(InterfaceSyntax @interface, string name) + public IEnumerable LookupInterfaceFunc(InterfaceSyntax @interface, string name) { return @interface.Functions.Where(x => x.Name == name); } diff --git a/src/compiler/NubLang/TypeChecking/Node/DefinitionNode.cs b/src/compiler/NubLang/TypeChecking/Node/DefinitionNode.cs index 9ded243..ff081c3 100644 --- a/src/compiler/NubLang/TypeChecking/Node/DefinitionNode.cs +++ b/src/compiler/NubLang/TypeChecking/Node/DefinitionNode.cs @@ -14,6 +14,6 @@ public record StructFieldNode(int Index, string Name, TypeNode Type, Optional Fields) : DefinitionNode; -public record TraitFuncNode(string Name, FuncSignatureNode Signature) : Node; +public record InterfacenFuncNode(string Name, FuncSignatureNode Signature) : Node; -public record TraitNode(string Name, IReadOnlyList Functions) : DefinitionNode; \ No newline at end of file +public record InterfaceNode(string Name, IReadOnlyList Functions) : DefinitionNode; \ No newline at end of file diff --git a/src/compiler/NubLang/TypeChecking/Node/TypeNode.cs b/src/compiler/NubLang/TypeChecking/Node/TypeNode.cs index 566f567..9567073 100644 --- a/src/compiler/NubLang/TypeChecking/Node/TypeNode.cs +++ b/src/compiler/NubLang/TypeChecking/Node/TypeNode.cs @@ -217,7 +217,7 @@ public class CustomTypeNode(string name) : NubComplexTypeNode return CustomTypeKind.Struct; } - if (definitionTable.GetTraits().Any(x => x.Name == Name)) + if (definitionTable.GetInterfaces().Any(x => x.Name == Name)) { return CustomTypeKind.Interface; } diff --git a/src/compiler/NubLang/TypeChecking/TypeChecker.cs b/src/compiler/NubLang/TypeChecking/TypeChecker.cs index 27a43df..b464d2e 100644 --- a/src/compiler/NubLang/TypeChecking/TypeChecker.cs +++ b/src/compiler/NubLang/TypeChecking/TypeChecker.cs @@ -52,23 +52,23 @@ public sealed class TypeChecker return node switch { ExternFuncSyntax definition => CheckExternFuncDefinition(definition), - InterfaceSyntax definition => CheckTraitDefinition(definition), + InterfaceSyntax definition => CheckInterfaceDefinition(definition), LocalFuncSyntax definition => CheckLocalFuncDefinition(definition), StructSyntax definition => CheckStruct(definition), _ => throw new ArgumentOutOfRangeException(nameof(node)) }; } - private TraitNode CheckTraitDefinition(InterfaceSyntax node) + private InterfaceNode CheckInterfaceDefinition(InterfaceSyntax node) { - var functions = new List(); + var functions = new List(); foreach (var function in node.Functions) { - functions.Add(new TraitFuncNode(function.Name, CheckFuncSignature(function.Signature))); + functions.Add(new InterfacenFuncNode(function.Name, CheckFuncSignature(function.Signature))); } - return new TraitNode(node.Name, functions); + return new InterfaceNode(node.Name, functions); } private StructNode CheckStruct(StructSyntax node) @@ -362,28 +362,28 @@ public sealed class TypeChecker if (boundExpression.Type is CustomTypeNode customType) { - var traits = _definitionTable.LookupTrait(customType).ToArray(); - if (traits.Length > 0) + var interfaces = _definitionTable.LookupInterface(customType).ToArray(); + if (interfaces.Length > 0) { - if (traits.Length > 1) + if (interfaces.Length > 1) { - throw new CheckException(Diagnostic.Error($"Trait {customType} has multiple definitions").Build()); + throw new CheckException(Diagnostic.Error($"Interface {customType} has multiple definitions").Build()); } - var trait = traits[0]; + var @interface = interfaces[0]; - var traitFuncs = _definitionTable.LookupTraitFunc(trait, expression.Member).ToArray(); - if (traits.Length > 0) + var interfaceFuncs = _definitionTable.LookupInterfaceFunc(@interface, expression.Member).ToArray(); + if (interfaces.Length > 0) { - if (traits.Length > 1) + if (interfaces.Length > 1) { - throw new CheckException(Diagnostic.Error($"Trait {customType} has multiple functions with the name {expression.Member}").Build()); + throw new CheckException(Diagnostic.Error($"Interface {customType} has multiple functions with the name {expression.Member}").Build()); } - var traitFunc = traitFuncs[0]; + var interfaceFunc = interfaceFuncs[0]; - var returnType = CheckType(traitFunc.Signature.ReturnType); - var parameterTypes = traitFunc.Signature.Parameters.Select(p => CheckType(p.Type)).ToList(); + var returnType = CheckType(interfaceFunc.Signature.ReturnType); + var parameterTypes = interfaceFunc.Signature.Parameters.Select(p => CheckType(p.Type)).ToList(); var type = new FuncTypeNode(parameterTypes, returnType); return new InterfaceFuncAccessNode(type, customType, boundExpression, expression.Member); }