diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-20 14:20:36 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-20 14:20:36 +0100 |
| commit | 9fce582cb0aa3cbd73c9a398f66d75bf39c360de (patch) | |
| tree | ed1bfe5ea7456399fb355165e71a57c0ac501506 /src/main/java | |
| parent | b48edd39f96c9f3f0917fb4000d10f0a78920b7d (diff) | |
Support multiple offsets to allow access of nested structures
Diffstat (limited to 'src/main/java')
4 files changed, 17 insertions, 5 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java index e8d991d2..cdeb1dac 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenClosures.java @@ -23,7 +23,7 @@ class PatioCodeGenClosures { private PatioCodeGenClosures() {} - private static final int FUNCTION_POINTER_OFFSET = 0; + private static final List<Integer> FUNCTION_POINTER_OFFSET = List.of(0); private static PatioDataLayout closureDataLayoutForCall() { return new PatioStruct(List.of( diff --git a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java index 6a48399e..428994a9 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/PatioSerializer.java @@ -108,7 +108,11 @@ public class PatioSerializer { localRefToTree(memoryLoad.target()), treeNamed("pointer", localRefToTree(memoryLoad.pointer())), treeNamed("layout", dataLayoutToTree(memoryLoad.layout())), - treeNamed("offset", treeInt(memoryLoad.offset())) + treeNamed("offset", treeList( + memoryLoad.offset().stream() + .map(offset -> treeInt(offset)) + .toList() + )) ); case PatioMemoryStore memoryStore -> @@ -116,7 +120,11 @@ public class PatioSerializer { treeIdentifier("memory-store"), treeNamed("pointer", localRefToTree(memoryStore.pointer())), treeNamed("layout", dataLayoutToTree(memoryStore.layout())), - treeNamed("offset", treeInt(memoryStore.offset())), + treeNamed("offset", treeList( + memoryStore.offset().stream() + .map(offset -> treeInt(offset)) + .toList() + )), treeNamed("value", localRefToTree(memoryStore.value())) ); diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java index 430296ee..7a5f49ce 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryLoad.java @@ -4,6 +4,8 @@ import org.shedlang.compiler.patio.ast.PatioLocalRef; import org.shedlang.compiler.patio.ast.types.PatioDataLayout; import org.shedlang.compiler.sources.Source; +import java.util.List; + /** * Load the value at the given offset from the given pointer and store it in the * target local. @@ -12,7 +14,7 @@ public record PatioMemoryLoad( PatioLocalRef target, PatioLocalRef pointer, PatioDataLayout layout, - int offset, + List<Integer> offset, Source source ) implements PatioInstruction { } diff --git a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java index b32899db..0a9b35a6 100644 --- a/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java +++ b/src/main/java/org/shedlang/compiler/patio/ast/instructions/PatioMemoryStore.java @@ -4,13 +4,15 @@ import org.shedlang.compiler.patio.ast.PatioLocalRef; import org.shedlang.compiler.patio.ast.types.PatioDataLayout; import org.shedlang.compiler.sources.Source; +import java.util.List; + /** * Store the given value at the given offset from the given pointer. */ public record PatioMemoryStore( PatioLocalRef pointer, PatioDataLayout layout, - int offset, + List<Integer> offset, PatioLocalRef value, Source source ) implements PatioInstruction { |
