diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-06-30 19:35:21 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-06-30 19:35:21 +0100 |
| commit | 71c588ca231d275c5263b3e9ca5f7f57c4e048a1 (patch) | |
| tree | 7e132e16697d881fd3472fc1b81f9731ecd7ae4e /src/main/java/org/shedlang/compiler/stackir | |
| parent | e8e3854cdda2c5aa2d47069e90698f5288f28b7c (diff) | |
Add field-load instruction
Diffstat (limited to 'src/main/java/org/shedlang/compiler/stackir')
3 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java b/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java index 35789b18..ef832b90 100644 --- a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java +++ b/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java @@ -74,6 +74,13 @@ public class InstructionSerializer { treeList( treeIdentifier("discard") ); + + case FieldLoadInstruction fieldLoad -> + treeList( + treeIdentifier("field-load"), + treeString(fieldLoad.namespaceName().toString()), + treeString(fieldLoad.fieldName()) + ); case LocalLoadInstruction localLoadInstruction -> treeList( diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java new file mode 100644 index 00000000..98ea9952 --- /dev/null +++ b/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java @@ -0,0 +1,15 @@ +package org.shedlang.compiler.stackir.instructions; + +import org.shedlang.compiler.sources.Source; +import org.shedlang.compiler.types.NamespaceName; + +/** + * Pop a value from the stack, get the given field from the popped value, and + * push the field's value onto the stack. + */ +public record FieldLoadInstruction( + NamespaceName namespaceName, + String fieldName, + Source source +) implements Instruction { +} 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 1fb0bede..6a21404c 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, LocalLoadInstruction, LocalStoreInstruction, NamespaceFieldStoreInstruction, NamespaceImportInstruction, PushBoolInstruction, PushIntInstruction, PushStringInstruction, PushUnitInstruction, ReturnInstruction { + permits CallInstruction, DefineFunctionInstruction, DiscardInstruction, FieldLoadInstruction, LocalLoadInstruction, LocalStoreInstruction, NamespaceFieldStoreInstruction, NamespaceImportInstruction, PushBoolInstruction, PushIntInstruction, PushStringInstruction, PushUnitInstruction, ReturnInstruction { Source source(); } |
