diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-03-08 13:39:40 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-03-08 13:39:40 +0000 |
| commit | 8cfdfc92fcf41f5db6d30015b20457ca64f0c3ce (patch) | |
| tree | 7dfd0d403b6b8add040eb1e09515194ca6b26065 /src/test/java | |
| parent | 2462a913d149fe896134519d95d65c3adfa30e47 (diff) | |
Support method calls from other namespaces (without Wasm support)
Diffstat (limited to 'src/test/java')
12 files changed, 43 insertions, 15 deletions
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 7b0ab151..f1dbee2c 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm32ExampleTests.java @@ -23,6 +23,7 @@ public class Wasm32ExampleTests extends ExampleTests { } private static final Set<String> DISABLED = Set.of( + "40-imported-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 71d5f17b..0a4cfd7b 100644 --- a/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java +++ b/src/test/java/org/shedlang/compiler/backends/wasm/Wasm64ExampleTests.java @@ -23,6 +23,7 @@ public class Wasm64ExampleTests extends ExampleTests { } private static final Set<String> DISABLED = Set.of( + "40-imported-struct-methods" ); @Override diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineEffectTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineEffectTests.java index 686f708c..f3ca07a0 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineEffectTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineEffectTests.java @@ -38,7 +38,7 @@ public class ShidToPatioDefineEffectTests { ) .build() ); - var context = ShidToPatioContext.forTypeInfos(typeInfos); + var context = ShidToPatioTesting.createContext(typeInfos); var result = ShidToPatio.generateInstruction(instruction, context); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineStructTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineStructTests.java index b363cbb8..cb9268fb 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineStructTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioDefineStructTests.java @@ -38,7 +38,7 @@ public class ShidToPatioDefineStructTests { .withFieldsArePositional(false) .build() ); - var context = ShidToPatioContext.forTypeInfos(typeInfos); + var context = ShidToPatioTesting.createContext(typeInfos); var result = ShidToPatio.generateInstruction(instruction, context); @@ -64,7 +64,7 @@ public class ShidToPatioDefineStructTests { .withFieldsArePositional(true) .build() ); - var context = ShidToPatioContext.forTypeInfos(typeInfos); + var context = ShidToPatioTesting.createContext(typeInfos); var result = ShidToPatio.generateInstruction(instruction, context); @@ -83,7 +83,7 @@ public class ShidToPatioDefineStructTests { var typeInfos = TypeInfos.EMPTY .addStructTypeInfo(structType1, StructTypeInfo.builder().build()) .addStructTypeInfo(structType2, StructTypeInfo.builder().build()); - var context = ShidToPatioContext.forTypeInfos(typeInfos); + var context = ShidToPatioTesting.createContext(typeInfos); context = ShidToPatio.generateInstruction(instruction1, context); context = ShidToPatio.generateInstruction(instruction2, context); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioFieldLoadTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioFieldLoadTests.java index 3f5fd284..10644e07 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioFieldLoadTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioFieldLoadTests.java @@ -31,7 +31,7 @@ public class ShidToPatioFieldLoadTests { .build() ) .toTypeInfos(); - var context = ShidToPatioContext.forTypeInfos(typeInfos) + var context = ShidToPatioTesting.createContext(typeInfos) .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); @@ -54,7 +54,7 @@ public class ShidToPatioFieldLoadTests { .addField("isActive", Types.BOOL) .build() ); - var context = ShidToPatioContext.forTypeInfos(typeInfos) + var context = ShidToPatioTesting.createContext(typeInfos) .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); @@ -77,7 +77,7 @@ public class ShidToPatioFieldLoadTests { .addMethod("read", FunctionType.builder().build()) .build() ); - var context = ShidToPatioContext.forTypeInfos(typeInfos) + var context = ShidToPatioTesting.createContext(typeInfos) .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java index 6fc4abc2..f7d24389 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodLoadTests.java @@ -11,18 +11,36 @@ import org.shedlang.compiler.types.NamespaceName; import org.shedlang.compiler.types.Types; import java.io.IOException; +import java.util.Optional; import static org.shedlang.compiler.shidtopatio.ShidToPatioTesting.serialize; @ExtendWith({SnapshotResolver.class}) public class ShidToPatioMethodLoadTests { @Test - public void canGenerateCodeForMethodLoad(Snapshotter snapshotter) throws IOException { + public void canGenerateCodeForMethodLoadInSameNamespace(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) + var globalContext = ShidToPatioContext.GlobalContext.forTypeInfos(typeInfo); + var context = ShidToPatioContext.initialForCompilationUnit(Optional.of(namespaceName), globalContext) + .temporaryPush(new PatioLocalRef("a")); + + var result = ShidToPatio.generateInstruction(shidInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } + + @Test + public void canGenerateCodeForMethodLoadInDifferentNamespace(Snapshotter snapshotter) throws IOException { + var namespaceName = NamespaceName.of("Example", "Project"); + var otherNamespaceName = NamespaceName.of("Example", "Project2"); + var structType = Types.struct(namespaceName, "User"); + var shidInstruction = Shid.methodLoad(structType, "name"); + var typeInfo = TypeCheckerContext.EMPTY.toTypeInfos(); + var globalContext = ShidToPatioContext.GlobalContext.forTypeInfos(typeInfo); + var context = ShidToPatioContext.initialForCompilationUnit(Optional.of(otherNamespaceName), globalContext) .temporaryPush(new PatioLocalRef("a")); var result = ShidToPatio.generateInstruction(shidInstruction, context); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java index 447a925a..65386f61 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethodStoreTests.java @@ -22,7 +22,7 @@ public class ShidToPatioMethodStoreTests { var structType = Types.struct(namespaceName, "User"); var shidInstruction = Shid.methodStore(structType, "name"); var typeInfo = TypeCheckerContext.EMPTY.toTypeInfos(); - var context = ShidToPatioContext.forTypeInfos(typeInfo) + var context = ShidToPatioTesting.createContext(typeInfo) .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceFieldStoreTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceFieldStoreTests.java index c57f9572..436bd92c 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceFieldStoreTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceFieldStoreTests.java @@ -32,7 +32,7 @@ public class ShidToPatioNamespaceFieldStoreTests { .build() ) .toTypeInfos(); - var context = ShidToPatioContext.forTypeInfos(typeInfo) + var context = ShidToPatioTesting.createContext(typeInfo) .temporaryPush(new PatioLocalRef("a")) .temporaryPush(new PatioLocalRef("b")); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceTests.java index 561a420f..67a97d96 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioNamespaceTests.java @@ -45,7 +45,7 @@ public class ShidToPatioNamespaceTests { .addField("y", Types.STRING) .build() ); - var context = ShidToPatioContext.forTypeInfos(typeInfos); + var context = ShidToPatioTesting.createContext(typeInfos); var shidNamespace = new ShidNamespace(namespaceName, instructions, Sources.NULL); var result = ShidToPatio.generateNamespace(shidNamespace, context); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioSwitchTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioSwitchTests.java index b22e7572..d40da05b 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioSwitchTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioSwitchTests.java @@ -46,7 +46,7 @@ public class ShidToPatioSwitchTests { var typeInfos = TypeInfos.EMPTY .addStructTypeInfo(structType1, StructTypeInfo.builder().build()) .addStructTypeInfo(structType2, StructTypeInfo.builder().build()); - var context = ShidToPatioContext.forTypeInfos(typeInfos) + var context = ShidToPatioTesting.createContext(typeInfos) .temporaryPush(new PatioLocalRef("other")) .temporaryPush(new PatioLocalRef("condition")); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTesting.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTesting.java index 644371eb..c384d7c4 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTesting.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTesting.java @@ -1,10 +1,18 @@ package org.shedlang.compiler.shidtopatio; import org.shedlang.compiler.patio.PatioSerializer; +import org.shedlang.compiler.typechecker.TypeInfos; + +import java.util.Optional; class ShidToPatioTesting { private ShidToPatioTesting() {} + static ShidToPatioContext createContext(TypeInfos typeInfos) { + var globalContext = ShidToPatioContext.GlobalContext.forTypeInfos(typeInfos); + return ShidToPatioContext.initialForCompilationUnit(Optional.empty(), globalContext); + } + static String serialize(ShidToPatioContext context) { var builder = new StringBuilder(); diff --git a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTryTests.java b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTryTests.java index 5166449d..f7cfb141 100644 --- a/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTryTests.java +++ b/src/test/java/org/shedlang/compiler/shidtopatio/ShidToPatioTryTests.java @@ -37,7 +37,7 @@ public class ShidToPatioTryTests { .build() ) .toTypeInfos(); - var context = ShidToPatioContext.forTypeInfos(typeInfos) + var context = ShidToPatioTesting.createContext(typeInfos) .temporaryPush(new PatioLocalRef("other")) .temporaryPush(new PatioLocalRef("handlerA")) .temporaryPush(new PatioLocalRef("handlerC")) @@ -68,7 +68,7 @@ public class ShidToPatioTryTests { .build() ) .toTypeInfos(); - var context = ShidToPatioContext.forTypeInfos(typeInfos) + var context = ShidToPatioTesting.createContext(typeInfos) .stashGcRootStackIndex(new PatioLocalRef("gcRootStackIndex")) .temporaryPush(new PatioLocalRef("other")) .temporaryPush(new PatioLocalRef("handlerA")); |
