aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-16 14:32:10 +0000
committerMichael Williamson <mike@zwobble.org>2026-03-20 10:14:41 +0000
commitb81f97cd01753eabe3722b8a9211e4f3f8d621ef (patch)
tree2638402581a59b19e7174e4ff0d44071b6b9582b /src/main/java
parent29e8e5f6823a76e468d980d95934372f2c13c0d6 (diff)
Garbage collect arrays
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ArrayBuilderRuntimeType.java35
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ArrayRuntimeType.java30
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java7
3 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ArrayBuilderRuntimeType.java b/src/main/java/org/shedlang/compiler/shidtopatio/ArrayBuilderRuntimeType.java
new file mode 100644
index 00000000..5cb8000a
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ArrayBuilderRuntimeType.java
@@ -0,0 +1,35 @@
+package org.shedlang.compiler.shidtopatio;
+
+import org.shedlang.compiler.patio.types.PatioDataLayout;
+import org.shedlang.compiler.patio.types.PatioDataLayouts;
+
+import java.util.List;
+
+public class ArrayBuilderRuntimeType implements RuntimeType {
+ public static final ArrayBuilderRuntimeType INSTANCE = new ArrayBuilderRuntimeType();
+
+ private ArrayBuilderRuntimeType() {
+ }
+
+ @Override
+ public PatioDataLayout layout() {
+ return ShidToPatioGc.gcObjectDataLayout(
+ PatioDataLayouts.struct(List.of(
+ PatioDataLayouts.INT,
+ PatioDataLayouts.INT,
+ PatioDataLayouts.INT,
+ PatioDataLayouts.BOOL
+ ))
+ );
+ }
+
+ @Override
+ public List<Integer> gcChildrenOffset() {
+ return ShidToPatioGc.gcObjectOffset(List.of());
+ }
+
+ @Override
+ public int gcChildrenCount() {
+ return 1;
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ArrayRuntimeType.java b/src/main/java/org/shedlang/compiler/shidtopatio/ArrayRuntimeType.java
new file mode 100644
index 00000000..bc977526
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ArrayRuntimeType.java
@@ -0,0 +1,30 @@
+package org.shedlang.compiler.shidtopatio;
+
+import org.shedlang.compiler.patio.types.PatioDataLayout;
+import org.shedlang.compiler.patio.types.PatioDataLayouts;
+
+import java.util.List;
+
+public class ArrayRuntimeType implements RuntimeType {
+ public static final ArrayRuntimeType INSTANCE = new ArrayRuntimeType();
+
+ private ArrayRuntimeType() {
+ }
+
+ @Override
+ public PatioDataLayout layout() {
+ // TODO: separate out runtime type from the info needed by RTTI
+ return PatioDataLayouts.struct(List.of());
+ }
+
+ @Override
+ public List<Integer> gcChildrenOffset() {
+ return List.of();
+ }
+
+ @Override
+ public int gcChildrenCount() {
+ // This is a lie! We special case arrays in the runtime.
+ return 0;
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java
index 546a6ccd..87e5ff61 100644
--- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java
+++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioContext.java
@@ -48,6 +48,13 @@ public record ShidToPatioContext(
// Ensure that scalars have tag of 0: this is relied on in the
// runtime (for instance, when allocating ints and strings).
context = context.addRuntimeTypeTag(ScalarRuntimeType.INSTANCE);
+
+ // Ensure that arrays have tag of 1.
+ context = context.addRuntimeTypeTag(ArrayRuntimeType.INSTANCE);
+
+ // Ensure that array builders have tag of 2.
+ context = context.addRuntimeTypeTag(ArrayBuilderRuntimeType.INSTANCE);
+
context = generateStructTags(context);
context = generateEffectTags(context);