diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-19 21:12:09 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-19 21:12:09 +0100 |
| commit | b2a6c26840529ca98b061526e88fbfcd7266983e (patch) | |
| tree | de2173ba9ced920566d02385cc06f24a4815f677 /src/main/java | |
| parent | f08393c11645f29f93467f5c32fdce4abf41d2e7 (diff) | |
Add call-pointer instruction to Patio IR
Diffstat (limited to 'src/main/java')
3 files changed, 26 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java b/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java index a729f225..b8ef7fb6 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioInstructionSerializer.java @@ -34,6 +34,12 @@ public class PatioInstructionSerializer { case PatioAlloc alloc -> treeList(treeIdentifier("alloc"), treeInt(alloc.bytes())); + case PatioCallPointer callPointer -> + treeList( + treeIdentifier("call-pointer"), + treeNamed("arg-count", treeInt(callPointer.argCount())) + ); + case PatioDiscard discard -> treeList(treeIdentifier("discard")); diff --git a/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java new file mode 100644 index 00000000..07d3aa43 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/patio/instructions/PatioCallPointer.java @@ -0,0 +1,19 @@ +package org.shedlang.compiler.patio.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop a receiver and arguments from the stack and call the receiver with those + * arguments. + * + * <p>Specifically, the values should have been pushed onto the stack in the + * following order:</p> + * + * <ul> + * <li>The receiver i.e. a pointer to the function to be called.</li> + * <li>The arguments, from left to right.</li> + * </ul> + * + */ +public record PatioCallPointer(int argCount, Source source) implements PatioInstruction { +} 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 f839e6e7..9a015fdf 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, PatioDiscard, PatioLocalLoad, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioPushFunctionPointer, PatioReturn { +public sealed interface PatioInstruction permits PatioAlloc, PatioCallPointer, PatioDiscard, PatioLocalLoad, PatioLocalStore, PatioMemoryLoad, PatioMemoryStore, PatioPushFunctionPointer, PatioReturn { Source source(); } |
