aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 18:35:46 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 18:35:46 +0000
commit538d0c883cb5afaeef7a58a66a876b7c2cc80708 (patch)
tree2072c923999378dd117c12f64ce670ef40cfc0ab /src/main/java/org
parente0f232e9ad7fbe304e99bb4e880c761f06255791 (diff)
Support constructed type field accesses in Shid code gen
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java27
1 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
index 8c42982b..501e12e5 100644
--- a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
@@ -190,7 +190,22 @@ public class ShidCodeGen {
) {
context = compileExpression(node.receiver(), context);
// TODO: handle not a type with fields
- var receiver = switch (node.receiver().type()) {
+ var receiverType = node.receiver().type();
+ var receiver = receiverTypeToReceiver(receiverType);
+
+ context = context.addInstruction(new ShidFieldLoad(
+ receiver,
+ node.fieldName(),
+ node.source()
+ ));
+ return context;
+ }
+
+ private static ShidFieldLoad.Receiver receiverTypeToReceiver(Type receiverType) {
+ return switch (receiverType) {
+ case ConstructedType constructedType ->
+ receiverTypeToReceiver(constructedType.genericType());
+
case NamespaceType namespaceType ->
new ShidFieldLoad.Receiver.Namespace(namespaceType.namespaceName());
@@ -205,16 +220,8 @@ public class ShidCodeGen {
}
}
- default ->
- throw new RuntimeException("not a type with fields");
+ default -> throw new RuntimeException("not a type with fields");
};
-
- context = context.addInstruction(new ShidFieldLoad(
- receiver,
- node.fieldName(),
- node.source()
- ));
- return context;
}
private static Context compileFunction(