From 36124bbfe721aedf17089b82fcc433592366ae4e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 21 Jan 2024 19:10:39 +0000 Subject: Implement Patio byte-offset-of instruction --- .../shedlang/compiler/patio/PatioExampleTests.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index d485e9e5..8582cfd0 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -818,6 +818,42 @@ public abstract class PatioExampleTests { assertThat(result, isSilentExit(47)); } + @Test + public void canGetByteOffset() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.INT) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addBodyInstruction(Patio.byteOffsetOf( + Patio.localRef("x"), + PatioDataLayouts.struct(List.of( + PatioDataLayouts.struct(List.of( + PatioDataLayouts.BYTE, + PatioDataLayouts.BYTE + )), + PatioDataLayouts.struct(List.of( + PatioDataLayouts.BYTE, + PatioDataLayouts.BYTE, + PatioDataLayouts.BYTE, + PatioDataLayouts.BYTE + )), + PatioDataLayouts.BYTE + )), + List.of(1, 2) + )) + .addBodyInstruction(Patio.return_( + Patio.localRef("x") + )) + .build(); + var patio = Patio.compilationUnit(List.of( + patioFunction + )); + + var result = run(patio); + + assertThat(result, isSilentExit(4)); + } + private Matcher isSilentExit(int exitCode) { return allOf( has("stderr", x -> x.stderr(), equalTo("")), -- cgit v1.2.3