aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/shedlang/compiler/stackir
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-07 18:29:08 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-07 18:29:08 +0100
commit6820962c44cc7a27fe45d0a2ebe8140cd11f5811 (patch)
tree19d8b4208605761f53eb8602a8d5b682e45902ef /src/main/java/org/shedlang/compiler/stackir
parentbbd0ad7fad36761f55555347b01a32887fc4a5f9 (diff)
Add typed int add node
Diffstat (limited to 'src/main/java/org/shedlang/compiler/stackir')
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
index 9cd01151..c96b8cfd 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
@@ -12,6 +12,12 @@ public class StackCompiler {
private StackCompiler() {
}
+ private static PVector<Instruction> compileBinaryOperation(TypedBinaryOperationNode node) {
+ return compileExpression(node.left())
+ .plusAll(compileExpression(node.right()))
+ .plus(new IntAddInstruction(node.source()));
+ }
+
private static PVector<Instruction> compileBoolLiteral(TypedBoolLiteralNode node) {
return P.vector(new PushBoolInstruction(node.value(), node.source()));
}
@@ -42,6 +48,9 @@ public class StackCompiler {
public static PVector<Instruction> compileExpression(TypedExpressionNode node) {
return switch (node) {
+ case TypedBinaryOperationNode typedBinaryOperationNode ->
+ compileBinaryOperation(typedBinaryOperationNode);
+
case TypedBoolLiteralNode typedBoolLiteralNode ->
compileBoolLiteral(typedBoolLiteralNode);