diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-29 10:18:42 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-29 10:18:42 +0000 |
| commit | 15a356d4c09944174e482b75f6dab24ca474b285 (patch) | |
| tree | 2bce646e43d8e417cc1199fa2f66a1d098c153cc /src/main/java | |
| parent | 77ec4d04036f4e781a38cf5f477f238fe95d493d (diff) | |
Change TypedSumTypeDefinitionNode to have typeOrConstructor()
Diffstat (limited to 'src/main/java')
5 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/org/shedlang/compiler/ast/typed/TypedSumTypeDefinitionNode.java b/src/main/java/org/shedlang/compiler/ast/typed/TypedSumTypeDefinitionNode.java index cb6b6418..109a7ace 100644 --- a/src/main/java/org/shedlang/compiler/ast/typed/TypedSumTypeDefinitionNode.java +++ b/src/main/java/org/shedlang/compiler/ast/typed/TypedSumTypeDefinitionNode.java @@ -2,9 +2,10 @@ package org.shedlang.compiler.ast.typed; import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.SumType; +import org.shedlang.compiler.types.TypeOrConstructor; public record TypedSumTypeDefinitionNode( - SumType type, + TypeOrConstructor<SumType> typeOrConstructor, Source source ) implements TypedNamespaceStatementNode { } diff --git a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java index 501e12e5..d61aa192 100644 --- a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java +++ b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java @@ -571,7 +571,8 @@ public class ShidCodeGen { ) { var defineSumTypeInstruction = new ShidPushUnit(node.source()); - var localName = context.shedVariableToLocal(node.type().name()); + var sumType = node.typeOrConstructor().toType(); + var localName = context.shedVariableToLocal(sumType.name()); var storeInstruction = new ShidLocalStore(localName, node.source()); return context diff --git a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java index ac3fde79..4f428c1f 100644 --- a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java @@ -1621,7 +1621,7 @@ public class TypeChecker { var type = context.getLexicalState(SumType.class, untyped.name()); return context.toResult(new TypedSumTypeDefinitionNode( - type, + TypeOrConstructor.type(type), untyped.source() )); } diff --git a/src/main/java/org/shedlang/compiler/types/StructuredType.java b/src/main/java/org/shedlang/compiler/types/StructuredType.java index 114da180..bc836379 100644 --- a/src/main/java/org/shedlang/compiler/types/StructuredType.java +++ b/src/main/java/org/shedlang/compiler/types/StructuredType.java @@ -1,5 +1,5 @@ package org.shedlang.compiler.types; -public sealed interface StructuredType extends Type permits StructType { +public sealed interface StructuredType extends Type permits StructType, SumType { String name(); } diff --git a/src/main/java/org/shedlang/compiler/types/SumType.java b/src/main/java/org/shedlang/compiler/types/SumType.java index 8c293fca..08fef92f 100644 --- a/src/main/java/org/shedlang/compiler/types/SumType.java +++ b/src/main/java/org/shedlang/compiler/types/SumType.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.types; /** * A discriminated union of several different types. */ -public record SumType(NamespaceName namespaceName, String name) implements Type { +public record SumType(NamespaceName namespaceName, String name) implements StructuredType { @Override public String describe() { return namespaceName.toString() + "." + name; |
