aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 13:31:18 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 13:31:18 +0000
commitd6d868850097a443d5a011915de0a713d7722e54 (patch)
treeed453cea5b934f493f8480ad09cf47dc7c1f5a32 /src/main/java
parent16b74100b42d59379a2983c9bef2f6357c2376d3 (diff)
Extract offset functions for structs
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
index 7c7ece4d..67461ff6 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenStructs.java
@@ -56,7 +56,7 @@ public class PatioCodeGenStructs {
.addInstruction(new PatioMemoryStore(
valuePointer,
structDataLayout,
- List.of(0),
+ TAG_OFFSET,
new PatioInt(context.structTag(type)),
source
));
@@ -68,7 +68,7 @@ public class PatioCodeGenStructs {
.addInstruction(new PatioMemoryStore(
valuePointer,
structDataLayout,
- List.of(1, fieldIndex),
+ fieldOffset(fieldIndex),
bodyContext.shidLocalNameToLocal(field.name()),
source
));
@@ -126,7 +126,7 @@ public class PatioCodeGenStructs {
target,
valuePointer,
structDataLayout,
- List.of(1, fieldIndex),
+ fieldOffset(fieldIndex),
source
));
@@ -158,7 +158,7 @@ public class PatioCodeGenStructs {
target,
valuePointer,
structDataLayout,
- List.of(0),
+ TAG_OFFSET,
source
));
@@ -185,4 +185,10 @@ public class PatioCodeGenStructs {
))
));
}
+
+ private static final List<Integer> TAG_OFFSET = List.of(0);
+
+ private static List<Integer> fieldOffset(int fieldIndex) {
+ return List.of(1, fieldIndex);
+ }
}