From 5564950ec34d3be47b9e39d3c8cdf58c0b38af1d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 11 Jun 2023 23:02:41 +0100 Subject: Compile push-unit instruction to LLVM IR --- .../compiler/backends/llvm/LlvmCompiler.java | 5 ++--- .../backends/llvm/LlvmCompilerPushUnitTests.java | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushUnitTests.java (limited to 'src') diff --git a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java index be5dbf8c..710e9c7f 100644 --- a/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java +++ b/src/main/java/org/shedlang/compiler/backends/llvm/LlvmCompiler.java @@ -40,9 +40,8 @@ public class LlvmCompiler { case PushStringInstruction pushStringInstruction -> { throw new UnsupportedOperationException("TODO"); } - case PushUnitInstruction pushUnitInstruction -> { - throw new UnsupportedOperationException("TODO"); - } + case PushUnitInstruction pushUnit -> + context.push(new LlvmOperandInt(0)); }; } } diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushUnitTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushUnitTests.java new file mode 100644 index 00000000..7a3da398 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmCompilerPushUnitTests.java @@ -0,0 +1,21 @@ +package org.shedlang.compiler.backends.llvm; + +import org.junit.jupiter.api.Test; +import org.shedlang.compiler.stackir.instructions.Instructions; + +import static org.shedlang.compiler.backends.llvm.ir.ast.LlvmIrMatchers.isLlvmOperandInt; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.isSequence; + +public class LlvmCompilerPushUnitTests { + @Test + public void pushUnitIsCompiledToOperandInStack() { + var instruction = Instructions.pushUnit(); + var context = LlvmCompilerContext.EMPTY; + + var result = LlvmCompiler.compileInstruction(instruction, context); + + assertThat(result.instructions(), isSequence()); + assertThat(result.stack(), isSequence(isLlvmOperandInt(0))); + } +} -- cgit v1.2.3