diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-12-22 11:05:15 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-12-22 11:05:15 +0000 |
| commit | 1397d18e897e98ede05e8bbc7b394c0469fb887a (patch) | |
| tree | 6ed2e41c31ba7b6565b346c187fa7d94c92a2213 /src/main/java | |
| parent | 1a1f26b2abdd3bd9edfebd55c2559f1b77a8f947 (diff) | |
Implement Patio codegen for method store and load
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java | 13 | ||||
| -rw-r--r-- | src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethods.java | 53 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java index b612dbf3..beb8118a 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatio.java @@ -522,12 +522,24 @@ public class ShidToPatio { } case ShidMethodLoad methodLoad -> { + var destinationResult = context.allocateVal( + ShidToPatioLocalSpace.TEMPORARY, + methodLoad.methodName(), + ShidToPatioTypes.VALUE_TYPE + ); + var destination = destinationResult.value(); + context = destinationResult.context(); + context = ShidToPatioMethods.methodLoad( + destination, methodLoad.type(), methodLoad.methodName(), + methodLoad.source(), context ); + context = context.temporaryPush(destination); + yield context; } @@ -540,6 +552,7 @@ public class ShidToPatio { methodStore.type(), methodStore.methodName(), methodValue, + methodStore.source(), context ); diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethods.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethods.java index ae1bb925..c621c6cb 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethods.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioMethods.java @@ -1,17 +1,41 @@ package org.shedlang.compiler.shidtopatio; +import org.shedlang.compiler.patio.PatioDataElementMutable; +import org.shedlang.compiler.patio.PatioVisibility; +import org.shedlang.compiler.patio.instructions.PatioMemoryLoad; +import org.shedlang.compiler.patio.instructions.PatioMemoryStore; +import org.shedlang.compiler.patio.operands.PatioDataPtrConst; +import org.shedlang.compiler.patio.operands.PatioLocalRef; import org.shedlang.compiler.patio.operands.PatioOperand; +import org.shedlang.compiler.patio.types.PatioDataLayouts; +import org.shedlang.compiler.patio.types.PatioDataValues; +import org.shedlang.compiler.sources.Source; import org.shedlang.compiler.types.SimpleStructType; +import java.text.MessageFormat; +import java.util.List; + +import static org.shedlang.compiler.shidtopatio.ShidToPatioNamespaces.namespaceNameToPatioIdentifier; + public class ShidToPatioMethods { private ShidToPatioMethods() { } public static ShidToPatioContext methodLoad( + PatioLocalRef destination, SimpleStructType type, String methodName, + Source source, ShidToPatioContext context ) { + context = context.addInstruction(new PatioMemoryLoad( + destination, + globalOperandMethod(type, methodName), + PatioDataLayouts.fromType(ShidToPatioTypes.VALUE_TYPE), + List.of(), + source + )); + return context; } @@ -19,8 +43,37 @@ public class ShidToPatioMethods { SimpleStructType type, String methodName, PatioOperand methodValue, + Source source, ShidToPatioContext context ) { + context = context.addCompilationUnitElement(new PatioDataElementMutable( + globalNameMethod(type, methodName), + PatioVisibility.PRIVATE, + PatioDataValues.int_(0), + source + )); + + context = context.addInstruction(new PatioMemoryStore( + globalOperandMethod(type, methodName), + PatioDataLayouts.fromType(ShidToPatioTypes.VALUE_TYPE), + List.of(), + methodValue, + source + )); + return context; } + + private static PatioOperand globalOperandMethod(SimpleStructType type, String methodName) { + return PatioDataPtrConst.dataElement(globalNameMethod(type, methodName)); + } + + private static String globalNameMethod(SimpleStructType type, String methodName) { + return MessageFormat.format( + "shed__method__{0}__{1}__{2}", + namespaceNameToPatioIdentifier(type.namespaceName()), + type.name(), + methodName + ); + } } |
