aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-01-28 21:15:53 +0000
committerMichael Williamson <mike@zwobble.org>2024-01-28 21:15:53 +0000
commitca64b2bb8026fb4510696736d2d887e21ac2bfa3 (patch)
treef965e1845bf36de7df6a738369faaa62297a9856
parentf495be56b344bf79f45ce1bc55165ae6933e8246 (diff)
Zero out GC children with explicit memory stores
-rw-r--r--runtime/src/gc.c6
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected14
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected21
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarLoadTests]/[method:canGenerateCodeForVarLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected4
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canGenerateCodeForVarStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected4
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canStoreIntoVarMultipleTimes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected8
-rw-r--r--src/main/java/org/shedlang/compiler/patio/types/PatioOffsets.java13
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioGc.java36
-rw-r--r--src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioVars.java8
15 files changed, 177 insertions, 21 deletions
diff --git a/runtime/src/gc.c b/runtime/src/gc.c
index b15c20dc..8d2efc08 100644
--- a/runtime/src/gc.c
+++ b/runtime/src/gc.c
@@ -87,12 +87,6 @@ void* shed__runtime__gc_alloc(size_t size, uint32_t children_offset, uint32_t ch
object->children_offset = children_offset;
object->children_count = children_count;
- __builtin_memset(
- ((void*) object) + children_offset,
- 0,
- sizeof(void*) * children_count
- );
-
// TODO: is it possible to leave adding the root to the caller, and avoid
// having to add so many roots? (Since some values will immediately become a
// descendant of a root.)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index f06a5f47..5475f888 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -74,6 +74,20 @@ Instructions:
(
(call (local "userDefinedEffectPointer__State__0") "shed__runtime__gc_alloc" ((int-const (byte-size-of (struct ((struct (data-ptr int int32 int32)) (struct (int int)))))) (int32-const (byte-offset-of (struct ((struct (data-ptr int int32 int32)) (struct (int int)))) (1))) (int32-const 2)))
+ (
+ memory-store
+ pointer=(local "userDefinedEffectPointer__State__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int))))
+ offset=(1 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "userDefinedEffectPointer__State__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int))))
+ offset=(1 1)
+ value=(int-const 0)
+ )
(call (local "closurePointer__read__0") "shed__runtime__gc_alloc" ((int-const (byte-size-of (struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct ()))))))) (int32-const (byte-offset-of (struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct ()))))) (1 2))) (int32-const 0)))
(
memory-store
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 00c9a799..7ffd8bed 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -73,6 +73,20 @@ Instructions:
memory-store
pointer=(local "closurePointer__f__0")
layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
+ offset=(1 2 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
+ offset=(1 2 1)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
offset=(1 0)
value=(function-ptr-const "shed__function__f__0")
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index b2251c34..b2b20774 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -73,6 +73,20 @@ Instructions:
memory-store
pointer=(local "closurePointer__f__0")
layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
+ offset=(1 2 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
+ offset=(1 2 1)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
offset=(1 0)
value=(function-ptr-const "shed__function__f__0")
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 9df8efff..cece95b3 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -73,6 +73,20 @@ Instructions:
memory-store
pointer=(local "closurePointer__f__0")
layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (data-ptr data-ptr))))))
+ offset=(1 2 0)
+ value=(data-ptr-const null)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (data-ptr data-ptr))))))
+ offset=(1 2 1)
+ value=(data-ptr-const null)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (data-ptr data-ptr))))))
offset=(1 0)
value=(function-ptr-const "shed__function__f__0")
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index dada1615..1d906b97 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -81,6 +81,20 @@ Instructions:
memory-store
pointer=(local "closurePointer__f__0")
layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
+ offset=(1 2 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
+ offset=(1 2 1)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "closurePointer__f__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (function-ptr (struct ()) (struct (int int))))))
offset=(1 0)
value=(function-ptr-const "shed__function__f__0")
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 8d3e1d22..665acac6 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -25,6 +25,20 @@ Compilation unit elements:
memory-store
pointer=(local "structValuePointer__0")
layout=(struct ((struct (data-ptr int int32 int32)) (struct (int (struct (int int))))))
+ offset=(1 1 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "structValuePointer__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int (struct (int int))))))
+ offset=(1 1 1)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "structValuePointer__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int (struct (int int))))))
offset=(1 0)
value=(int-const 0)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index ddc72f15..b2bde483 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -56,6 +56,20 @@
(call (local "namespaceValue__0") "shed__runtime__gc_alloc" ((int-const (byte-size-of (struct ((struct (data-ptr int int32 int32)) (struct (int int)))))) (int32-const (byte-offset-of (struct ((struct (data-ptr int int32 int32)) (struct (int int)))) (1))) (int32-const 2)))
(
memory-store
+ pointer=(local "namespaceValue__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int))))
+ offset=(1 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "namespaceValue__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int))))
+ offset=(1 1)
+ value=(int-const 0)
+ )
+ (
+ memory-store
pointer=(data-ptr-const "shed__namespace__An_Example")
layout=data-ptr
offset=()
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index d6376954..f1e57c98 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioTupleCreateTests]/[method:canGenerateCodeForTupleCreate(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -26,6 +26,27 @@ Instructions:
pointer=(local "tuplePointer__0")
layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int int))))
offset=(1 0)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "tuplePointer__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int int))))
+ offset=(1 1)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "tuplePointer__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int int))))
+ offset=(1 2)
+ value=(int-const 0)
+ )
+ (
+ memory-store
+ pointer=(local "tuplePointer__0")
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int int int))))
+ offset=(1 0)
value=(local "tupleElement__0__0")
)
(
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarLoadTests]/[method:canGenerateCodeForVarLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarLoadTests]/[method:canGenerateCodeForVarLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 6e93849c..80a5a9d5 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarLoadTests]/[method:canGenerateCodeForVarLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarLoadTests]/[method:canGenerateCodeForVarLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -12,8 +12,8 @@ Instructions:
memory-load
(local "varValue__x__0")
pointer=(local "local__x")
- layout=(struct ((struct (data-ptr int int32 int32)) int))
- offset=(1)
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int))))
+ offset=(1 0)
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canGenerateCodeForVarStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canGenerateCodeForVarStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index bd2b4eaf..feea5bf2 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canGenerateCodeForVarStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canGenerateCodeForVarStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -10,8 +10,8 @@ Instructions:
(
memory-store
pointer=(local "local__x")
- layout=(struct ((struct (data-ptr int int32 int32)) int))
- offset=(1)
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int))))
+ offset=(1 0)
value=(local "b")
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canStoreIntoVarMultipleTimes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canStoreIntoVarMultipleTimes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 2dd55297..08d01b4d 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canStoreIntoVarMultipleTimes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.shidtopatio.ShidToPatioVarStoreTests]/[method:canStoreIntoVarMultipleTimes(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -10,15 +10,15 @@ Instructions:
(
memory-store
pointer=(local "local__x")
- layout=(struct ((struct (data-ptr int int32 int32)) int))
- offset=(1)
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int))))
+ offset=(1 0)
value=(local "b")
)
(
memory-store
pointer=(local "local__x")
- layout=(struct ((struct (data-ptr int int32 int32)) int))
- offset=(1)
+ layout=(struct ((struct (data-ptr int int32 int32)) (struct (int))))
+ offset=(1 0)
value=(local "a")
)
)
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;