From cccf9edd15ad2148dadd09fa5a2a94edf9dbbf77 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 3 Apr 2026 10:11:21 +0100 Subject: Compile int-sub in patio-to-cranelift --- .../shedlang/compiler/patio/PatioExampleTests.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java index 08f4a50f..25219c9e 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioExampleTests.java @@ -365,6 +365,39 @@ public abstract class PatioExampleTests { )); } + @Test + public void intSub() throws IOException, InterruptedException { + var patioFunction = PatioFunctionDefinition.builder() + .withName(FUNCTION_NAME) + .withReturnType(PatioTypes.VOID) + .addLocal(Patio.val("x", PatioTypes.INT)) + .addLocal(Patio.val("y", PatioTypes.INT)) + .addLocal(Patio.val("z", PatioTypes.INT)) + .addBodyInstruction(Patio.localStore( + Patio.localRef("x"), + Patio.intConst(47) + )) + .addBodyInstruction(Patio.localStore( + Patio.localRef("y"), + Patio.intConst(5) + )) + .addBodyInstruction(Patio.intSub( + Patio.localRef("z"), + Patio.localRef("x"), + Patio.localRef("y") + )) + .addBodyInstruction(emitInt(Patio.localRef("z"))) + .addBodyInstruction(Patio.returnVoid()) + .build(); + var patio = Patio.compilationUnit(List.of(patioFunction)); + + var result = run(patio); + + assertThat(result, isSequence( + isInt(42) + )); + } + @Test public void switchWithUnreachableDefault() throws IOException, InterruptedException { var patioFunction = PatioFunctionDefinition.builder() -- cgit v1.2.3