From f4a0159dc00fd1caa7a251d7f6bcd23948cf5f7d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 16 Dec 2023 15:50:49 +0000 Subject: Store namespace fields as permanent GC roots --- ...mpiler.testing.snapshots.Snapshotter)].expected | 7 ++++++ .../shedlang/compiler/patio/PatioCodeGenGc.java | 29 ++++++++++++++++++++++ .../compiler/patio/PatioCodeGenNamespaces.java | 2 ++ 3 files changed, 38 insertions(+) diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceFieldStoreTests]/[method:canGenerateCodeForNamespaceFieldStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceFieldStoreTests]/[method:canGenerateCodeForNamespaceFieldStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected index 03399c60..2408d323 100644 --- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceFieldStoreTests]/[method:canGenerateCodeForNamespaceFieldStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected +++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceFieldStoreTests]/[method:canGenerateCodeForNamespaceFieldStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected @@ -1,5 +1,11 @@ Compilation unit elements: +( + function-decl + "shed__runtime__gc_add_perm_root" + params=((param "gc_root" int)) + return-type=void +) Locals: @@ -13,6 +19,7 @@ Instructions: offset=(1) value=(local "b") ) + (call _ "shed__runtime__gc_add_perm_root" ((local "b"))) ) Temporary stack: 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; } -- cgit v1.2.3