diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-04-24 13:15:25 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-04-24 13:15:25 +0100 |
| commit | 7bbb27312bf0d28bc0230f0a1e58354e8feef13d (patch) | |
| tree | ea3f2f103b825ce39eeebf68c47e79ebdef78938 /src/main/java/org/zwobble | |
| parent | 776fcb476f229030cb5d34f4b948603f05c01a79 (diff) | |
Add typed AST for struct definitions
Diffstat (limited to 'src/main/java/org/zwobble')
5 files changed, 37 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedNamespaceStatementNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedNamespaceStatementNode.java new file mode 100644 index 0000000..79dc0bb --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedNamespaceStatementNode.java @@ -0,0 +1,4 @@ +package org.zwobble.hobgoblin.compiler.ast.typed; + +public sealed interface TypedNamespaceStatementNode extends TypedNode permits TypedStructDefinitionNode { +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedStructDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedStructDefinitionNode.java new file mode 100644 index 0000000..0f966ab --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedStructDefinitionNode.java @@ -0,0 +1,13 @@ +package org.zwobble.hobgoblin.compiler.ast.typed; + +import org.zwobble.hobgoblin.compiler.sources.Source; +import org.zwobble.hobgoblin.compiler.types.StructType; + +import java.util.List; + +public record TypedStructDefinitionNode( + StructType type, + List<TypedStructFieldDefinitionNode> fields, + Source source +) implements TypedNamespaceStatementNode { +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedStructFieldDefinitionNode.java b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedStructFieldDefinitionNode.java new file mode 100644 index 0000000..739ea63 --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/ast/typed/TypedStructFieldDefinitionNode.java @@ -0,0 +1,11 @@ +package org.zwobble.hobgoblin.compiler.ast.typed; + +import org.zwobble.hobgoblin.compiler.sources.Source; +import org.zwobble.hobgoblin.compiler.types.Type; + +public record TypedStructFieldDefinitionNode( + String name, + TypedTypeLevelExpressionNode<Type> type, + Source source +) implements TypedNode { +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/StructType.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/StructType.java new file mode 100644 index 0000000..a5b50ab --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/StructType.java @@ -0,0 +1,8 @@ +package org.zwobble.hobgoblin.compiler.types; + +public record StructType(NamespaceName namespaceName, String name) implements Type { + @Override + public String describe() { + return namespaceName.toString() + "." + name; + } +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java index 2692261..f7b6833 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/Type.java @@ -1,4 +1,4 @@ package org.zwobble.hobgoblin.compiler.types; -public sealed interface Type extends TypeLevelValue permits ScalarType, TypeLevelValueType { +public sealed interface Type extends TypeLevelValue permits ScalarType, StructType, TypeLevelValueType { } |
