aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 12:45:08 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 12:46:37 +0000
commita22fbc506d196a01d8ecbadba8f9708b6fbb6d4f (patch)
tree87c211c50b3641e7b28a9181b754564c494be365
parent415533b5b57c2737595ec3ad74ef84a607ab4570 (diff)
Store additional data before storing free variables
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenDefineFunctionTests]/[method:effectHandlerMethodSwapsEffectHandlerInBody(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java4
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java32
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenFunctions.java1
4 files changed, 24 insertions, 17 deletions
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 f248c1db..a421098a 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
@@ -36,12 +36,13 @@ Compilation unit elements:
Locals:
* (val "closure__f__0" int)
- * (val "closurePointer__f__0" data-ptr)
* (val "effectHandlerCurrent__0" data-ptr)
+ * (val "closurePointer__f__0" data-ptr)
Instructions:
(
+ (call (local "effectHandlerCurrent__0") "shed__runtime__effects_get_handler" ())
(alloc-heap (local "closurePointer__f__0") (struct (function-ptr (struct (data-ptr)) (struct ()))))
(
memory-store
@@ -50,7 +51,6 @@ Instructions:
offset=(0)
value=(function-ptr "shed__effectHandlerMethod__f__0")
)
- (call (local "effectHandlerCurrent__0") "shed__runtime__effects_get_handler" ())
(
memory-store
pointer=(local "closurePointer__f__0")
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
index 6631d66c..9f5bfdaf 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java
@@ -18,6 +18,7 @@ import org.shedlang.compiler.util.P;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.function.BiFunction;
import java.util.stream.Stream;
import static org.shedlang.compiler.util.Iterables.sortedBy;
@@ -85,6 +86,7 @@ class PatioCodeGenClosures {
String name,
String functionName,
PatioDataLayout layout,
+ BiFunction<PatioLocalRef, PatioCodeGenContext, PatioCodeGenContext> storeAdditional,
FreeVariables freeVariables,
Source source,
PatioCodeGenContext context
@@ -107,6 +109,8 @@ class PatioCodeGenClosures {
source
));
+ context = storeAdditional.apply(closurePointer, context);
+
context = storeFreeVariables(
freeVariables,
closurePointer,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
index 8ce61a8c..28e1ec0f 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java
@@ -427,10 +427,27 @@ public class PatioCodeGenEffects {
return bodyContext;
});
+ var effectHandlerResult = context.allocateVal(
+ PatioCodeGenLocalSpace.EFFECT_HANDLER_CURRENT,
+ EFFECT_HANDLER_TYPE
+ );
+ var effectHandler = effectHandlerResult.value();
+ context = effectHandlerResult.context();
+
+ context = getCurrentEffectHandler(effectHandler, source, context);
+
var closurePointerResult = PatioCodeGenClosures.alloc(
name,
fullName,
layout,
+ (closurePointer, allocContext) ->
+ allocContext.addInstruction(new PatioMemoryStore(
+ closurePointer,
+ layout,
+ CLOSURE_EFFECT_HANDLER_OFFSET,
+ effectHandler,
+ source
+ )),
freeVariables,
source,
context
@@ -438,22 +455,7 @@ public class PatioCodeGenEffects {
var closurePointer = closurePointerResult.value();
context = closurePointerResult.context();
- var effectHandlerResult = context.allocateVal(
- PatioCodeGenLocalSpace.EFFECT_HANDLER_CURRENT,
- EFFECT_HANDLER_TYPE
- );
- var effectHandler = effectHandlerResult.value();
- context = effectHandlerResult.context();
- context = getCurrentEffectHandler(effectHandler, source, context);
-
- context = context.addInstruction(new PatioMemoryStore(
- closurePointer,
- layout,
- CLOSURE_EFFECT_HANDLER_OFFSET,
- effectHandler,
- source
- ));
context = context.addInstruction(new PatioDataPtrToInt(
target,
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenFunctions.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenFunctions.java
index 0e8bff4a..ffa58156 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenFunctions.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenFunctions.java
@@ -77,6 +77,7 @@ public class PatioCodeGenFunctions {
name,
fullName,
layout,
+ (closurePointer, allocContext) -> allocContext,
freeVariables,
source,
context