diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-20 22:50:04 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-20 22:50:04 +0000 |
| commit | 7b19c504459e2368ceb42540691abf664db935c6 (patch) | |
| tree | 73819aabaea50411e3f31ae6eb448b2c0bd77667 /src/test/java | |
| parent | 86f7fa2960fe0eaa49f0cebdedd8cc04f31ebd76 (diff) | |
Support capture of vars in effect handler methods
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java index eeb17968..696876b9 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java @@ -3,6 +3,7 @@ package org.shedlang.compiler.patio; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.shedlang.compiler.ast.typed.FreeVariables; +import org.shedlang.compiler.patio.ast.types.PatioTypes; import org.shedlang.compiler.patio.instructions.Patio; import org.shedlang.compiler.sources.Sources; import org.shedlang.compiler.stackir.instructions.DefineFunctionInstruction; @@ -91,6 +92,33 @@ public class PatioCodeGenDefineFunctionTests { } @Test + public void pointersToFreeMutableVariablesAreStoredInAndLoadedFromEnvironment(Snapshotter snapshotter) throws IOException { + var instruction = new DefineFunctionInstruction( + "f", + List.of(), + List.of(), + FreeVariables.builder() + .plus("a", Sources.NULL) + .plus("b", Sources.NULL) + .build(), + List.of( + Instructions.localLoad("a"), + Instructions.return_() + ), + Sources.NULL + ); + var context = PatioCodeGenContext.EMPTY + .declareStackIrVal("a", PatioTypes.DATA_POINTER).context() + .initStackIrLocal("a") + .declareStackIrVal("b", PatioTypes.DATA_POINTER).context() + .initStackIrLocal("b"); + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } + + @Test public void positionalAndNamedParamsAreDefined(Snapshotter snapshotter) throws IOException { var instruction = new DefineFunctionInstruction( "f", |
