diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-17 18:10:00 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-17 18:10:00 +0100 |
| commit | c2b45daf5ddab7b518aed9a51026a599fe4bccef (patch) | |
| tree | 8bfaa2d709fe614ac12e910f34e61507756f0352 /src/main/java | |
| parent | 486a1a499da88239f625c0bcc913c41c01496e3c (diff) | |
Add tuple-get instruction
Diffstat (limited to 'src/main/java')
5 files changed, 27 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index 3332a117..e6e3ba0a 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -471,6 +471,10 @@ public class PatioCodeGen { throw new UnsupportedOperationException("TODO"); } + case TupleGetInstruction tupleGet -> { + throw new UnsupportedOperationException("TODO"); + } + case VarLoadInstruction varLoad -> { var varValueResult = context.allocateVal( PatioCodeGenLocalSpace.VAR_VALUE, diff --git a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java b/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java index d2dfc37b..875dbcec 100644 --- a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java +++ b/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java @@ -177,6 +177,12 @@ public class InstructionSerializer { treeInt(tupleCreateInstruction.elementCount()) ); + case TupleGetInstruction tupleGetInstruction -> + treeList( + treeIdentifier("tuple-get"), + treeInt(tupleGetInstruction.elementIndex()) + ); + case VarLoadInstruction varLoadInstruction -> treeList( treeIdentifier("var-load"), diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java index 25b14e93..29703869 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java +++ b/src/main/java/org/shedlang/compiler/stackir/instructions/Instruction.java @@ -3,7 +3,7 @@ package org.shedlang.compiler.stackir.instructions; import org.shedlang.compiler.sources.Source; public sealed interface Instruction - permits CallInstruction, DefineFunctionInstruction, DiscardInstruction, FieldLoadInstruction, IfInstruction, IntAddInstruction, IntEqualsInstruction, IntNotEqualInstruction, IntSubInstruction, LocalLoadInstruction, LocalStoreInstruction, LoopBreakInstruction, LoopContinueInstruction, LoopInstruction, NamespaceFieldStoreInstruction, NamespaceImportInstruction, PushBoolInstruction, PushIntInstruction, PushStringInstruction, PushUnitInstruction, ReturnInstruction, StringAddInstruction, TupleCreateInstruction, VarLoadInstruction, VarStoreInstruction { + permits CallInstruction, DefineFunctionInstruction, DiscardInstruction, FieldLoadInstruction, IfInstruction, IntAddInstruction, IntEqualsInstruction, IntNotEqualInstruction, IntSubInstruction, LocalLoadInstruction, LocalStoreInstruction, LoopBreakInstruction, LoopContinueInstruction, LoopInstruction, NamespaceFieldStoreInstruction, NamespaceImportInstruction, PushBoolInstruction, PushIntInstruction, PushStringInstruction, PushUnitInstruction, ReturnInstruction, StringAddInstruction, TupleCreateInstruction, TupleGetInstruction, VarLoadInstruction, VarStoreInstruction { Source source(); } diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java index 0888d947..d1dec767 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java +++ b/src/main/java/org/shedlang/compiler/stackir/instructions/TupleCreateInstruction.java @@ -3,8 +3,9 @@ package org.shedlang.compiler.stackir.instructions; import org.shedlang.compiler.sources.Source; /** - * Pop {@code elementCount} values from the stack and create a tuple from those - * elements. Elements should have been pushed onto the stack in index order. + * Pop {@code elementCount} values from the stack, create a tuple from those + * elements, and push the tuple onto the stack. Elements should have been pushed + * onto the stack in index order. */ public record TupleCreateInstruction( int elementCount, diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java new file mode 100644 index 00000000..b621a336 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/stackir/instructions/TupleGetInstruction.java @@ -0,0 +1,13 @@ +package org.shedlang.compiler.stackir.instructions; + +import org.shedlang.compiler.sources.Source; + +/** + * Pop a tuple from the stack, get the element at the given index, and push it + * onto the stack. + */ +public record TupleGetInstruction( + int elementIndex, + Source source +) implements Instruction { +} |
