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/PatioCodeGenGc.java5
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java15
2 files changed, 14 insertions, 6 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
index cd036368..23ee6cac 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
@@ -42,8 +42,9 @@ public class PatioCodeGenGc {
}
/**
- * Creates a data value for GC objects that should never be garbage
- * collected. Such a value does not need to be added to the set of GC roots.
+ * Creates a data value for GC objects with no GC children that should never
+ * be garbage collected. Such a value does not need to be added to the set
+ * of GC roots.
*/
public static PatioDataValue gcObjectStaticDataValue(PatioDataValue value) {
return PatioDataValues.struct(List.of(
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
index 595033b1..682c6ceb 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
@@ -191,7 +191,7 @@ public class PatioCodeGenNamespaces {
target,
namespacePointer,
initialValue.layout(),
- List.of(namespaceTypeInfo.fieldIndex(fieldName)),
+ fieldOffset(namespaceTypeInfo.fieldIndex(fieldName)),
source
));
@@ -211,23 +211,30 @@ public class PatioCodeGenNamespaces {
context = context.addInstruction(new PatioMemoryStore(
new PatioDataPtr(globalNameNamespaceValue(namespaceName)),
initialValue.layout(),
- List.of(namespaceTypeInfo.fieldIndex(fieldName)),
+ fieldOffset(namespaceTypeInfo.fieldIndex(fieldName)),
fieldValue,
source
));
+ // TODO: we only have to add fields since namespace values are marked
+ // as GC objects without children. An (better?) alternative would be to
+ // have namespace values behave as ordinary GC objects with GC children.
context = PatioCodeGenGc.addPermGcRoot(fieldValue, source, context);
return context;
}
private static PatioDataValue namespaceDataInitialValue(NamespaceTypeInfo namespaceTypeInfo) {
- return PatioDataValues.struct(
+ return PatioCodeGenGc.gcObjectStaticDataValue(PatioDataValues.struct(
Lists.repeat(
PatioDataValues.int_(0),
namespaceTypeInfo.fieldCount()
)
- );
+ ));
+ }
+
+ private static List<Integer> fieldOffset(int fieldIndex) {
+ return PatioCodeGenGc.gcObjectOffset(List.of(fieldIndex));
}
// TODO: allocate names through context