From 4767848c0272da0468df8ff66c88daa39018de5e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 21 Jul 2023 13:42:34 +0100 Subject: Add Patio code gen for field loads --- .../compiler/patio/PatioCodeGenFieldLoadTests.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java new file mode 100644 index 00000000..f4bb5152 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.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 PatioCodeGenFieldLoadTests { + @Test + public void canGenerateCodeForFieldLoad(Snapshotter snapshotter) throws IOException { + var namespaceName = new NamespaceName(List.of("Example", "Project")); + var stackIrInstruction = Instructions.fieldLoad(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