aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java38
1 files changed, 31 insertions, 7 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
index a1baec0f..4eb221c1 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
@@ -32,8 +32,26 @@ public record PatioCodeGenContext(
FunctionContext functionContext
) {
public record GlobalContext(
- TypeInfos typeInfos
+ TypeInfos typeInfos,
+ PMap<StructType, Integer> tags
) {
+ public static final GlobalContext EMPTY = forTypeInfos(TypeInfos.EMPTY);
+
+ public static GlobalContext forTypeInfos(TypeInfos typeInfos) {
+ var tags = P.<StructType, Integer>map();
+ var structTypes = typeInfos.structTypes();
+ var nextTag = 0;
+ for (var structType : structTypes) {
+ tags = tags.plus(structType, nextTag);
+ nextTag++;
+ }
+
+ return new GlobalContext(
+ typeInfos,
+ tags
+ );
+ }
+
public NamespaceTypeInfo namespaceTypeInfo(NamespaceName namespaceName) {
return typeInfos.namespaceTypeInfo(namespaceName)
// TODO: throw better error
@@ -46,12 +64,14 @@ public record PatioCodeGenContext(
.orElseThrow(() -> new RuntimeException("No type info for: " + type));
}
- public static final GlobalContext EMPTY = forTypeInfos(TypeInfos.EMPTY);
-
- public static GlobalContext forTypeInfos(TypeInfos typeInfos) {
- return new GlobalContext(
- typeInfos
- );
+ public int tag(StructType type) {
+ var tag = this.tags.get(type);
+ if (tag == null) {
+ // TODO: throw better error
+ throw new RuntimeException("No tag for: " + type);
+ } else {
+ return tag;
+ }
}
}
@@ -259,6 +279,10 @@ public record PatioCodeGenContext(
return this.globalContext.structTypeInfo(type);
}
+ public int tag(StructType type) {
+ return globalContext.tag(type);
+ }
+
public PatioCodeGenResult<String> allocateCompilationUnitElementName(
PatioCodeGenCompilationUnitElementSpace space,
String name