aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-21 13:48:48 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-21 13:49:17 +0100
commit07eeb10e60c198be0e744881189daae810f9c603 (patch)
tree5d30c12db8fbb03c8ec665fcdf4f250f3367dae4 /src/test/java
parent4767848c0272da0468df8ff66c88daa39018de5e (diff)
Add Patio code gen for namespace-field-store
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java
new file mode 100644
index 00000000..7eb1b252
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java
@@ -0,0 +1,41 @@
+package org.shedlang.compiler.patio;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
+import org.shedlang.compiler.stackir.instructions.Instructions;
+import org.shedlang.compiler.testing.snapshots.SnapshotResolver;
+import org.shedlang.compiler.testing.snapshots.Snapshotter;
+import org.shedlang.compiler.typechecker.TypeCheckerContext;
+import org.shedlang.compiler.types.NamespaceName;
+import org.shedlang.compiler.types.Types;
+import org.shedlang.compiler.util.P;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import static org.shedlang.compiler.patio.PatioTesting.serialize;
+
+@ExtendWith({SnapshotResolver.class})
+public class PatioCodeGenNamespaceFieldStoreTests {
+ @Test
+ public void canGenerateCodeForNamespaceFieldStore(Snapshotter snapshotter) throws IOException {
+ var namespaceName = new NamespaceName(List.of("Example", "Project"));
+ var stackIrInstruction = Instructions.namespaceFieldStore(namespaceName, "y");
+ var typeInfo = TypeCheckerContext.EMPTY
+ .addNamespaceFields(namespaceName, P.orderedMap(
+ Map.entry("x", Types.INT),
+ Map.entry("y", Types.INT),
+ Map.entry("z", Types.INT)
+ ))
+ .toTypeInfo();
+ var context = PatioCodeGenContext.forTypeInfo(typeInfo)
+ .temporaryPush(new PatioLocalRef("a"))
+ .temporaryPush(new PatioLocalRef("b"));
+
+ var result = PatioCodeGen.generateInstruction(stackIrInstruction, context);
+
+ snapshotter.assertSnapshot(serialize(result));
+ }
+}