From 07eeb10e60c198be0e744881189daae810f9c603 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 21 Jul 2023 13:48:48 +0100 Subject: Add Patio code gen for namespace-field-store --- .../PatioCodeGenNamespaceFieldStoreTests.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceFieldStoreTests.java (limited to 'src/test/java') 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)); + } +} -- cgit v1.2.3