aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 15:50:49 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 15:52:18 +0000
commitf4a0159dc00fd1caa7a251d7f6bcd23948cf5f7d (patch)
tree21ce45b98a3d23f6744efe6556944405f6530994 /src/main/java
parent4d5143de9b16a980bd865d786a03cdfee46cbe17 (diff)
Store namespace fields as permanent GC roots
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java29
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java2
2 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
index 4e12e531..144cf49b 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
@@ -1,11 +1,25 @@
package org.shedlang.compiler.patio;
+import org.shedlang.compiler.patio.ast.PatioFunctionDeclaration;
+import org.shedlang.compiler.patio.ast.PatioLocal;
+import org.shedlang.compiler.patio.ast.instructions.PatioCall;
+import org.shedlang.compiler.patio.ast.operands.PatioOperand;
import org.shedlang.compiler.patio.ast.types.*;
+import org.shedlang.compiler.sources.Source;
+import org.shedlang.compiler.sources.Sources;
import org.shedlang.compiler.util.Lists;
import java.util.List;
+import java.util.Optional;
public class PatioCodeGenGc {
+ private static final PatioFunctionDeclaration ADD_PERM_GC_ROOT = new PatioFunctionDeclaration(
+ "shed__runtime__gc_add_perm_root",
+ List.of(PatioLocal.param("gc_root", PatioCodeGenTypes.VALUE_TYPE)),
+ PatioTypes.VOID,
+ Sources.RUNTIME
+ );
+
private PatioCodeGenGc() {
}
@@ -41,4 +55,19 @@ public class PatioCodeGenGc {
value
));
}
+
+ public static PatioCodeGenContext addPermGcRoot(
+ PatioOperand gcRoot,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(ADD_PERM_GC_ROOT)
+ .addInstruction(new PatioCall(
+ Optional.empty(),
+ ADD_PERM_GC_ROOT.name(),
+ List.of(gcRoot),
+ source
+ ));
+ }
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
index 8bbf4e8b..280575bc 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenNamespaces.java
@@ -219,6 +219,8 @@ public class PatioCodeGenNamespaces {
source
));
+ context = PatioCodeGenGc.addPermGcRoot(fieldValue, source, context);
+
return context;
}