From 1397d18e897e98ede05e8bbc7b394c0469fb887a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 22 Dec 2024 11:05:15 +0000 Subject: Implement Patio codegen for method store and load --- .../compiler/backends/llvm/Amd64ExampleTests.java | 1 - .../compiler/backends/llvm/I686ExampleTests.java | 1 - .../compiler/backends/wasm/Wasm32ExampleTests.java | 1 - .../compiler/backends/wasm/Wasm64ExampleTests.java | 1 - .../shidtopatio/ShidToPatioMethodLoadTests.java | 32 +++++++++++++++++++++ .../shidtopatio/ShidToPatioMethodStoreTests.java | 33 ++++++++++++++++++++++ 6 files changed, 65 insertions(+), 4 deletions(-) create mode 100644 src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java create mode 100644 src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java index bd754c3f..2fbe9f4b 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/Amd64ExampleTests.java @@ -23,7 +23,6 @@ public class Amd64ExampleTests extends ExampleTests { } private static final Set DISABLED = Set.of( - "35-struct-methods" ); @Override diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java index 9de1ff27..07240512 100644 --- a/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/llvm/I686ExampleTests.java @@ -23,7 +23,6 @@ public class I686ExampleTests extends ExampleTests { } private static final Set DISABLED = Set.of( - "35-struct-methods" ); @Override diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java index 1e56b989..7b0ab151 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java @@ -23,7 +23,6 @@ public class Wasm32ExampleTests extends ExampleTests { } private static final Set DISABLED = Set.of( - "35-struct-methods" ); @Override diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java index 972da7b7..71d5f17b 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java @@ -23,7 +23,6 @@ public class Wasm64ExampleTests extends ExampleTests { } private static final Set DISABLED = Set.of( - "35-struct-methods" ); @Override diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java new file mode 100644 index 00000000..6fc4abc2 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java @@ -0,0 +1,32 @@ +package org.shedlang.compiler.shidtopatio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.shid.instructions.Shid; +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 java.io.IOException; + +import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class ShidToPatioMethodLoadTests { + @Test + public void canGenerateCodeForMethodLoad(Snapshotter snapshotter) throws IOException { + var namespaceName = NamespaceName.of("Example", "Project"); + var structType = Types.struct(namespaceName, "User"); + var shidInstruction = Shid.methodLoad(structType, "name"); + var typeInfo = TypeCheckerContext.EMPTY.toTypeInfos(); + var context = ShidToPatioContext.forTypeInfos(typeInfo) + .temporaryPush(new PatioLocalRef("a")); + + var result = ShidToPatio.generateInstruction(shidInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java new file mode 100644 index 00000000..447a925a --- /dev/null +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java @@ -0,0 +1,33 @@ +package org.shedlang.compiler.shidtopatio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.patio.operands.PatioLocalRef; +import org.shedlang.compiler.shid.instructions.Shid; +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 java.io.IOException; + +import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class ShidToPatioMethodStoreTests { + @Test + public void canGenerateCodeForMethodStore(Snapshotter snapshotter) throws IOException { + var namespaceName = NamespaceName.of("Example", "Project"); + var structType = Types.struct(namespaceName, "User"); + var shidInstruction = Shid.methodStore(structType, "name"); + var typeInfo = TypeCheckerContext.EMPTY.toTypeInfos(); + var context = ShidToPatioContext.forTypeInfos(typeInfo) + .temporaryPush(new PatioLocalRef("a")) + .temporaryPush(new PatioLocalRef("b")); + + var result = ShidToPatio.generateInstruction(shidInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} -- cgit v1.2.3