diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-02-07 20:53:02 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-02-07 21:11:55 +0000 |
| commit | bd1515f9b219cef789cc31b2f8efbb217bfc2c3c (patch) | |
| tree | 13f18d9336f4702dcab5587664c8e67f8289bd3b /src/main/java/org/shedlang/compiler/ast | |
| parent | 9b56f880febd39cb705d658a50512ef3ae1a9162 (diff) | |
Add basic type checking for native type declarations
Diffstat (limited to 'src/main/java/org/shedlang/compiler/ast')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceStatementNode.java | 2 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/ast/typed/TypedNativeTypeDeclarationNode.java | 50 |
2 files changed, 51 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceStatementNode.java b/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceStatementNode.java index d38cff5e..c63b58d7 100644 --- a/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceStatementNode.java +++ b/src/main/java/org/shedlang/compiler/ast/typed/TypedNamespaceStatementNode.java @@ -1,4 +1,4 @@ package org.shedlang.compiler.ast.typed; -public sealed interface TypedNamespaceStatementNode extends TypedNode permits TypedAssignNode, TypedEffectDefinitionNode, TypedFunctionDefinitionNode, TypedNativeFunctionDeclarationNode, TypedStructDefinitionNode, TypedSumTypeDefinitionNode { +public sealed interface TypedNamespaceStatementNode extends TypedNode permits TypedAssignNode, TypedEffectDefinitionNode, TypedFunctionDefinitionNode, TypedNativeFunctionDeclarationNode, TypedNativeTypeDeclarationNode, TypedStructDefinitionNode, TypedSumTypeDefinitionNode { } diff --git a/src/main/java/org/shedlang/compiler/ast/typed/TypedNativeTypeDeclarationNode.java b/src/main/java/org/shedlang/compiler/ast/typed/TypedNativeTypeDeclarationNode.java new file mode 100644 index 00000000..2c438577 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/ast/typed/TypedNativeTypeDeclarationNode.java @@ -0,0 +1,50 @@ +package org.shedlang.compiler.ast.typed; + +import org.pcollections.PVector; +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.sources.Sources; +import org.shedlang.compiler.types.*; +import org.shedlang.compiler.util.P; + +import java.util.List; + +public record TypedNativeTypeDeclarationNode( + TypeOrConstructor<SimpleNativeType> typeOrConstructor, + List<TypedNativeFunctionDeclarationNode> methods, + Source source +) implements TypedNamespaceStatementNode { + public static Builder builder() { + var namespaceName = NamespaceName.of("Default", "Test", "Namespace"); + return new Builder( + TypeOrConstructor.type(Types.nativeType(namespaceName, "X")), + P.vector() + ); + } + + public record Builder( + TypeOrConstructor<SimpleNativeType> type, + PVector<TypedNativeFunctionDeclarationNode> methods + ) { + public TypedNativeTypeDeclarationNode build() { + return new TypedNativeTypeDeclarationNode( + this.type, + this.methods, + Sources.NULL + ); + } + + public Builder withType(SimpleNativeType type) { + return new Builder( + TypeOrConstructor.type(type), + this.methods + ); + } + + public Builder addMethod(TypedNativeFunctionDeclarationNode method) { + return new Builder( + this.type, + this.methods.plus(method) + ); + } + } +} |
