diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-23 22:40:47 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-23 22:41:07 +0000 |
| commit | 04204c8c4fb943b98409678bc47b924629bc6b1b (patch) | |
| tree | 00cfd1fb61426b2fc4282bfc348f0cc415940c81 /src/main/java | |
| parent | 4281ebfda1ba1753795e89328a4eca4327124e69 (diff) | |
Add ConstructedType
Diffstat (limited to 'src/main/java')
3 files changed, 22 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/types/ConstructedType.java b/src/main/java/org/shedlang/compiler/types/ConstructedType.java new file mode 100644 index 00000000..558b227b --- /dev/null +++ b/src/main/java/org/shedlang/compiler/types/ConstructedType.java @@ -0,0 +1,17 @@ +package org.shedlang.compiler.types; + +import java.util.List; +import java.util.stream.Collectors; + +public record ConstructedType<T extends StructuredType>( + TypeConstructor<T> constructor, + List<Type> args +) implements Type { + @Override + public String describe() { + var argsString = args.stream() + .map(arg -> arg.describe()) + .collect(Collectors.joining(", ")); + return constructor.describe() + "[" + argsString + "]"; + } +} diff --git a/src/main/java/org/shedlang/compiler/types/Type.java b/src/main/java/org/shedlang/compiler/types/Type.java index 8ec577bf..9a062156 100644 --- a/src/main/java/org/shedlang/compiler/types/Type.java +++ b/src/main/java/org/shedlang/compiler/types/Type.java @@ -6,5 +6,5 @@ package org.shedlang.compiler.types; * found through auxiliary data. */ public sealed interface Type extends TypeLevelValue - permits BoolType, BottomType, FunctionType, IntType, NamespaceType, StringType, StructuredType, SumType, TopType, TupleType, TypeLevelValueType, TypeParam, UnitType { + permits BoolType, BottomType, ConstructedType, FunctionType, IntType, NamespaceType, StringType, StructuredType, SumType, TopType, TupleType, TypeLevelValueType, TypeParam, UnitType { } diff --git a/src/main/java/org/shedlang/compiler/types/TypeParam.java b/src/main/java/org/shedlang/compiler/types/TypeParam.java index 240d701d..702d6a5f 100644 --- a/src/main/java/org/shedlang/compiler/types/TypeParam.java +++ b/src/main/java/org/shedlang/compiler/types/TypeParam.java @@ -1,6 +1,10 @@ package org.shedlang.compiler.types; public record TypeParam(Scope scope, String name) implements Type { + public static TypeParam forStructType(StructType structType, String name) { + return new TypeParam(new Scope.Struct(structType), name); + } + @Override public String describe() { return name; |
