aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 22:14:06 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 22:15:34 +0000
commit660f8ae4a3869129ed0a35b83a8a87ef2c042fdf (patch)
tree68e61527726508d3feba1edc38febe32ab568182
parentc8dd5dc5b3c11bf1822c960a8ad1e7260957b3f9 (diff)
Garbage collect on function exit
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected12
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected30
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected30
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected30
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected30
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected30
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected30
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected9
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenFieldLoadTests]/[method:canGenerateCodeForNamespaceFieldLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected4
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceFieldStoreTests]/[method:canGenerateCodeForNamespaceFieldStore(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected4
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected32
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected21
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected21
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java12
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java35
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java68
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java88
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java1
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java3
20 files changed, 457 insertions, 36 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 4591b5f8..844a8520 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineEffectTests]/[method:canGenerateCodeForDefineEffect(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -3,6 +3,12 @@ Compilation unit elements:
(exception-type "shed__effect__exception__Example_Project__State" int)
(
function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
"shed__runtime__effects_find_handler_method"
params=((param "effectTag" int) (param "methodIndex" int))
return-type=int
@@ -11,9 +17,10 @@ Compilation unit elements:
function
"shed__function__read__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (param "local__fence" int) (val "effectHandlerMethod__0" int) (val "tmp__0" int) (val "closurePointer__1" data-ptr) (val "callFunctionPointer__0" function-ptr))
+ locals=((param "closurePointer__0" data-ptr) (param "local__fence" int) (val "gcRootStackIndex__0" int) (val "effectHandlerMethod__0" int) (val "tmp__0" int) (val "closurePointer__1" data-ptr) (val "callFunctionPointer__0" function-ptr))
return-type=int
body=(
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(call (local "effectHandlerMethod__0") "shed__runtime__effects_find_handler_method" ((int 0) (int 0)))
(int-to-data-ptr (local "closurePointer__1") (local "effectHandlerMethod__0"))
(
@@ -31,9 +38,10 @@ Compilation unit elements:
function
"shed__function__write__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (param "local__arg0" int) (val "effectHandlerMethod__0" int) (val "tmp__0" int) (val "closurePointer__1" data-ptr) (val "callFunctionPointer__0" function-ptr))
+ locals=((param "closurePointer__0" data-ptr) (param "local__arg0" int) (val "gcRootStackIndex__0" int) (val "effectHandlerMethod__0" int) (val "tmp__0" int) (val "closurePointer__1" data-ptr) (val "callFunctionPointer__0" function-ptr))
return-type=int
body=(
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(call (local "effectHandlerMethod__0") "shed__runtime__effects_find_handler_method" ((int 0) (int 1)))
(int-to-data-ptr (local "closurePointer__1") (local "effectHandlerMethod__0"))
(
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index c6d0cf8a..2d07d2bb 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canCaptureFreeVariablesThatAreSetAfterDefinition(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,10 +1,34 @@
Compilation unit elements:
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
+(
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (val "local__a" int) (val "local__b" int))
+ locals=((param "closurePointer__0" data-ptr) (val "local__a" int) (val "local__b" int) (val "gcRootStackIndex__0" int))
return-type=int
body=(
(
@@ -21,6 +45,10 @@ Compilation unit elements:
layout=(struct ((struct (data-ptr int int int)) (struct (function-ptr (struct ()) (struct (int int))))))
offset=(1 2 1)
)
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "local__a")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "local__a"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 65d67506..01828098 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:canDefineMinimalFunction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,13 +1,41 @@
Compilation unit elements:
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
+(
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (val "tmp__0" int))
+ locals=((param "closurePointer__0" data-ptr) (val "gcRootStackIndex__0" int) (val "tmp__0" int))
return-type=int
body=(
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(local-store (local "tmp__0") (int 0))
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "tmp__0")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "tmp__0"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index f764af61..040ae764 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -13,12 +13,37 @@ Compilation unit elements:
return-type=void
)
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
+(
function
"shed__effectHandlerMethod__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (val "effectHandler__0" data-ptr) (val "effectHandler__1" data-ptr) (val "tmp__0" int))
+ locals=((param "closurePointer__0" data-ptr) (val "gcRootStackIndex__0" int) (val "effectHandler__0" data-ptr) (val "effectHandler__1" data-ptr) (val "tmp__0" int))
return-type=int
body=(
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(call (local "effectHandler__0") "shed__runtime__effects_get_handler" ())
(
memory-load
@@ -29,6 +54,9 @@ Compilation unit elements:
)
(call _ "shed__runtime__effects_set_handler" ((local "effectHandler__1")))
(local-store (local "tmp__0") (int 0))
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "tmp__0")))
+ (call _ "shed__runtime__gc_collect" ())
(call _ "shed__runtime__effects_set_handler" ((local "effectHandler__0")))
(resume (local "tmp__0"))
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index a528eb05..35b32735 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:immutableFreeVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,10 +1,34 @@
Compilation unit elements:
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
+(
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (val "local__a" int) (val "local__b" int))
+ locals=((param "closurePointer__0" data-ptr) (val "local__a" int) (val "local__b" int) (val "gcRootStackIndex__0" int))
return-type=int
body=(
(
@@ -21,6 +45,10 @@ Compilation unit elements:
layout=(struct ((struct (data-ptr int int int)) (struct (function-ptr (struct ()) (struct (int int))))))
offset=(1 2 1)
)
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "local__a")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "local__a"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 70ee5036..8f0b9f0f 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,10 +1,34 @@
Compilation unit elements:
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
+(
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (val "local__a" data-ptr) (val "local__b" data-ptr))
+ locals=((param "closurePointer__0" data-ptr) (val "local__a" data-ptr) (val "local__b" data-ptr) (val "gcRootStackIndex__0" int))
return-type=int
body=(
(
@@ -21,6 +45,10 @@ Compilation unit elements:
layout=(struct ((struct (data-ptr int int int)) (struct (function-ptr (struct ()) (struct (data-ptr data-ptr))))))
offset=(1 2 1)
)
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "local__a")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "local__a"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index bda47107..ba98ae45 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:positionalAndNamedParamsAreDefined(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -2,15 +2,39 @@ Compilation unit elements:
(
function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
+ function-decl
"shed__runtime__int_add"
params=((param "left" int) (param "right" int))
return-type=int
)
(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
+(
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (param "local__param1" int) (param "local__param2" int) (param "local__paramA" int) (param "local__paramB" int) (param "local__paramC" int) (val "local__a" int) (val "local__b" int) (val "binaryOpResult__0" int) (val "binaryOpResult__1" int))
+ locals=((param "closurePointer__0" data-ptr) (param "local__param1" int) (param "local__param2" int) (param "local__paramA" int) (param "local__paramB" int) (param "local__paramC" int) (val "local__a" int) (val "local__b" int) (val "gcRootStackIndex__0" int) (val "binaryOpResult__0" int) (val "binaryOpResult__1" int))
return-type=int
body=(
(
@@ -27,8 +51,12 @@ Compilation unit elements:
layout=(struct ((struct (data-ptr int int int)) (struct (function-ptr (struct ()) (struct (int int))))))
offset=(1 2 1)
)
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(call (local "binaryOpResult__0") "shed__runtime__int_add" ((local "local__a") (local "local__param1")))
(call (local "binaryOpResult__1") "shed__runtime__int_add" ((local "binaryOpResult__0") (local "local__paramA")))
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "binaryOpResult__1")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "binaryOpResult__1"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 5c789ad6..84129f10 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineStructTests]/[method:canGenerateCodeForDefineStruct(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,12 +1,19 @@
Compilation unit elements:
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+)
+(
function
"shed__function__User__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (param "local__isActive" int) (param "local__name" int) (val "structValuePointer__0" data-ptr) (val "structValue__0" int))
+ locals=((param "closurePointer__0" data-ptr) (param "local__isActive" int) (param "local__name" int) (val "gcRootStackIndex__0" int) (val "structValuePointer__0" data-ptr) (val "structValue__0" int))
return-type=int
body=(
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(alloc-heap (local "structValuePointer__0") (struct ((struct (data-ptr int int int)) (struct (int (struct (int int)))))))
(
memory-store
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenFieldLoadTests]/[method:canGenerateCodeForNamespaceFieldLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenFieldLoadTests]/[method:canGenerateCodeForNamespaceFieldLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 3e1630bf..db8a3491 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenFieldLoadTests]/[method:canGenerateCodeForNamespaceFieldLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenFieldLoadTests]/[method:canGenerateCodeForNamespaceFieldLoad(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -13,8 +13,8 @@ Instructions:
memory-load
(local "tmp__y__0")
pointer=(local "namespacePointer__Example_Project__0")
- layout=(struct (int int int))
- offset=(1)
+ layout=(struct ((struct (int int int int)) (struct (int int int))))
+ offset=(1 1)
)
)
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 2408d323..affb898f 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
@@ -15,8 +15,8 @@ Instructions:
(
memory-store
pointer=(data-ptr "shed__namespace__Example_Project")
- layout=(struct (int int int))
- offset=(1)
+ layout=(struct ((struct (int int int int)) (struct (int int int))))
+ offset=(1 1)
value=(local "b")
)
(call _ "shed__runtime__gc_add_perm_root" ((local "b")))
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index 54b131be..f886961d 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenNamespaceTests]/[method:canDefineNamespace(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,14 +1,42 @@
(
- (data-mutable "shed__namespace__An_Example" (struct ((int 0) (int 0))))
+ (data-mutable "shed__namespace__An_Example" (struct ((struct ((int 0) (int 6) (int 0) (int 0))) (struct ((int 0) (int 0))))))
(data-mutable "shed__namespaceIsInited__An_Example" (bool false))
(
+ function-decl
+ "shed__runtime__gc_get_root_stack_index"
+ params=()
+ return-type=int
+ )
+ (
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+ )
+ (
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+ )
+ (
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+ )
+ (
function
"shed__function__f__0"
visibility=private
- locals=((param "closurePointer__0" data-ptr) (val "tmp__0" int))
+ locals=((param "closurePointer__0" data-ptr) (val "gcRootStackIndex__0" int) (val "tmp__0" int))
return-type=int
body=(
+ (call (local "gcRootStackIndex__0") "shed__runtime__gc_get_root_stack_index" ())
(local-store (local "tmp__0") (int 0))
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gcRootStackIndex__0")))
+ (call _ "shed__runtime__gc_push_root" ((local "tmp__0")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "tmp__0"))
)
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index cc3c3c45..de8cd9a9 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenResumeTests]/[method:resumeInstructionGeneratesResumeInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,11 +1,32 @@
Compilation unit elements:
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
Locals:
Instructions:
(
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gc_root_stack_index")))
+ (call _ "shed__runtime__gc_push_root" ((local "b")))
+ (call _ "shed__runtime__gc_collect" ())
(call _ "shed__runtime__effects_set_handler" ((local "effect_handler")))
(resume (local "b"))
)
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
index f7d7a17e..6f20081e 100644
--- a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenReturnTests]/[method:returnInstructionGeneratesReturnInstruction(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -1,11 +1,32 @@
Compilation unit elements:
+(
+ function-decl
+ "shed__runtime__gc_set_root_stack_index"
+ params=((param "gc_root_stack_index" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_push_root"
+ params=((param "gc_root" int))
+ return-type=void
+)
+(
+ function-decl
+ "shed__runtime__gc_collect"
+ params=()
+ return-type=void
+)
Locals:
Instructions:
(
+ (call _ "shed__runtime__gc_set_root_stack_index" ((local "gc_root_stack_index")))
+ (call _ "shed__runtime__gc_push_root" ((local "b")))
+ (call _ "shed__runtime__gc_collect" ())
(return (local "b"))
)
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index 81fa758d..6a18af6b 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -601,6 +601,12 @@ public class PatioCodeGen {
var value = valueResult.value();
context = valueResult.context();
+ context = PatioCodeGenClosures.beforeExit(
+ List.of(value),
+ resume.source(),
+ context
+ );
+
yield PatioCodeGenEffects.resume(value, resume.source(), context);
}
@@ -609,6 +615,12 @@ public class PatioCodeGen {
var value = valueResult.value();
context = valueResult.context();
+ context = PatioCodeGenClosures.beforeExit(
+ List.of(value),
+ return_.source(),
+ context
+ );
+
yield context.addInstruction(new PatioReturn(value, return_.source()));
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
index bc1cd8c1..c42b1be8 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -124,6 +124,21 @@ class PatioCodeGenClosures {
bodyContextParent
);
+ var gcRootStackIndexResult = bodyContext.allocateVal(
+ PatioCodeGenLocalSpace.GC_ROOT_STACK_INDEX,
+ PatioCodeGenGc.GC_ROOT_STACK_INDEX_TYPE
+ );
+ var gcRootStackIndex = gcRootStackIndexResult.value();
+ bodyContext = gcRootStackIndexResult.context();
+
+ bodyContext = PatioCodeGenGc.getGcRootStackIndex(
+ gcRootStackIndex,
+ source,
+ bodyContext
+ );
+
+ bodyContext = bodyContext.stashGcRootStackIndex(gcRootStackIndex);
+
bodyContext = generateBody.apply(closurePointer, bodyContext);
return bodyContext;
@@ -248,6 +263,26 @@ class PatioCodeGenClosures {
return bodyContext;
}
+ static PatioCodeGenContext beforeExit(
+ List<PatioOperand> escapees,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ context = PatioCodeGenGc.setGcRootStackIndex(
+ context.stashedGcRootStackIndex(),
+ source,
+ context
+ );
+
+ for (var escapee : escapees) {
+ context = PatioCodeGenGc.pushGcRoot(escapee, source, context);
+ }
+
+ context = PatioCodeGenGc.collect(source, context);
+
+ return context;
+ }
+
static PatioCodeGenContext call(
PatioLocalRef target,
PatioLocalRef closure,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
index 6083cf75..87d5901a 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenContext.java
@@ -187,7 +187,8 @@ public record PatioCodeGenContext(
OrderedPMap<String, PatioLocal> localsByName,
PMap<String, PatioLocalRef> shidNameToLocal,
PMap<String, PVector<Function<PatioCodeGenContext, PatioCodeGenContext>>> waitingForShidLocal,
- Optional<PatioOperand> stashedEffectHandler
+ Optional<PatioOperand> stashedEffectHandler,
+ Optional<PatioOperand> stashedGcRootStackIndex
) {
public static final FunctionContext EMPTY = new FunctionContext(
P.stack(),
@@ -195,6 +196,7 @@ public record PatioCodeGenContext(
OrderedPMap.empty(),
P.map(),
P.map(),
+ Optional.empty(),
Optional.empty()
);
@@ -206,7 +208,8 @@ public record PatioCodeGenContext(
this.localsByName,
this.shidNameToLocal,
this.waitingForShidLocal,
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
).toResult(this.temporaryStack.get(0));
}
@@ -218,7 +221,8 @@ public record PatioCodeGenContext(
this.localsByName,
this.shidNameToLocal,
this.waitingForShidLocal,
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
).toResult(this.temporaryStack);
}
@@ -230,7 +234,8 @@ public record PatioCodeGenContext(
this.localsByName,
this.shidNameToLocal,
this.waitingForShidLocal,
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
);
}
@@ -242,7 +247,8 @@ public record PatioCodeGenContext(
this.localsByName,
this.shidNameToLocal,
this.waitingForShidLocal,
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
);
}
@@ -264,7 +270,8 @@ public record PatioCodeGenContext(
this.localsByName.plus(fullName, createLocal.apply(fullName)),
this.shidNameToLocal,
this.waitingForShidLocal,
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
).toResult(new PatioLocalRef(fullName));
}
@@ -299,7 +306,8 @@ public record PatioCodeGenContext(
// TODO: the mapping is redundant given we fix the mapping
this.shidNameToLocal.plus(name, localRef),
this.waitingForShidLocal.plus(name, P.vector()),
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
);
return context.toResult(localRef);
@@ -313,7 +321,8 @@ public record PatioCodeGenContext(
this.localsByName,
this.shidNameToLocal,
this.waitingForShidLocal.minus(name),
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
);
return context.toResult(this.waitingForShidLocal.getOrDefault(name, P.vector()));
@@ -363,7 +372,8 @@ public record PatioCodeGenContext(
name,
this.waitingForShidLocal.getOrDefault(name, P.vector()).plus(func)
),
- this.stashedEffectHandler
+ this.stashedEffectHandler,
+ this.stashedGcRootStackIndex
);
}
@@ -376,7 +386,8 @@ public record PatioCodeGenContext(
this.shidNameToLocal,
this.waitingForShidLocal,
// TODO: check current value is empty
- Optional.of(effectHandler)
+ Optional.of(effectHandler),
+ this.stashedGcRootStackIndex
);
}
@@ -387,6 +398,27 @@ public record PatioCodeGenContext(
.orElseThrow(() -> new RuntimeException("No stashed effect handler"));
}
+ @CheckReturnValue
+ public FunctionContext stashGcRootStackIndex(PatioOperand gcRootStackIndex) {
+ return new FunctionContext(
+ this.temporaryStack,
+ this.instructions,
+ this.localsByName,
+ this.shidNameToLocal,
+ this.waitingForShidLocal,
+ this.stashedEffectHandler,
+ // TODO: check current value is empty
+ Optional.of(gcRootStackIndex)
+ );
+ }
+
+ @CheckReturnValue
+ public PatioOperand stashedGcRootStackIndexOrThrow() {
+ // TODO: better error
+ return this.stashedGcRootStackIndex
+ .orElseThrow(() -> new RuntimeException("No stashed GC root stack index"));
+ }
+
private <T> Result<T> toResult(T value) {
return new Result<>(value, this);
}
@@ -691,7 +723,8 @@ public record PatioCodeGenContext(
this.functionContext.localsByName,
this.functionContext.shidNameToLocal,
this.functionContext.waitingForShidLocal,
- this.functionContext.stashedEffectHandler
+ this.functionContext.stashedEffectHandler,
+ this.functionContext.stashedGcRootStackIndex
)
);
}
@@ -712,7 +745,8 @@ public record PatioCodeGenContext(
this.functionContext.localsByName,
this.functionContext.shidNameToLocal,
this.functionContext.waitingForShidLocal,
- this.functionContext.stashedEffectHandler
+ this.functionContext.stashedEffectHandler,
+ this.functionContext.stashedGcRootStackIndex
)
).toResult(this.functionContext.instructions);
}
@@ -734,6 +768,16 @@ public record PatioCodeGenContext(
}
@CheckReturnValue
+ public PatioCodeGenContext stashGcRootStackIndex(PatioOperand gcRootStackIndex) {
+ return withFunctionContext(this.functionContext.stashGcRootStackIndex(gcRootStackIndex));
+ }
+
+ @CheckReturnValue
+ public PatioOperand stashedGcRootStackIndex() {
+ return this.functionContext.stashedGcRootStackIndexOrThrow();
+ }
+
+ @CheckReturnValue
private PatioCodeGenContext withCompilationUnitContext(CompilationUnitContext compilationUnitContext) {
return new PatioCodeGenContext(this.globalContext, compilationUnitContext, this.blockStack, this.functionContext);
}
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
index 23ee6cac..8d9c3ccd 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenGc.java
@@ -15,13 +15,6 @@ 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() {
}
@@ -59,6 +52,87 @@ public class PatioCodeGenGc {
));
}
+ // == Roots ==
+
+ // == Root stack ==
+
+ public static final PatioType GC_ROOT_STACK_INDEX_TYPE = PatioTypes.INT;
+
+ private static final PatioFunctionDeclaration GET_GC_ROOT_STACK_INDEX = new PatioFunctionDeclaration(
+ "shed__runtime__gc_get_root_stack_index",
+ List.of(),
+ GC_ROOT_STACK_INDEX_TYPE,
+ Sources.RUNTIME
+ );
+
+ public static PatioCodeGenContext getGcRootStackIndex(
+ PatioLocalRef target,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(GET_GC_ROOT_STACK_INDEX)
+ .addInstruction(new PatioCall(
+ Optional.of(target),
+ GET_GC_ROOT_STACK_INDEX.name(),
+ List.of(),
+ source
+ ));
+ }
+
+ private static final PatioFunctionDeclaration SET_GC_ROOT_STACK_INDEX = new PatioFunctionDeclaration(
+ "shed__runtime__gc_set_root_stack_index",
+ List.of(PatioLocal.param("gc_root_stack_index", GC_ROOT_STACK_INDEX_TYPE)),
+ PatioTypes.VOID,
+ Sources.RUNTIME
+ );
+
+ public static PatioCodeGenContext setGcRootStackIndex(
+ PatioOperand gcRootIndex,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(SET_GC_ROOT_STACK_INDEX)
+ .addInstruction(new PatioCall(
+ Optional.empty(),
+ SET_GC_ROOT_STACK_INDEX.name(),
+ List.of(gcRootIndex),
+ source
+ ));
+ }
+
+ private static final PatioFunctionDeclaration PUSH_GC_ROOT = new PatioFunctionDeclaration(
+ "shed__runtime__gc_push_root",
+ List.of(PatioLocal.param("gc_root", PatioCodeGenTypes.VALUE_TYPE)),
+ PatioTypes.VOID,
+ Sources.RUNTIME
+ );
+
+ public static PatioCodeGenContext pushGcRoot(
+ PatioOperand escapee,
+ Source source,
+ PatioCodeGenContext context
+ ) {
+ return context
+ .ensureCompilationUnitElement(PUSH_GC_ROOT)
+ .addInstruction(new PatioCall(
+ Optional.empty(),
+ PUSH_GC_ROOT.name(),
+ List.of(escapee),
+ source
+ ));
+ }
+
+ // == Perm roots ==
+
+ 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
+ );
+
public static PatioCodeGenContext addPermGcRoot(
PatioOperand gcRoot,
Source source,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
index fcaa54ea..54337eb4 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenLocalSpace.java
@@ -12,6 +12,7 @@ public enum PatioCodeGenLocalSpace {
EFFECT_HANDLER_CURRENT("effectHandlerCurrent"),
EFFECT_HANDLER_METHOD("effectHandlerMethod"),
EFFECT_HANDLER_METHOD_POINTER("effectHandlerMethodPointer"),
+ GC_ROOT_STACK_INDEX("gcRootStackIndex"),
INT("int"),
MAIN("main"),
NAMESPACE_IS_INITED_POINTER("namespaceIsInitedPointer"),
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java
index b0a97f31..6ac0e4f7 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java
@@ -19,7 +19,8 @@ public class PatioCodeGenResumeTests {
var context = PatioCodeGenContext.EMPTY
.temporaryPush(new PatioLocalRef("a"))
.temporaryPush(new PatioLocalRef("b"))
- .stashEffectHandler(new PatioLocalRef("effect_handler"));
+ .stashEffectHandler(new PatioLocalRef("effect_handler"))
+ .stashGcRootStackIndex(new PatioLocalRef("gc_root_stack_index"));
var result = PatioCodeGen.generateInstruction(shid, context);
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java
index 9a7166c5..f2bf807e 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java
@@ -18,7 +18,8 @@ public class PatioCodeGenReturnTests {
var shid = Shid.return_();
var context = PatioCodeGenContext.EMPTY
.temporaryPush(new PatioLocalRef("a"))
- .temporaryPush(new PatioLocalRef("b"));
+ .temporaryPush(new PatioLocalRef("b"))
+ .stashGcRootStackIndex(new PatioLocalRef("gc_root_stack_index"));;
var result = PatioCodeGen.generateInstruction(shid, context);