aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-09-28 14:07:01 +0100
committerMichael Williamson <mike@zwobble.org>2023-09-28 14:07:01 +0100
commit49aee72f35f1ffdfc90a89162a500193746ef467 (patch)
treed4b4c2c1b013dde4cbc396c35e14bca7b57c1013 /src/main/java
parent09da904f2de0b16f883add671469989bafc726e9 (diff)
Generate stack IR for field accesses
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java2
-rw-r--r--src/main/java/org/shedlang/compiler/stackir/StackCompiler.java18
2 files changed, 18 insertions, 2 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index a78c5eaf..1a194db8 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -258,7 +258,7 @@ public class PatioCodeGen {
);
}
- case FieldLoadInstruction.Receiver.Struct struct -> {
+ case FieldLoadInstruction.Receiver.Struct receiverStruct -> {
throw new UnsupportedOperationException("TODO");
}
}
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
index 8f46ca1d..8e0ec59e 100644
--- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
+++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java
@@ -4,6 +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.util.P;
import java.util.List;
@@ -122,7 +123,7 @@ public class StackCompiler {
compileCall(typedCallNode, context);
case TypedFieldAccessNode typedFieldAccessNode ->
- throw new UnsupportedOperationException("TODO");
+ compileFieldAccess(typedFieldAccessNode, context);
case TypedIfNode typedIfNode ->
compileIf(typedIfNode, context);
@@ -150,6 +151,21 @@ public class StackCompiler {
return context;
}
+ private static Context compileFieldAccess(
+ TypedFieldAccessNode node,
+ Context context
+ ) {
+ context = compileExpression(node.receiver(), context);
+ // TODO: handle not a struct type
+ var receiverType = (StructType) node.receiver().type();
+ context = context.addInstruction(new FieldLoadInstruction(
+ new FieldLoadInstruction.Receiver.Struct(receiverType),
+ node.fieldName(),
+ node.source()
+ ));
+ return context;
+ }
+
private static Context compileFunctionDefinition(
TypedFunctionDefinitionNode node,
Context context