diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-01-28 21:15:53 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-01-28 21:15:53 +0000 |
| commit | ca64b2bb8026fb4510696736d2d887e21ac2bfa3 (patch) | |
| tree | f965e1845bf36de7df6a738369faaa62297a9856 /src/main/java | |
| parent | f495be56b344bf79f45ce1bc55165ae6933e8246 (diff) | |
Zero out GC children with explicit memory stores
Diffstat (limited to 'src/main/java')
3 files changed, 50 insertions, 7 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/types/PatioOffsets.java b/src/main/java/org/shedlang/compiler/patio/types/PatioOffsets.java index f427bd41..5a3be3ff 100644 --- a/src/main/java/org/shedlang/compiler/patio/types/PatioOffsets.java +++ b/src/main/java/org/shedlang/compiler/patio/types/PatioOffsets.java @@ -1,6 +1,9 @@ package org.shedlang.compiler.patio.types; import org.pcollections.PVector; +import org.pcollections.TreePVector; + +import java.util.List; public class PatioOffsets { private PatioOffsets() { @@ -8,6 +11,16 @@ public class PatioOffsets { public static PatioDataLayout offsetDataLayout( PatioDataLayout patioDataLayout, + List<Integer> patioOffsets + ) { + return offsetDataLayout( + patioDataLayout, + TreePVector.from(patioOffsets) + ); + } + + public static PatioDataLayout offsetDataLayout( + PatioDataLayout patioDataLayout, PVector<Integer> patioOffsets ) { // TODO: check that offset is valid? diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java index 351dee49..4bb7c3a3 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java @@ -3,11 +3,10 @@ package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.patio.PatioFunctionDeclaration; import org.shedlang.compiler.patio.PatioLocal; import org.shedlang.compiler.patio.instructions.PatioCall; -import org.shedlang.compiler.patio.operands.PatioInt32Const; -import org.shedlang.compiler.patio.operands.PatioIntConst; -import org.shedlang.compiler.patio.operands.PatioLocalRef; -import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.instructions.PatioMemoryStore; +import org.shedlang.compiler.patio.operands.*; import org.shedlang.compiler.patio.types.*; +import org.shedlang.compiler.patio.values.PatioDataPtrValueNull; import org.shedlang.compiler.patio.values.PatioIntValueByteOffsetOf; import org.shedlang.compiler.patio.values.PatioIntValueByteSizeOf; import org.shedlang.compiler.sources.Source; @@ -154,12 +153,39 @@ public class ShidToPatioGc { var offset = new PatioInt32Const(new PatioIntValueByteOffsetOf(layout, childrenOffset)); - return context.addInstruction(new PatioCall( + context = context.addInstruction(new PatioCall( Optional.of(destination), ALLOC.name(), List.of(size, offset, PatioInt32Const.of(childrenCount)), source )); + + for (var childIndex = 0; childIndex < childrenCount; childIndex++) { + var childOffset = Lists.concat(childrenOffset, List.of(childIndex)); + var childDataLayout = PatioOffsets.offsetDataLayout(layout, childOffset); + + var zero = switch (childDataLayout) { + case PatioDataLayoutDataPtr patioDataLayoutDataPtr -> + new PatioDataPtrConst(new PatioDataPtrValueNull()); + + case PatioDataLayoutInt dataLayoutInt -> + PatioIntConst.of(0); + + default -> + // TODO: better error + throw new IllegalArgumentException("unsupported child"); + }; + + context = context.addInstruction(new PatioMemoryStore( + destination, + layout, + childOffset, + zero, + source + )); + } + + return context; } // == Collection == diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java index 37e30123..34143882 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java @@ -16,9 +16,13 @@ public class ShidToPatioVars { } private static final PatioDataLayout VAR_DATA_LAYOUT = - ShidToPatioGc.gcObjectDataLayout(PatioDataLayouts.fromType(ShidToPatioTypes.VALUE_TYPE)); + ShidToPatioGc.gcObjectDataLayout( + PatioDataLayouts.struct(List.of( + PatioDataLayouts.fromType(ShidToPatioTypes.VALUE_TYPE) + )) + ); - private static final List<Integer> VALUE_OFFSET = ShidToPatioGc.gcObjectOffset(List.of()); + private static final List<Integer> VALUE_OFFSET = ShidToPatioGc.gcObjectOffset(List.of(0)); private static final List<Integer> GC_CHILDREN_OFFSET = ShidToPatioGc.gcObjectOffset(List.of()); private static final int GC_CHILDREN_COUNT = 1; |
