diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 15:28:05 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 15:28:05 +0100 |
| commit | bd56a334bc2b9c9670c6d50e55939fb67389317c (patch) | |
| tree | 9ec17ca96fb0f531e507b68752bc324174f5e7cf /src/main/java | |
| parent | 2d6ca67c0a0ca4e72ab409e5503a112f30e1f0a7 (diff) | |
Add Patio code gen for int-add
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index db00aea8..ef034b20 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -1,6 +1,7 @@ package org.shedlang.compiler.patio; import org.shedlang.compiler.patio.ast.PatioLocalRef; +import org.shedlang.compiler.patio.ast.instructions.PatioIntAdd; import org.shedlang.compiler.patio.ast.instructions.PatioIntGet; import org.shedlang.compiler.patio.ast.instructions.PatioReturn; import org.shedlang.compiler.sources.Source; @@ -127,6 +128,32 @@ public class PatioCodeGen { case DiscardInstruction discard -> context.temporaryPop().context(); + case IntAddInstruction intAdd -> { + var rightResult = context.temporaryPop(); + var right = rightResult.value(); + context = rightResult.context(); + + var leftResult = context.temporaryPop(); + var left = leftResult.value(); + context = leftResult.context(); + + var targetResult = context.allocateLocal( + PatioCodeGenLocalSpace.TEMPORARY, + PatioCodeGenTypes.VALUE_TYPE + ); + var target = targetResult.value(); + context = targetResult.context(); + + yield context + .addInstruction(new PatioIntAdd( + target, + left, + right, + intAdd.source() + )) + .temporaryPush(target); + } + case LocalLoadInstruction localLoad -> { var local = context.stackIrLocalNameToLocal(localLoad.name()); |
