diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 17:18:59 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 17:18:59 +0100 |
| commit | b566789e4dd17ab81fc73917d24cb9bf2a678707 (patch) | |
| tree | be94df676a45e4ef375fd533c7505e85c9f12a75 /src/test/java | |
| parent | 4a6e046a50e68ca90cae7725362e922fd3ca2f58 (diff) | |
Create data element for namespace value
Diffstat (limited to 'src/test/java')
3 files changed, 25 insertions, 2 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java index ff37b834..60e5d3dd 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenNamespaceTests.java @@ -9,10 +9,15 @@ import org.shedlang.compiler.stackir.instructions.Instruction; 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.TypeInfo; import org.shedlang.compiler.types.NamespaceName; +import org.shedlang.compiler.types.NamespaceTypeInfo; +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.serializeCompilationUnit; @@ -32,8 +37,13 @@ public class PatioCodeGenNamespaceTests { Sources.NULL ); var instructions = List.<Instruction>of(instruction); - var context = PatioCodeGenContext.EMPTY; var namespaceName = NamespaceName.of("An","Example"); + var context = PatioCodeGenContext.forTypeInfo(new TypeInfo(P.map( + Map.entry(namespaceName, new NamespaceTypeInfo(P.orderedMap( + Map.entry("x", Types.INT), + Map.entry("y", Types.STRING) + ))) + ))); var result = PatioCodeGen.generateNamespace(namespaceName, instructions, context); diff --git a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java index 59bbdaaf..4a43eb44 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java @@ -39,9 +39,18 @@ public class PatioSerializerTests { )); } + // == Compilation unit elements == + @Test + public void canSerializeDataElement() { + var element = Patio.dataElement("x", PatioTypes.scalar(PatioTypes.INT)); - // == Compilation unit elements == + var string = PatioTesting.serializeCompilationUnitElement(element); + + assertThat(string, equalTo(""" + (data "x" int)""" + )); + } @Test public void canSerializeFunctionDefinition() { diff --git a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java index 53497bea..48b458c7 100644 --- a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java +++ b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java @@ -36,6 +36,10 @@ public class Patio { return new PatioCompilationUnit(elements, Sources.NULL); } + public static PatioDataElement dataElement(String name, PatioDataLayout layout) { + return new PatioDataElement(name, layout, Sources.NULL); + } + public static PatioInstruction dataPtrToInt(String target, String value) { return new PatioDataPtrToInt( new PatioLocalRef(target), |
