diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-09-28 13:55:15 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-09-28 13:55:15 +0100 |
| commit | e73983a9a1862a99f2efe3f1c6ed81f978d57403 (patch) | |
| tree | df6762f7935384529183aeb525b9ffeff22c1a6f /src/main/java | |
| parent | 1ce720a70e964dd002800f4bc96c631229e0fa24 (diff) | |
Create separate notion of receiver for FieldLoadInstruction
Diffstat (limited to 'src/main/java')
4 files changed, 28 insertions, 11 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java index 684ed468..41df54f4 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java @@ -246,14 +246,18 @@ public class PatioCodeGen { var target = targetResult.value(); context = targetResult.context(); - context = PatioCodeGenNamespaces.fieldLoad( - target, - receiver, - fieldLoad.namespaceName(), - fieldLoad.fieldName(), - fieldLoad.source(), - context - ); + switch (fieldLoad.receiver()) { + case FieldLoadInstruction.Receiver.Namespace receiverNamespace -> { + context = PatioCodeGenNamespaces.fieldLoad( + target, + receiver, + receiverNamespace.name(), + fieldLoad.fieldName(), + fieldLoad.source(), + context + ); + } + } context = context.temporaryPush(target); diff --git a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java b/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java index d8ded6d3..53d0ce44 100644 --- a/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java +++ b/src/main/java/org/shedlang/compiler/stackir/InstructionSerializer.java @@ -84,7 +84,13 @@ public class InstructionSerializer { case FieldLoadInstruction fieldLoad -> treeList( treeIdentifier("field-load"), - treeString(fieldLoad.namespaceName().toString()), + switch (fieldLoad.receiver()) { + case FieldLoadInstruction.Receiver.Namespace namespace -> + treeList( + treeIdentifier("namespace"), + treeString(namespace.name().toString()) + ); + }, treeString(fieldLoad.fieldName()) ); diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index 35d6f497..8f46ca1d 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -310,7 +310,11 @@ public class StackCompiler { context = context .addInstruction(new NamespaceImportInstruction(ShedBuiltins.NAMESPACE_NAME, node.source())) - .addInstruction(new FieldLoadInstruction(ShedBuiltins.NAMESPACE_NAME, ShedBuiltins.PRINT_NAME, node.source())) + .addInstruction(new FieldLoadInstruction( + new FieldLoadInstruction.Receiver.Namespace(ShedBuiltins.NAMESPACE_NAME), + ShedBuiltins.PRINT_NAME, + node.source() + )) .addInstruction(new LocalStoreInstruction(printLocalName, node.source())); for (var boundVariableName : node.boundVariableNames()) { diff --git a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java b/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java index 98ea9952..6428e30e 100644 --- a/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java +++ b/src/main/java/org/shedlang/compiler/stackir/instructions/FieldLoadInstruction.java @@ -8,8 +8,11 @@ import org.shedlang.compiler.types.NamespaceName; * push the field's value onto the stack. */ public record FieldLoadInstruction( - NamespaceName namespaceName, + Receiver receiver, String fieldName, Source source ) implements Instruction { + public sealed interface Receiver { + record Namespace(NamespaceName name) implements Receiver {} + } } |
