aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-10-21 13:47:49 +0100
committerMichael Williamson <mike@zwobble.org>2023-10-21 13:47:49 +0100
commit386df535db2970c6ab8acc47adaf803d61934a3f (patch)
tree69b53e2e83b128feb2440f835a7e41230947b0d4 /src/main/java
parent317f6fa18dfb5dd0020a086d2815c538fcb558ff (diff)
Generate stack IR for field access on namespace
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
index 7a9fc502..130b5fdf 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
@@ -4,7 +4,7 @@ import org.pcollections.*;
import org.shedlang.compiler.ShedBuiltins;
import org.shedlang.compiler.ast.typed.*;
import org.shedlang.compiler.stackir.instructions.*;
-import org.shedlang.compiler.types.StructType;
+import org.shedlang.compiler.types.*;
import org.shedlang.compiler.util.Iterables;
import org.shedlang.compiler.util.P;
@@ -161,10 +161,20 @@ public class StackCompiler {
Context context
) {
context = compileExpression(node.receiver(), context);
- // TODO: handle not a struct type
- var receiverType = (StructType) node.receiver().type();
+ // TODO: handle not a type with fields
+ var receiver = switch (node.receiver().type()) {
+ case NamespaceType namespaceType ->
+ new FieldLoadInstruction.Receiver.Namespace(namespaceType.namespaceName());
+
+ case StructType structType ->
+ new FieldLoadInstruction.Receiver.Struct(structType);
+
+ default ->
+ throw new RuntimeException("not a type with fields");
+ };
+
context = context.addInstruction(new FieldLoadInstruction(
- new FieldLoadInstruction.Receiver.Struct(receiverType),
+ receiver,
node.fieldName(),
node.source()
));