From 6e7df5e2a5cf3edf4d027dc0deb6f62498794913 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 19 Jul 2023 21:18:51 +0100 Subject: Add push-int instruction to Patio IR --- .../shedlang/compiler/patio/PatioInstructionSerializer.java | 10 ++++++++-- .../shedlang/compiler/patio/instructions/PatioInstruction.java | 2 +- .../org/shedlang/compiler/patio/instructions/PatioPushInt.java | 9 +++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/shedlang/compiler/patio/instructions/PatioPushInt.java (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java b/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java index b8ef7fb6..4ebb08d0 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java @@ -67,10 +67,16 @@ public class PatioInstructionSerializer { treeNamed("offset", treeInt(memoryStore.offset())) ); - case PatioPushFunctionPointer patioPushFunctionPointer -> + case PatioPushFunctionPointer pushFunctionPointer -> treeList( treeIdentifier("push-function-pointer"), - treeString(patioPushFunctionPointer.name()) + treeString(pushFunctionPointer.name()) + ); + + case PatioPushInt pushInt -> + treeList( + treeIdentifier("push-int"), + treeInt(pushInt.value()) ); case PatioReturn return_ -> diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java index 9a015fdf..efea5694 100644 --- a/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioInstruction.java @@ -2,6 +2,6 @@ package org.shedlang.compiler.patio.instructions; import org.shedlang.compiler.sources.Source; -public sealed interface PatioInstruction permits PatioAlloc, PatioCallPointer, PatioDiscard, PatioLocalLoad, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioPushFunctionPointer, PatioReturn { +public sealed interface PatioInstruction permits PatioAlloc, PatioCallPointer, PatioDiscard, PatioLocalLoad, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioPushFunctionPointer, PatioPushInt, PatioReturn { Source source(); } diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioPushInt.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioPushInt.java new file mode 100644 index 00000000..ef455051 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioPushInt.java @@ -0,0 +1,9 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Push an integer onto the stack. + */ +public record PatioPushInt(int value, Source source) implements PatioInstruction { +} -- cgit v1.2.3