diff options
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java | 27 |
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( |
