From 4f8135071ae6faf7abfbc2f4765101ce9c0bb287 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 19 Dec 2024 16:30:17 +0000 Subject: Define methods directly on struct --- .../ast/untyped/UntypedExtendInlineNode.java | 12 ---------- .../ast/untyped/UntypedNamespaceStatementNode.java | 2 +- .../ast/untyped/UntypedStructDefinitionNode.java | 27 +++++++++++++++++----- 3 files changed, 22 insertions(+), 19 deletions(-) delete mode 100644 src/main/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNode.java (limited to 'src/main/java/org/shedlang/compiler/ast') diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNode.java deleted file mode 100644 index b92e2513..00000000 --- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedExtendInlineNode.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.shedlang.compiler.ast.untyped; - -import org.shedlang.compiler.sources.Source; - -import java.util.List; - -public record UntypedExtendInlineNode( - UntypedTypeLevelExpressionNode extendedType, - List methods, - Source source -) implements UntypedNamespaceStatementNode { -} diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java index 4df38b08..8d94d5b8 100644 --- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java +++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedNamespaceStatementNode.java @@ -1,4 +1,4 @@ package org.shedlang.compiler.ast.untyped; -public sealed interface UntypedNamespaceStatementNode extends UntypedNode permits UntypedAssignNode, UntypedEffectDefinitionNode, UntypedExtendInlineNode, UntypedFunctionDefinitionNode, UntypedStructDefinitionNode, UntypedSumTypeDefinitionNode { +public sealed interface UntypedNamespaceStatementNode extends UntypedNode permits UntypedAssignNode, UntypedEffectDefinitionNode, UntypedFunctionDefinitionNode, UntypedStructDefinitionNode, UntypedSumTypeDefinitionNode { } diff --git a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNode.java b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNode.java index f4493eb0..af335ee5 100644 --- a/src/main/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNode.java +++ b/src/main/java/org/shedlang/compiler/ast/untyped/UntypedStructDefinitionNode.java @@ -15,10 +15,18 @@ public record UntypedStructDefinitionNode( Optional> typeLevelParams, List fields, boolean fieldsArePositional, + List methods, Source source ) implements UntypedNamespaceStatementNode, UntypedVariableDeclarationNode { public static Builder builder() { - return new Builder("X", Visibility.PRIVATE, Optional.empty(), P.vector(), false); + return new Builder( + "X", + Visibility.PRIVATE, + Optional.empty(), + P.vector(), + false, + P.vector() + ); } public record Builder( @@ -26,7 +34,8 @@ public record UntypedStructDefinitionNode( Visibility visibility, Optional> typeLevelParams, PVector fields, - boolean fieldsArePositional + boolean fieldsArePositional, + PVector methods ) { public UntypedStructDefinitionNode build() { return new UntypedStructDefinitionNode( @@ -35,6 +44,7 @@ public record UntypedStructDefinitionNode( this.typeLevelParams, this.fields, this.fieldsArePositional, + this.methods, Sources.NULL ); } @@ -45,7 +55,8 @@ public record UntypedStructDefinitionNode( this.visibility, this.typeLevelParams, this.fields, - this.fieldsArePositional + this.fieldsArePositional, + this.methods ); } @@ -55,7 +66,8 @@ public record UntypedStructDefinitionNode( this.visibility, Optional.of(typeLevelParams), this.fields, - this.fieldsArePositional + this.fieldsArePositional, + this.methods ); } @@ -65,7 +77,8 @@ public record UntypedStructDefinitionNode( this.visibility, this.typeLevelParams, this.fields.plus(field), - this.fieldsArePositional + this.fieldsArePositional, + this.methods ); } @@ -75,7 +88,9 @@ public record UntypedStructDefinitionNode( this.visibility, this.typeLevelParams, this.fields, - fieldsArePositional + fieldsArePositional, + this.methods + ); } } -- cgit v1.2.3